2 ** Copyright (c) Massachusetts Institute of Technology 1994-1998.
3 ** All Rights Reserved.
4 ** Unpublished rights reserved under the copyright laws of
7 ** THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 ** OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 ** This code is distributed freely and may be used freely under the
11 ** following conditions:
13 ** 1. This notice may not be removed or altered.
15 ** 2. Works derived from this code are not distributed for
16 ** commercial gain without explicit permission from MIT
17 ** (for permission contact lclint-request@sds.lcs.mit.edu).
24 ** Yacc/Bison grammar for extended ANSI C used by LCLint.
26 ** original grammar by Nate Osgood ---
27 ** hacrat@catfish.lcs.mit.edu Mon Jun 14 13:06:32 1993
29 ** changes for LCLint --- handle typedef names correctly
30 ** fix struct/union parsing bug (empty struct is accepted)
31 ** add productions to handle macros --- require
32 ** error correction --- main source of conflicts in grammar.
33 ** need to process initializations sequentially, L->R
35 ** production names are cryptic, so more productions fit on one line
37 ** conflicts: 87 shift/reduce, 18 reduce/reduce
38 ** most of these are due to handling macros
39 ** a few are due to handling type expressions
45 extern void swallowMacro (void);
46 extern void yyerror (char *);
48 # include "lclintMacros.nf"
50 # include "cscanner.h"
51 # include "mtincludes.h"
52 # include "cgrammar.h"
53 # include "exprChecks.h"
58 # define SHOWCSYM FALSE
61 ** This is necessary, or else when the bison-generated code #include's malloc.h,
62 ** there will be a parse error.
64 ** Unfortunately, it means the error checking on malloc, etc. is lost for allocations
65 ** in bison-generated files under Win32.
83 /*@dependent@*/ sRef sr;
86 /*@only@*/ functionClauseList funcclauselist;
87 /*@only@*/ functionClause funcclause;
88 /*@only@*/ flagSpec flagspec;
89 /*@only@*/ globalsClause globsclause;
90 /*@only@*/ modifiesClause modsclause;
91 /*@only@*/ warnClause warnclause;
92 /*@only@*/ stateClause stateclause;
94 /*@only@*/ metaStateConstraint msconstraint;
95 /*@only@*/ metaStateSpecifier msspec;
96 /*@only@*/ metaStateExpression msexpr;
97 /*@observer@*/ metaStateInfo msinfo;
99 /*@only@*/ sRefList srlist;
100 /*@only@*/ globSet globset;
101 /*@only@*/ qtype qtyp;
102 /*@only@*/ cstring cname;
103 /*@observer@*/ annotationInfo annotation;
104 /*@only@*/ idDecl ntyp;
105 /*@only@*/ idDeclList ntyplist;
106 /*@only@*/ uentryList flist;
107 /*@owned@*/ uentryList entrylist;
108 /*@observer@*/ /*@dependent@*/ uentry entry;
109 /*@only@*/ uentry oentry;
110 /*@only@*/ exprNode expr;
111 /*@only@*/ enumNameList enumnamelist;
112 /*@only@*/ exprNodeList alist;
113 /*@only@*/ sRefSet srset;
114 /*@only@*/ cstringList cstringlist;
125 /* standard C tokens */
127 %token <tok> BADTOK SKIPTOK
128 %token <tok> CTOK_ELIPSIS CASE DEFAULT CIF CELSE SWITCH WHILE DO CFOR
129 %token <tok> GOTO CONTINUE BREAK RETURN
130 %token <tok> TSEMI TLBRACE TRBRACE TCOMMA TCOLON TASSIGN TLPAREN
131 %token <tok> TRPAREN TLSQBR TRSQBR TDOT TAMPERSAND TEXCL TTILDE
132 %token <tok> TMINUS TPLUS TMULT TDIV TPERCENT TLT TGT TCIRC TBAR TQUEST
133 %token <tok> CSIZEOF CALIGNOF ARROW_OP CTYPEDEF COFFSETOF
134 %token <tok> INC_OP DEC_OP LEFT_OP RIGHT_OP
135 %token <tok> LE_OP GE_OP EQ_OP NE_OP AND_OP OR_OP
136 %token <tok> MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN SUB_ASSIGN
137 %token <tok> LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
138 %token <tok> CSTRUCT CUNION CENUM
139 %token <tok> VA_ARG VA_DCL
141 %token <tok> QGLOBALS
142 %token <tok> QMODIFIES
144 %token <tok> QCONSTANT
145 %token <tok> QFUNCTION
147 %token <tok> QDEFINES
149 %token <tok> QALLOCATES
151 %token <tok> QRELEASES
152 %token <tok> QPRECLAUSE
153 %token <tok> QPOSTCLAUSE
155 %token <tok> QUNDEF QKILLED
156 %token <tok> QENDMACRO
158 /* additional tokens introduced by lclint pre-processor. */
159 %token <tok> LLMACRO LLMACROITER LLMACROEND TENDMACRO
161 /* break comments: */
162 %token <tok> QSWITCHBREAK QLOOPBREAK QINNERBREAK QSAFEBREAK
163 %token <tok> QINNERCONTINUE
165 /* case fall-through marker: */
166 %token <tok> QFALLTHROUGH
168 /* used in scanner only */
169 %token <tok> QLINTNOTREACHED
170 %token <tok> QLINTFALLTHROUGH
171 %token <tok> QLINTFALLTHRU
172 %token <tok> QARGSUSED
173 %token <tok> QPRINTFLIKE QLINTPRINTFLIKE QSCANFLIKE QMESSAGELIKE
175 /* not-reached marker: (used like a label) */
176 %token <tok> QNOTREACHED
178 /* type qualifiers: */
179 %token <tok> QCONST QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
180 %token <tok> QOUT QIN QYIELD QONLY QTEMP QSHARED QREF QUNIQUE
181 %token <tok> QCHECKED QUNCHECKED QCHECKEDSTRICT QCHECKMOD
182 %token <tok> QKEEP QKEPT QPARTIAL QSPECIAL QOWNED QDEPENDENT
183 %token <tok> QRETURNED QEXPOSED QNULL QOBSERVER QISNULL
184 %token <tok> QEXITS QMAYEXIT QNEVEREXIT QTRUEEXIT QFALSEEXIT
185 %token <tok> QLONG QSIGNED QUNSIGNED QSHORT QUNUSED QSEF QNOTNULL QRELNULL
186 %token <tok> QABSTRACT QCONCRETE QMUTABLE QIMMUTABLE
187 %token <tok> QTRUENULL QFALSENULL QEXTERNAL
188 %token <tok> QREFCOUNTED QREFS QNEWREF QTEMPREF QKILLREF QRELDEF
189 %token <ctyp> CGCHAR CBOOL CINT CGFLOAT CDOUBLE CVOID
190 %token <tok> QANYTYPE QINTEGRALTYPE QUNSIGNEDINTEGRALTYPE QSIGNEDINTEGRALTYPE
192 %type <typequal> nullterminatedQualifier
193 %token <tok> QNULLTERMINATED
194 %token <tok> QSETBUFFERSIZE
195 %token <tok> QSETSTRINGLENGTH
197 %token <tok> QMAXREAD
198 %token <tok> QTESTINRANGE
203 /* identifiers, literals */
204 %token <entry> IDENTIFIER
205 %token <cname> NEW_IDENTIFIER TYPE_NAME_OR_ID
206 %token <annotation> CANNOTATION
207 %token <expr> CCONSTANT
209 %type <flagspec> flagSpec
210 %type <expr> cconstantExpr
211 %token <entry> ITER_NAME ITER_ENDNAME
212 %type <entry> endIter
214 %type <funcclauselist> functionClauses functionClausesPlain
215 %type <funcclause> functionClause functionClause functionClausePlain
217 %type <globsclause> globalsClause globalsClausePlain
218 %type <modsclause> modifiesClause modifiesClausePlain nomodsClause
219 %type <warnclause> warnClause warnClausePlain
220 %type <funcclause> conditionClause conditionClausePlain
221 %type <stateclause> stateClause stateClausePlain
222 %type <msconstraint> metaStateConstraint
223 %type <msspec> metaStateSpecifier
224 %type <msexpr> metaStateExpression
226 %type <sr> globId globIdListExpr
227 %type <globset> globIdList
229 %token <ctyp> TYPE_NAME
230 %token <msinfo> METASTATE_NAME
231 %type <msinfo> metaStateName
232 %type <cname> enumerator newId /*@-varuse@*/ /* yacc declares yytranslate here */
233 %type <count> pointers /*@=varuse@*/
235 %type <tok> doHeader stateTag conditionTag startConditionClause
236 %type <typequal> exitsQualifier checkQualifier stateQualifier
237 paramQualifier returnQualifier visibilityQualifier
238 typedefQualifier refcountQualifier definedQualifier
240 /* type construction */
241 %type <ctyp> abstractDecl abstractDeclBase optAbstractDeclBase
242 %type <ctyp> suSpc enumSpc typeName typeSpecifier
244 %type <ntyp> namedDecl namedDeclBase optNamedDecl
245 %type <ntyp> plainNamedDecl plainNamedDeclBase
246 %type <ntyp> structNamedDecl
247 %type <ntyp> fcnDefHdrAux plainFcn
249 %type <oentry> paramDecl
252 %type <ntyplist> structNamedDeclList
254 %type <entrylist> genericParamList paramTypeList paramList idList paramIdList
255 %type <alist> argumentExprList iterArgList
256 %type <alist> initList
257 %type <flist> structDeclList structDecl
258 %type <srset> locModifies modList specClauseList optSpecClauseList
259 %type <sr> mExpr modListExpr specClauseListExpr
262 %type <con> BufConstraint
263 %type <tok> relationalOp
264 %type <tok> BufBinaryOp
265 %type <tok> bufferModifier
267 %type <conE> BufConstraintExpr
269 %type <conE> BufConstraintTerm
270 %type <sr> BufConstraintSrefExpr
272 %type <conL> BufConstraintList
274 %type <tok> BufUnaryOp
276 %type <enumnamelist> enumeratorList
277 %type <cstringlist> fieldDesignator
279 %type <expr> sizeofExpr sizeofExprAux offsetofExpr
280 %type <expr> openScope closeScope
281 %type <expr> instanceDecl namedInitializer optDeclarators
282 %type <expr> primaryExpr postfixExpr primaryIterExpr postfixIterExpr
283 %type <expr> unaryExpr castExpr timesExpr plusExpr
284 %type <expr> unaryIterExpr castIterExpr timesIterExpr plusIterExpr
285 %type <expr> shiftExpr relationalExpr equalityExpr bitandExpr
286 %type <expr> xorExpr bitorExpr andExpr
287 %type <expr> orExpr conditionalExpr assignExpr
288 %type <expr> shiftIterExpr relationalIterExpr equalityIterExpr bitandIterExpr
289 %type <expr> xorIterExpr bitorIterExpr andIterExpr
290 %type <expr> orIterExpr conditionalIterExpr assignIterExpr iterArgExpr
291 %type <expr> expr optExpr constantExpr
292 %type <expr> init macroBody iterBody endBody partialIterStmt iterSelectionStmt
293 %type <expr> stmt stmtList fcnBody iterStmt iterDefStmt iterDefStmtList
294 %type <expr> labeledStmt caseStmt defaultStmt
295 %type <expr> compoundStmt compoundStmtAux compoundStmtRest compoundStmtAuxErr
296 %type <expr> expressionStmt selectionStmt iterationStmt jumpStmt iterDefIterationStmt
297 %type <expr> stmtErr stmtListErr compoundStmtErr expressionStmtErr
298 %type <expr> iterationStmtErr initializerList initializer ifPred whilePred forPred iterWhilePred
300 %type <typequal> storageSpecifier typeQualifier typeModifier globQual
301 %type <tquallist> optGlobQuals
302 %type <qtyp> completeType completeTypeSpecifier optCompleteType
303 %type <qtyp> completeTypeSpecifierAux altType typeExpression
304 /*%type <expr> lclintassertion*/
316 | externalDefs externalDef
319 : fcnDef optSemi { uentry_clearDecl (); }
320 | constantDecl { uentry_clearDecl (); }
321 | fcnDecl { uentry_clearDecl (); }
322 | iterDecl { uentry_clearDecl (); }
323 | macroDef { uentry_clearDecl (); }
324 | initializer { uentry_checkDecl (); exprNode_free ($1); }
325 | error { uentry_clearDecl (); }
328 : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
329 { checkConstant ($2, $4); }
330 | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
331 { checkValueConstant ($2, $4, $8) ; }
334 : QFUNCTION { context_enterFunctionHeader (); } plainFcn optSemi QENDMACRO
336 declareStaticFunction ($3); context_quietExitFunction ();
337 context_exitFunctionHeader ();
343 qtype qint = qtype_create (ctype_int);
344 $$ = idDecl_fixBase ($1, qint);
347 | completeTypeSpecifier NotType plainNamedDecl
348 { $$ = idDecl_fixBase ($3, $1); }
352 | pointers plainNamedDeclBase
353 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
356 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
357 | IsType TLPAREN NotType namedDecl IsType TRPAREN
358 { $$ = idDecl_expectFunction ($4); }
359 | namedDeclBase TLSQBR TRSQBR
360 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
361 | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
363 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), exprNode_getLongValue ($4)));
365 | namedDeclBase PushType TLPAREN TRPAREN
366 { setCurrentParams (uentryList_missingParams); }
368 { /* need to support globals and modifies here! */
369 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
370 uentryList_makeMissingParams ());
372 $$ = idDecl_replaceCtype ($1, ct);
373 idDecl_addClauses ($$, $6);
376 | namedDeclBase PushType TLPAREN genericParamList TRPAREN
377 { setCurrentParams ($4); }
379 { setImplictfcnConstraints ();
380 clearCurrentParams ();
381 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
382 idDecl_addClauses ($$, $7);
387 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
388 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
389 { $$ = idDecl_expectFunction ($4); }
390 | plainNamedDeclBase TLSQBR TRSQBR
391 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
392 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
396 if (exprNode_hasValue ($4)
397 && multiVal_isInt (exprNode_getValue ($4)))
399 value = (int) multiVal_forceInt (exprNode_getValue ($4));
406 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
408 | plainNamedDeclBase PushType TLPAREN TRPAREN
409 { setCurrentParams (uentryList_missingParams); }
412 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
413 uentryList_makeMissingParams ());
415 $$ = idDecl_replaceCtype ($1, ct);
416 idDecl_addClauses ($$, $6);
419 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
420 { setCurrentParams ($4); }
423 clearCurrentParams ();
424 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
425 idDecl_addClauses ($$, $7);
430 : QITER newId TLPAREN genericParamList TRPAREN
431 { setCurrentParams ($4); } functionClausesPlain
432 { clearCurrentParams (); } optSemi QENDMACRO
433 { declareCIter ($2, $4); }
436 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); }
437 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); }
438 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); }
439 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); }
442 : fcnDefHdrAux { clabstract_declareFunction ($1); }
445 : metaStateSpecifier TASSIGN metaStateExpression
446 { $$ = metaStateConstraint_create ($1, $3); }
449 : BufConstraintSrefExpr { cscanner_expectingMetaStateName (); } TCOLON metaStateName
450 { cscanner_clearExpectingMetaStateName ();
451 $$ = metaStateSpecifier_create ($1, $4); }
454 : metaStateSpecifier { $$ = metaStateExpression_create ($1); }
455 | metaStateSpecifier TBAR metaStateExpression { $$ = metaStateExpression_createMerge ($1, $3); }
463 : BufConstraint TCAND BufConstraintList { $$ = constraintList_add ($3, $1); }
464 | BufConstraint {constraintList c; c = constraintList_makeNew(); c = constraintList_add (c, $1); $$ = c}
467 : BufConstraintExpr relationalOp BufConstraintExpr {
468 $$ = makeConstraintParse3 ($1, $2, $3);
469 DPRINTF(("Done BufConstraint1\n")); }
482 | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3); DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
483 | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
484 DPRINTF( ("Got BufConstraintExpr BINary Op ") );
485 $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
488 : BufConstraintSrefExpr { $$ = constraintExpr_makeTermsRef($1);}
492 t = cstring_toCharsSafe (exprNode_unparse($1));
496 $$ = constraintExpr_makeIntLiteral (exprNode_getLongValue ($1));
499 BufConstraintSrefExpr
501 { /*@-onlytrans@*/ $$ = checkbufferConstraintClausesId ($1); /*@=onlytrans@*/ /*@i523@*/ }
503 { $$ = fixStateClausesId ($1); }
504 | BufConstraintSrefExpr TLSQBR TRSQBR
505 { $$ = sRef_makeAnyArrayFetch ($1); }
506 | BufConstraintSrefExpr TLSQBR CCONSTANT TRSQBR
510 t = cstring_toCharsSafe (exprNode_unparse($3));
513 $$ = sRef_makeArrayFetchKnown ($1, exprNode_getLongValue ($3));
515 | TMULT BufConstraintSrefExpr
516 { $$ = sRef_constructPointer ($2); }
517 | TLPAREN BufConstraintSrefExpr TRPAREN
519 | BufConstraintSrefExpr TDOT newId
520 { cstring_markOwned ($3); $$ = sRef_buildField ($1, $3); }
521 | BufConstraintSrefExpr ARROW_OP newId
522 { cstring_markOwned ($3); $$ = sRef_makeArrow ($1, $3); }
525 | BufConstraintTerm TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
526 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
527 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
528 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
529 $$ = sRef_buildField ($1, $3); }
545 ** Function clauses can appear in any order.
549 : { $$ = functionClauseList_new (); }
550 | functionClause functionClauses
551 { $$ = functionClauseList_prepend ($2, $1); }
554 ** Inside macro definitions, there are no end macros.
559 { $$ = functionClauseList_new (); }
560 | functionClausePlain functionClausesPlain
561 { $$ = functionClauseList_prepend ($2, $1); }
564 : globalsClause { $$ = functionClause_createGlobals ($1); }
565 | modifiesClause { $$ = functionClause_createModifies ($1); }
566 | nomodsClause { $$ = functionClause_createModifies ($1); }
567 | stateClause { $$ = functionClause_createState ($1); }
568 | conditionClause { $$ = $1; }
569 | warnClause { $$ = functionClause_createWarn ($1); }
572 : globalsClausePlain { $$ = functionClause_createGlobals ($1); }
573 | modifiesClausePlain { $$ = functionClause_createModifies ($1); }
574 | nomodsClause { $$ = functionClause_createModifies ($1); }
575 | stateClausePlain { $$ = functionClause_createState ($1); }
576 | conditionClausePlain { $$ = $1; }
577 | warnClausePlain { $$ = functionClause_createWarn ($1); }
580 : globalsClausePlain QENDMACRO { $$ = $1; }
583 : QGLOBALS { setProcessingGlobalsList (); }
586 unsetProcessingGlobals ();
587 $$ = globalsClause_create ($1, $3);
591 : QNOMODS { $$ = modifiesClause_createNoMods ($1); }
594 : modifiesClausePlain QENDMACRO { $$ = $1; }
599 context_setProtectVars (); enterParamsTemp ();
600 sRef_setGlobalScopeSafe ();
605 sRef_clearGlobalScopeSafe ();
606 context_releaseVars ();
607 $$ = modifiesClause_create ($1, $3);
612 { $$ = flagSpec_createPlain ($1); }
613 | flagId TBAR flagSpec
614 { $$ = flagSpec_createOr ($1, $3); }
620 : warnClausePlain QENDMACRO { $$ = $1; }
623 : QWARN flagSpec cconstantExpr
624 { $$ = warnClause_create ($1, $2, $3); }
626 { $$ = warnClause_create ($1, $2, exprNode_undefined); }
629 : globIdListExpr { $$ = globSet_single ($1); }
630 | globIdList TCOMMA globIdListExpr { $$ = globSet_insert ($1, $3); }
633 : optGlobQuals globId { $$ = clabstract_createGlobal ($2, $1); }
636 : /* empty */ { $$ = qualList_undefined; }
637 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
640 : id { $$ = uentry_getSref ($1); }
641 | NEW_IDENTIFIER { $$ = clabstract_unrecognizedGlobal ($1); }
642 | initializer { $$ = clabstract_checkGlobal ($1); }
645 : QUNDEF { $$ = qual_createUndef (); }
646 | QKILLED { $$ = qual_createKilled (); }
647 | QOUT { $$ = qual_createOut (); }
648 | QIN { $$ = qual_createIn (); }
649 | QPARTIAL { $$ = qual_createPartial (); }
665 qtype qint = qtype_create (ctype_int);
666 $$ = idDecl_fixBase ($1, qint);
669 | completeTypeSpecifier NotType namedDecl
670 { $$ = idDecl_fixBase ($3, $1); }
673 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
676 exprNode_checkFunctionBody ($3); $$ = $3;
677 context_exitInner ($3);
680 { doneParams (); context_enterInnerContext (); }
683 context_exitInner ($3);
684 exprNode_checkFunctionBody ($3);
685 $$ = $3; /* old style */
691 context_setFunctionDefined (exprNode_loc ($2));
692 exprNode_checkFunction (context_getHeader (), $2);
695 context_exitFunction ();
699 : modList optSemi { $$ = $1; }
700 | optSemi { $$ = sRefSet_new (); }
703 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
704 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
705 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
706 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
707 | TMULT modListExpr { $$ = modListPointer ($2); }
708 | TLPAREN modListExpr TRPAREN { $$ = $2; }
709 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
710 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
714 : modListExpr { $$ = $1; }
715 | cconstantExpr { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
719 : modListExpr { $$ = sRefSet_single ($1); }
720 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
724 { $$ = checkStateClausesId ($1); }
726 { $$ = fixStateClausesId ($1); }
727 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
728 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
729 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
730 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
731 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
732 $$ = sRef_buildField ($1, $3); }
733 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
734 $$ = sRef_makeArrow ($1, $3); }
737 : /* empty */ { $$ = sRefSet_undefined }
742 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
743 else { $$ = sRefSet_undefined; }
745 | specClauseList TCOMMA specClauseListExpr
746 { if (sRef_isValid ($3))
748 $$ = sRefSet_insert ($1, $3);
757 : id { $$ = exprNode_fromIdentifier ($1); }
758 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
760 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
761 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
762 | QEXTENSION { $$ = exprNode_makeError (); }
766 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
767 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
768 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
769 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
770 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
771 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
772 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
773 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
776 : assignExpr { $$ = exprNodeList_singleton ($1); }
777 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
781 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
782 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
783 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
784 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
785 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
786 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
787 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
788 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
789 | sizeofExpr { $$ = $1; }
790 | offsetofExpr { $$ = $1; }
793 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
794 | newId { $$ = cstringList_single ($1); }
797 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
798 { $$ = exprNode_offsetof ($4, $7); }
801 : IsType { context_setProtectVars (); }
802 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
805 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); }
806 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); }
807 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); }
808 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); }
812 | TLPAREN typeExpression TRPAREN castExpr
813 { $$ = exprNode_cast ($1, $4, $2); }
817 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
818 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
819 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
823 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
824 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
828 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
829 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
833 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
834 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
835 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
836 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
840 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
841 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
845 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
849 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
854 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
859 { exprNode_produceGuards ($1);
860 context_enterAndClause ($1);
864 $$ = exprNode_op ($1, $4, $2);
865 context_exitAndClause ($$, $4);
872 exprNode_produceGuards ($1);
873 context_enterOrClause ($1);
877 $$ = exprNode_op ($1, $4, $2);
878 context_exitOrClause ($$, $4);
883 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
884 { context_enterFalseClause ($1); } conditionalExpr
885 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
889 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
890 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
891 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
892 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
893 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
894 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
895 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
896 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
897 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
898 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
899 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
903 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
906 : /* empty */ { $$ = exprNode_undefined; }
912 /* instance_orTypeDecl_and_possible_initialization */
915 : instanceDecl { $$ = $1; }
916 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
917 | typeDecl { $$ = exprNode_makeError (); }
920 : completeTypeSpecifier IsType TSEMI
921 { $$ = exprNode_makeError (); }
923 ** This causes r/r conflicts with function definitions.
924 ** Instead we need to snarf one first. (gack)
926 ** | completeTypeSpecifier { setProcessingVars ($1); }
928 ** namedInitializerList IsType TSEMI
929 ** { unsetProcessingVars (); }
932 ** the solution is pretty ugly:
934 | completeTypeSpecifier NotType namedDecl NotType
936 setProcessingVars ($1);
937 processNamedDecl ($3);
939 IsType optDeclarators TSEMI IsType
941 unsetProcessingVars ();
942 $$ = exprNode_makeEmptyInitialization ($3);
943 DPRINTF (("Empty initialization: %s", exprNode_unparse ($$)));
945 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
946 { setProcessingVars ($1); processNamedDecl ($3); }
947 IsType init optDeclarators TSEMI IsType
948 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
949 unsetProcessingVars ();
955 processNamedDecl ($1);
956 $$ = exprNode_makeEmptyInitialization ($1);
958 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
959 { $$ = exprNode_makeInitialization ($1, $6); }
962 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
963 NotType namedInitializerList IsType TSEMI { unsetProcessingTypedef (); }
964 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
965 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
968 : { g_expectingTypeName = TRUE; }
971 : { g_expectingTypeName = TRUE; context_pushLoc (); }
974 : namedInitializerListAux IsType { ; }
976 namedInitializerListAux
977 : namedInitializer { ; }
978 | namedInitializerList TCOMMA NotType namedInitializer { ; }
981 : /* empty */ { $$ = exprNode_makeError (); }
982 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
986 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
987 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
992 { $$ = exprNodeList_singleton ($1); }
993 | initList TCOMMA init
994 { $$ = exprNodeList_push ($1, $3); }
997 ** need to do the storage class global hack so tags are
998 ** declared with the right storage class.
1002 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1003 | QINLINE { $$ = qual_createInline (); }
1004 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1005 | QAUTO { $$ = qual_createAuto (); }
1006 | QREGISTER { $$ = qual_createRegister (); }
1008 nullterminatedQualifier:
1009 QNULLTERMINATED IsType { $$ = qual_createNullTerminated (); }
1012 : stateClausePlain QENDMACRO { $$ = $1; }
1017 context_setProtectVars ();
1019 sRef_setGlobalScopeSafe ();
1021 specClauseList optSemi IsType
1024 sRef_clearGlobalScopeSafe ();
1025 context_releaseVars ();
1026 $$ = stateClause_createPlain ($1, $4);
1030 : conditionClausePlain QENDMACRO { $$ = $1; }
1032 startConditionClause
1033 : conditionTag NotType { $$ = $1; context_enterFunctionHeader (); }
1035 conditionClausePlain
1036 : startConditionClause stateQualifier
1038 context_exitFunctionHeader ();
1039 context_setProtectVars ();
1041 sRef_setGlobalScopeSafe ();
1043 optSpecClauseList optSemi IsType
1046 sRef_clearGlobalScopeSafe ();
1047 context_releaseVars ();
1048 $$ = functionClause_createState (stateClause_create ($1, $2, $4));
1050 | startConditionClause
1052 context_setProtectVars ();
1054 sRef_setGlobalScopeSafe ();
1056 BufConstraintList optSemi IsType
1058 context_exitFunctionHeader ();
1060 sRef_clearGlobalScopeSafe ();
1061 context_releaseVars ();
1062 DPRINTF (("done optGlobBufConstraintsAux\n"));
1064 if (lltok_isEnsures ($1))
1066 $$ = functionClause_createEnsures ($3);
1068 else if (lltok_isRequires ($1))
1070 $$ = functionClause_createRequires ($3);
1077 | startConditionClause
1079 context_setProtectVars ();
1081 sRef_setGlobalScopeSafe ();
1083 metaStateConstraint optSemi IsType
1085 context_exitFunctionHeader ();
1087 sRef_clearGlobalScopeSafe ();
1088 context_releaseVars ();
1089 DPRINTF (("done optGlobBufConstraintsAux\n"));
1091 if (lltok_isEnsures ($1))
1093 $$ = functionClause_createMetaEnsures ($3);
1095 else if (lltok_isRequires ($1))
1097 $$ = functionClause_createMetaRequires ($3);
1106 : QEXITS { $$ = qual_createExits (); }
1107 | QMAYEXIT { $$ = qual_createMayExit (); }
1108 | QTRUEEXIT { $$ = qual_createTrueExit (); }
1109 | QFALSEEXIT { $$ = qual_createFalseExit (); }
1110 | QNEVEREXIT { $$ = qual_createNeverExit (); }
1113 : QCHECKED { $$ = qual_createChecked (); }
1114 | QCHECKMOD { $$ = qual_createCheckMod (); }
1115 | QUNCHECKED { $$ = qual_createUnchecked (); }
1116 | QCHECKEDSTRICT { $$ = qual_createCheckedStrict (); }
1119 : QOWNED { $$ = qual_createOwned (); }
1120 | QDEPENDENT { $$ = qual_createDependent (); }
1121 | QYIELD { $$ = qual_createYield (); }
1122 | QTEMP { $$ = qual_createTemp (); }
1123 | QONLY { $$ = qual_createOnly (); }
1124 | QKEEP { $$ = qual_createKeep (); }
1125 | QKEPT { $$ = qual_createKept (); }
1126 | QSHARED { $$ = qual_createShared (); }
1127 | QUNIQUE { $$ = qual_createUnique (); }
1128 | QNULL { $$ = qual_createNull (); }
1129 | QISNULL { $$ = qual_createIsNull (); }
1130 | QRELNULL { $$ = qual_createRelNull (); }
1131 | QNOTNULL { $$ = qual_createNotNull (); }
1132 | QEXPOSED { $$ = qual_createExposed (); }
1133 | QOBSERVER { $$ = qual_createObserver (); }
1134 | CANNOTATION { $$ = qual_createMetaState ($1); }
1137 : QRETURNED { $$ = qual_createReturned (); }
1138 | QSEF { $$ = qual_createSef (); }
1141 : QUNUSED { $$ = qual_createUnused (); }
1142 | QEXTERNAL { $$ = qual_createExternal (); }
1145 : QTRUENULL { $$ = qual_createTrueNull (); }
1146 | QFALSENULL { $$ = qual_createFalseNull (); }
1149 : QABSTRACT { $$ = qual_createAbstract (); }
1150 | QCONCRETE { $$ = qual_createConcrete (); }
1151 | QMUTABLE { $$ = qual_createMutable (); }
1152 | QIMMUTABLE { $$ = qual_createImmutable (); }
1155 : QREFCOUNTED { $$ = qual_createRefCounted (); }
1156 | QREFS { $$ = qual_createRefs (); }
1157 | QKILLREF { $$ = qual_createKillRef (); }
1158 | QRELDEF { $$ = qual_createRelDef (); }
1159 | QNEWREF { $$ = qual_createNewRef (); }
1160 | QTEMPREF { $$ = qual_createTempRef (); }
1163 : QSHORT { $$ = qual_createShort (); }
1164 | QLONG { $$ = qual_createLong (); }
1165 | QSIGNED { $$ = qual_createSigned (); }
1166 | QUNSIGNED { $$ = qual_createUnsigned (); }
1169 : QOUT { $$ = qual_createOut (); }
1170 | QIN { $$ = qual_createIn (); }
1171 | QPARTIAL { $$ = qual_createPartial (); }
1172 | QSPECIAL { $$ = qual_createSpecial (); }
1175 : QCONST IsType { $$ = qual_createConst (); }
1176 | QVOLATILE IsType { $$ = qual_createVolatile (); }
1177 | definedQualifier IsType { $$ = $1; }
1178 | stateQualifier IsType { $$ = $1; }
1179 | exitsQualifier IsType { $$ = $1; }
1180 | paramQualifier IsType { $$ = $1; }
1181 | checkQualifier IsType { $$ = $1; }
1182 | returnQualifier IsType { $$ = $1; }
1183 | visibilityQualifier IsType { $$ = $1; }
1184 | typedefQualifier IsType { $$ = $1; }
1185 | refcountQualifier IsType { $$ = $1; }
1188 ** This is copied into the mtgrammar!
1198 | QANYTYPE NotType { $$ = ctype_unknown; }
1199 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
1200 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1201 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
1205 | typeModifier NotType { $$ = ctype_fromQual ($1); }
1208 : IsType completeTypeSpecifier IsType
1209 { $$ = qtype_resolve ($2); }
1211 completeTypeSpecifier
1212 : completeTypeSpecifierAux { $$ = $1; }
1213 | completeTypeSpecifierAux QALT altType QENDMACRO
1214 { $$ = qtype_mergeAlt ($1, $3); }
1218 | typeExpression TCOMMA altType
1219 { $$ = qtype_mergeAlt ($1, $3); }
1221 completeTypeSpecifierAux
1222 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1223 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1224 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
1227 : /* empty */ { $$ = qtype_unknown (); }
1228 | completeTypeSpecifier { $$ = $1; }
1231 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1232 CreateStructInnerScope
1233 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1235 { $$ = declareStruct ($3, $8); }
1236 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1237 CreateStructInnerScope
1238 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1240 { $$ = declareUnion ($3, $8); }
1241 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
1242 { $$ = declareStruct ($3, uentryList_new ()); }
1243 | NotType CUNION newId IsType TLBRACE TRBRACE
1244 { $$ = declareUnion ($3, uentryList_new ()); }
1245 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1246 CreateStructInnerScope
1247 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1249 { $$ = declareUnnamedStruct ($7); }
1250 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1251 CreateStructInnerScope structDeclList DeleteStructInnerScope
1252 { sRef_clearGlobalScopeSafe (); }
1254 { $$ = declareUnnamedUnion ($7); }
1255 | NotType CSTRUCT IsType TLBRACE TRBRACE
1256 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
1257 | NotType CUNION IsType TLBRACE TRBRACE
1258 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
1259 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
1260 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
1263 : { g_expectingTypeName = FALSE; }
1267 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1268 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1271 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
1272 { $$ = fixUentryList ($3, $1); }
1273 | completeTypeSpecifier IsType TSEMI
1274 { $$ = fixUnnamedDecl ($1); }
1277 : structNamedDecl NotType
1278 { $$ = idDeclList_singleton ($1); }
1279 | structNamedDeclList TCOMMA structNamedDecl NotType
1280 { $$ = idDeclList_add ($1, $3); }
1282 structNamedDecl /* hack to get around namespace problems */
1283 : namedDecl { $$ = $1; }
1284 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1285 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1286 /* Need the IsType in case there is a cast in the constant expression. */
1289 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1290 { $$ = declareUnnamedEnum ($4); }
1291 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1292 { context_popLoc (); $$ = declareEnum ($3, $6); }
1293 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1297 { $$ = enumNameList_single ($1); }
1298 | enumeratorList TCOMMA enumerator
1299 { $$ = enumNameList_push ($1, $3); }
1300 | enumeratorList TCOMMA
1304 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1305 usymtab_supGlobalEntry (ue);
1308 | newId TASSIGN IsType constantExpr
1309 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1310 usymtab_supGlobalEntry (ue);
1316 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1317 | pointers TYPE_NAME
1319 qtype qt = qtype_unknown ();
1321 qtype_adjustPointers ($1, qt);
1322 $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1324 | pointers optNamedDecl
1325 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1329 | pointers namedDeclBase
1330 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1333 : paramTypeList { $$ = handleParamTypeList ($1); }
1334 | NotType paramIdList { $$ = handleParamIdList ($2); }
1337 : QCONST { /* ignored for now */; }
1342 | innerModsList innerMods { ; }
1346 | TMULT innerModsList { $$ = 1; }
1347 | TMULT pointers { $$ = 1 + $2; }
1348 | TMULT innerModsList pointers { $$ = 1 + $3; }
1352 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1355 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1356 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1359 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1361 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1364 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1365 | paramList TCOMMA { storeLoc (); } paramDecl
1366 { $$ = uentryList_add ($1, $4); }
1369 : IsType completeTypeSpecifier optNamedDecl IsType
1371 if (isFlipOldStyle ())
1373 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1379 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1381 | newId /* its an old-style declaration */
1383 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1387 llparseerror (message ("Inconsistent function parameter syntax: %q",
1388 idDecl_unparse (tparam)));
1392 $$ = makeCurrentParam (tparam);
1393 idDecl_free (tparam);
1398 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1401 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1403 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1406 : /* empty */ { $$ = ctype_unknown; }
1410 : IsType TLPAREN NotType abstractDecl TRPAREN
1411 { $$ = ctype_expectFunction ($4); }
1412 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1413 | TLSQBR constantExpr TRSQBR
1414 { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
1415 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1416 | abstractDeclBase TLSQBR constantExpr TRSQBR
1417 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
1418 | IsType TLPAREN TRPAREN
1419 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1420 | IsType TLPAREN paramTypeList TRPAREN
1421 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1422 | abstractDeclBase IsType TLPAREN TRPAREN
1423 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1424 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1425 { $$ = ctype_makeParamsFunction ($1, $4); }
1439 /* | lclintassertion {$$ = $1; printf ("Doing stmt lclintassertion\n"); }*/
1443 : QSETBUFFERSIZE id CCONSTANT QENDMACRO { printf(" QSETBUFFERSIZE id CCONSTANT HEllo World\n"); uentry_setBufferSize($2, $3); $$ = exprNode_createTok ($4);
1445 | QSETSTRINGLENGTH id CCONSTANT QENDMACRO { printf(" QSETSTRINGLENGTH id CCONSTANT HEllo World\n"); uentry_setStringLength($2, $3); $$ = exprNode_createTok ($4);
1447 | QTESTINRANGE id CCONSTANT QENDMACRO {printf(" QTESTINRANGE\n"); uentry_testInRange($2, $3); $$ = exprNode_createTok ($4);
1450 /* | QSETBUFFERSIZE id id {$$ = $2; printf(" QSETBUFFERSIZE id id HEllo World\n");} */
1453 : iterDefStmtList { $$ = $1; }
1460 | iterDefStmtList iterDefStmt
1461 { $$ = exprNode_concat ($1, $2); }
1463 iterDefIterationStmt
1464 : iterWhilePred iterDefStmtList
1465 { $$ = exprNode_while ($1, $2); }
1466 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1467 { $$ = exprNode_doWhile ($2, $5); }
1468 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1469 { $$ = exprNode_doWhile ($2, $5); }
1470 | forPred iterDefStmt
1471 { $$ = exprNode_for ($1, $2); }
1474 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1475 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1477 { $$ = exprNode_forPred ($3, $5, $8);
1478 context_enterForClause ($5); }
1481 : ITER_NAME CreateInnerScope TLPAREN
1482 { setProcessingIterVars ($1); }
1484 { $$ = exprNode_iterStart ($1, $5); }
1485 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1491 | openScope initializerList { $$ = $1; DPRINTF (("def stmt: %s", exprNode_unparse ($$))); }
1496 | iterDefIterationStmt
1499 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1500 | error { $$ = exprNode_makeError (); }
1503 : ifPred iterDefStmt
1504 { /* don't: context_exitTrueClause ($1, $2); */
1505 $$ = exprNode_if ($1, $2);
1509 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1512 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1527 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1529 | error { $$ = exprNode_makeError (); }
1532 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1533 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
1535 /* Note that we can semantically check that the object to the case is
1536 indeed constant. In this case, we may not want to go through this effort */
1539 : CASE constantExpr { context_enterCaseClause ($2); }
1540 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
1541 | QFALLTHROUGH CASE constantExpr { context_enterCaseClause ($3); }
1542 TCOLON { $$ = exprNode_caseMarker ($3, TRUE); }
1545 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1546 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1547 | QFALLTHROUGH DEFAULT { context_enterCaseClause (exprNode_undefined); }
1548 TCOLON { $$ = exprNode_defaultMarker ($2, TRUE); }
1551 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1552 | CreateInnerScope compoundStmtAux
1553 { $$ = $2; context_exitInner ($2); }
1556 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1559 : { context_enterInnerContext (); }
1562 : { context_exitInnerPlain (); }
1564 CreateStructInnerScope
1565 : { context_enterStructInnerContext (); }
1567 DeleteStructInnerScope
1568 : { context_exitStructInnerContext (); }
1570 DeleteInnerScopeSafe
1571 : { context_exitInnerSafe (); }
1574 : TRBRACE { $$ = exprNode_createTok ($1); }
1575 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1576 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1577 | stmtList QNOTREACHED TRBRACE
1578 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1579 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1580 | initializerList QNOTREACHED TRBRACE
1581 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1582 | initializerList stmtList TRBRACE
1583 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1584 | initializerList stmtList QNOTREACHED TRBRACE
1585 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1586 lltok_getLoc ($3)));
1591 : TLBRACE compoundStmtRest
1592 { $$ = exprNode_makeBlock ($2); }
1596 { $$ = exprNode_createTok ($2); }
1597 | TLBRACE stmtListErr TRBRACE
1598 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1599 | TLBRACE initializerList TRBRACE
1600 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1601 | TLBRACE initializerList stmtList TRBRACE
1602 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1606 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1609 : initializer { $$ = $1; }
1610 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1614 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1617 : TSEMI { $$ = exprNode_createTok ($1); }
1618 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1621 : TSEMI { $$ = exprNode_createTok ($1); }
1622 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1623 | expr { $$ = exprNode_checkExpr ($1); }
1626 : CIF TLPAREN expr TRPAREN
1627 { $$ = $3; exprNode_produceGuards ($3); context_enterTrueClause ($3); }
1629 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1630 ** { $$ = $3; context_enterTrueClause (); }
1636 context_exitTrueClause ($1, $2);
1637 $$ = exprNode_if ($1, $2);
1639 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
1641 context_exitClause ($1, $2, $5);
1642 $$ = exprNode_ifelse ($1, $2, $5);
1644 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1645 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1648 : WHILE TLPAREN expr TRPAREN
1649 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1650 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1653 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1656 : ITER_NAME { context_enterIterClause (); }
1657 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1659 compoundStmt endIter DeleteInnerScope
1661 $$ = exprNode_iter ($1, $6, $8, $9);
1666 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1667 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1668 { $$ = exprNodeList_push ($1, $4); }
1671 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1672 | id { $$ = exprNode_iterId ($1); }
1673 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1675 if (uentry_isValid (ue))
1677 $$ = exprNode_iterId (ue);
1681 $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1684 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1687 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1692 | cconstantExpr CCONSTANT { $$ = exprNode_combineLiterals ($1, $2); }
1696 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1700 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1701 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1702 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1703 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1704 { $$ = exprNode_vaArg ($1, $3, $5); }
1705 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
1706 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
1707 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1708 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1712 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1713 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1714 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1715 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1716 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1717 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1718 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1719 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1720 | sizeofExpr { $$ = $1; }
1724 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1728 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1729 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1730 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1734 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1735 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1739 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1740 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1744 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1745 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1746 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1747 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1750 : relationalIterExpr
1751 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1752 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1756 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1760 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1765 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1769 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1773 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1777 | orExpr TQUEST { context_enterTrueClause ($1); }
1778 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1779 { $$ = exprNode_cond ($1, $4, $7); }
1782 : conditionalIterExpr
1783 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1784 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1785 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1786 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1787 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1788 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1789 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1790 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1791 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1792 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1793 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1796 : ITER_ENDNAME { $$ = $1; }
1797 | /* empty */ { $$ = uentry_undefined; }
1800 : DO { context_enterDoWhileClause (); $$ = $1; }
1804 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1805 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
1806 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1808 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1811 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1812 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1813 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1814 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1815 { $$ = exprNode_doWhile ($2, $5); }
1816 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1819 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1820 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1821 | QINNERCONTINUE CONTINUE TSEMI
1822 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1823 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1824 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1825 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1826 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1827 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1828 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1829 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1840 | ITER_NAME { $$ = uentry_getName ($1); }
1841 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1842 | id { $$ = uentry_getName ($1); }
1843 | TYPE_NAME_OR_ID { $$ = $1; }
1847 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1851 /*@-redecl@*/ /*@-namechecks@*/
1852 extern char *yytext;
1853 /*@=redecl@*/ /*@=namechecks@*/
1855 # include "bison.reset"
1857 void yyerror (/*@unused@*/ char *s)
1859 static bool givehint = FALSE;
1861 if (context_inIterDef ())
1863 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1864 context_inFunctionName ()));
1866 else if (context_inIterEnd ())
1868 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1869 context_inFunctionName ()));
1871 else if (context_inMacro ())
1873 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1874 context_inFunctionName ()));
1876 if (context_inMacroUnknown ())
1880 llhint (cstring_makeLiteral
1881 ("Precede macro definition with /*@notfunction@*/ "
1882 "to suppress checking and force expansion"));
1888 context_exitAllClausesQuiet ();
1892 llparseerror (cstring_undefined);