2 ** Copyright (c) Massachusetts Institute of Technology 1994-1998.
3 ** All Rights Reserved.
4 ** Unpublished rights reserved under the copyright laws of
7 ** THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 ** OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 ** This code is distributed freely and may be used freely under the
11 ** following conditions:
13 ** 1. This notice may not be removed or altered.
15 ** 2. Works derived from this code are not distributed for
16 ** commercial gain without explicit permission from MIT
17 ** (for permission contact lclint-request@sds.lcs.mit.edu).
24 ** Yacc/Bison grammar for extended ANSI C used by LCLint.
26 ** original grammar by Nate Osgood ---
27 ** hacrat@catfish.lcs.mit.edu Mon Jun 14 13:06:32 1993
29 ** changes for LCLint --- handle typedef names correctly
30 ** fix struct/union parsing bug (empty struct is accepted)
31 ** add productions to handle macros --- require
32 ** error correction --- main source of conflicts in grammar.
33 ** need to process initializations sequentially, L->R
35 ** production names are cryptic, so more productions fit on one line
37 ** conflicts: 87 shift/reduce, 18 reduce/reduce
38 ** most of these are due to handling macros
39 ** a few are due to handling type expressions
45 extern void swallowMacro (void);
46 extern void yyerror (char *);
48 # include "lclintMacros.nf"
50 # include "cscanner.h"
51 # include "cgrammar.h"
52 # include "exprChecks.h"
57 # define SHOWCSYM FALSE
60 ** This is necessary, or else when the bison-generated code #include's malloc.h,
61 ** there will be a parse error.
63 ** Unfortunately, it means the error checking on malloc, etc. is lost for allocations
64 ** in bison-generated files under Win32.
82 /*@dependent@*/ sRef sr;
85 /*@only@*/ functionClauseList funcclauselist;
86 /*@only@*/ functionClause funcclause;
87 /*@only@*/ flagSpec flagspec;
88 /*@only@*/ globalsClause globsclause;
89 /*@only@*/ modifiesClause modsclause;
90 /*@only@*/ warnClause warnclause;
91 /*@only@*/ stateClause stateclause;
93 /*@only@*/ functionConstraint fcnconstraint;
95 /*@only@*/ metaStateConstraint msconstraint;
96 /*@only@*/ metaStateSpecifier msspec;
97 /*@only@*/ metaStateExpression msexpr;
98 /*@observer@*/ metaStateInfo msinfo;
100 /*@only@*/ sRefList srlist;
101 /*@only@*/ globSet globset;
102 /*@only@*/ qtype qtyp;
103 /*@only@*/ cstring cname;
104 /*@observer@*/ annotationInfo annotation;
105 /*@only@*/ idDecl ntyp;
106 /*@only@*/ idDeclList ntyplist;
107 /*@only@*/ uentryList flist;
108 /*@owned@*/ uentryList entrylist;
109 /*@observer@*/ /*@dependent@*/ uentry entry;
110 /*@only@*/ uentry oentry;
111 /*@only@*/ exprNode expr;
112 /*@only@*/ enumNameList enumnamelist;
113 /*@only@*/ exprNodeList exprlist;
114 /*@only@*/ sRefSet srset;
115 /*@only@*/ cstringList cstringlist;
126 /* standard C tokens */
128 %token <tok> BADTOK SKIPTOK
129 %token <tok> CTOK_ELIPSIS CASE DEFAULT CIF CELSE SWITCH WHILE DO CFOR
130 %token <tok> GOTO CONTINUE BREAK RETURN
131 %token <tok> TSEMI TLBRACE TRBRACE TCOMMA TCOLON TASSIGN TLPAREN
132 %token <tok> TRPAREN TLSQBR TRSQBR TDOT TAMPERSAND TEXCL TTILDE
133 %token <tok> TMINUS TPLUS TMULT TDIV TPERCENT TLT TGT TCIRC TBAR TQUEST
134 %token <tok> CSIZEOF CALIGNOF ARROW_OP CTYPEDEF COFFSETOF
135 %token <tok> INC_OP DEC_OP LEFT_OP RIGHT_OP
136 %token <tok> LE_OP GE_OP EQ_OP NE_OP AND_OP OR_OP
137 %token <tok> MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN SUB_ASSIGN
138 %token <tok> LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
139 %token <tok> CSTRUCT CUNION CENUM
140 %token <tok> VA_ARG VA_DCL
142 %token <tok> QGLOBALS
143 %token <tok> QMODIFIES
145 %token <tok> QCONSTANT
146 %token <tok> QFUNCTION
148 %token <tok> QDEFINES
150 %token <tok> QALLOCATES
152 %token <tok> QRELEASES
153 %token <tok> QPRECLAUSE
154 %token <tok> QPOSTCLAUSE
156 %token <tok> QUNDEF QKILLED
157 %token <tok> QENDMACRO
159 /* additional tokens introduced by lclint pre-processor. */
160 %token <tok> LLMACRO LLMACROITER LLMACROEND TENDMACRO
162 /* break comments: */
163 %token <tok> QSWITCHBREAK QLOOPBREAK QINNERBREAK QSAFEBREAK
164 %token <tok> QINNERCONTINUE
166 /* case fall-through marker: */
167 %token <tok> QFALLTHROUGH
169 /* used in scanner only */
170 %token <tok> QLINTNOTREACHED
171 %token <tok> QLINTFALLTHROUGH
172 %token <tok> QLINTFALLTHRU
173 %token <tok> QARGSUSED
174 %token <tok> QPRINTFLIKE QLINTPRINTFLIKE QSCANFLIKE QMESSAGELIKE
176 /* not-reached marker: (used like a label) */
177 %token <tok> QNOTREACHED
179 /* type qualifiers: */
180 %token <tok> QCONST QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
181 %token <tok> QOUT QIN QYIELD QONLY QTEMP QSHARED QREF QUNIQUE
182 %token <tok> QCHECKED QUNCHECKED QCHECKEDSTRICT QCHECKMOD
183 %token <tok> QKEEP QKEPT QPARTIAL QSPECIAL QOWNED QDEPENDENT
184 %token <tok> QRETURNED QEXPOSED QNULL QOBSERVER QISNULL
185 %token <tok> QEXITS QMAYEXIT QNEVEREXIT QTRUEEXIT QFALSEEXIT
186 %token <tok> QLONG QSIGNED QUNSIGNED QSHORT QUNUSED QSEF QNOTNULL QRELNULL
187 %token <tok> QABSTRACT QCONCRETE QMUTABLE QIMMUTABLE
188 %token <tok> QTRUENULL QFALSENULL QEXTERNAL
189 %token <tok> QREFCOUNTED QREFS QNEWREF QTEMPREF QKILLREF QRELDEF
190 %token <ctyp> CGCHAR CBOOL CINT CGFLOAT CDOUBLE CVOID
191 %token <tok> QANYTYPE QINTEGRALTYPE QUNSIGNEDINTEGRALTYPE QSIGNEDINTEGRALTYPE
193 %type <typequal> nullterminatedQualifier
194 %token <tok> QNULLTERMINATED
195 %token <tok> QSETBUFFERSIZE
196 %token <tok> QSETSTRINGLENGTH
198 %token <tok> QMAXREAD
199 %token <tok> QTESTINRANGE
204 /* identifiers, literals */
205 %token <entry> IDENTIFIER
206 %token <cname> NEW_IDENTIFIER TYPE_NAME_OR_ID
207 %token <annotation> CANNOTATION
208 %token <expr> CCONSTANT
210 %type <flagspec> flagSpec
211 %type <expr> cconstantExpr
212 %token <entry> ITER_NAME ITER_ENDNAME
213 %type <entry> endIter
215 %type <funcclauselist> functionClauses functionClausesPlain
216 %type <funcclause> functionClause functionClause functionClausePlain
218 %type <globsclause> globalsClause globalsClausePlain
219 %type <modsclause> modifiesClause modifiesClausePlain nomodsClause
220 %type <warnclause> warnClause warnClausePlain optWarnClause
221 %type <funcclause> conditionClause conditionClausePlain
222 %type <stateclause> stateClause stateClausePlain
223 %type <msconstraint> metaStateConstraint
224 %type <fcnconstraint> functionConstraint
225 %type <msspec> metaStateSpecifier
226 %type <msexpr> metaStateExpression
228 %type <sr> globId globIdListExpr
229 %type <globset> globIdList
231 %token <ctyp> TYPE_NAME
232 %token <msinfo> METASTATE_NAME
233 %type <msinfo> metaStateName
234 %type <cname> enumerator newId /*@-varuse@*/ /* yacc declares yytranslate here */
235 %type <count> pointers /*@=varuse@*/
237 %type <tok> doHeader stateTag conditionTag startConditionClause
238 %type <typequal> exitsQualifier checkQualifier stateQualifier
239 paramQualifier returnQualifier visibilityQualifier
240 typedefQualifier refcountQualifier definedQualifier
242 /* type construction */
243 %type <ctyp> abstractDecl abstractDeclBase optAbstractDeclBase
244 %type <ctyp> suSpc enumSpc typeName typeSpecifier
246 %type <ntyp> namedDecl namedDeclBase optNamedDecl
247 %type <ntyp> plainNamedDecl plainNamedDeclBase
248 %type <ntyp> structNamedDecl
249 %type <ntyp> fcnDefHdrAux plainFcn
251 %type <oentry> paramDecl
254 %type <ntyplist> structNamedDeclList
256 %type <entrylist> genericParamList paramTypeList paramList idList paramIdList
257 %type <exprlist> argumentExprList iterArgList
258 %type <exprlist> initList namedInitializerList namedInitializerListAux
259 %type <flist> structDeclList structDecl
260 %type <srset> locModifies modList specClauseList optSpecClauseList
261 %type <sr> mExpr modListExpr specClauseListExpr
264 %type <con> BufConstraint
265 %type <tok> relationalOp
266 %type <tok> BufBinaryOp
267 %type <tok> bufferModifier
269 %type <conE> BufConstraintExpr
271 %type <conE> BufConstraintTerm
272 %type <sr> BufConstraintSrefExpr
274 %type <conL> BufConstraintList
276 %type <tok> BufUnaryOp
278 %type <enumnamelist> enumeratorList
279 %type <cstringlist> fieldDesignator
281 %type <expr> sizeofExpr sizeofExprAux offsetofExpr
282 %type <expr> openScope closeScope
283 %type <expr> instanceDecl namedInitializer optDeclarators
284 %type <expr> primaryExpr postfixExpr primaryIterExpr postfixIterExpr
285 %type <expr> unaryExpr castExpr timesExpr plusExpr
286 %type <expr> unaryIterExpr castIterExpr timesIterExpr plusIterExpr
287 %type <expr> shiftExpr relationalExpr equalityExpr bitandExpr
288 %type <expr> xorExpr bitorExpr andExpr
289 %type <expr> orExpr conditionalExpr assignExpr
290 %type <expr> shiftIterExpr relationalIterExpr equalityIterExpr bitandIterExpr
291 %type <expr> xorIterExpr bitorIterExpr andIterExpr
292 %type <expr> orIterExpr conditionalIterExpr assignIterExpr iterArgExpr
293 %type <expr> expr optExpr constantExpr
294 %type <expr> init macroBody iterBody endBody partialIterStmt iterSelectionStmt
295 %type <expr> stmt stmtList fcnBody iterStmt iterDefStmt iterDefStmtList
296 %type <expr> labeledStmt caseStmt defaultStmt
297 %type <expr> compoundStmt compoundStmtAux compoundStmtRest compoundStmtAuxErr
298 %type <expr> expressionStmt selectionStmt iterationStmt jumpStmt iterDefIterationStmt
299 %type <expr> stmtErr stmtListErr compoundStmtErr expressionStmtErr
300 %type <expr> iterationStmtErr initializerList initializer ifPred whilePred forPred iterWhilePred
302 %type <typequal> storageSpecifier typeQualifier typeModifier globQual
303 %type <tquallist> optGlobQuals
304 %type <qtyp> completeType completeTypeSpecifier optCompleteType
305 %type <qtyp> completeTypeSpecifierAux altType typeExpression
306 /*%type <expr> lclintassertion*/
317 : externalDef { context_checkGlobalScope (); }
318 | externalDefs externalDef { context_checkGlobalScope (); }
321 : fcnDef optSemi { uentry_clearDecl (); }
322 | constantDecl { uentry_clearDecl (); }
323 | fcnDecl { uentry_clearDecl (); }
324 | iterDecl { uentry_clearDecl (); }
325 | macroDef { uentry_clearDecl (); }
326 | initializer { uentry_checkDecl (); exprNode_free ($1); }
327 | error { uentry_clearDecl (); }
330 : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
331 { checkConstant ($2, $4); }
332 | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
333 { checkValueConstant ($2, $4, $8) ; }
336 : QFUNCTION { context_enterFunctionHeader (); } plainFcn optSemi QENDMACRO
338 declareStaticFunction ($3); context_quietExitFunction ();
339 context_exitFunctionHeader ();
345 qtype qint = qtype_create (ctype_int);
346 $$ = idDecl_fixBase ($1, qint);
349 | completeTypeSpecifier NotType plainNamedDecl
350 { $$ = idDecl_fixBase ($3, $1); }
354 | pointers plainNamedDeclBase
355 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
358 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
359 | IsType TLPAREN NotType namedDecl IsType TRPAREN
360 { $$ = idDecl_expectFunction ($4); }
361 | namedDeclBase TLSQBR TRSQBR
362 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
363 | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
365 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), exprNode_getLongValue ($4)));
367 | namedDeclBase PushType TLPAREN TRPAREN
368 { setCurrentParams (uentryList_missingParams); }
370 { /* need to support globals and modifies here! */
371 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
372 uentryList_makeMissingParams ());
374 $$ = idDecl_replaceCtype ($1, ct);
375 idDecl_addClauses ($$, $6);
377 /*drl 7/25/01 added*/
378 setImplictfcnConstraints();
380 | namedDeclBase PushType TLPAREN genericParamList TRPAREN
381 { setCurrentParams ($4); }
383 { setImplictfcnConstraints ();
384 clearCurrentParams ();
385 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
386 idDecl_addClauses ($$, $7);
391 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
392 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
393 { $$ = idDecl_expectFunction ($4); }
394 | plainNamedDeclBase TLSQBR TRSQBR
395 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
396 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
400 if (exprNode_hasValue ($4)
401 && multiVal_isInt (exprNode_getValue ($4)))
403 value = (int) multiVal_forceInt (exprNode_getValue ($4));
410 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
412 | plainNamedDeclBase PushType TLPAREN TRPAREN
413 { setCurrentParams (uentryList_missingParams); }
416 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
417 uentryList_makeMissingParams ());
419 $$ = idDecl_replaceCtype ($1, ct);
420 idDecl_addClauses ($$, $6);
423 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
424 { setCurrentParams ($4); }
427 clearCurrentParams ();
428 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
429 idDecl_addClauses ($$, $7);
434 : QITER newId TLPAREN genericParamList TRPAREN
435 { setCurrentParams ($4); } functionClausesPlain
436 { clearCurrentParams (); } optSemi QENDMACRO
437 { declareCIter ($2, $4); }
440 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); }
441 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); }
442 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); }
443 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); }
446 : fcnDefHdrAux { clabstract_declareFunction ($1); }
449 : metaStateSpecifier TASSIGN metaStateExpression
450 { $$ = metaStateConstraint_create ($1, $3); }
453 : BufConstraintSrefExpr { cscanner_expectingMetaStateName (); } TCOLON metaStateName
454 { cscanner_clearExpectingMetaStateName ();
455 $$ = metaStateSpecifier_create ($1, $4); }
456 | CTOK_ELIPSIS { cscanner_expectingMetaStateName (); } TCOLON metaStateName
457 { cscanner_clearExpectingMetaStateName ();
458 $$ = metaStateSpecifier_createElipsis ($4); }
461 : metaStateSpecifier { $$ = metaStateExpression_create ($1); }
462 | metaStateSpecifier TBAR metaStateExpression { $$ = metaStateExpression_createMerge ($1, $3); }
470 : BufConstraint TCAND BufConstraintList { $$ = constraintList_add ($3, $1); }
471 | BufConstraint { $$ = constraintList_single ($1); }
474 : BufConstraintExpr relationalOp BufConstraintExpr {
475 $$ = makeConstraintParse3 ($1, $2, $3);
476 DPRINTF(("Done BufConstraint1\n")); }
489 | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3); DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
490 | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
491 DPRINTF( ("Got BufConstraintExpr BINary Op ") );
492 $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
495 : BufConstraintSrefExpr { $$ = constraintExpr_makeTermsRef ($1);}
496 | CCONSTANT { $$ = constraintExpr_makeIntLiteral (exprNode_getLongValue ($1)); }
498 BufConstraintSrefExpr
500 { /*@-onlytrans@*/ $$ = checkbufferConstraintClausesId ($1); /*@=onlytrans@*/ /*@i523@*/ }
502 { $$ = fixStateClausesId ($1); }
503 | BufConstraintSrefExpr TLSQBR TRSQBR
504 { $$ = sRef_makeAnyArrayFetch ($1); }
505 | BufConstraintSrefExpr TLSQBR CCONSTANT TRSQBR
509 t = cstring_toCharsSafe (exprNode_unparse($3));
512 $$ = sRef_makeArrayFetchKnown ($1, exprNode_getLongValue ($3));
514 | TMULT BufConstraintSrefExpr
515 { $$ = sRef_constructPointer ($2); }
516 | TLPAREN BufConstraintSrefExpr TRPAREN
518 | BufConstraintSrefExpr TDOT newId
519 { cstring_markOwned ($3); $$ = sRef_buildField ($1, $3); }
520 | BufConstraintSrefExpr ARROW_OP newId
521 { cstring_markOwned ($3); $$ = sRef_makeArrow ($1, $3); }
524 | BufConstraintTerm TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
525 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
526 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
527 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
528 $$ = sRef_buildField ($1, $3); }
544 ** Function clauses can appear in any order.
548 : { $$ = functionClauseList_new (); }
549 | functionClause functionClauses
550 { $$ = functionClauseList_prepend ($2, $1); }
553 ** Inside macro definitions, there are no end macros.
558 { $$ = functionClauseList_new (); }
559 | functionClausePlain functionClausesPlain
560 { $$ = functionClauseList_prepend ($2, $1); }
563 : globalsClause { $$ = functionClause_createGlobals ($1); }
564 | modifiesClause { $$ = functionClause_createModifies ($1); }
565 | nomodsClause { $$ = functionClause_createModifies ($1); }
566 | stateClause { $$ = functionClause_createState ($1); }
567 | conditionClause { $$ = $1; }
568 | warnClause { $$ = functionClause_createWarn ($1); }
571 : globalsClausePlain { $$ = functionClause_createGlobals ($1); }
572 | modifiesClausePlain { $$ = functionClause_createModifies ($1); }
573 | nomodsClause { $$ = functionClause_createModifies ($1); }
574 | stateClausePlain { $$ = functionClause_createState ($1); }
575 | conditionClausePlain { $$ = $1; }
576 | warnClausePlain { $$ = functionClause_createWarn ($1); }
579 : globalsClausePlain QENDMACRO { $$ = $1; }
582 : QGLOBALS { setProcessingGlobalsList (); }
585 unsetProcessingGlobals ();
586 $$ = globalsClause_create ($1, $3);
590 : QNOMODS { $$ = modifiesClause_createNoMods ($1); }
593 : modifiesClausePlain QENDMACRO { $$ = $1; }
598 context_setProtectVars (); enterParamsTemp ();
599 sRef_setGlobalScopeSafe ();
604 sRef_clearGlobalScopeSafe ();
605 context_releaseVars ();
606 $$ = modifiesClause_create ($1, $3);
611 { $$ = flagSpec_createPlain ($1); }
612 | flagId TBAR flagSpec
613 { $$ = flagSpec_createOr ($1, $3); }
620 | /* empty */ { $$ = warnClause_undefined; }
623 : warnClausePlain QENDMACRO { $$ = $1; }
626 : QWARN flagSpec cconstantExpr
628 llassert (exprNode_knownStringValue ($3));
629 $$ = warnClause_create ($1, $2, cstring_copy (multiVal_forceString (exprNode_getValue ($3))));
633 { $$ = warnClause_create ($1, $2, cstring_undefined); }
636 : globIdListExpr { $$ = globSet_single ($1); }
637 | globIdList TCOMMA globIdListExpr { $$ = globSet_insert ($1, $3); }
640 : optGlobQuals globId { $$ = clabstract_createGlobal ($2, $1); }
643 : /* empty */ { $$ = qualList_undefined; }
644 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
647 : id { $$ = uentry_getSref ($1); }
648 | NEW_IDENTIFIER { $$ = clabstract_unrecognizedGlobal ($1); }
649 | initializer { $$ = clabstract_checkGlobal ($1); }
652 : QUNDEF { $$ = qual_createUndef (); }
653 | QKILLED { $$ = qual_createKilled (); }
654 | QOUT { $$ = qual_createOut (); }
655 | QIN { $$ = qual_createIn (); }
656 | QPARTIAL { $$ = qual_createPartial (); }
672 qtype qint = qtype_create (ctype_int);
673 $$ = idDecl_fixBase ($1, qint);
676 | completeTypeSpecifier NotType namedDecl
677 { $$ = idDecl_fixBase ($3, $1); }
680 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
683 exprNode_checkFunctionBody ($3); $$ = $3;
684 context_exitInner ($3);
686 | { context_enterOldStyleScope (); } initializerList
687 { oldStyleDoneParams (); context_enterInnerContext (); }
690 exprNode_checkFunctionBody ($4);
691 $$ = $4; /* oldstyle */
692 context_exitInner ($4);
698 context_setFunctionDefined (exprNode_loc ($2));
699 exprNode_checkFunction (context_getHeader (), $2);
702 context_exitFunction ();
706 : modList optSemi { $$ = $1; }
707 | optSemi { $$ = sRefSet_new (); }
710 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
711 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
712 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
713 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
714 | TMULT modListExpr { $$ = modListPointer ($2); }
715 | TLPAREN modListExpr TRPAREN { $$ = $2; }
716 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
717 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
721 : modListExpr { $$ = $1; }
722 | cconstantExpr { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
726 : modListExpr { $$ = sRefSet_single ($1); }
727 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
731 { $$ = checkStateClausesId ($1); }
733 { $$ = fixStateClausesId ($1); }
734 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
735 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
736 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
737 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
738 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
739 $$ = sRef_buildField ($1, $3); }
740 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
741 $$ = sRef_makeArrow ($1, $3); }
744 : /* empty */ { $$ = sRefSet_undefined }
749 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
750 else { $$ = sRefSet_undefined; }
752 | specClauseList TCOMMA specClauseListExpr
753 { if (sRef_isValid ($3))
755 $$ = sRefSet_insert ($1, $3);
764 : id { $$ = exprNode_fromIdentifier ($1); }
765 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
767 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
768 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
769 | QEXTENSION { $$ = exprNode_makeError (); }
773 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
774 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
775 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
776 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
777 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
778 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
779 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
780 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
783 : assignExpr { $$ = exprNodeList_singleton ($1); }
784 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
788 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
789 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
790 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
791 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
792 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
793 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
794 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
795 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
796 | sizeofExpr { $$ = $1; }
797 | offsetofExpr { $$ = $1; }
800 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
801 | newId { $$ = cstringList_single ($1); }
804 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
805 { $$ = exprNode_offsetof ($4, $7); }
808 : IsType { context_setProtectVars (); }
809 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
812 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); }
813 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); }
814 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); }
815 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); }
819 | TLPAREN typeExpression TRPAREN castExpr
820 { $$ = exprNode_cast ($1, $4, $2); }
824 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
825 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
826 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
830 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
831 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
835 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
836 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
840 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
841 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
842 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
843 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
847 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
848 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
852 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
856 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
861 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
866 { exprNode_produceGuards ($1);
867 context_enterAndClause ($1);
871 $$ = exprNode_op ($1, $4, $2);
872 context_exitAndClause ($$, $4);
879 exprNode_produceGuards ($1);
880 context_enterOrClause ($1);
884 $$ = exprNode_op ($1, $4, $2);
885 context_exitOrClause ($$, $4);
890 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
891 { context_enterFalseClause ($1); } conditionalExpr
892 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
896 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
897 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
898 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
899 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
900 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
901 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
902 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
903 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
904 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
905 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
906 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
910 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
913 : /* empty */ { $$ = exprNode_undefined; }
919 /* instance_orTypeDecl_and_possible_initialization */
922 : instanceDecl { $$ = $1; }
923 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
924 | typeDecl { $$ = exprNode_makeError (); }
927 : completeTypeSpecifier IsType TSEMI
928 { $$ = exprNode_makeError (); }
930 ** This causes r/r conflicts with function definitions.
931 ** Instead we need to snarf one first. (gack)
933 ** | completeTypeSpecifier { setProcessingVars ($1); }
935 ** namedInitializerList IsType TSEMI
936 ** { unsetProcessingVars (); }
939 ** the solution is pretty ugly:
941 | completeTypeSpecifier NotType namedDecl NotType
943 setProcessingVars ($1);
944 processNamedDecl ($3);
946 IsType optDeclarators TSEMI IsType
948 unsetProcessingVars ();
949 $$ = exprNode_makeEmptyInitialization ($3);
950 DPRINTF (("Empty initialization: %s", exprNode_unparse ($$)));
952 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
953 { setProcessingVars ($1); processNamedDecl ($3); }
954 IsType init optDeclarators TSEMI IsType
955 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
956 unsetProcessingVars ();
962 processNamedDecl ($1);
963 $$ = exprNode_makeEmptyInitialization ($1);
965 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
966 { $$ = exprNode_makeInitialization ($1, $6); }
969 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
970 NotType namedInitializerList IsType optWarnClause TSEMI
971 { clabstract_declareType ($5, $7); }
972 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
973 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
976 : { g_expectingTypeName = TRUE; }
979 : { g_expectingTypeName = TRUE; context_pushLoc (); }
982 : namedInitializerListAux IsType { $$ = $1; }
984 namedInitializerListAux
985 : namedInitializer { $$ = exprNodeList_singleton ($1); }
986 | namedInitializerList TCOMMA NotType namedInitializer { $$ = exprNodeList_push ($1, $4); }
989 : /* empty */ { $$ = exprNode_makeError (); }
990 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
994 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
995 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1000 { $$ = exprNodeList_singleton ($1); }
1001 | initList TCOMMA init
1002 { $$ = exprNodeList_push ($1, $3); }
1005 ** need to do the storage class global hack so tags are
1006 ** declared with the right storage class.
1010 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1011 | QINLINE { $$ = qual_createInline (); }
1012 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1013 | QAUTO { $$ = qual_createAuto (); }
1014 | QREGISTER { $$ = qual_createRegister (); }
1016 nullterminatedQualifier:
1017 QNULLTERMINATED IsType { $$ = qual_createNullTerminated (); }
1020 : stateClausePlain QENDMACRO { $$ = $1; }
1025 context_setProtectVars ();
1027 sRef_setGlobalScopeSafe ();
1029 specClauseList optSemi IsType
1032 sRef_clearGlobalScopeSafe ();
1033 context_releaseVars ();
1034 $$ = stateClause_createPlain ($1, $4);
1038 : conditionClausePlain QENDMACRO { $$ = $1; }
1040 startConditionClause
1041 : conditionTag NotType { $$ = $1; context_enterFunctionHeader (); }
1043 conditionClausePlain
1044 : startConditionClause stateQualifier
1046 context_exitFunctionHeader ();
1047 context_setProtectVars ();
1049 sRef_setGlobalScopeSafe ();
1051 optSpecClauseList optSemi IsType
1054 sRef_clearGlobalScopeSafe ();
1055 context_releaseVars ();
1056 $$ = functionClause_createState (stateClause_create ($1, $2, $4));
1058 | startConditionClause
1060 context_setProtectVars ();
1062 sRef_setGlobalScopeSafe ();
1064 functionConstraint optSemi IsType
1066 context_exitFunctionHeader ();
1068 sRef_clearGlobalScopeSafe ();
1069 context_releaseVars ();
1070 DPRINTF (("done optGlobBufConstraintsAux\n"));
1072 if (lltok_isEnsures ($1))
1074 $$ = functionClause_createEnsures ($3);
1076 else if (lltok_isRequires ($1))
1078 $$ = functionClause_createRequires ($3);
1085 DPRINTF (("FunctionclauseS: %s", functionClause_unparse ($$)));
1089 : BufConstraintList { $$ = functionConstraint_createBufferConstraint ($1); }
1090 | metaStateConstraint { $$ = functionConstraint_createMetaStateConstraint ($1); DPRINTF (("Made constraint: %s", functionConstraint_unparse ($$))); }
1093 : QEXITS { $$ = qual_createExits (); }
1094 | QMAYEXIT { $$ = qual_createMayExit (); }
1095 | QTRUEEXIT { $$ = qual_createTrueExit (); }
1096 | QFALSEEXIT { $$ = qual_createFalseExit (); }
1097 | QNEVEREXIT { $$ = qual_createNeverExit (); }
1100 : QCHECKED { $$ = qual_createChecked (); }
1101 | QCHECKMOD { $$ = qual_createCheckMod (); }
1102 | QUNCHECKED { $$ = qual_createUnchecked (); }
1103 | QCHECKEDSTRICT { $$ = qual_createCheckedStrict (); }
1106 : QOWNED { $$ = qual_createOwned (); }
1107 | QDEPENDENT { $$ = qual_createDependent (); }
1108 | QYIELD { $$ = qual_createYield (); }
1109 | QTEMP { $$ = qual_createTemp (); }
1110 | QONLY { $$ = qual_createOnly (); }
1111 | QKEEP { $$ = qual_createKeep (); }
1112 | QKEPT { $$ = qual_createKept (); }
1113 | QSHARED { $$ = qual_createShared (); }
1114 | QUNIQUE { $$ = qual_createUnique (); }
1115 | QNULL { $$ = qual_createNull (); }
1116 | QISNULL { $$ = qual_createIsNull (); }
1117 | QRELNULL { $$ = qual_createRelNull (); }
1118 | QNOTNULL { $$ = qual_createNotNull (); }
1119 | QEXPOSED { $$ = qual_createExposed (); }
1120 | QOBSERVER { $$ = qual_createObserver (); }
1121 | QNULLTERMINATED { $$ = qual_createNullTerminated (); }
1122 | CANNOTATION { $$ = qual_createMetaState ($1); }
1126 : QRETURNED { $$ = qual_createReturned (); }
1127 | QSEF { $$ = qual_createSef (); }
1130 : QUNUSED { $$ = qual_createUnused (); }
1131 | QEXTERNAL { $$ = qual_createExternal (); }
1134 : QTRUENULL { $$ = qual_createTrueNull (); }
1135 | QFALSENULL { $$ = qual_createFalseNull (); }
1138 : QABSTRACT { $$ = qual_createAbstract (); }
1139 | QCONCRETE { $$ = qual_createConcrete (); }
1140 | QMUTABLE { $$ = qual_createMutable (); }
1141 | QIMMUTABLE { $$ = qual_createImmutable (); }
1144 : QREFCOUNTED { $$ = qual_createRefCounted (); }
1145 | QREFS { $$ = qual_createRefs (); }
1146 | QKILLREF { $$ = qual_createKillRef (); }
1147 | QRELDEF { $$ = qual_createRelDef (); }
1148 | QNEWREF { $$ = qual_createNewRef (); }
1149 | QTEMPREF { $$ = qual_createTempRef (); }
1152 : QSHORT { $$ = qual_createShort (); }
1153 | QLONG { $$ = qual_createLong (); }
1154 | QSIGNED { $$ = qual_createSigned (); }
1155 | QUNSIGNED { $$ = qual_createUnsigned (); }
1158 : QOUT { $$ = qual_createOut (); }
1159 | QIN { $$ = qual_createIn (); }
1160 | QPARTIAL { $$ = qual_createPartial (); }
1161 | QSPECIAL { $$ = qual_createSpecial (); }
1164 : QCONST IsType { $$ = qual_createConst (); }
1165 | QVOLATILE IsType { $$ = qual_createVolatile (); }
1166 | definedQualifier IsType { $$ = $1; }
1167 | stateQualifier IsType { $$ = $1; }
1168 | exitsQualifier IsType { $$ = $1; }
1169 | paramQualifier IsType { $$ = $1; }
1170 | checkQualifier IsType { $$ = $1; }
1171 | returnQualifier IsType { $$ = $1; }
1172 | visibilityQualifier IsType { $$ = $1; }
1173 | typedefQualifier IsType { $$ = $1; }
1174 | refcountQualifier IsType { $$ = $1; }
1177 ** This is copied into the mtgrammar!
1187 | QANYTYPE NotType { $$ = ctype_unknown; }
1188 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
1189 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1190 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
1194 | typeModifier NotType { $$ = ctype_fromQual ($1); }
1197 : IsType completeTypeSpecifier IsType
1198 { $$ = qtype_resolve ($2); }
1200 completeTypeSpecifier
1201 : completeTypeSpecifierAux { $$ = $1; }
1202 | completeTypeSpecifierAux QALT altType QENDMACRO
1203 { $$ = qtype_mergeAlt ($1, $3); }
1207 | typeExpression TCOMMA altType
1208 { $$ = qtype_mergeAlt ($1, $3); }
1210 completeTypeSpecifierAux
1211 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1212 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1213 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
1216 : /* empty */ { $$ = qtype_unknown (); }
1217 | completeTypeSpecifier { $$ = $1; }
1220 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1221 CreateStructInnerScope
1222 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1224 { $$ = declareStruct ($3, $8); }
1225 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1226 CreateStructInnerScope
1227 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1229 { $$ = declareUnion ($3, $8); }
1230 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
1231 { $$ = declareStruct ($3, uentryList_new ()); }
1232 | NotType CUNION newId IsType TLBRACE TRBRACE
1233 { $$ = declareUnion ($3, uentryList_new ()); }
1234 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1235 CreateStructInnerScope
1236 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1238 { $$ = declareUnnamedStruct ($7); }
1239 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1240 CreateStructInnerScope structDeclList DeleteStructInnerScope
1241 { sRef_clearGlobalScopeSafe (); }
1243 { $$ = declareUnnamedUnion ($7); }
1244 | NotType CSTRUCT IsType TLBRACE TRBRACE
1245 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
1246 | NotType CUNION IsType TLBRACE TRBRACE
1247 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
1248 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
1249 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
1252 : { g_expectingTypeName = FALSE; }
1256 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1257 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1260 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
1261 { $$ = fixUentryList ($3, $1); }
1262 | completeTypeSpecifier IsType TSEMI
1263 { $$ = fixUnnamedDecl ($1); }
1266 : structNamedDecl NotType
1267 { $$ = idDeclList_singleton ($1); }
1268 | structNamedDeclList TCOMMA structNamedDecl NotType
1269 { $$ = idDeclList_add ($1, $3); }
1271 structNamedDecl /* hack to get around namespace problems */
1272 : namedDecl { $$ = $1; }
1273 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1274 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1275 /* Need the IsType in case there is a cast in the constant expression. */
1278 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1279 { $$ = declareUnnamedEnum ($4); }
1280 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1281 { context_popLoc (); $$ = declareEnum ($3, $6); }
1282 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1286 { $$ = enumNameList_single ($1); }
1287 | enumeratorList TCOMMA enumerator
1288 { $$ = enumNameList_push ($1, $3); }
1289 | enumeratorList TCOMMA
1293 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1294 usymtab_supGlobalEntry (ue);
1297 | newId TASSIGN IsType constantExpr
1298 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1299 usymtab_supGlobalEntry (ue);
1305 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1306 | pointers TYPE_NAME
1308 qtype qt = qtype_unknown ();
1310 qtype_adjustPointers ($1, qt);
1311 $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1313 | pointers optNamedDecl
1314 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1318 | pointers namedDeclBase
1319 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1322 : paramTypeList { $$ = handleParamTypeList ($1); }
1323 | NotType paramIdList { $$ = handleParamIdList ($2); }
1326 : QCONST { /* ignored for now */; }
1331 | innerModsList innerMods { ; }
1335 | TMULT innerModsList { $$ = 1; }
1336 | TMULT pointers { $$ = 1 + $2; }
1337 | TMULT innerModsList pointers { $$ = 1 + $3; }
1341 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1344 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1345 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1348 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1350 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1353 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1354 | paramList TCOMMA { storeLoc (); } paramDecl
1355 { $$ = uentryList_add ($1, $4); }
1358 : IsType completeTypeSpecifier optNamedDecl IsType
1360 if (isFlipOldStyle ())
1362 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1368 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1370 | newId /* its an old-style declaration */
1372 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1376 llparseerror (message ("Inconsistent function parameter syntax: %q",
1377 idDecl_unparse (tparam)));
1381 $$ = makeCurrentParam (tparam);
1382 idDecl_free (tparam);
1387 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1390 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1392 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1395 : /* empty */ { $$ = ctype_unknown; }
1399 : IsType TLPAREN NotType abstractDecl TRPAREN
1400 { $$ = ctype_expectFunction ($4); }
1401 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1402 | TLSQBR constantExpr TRSQBR
1403 { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
1404 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1405 | abstractDeclBase TLSQBR constantExpr TRSQBR
1406 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
1407 | IsType TLPAREN TRPAREN
1408 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1409 | IsType TLPAREN paramTypeList TRPAREN
1410 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1411 | abstractDeclBase IsType TLPAREN TRPAREN
1412 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1413 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1414 { $$ = ctype_makeParamsFunction ($1, $4); }
1428 /* | lclintassertion {$$ = $1; printf ("Doing stmt lclintassertion\n"); }*/
1432 : QSETBUFFERSIZE id CCONSTANT QENDMACRO { printf(" QSETBUFFERSIZE id CCONSTANT HEllo World\n"); uentry_setBufferSize($2, $3); $$ = exprNode_createTok ($4);
1434 | QSETSTRINGLENGTH id CCONSTANT QENDMACRO { printf(" QSETSTRINGLENGTH id CCONSTANT HEllo World\n"); uentry_setStringLength($2, $3); $$ = exprNode_createTok ($4);
1436 | QTESTINRANGE id CCONSTANT QENDMACRO {printf(" QTESTINRANGE\n"); uentry_testInRange($2, $3); $$ = exprNode_createTok ($4);
1439 /* | QSETBUFFERSIZE id id {$$ = $2; printf(" QSETBUFFERSIZE id id HEllo World\n");} */
1442 : iterDefStmtList { $$ = $1; }
1449 | iterDefStmtList iterDefStmt
1450 { $$ = exprNode_concat ($1, $2); }
1452 iterDefIterationStmt
1453 : iterWhilePred iterDefStmtList
1454 { $$ = exprNode_while ($1, $2); }
1455 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1456 { $$ = exprNode_doWhile ($2, $5); }
1457 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1458 { $$ = exprNode_doWhile ($2, $5); }
1459 | forPred iterDefStmt
1460 { $$ = exprNode_for ($1, $2); }
1463 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1464 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1466 { $$ = exprNode_forPred ($3, $5, $8);
1467 context_enterForClause ($5); }
1470 : ITER_NAME CreateInnerScope TLPAREN
1471 { setProcessingIterVars ($1); }
1473 { $$ = exprNode_iterStart ($1, $5); }
1474 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1480 | openScope initializerList { $$ = $1; DPRINTF (("def stmt: %s", exprNode_unparse ($$))); }
1485 | iterDefIterationStmt
1488 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1489 | error { $$ = exprNode_makeError (); }
1492 : ifPred iterDefStmt
1493 { /* don't: context_exitTrueClause ($1, $2); */
1494 $$ = exprNode_if ($1, $2);
1498 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1501 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1516 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1518 | error { $$ = exprNode_makeError (); }
1521 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1522 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
1524 /* Note that we can semantically check that the object to the case is
1525 indeed constant. In this case, we may not want to go through this effort */
1528 : CASE constantExpr { context_enterCaseClause ($2); }
1529 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
1530 | QFALLTHROUGH CASE constantExpr { context_enterCaseClause ($3); }
1531 TCOLON { $$ = exprNode_caseMarker ($3, TRUE); }
1534 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1535 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1536 | QFALLTHROUGH DEFAULT { context_enterCaseClause (exprNode_undefined); }
1537 TCOLON { $$ = exprNode_defaultMarker ($2, TRUE); }
1540 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1541 | CreateInnerScope compoundStmtAux
1542 { $$ = $2; context_exitInner ($2); }
1545 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1548 : { context_enterInnerContext (); }
1551 : { context_exitInnerPlain (); }
1553 CreateStructInnerScope
1554 : { context_enterStructInnerContext (); }
1556 DeleteStructInnerScope
1557 : { context_exitStructInnerContext (); }
1559 DeleteInnerScopeSafe
1560 : { context_exitInnerSafe (); }
1563 : TRBRACE { $$ = exprNode_createTok ($1); }
1564 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1565 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1566 | stmtList QNOTREACHED TRBRACE
1567 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1568 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1569 | initializerList QNOTREACHED TRBRACE
1570 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1571 | initializerList stmtList TRBRACE
1572 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1573 | initializerList stmtList QNOTREACHED TRBRACE
1574 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1575 lltok_getLoc ($3)));
1579 : TLBRACE compoundStmtRest
1580 { $$ = exprNode_makeBlock ($2); }
1584 { $$ = exprNode_createTok ($2); }
1585 | TLBRACE stmtListErr TRBRACE
1586 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1587 | TLBRACE initializerList TRBRACE
1588 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1589 | TLBRACE initializerList stmtList TRBRACE
1590 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1594 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1597 : initializer { $$ = $1; }
1598 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1602 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1605 : TSEMI { $$ = exprNode_createTok ($1); }
1606 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1609 : TSEMI { $$ = exprNode_createTok ($1); }
1610 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1611 | expr { $$ = exprNode_checkExpr ($1); }
1614 : CIF TLPAREN expr TRPAREN
1615 { $$ = $3; exprNode_produceGuards ($3); context_enterTrueClause ($3); }
1617 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1618 ** { $$ = $3; context_enterTrueClause (); }
1624 context_exitTrueClause ($1, $2);
1625 $$ = exprNode_if ($1, $2);
1627 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
1629 context_exitClause ($1, $2, $5);
1630 $$ = exprNode_ifelse ($1, $2, $5);
1632 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1633 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1636 : WHILE TLPAREN expr TRPAREN
1637 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1638 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1641 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1644 : ITER_NAME { context_enterIterClause (); }
1645 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1647 compoundStmt endIter DeleteInnerScope
1649 $$ = exprNode_iter ($1, $6, $8, $9);
1654 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1655 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1656 { $$ = exprNodeList_push ($1, $4); }
1659 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1660 | id { $$ = exprNode_iterId ($1); }
1661 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1663 if (uentry_isValid (ue))
1665 $$ = exprNode_iterId (ue);
1669 $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1672 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1675 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1680 | cconstantExpr CCONSTANT { $$ = exprNode_combineLiterals ($1, $2); }
1684 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1688 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1689 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1690 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1691 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1692 { $$ = exprNode_vaArg ($1, $3, $5); }
1693 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
1694 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
1695 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1696 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1700 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1701 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1702 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1703 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1704 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1705 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1706 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1707 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1708 | sizeofExpr { $$ = $1; }
1712 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1716 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1717 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1718 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1722 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1723 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1727 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1728 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1732 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1733 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1734 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1735 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1738 : relationalIterExpr
1739 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1740 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1744 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1748 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1753 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1757 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1761 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1765 | orExpr TQUEST { context_enterTrueClause ($1); }
1766 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1767 { $$ = exprNode_cond ($1, $4, $7); }
1770 : conditionalIterExpr
1771 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1772 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1773 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1774 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1775 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1776 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1777 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1778 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1779 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1780 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1781 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1784 : ITER_ENDNAME { $$ = $1; }
1785 | /* empty */ { $$ = uentry_undefined; }
1788 : DO { context_enterDoWhileClause (); $$ = $1; }
1792 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1793 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
1794 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1796 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1799 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1800 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1801 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1802 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1803 { $$ = exprNode_doWhile ($2, $5); }
1804 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1807 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1808 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1809 | QINNERCONTINUE CONTINUE TSEMI
1810 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1811 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1812 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1813 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1814 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1815 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1816 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1817 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1828 | ITER_NAME { $$ = uentry_getName ($1); }
1829 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1830 | id { $$ = uentry_getName ($1); }
1831 | TYPE_NAME_OR_ID { $$ = $1; }
1835 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1839 /*@-redecl@*/ /*@-namechecks@*/
1840 extern char *yytext;
1841 /*@=redecl@*/ /*@=namechecks@*/
1843 # include "bison.reset"
1845 void yyerror (/*@unused@*/ char *s)
1847 static bool givehint = FALSE;
1849 if (context_inIterDef ())
1851 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1852 context_inFunctionName ()));
1854 else if (context_inIterEnd ())
1856 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1857 context_inFunctionName ()));
1859 else if (context_inMacro ())
1861 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1862 context_inFunctionName ()));
1864 if (context_inUnknownMacro ())
1868 llhint (cstring_makeLiteral
1869 ("Precede macro definition with /*@notfunction@*/ "
1870 "to suppress checking and force expansion"));
1876 context_exitAllClausesQuiet ();
1880 llparseerror (cstring_undefined);