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: splint@cs.virginia.edu
21 ** To report a bug: splint-bug@cs.virginia.edu
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
161 %token <tok> QUNDEF QKILLED
162 %token <tok> QENDMACRO
164 /* additional tokens introduced by splint pre-processor. */
165 %token <tok> LLMACRO LLMACROITER LLMACROEND TENDMACRO
167 /* break comments: */
168 %token <tok> QSWITCHBREAK QLOOPBREAK QINNERBREAK QSAFEBREAK
169 %token <tok> QINNERCONTINUE
171 /* case fall-through marker: */
172 %token <tok> QFALLTHROUGH
174 /* used in scanner only */
175 %token <tok> QLINTNOTREACHED
176 %token <tok> QLINTFALLTHROUGH
177 %token <tok> QLINTFALLTHRU
178 %token <tok> QARGSUSED
179 %token <tok> QPRINTFLIKE QLINTPRINTFLIKE QSCANFLIKE QMESSAGELIKE
181 /* not-reached marker: (used like a label) */
182 %token <tok> QNOTREACHED
184 /* type qualifiers: */
185 %token <tok> QCONST QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
186 %token <tok> QOUT QIN QYIELD QONLY QTEMP QSHARED QREF QUNIQUE
187 %token <tok> QCHECKED QUNCHECKED QCHECKEDSTRICT QCHECKMOD
188 %token <tok> QKEEP QKEPT QPARTIAL QSPECIAL QOWNED QDEPENDENT
189 %token <tok> QRETURNED QEXPOSED QNULL QOBSERVER QISNULL
190 %token <tok> QEXITS QMAYEXIT QNEVEREXIT QTRUEEXIT QFALSEEXIT
191 %token <tok> QLONG QSIGNED QUNSIGNED QSHORT QUNUSED QSEF QNOTNULL QRELNULL
192 %token <tok> QABSTRACT QCONCRETE QMUTABLE QIMMUTABLE
193 %token <tok> QTRUENULL QFALSENULL QEXTERNAL
194 %token <tok> QREFCOUNTED QREFS QNEWREF QTEMPREF QKILLREF QRELDEF
195 %token <ctyp> CGCHAR CBOOL CINT CGFLOAT CDOUBLE CVOID
196 %token <tok> QANYTYPE QINTEGRALTYPE QUNSIGNEDINTEGRALTYPE QSIGNEDINTEGRALTYPE
198 %type <typequal> nullterminatedQualifier
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 <tok> BufUnaryOp
283 %type <enumnamelist> enumeratorList
284 %type <cstringlist> fieldDesignator
286 %type <expr> sizeofExpr sizeofExprAux offsetofExpr
287 %type <expr> openScope closeScope
288 %type <expr> instanceDecl namedInitializer optDeclarators
289 %type <expr> primaryExpr postfixExpr primaryIterExpr postfixIterExpr
290 %type <expr> unaryExpr castExpr timesExpr plusExpr
291 %type <expr> unaryIterExpr castIterExpr timesIterExpr plusIterExpr
292 %type <expr> shiftExpr relationalExpr equalityExpr bitandExpr
293 %type <expr> xorExpr bitorExpr andExpr
294 %type <expr> orExpr conditionalExpr assignExpr
295 %type <expr> shiftIterExpr relationalIterExpr equalityIterExpr bitandIterExpr
296 %type <expr> xorIterExpr bitorIterExpr andIterExpr
297 %type <expr> orIterExpr conditionalIterExpr assignIterExpr iterArgExpr
298 %type <expr> expr optExpr constantExpr
299 %type <expr> init macroBody iterBody endBody partialIterStmt iterSelectionStmt
300 %type <expr> stmt stmtList fcnBody iterStmt iterDefStmt iterDefStmtList
301 %type <expr> labeledStmt caseStmt defaultStmt
302 %type <expr> compoundStmt compoundStmtAux compoundStmtRest compoundStmtAuxErr
303 %type <expr> expressionStmt selectionStmt iterationStmt jumpStmt iterDefIterationStmt
304 %type <expr> stmtErr stmtListErr compoundStmtErr expressionStmtErr
305 %type <expr> iterationStmtErr initializerList initializer ifPred whilePred forPred iterWhilePred
307 %type <typequal> storageSpecifier typeQualifier typeModifier globQual
308 %type <tquallist> optGlobQuals
309 %type <qtyp> completeType completeTypeSpecifier optCompleteType
310 %type <qtyp> completeTypeSpecifierAux altType typeExpression
321 : externalDef { context_checkGlobalScope (); }
322 | externalDefs externalDef { context_checkGlobalScope (); }
325 : fcnDef optSemi { uentry_clearDecl (); }
326 | constantDecl { uentry_clearDecl (); }
327 | fcnDecl { uentry_clearDecl (); }
328 | iterDecl { uentry_clearDecl (); }
329 | macroDef { uentry_clearDecl (); }
330 | initializer { uentry_checkDecl (); exprNode_free ($1); }
331 | error { uentry_clearDecl (); }
334 : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
335 { checkConstant ($2, $4); }
336 | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
337 { checkValueConstant ($2, $4, $8) ; }
340 : QFUNCTION { context_enterFunctionHeader (); } plainFcn optSemi QENDMACRO
342 declareStaticFunction ($3); context_quietExitFunction ();
343 context_exitFunctionHeader ();
349 qtype qint = qtype_create (ctype_int);
350 $$ = idDecl_fixBase ($1, qint);
353 | completeTypeSpecifier NotType plainNamedDecl
354 { $$ = idDecl_fixBase ($3, $1); }
358 | pointers plainNamedDeclBase
359 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
362 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
363 | IsType TLPAREN NotType namedDecl IsType TRPAREN
364 { $$ = idDecl_expectFunction ($4); }
365 | namedDeclBase TLSQBR TRSQBR
366 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
367 | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
369 exprNode_findValue($4);
370 if (exprNode_hasValue ($4))
372 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), exprNode_getLongValue ($4)));
376 $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1)));
379 | namedDeclBase PushType TLPAREN TRPAREN
380 { setCurrentParams (uentryList_missingParams); }
382 { /* need to support globals and modifies here! */
383 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
384 uentryList_makeMissingParams ());
386 $$ = idDecl_replaceCtype ($1, ct);
387 idDecl_addClauses ($$, $6);
389 /*drl 7/25/01 added*/
390 setImplictfcnConstraints();
392 | namedDeclBase PushType TLPAREN genericParamList TRPAREN
393 { setCurrentParams ($4); }
395 { setImplictfcnConstraints ();
396 clearCurrentParams ();
397 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
398 idDecl_addClauses ($$, $7);
403 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
404 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
405 { $$ = idDecl_expectFunction ($4); }
406 | plainNamedDeclBase TLSQBR TRSQBR
407 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
408 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
412 if (exprNode_hasValue ($4)
413 && multiVal_isInt (exprNode_getValue ($4)))
415 value = (int) multiVal_forceInt (exprNode_getValue ($4));
422 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
424 | plainNamedDeclBase PushType TLPAREN TRPAREN
425 { setCurrentParams (uentryList_missingParams); }
428 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
429 uentryList_makeMissingParams ());
431 $$ = idDecl_replaceCtype ($1, ct);
432 idDecl_addClauses ($$, $6);
435 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
436 { setCurrentParams ($4); }
439 clearCurrentParams ();
440 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
441 idDecl_addClauses ($$, $7);
446 : QITER newId TLPAREN genericParamList TRPAREN
447 { setCurrentParams ($4); } functionClausesPlain
448 { clearCurrentParams (); } optSemi QENDMACRO
449 { declareCIter ($2, $4); }
452 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); }
453 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); }
454 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); }
455 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); }
458 : fcnDefHdrAux { clabstract_declareFunction ($1); }
461 : metaStateSpecifier TASSIGN metaStateExpression
462 { $$ = metaStateConstraint_create ($1, $3); }
465 : BufConstraintSrefExpr { cscanner_expectingMetaStateName (); } TCOLON metaStateName
466 { cscanner_clearExpectingMetaStateName ();
467 $$ = metaStateSpecifier_create ($1, $4); }
468 | CTOK_ELIPSIS { cscanner_expectingMetaStateName (); } TCOLON metaStateName
469 { cscanner_clearExpectingMetaStateName ();
470 $$ = metaStateSpecifier_createElipsis ($4); }
473 : metaStateSpecifier { $$ = metaStateExpression_create ($1); }
474 | metaStateSpecifier TBAR metaStateExpression { $$ = metaStateExpression_createMerge ($1, $3); }
482 : BufConstraint TCAND BufConstraintList { $$ = constraintList_add ($3, $1); }
483 | BufConstraint { $$ = constraintList_single ($1); }
486 : BufConstraintExpr relationalOp BufConstraintExpr {
487 $$ = makeConstraintParse3 ($1, $2, $3);
488 DPRINTF(("Done BufConstraint1\n")); }
501 | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3); DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
502 | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
503 DPRINTF( ("Got BufConstraintExpr BINary Op ") );
504 $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
507 : BufConstraintSrefExpr { $$ = constraintExpr_makeTermsRef ($1);}
508 | CCONSTANT { $$ = constraintExpr_makeIntLiteral (exprNode_getLongValue ($1)); }
510 BufConstraintSrefExpr
512 { /*@-onlytrans@*/ $$ = checkbufferConstraintClausesId ($1); /*@=onlytrans@*/ /*@i523@*/ }
514 { $$ = fixStateClausesId ($1); }
515 | BufConstraintSrefExpr TLSQBR TRSQBR
516 { $$ = sRef_makeAnyArrayFetch ($1); }
517 | BufConstraintSrefExpr TLSQBR CCONSTANT TRSQBR
521 t = cstring_toCharsSafe (exprNode_unparse($3));
524 $$ = sRef_makeArrayFetchKnown ($1, exprNode_getLongValue ($3));
526 | TMULT BufConstraintSrefExpr
527 { $$ = sRef_constructPointer ($2); }
528 | TLPAREN BufConstraintSrefExpr TRPAREN
530 | BufConstraintSrefExpr TDOT newId
531 { cstring_markOwned ($3); $$ = sRef_buildField ($1, $3); }
532 | BufConstraintSrefExpr ARROW_OP newId
533 { cstring_markOwned ($3); $$ = sRef_makeArrow ($1, $3); }
536 | BufConstraintTerm TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
537 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
538 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
539 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
540 $$ = sRef_buildField ($1, $3); }
556 ** Function clauses can appear in any order.
560 : { $$ = functionClauseList_new (); }
561 | functionClause functionClauses
562 { $$ = functionClauseList_prepend ($2, $1); }
565 ** Inside macro definitions, there are no end macros.
570 { $$ = functionClauseList_new (); }
571 | functionClausePlain functionClausesPlain
572 { $$ = functionClauseList_prepend ($2, $1); }
575 : globalsClause { $$ = functionClause_createGlobals ($1); }
576 | modifiesClause { $$ = functionClause_createModifies ($1); }
577 | nomodsClause { $$ = functionClause_createModifies ($1); }
578 | stateClause { $$ = functionClause_createState ($1); }
579 | conditionClause { $$ = $1; }
580 | warnClause { $$ = functionClause_createWarn ($1); }
583 : globalsClausePlain { $$ = functionClause_createGlobals ($1); }
584 | modifiesClausePlain { $$ = functionClause_createModifies ($1); }
585 | nomodsClause { $$ = functionClause_createModifies ($1); }
586 | stateClausePlain { $$ = functionClause_createState ($1); }
587 | conditionClausePlain { $$ = $1; }
588 | warnClausePlain { $$ = functionClause_createWarn ($1); }
591 : globalsClausePlain QENDMACRO { $$ = $1; }
594 : QGLOBALS { setProcessingGlobalsList (); }
597 unsetProcessingGlobals ();
598 $$ = globalsClause_create ($1, $3);
602 : QNOMODS { $$ = modifiesClause_createNoMods ($1); }
605 : modifiesClausePlain QENDMACRO { $$ = $1; }
610 context_setProtectVars (); enterParamsTemp ();
611 sRef_setGlobalScopeSafe ();
616 sRef_clearGlobalScopeSafe ();
617 context_releaseVars ();
618 $$ = modifiesClause_create ($1, $3);
623 { $$ = flagSpec_createPlain ($1); }
624 | flagId TBAR flagSpec
625 { $$ = flagSpec_createOr ($1, $3); }
632 | /* empty */ { $$ = warnClause_undefined; }
635 : warnClausePlain QENDMACRO { $$ = $1; }
638 : QWARN flagSpec cconstantExpr
640 llassert (exprNode_knownStringValue ($3));
641 $$ = warnClause_create ($1, $2, cstring_copy (multiVal_forceString (exprNode_getValue ($3))));
645 { $$ = warnClause_create ($1, $2, cstring_undefined); }
648 : globIdListExpr { $$ = globSet_single ($1); }
649 | globIdList TCOMMA globIdListExpr { $$ = globSet_insert ($1, $3); }
652 : optGlobQuals globId { $$ = clabstract_createGlobal ($2, $1); }
655 : /* empty */ { $$ = qualList_undefined; }
656 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
659 : id { $$ = uentry_getSref ($1); }
660 | NEW_IDENTIFIER { $$ = clabstract_unrecognizedGlobal ($1); }
661 | initializer { $$ = clabstract_checkGlobal ($1); }
664 : QUNDEF { $$ = qual_createUndef (); }
665 | QKILLED { $$ = qual_createKilled (); }
666 | QOUT { $$ = qual_createOut (); }
667 | QIN { $$ = qual_createIn (); }
668 | QPARTIAL { $$ = qual_createPartial (); }
684 qtype qint = qtype_create (ctype_int);
685 $$ = idDecl_fixBase ($1, qint);
688 | completeTypeSpecifier NotType namedDecl
689 { $$ = idDecl_fixBase ($3, $1); }
692 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
695 exprNode_checkFunctionBody ($3); $$ = $3;
696 context_exitInner ($3);
698 | { context_enterOldStyleScope (); } initializerList
699 { oldStyleDoneParams (); context_enterInnerContext (); }
702 exprNode_checkFunctionBody ($4);
703 $$ = $4; /* oldstyle */
704 context_exitInner ($4);
710 context_setFunctionDefined (exprNode_loc ($2));
711 exprNode_checkFunction (context_getHeader (), $2);
714 context_exitFunction ();
718 : modList optSemi { $$ = $1; }
719 | optSemi { $$ = sRefSet_new (); }
722 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
723 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
724 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
725 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
726 | TMULT modListExpr { $$ = modListPointer ($2); }
727 | TLPAREN modListExpr TRPAREN { $$ = $2; }
728 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
729 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
733 : modListExpr { $$ = $1; }
734 | cconstantExpr { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
738 : modListExpr { $$ = sRefSet_single ($1); }
739 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
743 { $$ = checkStateClausesId ($1); }
745 { $$ = fixStateClausesId ($1); }
746 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
747 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
748 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
749 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
750 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
751 $$ = sRef_buildField ($1, $3); }
752 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
753 $$ = sRef_makeArrow ($1, $3); }
756 : /* empty */ { $$ = sRefSet_undefined }
761 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
762 else { $$ = sRefSet_undefined; }
764 | specClauseList TCOMMA specClauseListExpr
765 { if (sRef_isValid ($3))
767 $$ = sRefSet_insert ($1, $3);
776 : id { $$ = exprNode_fromIdentifier ($1); }
777 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
779 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
780 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
781 | QEXTENSION { $$ = exprNode_makeError (); }
785 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
786 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
787 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
788 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
789 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
790 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
791 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
792 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
795 : assignExpr { $$ = exprNodeList_singleton ($1); }
796 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
800 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
801 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
802 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
803 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
804 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
805 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
806 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
807 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
808 | sizeofExpr { $$ = $1; }
809 | offsetofExpr { $$ = $1; }
812 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
813 | newId { $$ = cstringList_single ($1); }
816 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
817 { $$ = exprNode_offsetof ($4, $7); }
820 : IsType { context_setProtectVars (); }
821 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
824 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); }
825 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); }
826 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); }
827 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); }
831 | TLPAREN typeExpression TRPAREN castExpr
832 { $$ = exprNode_cast ($1, $4, $2); }
836 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
837 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
838 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
842 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
843 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
847 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
848 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
852 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
853 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
854 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
855 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
859 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
860 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
864 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
868 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
873 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
878 { exprNode_produceGuards ($1);
879 context_enterAndClause ($1);
883 $$ = exprNode_op ($1, $4, $2);
884 context_exitAndClause ($$, $4);
891 exprNode_produceGuards ($1);
892 context_enterOrClause ($1);
896 $$ = exprNode_op ($1, $4, $2);
897 context_exitOrClause ($$, $4);
902 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
903 { context_enterFalseClause ($1); } conditionalExpr
904 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
908 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
909 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
910 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
911 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
912 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
913 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
914 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
915 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
916 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
917 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
918 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
922 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
925 : /* empty */ { $$ = exprNode_undefined; }
931 /* instance_orTypeDecl_and_possible_initialization */
934 : instanceDecl { $$ = $1; }
935 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
936 | typeDecl { $$ = exprNode_makeError (); }
939 : completeTypeSpecifier IsType TSEMI
940 { $$ = exprNode_makeError (); }
942 ** This causes r/r conflicts with function definitions.
943 ** Instead we need to snarf one first. (gack)
945 ** | completeTypeSpecifier { setProcessingVars ($1); }
947 ** namedInitializerList IsType TSEMI
948 ** { unsetProcessingVars (); }
951 ** the solution is pretty ugly:
953 | completeTypeSpecifier NotType namedDecl NotType
955 setProcessingVars ($1);
956 processNamedDecl ($3);
958 IsType optDeclarators TSEMI IsType
960 unsetProcessingVars ();
961 $$ = exprNode_makeEmptyInitialization ($3);
962 DPRINTF (("Empty initialization: %s", exprNode_unparse ($$)));
964 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
965 { setProcessingVars ($1); processNamedDecl ($3); }
966 IsType init optDeclarators TSEMI IsType
967 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
968 unsetProcessingVars ();
974 processNamedDecl ($1);
975 $$ = exprNode_makeEmptyInitialization ($1);
977 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
978 { $$ = exprNode_makeInitialization ($1, $6); }
981 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
982 NotType namedInitializerList IsType optWarnClause TSEMI
983 { clabstract_declareType ($5, $7); }
984 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
985 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
988 : { g_expectingTypeName = TRUE; }
991 : { g_expectingTypeName = TRUE; context_pushLoc (); }
994 : namedInitializerListAux IsType { $$ = $1; }
996 namedInitializerListAux
997 : namedInitializer { $$ = exprNodeList_singleton ($1); }
998 | namedInitializerList TCOMMA NotType namedInitializer { $$ = exprNodeList_push ($1, $4); }
1001 : /* empty */ { $$ = exprNode_makeError (); }
1002 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
1006 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1007 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1012 { $$ = exprNodeList_singleton ($1); }
1013 | initList TCOMMA init
1014 { $$ = exprNodeList_push ($1, $3); }
1017 ** need to do the storage class global hack so tags are
1018 ** declared with the right storage class.
1022 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1023 | QINLINE { $$ = qual_createInline (); }
1024 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1025 | QAUTO { $$ = qual_createAuto (); }
1026 | QREGISTER { $$ = qual_createRegister (); }
1028 nullterminatedQualifier:
1029 QNULLTERMINATED IsType { $$ = qual_createNullTerminated (); }
1032 : stateClausePlain QENDMACRO { $$ = $1; }
1037 context_setProtectVars ();
1039 sRef_setGlobalScopeSafe ();
1041 specClauseList optSemi IsType
1044 sRef_clearGlobalScopeSafe ();
1045 context_releaseVars ();
1046 $$ = stateClause_createPlain ($1, $4);
1050 : conditionClausePlain QENDMACRO { $$ = $1; }
1052 startConditionClause
1053 : conditionTag NotType { $$ = $1; context_enterFunctionHeader (); }
1055 conditionClausePlain
1056 : startConditionClause stateQualifier
1058 context_exitFunctionHeader ();
1059 context_setProtectVars ();
1061 sRef_setGlobalScopeSafe ();
1063 optSpecClauseList optSemi IsType
1066 sRef_clearGlobalScopeSafe ();
1067 context_releaseVars ();
1068 $$ = functionClause_createState (stateClause_create ($1, $2, $4));
1070 | startConditionClause
1072 context_setProtectVars ();
1074 sRef_setGlobalScopeSafe ();
1076 functionConstraint optSemi IsType
1078 context_exitFunctionHeader ();
1080 sRef_clearGlobalScopeSafe ();
1081 context_releaseVars ();
1082 DPRINTF (("done optGlobBufConstraintsAux\n"));
1084 if (lltok_isEnsures ($1))
1086 $$ = functionClause_createEnsures ($3);
1088 else if (lltok_isRequires ($1))
1090 $$ = functionClause_createRequires ($3);
1097 DPRINTF (("FunctionclauseS: %s", functionClause_unparse ($$)));
1101 : BufConstraintList { $$ = functionConstraint_createBufferConstraint ($1); }
1102 | metaStateConstraint { $$ = functionConstraint_createMetaStateConstraint ($1); DPRINTF (("Made constraint: %s", functionConstraint_unparse ($$))); }
1105 : QEXITS { $$ = qual_createExits (); }
1106 | QMAYEXIT { $$ = qual_createMayExit (); }
1107 | QTRUEEXIT { $$ = qual_createTrueExit (); }
1108 | QFALSEEXIT { $$ = qual_createFalseExit (); }
1109 | QNEVEREXIT { $$ = qual_createNeverExit (); }
1112 : QCHECKED { $$ = qual_createChecked (); }
1113 | QCHECKMOD { $$ = qual_createCheckMod (); }
1114 | QUNCHECKED { $$ = qual_createUnchecked (); }
1115 | QCHECKEDSTRICT { $$ = qual_createCheckedStrict (); }
1118 : QOWNED { $$ = qual_createOwned (); }
1119 | QDEPENDENT { $$ = qual_createDependent (); }
1120 | QYIELD { $$ = qual_createYield (); }
1121 | QTEMP { $$ = qual_createTemp (); }
1122 | QONLY { $$ = qual_createOnly (); }
1123 | QKEEP { $$ = qual_createKeep (); }
1124 | QKEPT { $$ = qual_createKept (); }
1125 | QSHARED { $$ = qual_createShared (); }
1126 | QUNIQUE { $$ = qual_createUnique (); }
1127 | QNULL { $$ = qual_createNull (); }
1128 | QISNULL { $$ = qual_createIsNull (); }
1129 | QRELNULL { $$ = qual_createRelNull (); }
1130 | QNOTNULL { $$ = qual_createNotNull (); }
1131 | QEXPOSED { $$ = qual_createExposed (); }
1132 | QOBSERVER { $$ = qual_createObserver (); }
1133 | QNULLTERMINATED { $$ = qual_createNullTerminated (); }
1134 | CANNOTATION { $$ = qual_createMetaState ($1); }
1138 : QRETURNED { $$ = qual_createReturned (); }
1139 | QSEF { $$ = qual_createSef (); }
1142 : QUNUSED { $$ = qual_createUnused (); }
1143 | QEXTERNAL { $$ = qual_createExternal (); }
1146 : QTRUENULL { $$ = qual_createTrueNull (); }
1147 | QFALSENULL { $$ = qual_createFalseNull (); }
1150 : QABSTRACT { $$ = qual_createAbstract (); }
1151 | QCONCRETE { $$ = qual_createConcrete (); }
1152 | QMUTABLE { $$ = qual_createMutable (); }
1153 | QIMMUTABLE { $$ = qual_createImmutable (); }
1156 : QREFCOUNTED { $$ = qual_createRefCounted (); }
1157 | QREFS { $$ = qual_createRefs (); }
1158 | QKILLREF { $$ = qual_createKillRef (); }
1159 | QRELDEF { $$ = qual_createRelDef (); }
1160 | QNEWREF { $$ = qual_createNewRef (); }
1161 | QTEMPREF { $$ = qual_createTempRef (); }
1164 : QSHORT { $$ = qual_createShort (); }
1165 | QLONG { $$ = qual_createLong (); }
1166 | QSIGNED { $$ = qual_createSigned (); }
1167 | QUNSIGNED { $$ = qual_createUnsigned (); }
1170 : QOUT { $$ = qual_createOut (); }
1171 | QIN { $$ = qual_createIn (); }
1172 | QPARTIAL { $$ = qual_createPartial (); }
1173 | QSPECIAL { $$ = qual_createSpecial (); }
1176 : QCONST IsType { $$ = qual_createConst (); }
1177 | QVOLATILE IsType { $$ = qual_createVolatile (); }
1178 | definedQualifier IsType { $$ = $1; }
1179 | stateQualifier IsType { $$ = $1; }
1180 | exitsQualifier IsType { $$ = $1; }
1181 | paramQualifier IsType { $$ = $1; }
1182 | checkQualifier IsType { $$ = $1; }
1183 | returnQualifier IsType { $$ = $1; }
1184 | visibilityQualifier IsType { $$ = $1; }
1185 | typedefQualifier IsType { $$ = $1; }
1186 | refcountQualifier IsType { $$ = $1; }
1189 ** This is copied into the mtgrammar!
1199 | QANYTYPE NotType { $$ = ctype_unknown; }
1200 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
1201 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1202 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
1206 | typeModifier NotType { $$ = ctype_fromQual ($1); }
1209 : IsType completeTypeSpecifier IsType
1210 { $$ = qtype_resolve ($2); }
1212 completeTypeSpecifier
1213 : completeTypeSpecifierAux { $$ = $1; }
1214 | completeTypeSpecifierAux QALT altType QENDMACRO
1215 { $$ = qtype_mergeAlt ($1, $3); }
1219 | typeExpression TCOMMA altType
1220 { $$ = qtype_mergeAlt ($1, $3); }
1222 completeTypeSpecifierAux
1223 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1224 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1225 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
1228 : /* empty */ { $$ = qtype_unknown (); }
1229 | completeTypeSpecifier { $$ = $1; }
1232 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1233 CreateStructInnerScope
1234 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1236 { $$ = declareStruct ($3, $8); }
1237 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1238 CreateStructInnerScope
1239 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1241 { $$ = declareUnion ($3, $8); }
1242 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
1243 { $$ = declareStruct ($3, uentryList_new ()); }
1244 | NotType CUNION newId IsType TLBRACE TRBRACE
1245 { $$ = declareUnion ($3, uentryList_new ()); }
1246 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1247 CreateStructInnerScope
1248 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1250 { $$ = declareUnnamedStruct ($7); }
1251 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1252 CreateStructInnerScope structDeclList DeleteStructInnerScope
1253 { sRef_clearGlobalScopeSafe (); }
1255 { $$ = declareUnnamedUnion ($7); }
1256 | NotType CSTRUCT IsType TLBRACE TRBRACE
1257 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
1258 | NotType CUNION IsType TLBRACE TRBRACE
1259 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
1260 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
1261 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
1264 : { g_expectingTypeName = FALSE; }
1268 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1269 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1272 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
1273 { $$ = fixUentryList ($3, $1); }
1274 | completeTypeSpecifier IsType TSEMI
1275 { $$ = fixUnnamedDecl ($1); }
1278 : structNamedDecl NotType
1279 { $$ = idDeclList_singleton ($1); }
1280 | structNamedDeclList TCOMMA structNamedDecl NotType
1281 { $$ = idDeclList_add ($1, $3); }
1283 structNamedDecl /* hack to get around namespace problems */
1284 : namedDecl { $$ = $1; }
1285 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1286 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1287 /* Need the IsType in case there is a cast in the constant expression. */
1290 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1291 { $$ = declareUnnamedEnum ($4); }
1292 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1293 { context_popLoc (); $$ = declareEnum ($3, $6); }
1294 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1298 { $$ = enumNameList_single ($1); }
1299 | enumeratorList TCOMMA enumerator
1300 { $$ = enumNameList_push ($1, $3); }
1301 | enumeratorList TCOMMA
1305 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1306 usymtab_supGlobalEntry (ue);
1309 | newId TASSIGN IsType constantExpr
1310 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1311 usymtab_supGlobalEntry (ue);
1317 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1318 | pointers TYPE_NAME
1320 qtype qt = qtype_unknown ();
1322 qtype_adjustPointers ($1, qt);
1323 $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1325 | pointers optNamedDecl
1326 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1330 | pointers namedDeclBase
1331 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1334 : paramTypeList { $$ = handleParamTypeList ($1); }
1335 | NotType paramIdList { $$ = handleParamIdList ($2); }
1338 : QCONST { /* ignored for now */; }
1343 | innerModsList innerMods { ; }
1347 | TMULT innerModsList { $$ = 1; }
1348 | TMULT pointers { $$ = 1 + $2; }
1349 | TMULT innerModsList pointers { $$ = 1 + $3; }
1353 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1356 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1357 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1360 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1362 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1365 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1366 | paramList TCOMMA { storeLoc (); } paramDecl
1367 { $$ = uentryList_add ($1, $4); }
1370 : IsType completeTypeSpecifier optNamedDecl IsType
1372 if (isFlipOldStyle ())
1374 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1380 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1382 | newId /* its an old-style declaration */
1384 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1388 llparseerror (message ("Inconsistent function parameter syntax: %q",
1389 idDecl_unparse (tparam)));
1393 $$ = makeCurrentParam (tparam);
1394 idDecl_free (tparam);
1399 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1402 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1404 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1407 : /* empty */ { $$ = ctype_unknown; }
1411 : IsType TLPAREN NotType abstractDecl TRPAREN
1412 { $$ = ctype_expectFunction ($4); }
1413 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1414 | TLSQBR constantExpr TRSQBR
1415 { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
1416 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1417 | abstractDeclBase TLSQBR constantExpr TRSQBR
1418 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
1419 | IsType TLPAREN TRPAREN
1420 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1421 | IsType TLPAREN paramTypeList TRPAREN
1422 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1423 | abstractDeclBase IsType TLPAREN TRPAREN
1424 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1425 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1426 { $$ = ctype_makeParamsFunction ($1, $4); }
1442 : iterDefStmtList { $$ = $1; }
1449 | iterDefStmtList iterDefStmt
1450 { $$ = exprNode_concat ($1, $2); }
1452 iterDefIterationStmt
1453 : iterWhilePred iterDefStmtList
1454 { $$ = exprNode_while ($1, $2); }
1455 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1456 { $$ = exprNode_doWhile ($2, $5); }
1457 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1458 { $$ = exprNode_doWhile ($2, $5); }
1459 | forPred iterDefStmt
1460 { $$ = exprNode_for ($1, $2); }
1463 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1464 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1466 { $$ = exprNode_forPred ($3, $5, $8);
1467 context_enterForClause ($5); }
1470 : ITER_NAME CreateInnerScope TLPAREN
1471 { setProcessingIterVars ($1); }
1473 { $$ = exprNode_iterStart ($1, $5); }
1474 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1480 | openScope initializerList { $$ = $1; DPRINTF (("def stmt: %s", exprNode_unparse ($$))); }
1485 | iterDefIterationStmt
1488 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1489 | error { $$ = exprNode_makeError (); }
1492 : ifPred { exprNode_checkIfPred ($1); } iterDefStmt
1493 { /* don't: context_exitTrueClause ($1, $2); */
1494 $$ = exprNode_if ($1, $3);
1498 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1501 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1516 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1518 | error { $$ = exprNode_makeError (); }
1521 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1522 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
1525 ** We allow more than one QFALLTHROUGH token to support mixed lint/splint markers.
1528 optExtraFallThroughs
1530 | QFALLTHROUGH optExtraFallThroughs { ; }
1532 /* Note that we can semantically check that the object to the case is
1533 indeed constant. In this case, we may not want to go through this effort */
1536 : CASE constantExpr { context_enterCaseClause ($2); }
1537 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
1538 | QFALLTHROUGH optExtraFallThroughs CASE constantExpr { context_enterCaseClause ($4); }
1539 TCOLON { $$ = exprNode_caseMarker ($4, TRUE); }
1542 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1543 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1544 | QFALLTHROUGH optExtraFallThroughs DEFAULT { context_enterCaseClause (exprNode_undefined); }
1545 TCOLON { $$ = exprNode_defaultMarker ($3, TRUE); }
1548 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1549 | CreateInnerScope compoundStmtAux
1550 { $$ = $2; context_exitInner ($2); }
1553 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1556 : { context_enterInnerContext (); }
1559 : { context_exitInnerPlain (); }
1561 CreateStructInnerScope
1562 : { context_enterStructInnerContext (); }
1564 DeleteStructInnerScope
1565 : { context_exitStructInnerContext (); }
1567 DeleteInnerScopeSafe
1568 : { context_exitInnerSafe (); }
1571 : TRBRACE { $$ = exprNode_createTok ($1); }
1572 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1573 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1574 | stmtList QNOTREACHED TRBRACE
1575 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1576 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1577 | initializerList QNOTREACHED TRBRACE
1578 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1579 | initializerList stmtList TRBRACE
1580 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1581 | initializerList stmtList QNOTREACHED TRBRACE
1582 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1583 lltok_getLoc ($3)));
1587 : TLBRACE compoundStmtRest
1588 { $$ = exprNode_makeBlock ($2); }
1592 { $$ = exprNode_createTok ($2); }
1593 | TLBRACE stmtListErr TRBRACE
1594 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1595 | TLBRACE initializerList TRBRACE
1596 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1597 | TLBRACE initializerList stmtList TRBRACE
1598 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1602 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1605 : initializer { $$ = $1; }
1606 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1610 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1613 : TSEMI { $$ = exprNode_createTok ($1); }
1614 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1617 : TSEMI { $$ = exprNode_createTok ($1); }
1618 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1619 | expr { $$ = exprNode_checkExpr ($1); }
1622 : CIF TLPAREN expr TRPAREN
1624 exprNode_produceGuards ($3); context_enterTrueClause ($3);
1625 exprNode_checkIfPred ($3);
1630 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1631 ** { $$ = $3; context_enterTrueClause (); }
1637 context_exitTrueClause ($1, $2);
1638 $$ = exprNode_if ($1, $2);
1640 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
1642 context_exitClause ($1, $2, $5);
1643 $$ = exprNode_ifelse ($1, $2, $5);
1645 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1646 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1649 : WHILE TLPAREN expr TRPAREN
1650 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1651 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1654 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1657 : ITER_NAME { context_enterIterClause (); }
1658 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1660 compoundStmt endIter DeleteInnerScope
1662 $$ = exprNode_iter ($1, $6, $8, $9);
1667 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1668 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1669 { $$ = exprNodeList_push ($1, $4); }
1672 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1673 | id { $$ = exprNode_iterId ($1); }
1674 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1676 if (uentry_isValid (ue))
1678 $$ = exprNode_iterId (ue);
1682 $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1685 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1688 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1693 | cconstantExpr CCONSTANT { $$ = exprNode_combineLiterals ($1, $2); }
1697 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1701 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1702 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1703 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1704 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1705 { $$ = exprNode_vaArg ($1, $3, $5); }
1706 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
1707 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
1708 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1709 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1713 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1714 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1715 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1716 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1717 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1718 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1719 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1720 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1721 | sizeofExpr { $$ = $1; }
1725 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1729 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1730 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1731 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1735 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1736 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1740 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1741 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1745 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1746 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1747 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1748 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1751 : relationalIterExpr
1752 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1753 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1757 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1761 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1766 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1770 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1774 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1778 | orExpr TQUEST { context_enterTrueClause ($1); }
1779 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1780 { $$ = exprNode_cond ($1, $4, $7); }
1783 : conditionalIterExpr
1784 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1785 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1786 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1787 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1788 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1789 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1790 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1791 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1792 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1793 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1794 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1797 : ITER_ENDNAME { $$ = $1; }
1798 | /* empty */ { $$ = uentry_undefined; }
1801 : DO { context_enterDoWhileClause (); $$ = $1; }
1805 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1806 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
1807 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1809 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1812 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1813 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1814 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1815 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1816 { $$ = exprNode_doWhile ($2, $5); }
1817 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1820 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1821 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1822 | QINNERCONTINUE CONTINUE TSEMI
1823 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1824 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1825 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1826 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1827 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1828 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1829 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1830 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1841 | ITER_NAME { $$ = uentry_getName ($1); }
1842 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1843 | id { $$ = uentry_getName ($1); }
1844 | TYPE_NAME_OR_ID { $$ = $1; }
1848 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1852 /*@-redecl@*/ /*@-namechecks@*/
1853 extern char *yytext;
1854 /*@=redecl@*/ /*@=namechecks@*/
1856 # include "bison.reset"
1858 void yyerror (/*@unused@*/ char *s)
1860 static bool givehint = FALSE;
1862 if (context_inIterDef ())
1864 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1865 context_inFunctionName ()));
1867 else if (context_inIterEnd ())
1869 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1870 context_inFunctionName ()));
1872 else if (context_inMacro ())
1874 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1875 context_inFunctionName ()));
1877 if (context_inUnknownMacro ())
1881 llhint (cstring_makeLiteral
1882 ("Precede macro definition with /*@notfunction@*/ "
1883 "to suppress checking and force expansion"));
1889 context_exitAllClausesQuiet ();
1893 llparseerror (cstring_undefined);