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.
83 /*@only@*/ functionClauseList funcclauselist;
84 /*@only@*/ functionClause funcclause;
85 /*@only@*/ flagSpec flagspec;
86 /*@only@*/ globalsClause globsclause;
87 /*@only@*/ modifiesClause modsclause;
88 /*@only@*/ warnClause warnclause;
89 /*@only@*/ stateClause stateclause;
91 /*@only@*/ sRefList srlist;
92 /*@only@*/ globSet globset;
93 /*@only@*/ qtype qtyp;
94 /*@only@*/ cstring cname;
95 /*@observer@*/ annotationInfo annotation;
96 /*@only@*/ idDecl ntyp;
97 /*@only@*/ idDeclList ntyplist;
98 /*@only@*/ uentryList flist;
99 /*@owned@*/ uentryList entrylist;
100 /*@observer@*/ /*@dependent@*/ uentry entry;
101 /*@only@*/ uentry oentry;
102 /*@only@*/ exprNode expr;
103 /*@only@*/ enumNameList enumnamelist;
104 /*@only@*/ exprNodeList alist;
105 /*@only@*/ sRefSet srset;
106 /*@only@*/ cstringList cstringlist;
116 /* standard C tokens */
118 %token <tok> BADTOK SKIPTOK
119 %token <tok> CTOK_ELIPSIS CASE DEFAULT CIF CELSE SWITCH WHILE DO CFOR
120 %token <tok> GOTO CONTINUE BREAK RETURN
121 %token <tok> TSEMI TLBRACE TRBRACE TCOMMA TCOLON TASSIGN TLPAREN
122 %token <tok> TRPAREN TLSQBR TRSQBR TDOT TAMPERSAND TEXCL TTILDE
123 %token <tok> TMINUS TPLUS TMULT TDIV TPERCENT TLT TGT TCIRC TBAR TQUEST
124 %token <tok> CSIZEOF CALIGNOF ARROW_OP CTYPEDEF COFFSETOF
125 %token <tok> INC_OP DEC_OP LEFT_OP RIGHT_OP
126 %token <tok> LE_OP GE_OP EQ_OP NE_OP AND_OP OR_OP
127 %token <tok> MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN SUB_ASSIGN
128 %token <tok> LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
129 %token <tok> CSTRUCT CUNION CENUM
130 %token <tok> VA_ARG VA_DCL
132 %token <tok> QGLOBALS
133 %token <tok> QMODIFIES
135 %token <tok> QCONSTANT
136 %token <tok> QFUNCTION
138 %token <tok> QDEFINES
140 %token <tok> QALLOCATES
142 %token <tok> QRELEASES
143 %token <tok> QPRECLAUSE
144 %token <tok> QPOSTCLAUSE
146 %token <tok> QUNDEF QKILLED
147 %token <tok> QENDMACRO
149 /* additional tokens introduced by lclint pre-processor. */
150 %token <tok> LLMACRO LLMACROITER LLMACROEND TENDMACRO
152 /* break comments: */
153 %token <tok> QSWITCHBREAK QLOOPBREAK QINNERBREAK QSAFEBREAK
154 %token <tok> QINNERCONTINUE
156 /* case fall-through marker: */
157 %token <tok> QFALLTHROUGH
159 /* used in scanner only */
160 %token <tok> QLINTNOTREACHED
161 %token <tok> QLINTFALLTHROUGH
162 %token <tok> QLINTFALLTHRU
163 %token <tok> QARGSUSED
164 %token <tok> QPRINTFLIKE QLINTPRINTFLIKE QSCANFLIKE QMESSAGELIKE
166 /* not-reached marker: (used like a label) */
167 %token <tok> QNOTREACHED
169 /* type qualifiers: */
170 %token <tok> QCONST QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
171 %token <tok> QOUT QIN QYIELD QONLY QTEMP QSHARED QREF QUNIQUE
172 %token <tok> QCHECKED QUNCHECKED QCHECKEDSTRICT QCHECKMOD
173 %token <tok> QKEEP QKEPT QPARTIAL QSPECIAL QOWNED QDEPENDENT
174 %token <tok> QRETURNED QEXPOSED QNULL QOBSERVER QISNULL
175 %token <tok> QEXITS QMAYEXIT QNEVEREXIT QTRUEEXIT QFALSEEXIT
176 %token <tok> QLONG QSIGNED QUNSIGNED QSHORT QUNUSED QSEF QNOTNULL QRELNULL
177 %token <tok> QABSTRACT QCONCRETE QMUTABLE QIMMUTABLE
178 %token <tok> QTRUENULL QFALSENULL QEXTERNAL
179 %token <tok> QREFCOUNTED QREFS QNEWREF QTEMPREF QKILLREF QRELDEF
180 %token <ctyp> CGCHAR CBOOL CINT CGFLOAT CDOUBLE CVOID
181 %token <tok> QANYTYPE QINTEGRALTYPE QUNSIGNEDINTEGRALTYPE QSIGNEDINTEGRALTYPE
183 %type <typequal> nullterminatedQualifier
184 %token <tok> QNULLTERMINATED
185 %token <tok> QSETBUFFERSIZE
186 %token <tok> QBUFFERCONSTRAINT
187 %token <tok> QENSURESCONSTRAINT
188 %token <tok> QSETSTRINGLENGTH
190 %token <tok> QMAXREAD
191 %token <tok> QTESTINRANGE
196 /* identifiers, literals */
197 %token <entry> IDENTIFIER
198 %token <cname> NEW_IDENTIFIER TYPE_NAME_OR_ID
199 %token <annotation> CANNOTATION
200 %token <expr> CCONSTANT
202 %type <flagspec> flagSpec
203 %type <expr> cconstantExpr
204 %token <entry> ITER_NAME ITER_ENDNAME
205 %type <entry> endIter
207 %type <funcclauselist> functionClauses functionClausesPlain
208 %type <funcclause> functionClause functionClause functionClausePlain
210 %type <globsclause> globalsClause globalsClausePlain
211 %type <modsclause> modifiesClause modifiesClausePlain nomodsClause
212 %type <warnclause> warnClause warnClausePlain
213 %type <stateclause> conditionClause conditionClausePlain
214 %type <stateclause> stateClause stateClausePlain
216 %type <sr> globId globIdListExpr
217 %type <globset> globIdList
219 %token <ctyp> TYPE_NAME
220 %type <cname> enumerator newId /*@-varuse@*/ /* yacc declares yytranslate here */
221 %type <count> pointers /*@=varuse@*/
223 %type <tok> doHeader stateTag conditionTag
224 %type <typequal> exitsQualifier checkQualifier stateQualifier
225 paramQualifier returnQualifier visibilityQualifier
226 typedefQualifier refcountQualifier definedQualifier
228 /* type construction */
229 %type <ctyp> abstractDecl abstractDeclBase optAbstractDeclBase
230 %type <ctyp> suSpc enumSpc typeName typeSpecifier
232 %type <ntyp> namedDecl namedDeclBase optNamedDecl
233 %type <ntyp> plainNamedDecl plainNamedDeclBase
234 %type <ntyp> structNamedDecl
235 %type <ntyp> fcnDefHdrAux plainFcn
237 %type <oentry> paramDecl
240 %type <ntyplist> structNamedDeclList
242 %type <entrylist> genericParamList paramTypeList paramList idList paramIdList
243 %type <alist> argumentExprList iterArgList
244 %type <alist> initList
245 %type <flist> structDeclList structDecl
246 %type <srset> locModifies modList specClauseList optSpecClauseList
247 %type <sr> mExpr modListExpr specClauseListExpr
250 %type <con> BufConstraint
251 %type <tok> relationalOp
252 %type <tok> BufBinaryOp
253 %type <tok> bufferModifier
255 %type <conE> BufConstraintExpr
257 %type <conE> BufConstraintTerm
258 %type <sr> BufConstraintSrefExpr
260 %type <conL> BufConstraintList
262 %type <tok> BufUnaryOp
264 %type <enumnamelist> enumeratorList
265 %type <cstringlist> fieldDesignator
267 %type <expr> sizeofExpr sizeofExprAux offsetofExpr
268 %type <expr> openScope closeScope
269 %type <expr> instanceDecl namedInitializer optDeclarators
270 %type <expr> primaryExpr postfixExpr primaryIterExpr postfixIterExpr
271 %type <expr> unaryExpr castExpr timesExpr plusExpr
272 %type <expr> unaryIterExpr castIterExpr timesIterExpr plusIterExpr
273 %type <expr> shiftExpr relationalExpr equalityExpr bitandExpr
274 %type <expr> xorExpr bitorExpr andExpr
275 %type <expr> orExpr conditionalExpr assignExpr
276 %type <expr> shiftIterExpr relationalIterExpr equalityIterExpr bitandIterExpr
277 %type <expr> xorIterExpr bitorIterExpr andIterExpr
278 %type <expr> orIterExpr conditionalIterExpr assignIterExpr iterArgExpr
279 %type <expr> expr optExpr constantExpr
280 %type <expr> init macroBody iterBody endBody partialIterStmt iterSelectionStmt
281 %type <expr> stmt stmtList fcnBody iterStmt iterDefStmt iterDefStmtList
282 %type <expr> labeledStmt caseStmt defaultStmt
283 %type <expr> compoundStmt compoundStmtAux compoundStmtRest compoundStmtAuxErr
284 %type <expr> expressionStmt selectionStmt iterationStmt jumpStmt iterDefIterationStmt
285 %type <expr> stmtErr stmtListErr compoundStmtErr expressionStmtErr
286 %type <expr> iterationStmtErr initializerList initializer ifPred whilePred forPred iterWhilePred
288 %type <typequal> storageSpecifier typeQualifier typeModifier globQual
289 %type <tquallist> optGlobQuals
290 %type <qtyp> completeType completeTypeSpecifier optCompleteType
291 %type <qtyp> completeTypeSpecifierAux altType typeExpression
292 /*%type <expr> lclintassertion*/
304 | externalDefs externalDef
307 : fcnDef optSemi { uentry_clearDecl (); }
308 | constantDecl { uentry_clearDecl (); }
309 | fcnDecl { uentry_clearDecl (); }
310 | iterDecl { uentry_clearDecl (); }
311 | macroDef { uentry_clearDecl (); }
312 | initializer { uentry_checkDecl (); exprNode_free ($1); }
313 | error { uentry_clearDecl (); }
316 : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
317 { checkConstant ($2, $4); }
318 | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
319 { checkValueConstant ($2, $4, $8) ; }
322 : QFUNCTION { context_enterFunctionHeader (); } plainFcn optSemi QENDMACRO
324 declareStaticFunction ($3); context_quietExitFunction ();
325 context_exitFunctionHeader ();
331 qtype qint = qtype_create (ctype_int);
332 $$ = idDecl_fixBase ($1, qint);
335 | completeTypeSpecifier NotType plainNamedDecl
336 { $$ = idDecl_fixBase ($3, $1); }
340 | pointers plainNamedDeclBase
341 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
344 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
345 | IsType TLPAREN NotType namedDecl IsType TRPAREN
346 { $$ = idDecl_expectFunction ($4); }
347 | namedDeclBase TLSQBR TRSQBR
348 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
349 | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
351 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), exprNode_getLongValue ($4)));
353 | namedDeclBase PushType TLPAREN TRPAREN
354 { setCurrentParams (uentryList_missingParams); }
356 optGlobBufConstraints
357 { /* need to support globals and modifies here! */
358 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
359 uentryList_makeMissingParams ());
361 $$ = idDecl_replaceCtype ($1, ct);
362 idDecl_addClauses ($$, $6);
365 | namedDeclBase PushType TLPAREN genericParamList TRPAREN
366 { setCurrentParams ($4); }
368 optGlobBufConstraints
369 { setImplictfcnConstraints ();
370 clearCurrentParams ();
371 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
372 idDecl_addClauses ($$, $7);
377 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
378 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
379 { $$ = idDecl_expectFunction ($4); }
380 | plainNamedDeclBase TLSQBR TRSQBR
381 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
382 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
386 if (exprNode_hasValue ($4)
387 && multiVal_isInt (exprNode_getValue ($4)))
389 value = (int) multiVal_forceInt (exprNode_getValue ($4));
396 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
398 | plainNamedDeclBase PushType TLPAREN TRPAREN
399 { setCurrentParams (uentryList_missingParams); }
402 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
403 uentryList_makeMissingParams ());
405 $$ = idDecl_replaceCtype ($1, ct);
406 idDecl_addClauses ($$, $6);
409 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
410 { setCurrentParams ($4); }
413 clearCurrentParams ();
414 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
415 idDecl_addClauses ($$, $7);
420 : QITER newId TLPAREN genericParamList TRPAREN
421 { setCurrentParams ($4); } functionClausesPlain
422 { clearCurrentParams (); } optSemi QENDMACRO
423 { declareCIter ($2, $4); }
426 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); }
427 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); }
428 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); }
429 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); }
432 : fcnDefHdrAux { clabstract_declareFunction ($1); }
436 optGlobBufConstraints
437 : { setProcessingGlobMods (); } optGlobBufConstraintsRest
438 { clearProcessingGlobMods (); }
440 optGlobBufConstraintsRest
441 : optGlobBufConstraintsAux optGlobEnsuresConstraintsAux
444 optGlobEnsuresConstraintsAux
446 DPRINTF ( ("doing optGlobEnsuresConstraintsAux\n") );
447 context_setProtectVars (); enterParamsTemp ();
448 sRef_setGlobalScopeSafe ();
450 } QENSURESCONSTRAINT BufConstraintList optSemi QENDMACRO
452 setEnsuresConstraints ($3);
454 sRef_clearGlobalScopeSafe ();
455 context_releaseVars ();
456 DPRINTF (("done optGlobBufConstraintsAux\n"));}
460 optGlobBufConstraintsAux
462 DPRINTF ( ("doing optGlobBufConstraintsAux\n") );
463 context_setProtectVars (); enterParamsTemp ();
464 sRef_setGlobalScopeSafe ();
466 } QBUFFERCONSTRAINT BufConstraintList optSemi QENDMACRO
468 setFunctionConstraints ($3);
470 sRef_clearGlobalScopeSafe ();
471 context_releaseVars ();
472 DPRINTF (("done optGlobBufConstraintsAux\n"));}
476 : BufConstraint TCAND BufConstraintList { $$ = constraintList_add ($3, $1); }
477 | BufConstraint {constraintList c; c = constraintList_makeNew(); c = constraintList_add (c, $1); $$ = c}
480 : BufConstraintExpr relationalOp BufConstraintExpr {
481 $$ = makeConstraintParse3 ($1, $2, $3);
482 DPRINTF(("Done BufConstraint1\n")); }
495 | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3); DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
496 | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
497 DPRINTF( ("Got BufConstraintExpr BINary Op ") );
498 $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
501 : BufConstraintSrefExpr { $$ = constraintExpr_makeTermsRef($1);}
502 | CCONSTANT { char *t; int c;
503 t = cstring_toCharsSafe (exprNode_unparse($1));
505 $$ = constraintExpr_makeIntLiteral (c);
509 BufConstraintSrefExpr
512 checkbufferConstraintClausesId ($1);}
513 | NEW_IDENTIFIER { $$ = fixStateClausesId ($1); }
515 | BufConstraintSrefExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
516 | BufConstraintSrefExpr TLSQBR CCONSTANT TRSQBR {
518 t = cstring_toCharsSafe (exprNode_unparse($3));
520 $$ = sRef_makeArrayFetchKnown($1, c); }
521 | TMULT BufConstraintSrefExpr { $$ = sRef_constructPointer ($2); }
522 | TLPAREN BufConstraintSrefExpr TRPAREN { $$ = $2; }
523 | BufConstraintSrefExpr TDOT newId { cstring_markOwned ($3);
524 $$ = sRef_buildField ($1, $3); }
525 | BufConstraintSrefExpr ARROW_OP newId { cstring_markOwned ($3);
526 $$ = sRef_makeArrow ($1, $3); }
529 | BufConstraintTerm TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
530 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
531 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
532 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
533 $$ = sRef_buildField ($1, $3); }
549 ** Function clauses can appear in any order.
553 : { $$ = functionClauseList_new (); }
554 | functionClause functionClauses
555 { $$ = functionClauseList_prepend ($2, $1); }
558 ** Inside macro definitions, there are no end macros.
563 { $$ = functionClauseList_new (); }
564 | functionClausePlain functionClausesPlain
565 { $$ = functionClauseList_prepend ($2, $1); }
568 : globalsClause { $$ = functionClause_createGlobals ($1); }
569 | modifiesClause { $$ = functionClause_createModifies ($1); }
570 | nomodsClause { $$ = functionClause_createModifies ($1); }
571 | stateClause { $$ = functionClause_createState ($1); }
572 | conditionClause { $$ = functionClause_createState ($1); }
573 | warnClause { $$ = functionClause_createWarn ($1); }
576 : globalsClausePlain { $$ = functionClause_createGlobals ($1); }
577 | modifiesClausePlain { $$ = functionClause_createModifies ($1); }
578 | nomodsClause { $$ = functionClause_createModifies ($1); }
579 | stateClausePlain { $$ = functionClause_createState ($1); }
580 | conditionClausePlain { $$ = functionClause_createState ($1); }
581 | warnClausePlain { $$ = functionClause_createWarn ($1); }
584 : globalsClausePlain QENDMACRO { $$ = $1; }
587 : QGLOBALS { setProcessingGlobalsList (); }
590 unsetProcessingGlobals ();
591 $$ = globalsClause_create ($1, $3);
595 : QNOMODS { $$ = modifiesClause_createNoMods ($1); }
598 : modifiesClausePlain QENDMACRO { $$ = $1; }
603 context_setProtectVars (); enterParamsTemp ();
604 sRef_setGlobalScopeSafe ();
609 sRef_clearGlobalScopeSafe ();
610 context_releaseVars ();
611 $$ = modifiesClause_create ($1, $3);
616 { $$ = flagSpec_createPlain ($1); }
617 | flagId TBAR flagSpec
618 { $$ = flagSpec_createOr ($1, $3); }
624 : warnClausePlain QENDMACRO { $$ = $1; }
627 : QWARN flagSpec cconstantExpr
628 { $$ = warnClause_create ($1, $2, $3); }
630 { $$ = warnClause_create ($1, $2, exprNode_undefined); }
633 : globIdListExpr { $$ = globSet_single ($1); }
634 | globIdList TCOMMA globIdListExpr { $$ = globSet_insert ($1, $3); }
637 : optGlobQuals globId { $$ = clabstract_createGlobal ($2, $1); }
640 : /* empty */ { $$ = qualList_undefined; }
641 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
644 : id { $$ = uentry_getSref ($1); }
645 | NEW_IDENTIFIER { $$ = clabstract_unrecognizedGlobal ($1); }
646 | initializer { $$ = clabstract_checkGlobal ($1); }
649 : QUNDEF { $$ = qual_createUndef (); }
650 | QKILLED { $$ = qual_createKilled (); }
651 | QOUT { $$ = qual_createOut (); }
652 | QIN { $$ = qual_createIn (); }
653 | QPARTIAL { $$ = qual_createPartial (); }
669 qtype qint = qtype_create (ctype_int);
670 $$ = idDecl_fixBase ($1, qint);
673 | completeTypeSpecifier NotType namedDecl
674 { $$ = idDecl_fixBase ($3, $1); }
677 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
680 exprNode_checkFunctionBody ($3); $$ = $3;
681 context_exitInner ($3);
684 { doneParams (); context_enterInnerContext (); }
687 context_exitInner ($3);
688 exprNode_checkFunctionBody ($3);
689 $$ = $3; /* old style */
695 context_setFunctionDefined (exprNode_loc ($2));
696 exprNode_checkFunction (context_getHeader (), $2);
699 context_exitFunction ();
703 : modList optSemi { $$ = $1; }
704 | optSemi { $$ = sRefSet_new (); }
707 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
708 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
709 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
710 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
711 | TMULT modListExpr { $$ = modListPointer ($2); }
712 | TLPAREN modListExpr TRPAREN { $$ = $2; }
713 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
714 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
718 : modListExpr { $$ = $1; }
719 | cconstantExpr { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
723 : modListExpr { $$ = sRefSet_single ($1); }
724 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
728 { $$ = checkStateClausesId ($1); }
730 { $$ = fixStateClausesId ($1); }
731 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
732 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
733 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
734 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
735 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
736 $$ = sRef_buildField ($1, $3); }
737 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
738 $$ = sRef_makeArrow ($1, $3); }
741 : /* empty */ { $$ = sRefSet_undefined }
746 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
747 else { $$ = sRefSet_undefined; }
749 | specClauseList TCOMMA specClauseListExpr
750 { if (sRef_isValid ($3))
752 $$ = sRefSet_insert ($1, $3);
761 : id { $$ = exprNode_fromIdentifier ($1); }
762 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
764 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
765 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
766 | QEXTENSION { $$ = exprNode_makeError (); }
770 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
771 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
772 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
773 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
774 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
775 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
776 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
777 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
780 : assignExpr { $$ = exprNodeList_singleton ($1); }
781 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
785 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
786 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
787 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
788 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
789 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
790 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
791 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
792 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
793 | sizeofExpr { $$ = $1; }
794 | offsetofExpr { $$ = $1; }
797 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
798 | newId { $$ = cstringList_single ($1); }
801 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
802 { $$ = exprNode_offsetof ($4, $7); }
805 : IsType { context_setProtectVars (); }
806 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
809 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); }
810 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); }
811 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); }
812 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); }
816 | TLPAREN typeExpression TRPAREN castExpr
817 { $$ = exprNode_cast ($1, $4, $2); }
821 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
822 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
823 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
827 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
828 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
832 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
833 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
837 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
838 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
839 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
840 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
844 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
845 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
849 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
853 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
858 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
863 { exprNode_produceGuards ($1);
864 context_enterAndClause ($1);
868 $$ = exprNode_op ($1, $4, $2);
869 context_exitAndClause ($$, $4);
876 exprNode_produceGuards ($1);
877 context_enterOrClause ($1);
881 $$ = exprNode_op ($1, $4, $2);
882 context_exitOrClause ($$, $4);
887 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
888 { context_enterFalseClause ($1); } conditionalExpr
889 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
893 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
894 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
895 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
896 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
897 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
898 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
899 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
900 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
901 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
902 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
903 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
907 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
910 : /* empty */ { $$ = exprNode_undefined; }
916 /* instance_orTypeDecl_and_possible_initialization */
919 : instanceDecl { $$ = $1; }
920 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
921 | typeDecl { $$ = exprNode_makeError (); }
924 : completeTypeSpecifier IsType TSEMI
925 { $$ = exprNode_makeError (); }
927 ** This causes r/r conflicts with function definitions.
928 ** Instead we need to snarf one first. (gack)
930 ** | completeTypeSpecifier { setProcessingVars ($1); }
932 ** namedInitializerList IsType TSEMI
933 ** { unsetProcessingVars (); }
936 ** the solution is pretty ugly:
938 | completeTypeSpecifier NotType namedDecl NotType
940 setProcessingVars ($1);
941 processNamedDecl ($3);
943 IsType optDeclarators TSEMI IsType
945 unsetProcessingVars ();
946 $$ = exprNode_makeEmptyInitialization ($3);
947 DPRINTF (("Empty initialization: %s", exprNode_unparse ($$)));
949 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
950 { setProcessingVars ($1); processNamedDecl ($3); }
951 IsType init optDeclarators TSEMI IsType
952 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
953 unsetProcessingVars ();
959 processNamedDecl ($1);
960 $$ = exprNode_makeEmptyInitialization ($1);
962 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
963 { $$ = exprNode_makeInitialization ($1, $6); }
966 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
967 NotType namedInitializerList IsType TSEMI { unsetProcessingTypedef (); }
968 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
969 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
972 : { g_expectingTypeName = TRUE; }
975 : { g_expectingTypeName = TRUE; context_pushLoc (); }
978 : namedInitializerListAux IsType { ; }
980 namedInitializerListAux
981 : namedInitializer { ; }
982 | namedInitializerList TCOMMA NotType namedInitializer { ; }
985 : /* empty */ { $$ = exprNode_makeError (); }
986 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
990 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
991 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
996 { $$ = exprNodeList_singleton ($1); }
997 | initList TCOMMA init
998 { $$ = exprNodeList_push ($1, $3); }
1001 ** need to do the storage class global hack so tags are
1002 ** declared with the right storage class.
1006 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1007 | QINLINE { $$ = qual_createInline (); }
1008 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1009 | QAUTO { $$ = qual_createAuto (); }
1010 | QREGISTER { $$ = qual_createRegister (); }
1012 nullterminatedQualifier:
1013 QNULLTERMINATED IsType { $$ = qual_createNullTerminated (); }
1016 : stateClausePlain QENDMACRO { $$ = $1; }
1021 context_setProtectVars ();
1023 sRef_setGlobalScopeSafe ();
1025 specClauseList optSemi IsType
1028 sRef_clearGlobalScopeSafe ();
1029 context_releaseVars ();
1030 $$ = stateClause_createPlain ($1, $4);
1034 : conditionClausePlain QENDMACRO { $$ = $1; }
1036 conditionClausePlain
1037 : conditionTag { context_enterFunctionHeader (); } NotType stateQualifier
1039 context_exitFunctionHeader ();
1040 context_setProtectVars ();
1042 sRef_setGlobalScopeSafe ();
1044 optSpecClauseList optSemi IsType
1047 sRef_clearGlobalScopeSafe ();
1048 context_releaseVars ();
1049 $$ = stateClause_create ($1, $4, $6);
1053 : QEXITS { $$ = qual_createExits (); }
1054 | QMAYEXIT { $$ = qual_createMayExit (); }
1055 | QTRUEEXIT { $$ = qual_createTrueExit (); }
1056 | QFALSEEXIT { $$ = qual_createFalseExit (); }
1057 | QNEVEREXIT { $$ = qual_createNeverExit (); }
1060 : QCHECKED { $$ = qual_createChecked (); }
1061 | QCHECKMOD { $$ = qual_createCheckMod (); }
1062 | QUNCHECKED { $$ = qual_createUnchecked (); }
1063 | QCHECKEDSTRICT { $$ = qual_createCheckedStrict (); }
1066 : QOWNED { $$ = qual_createOwned (); }
1067 | QDEPENDENT { $$ = qual_createDependent (); }
1068 | QYIELD { $$ = qual_createYield (); }
1069 | QTEMP { $$ = qual_createTemp (); }
1070 | QONLY { $$ = qual_createOnly (); }
1071 | QKEEP { $$ = qual_createKeep (); }
1072 | QKEPT { $$ = qual_createKept (); }
1073 | QSHARED { $$ = qual_createShared (); }
1074 | QUNIQUE { $$ = qual_createUnique (); }
1075 | QNULL { $$ = qual_createNull (); }
1076 | QISNULL { $$ = qual_createIsNull (); }
1077 | QRELNULL { $$ = qual_createRelNull (); }
1078 | QNOTNULL { $$ = qual_createNotNull (); }
1079 | QEXPOSED { $$ = qual_createExposed (); }
1080 | QOBSERVER { $$ = qual_createObserver (); }
1081 | CANNOTATION { $$ = qual_createMetaState ($1); }
1084 : QRETURNED { $$ = qual_createReturned (); }
1085 | QSEF { $$ = qual_createSef (); }
1088 : QUNUSED { $$ = qual_createUnused (); }
1089 | QEXTERNAL { $$ = qual_createExternal (); }
1092 : QTRUENULL { $$ = qual_createTrueNull (); }
1093 | QFALSENULL { $$ = qual_createFalseNull (); }
1096 : QABSTRACT { $$ = qual_createAbstract (); }
1097 | QCONCRETE { $$ = qual_createConcrete (); }
1098 | QMUTABLE { $$ = qual_createMutable (); }
1099 | QIMMUTABLE { $$ = qual_createImmutable (); }
1102 : QREFCOUNTED { $$ = qual_createRefCounted (); }
1103 | QREFS { $$ = qual_createRefs (); }
1104 | QKILLREF { $$ = qual_createKillRef (); }
1105 | QRELDEF { $$ = qual_createRelDef (); }
1106 | QNEWREF { $$ = qual_createNewRef (); }
1107 | QTEMPREF { $$ = qual_createTempRef (); }
1110 : QSHORT { $$ = qual_createShort (); }
1111 | QLONG { $$ = qual_createLong (); }
1112 | QSIGNED { $$ = qual_createSigned (); }
1113 | QUNSIGNED { $$ = qual_createUnsigned (); }
1116 : QOUT { $$ = qual_createOut (); }
1117 | QIN { $$ = qual_createIn (); }
1118 | QPARTIAL { $$ = qual_createPartial (); }
1119 | QSPECIAL { $$ = qual_createSpecial (); }
1122 : QCONST IsType { $$ = qual_createConst (); }
1123 | QVOLATILE IsType { $$ = qual_createVolatile (); }
1124 | definedQualifier IsType { $$ = $1; }
1125 | stateQualifier IsType { $$ = $1; }
1126 | exitsQualifier IsType { $$ = $1; }
1127 | paramQualifier IsType { $$ = $1; }
1128 | checkQualifier IsType { $$ = $1; }
1129 | returnQualifier IsType { $$ = $1; }
1130 | visibilityQualifier IsType { $$ = $1; }
1131 | typedefQualifier IsType { $$ = $1; }
1132 | refcountQualifier IsType { $$ = $1; }
1135 ** This is copied into the mtgrammar!
1145 | QANYTYPE NotType { $$ = ctype_unknown; }
1146 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
1147 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1148 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
1152 | typeModifier NotType { $$ = ctype_fromQual ($1); }
1155 : IsType completeTypeSpecifier IsType
1156 { $$ = qtype_resolve ($2); }
1158 completeTypeSpecifier
1159 : completeTypeSpecifierAux { $$ = $1; }
1160 | completeTypeSpecifierAux QALT altType QENDMACRO
1161 { $$ = qtype_mergeAlt ($1, $3); }
1165 | typeExpression TCOMMA altType
1166 { $$ = qtype_mergeAlt ($1, $3); }
1168 completeTypeSpecifierAux
1169 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1170 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1171 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
1174 : /* empty */ { $$ = qtype_unknown (); }
1175 | completeTypeSpecifier { $$ = $1; }
1178 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1179 CreateStructInnerScope
1180 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1182 { $$ = declareStruct ($3, $8); }
1183 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1184 CreateStructInnerScope
1185 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1187 { $$ = declareUnion ($3, $8); }
1188 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
1189 { $$ = declareStruct ($3, uentryList_new ()); }
1190 | NotType CUNION newId IsType TLBRACE TRBRACE
1191 { $$ = declareUnion ($3, uentryList_new ()); }
1192 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1193 CreateStructInnerScope
1194 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1196 { $$ = declareUnnamedStruct ($7); }
1197 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1198 CreateStructInnerScope
1199 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1201 { $$ = declareUnnamedUnion ($7); }
1202 | NotType CSTRUCT IsType TLBRACE TRBRACE
1203 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
1204 | NotType CUNION IsType TLBRACE TRBRACE
1205 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
1206 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
1207 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
1210 : { g_expectingTypeName = FALSE; }
1214 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1215 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1218 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
1219 { $$ = fixUentryList ($3, $1); }
1220 | completeTypeSpecifier IsType TSEMI
1221 { $$ = fixUnnamedDecl ($1); }
1224 : structNamedDecl NotType
1225 { $$ = idDeclList_singleton ($1); }
1226 | structNamedDeclList TCOMMA structNamedDecl NotType
1227 { $$ = idDeclList_add ($1, $3); }
1229 structNamedDecl /* hack to get around namespace problems */
1230 : namedDecl { $$ = $1; }
1231 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1232 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1233 /* Need the IsType in case there is a cast in the constant expression. */
1236 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1237 { $$ = declareUnnamedEnum ($4); }
1238 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1239 { context_popLoc (); $$ = declareEnum ($3, $6); }
1240 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1244 { $$ = enumNameList_single ($1); }
1245 | enumeratorList TCOMMA enumerator
1246 { $$ = enumNameList_push ($1, $3); }
1247 | enumeratorList TCOMMA
1251 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1252 usymtab_supGlobalEntry (ue);
1255 | newId TASSIGN IsType constantExpr
1256 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1257 usymtab_supGlobalEntry (ue);
1263 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1264 | pointers TYPE_NAME
1266 qtype qt = qtype_unknown ();
1268 qtype_adjustPointers ($1, qt);
1269 $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1271 | pointers optNamedDecl
1272 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1276 | pointers namedDeclBase
1277 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1280 : paramTypeList { $$ = handleParamTypeList ($1); }
1281 | NotType paramIdList { $$ = handleParamIdList ($2); }
1284 : QCONST { /* ignored for now */; }
1289 | innerModsList innerMods { ; }
1293 | TMULT innerModsList { $$ = 1; }
1294 | TMULT pointers { $$ = 1 + $2; }
1295 | TMULT innerModsList pointers { $$ = 1 + $3; }
1299 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1302 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1303 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1306 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1308 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1311 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1312 | paramList TCOMMA { storeLoc (); } paramDecl
1313 { $$ = uentryList_add ($1, $4); }
1316 : IsType completeTypeSpecifier optNamedDecl IsType
1318 if (isFlipOldStyle ())
1320 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1326 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1328 | newId /* its an old-style declaration */
1330 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1334 llparseerror (message ("Inconsistent function parameter syntax: %q",
1335 idDecl_unparse (tparam)));
1339 $$ = makeCurrentParam (tparam);
1340 idDecl_free (tparam);
1345 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1348 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1350 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1353 : /* empty */ { $$ = ctype_unknown; }
1357 : IsType TLPAREN NotType abstractDecl TRPAREN
1358 { $$ = ctype_expectFunction ($4); }
1359 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1360 | TLSQBR constantExpr TRSQBR
1361 { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
1362 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1363 | abstractDeclBase TLSQBR constantExpr TRSQBR
1364 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
1365 | IsType TLPAREN TRPAREN
1366 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1367 | IsType TLPAREN paramTypeList TRPAREN
1368 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1369 | abstractDeclBase IsType TLPAREN TRPAREN
1370 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1371 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1372 { $$ = ctype_makeParamsFunction ($1, $4); }
1386 /* | lclintassertion {$$ = $1; printf ("Doing stmt lclintassertion\n"); }*/
1390 : QSETBUFFERSIZE id CCONSTANT QENDMACRO { printf(" QSETBUFFERSIZE id CCONSTANT HEllo World\n"); uentry_setBufferSize($2, $3); $$ = exprNode_createTok ($4);
1392 | QSETSTRINGLENGTH id CCONSTANT QENDMACRO { printf(" QSETSTRINGLENGTH id CCONSTANT HEllo World\n"); uentry_setStringLength($2, $3); $$ = exprNode_createTok ($4);
1394 | QTESTINRANGE id CCONSTANT QENDMACRO {printf(" QTESTINRANGE\n"); uentry_testInRange($2, $3); $$ = exprNode_createTok ($4);
1397 /* | QSETBUFFERSIZE id id {$$ = $2; printf(" QSETBUFFERSIZE id id HEllo World\n");} */
1400 : iterDefStmtList { $$ = $1; }
1407 | iterDefStmtList iterDefStmt
1408 { $$ = exprNode_concat ($1, $2); }
1410 iterDefIterationStmt
1411 : iterWhilePred iterDefStmtList
1412 { $$ = exprNode_while ($1, $2); }
1413 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1414 { $$ = exprNode_doWhile ($2, $5); }
1415 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1416 { $$ = exprNode_doWhile ($2, $5); }
1417 | forPred iterDefStmt
1418 { $$ = exprNode_for ($1, $2); }
1421 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1422 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1424 { $$ = exprNode_forPred ($3, $5, $8);
1425 context_enterForClause ($5); }
1428 : ITER_NAME CreateInnerScope TLPAREN
1429 { setProcessingIterVars ($1); }
1431 { $$ = exprNode_iterStart ($1, $5); }
1432 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1438 | openScope initializerList { $$ = $1; DPRINTF (("def stmt: %s", exprNode_unparse ($$))); }
1443 | iterDefIterationStmt
1446 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1447 | error { $$ = exprNode_makeError (); }
1450 : ifPred iterDefStmt
1451 { /* don't: context_exitTrueClause ($1, $2); */
1452 $$ = exprNode_if ($1, $2);
1456 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1459 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1474 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1476 | error { $$ = exprNode_makeError (); }
1479 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1480 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
1482 /* Note that we can semantically check that the object to the case is
1483 indeed constant. In this case, we may not want to go through this effort */
1486 : CASE constantExpr { context_enterCaseClause ($2); }
1487 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
1488 | QFALLTHROUGH CASE constantExpr { context_enterCaseClause ($3); }
1489 TCOLON { $$ = exprNode_caseMarker ($3, TRUE); }
1492 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1493 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1494 | QFALLTHROUGH DEFAULT { context_enterCaseClause (exprNode_undefined); }
1495 TCOLON { $$ = exprNode_defaultMarker ($2, TRUE); }
1498 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1499 | CreateInnerScope compoundStmtAux
1500 { $$ = $2; context_exitInner ($2); }
1503 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1506 : { context_enterInnerContext (); }
1509 : { context_exitInnerPlain (); }
1511 CreateStructInnerScope
1512 : { context_enterStructInnerContext (); }
1514 DeleteStructInnerScope
1515 : { context_exitStructInnerContext (); }
1517 DeleteInnerScopeSafe
1518 : { context_exitInnerSafe (); }
1521 : TRBRACE { $$ = exprNode_createTok ($1); }
1522 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1523 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1524 | stmtList QNOTREACHED TRBRACE
1525 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1526 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1527 | initializerList QNOTREACHED TRBRACE
1528 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1529 | initializerList stmtList TRBRACE
1530 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1531 | initializerList stmtList QNOTREACHED TRBRACE
1532 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1533 lltok_getLoc ($3)));
1538 : TLBRACE compoundStmtRest
1539 { $$ = exprNode_makeBlock ($2); }
1543 { $$ = exprNode_createTok ($2); }
1544 | TLBRACE stmtListErr TRBRACE
1545 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1546 | TLBRACE initializerList TRBRACE
1547 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1548 | TLBRACE initializerList stmtList TRBRACE
1549 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1553 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1556 : initializer { $$ = $1; }
1557 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1561 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1564 : TSEMI { $$ = exprNode_createTok ($1); }
1565 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1568 : TSEMI { $$ = exprNode_createTok ($1); }
1569 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1570 | expr { $$ = exprNode_checkExpr ($1); }
1573 : CIF TLPAREN expr TRPAREN
1574 { $$ = $3; exprNode_produceGuards ($3); context_enterTrueClause ($3); }
1576 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1577 ** { $$ = $3; context_enterTrueClause (); }
1583 context_exitTrueClause ($1, $2);
1584 $$ = exprNode_if ($1, $2);
1586 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
1588 context_exitClause ($1, $2, $5);
1589 $$ = exprNode_ifelse ($1, $2, $5);
1591 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1592 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1595 : WHILE TLPAREN expr TRPAREN
1596 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1597 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1600 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1603 : ITER_NAME { context_enterIterClause (); }
1604 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1606 compoundStmt endIter DeleteInnerScope
1608 $$ = exprNode_iter ($1, $6, $8, $9);
1613 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1614 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1615 { $$ = exprNodeList_push ($1, $4); }
1618 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1619 | id { $$ = exprNode_iterId ($1); }
1620 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1622 if (uentry_isValid (ue))
1624 $$ = exprNode_iterId (ue);
1628 $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1631 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1634 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1639 | cconstantExpr CCONSTANT { $$ = exprNode_combineLiterals ($1, $2); }
1643 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1647 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1648 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1649 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1650 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1651 { $$ = exprNode_vaArg ($1, $3, $5); }
1652 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
1653 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
1654 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1655 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1659 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1660 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1661 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1662 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1663 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1664 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1665 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1666 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1667 | sizeofExpr { $$ = $1; }
1671 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1675 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1676 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1677 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1681 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1682 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1686 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1687 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1691 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1692 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1693 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1694 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1697 : relationalIterExpr
1698 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1699 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1703 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1707 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1712 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1716 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1720 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1724 | orExpr TQUEST { context_enterTrueClause ($1); }
1725 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1726 { $$ = exprNode_cond ($1, $4, $7); }
1729 : conditionalIterExpr
1730 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1731 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1732 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1733 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1734 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1735 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1736 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1737 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1738 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1739 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1740 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1743 : ITER_ENDNAME { $$ = $1; }
1744 | /* empty */ { $$ = uentry_undefined; }
1747 : DO { context_enterDoWhileClause (); $$ = $1; }
1751 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1752 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
1753 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1755 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1758 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1759 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1760 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1761 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1762 { $$ = exprNode_doWhile ($2, $5); }
1763 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1766 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1767 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1768 | QINNERCONTINUE CONTINUE TSEMI
1769 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1770 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1771 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1772 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1773 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1774 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1775 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1776 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1787 | ITER_NAME { $$ = uentry_getName ($1); }
1788 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1789 | id { $$ = uentry_getName ($1); }
1790 | TYPE_NAME_OR_ID { $$ = $1; }
1794 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1799 extern char *yytext;
1802 # include "bison.reset"
1804 void yyerror (/*@unused@*/ char *s)
1806 static bool givehint = FALSE;
1808 if (context_inIterDef ())
1810 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1811 context_inFunctionName ()));
1813 else if (context_inIterEnd ())
1815 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1816 context_inFunctionName ()));
1818 else if (context_inMacro ())
1820 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1821 context_inFunctionName ()));
1823 if (context_inMacroUnknown ())
1827 llhint (cstring_makeLiteral
1828 ("Precede macro definition with /*@notfunction@*/ "
1829 "to suppress checking and force expansion"));
1835 context_exitAllClausesQuiet ();
1839 llparseerror (cstring_undefined);