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@*/ functionConstraint fcnconstraint;
96 /*@only@*/ metaStateConstraint msconstraint;
97 /*@only@*/ metaStateSpecifier msspec;
98 /*@only@*/ metaStateExpression msexpr;
99 /*@observer@*/ metaStateInfo msinfo;
101 /*@only@*/ sRefList srlist;
102 /*@only@*/ globSet globset;
103 /*@only@*/ qtype qtyp;
104 /*@only@*/ cstring cname;
105 /*@observer@*/ annotationInfo annotation;
106 /*@only@*/ idDecl ntyp;
107 /*@only@*/ idDeclList ntyplist;
108 /*@only@*/ uentryList flist;
109 /*@owned@*/ uentryList entrylist;
110 /*@observer@*/ /*@dependent@*/ uentry entry;
111 /*@only@*/ uentry oentry;
112 /*@only@*/ exprNode expr;
113 /*@only@*/ enumNameList enumnamelist;
114 /*@only@*/ exprNodeList alist;
115 /*@only@*/ sRefSet srset;
116 /*@only@*/ cstringList cstringlist;
127 /* standard C tokens */
129 %token <tok> BADTOK SKIPTOK
130 %token <tok> CTOK_ELIPSIS CASE DEFAULT CIF CELSE SWITCH WHILE DO CFOR
131 %token <tok> GOTO CONTINUE BREAK RETURN
132 %token <tok> TSEMI TLBRACE TRBRACE TCOMMA TCOLON TASSIGN TLPAREN
133 %token <tok> TRPAREN TLSQBR TRSQBR TDOT TAMPERSAND TEXCL TTILDE
134 %token <tok> TMINUS TPLUS TMULT TDIV TPERCENT TLT TGT TCIRC TBAR TQUEST
135 %token <tok> CSIZEOF CALIGNOF ARROW_OP CTYPEDEF COFFSETOF
136 %token <tok> INC_OP DEC_OP LEFT_OP RIGHT_OP
137 %token <tok> LE_OP GE_OP EQ_OP NE_OP AND_OP OR_OP
138 %token <tok> MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN SUB_ASSIGN
139 %token <tok> LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
140 %token <tok> CSTRUCT CUNION CENUM
141 %token <tok> VA_ARG VA_DCL
143 %token <tok> QGLOBALS
144 %token <tok> QMODIFIES
146 %token <tok> QCONSTANT
147 %token <tok> QFUNCTION
149 %token <tok> QDEFINES
151 %token <tok> QALLOCATES
153 %token <tok> QRELEASES
154 %token <tok> QPRECLAUSE
155 %token <tok> QPOSTCLAUSE
157 %token <tok> QUNDEF QKILLED
158 %token <tok> QENDMACRO
160 /* additional tokens introduced by lclint pre-processor. */
161 %token <tok> LLMACRO LLMACROITER LLMACROEND TENDMACRO
163 /* break comments: */
164 %token <tok> QSWITCHBREAK QLOOPBREAK QINNERBREAK QSAFEBREAK
165 %token <tok> QINNERCONTINUE
167 /* case fall-through marker: */
168 %token <tok> QFALLTHROUGH
170 /* used in scanner only */
171 %token <tok> QLINTNOTREACHED
172 %token <tok> QLINTFALLTHROUGH
173 %token <tok> QLINTFALLTHRU
174 %token <tok> QARGSUSED
175 %token <tok> QPRINTFLIKE QLINTPRINTFLIKE QSCANFLIKE QMESSAGELIKE
177 /* not-reached marker: (used like a label) */
178 %token <tok> QNOTREACHED
180 /* type qualifiers: */
181 %token <tok> QCONST QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
182 %token <tok> QOUT QIN QYIELD QONLY QTEMP QSHARED QREF QUNIQUE
183 %token <tok> QCHECKED QUNCHECKED QCHECKEDSTRICT QCHECKMOD
184 %token <tok> QKEEP QKEPT QPARTIAL QSPECIAL QOWNED QDEPENDENT
185 %token <tok> QRETURNED QEXPOSED QNULL QOBSERVER QISNULL
186 %token <tok> QEXITS QMAYEXIT QNEVEREXIT QTRUEEXIT QFALSEEXIT
187 %token <tok> QLONG QSIGNED QUNSIGNED QSHORT QUNUSED QSEF QNOTNULL QRELNULL
188 %token <tok> QABSTRACT QCONCRETE QMUTABLE QIMMUTABLE
189 %token <tok> QTRUENULL QFALSENULL QEXTERNAL
190 %token <tok> QREFCOUNTED QREFS QNEWREF QTEMPREF QKILLREF QRELDEF
191 %token <ctyp> CGCHAR CBOOL CINT CGFLOAT CDOUBLE CVOID
192 %token <tok> QANYTYPE QINTEGRALTYPE QUNSIGNEDINTEGRALTYPE QSIGNEDINTEGRALTYPE
194 %type <typequal> nullterminatedQualifier
195 %token <tok> QNULLTERMINATED
196 %token <tok> QSETBUFFERSIZE
197 %token <tok> QSETSTRINGLENGTH
199 %token <tok> QMAXREAD
200 %token <tok> QTESTINRANGE
205 /* identifiers, literals */
206 %token <entry> IDENTIFIER
207 %token <cname> NEW_IDENTIFIER TYPE_NAME_OR_ID
208 %token <annotation> CANNOTATION
209 %token <expr> CCONSTANT
211 %type <flagspec> flagSpec
212 %type <expr> cconstantExpr
213 %token <entry> ITER_NAME ITER_ENDNAME
214 %type <entry> endIter
216 %type <funcclauselist> functionClauses functionClausesPlain
217 %type <funcclause> functionClause functionClause functionClausePlain
219 %type <globsclause> globalsClause globalsClausePlain
220 %type <modsclause> modifiesClause modifiesClausePlain nomodsClause
221 %type <warnclause> warnClause warnClausePlain
222 %type <funcclause> conditionClause conditionClausePlain
223 %type <stateclause> stateClause stateClausePlain
224 %type <msconstraint> metaStateConstraint
225 %type <fcnconstraint> functionConstraint
226 %type <msspec> metaStateSpecifier
227 %type <msexpr> metaStateExpression
229 %type <sr> globId globIdListExpr
230 %type <globset> globIdList
232 %token <ctyp> TYPE_NAME
233 %token <msinfo> METASTATE_NAME
234 %type <msinfo> metaStateName
235 %type <cname> enumerator newId /*@-varuse@*/ /* yacc declares yytranslate here */
236 %type <count> pointers /*@=varuse@*/
238 %type <tok> doHeader stateTag conditionTag startConditionClause
239 %type <typequal> exitsQualifier checkQualifier stateQualifier
240 paramQualifier returnQualifier visibilityQualifier
241 typedefQualifier refcountQualifier definedQualifier
243 /* type construction */
244 %type <ctyp> abstractDecl abstractDeclBase optAbstractDeclBase
245 %type <ctyp> suSpc enumSpc typeName typeSpecifier
247 %type <ntyp> namedDecl namedDeclBase optNamedDecl
248 %type <ntyp> plainNamedDecl plainNamedDeclBase
249 %type <ntyp> structNamedDecl
250 %type <ntyp> fcnDefHdrAux plainFcn
252 %type <oentry> paramDecl
255 %type <ntyplist> structNamedDeclList
257 %type <entrylist> genericParamList paramTypeList paramList idList paramIdList
258 %type <alist> argumentExprList iterArgList
259 %type <alist> initList
260 %type <flist> structDeclList structDecl
261 %type <srset> locModifies modList specClauseList optSpecClauseList
262 %type <sr> mExpr modListExpr specClauseListExpr
265 %type <con> BufConstraint
266 %type <tok> relationalOp
267 %type <tok> BufBinaryOp
268 %type <tok> bufferModifier
270 %type <conE> BufConstraintExpr
272 %type <conE> BufConstraintTerm
273 %type <sr> BufConstraintSrefExpr
275 %type <conL> BufConstraintList
277 %type <tok> BufUnaryOp
279 %type <enumnamelist> enumeratorList
280 %type <cstringlist> fieldDesignator
282 %type <expr> sizeofExpr sizeofExprAux offsetofExpr
283 %type <expr> openScope closeScope
284 %type <expr> instanceDecl namedInitializer optDeclarators
285 %type <expr> primaryExpr postfixExpr primaryIterExpr postfixIterExpr
286 %type <expr> unaryExpr castExpr timesExpr plusExpr
287 %type <expr> unaryIterExpr castIterExpr timesIterExpr plusIterExpr
288 %type <expr> shiftExpr relationalExpr equalityExpr bitandExpr
289 %type <expr> xorExpr bitorExpr andExpr
290 %type <expr> orExpr conditionalExpr assignExpr
291 %type <expr> shiftIterExpr relationalIterExpr equalityIterExpr bitandIterExpr
292 %type <expr> xorIterExpr bitorIterExpr andIterExpr
293 %type <expr> orIterExpr conditionalIterExpr assignIterExpr iterArgExpr
294 %type <expr> expr optExpr constantExpr
295 %type <expr> init macroBody iterBody endBody partialIterStmt iterSelectionStmt
296 %type <expr> stmt stmtList fcnBody iterStmt iterDefStmt iterDefStmtList
297 %type <expr> labeledStmt caseStmt defaultStmt
298 %type <expr> compoundStmt compoundStmtAux compoundStmtRest compoundStmtAuxErr
299 %type <expr> expressionStmt selectionStmt iterationStmt jumpStmt iterDefIterationStmt
300 %type <expr> stmtErr stmtListErr compoundStmtErr expressionStmtErr
301 %type <expr> iterationStmtErr initializerList initializer ifPred whilePred forPred iterWhilePred
303 %type <typequal> storageSpecifier typeQualifier typeModifier globQual
304 %type <tquallist> optGlobQuals
305 %type <qtyp> completeType completeTypeSpecifier optCompleteType
306 %type <qtyp> completeTypeSpecifierAux altType typeExpression
307 /*%type <expr> lclintassertion*/
319 | externalDefs externalDef
322 : fcnDef optSemi { uentry_clearDecl (); }
323 | constantDecl { uentry_clearDecl (); }
324 | fcnDecl { uentry_clearDecl (); }
325 | iterDecl { uentry_clearDecl (); }
326 | macroDef { uentry_clearDecl (); }
327 | initializer { uentry_checkDecl (); exprNode_free ($1); }
328 | error { uentry_clearDecl (); }
331 : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
332 { checkConstant ($2, $4); }
333 | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
334 { checkValueConstant ($2, $4, $8) ; }
337 : QFUNCTION { context_enterFunctionHeader (); } plainFcn optSemi QENDMACRO
339 declareStaticFunction ($3); context_quietExitFunction ();
340 context_exitFunctionHeader ();
346 qtype qint = qtype_create (ctype_int);
347 $$ = idDecl_fixBase ($1, qint);
350 | completeTypeSpecifier NotType plainNamedDecl
351 { $$ = idDecl_fixBase ($3, $1); }
355 | pointers plainNamedDeclBase
356 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
359 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
360 | IsType TLPAREN NotType namedDecl IsType TRPAREN
361 { $$ = idDecl_expectFunction ($4); }
362 | namedDeclBase TLSQBR TRSQBR
363 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
364 | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
366 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), exprNode_getLongValue ($4)));
368 | namedDeclBase PushType TLPAREN TRPAREN
369 { setCurrentParams (uentryList_missingParams); }
371 { /* need to support globals and modifies here! */
372 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
373 uentryList_makeMissingParams ());
375 $$ = idDecl_replaceCtype ($1, ct);
376 idDecl_addClauses ($$, $6);
379 | namedDeclBase PushType TLPAREN genericParamList TRPAREN
380 { setCurrentParams ($4); }
382 { setImplictfcnConstraints ();
383 clearCurrentParams ();
384 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
385 idDecl_addClauses ($$, $7);
390 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
391 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
392 { $$ = idDecl_expectFunction ($4); }
393 | plainNamedDeclBase TLSQBR TRSQBR
394 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
395 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
399 if (exprNode_hasValue ($4)
400 && multiVal_isInt (exprNode_getValue ($4)))
402 value = (int) multiVal_forceInt (exprNode_getValue ($4));
409 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
411 | plainNamedDeclBase PushType TLPAREN TRPAREN
412 { setCurrentParams (uentryList_missingParams); }
415 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
416 uentryList_makeMissingParams ());
418 $$ = idDecl_replaceCtype ($1, ct);
419 idDecl_addClauses ($$, $6);
422 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
423 { setCurrentParams ($4); }
426 clearCurrentParams ();
427 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
428 idDecl_addClauses ($$, $7);
433 : QITER newId TLPAREN genericParamList TRPAREN
434 { setCurrentParams ($4); } functionClausesPlain
435 { clearCurrentParams (); } optSemi QENDMACRO
436 { declareCIter ($2, $4); }
439 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); }
440 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); }
441 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); }
442 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); }
445 : fcnDefHdrAux { clabstract_declareFunction ($1); }
448 : metaStateSpecifier TASSIGN metaStateExpression
449 { $$ = metaStateConstraint_create ($1, $3); }
452 : BufConstraintSrefExpr { cscanner_expectingMetaStateName (); } TCOLON metaStateName
453 { cscanner_clearExpectingMetaStateName ();
454 $$ = metaStateSpecifier_create ($1, $4); }
457 : metaStateSpecifier { $$ = metaStateExpression_create ($1); }
458 | metaStateSpecifier TBAR metaStateExpression { $$ = metaStateExpression_createMerge ($1, $3); }
466 : BufConstraint TCAND BufConstraintList { $$ = constraintList_add ($3, $1); }
467 | BufConstraint { $$ = constraintList_single ($1); }
470 : BufConstraintExpr relationalOp BufConstraintExpr {
471 $$ = makeConstraintParse3 ($1, $2, $3);
472 DPRINTF(("Done BufConstraint1\n")); }
485 | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3); DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
486 | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
487 DPRINTF( ("Got BufConstraintExpr BINary Op ") );
488 $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
491 : BufConstraintSrefExpr { $$ = constraintExpr_makeTermsRef($1);}
495 t = cstring_toCharsSafe (exprNode_unparse($1));
499 $$ = constraintExpr_makeIntLiteral (exprNode_getLongValue ($1));
502 BufConstraintSrefExpr
504 { /*@-onlytrans@*/ $$ = checkbufferConstraintClausesId ($1); /*@=onlytrans@*/ /*@i523@*/ }
506 { $$ = fixStateClausesId ($1); }
507 | BufConstraintSrefExpr TLSQBR TRSQBR
508 { $$ = sRef_makeAnyArrayFetch ($1); }
509 | BufConstraintSrefExpr TLSQBR CCONSTANT TRSQBR
513 t = cstring_toCharsSafe (exprNode_unparse($3));
516 $$ = sRef_makeArrayFetchKnown ($1, exprNode_getLongValue ($3));
518 | TMULT BufConstraintSrefExpr
519 { $$ = sRef_constructPointer ($2); }
520 | TLPAREN BufConstraintSrefExpr TRPAREN
522 | BufConstraintSrefExpr TDOT newId
523 { cstring_markOwned ($3); $$ = sRef_buildField ($1, $3); }
524 | BufConstraintSrefExpr ARROW_OP newId
525 { cstring_markOwned ($3); $$ = sRef_makeArrow ($1, $3); }
528 | BufConstraintTerm TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
529 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
530 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
531 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
532 $$ = sRef_buildField ($1, $3); }
548 ** Function clauses can appear in any order.
552 : { $$ = functionClauseList_new (); }
553 | functionClause functionClauses
554 { $$ = functionClauseList_prepend ($2, $1); }
557 ** Inside macro definitions, there are no end macros.
562 { $$ = functionClauseList_new (); }
563 | functionClausePlain functionClausesPlain
564 { $$ = functionClauseList_prepend ($2, $1); }
567 : globalsClause { $$ = functionClause_createGlobals ($1); }
568 | modifiesClause { $$ = functionClause_createModifies ($1); }
569 | nomodsClause { $$ = functionClause_createModifies ($1); }
570 | stateClause { $$ = functionClause_createState ($1); }
571 | conditionClause { $$ = $1; }
572 | warnClause { $$ = functionClause_createWarn ($1); }
575 : globalsClausePlain { $$ = functionClause_createGlobals ($1); }
576 | modifiesClausePlain { $$ = functionClause_createModifies ($1); }
577 | nomodsClause { $$ = functionClause_createModifies ($1); }
578 | stateClausePlain { $$ = functionClause_createState ($1); }
579 | conditionClausePlain { $$ = $1; }
580 | warnClausePlain { $$ = functionClause_createWarn ($1); }
583 : globalsClausePlain QENDMACRO { $$ = $1; }
586 : QGLOBALS { setProcessingGlobalsList (); }
589 unsetProcessingGlobals ();
590 $$ = globalsClause_create ($1, $3);
594 : QNOMODS { $$ = modifiesClause_createNoMods ($1); }
597 : modifiesClausePlain QENDMACRO { $$ = $1; }
602 context_setProtectVars (); enterParamsTemp ();
603 sRef_setGlobalScopeSafe ();
608 sRef_clearGlobalScopeSafe ();
609 context_releaseVars ();
610 $$ = modifiesClause_create ($1, $3);
615 { $$ = flagSpec_createPlain ($1); }
616 | flagId TBAR flagSpec
617 { $$ = flagSpec_createOr ($1, $3); }
623 : warnClausePlain QENDMACRO { $$ = $1; }
626 : QWARN flagSpec cconstantExpr
627 { $$ = warnClause_create ($1, $2, $3); }
629 { $$ = warnClause_create ($1, $2, exprNode_undefined); }
632 : globIdListExpr { $$ = globSet_single ($1); }
633 | globIdList TCOMMA globIdListExpr { $$ = globSet_insert ($1, $3); }
636 : optGlobQuals globId { $$ = clabstract_createGlobal ($2, $1); }
639 : /* empty */ { $$ = qualList_undefined; }
640 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
643 : id { $$ = uentry_getSref ($1); }
644 | NEW_IDENTIFIER { $$ = clabstract_unrecognizedGlobal ($1); }
645 | initializer { $$ = clabstract_checkGlobal ($1); }
648 : QUNDEF { $$ = qual_createUndef (); }
649 | QKILLED { $$ = qual_createKilled (); }
650 | QOUT { $$ = qual_createOut (); }
651 | QIN { $$ = qual_createIn (); }
652 | QPARTIAL { $$ = qual_createPartial (); }
668 qtype qint = qtype_create (ctype_int);
669 $$ = idDecl_fixBase ($1, qint);
672 | completeTypeSpecifier NotType namedDecl
673 { $$ = idDecl_fixBase ($3, $1); }
676 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
679 exprNode_checkFunctionBody ($3); $$ = $3;
680 context_exitInner ($3);
683 { doneParams (); context_enterInnerContext (); }
686 context_exitInner ($3);
687 exprNode_checkFunctionBody ($3);
688 $$ = $3; /* old style */
694 context_setFunctionDefined (exprNode_loc ($2));
695 exprNode_checkFunction (context_getHeader (), $2);
698 context_exitFunction ();
702 : modList optSemi { $$ = $1; }
703 | optSemi { $$ = sRefSet_new (); }
706 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
707 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
708 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
709 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
710 | TMULT modListExpr { $$ = modListPointer ($2); }
711 | TLPAREN modListExpr TRPAREN { $$ = $2; }
712 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
713 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
717 : modListExpr { $$ = $1; }
718 | cconstantExpr { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
722 : modListExpr { $$ = sRefSet_single ($1); }
723 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
727 { $$ = checkStateClausesId ($1); }
729 { $$ = fixStateClausesId ($1); }
730 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
731 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
732 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
733 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
734 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
735 $$ = sRef_buildField ($1, $3); }
736 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
737 $$ = sRef_makeArrow ($1, $3); }
740 : /* empty */ { $$ = sRefSet_undefined }
745 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
746 else { $$ = sRefSet_undefined; }
748 | specClauseList TCOMMA specClauseListExpr
749 { if (sRef_isValid ($3))
751 $$ = sRefSet_insert ($1, $3);
760 : id { $$ = exprNode_fromIdentifier ($1); }
761 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
763 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
764 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
765 | QEXTENSION { $$ = exprNode_makeError (); }
769 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
770 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
771 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
772 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
773 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
774 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
775 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
776 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
779 : assignExpr { $$ = exprNodeList_singleton ($1); }
780 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
784 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
785 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
786 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
787 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
788 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
789 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
790 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
791 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
792 | sizeofExpr { $$ = $1; }
793 | offsetofExpr { $$ = $1; }
796 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
797 | newId { $$ = cstringList_single ($1); }
800 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
801 { $$ = exprNode_offsetof ($4, $7); }
804 : IsType { context_setProtectVars (); }
805 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
808 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); }
809 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); }
810 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); }
811 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); }
815 | TLPAREN typeExpression TRPAREN castExpr
816 { $$ = exprNode_cast ($1, $4, $2); }
820 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
821 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
822 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
826 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
827 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
831 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
832 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
836 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
837 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
838 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
839 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
843 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
844 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
848 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
852 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
857 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
862 { exprNode_produceGuards ($1);
863 context_enterAndClause ($1);
867 $$ = exprNode_op ($1, $4, $2);
868 context_exitAndClause ($$, $4);
875 exprNode_produceGuards ($1);
876 context_enterOrClause ($1);
880 $$ = exprNode_op ($1, $4, $2);
881 context_exitOrClause ($$, $4);
886 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
887 { context_enterFalseClause ($1); } conditionalExpr
888 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
892 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
893 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
894 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
895 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
896 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
897 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
898 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
899 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
900 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
901 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
902 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
906 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
909 : /* empty */ { $$ = exprNode_undefined; }
915 /* instance_orTypeDecl_and_possible_initialization */
918 : instanceDecl { $$ = $1; }
919 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
920 | typeDecl { $$ = exprNode_makeError (); }
923 : completeTypeSpecifier IsType TSEMI
924 { $$ = exprNode_makeError (); }
926 ** This causes r/r conflicts with function definitions.
927 ** Instead we need to snarf one first. (gack)
929 ** | completeTypeSpecifier { setProcessingVars ($1); }
931 ** namedInitializerList IsType TSEMI
932 ** { unsetProcessingVars (); }
935 ** the solution is pretty ugly:
937 | completeTypeSpecifier NotType namedDecl NotType
939 setProcessingVars ($1);
940 processNamedDecl ($3);
942 IsType optDeclarators TSEMI IsType
944 unsetProcessingVars ();
945 $$ = exprNode_makeEmptyInitialization ($3);
946 DPRINTF (("Empty initialization: %s", exprNode_unparse ($$)));
948 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
949 { setProcessingVars ($1); processNamedDecl ($3); }
950 IsType init optDeclarators TSEMI IsType
951 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
952 unsetProcessingVars ();
958 processNamedDecl ($1);
959 $$ = exprNode_makeEmptyInitialization ($1);
961 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
962 { $$ = exprNode_makeInitialization ($1, $6); }
965 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
966 NotType namedInitializerList IsType TSEMI { unsetProcessingTypedef (); }
967 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
968 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
971 : { g_expectingTypeName = TRUE; }
974 : { g_expectingTypeName = TRUE; context_pushLoc (); }
977 : namedInitializerListAux IsType { ; }
979 namedInitializerListAux
980 : namedInitializer { ; }
981 | namedInitializerList TCOMMA NotType namedInitializer { ; }
984 : /* empty */ { $$ = exprNode_makeError (); }
985 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
989 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
990 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
995 { $$ = exprNodeList_singleton ($1); }
996 | initList TCOMMA init
997 { $$ = exprNodeList_push ($1, $3); }
1000 ** need to do the storage class global hack so tags are
1001 ** declared with the right storage class.
1005 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1006 | QINLINE { $$ = qual_createInline (); }
1007 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1008 | QAUTO { $$ = qual_createAuto (); }
1009 | QREGISTER { $$ = qual_createRegister (); }
1011 nullterminatedQualifier:
1012 QNULLTERMINATED IsType { $$ = qual_createNullTerminated (); }
1015 : stateClausePlain QENDMACRO { $$ = $1; }
1020 context_setProtectVars ();
1022 sRef_setGlobalScopeSafe ();
1024 specClauseList optSemi IsType
1027 sRef_clearGlobalScopeSafe ();
1028 context_releaseVars ();
1029 $$ = stateClause_createPlain ($1, $4);
1033 : conditionClausePlain QENDMACRO { $$ = $1; }
1035 startConditionClause
1036 : conditionTag NotType { $$ = $1; context_enterFunctionHeader (); }
1038 conditionClausePlain
1039 : startConditionClause stateQualifier
1041 context_exitFunctionHeader ();
1042 context_setProtectVars ();
1044 sRef_setGlobalScopeSafe ();
1046 optSpecClauseList optSemi IsType
1049 sRef_clearGlobalScopeSafe ();
1050 context_releaseVars ();
1051 $$ = functionClause_createState (stateClause_create ($1, $2, $4));
1053 | startConditionClause
1055 context_setProtectVars ();
1057 sRef_setGlobalScopeSafe ();
1059 functionConstraint optSemi IsType
1061 context_exitFunctionHeader ();
1063 sRef_clearGlobalScopeSafe ();
1064 context_releaseVars ();
1065 DPRINTF (("done optGlobBufConstraintsAux\n"));
1067 if (lltok_isEnsures ($1))
1069 $$ = functionClause_createEnsures ($3);
1071 else if (lltok_isRequires ($1))
1073 $$ = functionClause_createRequires ($3);
1080 DPRINTF (("FunctionclauseS: %s", functionClause_unparse ($$)));
1084 : BufConstraintList { $$ = functionConstraint_createBufferConstraint ($1); }
1085 | metaStateConstraint { $$ = functionConstraint_createMetaStateConstraint ($1); DPRINTF (("Made constraint: %s", functionConstraint_unparse ($$))); }
1088 : QEXITS { $$ = qual_createExits (); }
1089 | QMAYEXIT { $$ = qual_createMayExit (); }
1090 | QTRUEEXIT { $$ = qual_createTrueExit (); }
1091 | QFALSEEXIT { $$ = qual_createFalseExit (); }
1092 | QNEVEREXIT { $$ = qual_createNeverExit (); }
1095 : QCHECKED { $$ = qual_createChecked (); }
1096 | QCHECKMOD { $$ = qual_createCheckMod (); }
1097 | QUNCHECKED { $$ = qual_createUnchecked (); }
1098 | QCHECKEDSTRICT { $$ = qual_createCheckedStrict (); }
1101 : QOWNED { $$ = qual_createOwned (); }
1102 | QDEPENDENT { $$ = qual_createDependent (); }
1103 | QYIELD { $$ = qual_createYield (); }
1104 | QTEMP { $$ = qual_createTemp (); }
1105 | QONLY { $$ = qual_createOnly (); }
1106 | QKEEP { $$ = qual_createKeep (); }
1107 | QKEPT { $$ = qual_createKept (); }
1108 | QSHARED { $$ = qual_createShared (); }
1109 | QUNIQUE { $$ = qual_createUnique (); }
1110 | QNULL { $$ = qual_createNull (); }
1111 | QISNULL { $$ = qual_createIsNull (); }
1112 | QRELNULL { $$ = qual_createRelNull (); }
1113 | QNOTNULL { $$ = qual_createNotNull (); }
1114 | QEXPOSED { $$ = qual_createExposed (); }
1115 | QOBSERVER { $$ = qual_createObserver (); }
1116 | CANNOTATION { $$ = qual_createMetaState ($1); }
1119 : QRETURNED { $$ = qual_createReturned (); }
1120 | QSEF { $$ = qual_createSef (); }
1123 : QUNUSED { $$ = qual_createUnused (); }
1124 | QEXTERNAL { $$ = qual_createExternal (); }
1127 : QTRUENULL { $$ = qual_createTrueNull (); }
1128 | QFALSENULL { $$ = qual_createFalseNull (); }
1131 : QABSTRACT { $$ = qual_createAbstract (); }
1132 | QCONCRETE { $$ = qual_createConcrete (); }
1133 | QMUTABLE { $$ = qual_createMutable (); }
1134 | QIMMUTABLE { $$ = qual_createImmutable (); }
1137 : QREFCOUNTED { $$ = qual_createRefCounted (); }
1138 | QREFS { $$ = qual_createRefs (); }
1139 | QKILLREF { $$ = qual_createKillRef (); }
1140 | QRELDEF { $$ = qual_createRelDef (); }
1141 | QNEWREF { $$ = qual_createNewRef (); }
1142 | QTEMPREF { $$ = qual_createTempRef (); }
1145 : QSHORT { $$ = qual_createShort (); }
1146 | QLONG { $$ = qual_createLong (); }
1147 | QSIGNED { $$ = qual_createSigned (); }
1148 | QUNSIGNED { $$ = qual_createUnsigned (); }
1151 : QOUT { $$ = qual_createOut (); }
1152 | QIN { $$ = qual_createIn (); }
1153 | QPARTIAL { $$ = qual_createPartial (); }
1154 | QSPECIAL { $$ = qual_createSpecial (); }
1157 : QCONST IsType { $$ = qual_createConst (); }
1158 | QVOLATILE IsType { $$ = qual_createVolatile (); }
1159 | definedQualifier IsType { $$ = $1; }
1160 | stateQualifier IsType { $$ = $1; }
1161 | exitsQualifier IsType { $$ = $1; }
1162 | paramQualifier IsType { $$ = $1; }
1163 | checkQualifier IsType { $$ = $1; }
1164 | returnQualifier IsType { $$ = $1; }
1165 | visibilityQualifier IsType { $$ = $1; }
1166 | typedefQualifier IsType { $$ = $1; }
1167 | refcountQualifier IsType { $$ = $1; }
1170 ** This is copied into the mtgrammar!
1180 | QANYTYPE NotType { $$ = ctype_unknown; }
1181 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
1182 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1183 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
1187 | typeModifier NotType { $$ = ctype_fromQual ($1); }
1190 : IsType completeTypeSpecifier IsType
1191 { $$ = qtype_resolve ($2); }
1193 completeTypeSpecifier
1194 : completeTypeSpecifierAux { $$ = $1; }
1195 | completeTypeSpecifierAux QALT altType QENDMACRO
1196 { $$ = qtype_mergeAlt ($1, $3); }
1200 | typeExpression TCOMMA altType
1201 { $$ = qtype_mergeAlt ($1, $3); }
1203 completeTypeSpecifierAux
1204 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1205 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1206 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
1209 : /* empty */ { $$ = qtype_unknown (); }
1210 | completeTypeSpecifier { $$ = $1; }
1213 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1214 CreateStructInnerScope
1215 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1217 { $$ = declareStruct ($3, $8); }
1218 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1219 CreateStructInnerScope
1220 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1222 { $$ = declareUnion ($3, $8); }
1223 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
1224 { $$ = declareStruct ($3, uentryList_new ()); }
1225 | NotType CUNION newId IsType TLBRACE TRBRACE
1226 { $$ = declareUnion ($3, uentryList_new ()); }
1227 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1228 CreateStructInnerScope
1229 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1231 { $$ = declareUnnamedStruct ($7); }
1232 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1233 CreateStructInnerScope structDeclList DeleteStructInnerScope
1234 { sRef_clearGlobalScopeSafe (); }
1236 { $$ = declareUnnamedUnion ($7); }
1237 | NotType CSTRUCT IsType TLBRACE TRBRACE
1238 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
1239 | NotType CUNION IsType TLBRACE TRBRACE
1240 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
1241 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
1242 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
1245 : { g_expectingTypeName = FALSE; }
1249 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1250 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1253 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
1254 { $$ = fixUentryList ($3, $1); }
1255 | completeTypeSpecifier IsType TSEMI
1256 { $$ = fixUnnamedDecl ($1); }
1259 : structNamedDecl NotType
1260 { $$ = idDeclList_singleton ($1); }
1261 | structNamedDeclList TCOMMA structNamedDecl NotType
1262 { $$ = idDeclList_add ($1, $3); }
1264 structNamedDecl /* hack to get around namespace problems */
1265 : namedDecl { $$ = $1; }
1266 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1267 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1268 /* Need the IsType in case there is a cast in the constant expression. */
1271 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1272 { $$ = declareUnnamedEnum ($4); }
1273 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1274 { context_popLoc (); $$ = declareEnum ($3, $6); }
1275 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1279 { $$ = enumNameList_single ($1); }
1280 | enumeratorList TCOMMA enumerator
1281 { $$ = enumNameList_push ($1, $3); }
1282 | enumeratorList TCOMMA
1286 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1287 usymtab_supGlobalEntry (ue);
1290 | newId TASSIGN IsType constantExpr
1291 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1292 usymtab_supGlobalEntry (ue);
1298 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1299 | pointers TYPE_NAME
1301 qtype qt = qtype_unknown ();
1303 qtype_adjustPointers ($1, qt);
1304 $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1306 | pointers optNamedDecl
1307 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1311 | pointers namedDeclBase
1312 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1315 : paramTypeList { $$ = handleParamTypeList ($1); }
1316 | NotType paramIdList { $$ = handleParamIdList ($2); }
1319 : QCONST { /* ignored for now */; }
1324 | innerModsList innerMods { ; }
1328 | TMULT innerModsList { $$ = 1; }
1329 | TMULT pointers { $$ = 1 + $2; }
1330 | TMULT innerModsList pointers { $$ = 1 + $3; }
1334 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1337 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1338 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1341 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1343 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1346 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1347 | paramList TCOMMA { storeLoc (); } paramDecl
1348 { $$ = uentryList_add ($1, $4); }
1351 : IsType completeTypeSpecifier optNamedDecl IsType
1353 if (isFlipOldStyle ())
1355 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1361 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1363 | newId /* its an old-style declaration */
1365 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1369 llparseerror (message ("Inconsistent function parameter syntax: %q",
1370 idDecl_unparse (tparam)));
1374 $$ = makeCurrentParam (tparam);
1375 idDecl_free (tparam);
1380 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1383 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1385 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1388 : /* empty */ { $$ = ctype_unknown; }
1392 : IsType TLPAREN NotType abstractDecl TRPAREN
1393 { $$ = ctype_expectFunction ($4); }
1394 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1395 | TLSQBR constantExpr TRSQBR
1396 { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
1397 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1398 | abstractDeclBase TLSQBR constantExpr TRSQBR
1399 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
1400 | IsType TLPAREN TRPAREN
1401 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1402 | IsType TLPAREN paramTypeList TRPAREN
1403 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1404 | abstractDeclBase IsType TLPAREN TRPAREN
1405 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1406 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1407 { $$ = ctype_makeParamsFunction ($1, $4); }
1421 /* | lclintassertion {$$ = $1; printf ("Doing stmt lclintassertion\n"); }*/
1425 : QSETBUFFERSIZE id CCONSTANT QENDMACRO { printf(" QSETBUFFERSIZE id CCONSTANT HEllo World\n"); uentry_setBufferSize($2, $3); $$ = exprNode_createTok ($4);
1427 | QSETSTRINGLENGTH id CCONSTANT QENDMACRO { printf(" QSETSTRINGLENGTH id CCONSTANT HEllo World\n"); uentry_setStringLength($2, $3); $$ = exprNode_createTok ($4);
1429 | QTESTINRANGE id CCONSTANT QENDMACRO {printf(" QTESTINRANGE\n"); uentry_testInRange($2, $3); $$ = exprNode_createTok ($4);
1432 /* | QSETBUFFERSIZE id id {$$ = $2; printf(" QSETBUFFERSIZE id id HEllo World\n");} */
1435 : iterDefStmtList { $$ = $1; }
1442 | iterDefStmtList iterDefStmt
1443 { $$ = exprNode_concat ($1, $2); }
1445 iterDefIterationStmt
1446 : iterWhilePred iterDefStmtList
1447 { $$ = exprNode_while ($1, $2); }
1448 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1449 { $$ = exprNode_doWhile ($2, $5); }
1450 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1451 { $$ = exprNode_doWhile ($2, $5); }
1452 | forPred iterDefStmt
1453 { $$ = exprNode_for ($1, $2); }
1456 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1457 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1459 { $$ = exprNode_forPred ($3, $5, $8);
1460 context_enterForClause ($5); }
1463 : ITER_NAME CreateInnerScope TLPAREN
1464 { setProcessingIterVars ($1); }
1466 { $$ = exprNode_iterStart ($1, $5); }
1467 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1473 | openScope initializerList { $$ = $1; DPRINTF (("def stmt: %s", exprNode_unparse ($$))); }
1478 | iterDefIterationStmt
1481 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1482 | error { $$ = exprNode_makeError (); }
1485 : ifPred iterDefStmt
1486 { /* don't: context_exitTrueClause ($1, $2); */
1487 $$ = exprNode_if ($1, $2);
1491 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1494 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1509 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1511 | error { $$ = exprNode_makeError (); }
1514 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1515 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
1517 /* Note that we can semantically check that the object to the case is
1518 indeed constant. In this case, we may not want to go through this effort */
1521 : CASE constantExpr { context_enterCaseClause ($2); }
1522 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
1523 | QFALLTHROUGH CASE constantExpr { context_enterCaseClause ($3); }
1524 TCOLON { $$ = exprNode_caseMarker ($3, TRUE); }
1527 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1528 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1529 | QFALLTHROUGH DEFAULT { context_enterCaseClause (exprNode_undefined); }
1530 TCOLON { $$ = exprNode_defaultMarker ($2, TRUE); }
1533 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1534 | CreateInnerScope compoundStmtAux
1535 { $$ = $2; context_exitInner ($2); }
1538 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1541 : { context_enterInnerContext (); }
1544 : { context_exitInnerPlain (); }
1546 CreateStructInnerScope
1547 : { context_enterStructInnerContext (); }
1549 DeleteStructInnerScope
1550 : { context_exitStructInnerContext (); }
1552 DeleteInnerScopeSafe
1553 : { context_exitInnerSafe (); }
1556 : TRBRACE { $$ = exprNode_createTok ($1); }
1557 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1558 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1559 | stmtList QNOTREACHED TRBRACE
1560 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1561 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1562 | initializerList QNOTREACHED TRBRACE
1563 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1564 | initializerList stmtList TRBRACE
1565 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1566 | initializerList stmtList QNOTREACHED TRBRACE
1567 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1568 lltok_getLoc ($3)));
1573 : TLBRACE compoundStmtRest
1574 { $$ = exprNode_makeBlock ($2); }
1578 { $$ = exprNode_createTok ($2); }
1579 | TLBRACE stmtListErr TRBRACE
1580 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1581 | TLBRACE initializerList TRBRACE
1582 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1583 | TLBRACE initializerList stmtList TRBRACE
1584 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1588 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1591 : initializer { $$ = $1; }
1592 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1596 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1599 : TSEMI { $$ = exprNode_createTok ($1); }
1600 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1603 : TSEMI { $$ = exprNode_createTok ($1); }
1604 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1605 | expr { $$ = exprNode_checkExpr ($1); }
1608 : CIF TLPAREN expr TRPAREN
1609 { $$ = $3; exprNode_produceGuards ($3); context_enterTrueClause ($3); }
1611 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1612 ** { $$ = $3; context_enterTrueClause (); }
1618 context_exitTrueClause ($1, $2);
1619 $$ = exprNode_if ($1, $2);
1621 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
1623 context_exitClause ($1, $2, $5);
1624 $$ = exprNode_ifelse ($1, $2, $5);
1626 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1627 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1630 : WHILE TLPAREN expr TRPAREN
1631 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1632 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1635 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1638 : ITER_NAME { context_enterIterClause (); }
1639 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1641 compoundStmt endIter DeleteInnerScope
1643 $$ = exprNode_iter ($1, $6, $8, $9);
1648 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1649 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1650 { $$ = exprNodeList_push ($1, $4); }
1653 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1654 | id { $$ = exprNode_iterId ($1); }
1655 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1657 if (uentry_isValid (ue))
1659 $$ = exprNode_iterId (ue);
1663 $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1666 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1669 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1674 | cconstantExpr CCONSTANT { $$ = exprNode_combineLiterals ($1, $2); }
1678 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1682 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1683 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1684 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1685 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1686 { $$ = exprNode_vaArg ($1, $3, $5); }
1687 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
1688 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
1689 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1690 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1694 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1695 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1696 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1697 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1698 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1699 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1700 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1701 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1702 | sizeofExpr { $$ = $1; }
1706 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1710 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1711 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1712 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1716 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1717 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1721 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1722 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1726 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1727 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1728 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1729 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1732 : relationalIterExpr
1733 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1734 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1738 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1742 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1747 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1751 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1755 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1759 | orExpr TQUEST { context_enterTrueClause ($1); }
1760 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1761 { $$ = exprNode_cond ($1, $4, $7); }
1764 : conditionalIterExpr
1765 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1766 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1767 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1768 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1769 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1770 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1771 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1772 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1773 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1774 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1775 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1778 : ITER_ENDNAME { $$ = $1; }
1779 | /* empty */ { $$ = uentry_undefined; }
1782 : DO { context_enterDoWhileClause (); $$ = $1; }
1786 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1787 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
1788 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1790 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1793 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1794 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1795 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1796 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1797 { $$ = exprNode_doWhile ($2, $5); }
1798 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1801 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1802 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1803 | QINNERCONTINUE CONTINUE TSEMI
1804 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1805 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1806 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1807 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1808 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1809 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1810 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1811 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1822 | ITER_NAME { $$ = uentry_getName ($1); }
1823 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1824 | id { $$ = uentry_getName ($1); }
1825 | TYPE_NAME_OR_ID { $$ = $1; }
1829 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1833 /*@-redecl@*/ /*@-namechecks@*/
1834 extern char *yytext;
1835 /*@=redecl@*/ /*@=namechecks@*/
1837 # include "bison.reset"
1839 void yyerror (/*@unused@*/ char *s)
1841 static bool givehint = FALSE;
1843 if (context_inIterDef ())
1845 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1846 context_inFunctionName ()));
1848 else if (context_inIterEnd ())
1850 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1851 context_inFunctionName ()));
1853 else if (context_inMacro ())
1855 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1856 context_inFunctionName ()));
1858 if (context_inMacroUnknown ())
1862 llhint (cstring_makeLiteral
1863 ("Precede macro definition with /*@notfunction@*/ "
1864 "to suppress checking and force expansion"));
1870 context_exitAllClausesQuiet ();
1874 llparseerror (cstring_undefined);