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.
78 specialClauseKind sck;
83 /*@only@*/ qtype qtyp;
84 /*@only@*/ cstring cname;
85 /*@only@*/ idDecl ntyp;
86 /*@only@*/ idDeclList ntyplist;
87 /*@only@*/ uentryList flist;
88 /*@owned@*/ uentryList entrylist;
89 /*@observer@*/ /*@dependent@*/ uentry entry;
90 /*@only@*/ uentry oentry;
91 /*@only@*/ exprNode expr;
92 /*@only@*/ enumNameList enumnamelist;
93 /*@only@*/ exprNodeList alist;
94 /*@only@*/ sRefSet srset;
95 /*@only@*/ cstringList cstringlist;
105 /* standard C tokens */
107 %token <tok> BADTOK SKIPTOK
108 %token <tok> CTOK_ELIPSIS CASE DEFAULT CIF CELSE SWITCH WHILE DO CFOR
109 %token <tok> GOTO CONTINUE BREAK RETURN
110 %token <tok> TSEMI TLBRACE TRBRACE TCOMMA TCOLON TASSIGN TLPAREN
111 %token <tok> TRPAREN TLSQBR TRSQBR TDOT TAMPERSAND TEXCL TTILDE
112 %token <tok> TMINUS TPLUS TMULT TDIV TPERCENT TLT TGT TCIRC TBAR TQUEST
113 %token <tok> CSIZEOF CALIGNOF ARROW_OP CTYPEDEF COFFSETOF
114 %token <tok> INC_OP DEC_OP LEFT_OP RIGHT_OP
115 %token <tok> LE_OP GE_OP EQ_OP NE_OP AND_OP OR_OP
116 %token <tok> MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN SUB_ASSIGN
117 %token <tok> LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
118 %token <tok> CSTRUCT CUNION CENUM
119 %token <tok> VA_ARG VA_DCL
120 %token <tok> QGLOBALS
121 %token <tok> QMODIFIES
123 %token <tok> QCONSTANT
124 %token <tok> QFUNCTION
126 %token <tok> QDEFINES
128 %token <tok> QALLOCATES
130 %token <tok> QRELEASES
131 %token <tok> QPRECLAUSE
132 %token <tok> QPOSTCLAUSE
134 %token <tok> QUNDEF QKILLED
135 %token <tok> QENDMACRO
137 /* additional tokens introduced by lclint pre-processor. */
138 %token <tok> LLMACRO LLMACROITER LLMACROEND TENDMACRO
140 /* break comments: */
141 %token <tok> QSWITCHBREAK QLOOPBREAK QINNERBREAK QSAFEBREAK
142 %token <tok> QINNERCONTINUE
144 /* case fall-through marker: */
145 %token <tok> QFALLTHROUGH
147 /* used in scanner only */
148 %token <tok> QLINTNOTREACHED
149 %token <tok> QLINTFALLTHROUGH
150 %token <tok> QLINTFALLTHRU
151 %token <tok> QARGSUSED
152 %token <tok> QPRINTFLIKE QLINTPRINTFLIKE QSCANFLIKE QMESSAGELIKE
154 /* not-reached marker: (used like a label) */
155 %token <tok> QNOTREACHED
157 /* type qualifiers: */
158 %token <tok> QCONST QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
159 %token <tok> QOUT QIN QYIELD QONLY QTEMP QSHARED QREF QUNIQUE
160 %token <tok> QCHECKED QUNCHECKED QCHECKEDSTRICT QCHECKMOD
161 %token <tok> QKEEP QKEPT QPARTIAL QSPECIAL QOWNED QDEPENDENT
162 %token <tok> QRETURNED QEXPOSED QNULL QOBSERVER QISNULL
163 %token <tok> QEXITS QMAYEXIT QNEVEREXIT QTRUEEXIT QFALSEEXIT
164 %token <tok> QLONG QSIGNED QUNSIGNED QSHORT QUNUSED QSEF QNOTNULL QRELNULL
165 %token <tok> QABSTRACT QCONCRETE QMUTABLE QIMMUTABLE
166 %token <tok> QTRUENULL QFALSENULL QEXTERNAL
167 %token <tok> QREFCOUNTED QREFS QNEWREF QTEMPREF QKILLREF QRELDEF
168 %token <ctyp> CGCHAR CBOOL CINT CGFLOAT CDOUBLE CVOID
169 %token <tok> QANYTYPE QINTEGRALTYPE QUNSIGNEDINTEGRALTYPE QSIGNEDINTEGRALTYPE
171 %token <tok> QNULLTERMINATED
172 %token <tok> QSETBUFFERSIZE
173 %token <tok> QBUFFERCONSTRAINT
174 %token <tok> QENSURESCONSTRAINT
175 %token <tok> QSETSTRINGLENGTH
177 %token <tok> QMAXREAD
178 %token <tok> QTESTINRANGE
182 /* identifiers, literals */
183 %token <entry> IDENTIFIER
184 %token <cname> NEW_IDENTIFIER TYPE_NAME_OR_ID
185 %token <expr> CCONSTANT
186 %token <entry> ITER_NAME ITER_ENDNAME
187 %type <entry> endIter
189 %token <ctyp> TYPE_NAME
190 %type <cname> enumerator newId /*@-varuse@*/ /* yacc declares yytranslate here */
191 %type <count> pointers /*@=varuse@*/
193 %type <tok> doHeader specialTag endSpecialTag stateSpecialClause endStateTag
194 %type <sck> specialClauseType
196 /* type construction */
197 %type <ctyp> abstractDecl abstractDeclBase optAbstractDeclBase
198 %type <ctyp> suSpc enumSpc typeName typeSpecifier
200 %type <ntyp> namedDecl namedDeclBase optNamedDecl
201 %type <ntyp> plainNamedDecl plainNamedDeclBase
202 %type <ntyp> structNamedDecl
203 %type <ntyp> fcnDefHdrAux plainFcn
205 %type <oentry> paramDecl
208 %type <ntyplist> structNamedDeclList
210 %type <entrylist> genericParamList paramTypeList paramList idList paramIdList
211 %type <alist> argumentExprList iterArgList
212 %type <alist> initList
213 %type <flist> structDeclList structDecl
214 %type <srset> locModifies locPlainModifies modList specClauseList
215 %type <sr> mExpr modListExpr specClauseListExpr
218 %type <con> BufConstraint
219 %type <tok> relationalOp
220 %type <tok> BufBinaryOp
221 %type <tok> bufferModifier
223 %type <conE> BufConstraintExpr
225 %type <conE> BufConstraintTerm
226 %type <sr> BufConstraintSrefExpr
228 %type <conL> BufConstraintList
230 %type <tok> BufUnaryOp
232 %type <enumnamelist> enumeratorList
233 %type <cstringlist> fieldDesignator
235 %type <expr> sizeofExpr sizeofExprAux offsetofExpr
236 %type <expr> openScope closeScope
237 %type <expr> instanceDecl namedInitializer optDeclarators
238 %type <expr> primaryExpr postfixExpr primaryIterExpr postfixIterExpr
239 %type <expr> unaryExpr castExpr timesExpr plusExpr
240 %type <expr> unaryIterExpr castIterExpr timesIterExpr plusIterExpr
241 %type <expr> shiftExpr relationalExpr equalityExpr bitandExpr
242 %type <expr> xorExpr bitorExpr andExpr
243 %type <expr> orExpr conditionalExpr assignExpr
244 %type <expr> shiftIterExpr relationalIterExpr equalityIterExpr bitandIterExpr
245 %type <expr> xorIterExpr bitorIterExpr andIterExpr
246 %type <expr> orIterExpr conditionalIterExpr assignIterExpr iterArgExpr
247 %type <expr> expr optExpr constantExpr
248 %type <expr> init macroBody iterBody endBody partialIterStmt iterSelectionStmt
249 %type <expr> stmt stmtList fcnBody iterStmt iterDefStmt iterDefStmtList
250 %type <expr> labeledStmt caseStmt defaultStmt
251 %type <expr> compoundStmt compoundStmtAux compoundStmtRest compoundStmtAuxErr
252 %type <expr> expressionStmt selectionStmt iterationStmt jumpStmt iterDefIterationStmt
253 %type <expr> stmtErr stmtListErr compoundStmtErr expressionStmtErr
254 %type <expr> iterationStmtErr initializerList initializer ifPred whilePred forPred iterWhilePred
257 %type <typequal> storageSpecifier typeQualifier typeModifier globQual
258 %type <tquallist> optGlobQuals
259 %type <qtyp> completeType completeTypeSpecifier optCompleteType
260 %type <qtyp> completeTypeSpecifierAux altType typeExpression
261 /*%type <expr> lclintassertion*/
273 | externalDefs externalDef
276 : fcnDef optSemi { uentry_clearDecl (); }
277 | constantDecl { uentry_clearDecl (); }
278 | fcnDecl { uentry_clearDecl (); }
279 | iterDecl { uentry_clearDecl (); }
280 | macroDef { uentry_clearDecl (); }
281 | initializer { uentry_checkDecl (); exprNode_free ($1); }
282 | error { uentry_clearDecl (); }
285 : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
286 { checkConstant ($2, $4); }
287 | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
288 { checkValueConstant ($2, $4, $8) ; }
291 : QFUNCTION { context_enterFunctionDecl (); } plainFcn optSemi QENDMACRO
292 { declareStaticFunction ($3); context_quietExitFunction ();
293 context_exitFunctionDecl (); }
298 qtype qint = qtype_create (ctype_int);
299 $$ = idDecl_fixBase ($1, qint);
302 | completeTypeSpecifier NotType plainNamedDecl
303 { $$ = idDecl_fixBase ($3, $1); }
307 | pointers plainNamedDeclBase
308 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
311 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
312 | IsType TLPAREN NotType namedDecl IsType TRPAREN
313 { $$ = idDecl_expectFunction ($4); }
314 | namedDeclBase TLSQBR TRSQBR
315 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
316 | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
318 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), exprNode_getLongValue ($4)));
320 | namedDeclBase PushType TLPAREN TRPAREN
321 { setCurrentParams (uentryList_missingParams);
323 optGlobMods optGlobBufConstraints
324 { /* need to support globals and modifies here! */
325 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
326 uentryList_makeMissingParams ());
328 $$ = idDecl_replaceCtype ($1, ct);
331 | namedDeclBase PushType TLPAREN genericParamList TRPAREN
332 { setCurrentParams ($4);
334 optGlobMods optGlobBufConstraints
335 { setImplictfcnConstraints ();
336 clearCurrentParams ();
337 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
342 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
343 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
344 { $$ = idDecl_expectFunction ($4); }
345 | plainNamedDeclBase TLSQBR TRSQBR
346 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
347 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
351 if (exprNode_hasValue ($4)
352 && multiVal_isInt (exprNode_getValue ($4)))
354 value = (int) multiVal_forceInt (exprNode_getValue ($4));
361 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
363 | plainNamedDeclBase PushType TLPAREN TRPAREN
364 { setCurrentParams (uentryList_missingParams);
367 { /* need to support globals and modifies here! */
368 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
369 uentryList_makeMissingParams ());
371 $$ = idDecl_replaceCtype ($1, ct);
374 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
375 { setCurrentParams ($4);
378 { clearCurrentParams ();
379 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
384 : QITER newId TLPAREN genericParamList TRPAREN
385 { setCurrentParams ($4); } optPlainGlobMods
386 { clearCurrentParams (); } optSemi QENDMACRO
387 { declareCIter ($2, $4); }
390 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); }
391 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); }
392 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); }
393 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); }
396 : fcnDefHdrAux { declareFunction ($1); }
399 : { setProcessingGlobMods (); } optGlobModsRest
400 { clearProcessingGlobMods (); }
405 optGlobBufConstraints
406 : { setProcessingGlobMods (); } optGlobBufConstraintsRest
407 { clearProcessingGlobMods (); }
410 optGlobBufConstraintsRest
411 : optGlobBufConstraintsAux optGlobEnsuresConstraintsAux
414 optGlobEnsuresConstraintsAux
416 DPRINTF ( ("doing optGlobEnsuresConstraintsAux\n") );
417 context_setProtectVars (); enterParamsTemp ();
418 sRef_setGlobalScopeSafe ();
420 } QENSURESCONSTRAINT BufConstraintList QENDMACRO
422 setEnsuresConstraints ($3);
424 sRef_clearGlobalScopeSafe ();
425 context_releaseVars ();
426 DPRINTF (("done optGlobBufConstraintsAux\n"));}
430 optGlobBufConstraintsAux
432 DPRINTF ( ("doing optGlobBufConstraintsAux\n") );
433 context_setProtectVars (); enterParamsTemp ();
434 sRef_setGlobalScopeSafe ();
436 } QBUFFERCONSTRAINT BufConstraintList QENDMACRO
438 setFunctionConstraints ($3);
440 sRef_clearGlobalScopeSafe ();
441 context_releaseVars ();
442 DPRINTF (("done optGlobBufConstraintsAux\n"));}
446 : BufConstraint BufConstraintList{ $$ = constraintList_add ($2, $1); }
447 | BufConstraint {constraintList c; c = constraintList_makeNew(); c = constraintList_add (c, $1); $$ = c}
450 : BufConstraintExpr relationalOp BufConstraintExpr TSEMI {
451 $$ = makeConstraintParse3 ($1, $2, $3);
452 DPRINTF(("Done BufConstraint1\n")); }
465 | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3); DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
466 | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
467 DPRINTF( ("Got BufConstraintExpr BINary Op ") );
468 $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
471 : BufConstraintSrefExpr { $$ = constraintExpr_makeTermsRef($1);}
472 | CCONSTANT { char *t; int c;
473 t = cstring_toCharsSafe (exprNode_unparse($1));
475 $$ = constraintExpr_makeIntLiteral (c);
479 BufConstraintSrefExpr
482 checkbufferConstraintClausesId ($1);}
483 | NEW_IDENTIFIER { $$ = fixSpecClausesId ($1); }
485 | BufConstraintSrefExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
486 | BufConstraintSrefExpr TLSQBR CCONSTANT TRSQBR {
488 t = cstring_toCharsSafe (exprNode_unparse($3));
490 $$ = sRef_makeArrayFetchKnown($1, c); }
491 | TMULT BufConstraintSrefExpr { $$ = sRef_constructPointer ($2); }
492 | TLPAREN BufConstraintSrefExpr TRPAREN { $$ = $2; }
493 | BufConstraintSrefExpr TDOT newId { cstring_markOwned ($3);
494 $$ = sRef_buildField ($1, $3); }
495 | BufConstraintSrefExpr ARROW_OP newId { cstring_markOwned ($3);
496 $$ = sRef_makeArrow ($1, $3); }
499 | BufConstraintTerm TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
500 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
501 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
502 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
503 $$ = sRef_buildField ($1, $3); }
521 : { setProcessingGlobMods (); } optPlainGlobModsRest
522 { clearProcessingGlobMods (); }
525 /*: id { $$ = unentry_getSref($1); checkModifiesId ($1); }
526 | NEW_INDENTIFIER { $$ = fixModifiesId ($1)} */
532 : { setProcessingGlobMods (); } optPlainGlobModsRest
533 { clearProcessingGlobMods (); }
537 | specialClauses optGlobModsAux
540 : optPlainGlobModsAux
541 | specialClauses optPlainGlobModsAux
545 | specialClause specialClauses
548 : globIdListExpr { ; }
549 | globIdList TCOMMA globIdListExpr { ; }
552 : optGlobQuals globId { globListAdd ($2, $1); }
555 : id { $$ = uentry_getSref ($1); }
556 | NEW_IDENTIFIER { $$ = globListUnrecognized ($1); }
559 : QUNDEF { $$ = qual_createUndef (); }
560 | QKILLED { $$ = qual_createKilled (); }
561 | QOUT { $$ = qual_createOut (); }
562 | QIN { $$ = qual_createIn (); }
563 | QPARTIAL { $$ = qual_createPartial (); }
566 : /* empty */ { $$ = qualList_undefined; }
567 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
570 : QGLOBALS { setProcessingGlobalsList (); } initializerList optSemi
572 { unsetProcessingGlobals (); }
573 | QGLOBALS { setProcessingGlobalsList (); } globIdList optSemi
575 { unsetProcessingGlobals (); }
577 { setFunctionNoGlobals ();
578 setFunctionModifies (sRefSet_single (sRef_makeNothing ()));
584 : QGLOBALS { setProcessingGlobalsList (); } initializerList optSemi
586 { unsetProcessingGlobals (); }
587 | QGLOBALS { setProcessingGlobalsList (); } globIdList optSemi
589 { unsetProcessingGlobals (); }
591 { setFunctionNoGlobals ();
592 setFunctionModifies (sRefSet_single (sRef_makeNothing ()));
604 context_setProtectVars (); enterParamsTemp ();
605 sRef_setGlobalScopeSafe ();
609 setFunctionModifies ($3); exitParamsTemp ();
610 sRef_clearGlobalScopeSafe ();
611 context_releaseVars ();
617 context_setProtectVars (); enterParamsTemp ();
618 sRef_setGlobalScopeSafe ();
622 setFunctionModifies ($3); exitParamsTemp ();
623 sRef_clearGlobalScopeSafe ();
624 context_releaseVars ();
645 : QONLY { $$ = SP_ISONLY; }
646 | QOBSERVER { $$ = SP_ISOBSERVER; }
647 | QEXPOSED { $$ = SP_ISEXPOSED; }
648 | QDEPENDENT { $$ = SP_ISDEPENDENT; }
649 | QOWNED { $$ = SP_ISOWNED; }
650 | QSHARED { $$ = SP_ISSHARED; }
651 | QISNULL { $$ = SP_ISNULL; }
652 | QNOTNULL { $$ = SP_ISNOTNULL; }
657 context_setProtectVars ();
659 sRef_setGlobalScopeSafe ();
661 specClauseList optSemi endSpecialTag IsType
663 setFunctionSpecialClause ($1, $4, $6);
665 sRef_clearGlobalScopeSafe ();
666 context_releaseVars ();
668 | stateSpecialClause NotType specialClauseType
670 context_setProtectVars ();
672 sRef_setGlobalScopeSafe ();
674 specClauseList optSemi endStateTag IsType
676 setFunctionStateSpecialClause ($1, $3, $5, $7);
678 sRef_clearGlobalScopeSafe ();
679 context_releaseVars ();
685 qtype qint = qtype_create (ctype_int);
686 $$ = idDecl_fixBase ($1, qint);
689 | completeTypeSpecifier NotType namedDecl
690 { $$ = idDecl_fixBase ($3, $1); }
693 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
696 exprNode_checkFunctionBody ($3); $$ = $3;
697 context_exitInner ($3);
700 { doneParams (); context_enterInnerContext (); }
703 context_exitInner ($3);
704 exprNode_checkFunctionBody ($3);
705 $$ = $3; /* old style */
711 context_setFunctionDefined (exprNode_loc ($2));
712 exprNode_checkFunction (context_getHeader (), $2);
715 context_exitFunction ();
719 : modList optSemi QENDMACRO { $$ = $1; }
720 | optSemi QENDMACRO { $$ = sRefSet_new (); }
723 : modList optSemi { $$ = $1; }
724 | optSemi { $$ = sRefSet_new (); }
727 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
728 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
729 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
730 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
731 | TMULT modListExpr { $$ = modListPointer ($2); }
732 | TLPAREN modListExpr TRPAREN { $$ = $2; }
733 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
734 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
738 : modListExpr { $$ = $1; }
739 | CCONSTANT { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
743 : modListExpr { $$ = sRefSet_single ($1); }
744 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
748 { $$ = checkSpecClausesId ($1); }
750 { $$ = fixSpecClausesId ($1); }
751 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
752 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
753 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
754 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
755 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
756 $$ = sRef_buildField ($1, $3); }
757 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
758 $$ = sRef_makeArrow ($1, $3); }
762 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
763 else { $$ = sRefSet_undefined; }
765 | specClauseList TCOMMA specClauseListExpr
766 { if (sRef_isValid ($3))
768 $$ = sRefSet_insert ($1, $3);
777 : id { $$ = exprNode_fromIdentifier ($1); }
778 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
779 | CCONSTANT { $$ = $1; }
780 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
781 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
782 | QEXTENSION { $$ = exprNode_makeError (); }
786 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
787 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
788 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
789 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
790 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $4); }
791 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $4); }
792 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
793 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
796 : assignExpr { $$ = exprNodeList_singleton ($1); }
797 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
801 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
802 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
803 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
804 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
805 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
806 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
807 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
808 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
809 | sizeofExpr { $$ = $1; }
810 | offsetofExpr { $$ = $1; }
813 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
814 | newId { $$ = cstringList_single ($1); }
817 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
818 { $$ = exprNode_offsetof ($4, $7); }
821 : IsType { context_setProtectVars (); }
822 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
825 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); }
826 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); }
827 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); }
828 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); }
832 | TLPAREN typeExpression TRPAREN castExpr
833 { $$ = exprNode_cast ($1, $4, $2); }
837 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
838 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
839 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
843 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
844 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
848 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
849 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
853 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
854 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
855 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
856 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
860 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
861 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
865 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
869 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
874 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
879 { exprNode_produceGuards ($1);
880 context_enterAndClause ($1);
884 $$ = exprNode_op ($1, $4, $2);
885 context_exitAndClause ($$, $4);
892 exprNode_produceGuards ($1);
893 context_enterOrClause ($1);
897 $$ = exprNode_op ($1, $4, $2);
898 context_exitOrClause ($$, $4);
903 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
904 { context_enterFalseClause ($1); } conditionalExpr
905 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
909 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
910 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
911 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
912 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
913 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
914 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
915 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
916 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
917 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
918 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
919 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
923 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
926 : /* empty */ { $$ = exprNode_undefined; }
932 /* instance_orTypeDecl_and_possible_initialization */
935 : instanceDecl { $$ = $1; }
936 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
937 | typeDecl { $$ = exprNode_makeError (); }
940 : completeTypeSpecifier IsType TSEMI { $$ = exprNode_makeError (); }
942 ** This causes r/r conflicts with function definitions.
943 ** Instead we need to snarf one first. (gack)
945 ** | completeTypeSpecifier { setProcessingVars ($1); }
947 ** namedInitializerList IsType TSEMI
948 ** { unsetProcessingVars (); }
951 ** the solution is pretty ugly:
953 | completeTypeSpecifier NotType namedDecl NotType
955 setProcessingVars ($1);
956 processNamedDecl ($3); }
957 IsType optDeclarators TSEMI IsType { unsetProcessingVars (); $$ = $7; }
958 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
959 { setProcessingVars ($1); processNamedDecl ($3);
961 IsType init optDeclarators TSEMI IsType
962 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
963 unsetProcessingVars ();
966 : namedDecl NotType { processNamedDecl ($1); $$ = exprNode_makeError (); }
967 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
968 { $$ = exprNode_makeInitialization ($1, $6); }
972 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
973 NotType namedInitializerList IsType TSEMI { unsetProcessingTypedef (); }
974 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
975 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
978 : { g_expectingTypeName = TRUE; }
981 : { g_expectingTypeName = TRUE; context_pushLoc (); }
984 : namedInitializerListAux IsType { ; }
986 namedInitializerListAux
987 : namedInitializer { ; }
988 | namedInitializerList TCOMMA NotType namedInitializer { ; }
991 : /* empty */ { $$ = exprNode_makeError (); }
992 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
995 : assignExpr { $$ = $1; }
996 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
997 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1002 { $$ = exprNodeList_singleton ($1); }
1003 | initList TCOMMA init
1004 { $$ = exprNodeList_push ($1, $3); }
1007 ** need to do the storage class global hack so tags are
1008 ** declared with the right storage class.
1012 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1013 | QINLINE { $$ = qual_createInline (); }
1014 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1015 | QAUTO { $$ = qual_createAuto (); }
1016 | QREGISTER { $$ = qual_createRegister (); }
1019 : QCONST IsType { $$ = qual_createConst (); }
1020 | QVOLATILE IsType { $$ = qual_createVolatile (); }
1021 | QOUT IsType { $$ = qual_createOut (); }
1022 | QIN IsType { $$ = qual_createIn (); }
1023 | QPARTIAL IsType { $$ = qual_createPartial (); }
1024 | QSPECIAL IsType { $$ = qual_createSpecial (); }
1025 | QOWNED IsType { $$ = qual_createOwned (); }
1026 | QDEPENDENT IsType { $$ = qual_createDependent (); }
1027 | QYIELD IsType { $$ = qual_createYield (); }
1028 | QTEMP IsType { $$ = qual_createTemp (); }
1029 | QONLY IsType { $$ = qual_createOnly (); }
1030 | QKEEP IsType { $$ = qual_createKeep (); }
1031 | QKEPT IsType { $$ = qual_createKept (); }
1032 | QSHARED IsType { $$ = qual_createShared (); }
1033 | QUNIQUE IsType { $$ = qual_createUnique (); }
1034 | QEXITS IsType { $$ = qual_createExits (); }
1035 | QMAYEXIT IsType { $$ = qual_createMayExit (); }
1036 | QTRUEEXIT IsType { $$ = qual_createTrueExit (); }
1037 | QFALSEEXIT IsType { $$ = qual_createFalseExit (); }
1038 | QNEVEREXIT IsType { $$ = qual_createNeverExit (); }
1039 | QNULL IsType { $$ = qual_createNull (); }
1040 | QRELNULL IsType { $$ = qual_createRelNull (); }
1041 | QRETURNED IsType { $$ = qual_createReturned (); }
1042 | QEXPOSED IsType { $$ = qual_createExposed (); }
1043 | QOBSERVER IsType { $$ = qual_createObserver (); }
1044 | QCHECKED IsType { $$ = qual_createChecked (); }
1045 | QCHECKMOD IsType { $$ = qual_createCheckMod (); }
1046 | QUNCHECKED IsType { $$ = qual_createUnchecked (); }
1047 | QCHECKEDSTRICT IsType { $$ = qual_createCheckedStrict (); }
1048 | QTRUENULL IsType { $$ = qual_createTrueNull (); }
1049 | QFALSENULL IsType { $$ = qual_createFalseNull (); }
1050 | QUNUSED IsType { $$ = qual_createUnused (); }
1051 | QEXTERNAL IsType { $$ = qual_createExternal (); }
1052 | QSEF IsType { $$ = qual_createSef (); }
1053 | QABSTRACT IsType { $$ = qual_createAbstract (); }
1054 | QCONCRETE IsType { $$ = qual_createConcrete (); }
1055 | QMUTABLE IsType { $$ = qual_createMutable (); }
1056 | QIMMUTABLE IsType { $$ = qual_createImmutable (); }
1057 | QNOTNULL IsType { $$ = qual_createNotNull (); }
1058 | QREFCOUNTED IsType { $$ = qual_createRefCounted (); }
1059 | QREFS IsType { $$ = qual_createRefs (); }
1060 | QKILLREF IsType { $$ = qual_createKillRef (); }
1061 | QRELDEF IsType { $$ = qual_createRelDef (); }
1062 | QNEWREF IsType { $$ = qual_createNewRef (); }
1063 | QTEMPREF IsType { $$ = qual_createTempRef (); }
1064 | QNULLTERMINATED IsType { $$ = qual_createNullTerminated (); }
1066 /* | QSETBUFFERSIZE IsType { $$ = qual_createSetBufferSize (); } */
1070 : QSHORT { $$ = qual_createShort (); }
1071 | QLONG { $$ = qual_createLong (); }
1072 | QSIGNED { $$ = qual_createSigned (); }
1073 | QUNSIGNED { $$ = qual_createUnsigned (); }
1082 | QANYTYPE NotType { $$ = ctype_unknown; }
1083 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
1084 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1085 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
1089 | typeModifier NotType { $$ = ctype_fromQual ($1); }
1092 : IsType completeTypeSpecifier IsType
1093 { $$ = qtype_resolve ($2); }
1095 completeTypeSpecifier
1096 : completeTypeSpecifierAux { $$ = $1; }
1097 | completeTypeSpecifierAux QALT altType QENDMACRO
1098 { $$ = qtype_mergeAlt ($1, $3); }
1102 | typeExpression TCOMMA altType
1103 { $$ = qtype_mergeAlt ($1, $3); }
1105 completeTypeSpecifierAux
1106 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1107 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1108 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
1111 : /* empty */ { $$ = qtype_unknown (); }
1112 | completeTypeSpecifier { $$ = $1; }
1115 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1116 CreateStructInnerScope
1117 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1119 { $$ = declareStruct ($3, $8); }
1120 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1121 CreateStructInnerScope
1122 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1124 { $$ = declareUnion ($3, $8); }
1125 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
1126 { $$ = declareStruct ($3, uentryList_new ()); }
1127 | NotType CUNION newId IsType TLBRACE TRBRACE
1128 { $$ = declareUnion ($3, uentryList_new ()); }
1129 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1130 CreateStructInnerScope
1131 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1133 { $$ = declareUnnamedStruct ($7); }
1134 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1135 CreateStructInnerScope
1136 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1138 { $$ = declareUnnamedUnion ($7); }
1139 | NotType CSTRUCT IsType TLBRACE TRBRACE
1140 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
1141 | NotType CUNION IsType TLBRACE TRBRACE
1142 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
1143 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
1144 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
1147 : { g_expectingTypeName = FALSE; }
1151 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1152 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1155 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
1156 { $$ = fixUentryList ($3, $1); }
1157 | completeTypeSpecifier IsType TSEMI
1158 { $$ = fixUnnamedDecl ($1); }
1161 : structNamedDecl NotType
1162 { $$ = idDeclList_singleton ($1); }
1163 | structNamedDeclList TCOMMA structNamedDecl NotType
1164 { $$ = idDeclList_add ($1, $3); }
1166 structNamedDecl /* hack to get around namespace problems */
1167 : namedDecl { $$ = $1; }
1168 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1169 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1170 /* Need the IsType in case there is a cast in the constant expression. */
1173 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1174 { $$ = declareUnnamedEnum ($4); }
1175 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1176 { context_popLoc (); $$ = declareEnum ($3, $6); }
1177 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1181 { $$ = enumNameList_single ($1); }
1182 | enumeratorList TCOMMA enumerator
1183 { $$ = enumNameList_push ($1, $3); }
1184 | enumeratorList TCOMMA
1188 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1189 usymtab_supGlobalEntry (ue);
1192 | newId TASSIGN IsType constantExpr
1193 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1194 usymtab_supGlobalEntry (ue);
1200 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1201 | pointers TYPE_NAME
1203 qtype qt = qtype_unknown ();
1205 qtype_adjustPointers ($1, qt);
1206 $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1208 | pointers optNamedDecl
1209 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1213 | pointers namedDeclBase
1214 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1217 : paramTypeList { $$ = handleParamTypeList ($1); }
1218 | NotType paramIdList { $$ = handleParamIdList ($2); }
1221 : QCONST { /* ignored for now */; }
1226 | innerModsList innerMods { ; }
1230 | TMULT innerModsList { $$ = 1; }
1231 | TMULT pointers { $$ = 1 + $2; }
1232 | TMULT innerModsList pointers { $$ = 1 + $3; }
1236 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1239 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1240 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1243 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1245 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1248 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1249 | paramList TCOMMA { storeLoc (); } paramDecl
1250 { $$ = uentryList_add ($1, $4); }
1253 : IsType completeTypeSpecifier optNamedDecl IsType
1255 if (isFlipOldStyle ())
1257 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1263 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1265 | newId /* its an old-style declaration */
1267 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1271 llparseerror (message ("Inconsistent function parameter syntax: %q",
1272 idDecl_unparse (tparam)));
1276 $$ = makeCurrentParam (tparam);
1277 idDecl_free (tparam);
1282 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1285 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1287 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1290 : /* empty */ { $$ = ctype_unknown; }
1294 : IsType TLPAREN NotType abstractDecl TRPAREN
1295 { $$ = ctype_expectFunction ($4); }
1296 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1297 | TLSQBR constantExpr TRSQBR
1298 { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
1299 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1300 | abstractDeclBase TLSQBR constantExpr TRSQBR
1301 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
1302 | IsType TLPAREN TRPAREN
1303 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1304 | IsType TLPAREN paramTypeList TRPAREN
1305 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1306 | abstractDeclBase IsType TLPAREN TRPAREN
1307 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1308 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1309 { $$ = ctype_makeParamsFunction ($1, $4); }
1323 /* | lclintassertion {$$ = $1; printf ("Doing stmt lclintassertion\n"); }*/
1327 : QSETBUFFERSIZE id CCONSTANT QENDMACRO { printf(" QSETBUFFERSIZE id CCONSTANT HEllo World\n"); uentry_setBufferSize($2, $3); $$ = exprNode_createTok ($4);
1329 | QSETSTRINGLENGTH id CCONSTANT QENDMACRO { printf(" QSETSTRINGLENGTH id CCONSTANT HEllo World\n"); uentry_setStringLength($2, $3); $$ = exprNode_createTok ($4);
1331 | QTESTINRANGE id CCONSTANT QENDMACRO {printf(" QTESTINRANGE\n"); uentry_testInRange($2, $3); $$ = exprNode_createTok ($4);
1334 /* | QSETBUFFERSIZE id id {$$ = $2; printf(" QSETBUFFERSIZE id id HEllo World\n");} */
1337 : TCOLON newId { $$ = exprNode_labelMarker ($2); }
1342 : iterDefStmtList { $$ = $1; }
1349 | iterDefStmtList iterDefStmt
1350 { $$ = exprNode_concat ($1, $2); }
1352 iterDefIterationStmt
1353 : iterWhilePred iterDefStmtList
1354 { $$ = exprNode_while ($1, $2); }
1355 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1356 { $$ = exprNode_doWhile ($2, $5); }
1357 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1358 { $$ = exprNode_doWhile ($2, $5); }
1359 | forPred iterDefStmt
1360 { $$ = exprNode_for ($1, $2); }
1363 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1364 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1366 { $$ = exprNode_forPred ($3, $5, $8);
1367 context_enterForClause ($5); }
1370 : ITER_NAME CreateInnerScope TLPAREN
1371 { setProcessingIterVars ($1); }
1373 { $$ = exprNode_iterStart ($1, $5); }
1374 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1380 | openScope initializerList { $$ = $2; }
1385 | iterDefIterationStmt
1388 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1389 | error { $$ = exprNode_makeError (); }
1392 : ifPred iterDefStmt
1393 { /* don't: context_exitTrueClause ($1, $2); */
1394 $$ = exprNode_if ($1, $2);
1398 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1401 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1416 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1418 | error { $$ = exprNode_makeError (); }
1421 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1422 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
1424 /* Note that we can semantically check that the object to the case is
1425 indeed constant. In this case, we may not want to go through this effort */
1428 : CASE constantExpr { context_enterCaseClause ($2); }
1429 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
1430 | QFALLTHROUGH CASE constantExpr { context_enterCaseClause ($3); }
1431 TCOLON { $$ = exprNode_caseMarker ($3, TRUE); }
1434 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1435 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1436 | QFALLTHROUGH DEFAULT { context_enterCaseClause (exprNode_undefined); }
1437 TCOLON { $$ = exprNode_defaultMarker ($2, TRUE); }
1440 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1441 | CreateInnerScope compoundStmtAux
1442 { $$ = $2; context_exitInner ($2); }
1445 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1448 : { context_enterInnerContext (); }
1451 : { context_exitInnerPlain (); }
1453 CreateStructInnerScope
1454 : { context_enterStructInnerContext (); }
1456 DeleteStructInnerScope
1457 : { context_exitStructInnerContext (); }
1459 DeleteInnerScopeSafe
1460 : { context_exitInnerSafe (); }
1463 : TRBRACE { $$ = exprNode_createTok ($1); }
1464 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1465 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1466 | stmtList QNOTREACHED TRBRACE
1467 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1468 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1469 | initializerList QNOTREACHED TRBRACE
1470 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1471 | initializerList stmtList TRBRACE
1472 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1473 | initializerList stmtList QNOTREACHED TRBRACE
1474 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1475 lltok_getLoc ($3)));
1480 : TLBRACE compoundStmtRest
1481 { $$ = exprNode_makeBlock ($2); }
1485 { $$ = exprNode_createTok ($2); }
1486 | TLBRACE stmtListErr TRBRACE
1487 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1488 | TLBRACE initializerList TRBRACE
1489 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1490 | TLBRACE initializerList stmtList TRBRACE
1491 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1495 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1498 : initializer { $$ = $1; }
1499 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1503 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1506 : TSEMI { $$ = exprNode_createTok ($1); }
1507 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1510 : TSEMI { $$ = exprNode_createTok ($1); }
1511 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1512 | expr { $$ = exprNode_checkExpr ($1); }
1515 : CIF TLPAREN expr TRPAREN
1516 { $$ = $3; exprNode_produceGuards ($3); context_enterTrueClause ($3); }
1518 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1519 ** { $$ = $3; context_enterTrueClause (); }
1525 context_exitTrueClause ($1, $2);
1526 $$ = exprNode_if ($1, $2);
1528 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
1530 context_exitClause ($1, $2, $5);
1531 $$ = exprNode_ifelse ($1, $2, $5);
1533 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1534 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1537 : WHILE TLPAREN expr TRPAREN
1538 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1539 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1542 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1545 : ITER_NAME { context_enterIterClause (); }
1546 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1548 compoundStmt endIter DeleteInnerScope
1550 $$ = exprNode_iter ($1, $6, $8, $9);
1555 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1556 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1557 { $$ = exprNodeList_push ($1, $4); }
1560 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1561 | id { $$ = exprNode_iterId ($1); }
1562 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1564 if (uentry_isValid (ue))
1566 $$ = exprNode_iterId (ue);
1570 $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1573 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1576 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1581 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1585 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1586 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1587 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1588 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1589 { $$ = exprNode_vaArg ($1, $3, $5); }
1590 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $4); }
1591 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $4); }
1592 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1593 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1597 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1598 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1599 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1600 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1601 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1602 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1603 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1604 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1605 | sizeofExpr { $$ = $1; }
1609 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1613 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1614 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1615 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1619 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1620 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1624 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1625 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1629 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1630 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1631 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1632 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1635 : relationalIterExpr
1636 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1637 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1641 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1645 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1650 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1654 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1658 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1662 | orExpr TQUEST { context_enterTrueClause ($1); }
1663 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1664 { $$ = exprNode_cond ($1, $4, $7); }
1667 : conditionalIterExpr
1668 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1669 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1670 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1671 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1672 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1673 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1674 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1675 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1676 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1677 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1678 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1681 : ITER_ENDNAME { $$ = $1; }
1682 | /* empty */ { $$ = uentry_undefined; }
1685 : DO { context_enterDoWhileClause (); $$ = $1; }
1689 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1690 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
1691 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1693 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1696 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1697 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1698 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1699 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1700 { $$ = exprNode_doWhile ($2, $5); }
1701 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1704 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1705 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1706 | QINNERCONTINUE CONTINUE TSEMI
1707 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1708 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1709 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1710 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1711 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1712 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1713 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1714 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1725 | ITER_NAME { $$ = uentry_getName ($1); }
1726 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1727 | id { $$ = uentry_getName ($1); }
1728 | TYPE_NAME_OR_ID { $$ = $1; }
1732 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1737 extern char *yytext;
1740 # include "bison.reset"
1742 void yyerror (/*@unused@*/ char *s)
1744 static bool givehint = FALSE;
1746 if (context_inIterDef ())
1748 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1749 context_inFunctionName ()));
1751 else if (context_inIterEnd ())
1753 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1754 context_inFunctionName ()));
1756 else if (context_inMacro ())
1758 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1759 context_inFunctionName ()));
1761 if (context_inMacroUnknown ())
1765 llhint (cstring_makeLiteral
1766 ("Precede macro definition with /*@notfunction@*/ "
1767 "to suppress checking and force expansion"));
1776 llparseerror (cstring_undefined);
1780 void printState (idDecl t) {
1781 cstring id = idDecl_getName (t);
1782 uentry ue = usymtab_lookupSafe (id);
1784 sRef s = uentry_getSref (ue);
1786 printf("State = %d\n", s->bufinfo.bufstate);
1790 /*take this out soon */
1791 /* void testassert1 (cstring id, icstring cons ) { */
1792 /* uentry ue =usymtab_lookupSafe (id); */
1793 /* sRef s = uentry_getSref (ue); */
1794 /* printf ("Doing testassert1 with setbuffersize\n"); */
1795 /* printf("State = %d\n", s->bufinfo.bufstate); */
1797 /* void testassert2 (cstring id) { */
1798 /* uentry ue =usymtab_lookupSafe (id); */
1799 /* sRef s = uentry_getSref (ue); */
1800 /* printf ("Doing testassert2 with setbuffersize\n"); */
1801 /* printf("State = %d\n", s->bufinfo.bufstate); */