2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
29 ** Yacc/Bison grammar for extended ANSI C used by Splint.
31 ** original grammar by Nate Osgood ---
32 ** hacrat@catfish.lcs.mit.edu Mon Jun 14 13:06:32 1993
34 ** changes for Splint --- handle typedef names correctly
35 ** fix struct/union parsing bug (empty struct is accepted)
36 ** add productions to handle macros --- require
37 ** error correction --- main source of conflicts in grammar.
38 ** need to process initializations sequentially, L->R
40 ** production names are cryptic, so more productions fit on one line
42 ** conflicts: 87 shift/reduce, 18 reduce/reduce
43 ** most of these are due to handling macros
44 ** a few are due to handling type expressions
50 extern void swallowMacro (void);
51 extern void yyerror (char *);
53 # include "splintMacros.nf"
55 # include "cscanner.h"
56 # include "cgrammar.h"
57 # include "exprChecks.h"
62 # define SHOWCSYM FALSE
65 ** This is necessary, or else when the bison-generated code #include's malloc.h,
66 ** there will be a parse error.
68 ** Unfortunately, it means the error checking on malloc, etc. is lost for allocations
69 ** in bison-generated files under Win32.
87 /*@dependent@*/ sRef sr;
90 /*@only@*/ functionClauseList funcclauselist;
91 /*@only@*/ functionClause funcclause;
92 /*@only@*/ flagSpec flagspec;
93 /*@only@*/ globalsClause globsclause;
94 /*@only@*/ modifiesClause modsclause;
95 /*@only@*/ warnClause warnclause;
96 /*@only@*/ stateClause stateclause;
98 /*@only@*/ functionConstraint fcnconstraint;
100 /*@only@*/ metaStateConstraint msconstraint;
101 /*@only@*/ metaStateSpecifier msspec;
102 /*@only@*/ metaStateExpression msexpr;
103 /*@observer@*/ metaStateInfo msinfo;
105 /*@only@*/ sRefList srlist;
106 /*@only@*/ globSet globset;
107 /*@only@*/ qtype qtyp;
108 /*@only@*/ cstring cname;
109 /*@observer@*/ annotationInfo annotation;
110 /*@only@*/ idDecl ntyp;
111 /*@only@*/ idDeclList ntyplist;
112 /*@only@*/ uentryList flist;
113 /*@owned@*/ uentryList entrylist;
114 /*@observer@*/ /*@dependent@*/ uentry entry;
115 /*@only@*/ uentry oentry;
116 /*@only@*/ exprNode expr;
117 /*@only@*/ enumNameList enumnamelist;
118 /*@only@*/ exprNodeList exprlist;
119 /*@only@*/ sRefSet srset;
120 /*@only@*/ cstringList cstringlist;
131 /* standard C tokens */
133 %token <tok> BADTOK SKIPTOK
134 %token <tok> CTOK_ELIPSIS CASE DEFAULT CIF CELSE SWITCH WHILE DO CFOR
135 %token <tok> GOTO CONTINUE BREAK RETURN
136 %token <tok> TSEMI TLBRACE TRBRACE TCOMMA TCOLON TASSIGN TLPAREN
137 %token <tok> TRPAREN TLSQBR TRSQBR TDOT TAMPERSAND TEXCL TTILDE
138 %token <tok> TMINUS TPLUS TMULT TDIV TPERCENT TLT TGT TCIRC TBAR TQUEST
139 %token <tok> CSIZEOF CALIGNOF ARROW_OP CTYPEDEF COFFSETOF
140 %token <tok> INC_OP DEC_OP LEFT_OP RIGHT_OP
141 %token <tok> LE_OP GE_OP EQ_OP NE_OP AND_OP OR_OP
142 %token <tok> MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN SUB_ASSIGN
143 %token <tok> LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
144 %token <tok> CSTRUCT CUNION CENUM
145 %token <tok> VA_ARG VA_DCL
147 %token <tok> QGLOBALS
148 %token <tok> QMODIFIES
150 %token <tok> QCONSTANT
151 %token <tok> QFUNCTION
153 %token <tok> QDEFINES
155 %token <tok> QALLOCATES
157 %token <tok> QRELEASES
158 %token <tok> QPRECLAUSE
159 %token <tok> QPOSTCLAUSE
160 %token <tok> QINVARIANT
162 %token <tok> QUNDEF QKILLED
163 %token <tok> QENDMACRO
165 /* additional tokens introduced by splint pre-processor. */
166 %token <tok> LLMACRO LLMACROITER LLMACROEND TENDMACRO
168 /* break comments: */
169 %token <tok> QSWITCHBREAK QLOOPBREAK QINNERBREAK QSAFEBREAK
170 %token <tok> QINNERCONTINUE
172 /* case fall-through marker: */
173 %token <tok> QFALLTHROUGH
175 /* used in scanner only */
176 %token <tok> QLINTNOTREACHED
177 %token <tok> QLINTFALLTHROUGH
178 %token <tok> QLINTFALLTHRU
179 %token <tok> QARGSUSED
180 %token <tok> QPRINTFLIKE QLINTPRINTFLIKE QSCANFLIKE QMESSAGELIKE
182 /* not-reached marker: (used like a label) */
183 %token <tok> QNOTREACHED
185 /* type qualifiers: */
186 %token <tok> QCONST QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
187 %token <tok> QOUT QIN QYIELD QONLY QTEMP QSHARED QREF QUNIQUE
188 %token <tok> QCHECKED QUNCHECKED QCHECKEDSTRICT QCHECKMOD
189 %token <tok> QKEEP QKEPT QPARTIAL QSPECIAL QOWNED QDEPENDENT
190 %token <tok> QRETURNED QEXPOSED QNULL QOBSERVER QISNULL
191 %token <tok> QEXITS QMAYEXIT QNEVEREXIT QTRUEEXIT QFALSEEXIT
192 %token <tok> QLONG QSIGNED QUNSIGNED QSHORT QUNUSED QSEF QNOTNULL QRELNULL
193 %token <tok> QABSTRACT QCONCRETE QMUTABLE QIMMUTABLE
194 %token <tok> QTRUENULL QFALSENULL QEXTERNAL
195 %token <tok> QREFCOUNTED QREFS QNEWREF QTEMPREF QKILLREF QRELDEF
196 %token <ctyp> CGCHAR CBOOL CINT CGFLOAT CDOUBLE CVOID
197 %token <tok> QANYTYPE QINTEGRALTYPE QUNSIGNEDINTEGRALTYPE QSIGNEDINTEGRALTYPE
199 %token <tok> QNULLTERMINATED
200 %token <tok> QSETBUFFERSIZE
201 %token <tok> QSETSTRINGLENGTH
203 %token <tok> QMAXREAD
204 %token <tok> QTESTINRANGE
209 /* identifiers, literals */
210 %token <entry> IDENTIFIER
211 %token <cname> NEW_IDENTIFIER TYPE_NAME_OR_ID
212 %token <annotation> CANNOTATION
213 %token <expr> CCONSTANT
215 %type <flagspec> flagSpec
216 %type <expr> cconstantExpr
217 %token <entry> ITER_NAME ITER_ENDNAME
218 %type <entry> endIter
220 %type <funcclauselist> functionClauses functionClausesPlain
221 %type <funcclause> functionClause functionClause functionClausePlain
223 %type <globsclause> globalsClause globalsClausePlain
224 %type <modsclause> modifiesClause modifiesClausePlain nomodsClause
225 %type <warnclause> warnClause warnClausePlain optWarnClause
226 %type <funcclause> conditionClause conditionClausePlain
227 %type <stateclause> stateClause stateClausePlain
228 %type <msconstraint> metaStateConstraint
229 %type <fcnconstraint> functionConstraint
230 %type <msspec> metaStateSpecifier
231 %type <msexpr> metaStateExpression
233 %type <sr> globId globIdListExpr
234 %type <globset> globIdList
236 %token <ctyp> TYPE_NAME
237 %token <msinfo> METASTATE_NAME
238 %type <msinfo> metaStateName
239 %type <cname> enumerator newId /*@-varuse@*/ /* yacc declares yytranslate here */
240 %type <count> pointers /*@=varuse@*/
242 %type <tok> doHeader stateTag conditionTag startConditionClause
243 %type <typequal> exitsQualifier checkQualifier stateQualifier
244 paramQualifier returnQualifier visibilityQualifier
245 typedefQualifier refcountQualifier definedQualifier
247 /* type construction */
248 %type <ctyp> abstractDecl abstractDeclBase optAbstractDeclBase
249 %type <ctyp> suSpc enumSpc typeName typeSpecifier
251 %type <ntyp> namedDecl namedDeclBase optNamedDecl
252 %type <ntyp> plainNamedDecl plainNamedDeclBase
253 %type <ntyp> structNamedDecl
254 %type <ntyp> fcnDefHdrAux plainFcn
256 %type <oentry> paramDecl
259 %type <ntyplist> structNamedDeclList
261 %type <entrylist> genericParamList paramTypeList paramList idList paramIdList
262 %type <exprlist> argumentExprList iterArgList
263 %type <exprlist> initList namedInitializerList namedInitializerListAux
264 %type <flist> structDeclList structDecl
265 %type <srset> locModifies modList specClauseList optSpecClauseList
266 %type <sr> mExpr modListExpr specClauseListExpr
269 %type <con> BufConstraint
270 %type <tok> relationalOp
271 %type <tok> BufBinaryOp
272 %type <tok> bufferModifier
274 %type <conE> BufConstraintExpr
276 %type <conE> BufConstraintTerm
277 %type <sr> BufConstraintSrefExpr
279 %type <conL> BufConstraintList
281 %type <conL> optStructInvariant
283 %type <tok> BufUnaryOp
285 /*drl 1/6/2002 either /\ or && */
286 %type <tok> constraintSeperator
288 %type <enumnamelist> enumeratorList
289 %type <cstringlist> fieldDesignator
291 %type <expr> sizeofExpr sizeofExprAux offsetofExpr
292 %type <expr> openScope closeScope
293 %type <expr> instanceDecl namedInitializer optDeclarators
294 %type <expr> primaryExpr postfixExpr primaryIterExpr postfixIterExpr
295 %type <expr> unaryExpr castExpr timesExpr plusExpr
296 %type <expr> unaryIterExpr castIterExpr timesIterExpr plusIterExpr
297 %type <expr> shiftExpr relationalExpr equalityExpr bitandExpr
298 %type <expr> xorExpr bitorExpr andExpr
299 %type <expr> orExpr conditionalExpr assignExpr
300 %type <expr> shiftIterExpr relationalIterExpr equalityIterExpr bitandIterExpr
301 %type <expr> xorIterExpr bitorIterExpr andIterExpr
302 %type <expr> orIterExpr conditionalIterExpr assignIterExpr iterArgExpr
303 %type <expr> expr optExpr constantExpr
304 %type <expr> init macroBody iterBody endBody partialIterStmt iterSelectionStmt
305 %type <expr> stmt stmtList fcnBody iterStmt iterDefStmt iterDefStmtList
306 %type <expr> labeledStmt caseStmt defaultStmt
307 %type <expr> compoundStmt compoundStmtAux compoundStmtRest compoundStmtAuxErr
308 %type <expr> expressionStmt selectionStmt iterationStmt jumpStmt iterDefIterationStmt
309 %type <expr> stmtErr stmtListErr compoundStmtErr expressionStmtErr
310 %type <expr> iterationStmtErr initializerList initializer ifPred whilePred forPred iterWhilePred
312 %type <typequal> storageSpecifier typeQualifier typeModifier globQual
313 %type <tquallist> optGlobQuals
314 %type <qtyp> completeType completeTypeSpecifier optCompleteType
315 %type <qtyp> completeTypeSpecifierAux altType typeExpression
326 : externalDef { context_checkGlobalScope (); }
327 | externalDefs externalDef { context_checkGlobalScope (); }
330 : fcnDef optSemi { uentry_clearDecl (); }
331 | constantDecl { uentry_clearDecl (); }
332 | fcnDecl { uentry_clearDecl (); }
333 | iterDecl { uentry_clearDecl (); }
334 | macroDef { uentry_clearDecl (); }
335 | initializer { uentry_checkDecl (); exprNode_free ($1); }
336 | TSEMI { uentry_clearDecl (); /* evans 2002-02-08: okay to have a null statement */ }
337 | error { uentry_clearDecl (); }
340 : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
341 { checkConstant ($2, $4); }
342 | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
343 { checkValueConstant ($2, $4, $8) ; }
346 : QFUNCTION { context_enterFunctionHeader (); } plainFcn optSemi QENDMACRO
348 declareStaticFunction ($3); context_quietExitFunction ();
349 context_exitFunctionHeader ();
355 qtype qint = qtype_create (ctype_int);
356 $$ = idDecl_fixBase ($1, qint);
359 | completeTypeSpecifier NotType plainNamedDecl
360 { $$ = idDecl_fixBase ($3, $1); }
364 | pointers plainNamedDeclBase
365 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
368 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
369 | IsType TLPAREN NotType namedDecl IsType TRPAREN
370 { $$ = idDecl_expectFunction ($4); }
371 | namedDeclBase TLSQBR TRSQBR
372 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
373 | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
375 exprNode_findValue ($4);
376 idDecl_notExpectingFunction ($1);
378 if (exprNode_hasValue ($4))
380 $$ = idDecl_replaceCtype ($1, ctype_makeInnerFixedArray (idDecl_getCtype ($1),
381 exprNode_getLongValue ($4)));
385 $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1)));
388 | namedDeclBase PushType TLPAREN TRPAREN
389 { setCurrentParams (uentryList_missingParams); }
391 { /* need to support globals and modifies here! */
392 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
393 uentryList_makeMissingParams ());
395 $$ = idDecl_replaceCtype ($1, ct);
396 idDecl_addClauses ($$, $6);
398 /*drl 7/25/01 added*/
399 setImplictfcnConstraints();
401 | namedDeclBase PushType TLPAREN genericParamList TRPAREN
402 { setCurrentParams ($4); }
404 { setImplictfcnConstraints ();
405 clearCurrentParams ();
406 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
407 idDecl_addClauses ($$, $7);
412 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
413 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
414 { $$ = idDecl_expectFunction ($4); }
415 | plainNamedDeclBase TLSQBR TRSQBR
416 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
417 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
421 if (exprNode_hasValue ($4)
422 && multiVal_isInt (exprNode_getValue ($4)))
424 value = (int) multiVal_forceInt (exprNode_getValue ($4));
431 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
433 | plainNamedDeclBase PushType TLPAREN TRPAREN
434 { setCurrentParams (uentryList_missingParams); }
437 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
438 uentryList_makeMissingParams ());
440 $$ = idDecl_replaceCtype ($1, ct);
441 idDecl_addClauses ($$, $6);
444 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
445 { setCurrentParams ($4); }
448 clearCurrentParams ();
449 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
450 idDecl_addClauses ($$, $7);
455 : QITER newId TLPAREN genericParamList TRPAREN
456 { setCurrentParams ($4); } functionClausesPlain
457 { clearCurrentParams (); } optSemi QENDMACRO
458 { declareCIter ($2, $4); }
461 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); }
462 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); }
463 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); }
464 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); }
467 : fcnDefHdrAux { clabstract_declareFunction ($1); }
470 : metaStateSpecifier TASSIGN metaStateExpression
471 { $$ = metaStateConstraint_create ($1, $3); }
474 : BufConstraintSrefExpr { cscanner_expectingMetaStateName (); } TCOLON metaStateName
475 { cscanner_clearExpectingMetaStateName ();
476 $$ = metaStateSpecifier_create ($1, $4); }
477 | CTOK_ELIPSIS { cscanner_expectingMetaStateName (); } TCOLON metaStateName
478 { cscanner_clearExpectingMetaStateName ();
479 $$ = metaStateSpecifier_createElipsis ($4); }
482 : metaStateSpecifier { $$ = metaStateExpression_create ($1); }
483 | metaStateSpecifier TBAR metaStateExpression { $$ = metaStateExpression_createMerge ($1, $3); }
495 : BufConstraint constraintSeperator BufConstraintList { $$ = constraintList_add ($3, $1); }
496 | BufConstraint { $$ = constraintList_single ($1); }
499 : BufConstraintExpr relationalOp BufConstraintExpr {
500 $$ = makeConstraintParse3 ($1, $2, $3);
501 DPRINTF(("Done BufConstraint1\n")); }
514 | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3); DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
515 | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
516 DPRINTF( ("Got BufConstraintExpr BINary Op ") );
517 $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
520 : BufConstraintSrefExpr { $$ = constraintExpr_makeTermsRef ($1);}
521 | CCONSTANT { $$ = constraintExpr_makeIntLiteral (exprNode_getLongValue ($1)); }
523 BufConstraintSrefExpr
525 { /*@-onlytrans@*/ $$ = checkbufferConstraintClausesId ($1); /*@=onlytrans@*/ /*@i523@*/ }
527 { $$ = fixStateClausesId ($1); }
528 | BufConstraintSrefExpr TLSQBR TRSQBR
529 { $$ = sRef_makeAnyArrayFetch ($1); }
530 | BufConstraintSrefExpr TLSQBR CCONSTANT TRSQBR
534 t = cstring_toCharsSafe (exprNode_unparse($3));
537 $$ = sRef_makeArrayFetchKnown ($1, exprNode_getLongValue ($3));
539 | TMULT BufConstraintSrefExpr
540 { $$ = sRef_constructPointer ($2); }
541 | TLPAREN BufConstraintSrefExpr TRPAREN
543 | BufConstraintSrefExpr TDOT newId
544 { cstring_markOwned ($3); $$ = sRef_buildField ($1, $3); }
545 | BufConstraintSrefExpr ARROW_OP newId
546 { cstring_markOwned ($3); $$ = sRef_makeArrow ($1, $3); }
549 | BufConstraintTerm TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
550 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
551 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
552 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
553 $$ = sRef_buildField ($1, $3); }
569 ** Function clauses can appear in any order.
573 : { $$ = functionClauseList_new (); }
574 | functionClause functionClauses
575 { $$ = functionClauseList_prepend ($2, $1); }
578 ** Inside macro definitions, there are no end macros.
583 { $$ = functionClauseList_new (); }
584 | functionClausePlain functionClausesPlain
585 { $$ = functionClauseList_prepend ($2, $1); }
588 : globalsClause { $$ = functionClause_createGlobals ($1); }
589 | modifiesClause { $$ = functionClause_createModifies ($1); }
590 | nomodsClause { $$ = functionClause_createModifies ($1); }
591 | stateClause { $$ = functionClause_createState ($1); }
592 | conditionClause { $$ = $1; }
593 | warnClause { $$ = functionClause_createWarn ($1); }
596 : globalsClausePlain { $$ = functionClause_createGlobals ($1); }
597 | modifiesClausePlain { $$ = functionClause_createModifies ($1); }
598 | nomodsClause { $$ = functionClause_createModifies ($1); }
599 | stateClausePlain { $$ = functionClause_createState ($1); }
600 | conditionClausePlain { $$ = $1; }
601 | warnClausePlain { $$ = functionClause_createWarn ($1); }
604 : globalsClausePlain QENDMACRO { $$ = $1; }
607 : QGLOBALS { setProcessingGlobalsList (); }
610 unsetProcessingGlobals ();
611 $$ = globalsClause_create ($1, $3);
615 : QNOMODS { $$ = modifiesClause_createNoMods ($1); }
618 : modifiesClausePlain QENDMACRO { $$ = $1; }
623 context_setProtectVars (); enterParamsTemp ();
624 sRef_setGlobalScopeSafe ();
629 sRef_clearGlobalScopeSafe ();
630 context_releaseVars ();
631 $$ = modifiesClause_create ($1, $3);
636 { $$ = flagSpec_createPlain ($1); }
637 | flagId TBAR flagSpec
638 { $$ = flagSpec_createOr ($1, $3); }
645 | /* empty */ { $$ = warnClause_undefined; }
648 : warnClausePlain QENDMACRO { $$ = $1; }
651 : QWARN flagSpec cconstantExpr
653 llassert (exprNode_knownStringValue ($3));
654 $$ = warnClause_create ($1, $2, cstring_copy (multiVal_forceString (exprNode_getValue ($3))));
658 { $$ = warnClause_create ($1, $2, cstring_undefined); }
661 : globIdListExpr { $$ = globSet_single ($1); }
662 | globIdList TCOMMA globIdListExpr { $$ = globSet_insert ($1, $3); }
665 : optGlobQuals globId { $$ = clabstract_createGlobal ($2, $1); }
668 : /* empty */ { $$ = qualList_undefined; }
669 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
672 : id { $$ = uentry_getSref ($1); }
673 | NEW_IDENTIFIER { $$ = clabstract_unrecognizedGlobal ($1); }
674 | initializer { $$ = clabstract_checkGlobal ($1); }
677 : QUNDEF { $$ = qual_createUndef (); }
678 | QKILLED { $$ = qual_createKilled (); }
679 | QOUT { $$ = qual_createOut (); }
680 | QIN { $$ = qual_createIn (); }
681 | QPARTIAL { $$ = qual_createPartial (); }
697 qtype qint = qtype_create (ctype_int);
698 $$ = idDecl_fixBase ($1, qint);
701 | completeTypeSpecifier NotType namedDecl
702 { $$ = idDecl_fixBase ($3, $1); }
705 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
708 exprNode_checkFunctionBody ($3); $$ = $3;
709 context_exitInner ($3);
711 | { context_enterOldStyleScope (); } initializerList
712 { oldStyleDoneParams (); context_enterInnerContext (); }
715 exprNode_checkFunctionBody ($4);
716 $$ = $4; /* oldstyle */
717 context_exitInner ($4);
723 context_setFunctionDefined (exprNode_loc ($2));
724 exprNode_checkFunction (context_getHeader (), $2);
727 context_exitFunction ();
731 : modList optSemi { $$ = $1; }
732 | optSemi { $$ = sRefSet_new (); }
735 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
736 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
737 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
738 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
739 | TMULT modListExpr { $$ = modListPointer ($2); }
740 | TLPAREN modListExpr TRPAREN { $$ = $2; }
741 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
742 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
746 : modListExpr { $$ = $1; }
747 | cconstantExpr { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
751 : modListExpr { $$ = sRefSet_single ($1); }
752 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
756 { $$ = checkStateClausesId ($1); }
758 { $$ = fixStateClausesId ($1); }
759 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
760 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
761 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
762 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
763 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
764 $$ = sRef_buildField ($1, $3); }
765 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
766 $$ = sRef_makeArrow ($1, $3); }
769 : /* empty */ { $$ = sRefSet_undefined }
774 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
775 else { $$ = sRefSet_undefined; }
777 | specClauseList TCOMMA specClauseListExpr
778 { if (sRef_isValid ($3))
780 $$ = sRefSet_insert ($1, $3);
789 : id { $$ = exprNode_fromIdentifier ($1); }
790 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
792 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
793 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
794 | QEXTENSION { $$ = exprNode_makeError (); }
798 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
799 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
800 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
801 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
802 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
803 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
804 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
805 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
808 : assignExpr { $$ = exprNodeList_singleton ($1); }
809 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
813 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
814 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
815 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
816 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
817 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
818 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
819 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
820 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
821 | sizeofExpr { $$ = $1; }
822 | offsetofExpr { $$ = $1; }
825 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
826 | newId { $$ = cstringList_single ($1); }
829 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
830 { $$ = exprNode_offsetof ($4, $7); }
833 : IsType { context_setProtectVars (); }
834 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
837 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); }
838 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); }
839 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); }
840 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); }
844 | TLPAREN typeExpression TRPAREN castExpr
845 { $$ = exprNode_cast ($1, $4, $2); }
849 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
850 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
851 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
855 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
856 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
860 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
861 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
865 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
866 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
867 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
868 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
872 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
873 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
877 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
881 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
886 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
891 { exprNode_produceGuards ($1);
892 context_enterAndClause ($1);
896 $$ = exprNode_op ($1, $4, $2);
897 context_exitAndClause ($$, $4);
904 exprNode_produceGuards ($1);
905 context_enterOrClause ($1);
909 $$ = exprNode_op ($1, $4, $2);
910 context_exitOrClause ($$, $4);
915 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
916 { context_enterFalseClause ($1); } conditionalExpr
917 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
921 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
922 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
923 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
924 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
925 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
926 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
927 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
928 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
929 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
930 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
931 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
935 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
938 : /* empty */ { $$ = exprNode_undefined; }
944 /* instance_orTypeDecl_and_possible_initialization */
947 : instanceDecl { $$ = $1; }
948 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
949 | typeDecl { $$ = exprNode_makeError (); }
952 : completeTypeSpecifier IsType TSEMI
953 { $$ = exprNode_makeError (); }
955 ** This causes r/r conflicts with function definitions.
956 ** Instead we need to snarf one first. (gack)
958 ** | completeTypeSpecifier { setProcessingVars ($1); }
960 ** namedInitializerList IsType TSEMI
961 ** { unsetProcessingVars (); }
964 ** the solution is pretty ugly:
966 | completeTypeSpecifier NotType namedDecl NotType
968 setProcessingVars ($1);
969 processNamedDecl ($3);
971 IsType optDeclarators TSEMI IsType
973 unsetProcessingVars ();
974 $$ = exprNode_makeEmptyInitialization ($3);
975 DPRINTF (("Empty initialization: %s", exprNode_unparse ($$)));
977 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
978 { setProcessingVars ($1); processNamedDecl ($3); }
979 IsType init optDeclarators TSEMI IsType
980 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
981 unsetProcessingVars ();
987 processNamedDecl ($1);
988 $$ = exprNode_makeEmptyInitialization ($1);
990 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
991 { $$ = exprNode_makeInitialization ($1, $6); }
994 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
995 NotType namedInitializerList IsType optWarnClause TSEMI
996 { clabstract_declareType ($5, $7); }
997 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
998 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
1001 : { g_expectingTypeName = TRUE; }
1004 : { g_expectingTypeName = TRUE; context_pushLoc (); }
1006 namedInitializerList
1007 : namedInitializerListAux IsType { $$ = $1; }
1009 namedInitializerListAux
1010 : namedInitializer { $$ = exprNodeList_singleton ($1); }
1011 | namedInitializerList TCOMMA NotType namedInitializer { $$ = exprNodeList_push ($1, $4); }
1014 : /* empty */ { $$ = exprNode_makeError (); }
1015 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
1019 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1020 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1025 { $$ = exprNodeList_singleton ($1); }
1026 | initList TCOMMA init
1027 { $$ = exprNodeList_push ($1, $3); }
1030 ** need to do the storage class global hack so tags are
1031 ** declared with the right storage class.
1035 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1036 | QINLINE { $$ = qual_createInline (); }
1037 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1038 | QAUTO { $$ = qual_createAuto (); }
1039 | QREGISTER { $$ = qual_createRegister (); }
1042 : stateClausePlain QENDMACRO { $$ = $1; }
1047 context_setProtectVars ();
1049 sRef_setGlobalScopeSafe ();
1051 specClauseList optSemi IsType
1054 sRef_clearGlobalScopeSafe ();
1055 context_releaseVars ();
1056 $$ = stateClause_createPlain ($1, $4);
1060 : conditionClausePlain QENDMACRO { $$ = $1; }
1062 startConditionClause
1063 : conditionTag NotType { $$ = $1; context_enterFunctionHeader (); }
1065 conditionClausePlain
1066 : startConditionClause stateQualifier
1068 context_exitFunctionHeader ();
1069 context_setProtectVars ();
1071 sRef_setGlobalScopeSafe ();
1073 optSpecClauseList optSemi IsType
1076 sRef_clearGlobalScopeSafe ();
1077 context_releaseVars ();
1078 $$ = functionClause_createState (stateClause_create ($1, $2, $4));
1080 | startConditionClause
1082 context_setProtectVars ();
1084 sRef_setGlobalScopeSafe ();
1086 functionConstraint optSemi IsType
1088 context_exitFunctionHeader ();
1090 sRef_clearGlobalScopeSafe ();
1091 context_releaseVars ();
1092 DPRINTF (("done optGlobBufConstraintsAux\n"));
1094 if (lltok_isEnsures ($1))
1096 $$ = functionClause_createEnsures ($3);
1098 else if (lltok_isRequires ($1))
1100 $$ = functionClause_createRequires ($3);
1107 DPRINTF (("FunctionclauseS: %s", functionClause_unparse ($$)));
1111 : BufConstraintList { $$ = functionConstraint_createBufferConstraint ($1); }
1112 | metaStateConstraint { $$ = functionConstraint_createMetaStateConstraint ($1); DPRINTF (("Made constraint: %s", functionConstraint_unparse ($$))); }
1115 : QEXITS { $$ = qual_createExits (); }
1116 | QMAYEXIT { $$ = qual_createMayExit (); }
1117 | QTRUEEXIT { $$ = qual_createTrueExit (); }
1118 | QFALSEEXIT { $$ = qual_createFalseExit (); }
1119 | QNEVEREXIT { $$ = qual_createNeverExit (); }
1122 : QCHECKED { $$ = qual_createChecked (); }
1123 | QCHECKMOD { $$ = qual_createCheckMod (); }
1124 | QUNCHECKED { $$ = qual_createUnchecked (); }
1125 | QCHECKEDSTRICT { $$ = qual_createCheckedStrict (); }
1128 : QOWNED { $$ = qual_createOwned (); }
1129 | QDEPENDENT { $$ = qual_createDependent (); }
1130 | QYIELD { $$ = qual_createYield (); }
1131 | QTEMP { $$ = qual_createTemp (); }
1132 | QONLY { $$ = qual_createOnly (); }
1133 | QKEEP { $$ = qual_createKeep (); }
1134 | QKEPT { $$ = qual_createKept (); }
1135 | QSHARED { $$ = qual_createShared (); }
1136 | QUNIQUE { $$ = qual_createUnique (); }
1137 | QNULL { $$ = qual_createNull (); }
1138 | QISNULL { $$ = qual_createIsNull (); }
1139 | QRELNULL { $$ = qual_createRelNull (); }
1140 | QNOTNULL { $$ = qual_createNotNull (); }
1141 | QEXPOSED { $$ = qual_createExposed (); }
1142 | QOBSERVER { $$ = qual_createObserver (); }
1143 | QNULLTERMINATED { $$ = qual_createNullTerminated (); }
1144 | CANNOTATION { $$ = qual_createMetaState ($1); }
1148 : QRETURNED { $$ = qual_createReturned (); }
1149 | QSEF { $$ = qual_createSef (); }
1152 : QUNUSED { $$ = qual_createUnused (); }
1153 | QEXTERNAL { $$ = qual_createExternal (); }
1156 : QTRUENULL { $$ = qual_createTrueNull (); }
1157 | QFALSENULL { $$ = qual_createFalseNull (); }
1160 : QABSTRACT { $$ = qual_createAbstract (); }
1161 | QCONCRETE { $$ = qual_createConcrete (); }
1162 | QMUTABLE { $$ = qual_createMutable (); }
1163 | QIMMUTABLE { $$ = qual_createImmutable (); }
1166 : QREFCOUNTED { $$ = qual_createRefCounted (); }
1167 | QREFS { $$ = qual_createRefs (); }
1168 | QKILLREF { $$ = qual_createKillRef (); }
1169 | QRELDEF { $$ = qual_createRelDef (); }
1170 | QNEWREF { $$ = qual_createNewRef (); }
1171 | QTEMPREF { $$ = qual_createTempRef (); }
1174 : QSHORT { $$ = qual_createShort (); }
1175 | QLONG { $$ = qual_createLong (); }
1176 | QSIGNED { $$ = qual_createSigned (); }
1177 | QUNSIGNED { $$ = qual_createUnsigned (); }
1180 : QOUT { $$ = qual_createOut (); }
1181 | QIN { $$ = qual_createIn (); }
1182 | QPARTIAL { $$ = qual_createPartial (); }
1183 | QSPECIAL { $$ = qual_createSpecial (); }
1186 : QCONST IsType { $$ = qual_createConst (); }
1187 | QVOLATILE IsType { $$ = qual_createVolatile (); }
1188 | definedQualifier IsType { $$ = $1; }
1189 | stateQualifier IsType { $$ = $1; }
1190 | exitsQualifier IsType { $$ = $1; }
1191 | paramQualifier IsType { $$ = $1; }
1192 | checkQualifier IsType { $$ = $1; }
1193 | returnQualifier IsType { $$ = $1; }
1194 | visibilityQualifier IsType { $$ = $1; }
1195 | typedefQualifier IsType { $$ = $1; }
1196 | refcountQualifier IsType { $$ = $1; }
1199 ** This is copied into the mtgrammar!
1209 | QANYTYPE NotType { $$ = ctype_unknown; }
1210 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
1211 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1212 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
1216 | typeModifier NotType { $$ = ctype_fromQual ($1); }
1219 : IsType completeTypeSpecifier IsType
1220 { $$ = qtype_resolve ($2); }
1222 completeTypeSpecifier
1223 : completeTypeSpecifierAux { $$ = $1; }
1224 | completeTypeSpecifierAux QALT altType QENDMACRO
1225 { $$ = qtype_mergeAlt ($1, $3); }
1229 | typeExpression TCOMMA altType
1230 { $$ = qtype_mergeAlt ($1, $3); }
1232 completeTypeSpecifierAux
1233 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1234 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1235 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
1238 : /* empty */ { $$ = qtype_unknown (); }
1239 | completeTypeSpecifier { $$ = $1; }
1243 : /* empty */ { $$ = constraintList_undefined; }
1244 /* don't want to have support for structure invariant until we're
1246 | QINVARIANT BufConstraintList QENDMACRO { $$ = $2 }
1250 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1251 CreateStructInnerScope
1252 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1254 optStructInvariant { {ctype ct; ct = declareStruct ($3, $8); /* setGlobalStructInfo(ct, $12);*/ $$ = ct;} }
1255 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1256 CreateStructInnerScope
1257 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1259 { $$ = declareUnion ($3, $8); }
1260 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
1261 { $$ = declareStruct ($3, uentryList_new ()); }
1262 | NotType CUNION newId IsType TLBRACE TRBRACE
1263 { $$ = declareUnion ($3, uentryList_new ()); }
1264 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1265 CreateStructInnerScope
1266 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1268 { $$ = declareUnnamedStruct ($7); }
1269 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1270 CreateStructInnerScope structDeclList DeleteStructInnerScope
1271 { sRef_clearGlobalScopeSafe (); }
1273 { $$ = declareUnnamedUnion ($7); }
1274 | NotType CSTRUCT IsType TLBRACE TRBRACE
1275 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
1276 | NotType CUNION IsType TLBRACE TRBRACE
1277 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
1278 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
1279 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
1282 : { g_expectingTypeName = FALSE; }
1286 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1287 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1290 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
1291 { $$ = fixUentryList ($3, $1); }
1292 | completeTypeSpecifier IsType TSEMI
1293 { $$ = fixUnnamedDecl ($1); }
1296 : structNamedDecl NotType
1297 { $$ = idDeclList_singleton ($1); }
1298 | structNamedDeclList TCOMMA structNamedDecl NotType
1299 { $$ = idDeclList_add ($1, $3); }
1301 structNamedDecl /* hack to get around namespace problems */
1302 : namedDecl { $$ = $1; }
1303 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1304 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1305 /* Need the IsType in case there is a cast in the constant expression. */
1308 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1309 { $$ = declareUnnamedEnum ($4); }
1310 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1311 { context_popLoc (); $$ = declareEnum ($3, $6); }
1312 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1316 { $$ = enumNameList_single ($1); }
1317 | enumeratorList TCOMMA enumerator
1318 { $$ = enumNameList_push ($1, $3); }
1319 | enumeratorList TCOMMA
1323 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1324 usymtab_supGlobalEntry (ue);
1327 | newId TASSIGN IsType constantExpr
1328 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1329 usymtab_supGlobalEntry (ue);
1335 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1336 | pointers TYPE_NAME
1338 qtype qt = qtype_unknown ();
1340 qtype_adjustPointers ($1, qt);
1341 $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1343 | pointers optNamedDecl
1344 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1348 | pointers namedDeclBase
1349 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1352 : paramTypeList { $$ = handleParamTypeList ($1); }
1353 | NotType paramIdList { $$ = handleParamIdList ($2); }
1356 : QCONST { /* ignored for now */; }
1361 | innerModsList innerMods { ; }
1365 | TMULT innerModsList { $$ = 1; }
1366 | TMULT pointers { $$ = 1 + $2; }
1367 | TMULT innerModsList pointers { $$ = 1 + $3; }
1371 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1374 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1375 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1378 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1380 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1383 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1384 | paramList TCOMMA { storeLoc (); } paramDecl
1385 { $$ = uentryList_add ($1, $4); }
1388 : IsType completeTypeSpecifier optNamedDecl IsType
1390 if (isFlipOldStyle ())
1392 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1398 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1400 | newId /* its an old-style declaration */
1402 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1406 llparseerror (message ("Inconsistent function parameter syntax: %q",
1407 idDecl_unparse (tparam)));
1411 $$ = makeCurrentParam (tparam);
1412 idDecl_free (tparam);
1417 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1420 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1422 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1425 : /* empty */ { $$ = ctype_unknown; }
1429 : IsType TLPAREN NotType abstractDecl TRPAREN
1430 { $$ = ctype_expectFunction ($4); }
1431 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1432 | TLSQBR constantExpr TRSQBR
1433 { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
1434 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1435 | abstractDeclBase TLSQBR constantExpr TRSQBR
1436 { $$ = ctype_makeInnerFixedArray ($1, exprNode_getLongValue ($3)); }
1437 | IsType TLPAREN TRPAREN
1438 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1439 | IsType TLPAREN paramTypeList TRPAREN
1440 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1441 | abstractDeclBase IsType TLPAREN TRPAREN
1442 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1443 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1444 { $$ = ctype_makeParamsFunction ($1, $4); }
1461 : iterDefStmtList { $$ = $1; }
1468 | iterDefStmtList iterDefStmt
1469 { $$ = exprNode_concat ($1, $2); }
1471 iterDefIterationStmt
1472 : iterWhilePred iterDefStmtList
1473 { $$ = exprNode_while ($1, $2); }
1474 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1475 { $$ = exprNode_doWhile ($2, $5); }
1476 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1477 { $$ = exprNode_doWhile ($2, $5); }
1478 | forPred iterDefStmt
1479 { $$ = exprNode_for ($1, $2); }
1482 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1483 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1485 { $$ = exprNode_forPred ($3, $5, $8);
1486 context_enterForClause ($5); }
1489 : ITER_NAME CreateInnerScope TLPAREN
1490 { setProcessingIterVars ($1); }
1492 { $$ = exprNode_iterStart ($1, $5); }
1493 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1499 | openScope initializerList { $$ = $1; DPRINTF (("def stmt: %s", exprNode_unparse ($$))); }
1504 | iterDefIterationStmt
1507 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1508 | error { $$ = exprNode_makeError (); }
1511 : ifPred { exprNode_checkIfPred ($1); } iterDefStmt
1512 { /* don't: context_exitTrueClause ($1, $2); */
1513 $$ = exprNode_if ($1, $3);
1517 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1520 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1535 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1537 | error { $$ = exprNode_makeError (); }
1540 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1541 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
1544 ** We allow more than one QFALLTHROUGH token to support mixed lint/splint markers.
1547 optExtraFallThroughs
1549 | QFALLTHROUGH optExtraFallThroughs { ; }
1551 /* Note that we can semantically check that the object to the case is
1552 indeed constant. In this case, we may not want to go through this effort */
1555 : CASE constantExpr { context_enterCaseClause ($2); }
1556 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
1557 | QFALLTHROUGH optExtraFallThroughs CASE constantExpr { context_enterCaseClause ($4); }
1558 TCOLON { $$ = exprNode_caseMarker ($4, TRUE); }
1561 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1562 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1563 | QFALLTHROUGH optExtraFallThroughs DEFAULT { context_enterCaseClause (exprNode_undefined); }
1564 TCOLON { $$ = exprNode_defaultMarker ($3, TRUE); }
1567 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1568 | CreateInnerScope compoundStmtAux
1569 { $$ = $2; context_exitInner ($2); }
1572 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1575 : { context_enterInnerContext (); }
1578 : { context_exitInnerPlain (); }
1580 CreateStructInnerScope
1581 : { context_enterStructInnerContext (); }
1583 DeleteStructInnerScope
1584 : { context_exitStructInnerContext (); }
1586 DeleteInnerScopeSafe
1587 : { context_exitInnerSafe (); }
1590 : TRBRACE { $$ = exprNode_createTok ($1); }
1591 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1592 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1593 | stmtList QNOTREACHED TRBRACE
1594 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1595 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1596 | initializerList QNOTREACHED TRBRACE
1597 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1598 | initializerList stmtList TRBRACE
1599 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1600 | initializerList stmtList QNOTREACHED TRBRACE
1601 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1602 lltok_getLoc ($3)));
1606 : TLBRACE compoundStmtRest
1607 { $$ = exprNode_makeBlock ($2); }
1611 { $$ = exprNode_createTok ($2); }
1612 | TLBRACE stmtListErr TRBRACE
1613 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1614 | TLBRACE initializerList TRBRACE
1615 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1616 | TLBRACE initializerList stmtList TRBRACE
1617 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1621 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1624 : initializer { $$ = $1; }
1625 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1629 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1632 : TSEMI { $$ = exprNode_createTok ($1); }
1633 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1636 : TSEMI { $$ = exprNode_createTok ($1); }
1637 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1638 | expr { $$ = exprNode_checkExpr ($1); }
1641 : CIF TLPAREN expr TRPAREN
1643 exprNode_produceGuards ($3); context_enterTrueClause ($3);
1644 exprNode_checkIfPred ($3);
1649 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1650 ** { $$ = $3; context_enterTrueClause (); }
1656 context_exitTrueClause ($1, $2);
1657 $$ = exprNode_if ($1, $2);
1659 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
1661 context_exitClause ($1, $2, $5);
1662 $$ = exprNode_ifelse ($1, $2, $5);
1664 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1665 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1668 : WHILE TLPAREN expr TRPAREN
1669 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1670 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1673 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1676 : ITER_NAME { context_enterIterClause (); }
1677 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1679 compoundStmt endIter DeleteInnerScope
1681 $$ = exprNode_iter ($1, $6, $8, $9);
1686 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1687 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1688 { $$ = exprNodeList_push ($1, $4); }
1691 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1692 | id { $$ = exprNode_iterId ($1); }
1693 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1695 if (uentry_isValid (ue))
1697 $$ = exprNode_iterId (ue);
1701 $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1704 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1707 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1712 | cconstantExpr CCONSTANT { $$ = exprNode_combineLiterals ($1, $2); }
1716 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1720 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1721 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1722 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1723 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1724 { $$ = exprNode_vaArg ($1, $3, $5); }
1725 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
1726 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
1727 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1728 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1732 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1733 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1734 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1735 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1736 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1737 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1738 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1739 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1740 | sizeofExpr { $$ = $1; }
1744 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1748 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1749 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1750 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1754 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1755 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1759 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1760 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1764 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1765 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1766 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1767 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1770 : relationalIterExpr
1771 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1772 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1776 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1780 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1785 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1789 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1793 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1797 | orExpr TQUEST { context_enterTrueClause ($1); }
1798 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1799 { $$ = exprNode_cond ($1, $4, $7); }
1802 : conditionalIterExpr
1803 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1804 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1805 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1806 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1807 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1808 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1809 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1810 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1811 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1812 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1813 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1816 : ITER_ENDNAME { $$ = $1; }
1817 | /* empty */ { $$ = uentry_undefined; }
1820 : DO { context_enterDoWhileClause (); $$ = $1; }
1824 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1825 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
1826 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1828 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1831 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1832 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1833 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1834 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1835 { $$ = exprNode_doWhile ($2, $5); }
1836 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1839 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1840 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1841 | QINNERCONTINUE CONTINUE TSEMI
1842 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1843 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1844 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1845 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1846 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1847 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1848 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1849 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1860 | ITER_NAME { $$ = uentry_getName ($1); }
1861 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1862 | id { $$ = uentry_getName ($1); }
1863 | TYPE_NAME_OR_ID { $$ = $1; }
1867 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1871 /*@-redecl@*/ /*@-namechecks@*/
1872 extern char *yytext;
1873 /*@=redecl@*/ /*@=namechecks@*/
1875 # include "bison.reset"
1877 void yyerror (/*@unused@*/ char *s)
1879 static bool givehint = FALSE;
1881 if (context_inIterDef ())
1883 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1884 context_inFunctionName ()));
1886 else if (context_inIterEnd ())
1888 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1889 context_inFunctionName ()));
1891 else if (context_inMacro ())
1893 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1894 context_inFunctionName ()));
1896 if (context_inUnknownMacro ())
1900 llhint (cstring_makeLiteral
1901 ("Precede macro definition with /*@notfunction@*/ "
1902 "to suppress checking and force expansion"));
1908 context_exitAllClausesQuiet ();
1912 llparseerror (cstring_undefined);