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);
336 optGlobMods optGlobBufConstraints
337 { setImplictfcnConstraints ();
338 clearCurrentParams ();
339 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
342 // printf("Done nameDeclBase\n");
346 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
347 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
348 { $$ = idDecl_expectFunction ($4); }
349 | plainNamedDeclBase TLSQBR TRSQBR
350 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
351 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
355 if (exprNode_hasValue ($4)
356 && multiVal_isInt (exprNode_getValue ($4)))
358 value = (int) multiVal_forceInt (exprNode_getValue ($4));
365 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
367 | plainNamedDeclBase PushType TLPAREN TRPAREN
368 { setCurrentParams (uentryList_missingParams);
371 { /* need to support globals and modifies here! */
372 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
373 uentryList_makeMissingParams ());
375 $$ = idDecl_replaceCtype ($1, ct);
378 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
379 { setCurrentParams ($4);
382 { clearCurrentParams ();
383 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
388 : QITER newId TLPAREN genericParamList TRPAREN
389 { setCurrentParams ($4); } optPlainGlobMods
390 { clearCurrentParams (); } optSemi QENDMACRO
391 { declareCIter ($2, $4); }
394 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); }
395 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); }
396 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); }
397 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); }
400 : fcnDefHdrAux { declareFunction ($1); }
403 : { setProcessingGlobMods (); } optGlobModsRest
404 { clearProcessingGlobMods (); }
409 optGlobBufConstraints
410 : { setProcessingGlobMods (); } optGlobBufConstraintsRest
411 { clearProcessingGlobMods (); }
414 optGlobBufConstraintsRest
415 : optGlobBufConstraintsAux optGlobEnsuresConstraintsAux
418 optGlobEnsuresConstraintsAux
420 DPRINTF ( ("doing optGlobEnsuresConstraintsAux\n") );
421 context_setProtectVars (); enterParamsTemp ();
422 sRef_setGlobalScopeSafe ();
424 } QENSURESCONSTRAINT BufConstraintList QENDMACRO
426 setEnsuresConstraints ($3);
428 sRef_clearGlobalScopeSafe ();
429 context_releaseVars ();
430 DPRINTF (("done optGlobBufConstraintsAux\n"));}
434 optGlobBufConstraintsAux
436 DPRINTF ( ("doing optGlobBufConstraintsAux\n") );
437 context_setProtectVars (); enterParamsTemp ();
438 sRef_setGlobalScopeSafe ();
440 } QBUFFERCONSTRAINT BufConstraintList QENDMACRO
442 setFunctionConstraints ($3);
444 sRef_clearGlobalScopeSafe ();
445 context_releaseVars ();
446 DPRINTF (("done optGlobBufConstraintsAux\n"));}
450 : BufConstraint BufConstraintList{ $$ = constraintList_add ($2, $1); }
451 | BufConstraint {constraintList c; c = constraintList_new(); c = constraintList_add (c, $1); $$ = c}
454 : BufConstraintExpr relationalOp BufConstraintExpr TSEMI {
455 $$ = makeConstraintParse3 ($1, $2, $3);
456 DPRINTF(("Done BufConstraint1\n")); }
469 | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3); DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
470 | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
471 DPRINTF( ("Got BufConstraintExpr BINary Op ") );
472 $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
475 : BufConstraintSrefExpr { $$ = constraintExpr_makeTermsRef($1);}
476 | CCONSTANT { char *t; int c;
477 t = cstring_toCharsSafe (exprNode_unparse($1));
479 $$ = constraintExpr_makeIntLiteral (c);
483 BufConstraintSrefExpr
486 checkbufferConstraintClausesId ($1);}
487 | NEW_IDENTIFIER { $$ = fixSpecClausesId ($1); }
489 | BufConstraintSrefExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
490 | BufConstraintSrefExpr TLSQBR CCONSTANT TRSQBR {
492 t = cstring_toCharsSafe (exprNode_unparse($3));
494 $$ = sRef_makeArrayFetchKnown($1, c); }
495 | TMULT BufConstraintSrefExpr { $$ = sRef_constructPointer ($2); }
496 | TLPAREN BufConstraintSrefExpr TRPAREN { $$ = $2; }
497 | BufConstraintSrefExpr TDOT newId { cstring_markOwned ($3);
498 $$ = sRef_buildField ($1, $3); }
499 | BufConstraintSrefExpr ARROW_OP newId { cstring_markOwned ($3);
500 $$ = sRef_makeArrow ($1, $3); }
503 | BufConstraintTerm TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
504 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
505 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
506 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
507 $$ = sRef_buildField ($1, $3); }
525 : { setProcessingGlobMods (); } optPlainGlobModsRest
526 { clearProcessingGlobMods (); }
529 /*: id { $$ = unentry_getSref($1); checkModifiesId ($1); }
530 | NEW_INDENTIFIER { $$ = fixModifiesId ($1)} */
536 : { setProcessingGlobMods (); } optPlainGlobModsRest
537 { clearProcessingGlobMods (); }
541 | specialClauses optGlobModsAux
544 : optPlainGlobModsAux
545 | specialClauses optPlainGlobModsAux
549 | specialClause specialClauses
552 : globIdListExpr { ; }
553 | globIdList TCOMMA globIdListExpr { ; }
556 : optGlobQuals globId { globListAdd ($2, $1); }
559 : id { $$ = uentry_getSref ($1); }
560 | NEW_IDENTIFIER { $$ = globListUnrecognized ($1); }
563 : QUNDEF { $$ = qual_createUndef (); }
564 | QKILLED { $$ = qual_createKilled (); }
565 | QOUT { $$ = qual_createOut (); }
566 | QIN { $$ = qual_createIn (); }
567 | QPARTIAL { $$ = qual_createPartial (); }
570 : /* empty */ { $$ = qualList_undefined; }
571 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
574 : QGLOBALS { setProcessingGlobalsList (); } initializerList optSemi
576 { unsetProcessingGlobals (); }
577 | QGLOBALS { setProcessingGlobalsList (); } globIdList optSemi
579 { unsetProcessingGlobals (); }
581 { setFunctionNoGlobals ();
582 setFunctionModifies (sRefSet_single (sRef_makeNothing ()));
588 : QGLOBALS { setProcessingGlobalsList (); } initializerList optSemi
590 { unsetProcessingGlobals (); }
591 | QGLOBALS { setProcessingGlobalsList (); } globIdList optSemi
593 { unsetProcessingGlobals (); }
595 { setFunctionNoGlobals ();
596 setFunctionModifies (sRefSet_single (sRef_makeNothing ()));
608 context_setProtectVars (); enterParamsTemp ();
609 sRef_setGlobalScopeSafe ();
613 setFunctionModifies ($3); exitParamsTemp ();
614 sRef_clearGlobalScopeSafe ();
615 context_releaseVars ();
621 context_setProtectVars (); enterParamsTemp ();
622 sRef_setGlobalScopeSafe ();
626 setFunctionModifies ($3); exitParamsTemp ();
627 sRef_clearGlobalScopeSafe ();
628 context_releaseVars ();
649 : QONLY { $$ = SP_ISONLY; }
650 | QOBSERVER { $$ = SP_ISOBSERVER; }
651 | QEXPOSED { $$ = SP_ISEXPOSED; }
652 | QDEPENDENT { $$ = SP_ISDEPENDENT; }
653 | QOWNED { $$ = SP_ISOWNED; }
654 | QSHARED { $$ = SP_ISSHARED; }
655 | QISNULL { $$ = SP_ISNULL; }
656 | QNOTNULL { $$ = SP_ISNOTNULL; }
661 context_setProtectVars ();
663 sRef_setGlobalScopeSafe ();
665 specClauseList optSemi endSpecialTag IsType
667 setFunctionSpecialClause ($1, $4, $6);
669 sRef_clearGlobalScopeSafe ();
670 context_releaseVars ();
672 | stateSpecialClause NotType specialClauseType
674 context_setProtectVars ();
676 sRef_setGlobalScopeSafe ();
678 specClauseList optSemi endStateTag IsType
680 setFunctionStateSpecialClause ($1, $3, $5, $7);
682 sRef_clearGlobalScopeSafe ();
683 context_releaseVars ();
689 qtype qint = qtype_create (ctype_int);
690 $$ = idDecl_fixBase ($1, qint);
693 | completeTypeSpecifier NotType namedDecl
694 { $$ = idDecl_fixBase ($3, $1); }
697 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
700 exprNode_checkFunctionBody ($3); $$ = $3;
701 context_exitInner ($3);
704 { doneParams (); context_enterInnerContext (); }
707 context_exitInner ($3);
708 exprNode_checkFunctionBody ($3);
709 $$ = $3; /* old style */
715 context_setFunctionDefined (exprNode_loc ($2));
716 /* exprNode_checkFunction (context_getHeader (), $2); */
719 context_exitFunction ();
723 : modList optSemi QENDMACRO { $$ = $1; }
724 | optSemi QENDMACRO { $$ = sRefSet_new (); }
727 : modList optSemi { $$ = $1; }
728 | optSemi { $$ = sRefSet_new (); }
731 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
732 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
733 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
734 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
735 | TMULT modListExpr { $$ = modListPointer ($2); }
736 | TLPAREN modListExpr TRPAREN { $$ = $2; }
737 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
738 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
742 : modListExpr { $$ = $1; }
743 | CCONSTANT { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
747 : modListExpr { $$ = sRefSet_single ($1); }
748 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
752 { $$ = checkSpecClausesId ($1); }
754 { $$ = fixSpecClausesId ($1); }
755 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
756 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
757 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
758 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
759 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
760 $$ = sRef_buildField ($1, $3); }
761 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
762 $$ = sRef_makeArrow ($1, $3); }
766 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
767 else { $$ = sRefSet_undefined; }
769 | specClauseList TCOMMA specClauseListExpr
770 { if (sRef_isValid ($3))
772 $$ = sRefSet_insert ($1, $3);
781 : id { $$ = exprNode_fromIdentifier ($1); }
782 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
783 | CCONSTANT { $$ = $1; }
784 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
785 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
786 | QEXTENSION { $$ = exprNode_makeError (); }
790 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
791 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
792 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
793 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
794 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $4); }
795 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $4); }
796 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
797 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
800 : assignExpr { $$ = exprNodeList_singleton ($1); }
801 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
805 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
806 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
807 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
808 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
809 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
810 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
811 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
812 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
813 | sizeofExpr { $$ = $1; }
814 | offsetofExpr { $$ = $1; }
817 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
818 | newId { $$ = cstringList_single ($1); }
821 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
822 { $$ = exprNode_offsetof ($4, $7); }
825 : IsType { context_setProtectVars (); }
826 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
829 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); }
830 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); }
831 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); }
832 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); }
836 | TLPAREN typeExpression TRPAREN castExpr
837 { $$ = exprNode_cast ($1, $4, $2); }
841 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
842 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
843 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
847 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
848 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
852 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
853 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
857 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
858 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
859 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
860 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
864 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
865 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
869 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
873 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
878 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
883 { exprNode_produceGuards ($1);
884 context_enterAndClause ($1);
888 $$ = exprNode_op ($1, $4, $2);
889 context_exitAndClause ($$, $4);
896 exprNode_produceGuards ($1);
897 context_enterOrClause ($1);
901 $$ = exprNode_op ($1, $4, $2);
902 context_exitOrClause ($$, $4);
907 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
908 { context_enterFalseClause ($1); } conditionalExpr
909 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
913 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
914 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
915 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
916 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
917 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
918 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
919 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
920 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
921 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
922 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
923 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
927 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
930 : /* empty */ { $$ = exprNode_undefined; }
936 /* instance_orTypeDecl_and_possible_initialization */
939 : instanceDecl { $$ = $1; }
940 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
941 | typeDecl { $$ = exprNode_makeError (); }
944 : completeTypeSpecifier IsType TSEMI { $$ = exprNode_makeError (); }
946 ** This causes r/r conflicts with function definitions.
947 ** Instead we need to snarf one first. (gack)
949 ** | completeTypeSpecifier { setProcessingVars ($1); }
951 ** namedInitializerList IsType TSEMI
952 ** { unsetProcessingVars (); }
955 ** the solution is pretty ugly:
957 | completeTypeSpecifier NotType namedDecl NotType
959 setProcessingVars ($1);
960 processNamedDecl ($3); }
961 IsType optDeclarators TSEMI IsType { unsetProcessingVars (); $$ = $7; }
962 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
963 { setProcessingVars ($1); processNamedDecl ($3);
965 IsType init optDeclarators TSEMI IsType
966 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
967 unsetProcessingVars ();
970 : namedDecl NotType { processNamedDecl ($1); $$ = exprNode_makeError (); }
971 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
972 { $$ = exprNode_makeInitialization ($1, $6); }
976 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
977 NotType namedInitializerList IsType TSEMI { unsetProcessingTypedef (); }
978 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
979 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
982 : { g_expectingTypeName = TRUE; }
985 : { g_expectingTypeName = TRUE; context_pushLoc (); }
988 : namedInitializerListAux IsType { ; }
990 namedInitializerListAux
991 : namedInitializer { ; }
992 | namedInitializerList TCOMMA NotType namedInitializer { ; }
995 : /* empty */ { $$ = exprNode_makeError (); }
996 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
999 : assignExpr { $$ = $1; }
1000 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1001 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1006 { $$ = exprNodeList_singleton ($1); }
1007 | initList TCOMMA init
1008 { $$ = exprNodeList_push ($1, $3); }
1011 ** need to do the storage class global hack so tags are
1012 ** declared with the right storage class.
1016 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1017 | QINLINE { $$ = qual_createInline (); }
1018 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1019 | QAUTO { $$ = qual_createAuto (); }
1020 | QREGISTER { $$ = qual_createRegister (); }
1023 : QCONST IsType { $$ = qual_createConst (); }
1024 | QVOLATILE IsType { $$ = qual_createVolatile (); }
1025 | QOUT IsType { $$ = qual_createOut (); }
1026 | QIN IsType { $$ = qual_createIn (); }
1027 | QPARTIAL IsType { $$ = qual_createPartial (); }
1028 | QSPECIAL IsType { $$ = qual_createSpecial (); }
1029 | QOWNED IsType { $$ = qual_createOwned (); }
1030 | QDEPENDENT IsType { $$ = qual_createDependent (); }
1031 | QYIELD IsType { $$ = qual_createYield (); }
1032 | QTEMP IsType { $$ = qual_createTemp (); }
1033 | QONLY IsType { $$ = qual_createOnly (); }
1034 | QKEEP IsType { $$ = qual_createKeep (); }
1035 | QKEPT IsType { $$ = qual_createKept (); }
1036 | QSHARED IsType { $$ = qual_createShared (); }
1037 | QUNIQUE IsType { $$ = qual_createUnique (); }
1038 | QEXITS IsType { $$ = qual_createExits (); }
1039 | QMAYEXIT IsType { $$ = qual_createMayExit (); }
1040 | QTRUEEXIT IsType { $$ = qual_createTrueExit (); }
1041 | QFALSEEXIT IsType { $$ = qual_createFalseExit (); }
1042 | QNEVEREXIT IsType { $$ = qual_createNeverExit (); }
1043 | QNULL IsType { $$ = qual_createNull (); }
1044 | QRELNULL IsType { $$ = qual_createRelNull (); }
1045 | QRETURNED IsType { $$ = qual_createReturned (); }
1046 | QEXPOSED IsType { $$ = qual_createExposed (); }
1047 | QOBSERVER IsType { $$ = qual_createObserver (); }
1048 | QCHECKED IsType { $$ = qual_createChecked (); }
1049 | QCHECKMOD IsType { $$ = qual_createCheckMod (); }
1050 | QUNCHECKED IsType { $$ = qual_createUnchecked (); }
1051 | QCHECKEDSTRICT IsType { $$ = qual_createCheckedStrict (); }
1052 | QTRUENULL IsType { $$ = qual_createTrueNull (); }
1053 | QFALSENULL IsType { $$ = qual_createFalseNull (); }
1054 | QUNUSED IsType { $$ = qual_createUnused (); }
1055 | QEXTERNAL IsType { $$ = qual_createExternal (); }
1056 | QSEF IsType { $$ = qual_createSef (); }
1057 | QABSTRACT IsType { $$ = qual_createAbstract (); }
1058 | QCONCRETE IsType { $$ = qual_createConcrete (); }
1059 | QMUTABLE IsType { $$ = qual_createMutable (); }
1060 | QIMMUTABLE IsType { $$ = qual_createImmutable (); }
1061 | QNOTNULL IsType { $$ = qual_createNotNull (); }
1062 | QREFCOUNTED IsType { $$ = qual_createRefCounted (); }
1063 | QREFS IsType { $$ = qual_createRefs (); }
1064 | QKILLREF IsType { $$ = qual_createKillRef (); }
1065 | QRELDEF IsType { $$ = qual_createRelDef (); }
1066 | QNEWREF IsType { $$ = qual_createNewRef (); }
1067 | QTEMPREF IsType { $$ = qual_createTempRef (); }
1068 | QNULLTERMINATED IsType { $$ = qual_createNullTerminated (); }
1070 /* | QSETBUFFERSIZE IsType { $$ = qual_createSetBufferSize (); } */
1074 : QSHORT { $$ = qual_createShort (); }
1075 | QLONG { $$ = qual_createLong (); }
1076 | QSIGNED { $$ = qual_createSigned (); }
1077 | QUNSIGNED { $$ = qual_createUnsigned (); }
1086 | QANYTYPE NotType { $$ = ctype_unknown; }
1087 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
1088 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1089 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
1093 | typeModifier NotType { $$ = ctype_fromQual ($1); }
1096 : IsType completeTypeSpecifier IsType
1097 { $$ = qtype_resolve ($2); }
1099 completeTypeSpecifier
1100 : completeTypeSpecifierAux { $$ = $1; }
1101 | completeTypeSpecifierAux QALT altType QENDMACRO
1102 { $$ = qtype_mergeAlt ($1, $3); }
1106 | typeExpression TCOMMA altType
1107 { $$ = qtype_mergeAlt ($1, $3); }
1109 completeTypeSpecifierAux
1110 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1111 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1112 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
1115 : /* empty */ { $$ = qtype_unknown (); }
1116 | completeTypeSpecifier { $$ = $1; }
1119 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1120 CreateStructInnerScope
1121 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1123 { $$ = declareStruct ($3, $8); }
1124 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1125 CreateStructInnerScope
1126 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1128 { $$ = declareUnion ($3, $8); }
1129 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
1130 { $$ = declareStruct ($3, uentryList_new ()); }
1131 | NotType CUNION newId IsType TLBRACE TRBRACE
1132 { $$ = declareUnion ($3, uentryList_new ()); }
1133 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1134 CreateStructInnerScope
1135 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1137 { $$ = declareUnnamedStruct ($7); }
1138 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1139 CreateStructInnerScope
1140 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1142 { $$ = declareUnnamedUnion ($7); }
1143 | NotType CSTRUCT IsType TLBRACE TRBRACE
1144 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
1145 | NotType CUNION IsType TLBRACE TRBRACE
1146 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
1147 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
1148 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
1151 : { g_expectingTypeName = FALSE; }
1155 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1156 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1159 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
1160 { $$ = fixUentryList ($3, $1); }
1161 | completeTypeSpecifier IsType TSEMI
1162 { $$ = fixUnnamedDecl ($1); }
1165 : structNamedDecl NotType
1166 { $$ = idDeclList_singleton ($1); }
1167 | structNamedDeclList TCOMMA structNamedDecl NotType
1168 { $$ = idDeclList_add ($1, $3); }
1170 structNamedDecl /* hack to get around namespace problems */
1171 : namedDecl { $$ = $1; }
1172 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1173 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1174 /* Need the IsType in case there is a cast in the constant expression. */
1177 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1178 { $$ = declareUnnamedEnum ($4); }
1179 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1180 { context_popLoc (); $$ = declareEnum ($3, $6); }
1181 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1185 { $$ = enumNameList_single ($1); }
1186 | enumeratorList TCOMMA enumerator
1187 { $$ = enumNameList_push ($1, $3); }
1188 | enumeratorList TCOMMA
1192 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1193 usymtab_supGlobalEntry (ue);
1196 | newId TASSIGN IsType constantExpr
1197 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1198 usymtab_supGlobalEntry (ue);
1204 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1205 | pointers TYPE_NAME
1207 qtype qt = qtype_unknown ();
1209 qtype_adjustPointers ($1, qt);
1210 $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1212 | pointers optNamedDecl
1213 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1217 | pointers namedDeclBase
1218 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1221 : paramTypeList { $$ = handleParamTypeList ($1); }
1222 | NotType paramIdList { $$ = handleParamIdList ($2); }
1225 : QCONST { /* ignored for now */; }
1230 | innerModsList innerMods { ; }
1234 | TMULT innerModsList { $$ = 1; }
1235 | TMULT pointers { $$ = 1 + $2; }
1236 | TMULT innerModsList pointers { $$ = 1 + $3; }
1240 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1243 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1244 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1247 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1249 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1252 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1253 | paramList TCOMMA { storeLoc (); } paramDecl
1254 { $$ = uentryList_add ($1, $4); }
1257 : IsType completeTypeSpecifier optNamedDecl IsType
1259 if (isFlipOldStyle ())
1261 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1267 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1269 | newId /* its an old-style declaration */
1271 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1275 llparseerror (message ("Inconsistent function parameter syntax: %q",
1276 idDecl_unparse (tparam)));
1280 $$ = makeCurrentParam (tparam);
1281 idDecl_free (tparam);
1286 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1289 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1291 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1294 : /* empty */ { $$ = ctype_unknown; }
1298 : IsType TLPAREN NotType abstractDecl TRPAREN
1299 { $$ = ctype_expectFunction ($4); }
1300 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1301 | TLSQBR constantExpr TRSQBR
1302 { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
1303 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1304 | abstractDeclBase TLSQBR constantExpr TRSQBR
1305 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
1306 | IsType TLPAREN TRPAREN
1307 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1308 | IsType TLPAREN paramTypeList TRPAREN
1309 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1310 | abstractDeclBase IsType TLPAREN TRPAREN
1311 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1312 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1313 { $$ = ctype_makeParamsFunction ($1, $4); }
1327 /* | lclintassertion {$$ = $1; printf ("Doing stmt lclintassertion\n"); }*/
1331 : QSETBUFFERSIZE id CCONSTANT QENDMACRO { printf(" QSETBUFFERSIZE id CCONSTANT HEllo World\n"); uentry_setBufferSize($2, $3); $$ = exprNode_createTok ($4);
1333 | QSETSTRINGLENGTH id CCONSTANT QENDMACRO { printf(" QSETSTRINGLENGTH id CCONSTANT HEllo World\n"); uentry_setStringLength($2, $3); $$ = exprNode_createTok ($4);
1335 | QTESTINRANGE id CCONSTANT QENDMACRO {printf(" QTESTINRANGE\n"); uentry_testInRange($2, $3); $$ = exprNode_createTok ($4);
1338 /* | QSETBUFFERSIZE id id {$$ = $2; printf(" QSETBUFFERSIZE id id HEllo World\n");} */
1341 : TCOLON newId { $$ = exprNode_labelMarker ($2); }
1346 : iterDefStmtList { $$ = $1; }
1353 | iterDefStmtList iterDefStmt
1354 { $$ = exprNode_concat ($1, $2); }
1356 iterDefIterationStmt
1357 : iterWhilePred iterDefStmtList
1358 { $$ = exprNode_while ($1, $2); }
1359 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1360 { $$ = exprNode_doWhile ($2, $5); }
1361 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1362 { $$ = exprNode_doWhile ($2, $5); }
1363 | forPred iterDefStmt
1364 { $$ = exprNode_for ($1, $2); }
1367 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1368 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1370 { $$ = exprNode_forPred ($3, $5, $8);
1371 context_enterForClause ($5); }
1374 : ITER_NAME CreateInnerScope TLPAREN
1375 { setProcessingIterVars ($1); }
1377 { $$ = exprNode_iterStart ($1, $5); }
1378 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1384 | openScope initializerList { $$ = $2; }
1389 | iterDefIterationStmt
1392 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1393 | error { $$ = exprNode_makeError (); }
1396 : ifPred iterDefStmt
1397 { /* don't: context_exitTrueClause ($1, $2); */
1398 $$ = exprNode_if ($1, $2);
1402 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1405 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1420 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1422 | error { $$ = exprNode_makeError (); }
1425 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1426 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
1428 /* Note that we can semantically check that the object to the case is
1429 indeed constant. In this case, we may not want to go through this effort */
1432 : CASE constantExpr { context_enterCaseClause ($2); }
1433 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
1434 | QFALLTHROUGH CASE constantExpr { context_enterCaseClause ($3); }
1435 TCOLON { $$ = exprNode_caseMarker ($3, TRUE); }
1438 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1439 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1440 | QFALLTHROUGH DEFAULT { context_enterCaseClause (exprNode_undefined); }
1441 TCOLON { $$ = exprNode_defaultMarker ($2, TRUE); }
1444 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1445 | CreateInnerScope compoundStmtAux
1446 { $$ = $2; context_exitInner ($2); }
1449 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1452 : { context_enterInnerContext (); }
1455 : { context_exitInnerPlain (); }
1457 CreateStructInnerScope
1458 : { context_enterStructInnerContext (); }
1460 DeleteStructInnerScope
1461 : { context_exitStructInnerContext (); }
1463 DeleteInnerScopeSafe
1464 : { context_exitInnerSafe (); }
1467 : TRBRACE { $$ = exprNode_createTok ($1); }
1468 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1469 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1470 | stmtList QNOTREACHED TRBRACE
1471 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1472 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1473 | initializerList QNOTREACHED TRBRACE
1474 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1475 | initializerList stmtList TRBRACE
1476 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1477 | initializerList stmtList QNOTREACHED TRBRACE
1478 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1479 lltok_getLoc ($3)));
1484 : TLBRACE compoundStmtRest
1485 { $$ = exprNode_makeBlock ($2); }
1489 { $$ = exprNode_createTok ($2); }
1490 | TLBRACE stmtListErr TRBRACE
1491 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1492 | TLBRACE initializerList TRBRACE
1493 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1494 | TLBRACE initializerList stmtList TRBRACE
1495 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1499 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1502 : initializer { $$ = $1; }
1503 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1507 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1510 : TSEMI { $$ = exprNode_createTok ($1); }
1511 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1514 : TSEMI { $$ = exprNode_createTok ($1); }
1515 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1516 | expr { $$ = exprNode_checkExpr ($1); }
1519 : CIF TLPAREN expr TRPAREN
1520 { $$ = $3; exprNode_produceGuards ($3); context_enterTrueClause ($3); }
1522 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1523 ** { $$ = $3; context_enterTrueClause (); }
1529 context_exitTrueClause ($1, $2);
1530 $$ = exprNode_if ($1, $2);
1532 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
1534 context_exitClause ($1, $2, $5);
1535 $$ = exprNode_ifelse ($1, $2, $5);
1537 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1538 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1541 : WHILE TLPAREN expr TRPAREN
1542 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1543 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1546 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1549 : ITER_NAME { context_enterIterClause (); }
1550 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1552 compoundStmt endIter DeleteInnerScope
1554 $$ = exprNode_iter ($1, $6, $8, $9);
1559 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1560 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1561 { $$ = exprNodeList_push ($1, $4); }
1564 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1565 | id { $$ = exprNode_iterId ($1); }
1566 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1568 if (uentry_isValid (ue))
1570 $$ = exprNode_iterId (ue);
1574 $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1577 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1580 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1585 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1589 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1590 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1591 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1592 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1593 { $$ = exprNode_vaArg ($1, $3, $5); }
1594 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $4); }
1595 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $4); }
1596 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1597 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1601 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1602 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1603 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1604 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1605 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1606 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1607 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1608 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1609 | sizeofExpr { $$ = $1; }
1613 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1617 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1618 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1619 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1623 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1624 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1628 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1629 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1633 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1634 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1635 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1636 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1639 : relationalIterExpr
1640 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1641 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1645 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1649 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1654 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1658 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1662 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1666 | orExpr TQUEST { context_enterTrueClause ($1); }
1667 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1668 { $$ = exprNode_cond ($1, $4, $7); }
1671 : conditionalIterExpr
1672 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1673 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1674 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1675 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1676 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1677 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1678 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1679 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1680 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1681 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1682 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1685 : ITER_ENDNAME { $$ = $1; }
1686 | /* empty */ { $$ = uentry_undefined; }
1689 : DO { context_enterDoWhileClause (); $$ = $1; }
1693 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1694 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
1695 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1697 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1700 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1701 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1702 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1703 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1704 { $$ = exprNode_doWhile ($2, $5); }
1705 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1708 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1709 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1710 | QINNERCONTINUE CONTINUE TSEMI
1711 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1712 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1713 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1714 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1715 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1716 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1717 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1718 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1729 | ITER_NAME { $$ = uentry_getName ($1); }
1730 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1731 | id { $$ = uentry_getName ($1); }
1732 | TYPE_NAME_OR_ID { $$ = $1; }
1736 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1741 extern char *yytext;
1744 # include "bison.reset"
1746 void yyerror (/*@unused@*/ char *s)
1748 static bool givehint = FALSE;
1750 if (context_inIterDef ())
1752 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1753 context_inFunctionName ()));
1755 else if (context_inIterEnd ())
1757 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1758 context_inFunctionName ()));
1760 else if (context_inMacro ())
1762 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1763 context_inFunctionName ()));
1765 if (context_inMacroUnknown ())
1769 llhint (cstring_makeLiteral
1770 ("Precede macro definition with /*@notfunction@*/ "
1771 "to suppress checking and force expansion"));
1780 llparseerror (cstring_undefined);
1784 void printState (idDecl t) {
1785 cstring id = idDecl_getName (t);
1786 uentry ue = usymtab_lookupSafe (id);
1788 sRef s = uentry_getSref (ue);
1790 printf("State = %d\n", s->bufinfo.bufstate);
1794 /*take this out soon */
1795 /* void testassert1 (cstring id, icstring cons ) { */
1796 /* uentry ue =usymtab_lookupSafe (id); */
1797 /* sRef s = uentry_getSref (ue); */
1798 /* printf ("Doing testassert1 with setbuffersize\n"); */
1799 /* printf("State = %d\n", s->bufinfo.bufstate); */
1801 /* void testassert2 (cstring id) { */
1802 /* uentry ue =usymtab_lookupSafe (id); */
1803 /* sRef s = uentry_getSref (ue); */
1804 /* printf ("Doing testassert2 with setbuffersize\n"); */
1805 /* printf("State = %d\n", s->bufinfo.bufstate); */