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);
47 # include "lclintMacros.nf"
49 # include "cgrammar.h"
50 # include "exprChecks.h"
55 # define SHOWCSYM FALSE
56 void yyerror (char *s);
59 ** This is necessary, or else when the bison-generated code #include's malloc.h,
60 ** there will be a parse error.
62 ** Unfortunately, it means the error checking on malloc, etc. is lost for allocations
63 ** in bison-generated files under Win32.
72 void checkandsetBufState(idDecl id, exprNode is);
79 specialClauseKind sck;
84 /*@only@*/ qtype qtyp;
85 /*@only@*/ cstring cname;
86 /*@only@*/ idDecl ntyp;
87 /*@only@*/ idDeclList ntyplist;
88 /*@only@*/ uentryList flist;
89 /*@owned@*/ uentryList entrylist;
90 /*@observer@*/ /*@dependent@*/ uentry entry;
91 /*@only@*/ uentry oentry;
92 /*@only@*/ exprNode expr;
93 /*@only@*/ enumNameList enumnamelist;
94 /*@only@*/ exprNodeList alist;
95 /*@only@*/ sRefSet srset;
96 /*@only@*/ cstringList cstringlist;
106 /* standard C tokens */
108 %token <tok> BADTOK SKIPTOK
109 %token <tok> CTOK_ELIPSIS CASE DEFAULT CIF CELSE SWITCH WHILE DO CFOR
110 %token <tok> GOTO CONTINUE BREAK RETURN
111 %token <tok> TSEMI TLBRACE TRBRACE TCOMMA TCOLON TASSIGN TLPAREN
112 %token <tok> TRPAREN TLSQBR TRSQBR TDOT TAMPERSAND TEXCL TTILDE
113 %token <tok> TMINUS TPLUS TMULT TDIV TPERCENT TLT TGT TCIRC TBAR TQUEST
114 %token <tok> CSIZEOF CALIGNOF ARROW_OP CTYPEDEF COFFSETOF
115 %token <tok> INC_OP DEC_OP LEFT_OP RIGHT_OP
116 %token <tok> LE_OP GE_OP EQ_OP NE_OP AND_OP OR_OP
117 %token <tok> MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN SUB_ASSIGN
118 %token <tok> LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
119 %token <tok> CSTRUCT CUNION CENUM
120 %token <tok> VA_ARG VA_DCL
121 %token <tok> QGLOBALS
122 %token <tok> QMODIFIES
124 %token <tok> QCONSTANT
125 %token <tok> QFUNCTION
127 %token <tok> QDEFINES
129 %token <tok> QALLOCATES
131 %token <tok> QRELEASES
132 %token <tok> QPRECLAUSE
133 %token <tok> QPOSTCLAUSE
135 %token <tok> QUNDEF QKILLED
136 %token <tok> QENDMACRO
138 /* additional tokens introduced by lclint pre-processor. */
139 %token <tok> LLMACRO LLMACROITER LLMACROEND TENDMACRO
141 /* break comments: */
142 %token <tok> QSWITCHBREAK QLOOPBREAK QINNERBREAK QSAFEBREAK
143 %token <tok> QINNERCONTINUE
145 /* case fall-through marker: */
146 %token <tok> QFALLTHROUGH
148 /* used in scanner only */
149 %token <tok> QLINTNOTREACHED
150 %token <tok> QLINTFALLTHROUGH
151 %token <tok> QLINTFALLTHRU
152 %token <tok> QARGSUSED
153 %token <tok> QPRINTFLIKE QLINTPRINTFLIKE QSCANFLIKE QMESSAGELIKE
155 /* not-reached marker: (used like a label) */
156 %token <tok> QNOTREACHED
158 /* type qualifiers: */
159 %token <tok> QCONST QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
160 %token <tok> QOUT QIN QYIELD QONLY QTEMP QSHARED QREF QUNIQUE
161 %token <tok> QCHECKED QUNCHECKED QCHECKEDSTRICT QCHECKMOD
162 %token <tok> QKEEP QKEPT QPARTIAL QSPECIAL QOWNED QDEPENDENT
163 %token <tok> QRETURNED QEXPOSED QNULL QOBSERVER QISNULL
164 %token <tok> QEXITS QMAYEXIT QNEVEREXIT QTRUEEXIT QFALSEEXIT
165 %token <tok> QLONG QSIGNED QUNSIGNED QSHORT QUNUSED QSEF QNOTNULL QRELNULL
166 %token <tok> QABSTRACT QCONCRETE QMUTABLE QIMMUTABLE
167 %token <tok> QTRUENULL QFALSENULL QEXTERNAL
168 %token <tok> QREFCOUNTED QREFS QNEWREF QTEMPREF QKILLREF QRELDEF
169 %token <ctyp> CGCHAR CBOOL CINT CGFLOAT CDOUBLE CVOID
170 %token <tok> QANYTYPE QINTEGRALTYPE QUNSIGNEDINTEGRALTYPE QSIGNEDINTEGRALTYPE
172 %token <tok> QNULLTERMINATED
173 %token <tok> QSETBUFFERSIZE
174 %token <tok> QBUFFERCONSTRAINT
175 %token <tok> QENSURESCONSTRAINT
176 %token <tok> QSETSTRINGLENGTH
178 %token <tok> QMAXREAD
179 %token <tok> QTESTINRANGE
183 /* identifiers, literals */
184 %token <entry> IDENTIFIER
185 %token <cname> NEW_IDENTIFIER TYPE_NAME_OR_ID
186 %token <expr> CCONSTANT
187 %token <entry> ITER_NAME ITER_ENDNAME
188 %type <entry> endIter
190 %token <ctyp> TYPE_NAME
191 %type <cname> enumerator newId /*@-varuse@*/ /* yacc declares yytranslate here */
192 %type <count> pointers /*@=varuse@*/
194 %type <tok> doHeader specialTag endSpecialTag stateSpecialClause endStateTag
195 %type <sck> specialClauseType
197 /* type construction */
198 %type <ctyp> abstractDecl abstractDeclBase optAbstractDeclBase
199 %type <ctyp> suSpc enumSpc typeName typeSpecifier
201 %type <ntyp> namedDecl namedDeclBase optNamedDecl
202 %type <ntyp> plainNamedDecl plainNamedDeclBase
203 %type <ntyp> structNamedDecl
204 %type <ntyp> fcnDefHdrAux plainFcn
206 %type <oentry> paramDecl
209 %type <ntyplist> structNamedDeclList
211 %type <entrylist> genericParamList paramTypeList paramList idList paramIdList
212 %type <alist> argumentExprList iterArgList
213 %type <alist> initList
214 %type <flist> structDeclList structDecl
215 %type <srset> locModifies locPlainModifies modList specClauseList
216 %type <sr> mExpr modListExpr specClauseListExpr
219 %type <con> BufConstraint
220 %type <tok> relationalOp
221 %type <tok> BufBinaryOp
222 %type <tok> bufferModifier
224 %type <conE> BufConstraintExpr
226 %type <conE> BufConstraintTerm
227 %type <sr> BufConstraintSrefExpr
229 %type <conL> BufConstraintList
231 %type <tok> BufUnaryOp
233 %type <enumnamelist> enumeratorList
234 %type <cstringlist> fieldDesignator
236 %type <expr> sizeofExpr sizeofExprAux offsetofExpr
237 %type <expr> openScope closeScope
238 %type <expr> instanceDecl namedInitializer optDeclarators
239 %type <expr> primaryExpr postfixExpr primaryIterExpr postfixIterExpr
240 %type <expr> unaryExpr castExpr timesExpr plusExpr
241 %type <expr> unaryIterExpr castIterExpr timesIterExpr plusIterExpr
242 %type <expr> shiftExpr relationalExpr equalityExpr bitandExpr
243 %type <expr> xorExpr bitorExpr andExpr
244 %type <expr> orExpr conditionalExpr assignExpr
245 %type <expr> shiftIterExpr relationalIterExpr equalityIterExpr bitandIterExpr
246 %type <expr> xorIterExpr bitorIterExpr andIterExpr
247 %type <expr> orIterExpr conditionalIterExpr assignIterExpr iterArgExpr
248 %type <expr> expr optExpr constantExpr
249 %type <expr> init macroBody iterBody endBody partialIterStmt iterSelectionStmt
250 %type <expr> stmt stmtList fcnBody iterStmt iterDefStmt iterDefStmtList
251 %type <expr> labeledStmt caseStmt defaultStmt
252 %type <expr> compoundStmt compoundStmtAux compoundStmtRest compoundStmtAuxErr
253 %type <expr> expressionStmt selectionStmt iterationStmt jumpStmt iterDefIterationStmt
254 %type <expr> stmtErr stmtListErr compoundStmtErr expressionStmtErr
255 %type <expr> iterationStmtErr initializerList initializer ifPred whilePred forPred iterWhilePred
258 %type <typequal> storageSpecifier typeQualifier typeModifier globQual
259 %type <tquallist> optGlobQuals
260 %type <qtyp> completeType completeTypeSpecifier optCompleteType
261 %type <qtyp> completeTypeSpecifierAux altType typeExpression
262 %type <expr> lclintassertion
274 | externalDefs externalDef
277 : fcnDef optSemi { uentry_clearDecl (); }
278 | constantDecl { uentry_clearDecl (); }
279 | fcnDecl { uentry_clearDecl (); }
280 | iterDecl { uentry_clearDecl (); }
281 | macroDef { uentry_clearDecl (); }
282 | initializer { uentry_checkDecl (); exprNode_free ($1); }
283 | error { uentry_clearDecl (); }
286 : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
287 { checkConstant ($2, $4); }
288 | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
289 { checkValueConstant ($2, $4, $8) ; }
292 : QFUNCTION { context_enterFunctionDecl (); } plainFcn optSemi QENDMACRO
293 { declareStaticFunction ($3); context_quietExitFunction ();
294 context_exitFunctionDecl (); }
299 qtype qint = qtype_create (ctype_int);
300 $$ = idDecl_fixBase ($1, qint);
303 | completeTypeSpecifier NotType plainNamedDecl
304 { $$ = idDecl_fixBase ($3, $1); }
308 | pointers plainNamedDeclBase
309 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
312 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
313 | IsType TLPAREN NotType namedDecl IsType TRPAREN
314 { $$ = idDecl_expectFunction ($4); }
315 | namedDeclBase TLSQBR TRSQBR
316 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
317 | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
319 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), exprNode_getLongValue ($4)));
321 | namedDeclBase PushType TLPAREN TRPAREN
322 { setCurrentParams (uentryList_missingParams);
324 optGlobMods optGlobBufConstraints
325 { /* need to support globals and modifies here! */
326 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
327 uentryList_makeMissingParams ());
329 $$ = idDecl_replaceCtype ($1, ct);
332 | namedDeclBase PushType TLPAREN genericParamList TRPAREN
333 { setCurrentParams ($4);
335 optGlobMods optGlobBufConstraints
336 { clearCurrentParams ();
337 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
340 // printf("Done nameDeclBase\n");
344 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
345 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
346 { $$ = idDecl_expectFunction ($4); }
347 | plainNamedDeclBase TLSQBR TRSQBR
348 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
349 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
353 if (exprNode_hasValue ($4)
354 && multiVal_isInt (exprNode_getValue ($4)))
356 value = (int) multiVal_forceInt (exprNode_getValue ($4));
363 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
365 | plainNamedDeclBase PushType TLPAREN TRPAREN
366 { setCurrentParams (uentryList_missingParams);
369 { /* need to support globals and modifies here! */
370 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
371 uentryList_makeMissingParams ());
373 $$ = idDecl_replaceCtype ($1, ct);
376 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
377 { setCurrentParams ($4);
380 { clearCurrentParams ();
381 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
386 : QITER newId TLPAREN genericParamList TRPAREN
387 { setCurrentParams ($4); } optPlainGlobMods
388 { clearCurrentParams (); } optSemi QENDMACRO
389 { declareCIter ($2, $4); }
392 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); }
393 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); }
394 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); }
395 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); }
398 : fcnDefHdrAux { declareFunction ($1); }
401 : { setProcessingGlobMods (); } optGlobModsRest
402 { clearProcessingGlobMods (); }
407 optGlobBufConstraints
408 : { setProcessingGlobMods (); } optGlobBufConstraintsRest
409 { clearProcessingGlobMods (); }
412 optGlobBufConstraintsRest
413 : optGlobBufConstraintsAux optGlobEnsuresConstraintsAux
416 optGlobEnsuresConstraintsAux
418 DPRINTF ( ("doing optGlobEnsuresConstraintsAux\n") );
419 context_setProtectVars (); enterParamsTemp ();
420 sRef_setGlobalScopeSafe ();
422 } QENSURESCONSTRAINT BufConstraintList QENDMACRO
424 setEnsuresConstraints ($3);
426 sRef_clearGlobalScopeSafe ();
427 context_releaseVars ();
428 DPRINTF (("done optGlobBufConstraintsAux\n"));}
432 optGlobBufConstraintsAux
434 DPRINTF ( ("doing optGlobBufConstraintsAux\n") );
435 context_setProtectVars (); enterParamsTemp ();
436 sRef_setGlobalScopeSafe ();
438 } QBUFFERCONSTRAINT BufConstraintList QENDMACRO
440 setFunctionConstraints ($3);
442 sRef_clearGlobalScopeSafe ();
443 context_releaseVars ();
444 DPRINTF (("done optGlobBufConstraintsAux\n"));}
448 : BufConstraint BufConstraintList{ $$ = constraintList_add ($2, $1); }
449 | BufConstraint {constraintList c; c = constraintList_new(); c = constraintList_add (c, $1); $$ = c}
452 : BufConstraintExpr relationalOp BufConstraintExpr TSEMI {
453 $$ = makeConstraintParse3 ($1, $2, $3);
454 DPRINTF(("Done BufConstraint1\n")); }
467 | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3); DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
468 | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
469 DPRINTF( ("Got BufConstraintExpr BINary Op ") );
470 $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
473 : BufConstraintSrefExpr { $$ = constraintExpr_makeTermsRef($1);}
474 | CCONSTANT { char *t; int c;
475 t = cstring_toCharsSafe (exprNode_unparse($1));
477 $$ = constraintExpr_makeIntLiteral (c);
481 BufConstraintSrefExpr
484 checkbufferConstraintClausesId ($1);}
485 | NEW_IDENTIFIER { $$ = fixSpecClausesId ($1); }
487 | BufConstraintSrefExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
488 | BufConstraintSrefExpr TLSQBR CCONSTANT TRSQBR {
490 t = cstring_toCharsSafe (exprNode_unparse($3));
492 $$ = sRef_makeArrayFetchKnown($1, c); }
493 | TMULT BufConstraintSrefExpr { $$ = sRef_constructPointer ($2); }
494 | TLPAREN BufConstraintSrefExpr TRPAREN { $$ = $2; }
495 | BufConstraintSrefExpr TDOT newId { cstring_markOwned ($3);
496 $$ = sRef_buildField ($1, $3); }
497 | BufConstraintSrefExpr ARROW_OP newId { cstring_markOwned ($3);
498 $$ = sRef_makeArrow ($1, $3); }
501 | BufConstraintTerm TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
502 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
503 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
504 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
505 $$ = sRef_buildField ($1, $3); }
523 : { setProcessingGlobMods (); } optPlainGlobModsRest
524 { clearProcessingGlobMods (); }
527 /*: id { $$ = unentry_getSref($1); checkModifiesId ($1); }
528 | NEW_INDENTIFIER { $$ = fixModifiesId ($1)} */
534 : { setProcessingGlobMods (); } optPlainGlobModsRest
535 { clearProcessingGlobMods (); }
539 | specialClauses optGlobModsAux
542 : optPlainGlobModsAux
543 | specialClauses optPlainGlobModsAux
547 | specialClause specialClauses
550 : globIdListExpr { ; }
551 | globIdList TCOMMA globIdListExpr { ; }
554 : optGlobQuals globId { globListAdd ($2, $1); }
557 : id { $$ = uentry_getSref ($1); }
558 | NEW_IDENTIFIER { $$ = globListUnrecognized ($1); }
561 : QUNDEF { $$ = qual_createUndef (); }
562 | QKILLED { $$ = qual_createKilled (); }
563 | QOUT { $$ = qual_createOut (); }
564 | QIN { $$ = qual_createIn (); }
565 | QPARTIAL { $$ = qual_createPartial (); }
568 : /* empty */ { $$ = qualList_undefined; }
569 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
572 : QGLOBALS { setProcessingGlobalsList (); } initializerList optSemi
574 { unsetProcessingGlobals (); }
575 | QGLOBALS { setProcessingGlobalsList (); } globIdList optSemi
577 { unsetProcessingGlobals (); }
579 { setFunctionNoGlobals ();
580 setFunctionModifies (sRefSet_single (sRef_makeNothing ()));
586 : QGLOBALS { setProcessingGlobalsList (); } initializerList optSemi
588 { unsetProcessingGlobals (); }
589 | QGLOBALS { setProcessingGlobalsList (); } globIdList optSemi
591 { unsetProcessingGlobals (); }
593 { setFunctionNoGlobals ();
594 setFunctionModifies (sRefSet_single (sRef_makeNothing ()));
606 context_setProtectVars (); enterParamsTemp ();
607 sRef_setGlobalScopeSafe ();
611 setFunctionModifies ($3); exitParamsTemp ();
612 sRef_clearGlobalScopeSafe ();
613 context_releaseVars ();
619 context_setProtectVars (); enterParamsTemp ();
620 sRef_setGlobalScopeSafe ();
624 setFunctionModifies ($3); exitParamsTemp ();
625 sRef_clearGlobalScopeSafe ();
626 context_releaseVars ();
647 : QONLY { $$ = SP_ISONLY; }
648 | QOBSERVER { $$ = SP_ISOBSERVER; }
649 | QEXPOSED { $$ = SP_ISEXPOSED; }
650 | QDEPENDENT { $$ = SP_ISDEPENDENT; }
651 | QOWNED { $$ = SP_ISOWNED; }
652 | QSHARED { $$ = SP_ISSHARED; }
653 | QISNULL { $$ = SP_ISNULL; }
654 | QNOTNULL { $$ = SP_ISNOTNULL; }
659 context_setProtectVars ();
661 sRef_setGlobalScopeSafe ();
663 specClauseList optSemi endSpecialTag IsType
665 setFunctionSpecialClause ($1, $4, $6);
667 sRef_clearGlobalScopeSafe ();
668 context_releaseVars ();
670 | stateSpecialClause NotType specialClauseType
672 context_setProtectVars ();
674 sRef_setGlobalScopeSafe ();
676 specClauseList optSemi endStateTag IsType
678 setFunctionStateSpecialClause ($1, $3, $5, $7);
680 sRef_clearGlobalScopeSafe ();
681 context_releaseVars ();
687 qtype qint = qtype_create (ctype_int);
688 $$ = idDecl_fixBase ($1, qint);
691 | completeTypeSpecifier NotType namedDecl
692 { $$ = idDecl_fixBase ($3, $1); }
695 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
698 exprNode_checkFunctionBody ($3); $$ = $3;
699 context_exitInner ($3);
702 { doneParams (); context_enterInnerContext (); }
705 context_exitInner ($3);
706 exprNode_checkFunctionBody ($3);
707 $$ = $3; /* old style */
713 context_setFunctionDefined (exprNode_loc ($2));
714 /* exprNode_checkFunction (context_getHeader (), $2); */
717 context_exitFunction ();
721 : modList optSemi QENDMACRO { $$ = $1; }
722 | optSemi QENDMACRO { $$ = sRefSet_new (); }
725 : modList optSemi { $$ = $1; }
726 | optSemi { $$ = sRefSet_new (); }
729 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
730 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
731 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
732 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
733 | TMULT modListExpr { $$ = modListPointer ($2); }
734 | TLPAREN modListExpr TRPAREN { $$ = $2; }
735 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
736 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
740 : modListExpr { $$ = $1; }
741 | CCONSTANT { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
745 : modListExpr { $$ = sRefSet_single ($1); }
746 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
750 { $$ = checkSpecClausesId ($1); }
752 { $$ = fixSpecClausesId ($1); }
753 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
754 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
755 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
756 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
757 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
758 $$ = sRef_buildField ($1, $3); }
759 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
760 $$ = sRef_makeArrow ($1, $3); }
764 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
765 else { $$ = sRefSet_undefined; }
767 | specClauseList TCOMMA specClauseListExpr
768 { if (sRef_isValid ($3))
770 $$ = sRefSet_insert ($1, $3);
779 : id { $$ = exprNode_fromIdentifier ($1); }
780 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
781 | CCONSTANT { $$ = $1; }
782 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
783 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
784 | QEXTENSION { $$ = exprNode_makeError (); }
788 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
789 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
790 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
791 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
792 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $4); }
793 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $4); }
794 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
795 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
798 : assignExpr { $$ = exprNodeList_singleton ($1); }
799 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
803 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
804 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
805 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
806 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
807 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
808 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
809 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
810 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
811 | sizeofExpr { $$ = $1; }
812 | offsetofExpr { $$ = $1; }
815 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
816 | newId { $$ = cstringList_single ($1); }
819 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
820 { $$ = exprNode_offsetof ($4, $7); }
823 : IsType { context_setProtectVars (); }
824 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
827 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); }
828 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); }
829 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); }
830 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); }
834 | TLPAREN typeExpression TRPAREN castExpr
835 { $$ = exprNode_cast ($1, $4, $2); }
839 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
840 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
841 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
845 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
846 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
850 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
851 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
855 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
856 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
857 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
858 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
862 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
863 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
867 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
871 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
876 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
881 { exprNode_produceGuards ($1);
882 context_enterAndClause ($1);
886 $$ = exprNode_op ($1, $4, $2);
887 context_exitAndClause ($$, $4);
894 exprNode_produceGuards ($1);
895 context_enterOrClause ($1);
899 $$ = exprNode_op ($1, $4, $2);
900 context_exitOrClause ($$, $4);
905 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
906 { context_enterFalseClause ($1); } conditionalExpr
907 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
911 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
912 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
913 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
914 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
915 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
916 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
917 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
918 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
919 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
920 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
921 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
925 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
928 : /* empty */ { $$ = exprNode_undefined; }
934 /* instance_orTypeDecl_and_possible_initialization */
937 : instanceDecl { $$ = $1; }
938 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
939 | typeDecl { $$ = exprNode_makeError (); }
942 : completeTypeSpecifier IsType TSEMI { $$ = exprNode_makeError (); }
944 ** This causes r/r conflicts with function definitions.
945 ** Instead we need to snarf one first. (gack)
947 ** | completeTypeSpecifier { setProcessingVars ($1); }
949 ** namedInitializerList IsType TSEMI
950 ** { unsetProcessingVars (); }
953 ** the solution is pretty ugly:
955 | completeTypeSpecifier NotType namedDecl NotType
957 setProcessingVars ($1);
958 processNamedDecl ($3); }
959 IsType optDeclarators TSEMI IsType { unsetProcessingVars (); $$ = $7; }
960 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
961 { setProcessingVars ($1); processNamedDecl ($3);
963 IsType init optDeclarators TSEMI IsType
964 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
965 unsetProcessingVars ();
968 : namedDecl NotType { processNamedDecl ($1); $$ = exprNode_makeError (); }
969 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
970 { $$ = exprNode_makeInitialization ($1, $6); }
974 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
975 NotType namedInitializerList IsType TSEMI { unsetProcessingTypedef (); }
976 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
977 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
980 : { g_expectingTypeName = TRUE; }
983 : { g_expectingTypeName = TRUE; context_pushLoc (); }
986 : namedInitializerListAux IsType { ; }
988 namedInitializerListAux
989 : namedInitializer { ; }
990 | namedInitializerList TCOMMA NotType namedInitializer { ; }
993 : /* empty */ { $$ = exprNode_makeError (); }
994 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
997 : assignExpr { $$ = $1; }
998 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
999 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1004 { $$ = exprNodeList_singleton ($1); }
1005 | initList TCOMMA init
1006 { $$ = exprNodeList_push ($1, $3); }
1009 ** need to do the storage class global hack so tags are
1010 ** declared with the right storage class.
1014 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1015 | QINLINE { $$ = qual_createInline (); }
1016 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1017 | QAUTO { $$ = qual_createAuto (); }
1018 | QREGISTER { $$ = qual_createRegister (); }
1021 : QCONST IsType { $$ = qual_createConst (); }
1022 | QVOLATILE IsType { $$ = qual_createVolatile (); }
1023 | QOUT IsType { $$ = qual_createOut (); }
1024 | QIN IsType { $$ = qual_createIn (); }
1025 | QPARTIAL IsType { $$ = qual_createPartial (); }
1026 | QSPECIAL IsType { $$ = qual_createSpecial (); }
1027 | QOWNED IsType { $$ = qual_createOwned (); }
1028 | QDEPENDENT IsType { $$ = qual_createDependent (); }
1029 | QYIELD IsType { $$ = qual_createYield (); }
1030 | QTEMP IsType { $$ = qual_createTemp (); }
1031 | QONLY IsType { $$ = qual_createOnly (); }
1032 | QKEEP IsType { $$ = qual_createKeep (); }
1033 | QKEPT IsType { $$ = qual_createKept (); }
1034 | QSHARED IsType { $$ = qual_createShared (); }
1035 | QUNIQUE IsType { $$ = qual_createUnique (); }
1036 | QEXITS IsType { $$ = qual_createExits (); }
1037 | QMAYEXIT IsType { $$ = qual_createMayExit (); }
1038 | QTRUEEXIT IsType { $$ = qual_createTrueExit (); }
1039 | QFALSEEXIT IsType { $$ = qual_createFalseExit (); }
1040 | QNEVEREXIT IsType { $$ = qual_createNeverExit (); }
1041 | QNULL IsType { $$ = qual_createNull (); }
1042 | QRELNULL IsType { $$ = qual_createRelNull (); }
1043 | QRETURNED IsType { $$ = qual_createReturned (); }
1044 | QEXPOSED IsType { $$ = qual_createExposed (); }
1045 | QOBSERVER IsType { $$ = qual_createObserver (); }
1046 | QCHECKED IsType { $$ = qual_createChecked (); }
1047 | QCHECKMOD IsType { $$ = qual_createCheckMod (); }
1048 | QUNCHECKED IsType { $$ = qual_createUnchecked (); }
1049 | QCHECKEDSTRICT IsType { $$ = qual_createCheckedStrict (); }
1050 | QTRUENULL IsType { $$ = qual_createTrueNull (); }
1051 | QFALSENULL IsType { $$ = qual_createFalseNull (); }
1052 | QUNUSED IsType { $$ = qual_createUnused (); }
1053 | QEXTERNAL IsType { $$ = qual_createExternal (); }
1054 | QSEF IsType { $$ = qual_createSef (); }
1055 | QABSTRACT IsType { $$ = qual_createAbstract (); }
1056 | QCONCRETE IsType { $$ = qual_createConcrete (); }
1057 | QMUTABLE IsType { $$ = qual_createMutable (); }
1058 | QIMMUTABLE IsType { $$ = qual_createImmutable (); }
1059 | QNOTNULL IsType { $$ = qual_createNotNull (); }
1060 | QREFCOUNTED IsType { $$ = qual_createRefCounted (); }
1061 | QREFS IsType { $$ = qual_createRefs (); }
1062 | QKILLREF IsType { $$ = qual_createKillRef (); }
1063 | QRELDEF IsType { $$ = qual_createRelDef (); }
1064 | QNEWREF IsType { $$ = qual_createNewRef (); }
1065 | QTEMPREF IsType { $$ = qual_createTempRef (); }
1066 | QNULLTERMINATED IsType { $$ = qual_createNullTerminated (); }
1068 /* | QSETBUFFERSIZE IsType { $$ = qual_createSetBufferSize (); } */
1072 : QSHORT { $$ = qual_createShort (); }
1073 | QLONG { $$ = qual_createLong (); }
1074 | QSIGNED { $$ = qual_createSigned (); }
1075 | QUNSIGNED { $$ = qual_createUnsigned (); }
1084 | QANYTYPE NotType { $$ = ctype_unknown; }
1085 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
1086 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1087 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
1091 | typeModifier NotType { $$ = ctype_fromQual ($1); }
1094 : IsType completeTypeSpecifier IsType
1095 { $$ = qtype_resolve ($2); }
1097 completeTypeSpecifier
1098 : completeTypeSpecifierAux { $$ = $1; }
1099 | completeTypeSpecifierAux QALT altType QENDMACRO
1100 { $$ = qtype_mergeAlt ($1, $3); }
1104 | typeExpression TCOMMA altType
1105 { $$ = qtype_mergeAlt ($1, $3); }
1107 completeTypeSpecifierAux
1108 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1109 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1110 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
1113 : /* empty */ { $$ = qtype_unknown (); }
1114 | completeTypeSpecifier { $$ = $1; }
1117 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1118 CreateStructInnerScope
1119 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1121 { $$ = declareStruct ($3, $8); }
1122 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1123 CreateStructInnerScope
1124 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1126 { $$ = declareUnion ($3, $8); }
1127 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
1128 { $$ = declareStruct ($3, uentryList_new ()); }
1129 | NotType CUNION newId IsType TLBRACE TRBRACE
1130 { $$ = declareUnion ($3, uentryList_new ()); }
1131 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1132 CreateStructInnerScope
1133 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1135 { $$ = declareUnnamedStruct ($7); }
1136 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1137 CreateStructInnerScope
1138 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1140 { $$ = declareUnnamedUnion ($7); }
1141 | NotType CSTRUCT IsType TLBRACE TRBRACE
1142 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
1143 | NotType CUNION IsType TLBRACE TRBRACE
1144 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
1145 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
1146 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
1149 : { g_expectingTypeName = FALSE; }
1153 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1154 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1157 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
1158 { $$ = fixUentryList ($3, $1); }
1159 | completeTypeSpecifier IsType TSEMI
1160 { $$ = fixUnnamedDecl ($1); }
1163 : structNamedDecl NotType
1164 { $$ = idDeclList_singleton ($1); }
1165 | structNamedDeclList TCOMMA structNamedDecl NotType
1166 { $$ = idDeclList_add ($1, $3); }
1168 structNamedDecl /* hack to get around namespace problems */
1169 : namedDecl { $$ = $1; }
1170 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1171 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1172 /* Need the IsType in case there is a cast in the constant expression. */
1175 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1176 { $$ = declareUnnamedEnum ($4); }
1177 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1178 { context_popLoc (); $$ = declareEnum ($3, $6); }
1179 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1183 { $$ = enumNameList_single ($1); }
1184 | enumeratorList TCOMMA enumerator
1185 { $$ = enumNameList_push ($1, $3); }
1186 | enumeratorList TCOMMA
1190 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1191 usymtab_supGlobalEntry (ue);
1194 | newId TASSIGN IsType constantExpr
1195 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1196 usymtab_supGlobalEntry (ue);
1202 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1203 | pointers TYPE_NAME
1205 qtype qt = qtype_unknown ();
1207 qtype_adjustPointers ($1, qt);
1208 $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1210 | pointers optNamedDecl
1211 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1215 | pointers namedDeclBase
1216 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1219 : paramTypeList { $$ = handleParamTypeList ($1); }
1220 | NotType paramIdList { $$ = handleParamIdList ($2); }
1223 : QCONST { /* ignored for now */; }
1228 | innerModsList innerMods { ; }
1232 | TMULT innerModsList { $$ = 1; }
1233 | TMULT pointers { $$ = 1 + $2; }
1234 | TMULT innerModsList pointers { $$ = 1 + $3; }
1238 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1241 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1242 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1245 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1247 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1250 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1251 | paramList TCOMMA { storeLoc (); } paramDecl
1252 { $$ = uentryList_add ($1, $4); }
1255 : IsType completeTypeSpecifier optNamedDecl IsType
1257 if (isFlipOldStyle ())
1259 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1265 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1267 | newId /* its an old-style declaration */
1269 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1273 llparseerror (message ("Inconsistent function parameter syntax: %q",
1274 idDecl_unparse (tparam)));
1278 $$ = makeCurrentParam (tparam);
1279 idDecl_free (tparam);
1284 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1287 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1289 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1292 : /* empty */ { $$ = ctype_unknown; }
1296 : IsType TLPAREN NotType abstractDecl TRPAREN
1297 { $$ = ctype_expectFunction ($4); }
1298 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1299 | TLSQBR constantExpr TRSQBR
1300 { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
1301 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1302 | abstractDeclBase TLSQBR constantExpr TRSQBR
1303 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
1304 | IsType TLPAREN TRPAREN
1305 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1306 | IsType TLPAREN paramTypeList TRPAREN
1307 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1308 | abstractDeclBase IsType TLPAREN TRPAREN
1309 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1310 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1311 { $$ = ctype_makeParamsFunction ($1, $4); }
1326 | lclintassertion {$$ = $1; printf ("Doing stmt lclintassertion\n"); }
1330 : QSETBUFFERSIZE id CCONSTANT QENDMACRO { printf(" QSETBUFFERSIZE id CCONSTANT HEllo World\n"); uentry_setBufferSize($2, $3); $$ = exprNode_createTok ($4);
1332 | QSETSTRINGLENGTH id CCONSTANT QENDMACRO { printf(" QSETSTRINGLENGTH id CCONSTANT HEllo World\n"); uentry_setStringLength($2, $3); $$ = exprNode_createTok ($4);
1334 | QTESTINRANGE id CCONSTANT QENDMACRO {printf(" QTESTINRANGE\n"); uentry_testInRange($2, $3); $$ = exprNode_createTok ($4);
1337 /* | QSETBUFFERSIZE id id {$$ = $2; printf(" QSETBUFFERSIZE id id HEllo World\n");} */
1340 : TCOLON newId { $$ = exprNode_labelMarker ($2); }
1345 : iterDefStmtList { $$ = $1; }
1352 | iterDefStmtList iterDefStmt
1353 { $$ = exprNode_concat ($1, $2); }
1355 iterDefIterationStmt
1356 : iterWhilePred iterDefStmtList
1357 { $$ = exprNode_while ($1, $2); }
1358 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1359 { $$ = exprNode_doWhile ($2, $5); }
1360 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1361 { $$ = exprNode_doWhile ($2, $5); }
1362 | forPred iterDefStmt
1363 { $$ = exprNode_for ($1, $2); }
1366 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1367 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1369 { $$ = exprNode_forPred ($3, $5, $8);
1370 context_enterForClause ($5); }
1373 : ITER_NAME CreateInnerScope TLPAREN
1374 { setProcessingIterVars ($1); }
1376 { $$ = exprNode_iterStart ($1, $5); }
1377 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1383 | openScope initializerList { $$ = $2; }
1388 | iterDefIterationStmt
1391 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1392 | error { $$ = exprNode_makeError (); }
1395 : ifPred iterDefStmt
1396 { /* don't: context_exitTrueClause ($1, $2); */
1397 $$ = exprNode_if ($1, $2);
1401 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1404 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1419 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1421 | error { $$ = exprNode_makeError (); }
1424 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1425 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
1427 /* Note that we can semantically check that the object to the case is
1428 indeed constant. In this case, we may not want to go through this effort */
1431 : CASE constantExpr { context_enterCaseClause ($2); }
1432 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
1433 | QFALLTHROUGH CASE constantExpr { context_enterCaseClause ($3); }
1434 TCOLON { $$ = exprNode_caseMarker ($3, TRUE); }
1437 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1438 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1439 | QFALLTHROUGH DEFAULT { context_enterCaseClause (exprNode_undefined); }
1440 TCOLON { $$ = exprNode_defaultMarker ($2, TRUE); }
1443 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1444 | CreateInnerScope compoundStmtAux
1445 { $$ = $2; context_exitInner ($2); }
1448 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1451 : { context_enterInnerContext (); }
1454 : { context_exitInnerPlain (); }
1456 CreateStructInnerScope
1457 : { context_enterStructInnerContext (); }
1459 DeleteStructInnerScope
1460 : { context_exitStructInnerContext (); }
1462 DeleteInnerScopeSafe
1463 : { context_exitInnerSafe (); }
1466 : TRBRACE { $$ = exprNode_createTok ($1); }
1467 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1468 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1469 | stmtList QNOTREACHED TRBRACE
1470 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1471 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1472 | initializerList QNOTREACHED TRBRACE
1473 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1474 | initializerList stmtList TRBRACE
1475 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1476 | initializerList stmtList QNOTREACHED TRBRACE
1477 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1478 lltok_getLoc ($3)));
1483 : TLBRACE compoundStmtRest
1484 { $$ = exprNode_makeBlock ($2); }
1488 { $$ = exprNode_createTok ($2); }
1489 | TLBRACE stmtListErr TRBRACE
1490 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1491 | TLBRACE initializerList TRBRACE
1492 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1493 | TLBRACE initializerList stmtList TRBRACE
1494 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1498 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1501 : initializer { $$ = $1; }
1502 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1506 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1509 : TSEMI { $$ = exprNode_createTok ($1); }
1510 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1513 : TSEMI { $$ = exprNode_createTok ($1); }
1514 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1515 | expr { $$ = exprNode_checkExpr ($1); }
1518 : CIF TLPAREN expr TRPAREN
1519 { $$ = $3; exprNode_produceGuards ($3); context_enterTrueClause ($3); }
1521 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1522 ** { $$ = $3; context_enterTrueClause (); }
1528 context_exitTrueClause ($1, $2);
1529 $$ = exprNode_if ($1, $2);
1531 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
1533 context_exitClause ($1, $2, $5);
1534 $$ = exprNode_ifelse ($1, $2, $5);
1536 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1537 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1540 : WHILE TLPAREN expr TRPAREN
1541 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1542 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1545 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1548 : ITER_NAME { context_enterIterClause (); }
1549 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1551 compoundStmt endIter DeleteInnerScope
1553 $$ = exprNode_iter ($1, $6, $8, $9);
1558 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1559 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1560 { $$ = exprNodeList_push ($1, $4); }
1563 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1564 | id { $$ = exprNode_iterId ($1); }
1565 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1567 if (uentry_isValid (ue))
1569 $$ = exprNode_iterId (ue);
1573 $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1576 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1579 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1584 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1588 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1589 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1590 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1591 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1592 { $$ = exprNode_vaArg ($1, $3, $5); }
1593 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $4); }
1594 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $4); }
1595 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1596 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1600 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1601 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1602 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1603 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1604 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1605 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1606 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1607 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1608 | sizeofExpr { $$ = $1; }
1612 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1616 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1617 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1618 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1622 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1623 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1627 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1628 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1632 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1633 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1634 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1635 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1638 : relationalIterExpr
1639 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1640 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1644 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1648 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1653 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1657 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1661 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1665 | orExpr TQUEST { context_enterTrueClause ($1); }
1666 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1667 { $$ = exprNode_cond ($1, $4, $7); }
1670 : conditionalIterExpr
1671 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1672 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1673 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1674 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1675 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1676 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1677 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1678 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1679 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1680 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1681 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1684 : ITER_ENDNAME { $$ = $1; }
1685 | /* empty */ { $$ = uentry_undefined; }
1688 : DO { context_enterDoWhileClause (); $$ = $1; }
1692 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1693 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
1694 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1696 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1699 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1700 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1701 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1702 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1703 { $$ = exprNode_doWhile ($2, $5); }
1704 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1707 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1708 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1709 | QINNERCONTINUE CONTINUE TSEMI
1710 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1711 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1712 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1713 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1714 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1715 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1716 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1717 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1728 | ITER_NAME { $$ = uentry_getName ($1); }
1729 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1730 | id { $$ = uentry_getName ($1); }
1731 | TYPE_NAME_OR_ID { $$ = $1; }
1735 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1740 extern char *yytext;
1743 # include "bison.reset"
1745 void yyerror (/*@unused@*/ char *s)
1747 static bool givehint = FALSE;
1749 if (context_inIterDef ())
1751 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1752 context_inFunctionName ()));
1754 else if (context_inIterEnd ())
1756 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1757 context_inFunctionName ()));
1759 else if (context_inMacro ())
1761 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1762 context_inFunctionName ()));
1764 if (context_inMacroUnknown ())
1768 llhint (cstring_makeLiteral
1769 ("Precede macro definition with /*@notfunction@*/ "
1770 "to suppress checking and force expansion"));
1779 llparseerror (cstring_undefined);
1783 void printState (idDecl t) {
1784 cstring id = idDecl_getName (t);
1785 uentry ue = usymtab_lookupSafe (id);
1787 sRef s = uentry_getSref (ue);
1789 printf("State = %d\n", s->bufinfo.bufstate);
1793 /*take this out soon */
1794 /* void testassert1 (cstring id, icstring cons ) { */
1795 /* uentry ue =usymtab_lookupSafe (id); */
1796 /* sRef s = uentry_getSref (ue); */
1797 /* printf ("Doing testassert1 with setbuffersize\n"); */
1798 /* printf("State = %d\n", s->bufinfo.bufstate); */
1800 /* void testassert2 (cstring id) { */
1801 /* uentry ue =usymtab_lookupSafe (id); */
1802 /* sRef s = uentry_getSref (ue); */
1803 /* printf ("Doing testassert2 with setbuffersize\n"); */
1804 /* printf("State = %d\n", s->bufinfo.bufstate); */