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 %type <typequal> nullterminatedQualifier
200 %token <tok> QNULLTERMINATED
201 %token <tok> QSETBUFFERSIZE
202 %token <tok> QSETSTRINGLENGTH
204 %token <tok> QMAXREAD
205 %token <tok> QTESTINRANGE
210 /* identifiers, literals */
211 %token <entry> IDENTIFIER
212 %token <cname> NEW_IDENTIFIER TYPE_NAME_OR_ID
213 %token <annotation> CANNOTATION
214 %token <expr> CCONSTANT
216 %type <flagspec> flagSpec
217 %type <expr> cconstantExpr
218 %token <entry> ITER_NAME ITER_ENDNAME
219 %type <entry> endIter
221 %type <funcclauselist> functionClauses functionClausesPlain
222 %type <funcclause> functionClause functionClause functionClausePlain
224 %type <globsclause> globalsClause globalsClausePlain
225 %type <modsclause> modifiesClause modifiesClausePlain nomodsClause
226 %type <warnclause> warnClause warnClausePlain optWarnClause
227 %type <funcclause> conditionClause conditionClausePlain
228 %type <stateclause> stateClause stateClausePlain
229 %type <msconstraint> metaStateConstraint
230 %type <fcnconstraint> functionConstraint
231 %type <msspec> metaStateSpecifier
232 %type <msexpr> metaStateExpression
234 %type <sr> globId globIdListExpr
235 %type <globset> globIdList
237 %token <ctyp> TYPE_NAME
238 %token <msinfo> METASTATE_NAME
239 %type <msinfo> metaStateName
240 %type <cname> enumerator newId /*@-varuse@*/ /* yacc declares yytranslate here */
241 %type <count> pointers /*@=varuse@*/
243 %type <tok> doHeader stateTag conditionTag startConditionClause
244 %type <typequal> exitsQualifier checkQualifier stateQualifier
245 paramQualifier returnQualifier visibilityQualifier
246 typedefQualifier refcountQualifier definedQualifier
248 /* type construction */
249 %type <ctyp> abstractDecl abstractDeclBase optAbstractDeclBase
250 %type <ctyp> suSpc enumSpc typeName typeSpecifier
252 %type <ntyp> namedDecl namedDeclBase optNamedDecl
253 %type <ntyp> plainNamedDecl plainNamedDeclBase
254 %type <ntyp> structNamedDecl
255 %type <ntyp> fcnDefHdrAux plainFcn
257 %type <oentry> paramDecl
260 %type <ntyplist> structNamedDeclList
262 %type <entrylist> genericParamList paramTypeList paramList idList paramIdList
263 %type <exprlist> argumentExprList iterArgList
264 %type <exprlist> initList namedInitializerList namedInitializerListAux
265 %type <flist> structDeclList structDecl
266 %type <srset> locModifies modList specClauseList optSpecClauseList
267 %type <sr> mExpr modListExpr specClauseListExpr
270 %type <con> BufConstraint
271 %type <tok> relationalOp
272 %type <tok> BufBinaryOp
273 %type <tok> bufferModifier
275 %type <conE> BufConstraintExpr
277 %type <conE> BufConstraintTerm
278 %type <sr> BufConstraintSrefExpr
280 %type <conL> BufConstraintList
282 %type <conL> optStructInvariant
284 %type <tok> BufUnaryOp
286 /*drl 1/6/2002 either /\ or && */
287 %type <tok> constraintSeperator
291 %type <enumnamelist> enumeratorList
292 %type <cstringlist> fieldDesignator
294 %type <expr> sizeofExpr sizeofExprAux offsetofExpr
295 %type <expr> openScope closeScope
296 %type <expr> instanceDecl namedInitializer optDeclarators
297 %type <expr> primaryExpr postfixExpr primaryIterExpr postfixIterExpr
298 %type <expr> unaryExpr castExpr timesExpr plusExpr
299 %type <expr> unaryIterExpr castIterExpr timesIterExpr plusIterExpr
300 %type <expr> shiftExpr relationalExpr equalityExpr bitandExpr
301 %type <expr> xorExpr bitorExpr andExpr
302 %type <expr> orExpr conditionalExpr assignExpr
303 %type <expr> shiftIterExpr relationalIterExpr equalityIterExpr bitandIterExpr
304 %type <expr> xorIterExpr bitorIterExpr andIterExpr
305 %type <expr> orIterExpr conditionalIterExpr assignIterExpr iterArgExpr
306 %type <expr> expr optExpr constantExpr
307 %type <expr> init macroBody iterBody endBody partialIterStmt iterSelectionStmt
308 %type <expr> stmt stmtList fcnBody iterStmt iterDefStmt iterDefStmtList
309 %type <expr> labeledStmt caseStmt defaultStmt
310 %type <expr> compoundStmt compoundStmtAux compoundStmtRest compoundStmtAuxErr
311 %type <expr> expressionStmt selectionStmt iterationStmt jumpStmt iterDefIterationStmt
312 %type <expr> stmtErr stmtListErr compoundStmtErr expressionStmtErr
313 %type <expr> iterationStmtErr initializerList initializer ifPred whilePred forPred iterWhilePred
315 %type <typequal> storageSpecifier typeQualifier typeModifier globQual
316 %type <tquallist> optGlobQuals
317 %type <qtyp> completeType completeTypeSpecifier optCompleteType
318 %type <qtyp> completeTypeSpecifierAux altType typeExpression
329 : externalDef { context_checkGlobalScope (); }
330 | externalDefs externalDef { context_checkGlobalScope (); }
333 : fcnDef optSemi { uentry_clearDecl (); }
334 | constantDecl { uentry_clearDecl (); }
335 | fcnDecl { uentry_clearDecl (); }
336 | iterDecl { uentry_clearDecl (); }
337 | macroDef { uentry_clearDecl (); }
338 | initializer { uentry_checkDecl (); exprNode_free ($1); }
339 | error { uentry_clearDecl (); }
342 : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
343 { checkConstant ($2, $4); }
344 | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
345 { checkValueConstant ($2, $4, $8) ; }
348 : QFUNCTION { context_enterFunctionHeader (); } plainFcn optSemi QENDMACRO
350 declareStaticFunction ($3); context_quietExitFunction ();
351 context_exitFunctionHeader ();
357 qtype qint = qtype_create (ctype_int);
358 $$ = idDecl_fixBase ($1, qint);
361 | completeTypeSpecifier NotType plainNamedDecl
362 { $$ = idDecl_fixBase ($3, $1); }
366 | pointers plainNamedDeclBase
367 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
370 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
371 | IsType TLPAREN NotType namedDecl IsType TRPAREN
372 { $$ = idDecl_expectFunction ($4); }
373 | namedDeclBase TLSQBR TRSQBR
374 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
375 | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
377 exprNode_findValue($4);
378 if (exprNode_hasValue ($4))
380 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), exprNode_getLongValue ($4)));
384 $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1)));
387 | namedDeclBase PushType TLPAREN TRPAREN
388 { setCurrentParams (uentryList_missingParams); }
390 { /* need to support globals and modifies here! */
391 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
392 uentryList_makeMissingParams ());
394 $$ = idDecl_replaceCtype ($1, ct);
395 idDecl_addClauses ($$, $6);
397 /*drl 7/25/01 added*/
398 setImplictfcnConstraints();
400 | namedDeclBase PushType TLPAREN genericParamList TRPAREN
401 { setCurrentParams ($4); }
403 { setImplictfcnConstraints ();
404 clearCurrentParams ();
405 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
406 idDecl_addClauses ($$, $7);
411 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
412 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
413 { $$ = idDecl_expectFunction ($4); }
414 | plainNamedDeclBase TLSQBR TRSQBR
415 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
416 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
420 if (exprNode_hasValue ($4)
421 && multiVal_isInt (exprNode_getValue ($4)))
423 value = (int) multiVal_forceInt (exprNode_getValue ($4));
430 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
432 | plainNamedDeclBase PushType TLPAREN TRPAREN
433 { setCurrentParams (uentryList_missingParams); }
436 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
437 uentryList_makeMissingParams ());
439 $$ = idDecl_replaceCtype ($1, ct);
440 idDecl_addClauses ($$, $6);
443 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
444 { setCurrentParams ($4); }
447 clearCurrentParams ();
448 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
449 idDecl_addClauses ($$, $7);
454 : QITER newId TLPAREN genericParamList TRPAREN
455 { setCurrentParams ($4); } functionClausesPlain
456 { clearCurrentParams (); } optSemi QENDMACRO
457 { declareCIter ($2, $4); }
460 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); }
461 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); }
462 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); }
463 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); }
466 : fcnDefHdrAux { clabstract_declareFunction ($1); }
469 : metaStateSpecifier TASSIGN metaStateExpression
470 { $$ = metaStateConstraint_create ($1, $3); }
473 : BufConstraintSrefExpr { cscanner_expectingMetaStateName (); } TCOLON metaStateName
474 { cscanner_clearExpectingMetaStateName ();
475 $$ = metaStateSpecifier_create ($1, $4); }
476 | CTOK_ELIPSIS { cscanner_expectingMetaStateName (); } TCOLON metaStateName
477 { cscanner_clearExpectingMetaStateName ();
478 $$ = metaStateSpecifier_createElipsis ($4); }
481 : metaStateSpecifier { $$ = metaStateExpression_create ($1); }
482 | metaStateSpecifier TBAR metaStateExpression { $$ = metaStateExpression_createMerge ($1, $3); }
494 : BufConstraint constraintSeperator BufConstraintList { $$ = constraintList_add ($3, $1); }
495 | BufConstraint { $$ = constraintList_single ($1); }
498 : BufConstraintExpr relationalOp BufConstraintExpr {
499 $$ = makeConstraintParse3 ($1, $2, $3);
500 DPRINTF(("Done BufConstraint1\n")); }
513 | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3); DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
514 | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
515 DPRINTF( ("Got BufConstraintExpr BINary Op ") );
516 $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
519 : BufConstraintSrefExpr { $$ = constraintExpr_makeTermsRef ($1);}
520 | CCONSTANT { $$ = constraintExpr_makeIntLiteral (exprNode_getLongValue ($1)); }
522 BufConstraintSrefExpr
524 { /*@-onlytrans@*/ $$ = checkbufferConstraintClausesId ($1); /*@=onlytrans@*/ /*@i523@*/ }
526 { $$ = fixStateClausesId ($1); }
527 | BufConstraintSrefExpr TLSQBR TRSQBR
528 { $$ = sRef_makeAnyArrayFetch ($1); }
529 | BufConstraintSrefExpr TLSQBR CCONSTANT TRSQBR
533 t = cstring_toCharsSafe (exprNode_unparse($3));
536 $$ = sRef_makeArrayFetchKnown ($1, exprNode_getLongValue ($3));
538 | TMULT BufConstraintSrefExpr
539 { $$ = sRef_constructPointer ($2); }
540 | TLPAREN BufConstraintSrefExpr TRPAREN
542 | BufConstraintSrefExpr TDOT newId
543 { cstring_markOwned ($3); $$ = sRef_buildField ($1, $3); }
544 | BufConstraintSrefExpr ARROW_OP newId
545 { cstring_markOwned ($3); $$ = sRef_makeArrow ($1, $3); }
548 | BufConstraintTerm TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
549 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
550 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
551 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
552 $$ = sRef_buildField ($1, $3); }
568 ** Function clauses can appear in any order.
572 : { $$ = functionClauseList_new (); }
573 | functionClause functionClauses
574 { $$ = functionClauseList_prepend ($2, $1); }
577 ** Inside macro definitions, there are no end macros.
582 { $$ = functionClauseList_new (); }
583 | functionClausePlain functionClausesPlain
584 { $$ = functionClauseList_prepend ($2, $1); }
587 : globalsClause { $$ = functionClause_createGlobals ($1); }
588 | modifiesClause { $$ = functionClause_createModifies ($1); }
589 | nomodsClause { $$ = functionClause_createModifies ($1); }
590 | stateClause { $$ = functionClause_createState ($1); }
591 | conditionClause { $$ = $1; }
592 | warnClause { $$ = functionClause_createWarn ($1); }
595 : globalsClausePlain { $$ = functionClause_createGlobals ($1); }
596 | modifiesClausePlain { $$ = functionClause_createModifies ($1); }
597 | nomodsClause { $$ = functionClause_createModifies ($1); }
598 | stateClausePlain { $$ = functionClause_createState ($1); }
599 | conditionClausePlain { $$ = $1; }
600 | warnClausePlain { $$ = functionClause_createWarn ($1); }
603 : globalsClausePlain QENDMACRO { $$ = $1; }
606 : QGLOBALS { setProcessingGlobalsList (); }
609 unsetProcessingGlobals ();
610 $$ = globalsClause_create ($1, $3);
614 : QNOMODS { $$ = modifiesClause_createNoMods ($1); }
617 : modifiesClausePlain QENDMACRO { $$ = $1; }
622 context_setProtectVars (); enterParamsTemp ();
623 sRef_setGlobalScopeSafe ();
628 sRef_clearGlobalScopeSafe ();
629 context_releaseVars ();
630 $$ = modifiesClause_create ($1, $3);
635 { $$ = flagSpec_createPlain ($1); }
636 | flagId TBAR flagSpec
637 { $$ = flagSpec_createOr ($1, $3); }
644 | /* empty */ { $$ = warnClause_undefined; }
647 : warnClausePlain QENDMACRO { $$ = $1; }
650 : QWARN flagSpec cconstantExpr
652 llassert (exprNode_knownStringValue ($3));
653 $$ = warnClause_create ($1, $2, cstring_copy (multiVal_forceString (exprNode_getValue ($3))));
657 { $$ = warnClause_create ($1, $2, cstring_undefined); }
660 : globIdListExpr { $$ = globSet_single ($1); }
661 | globIdList TCOMMA globIdListExpr { $$ = globSet_insert ($1, $3); }
664 : optGlobQuals globId { $$ = clabstract_createGlobal ($2, $1); }
667 : /* empty */ { $$ = qualList_undefined; }
668 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
671 : id { $$ = uentry_getSref ($1); }
672 | NEW_IDENTIFIER { $$ = clabstract_unrecognizedGlobal ($1); }
673 | initializer { $$ = clabstract_checkGlobal ($1); }
676 : QUNDEF { $$ = qual_createUndef (); }
677 | QKILLED { $$ = qual_createKilled (); }
678 | QOUT { $$ = qual_createOut (); }
679 | QIN { $$ = qual_createIn (); }
680 | QPARTIAL { $$ = qual_createPartial (); }
696 qtype qint = qtype_create (ctype_int);
697 $$ = idDecl_fixBase ($1, qint);
700 | completeTypeSpecifier NotType namedDecl
701 { $$ = idDecl_fixBase ($3, $1); }
704 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
707 exprNode_checkFunctionBody ($3); $$ = $3;
708 context_exitInner ($3);
710 | { context_enterOldStyleScope (); } initializerList
711 { oldStyleDoneParams (); context_enterInnerContext (); }
714 exprNode_checkFunctionBody ($4);
715 $$ = $4; /* oldstyle */
716 context_exitInner ($4);
722 context_setFunctionDefined (exprNode_loc ($2));
723 exprNode_checkFunction (context_getHeader (), $2);
726 context_exitFunction ();
730 : modList optSemi { $$ = $1; }
731 | optSemi { $$ = sRefSet_new (); }
734 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
735 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
736 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
737 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
738 | TMULT modListExpr { $$ = modListPointer ($2); }
739 | TLPAREN modListExpr TRPAREN { $$ = $2; }
740 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
741 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
745 : modListExpr { $$ = $1; }
746 | cconstantExpr { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
750 : modListExpr { $$ = sRefSet_single ($1); }
751 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
755 { $$ = checkStateClausesId ($1); }
757 { $$ = fixStateClausesId ($1); }
758 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
759 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
760 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
761 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
762 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
763 $$ = sRef_buildField ($1, $3); }
764 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
765 $$ = sRef_makeArrow ($1, $3); }
768 : /* empty */ { $$ = sRefSet_undefined }
773 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
774 else { $$ = sRefSet_undefined; }
776 | specClauseList TCOMMA specClauseListExpr
777 { if (sRef_isValid ($3))
779 $$ = sRefSet_insert ($1, $3);
788 : id { $$ = exprNode_fromIdentifier ($1); }
789 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
791 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
792 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
793 | QEXTENSION { $$ = exprNode_makeError (); }
797 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
798 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
799 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
800 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
801 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
802 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
803 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
804 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
807 : assignExpr { $$ = exprNodeList_singleton ($1); }
808 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
812 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
813 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
814 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
815 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
816 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
817 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
818 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
819 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
820 | sizeofExpr { $$ = $1; }
821 | offsetofExpr { $$ = $1; }
824 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
825 | newId { $$ = cstringList_single ($1); }
828 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
829 { $$ = exprNode_offsetof ($4, $7); }
832 : IsType { context_setProtectVars (); }
833 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
836 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); }
837 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); }
838 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); }
839 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); }
843 | TLPAREN typeExpression TRPAREN castExpr
844 { $$ = exprNode_cast ($1, $4, $2); }
848 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
849 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
850 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
854 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
855 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
859 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
860 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
864 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
865 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
866 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
867 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
871 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
872 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
876 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
880 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
885 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
890 { exprNode_produceGuards ($1);
891 context_enterAndClause ($1);
895 $$ = exprNode_op ($1, $4, $2);
896 context_exitAndClause ($$, $4);
903 exprNode_produceGuards ($1);
904 context_enterOrClause ($1);
908 $$ = exprNode_op ($1, $4, $2);
909 context_exitOrClause ($$, $4);
914 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
915 { context_enterFalseClause ($1); } conditionalExpr
916 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
920 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
921 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
922 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
923 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
924 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
925 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
926 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
927 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
928 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
929 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
930 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
934 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
937 : /* empty */ { $$ = exprNode_undefined; }
943 /* instance_orTypeDecl_and_possible_initialization */
946 : instanceDecl { $$ = $1; }
947 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
948 | typeDecl { $$ = exprNode_makeError (); }
951 : completeTypeSpecifier IsType TSEMI
952 { $$ = exprNode_makeError (); }
954 ** This causes r/r conflicts with function definitions.
955 ** Instead we need to snarf one first. (gack)
957 ** | completeTypeSpecifier { setProcessingVars ($1); }
959 ** namedInitializerList IsType TSEMI
960 ** { unsetProcessingVars (); }
963 ** the solution is pretty ugly:
965 | completeTypeSpecifier NotType namedDecl NotType
967 setProcessingVars ($1);
968 processNamedDecl ($3);
970 IsType optDeclarators TSEMI IsType
972 unsetProcessingVars ();
973 $$ = exprNode_makeEmptyInitialization ($3);
974 DPRINTF (("Empty initialization: %s", exprNode_unparse ($$)));
976 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
977 { setProcessingVars ($1); processNamedDecl ($3); }
978 IsType init optDeclarators TSEMI IsType
979 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
980 unsetProcessingVars ();
986 processNamedDecl ($1);
987 $$ = exprNode_makeEmptyInitialization ($1);
989 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
990 { $$ = exprNode_makeInitialization ($1, $6); }
993 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
994 NotType namedInitializerList IsType optWarnClause TSEMI
995 { clabstract_declareType ($5, $7); }
996 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
997 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
1000 : { g_expectingTypeName = TRUE; }
1003 : { g_expectingTypeName = TRUE; context_pushLoc (); }
1005 namedInitializerList
1006 : namedInitializerListAux IsType { $$ = $1; }
1008 namedInitializerListAux
1009 : namedInitializer { $$ = exprNodeList_singleton ($1); }
1010 | namedInitializerList TCOMMA NotType namedInitializer { $$ = exprNodeList_push ($1, $4); }
1013 : /* empty */ { $$ = exprNode_makeError (); }
1014 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
1018 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1019 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1024 { $$ = exprNodeList_singleton ($1); }
1025 | initList TCOMMA init
1026 { $$ = exprNodeList_push ($1, $3); }
1029 ** need to do the storage class global hack so tags are
1030 ** declared with the right storage class.
1034 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1035 | QINLINE { $$ = qual_createInline (); }
1036 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1037 | QAUTO { $$ = qual_createAuto (); }
1038 | QREGISTER { $$ = qual_createRegister (); }
1040 nullterminatedQualifier:
1041 QNULLTERMINATED IsType { $$ = qual_createNullTerminated (); }
1044 : stateClausePlain QENDMACRO { $$ = $1; }
1049 context_setProtectVars ();
1051 sRef_setGlobalScopeSafe ();
1053 specClauseList optSemi IsType
1056 sRef_clearGlobalScopeSafe ();
1057 context_releaseVars ();
1058 $$ = stateClause_createPlain ($1, $4);
1062 : conditionClausePlain QENDMACRO { $$ = $1; }
1064 startConditionClause
1065 : conditionTag NotType { $$ = $1; context_enterFunctionHeader (); }
1067 conditionClausePlain
1068 : startConditionClause stateQualifier
1070 context_exitFunctionHeader ();
1071 context_setProtectVars ();
1073 sRef_setGlobalScopeSafe ();
1075 optSpecClauseList optSemi IsType
1078 sRef_clearGlobalScopeSafe ();
1079 context_releaseVars ();
1080 $$ = functionClause_createState (stateClause_create ($1, $2, $4));
1082 | startConditionClause
1084 context_setProtectVars ();
1086 sRef_setGlobalScopeSafe ();
1088 functionConstraint optSemi IsType
1090 context_exitFunctionHeader ();
1092 sRef_clearGlobalScopeSafe ();
1093 context_releaseVars ();
1094 DPRINTF (("done optGlobBufConstraintsAux\n"));
1096 if (lltok_isEnsures ($1))
1098 $$ = functionClause_createEnsures ($3);
1100 else if (lltok_isRequires ($1))
1102 $$ = functionClause_createRequires ($3);
1109 DPRINTF (("FunctionclauseS: %s", functionClause_unparse ($$)));
1113 : BufConstraintList { $$ = functionConstraint_createBufferConstraint ($1); }
1114 | metaStateConstraint { $$ = functionConstraint_createMetaStateConstraint ($1); DPRINTF (("Made constraint: %s", functionConstraint_unparse ($$))); }
1117 : QEXITS { $$ = qual_createExits (); }
1118 | QMAYEXIT { $$ = qual_createMayExit (); }
1119 | QTRUEEXIT { $$ = qual_createTrueExit (); }
1120 | QFALSEEXIT { $$ = qual_createFalseExit (); }
1121 | QNEVEREXIT { $$ = qual_createNeverExit (); }
1124 : QCHECKED { $$ = qual_createChecked (); }
1125 | QCHECKMOD { $$ = qual_createCheckMod (); }
1126 | QUNCHECKED { $$ = qual_createUnchecked (); }
1127 | QCHECKEDSTRICT { $$ = qual_createCheckedStrict (); }
1130 : QOWNED { $$ = qual_createOwned (); }
1131 | QDEPENDENT { $$ = qual_createDependent (); }
1132 | QYIELD { $$ = qual_createYield (); }
1133 | QTEMP { $$ = qual_createTemp (); }
1134 | QONLY { $$ = qual_createOnly (); }
1135 | QKEEP { $$ = qual_createKeep (); }
1136 | QKEPT { $$ = qual_createKept (); }
1137 | QSHARED { $$ = qual_createShared (); }
1138 | QUNIQUE { $$ = qual_createUnique (); }
1139 | QNULL { $$ = qual_createNull (); }
1140 | QISNULL { $$ = qual_createIsNull (); }
1141 | QRELNULL { $$ = qual_createRelNull (); }
1142 | QNOTNULL { $$ = qual_createNotNull (); }
1143 | QEXPOSED { $$ = qual_createExposed (); }
1144 | QOBSERVER { $$ = qual_createObserver (); }
1145 | QNULLTERMINATED { $$ = qual_createNullTerminated (); }
1146 | CANNOTATION { $$ = qual_createMetaState ($1); }
1150 : QRETURNED { $$ = qual_createReturned (); }
1151 | QSEF { $$ = qual_createSef (); }
1154 : QUNUSED { $$ = qual_createUnused (); }
1155 | QEXTERNAL { $$ = qual_createExternal (); }
1158 : QTRUENULL { $$ = qual_createTrueNull (); }
1159 | QFALSENULL { $$ = qual_createFalseNull (); }
1162 : QABSTRACT { $$ = qual_createAbstract (); }
1163 | QCONCRETE { $$ = qual_createConcrete (); }
1164 | QMUTABLE { $$ = qual_createMutable (); }
1165 | QIMMUTABLE { $$ = qual_createImmutable (); }
1168 : QREFCOUNTED { $$ = qual_createRefCounted (); }
1169 | QREFS { $$ = qual_createRefs (); }
1170 | QKILLREF { $$ = qual_createKillRef (); }
1171 | QRELDEF { $$ = qual_createRelDef (); }
1172 | QNEWREF { $$ = qual_createNewRef (); }
1173 | QTEMPREF { $$ = qual_createTempRef (); }
1176 : QSHORT { $$ = qual_createShort (); }
1177 | QLONG { $$ = qual_createLong (); }
1178 | QSIGNED { $$ = qual_createSigned (); }
1179 | QUNSIGNED { $$ = qual_createUnsigned (); }
1182 : QOUT { $$ = qual_createOut (); }
1183 | QIN { $$ = qual_createIn (); }
1184 | QPARTIAL { $$ = qual_createPartial (); }
1185 | QSPECIAL { $$ = qual_createSpecial (); }
1188 : QCONST IsType { $$ = qual_createConst (); }
1189 | QVOLATILE IsType { $$ = qual_createVolatile (); }
1190 | definedQualifier IsType { $$ = $1; }
1191 | stateQualifier IsType { $$ = $1; }
1192 | exitsQualifier IsType { $$ = $1; }
1193 | paramQualifier IsType { $$ = $1; }
1194 | checkQualifier IsType { $$ = $1; }
1195 | returnQualifier IsType { $$ = $1; }
1196 | visibilityQualifier IsType { $$ = $1; }
1197 | typedefQualifier IsType { $$ = $1; }
1198 | refcountQualifier IsType { $$ = $1; }
1201 ** This is copied into the mtgrammar!
1211 | QANYTYPE NotType { $$ = ctype_unknown; }
1212 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
1213 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1214 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
1218 | typeModifier NotType { $$ = ctype_fromQual ($1); }
1221 : IsType completeTypeSpecifier IsType
1222 { $$ = qtype_resolve ($2); }
1224 completeTypeSpecifier
1225 : completeTypeSpecifierAux { $$ = $1; }
1226 | completeTypeSpecifierAux QALT altType QENDMACRO
1227 { $$ = qtype_mergeAlt ($1, $3); }
1231 | typeExpression TCOMMA altType
1232 { $$ = qtype_mergeAlt ($1, $3); }
1234 completeTypeSpecifierAux
1235 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1236 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1237 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
1240 : /* empty */ { $$ = qtype_unknown (); }
1241 | completeTypeSpecifier { $$ = $1; }
1245 : /* empty */ { $$ = constraintList_undefined; }
1246 /* don't want to have support for structure invariant until we're
1248 | QINVARIANT BufConstraintList QENDMACRO { $$ = $2 }
1252 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1253 CreateStructInnerScope
1254 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1256 optStructInvariant { {ctype ct; ct = declareStruct ($3, $8); /* setGlobalStructInfo(ct, $12);*/ $$ = ct;} }
1257 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1258 CreateStructInnerScope
1259 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1261 { $$ = declareUnion ($3, $8); }
1262 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
1263 { $$ = declareStruct ($3, uentryList_new ()); }
1264 | NotType CUNION newId IsType TLBRACE TRBRACE
1265 { $$ = declareUnion ($3, uentryList_new ()); }
1266 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1267 CreateStructInnerScope
1268 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1270 { $$ = declareUnnamedStruct ($7); }
1271 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1272 CreateStructInnerScope structDeclList DeleteStructInnerScope
1273 { sRef_clearGlobalScopeSafe (); }
1275 { $$ = declareUnnamedUnion ($7); }
1276 | NotType CSTRUCT IsType TLBRACE TRBRACE
1277 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
1278 | NotType CUNION IsType TLBRACE TRBRACE
1279 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
1280 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
1281 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
1284 : { g_expectingTypeName = FALSE; }
1288 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1289 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1292 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
1293 { $$ = fixUentryList ($3, $1); }
1294 | completeTypeSpecifier IsType TSEMI
1295 { $$ = fixUnnamedDecl ($1); }
1298 : structNamedDecl NotType
1299 { $$ = idDeclList_singleton ($1); }
1300 | structNamedDeclList TCOMMA structNamedDecl NotType
1301 { $$ = idDeclList_add ($1, $3); }
1303 structNamedDecl /* hack to get around namespace problems */
1304 : namedDecl { $$ = $1; }
1305 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1306 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1307 /* Need the IsType in case there is a cast in the constant expression. */
1310 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1311 { $$ = declareUnnamedEnum ($4); }
1312 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1313 { context_popLoc (); $$ = declareEnum ($3, $6); }
1314 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1318 { $$ = enumNameList_single ($1); }
1319 | enumeratorList TCOMMA enumerator
1320 { $$ = enumNameList_push ($1, $3); }
1321 | enumeratorList TCOMMA
1325 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1326 usymtab_supGlobalEntry (ue);
1329 | newId TASSIGN IsType constantExpr
1330 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1331 usymtab_supGlobalEntry (ue);
1337 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1338 | pointers TYPE_NAME
1340 qtype qt = qtype_unknown ();
1342 qtype_adjustPointers ($1, qt);
1343 $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1345 | pointers optNamedDecl
1346 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1350 | pointers namedDeclBase
1351 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1354 : paramTypeList { $$ = handleParamTypeList ($1); }
1355 | NotType paramIdList { $$ = handleParamIdList ($2); }
1358 : QCONST { /* ignored for now */; }
1363 | innerModsList innerMods { ; }
1367 | TMULT innerModsList { $$ = 1; }
1368 | TMULT pointers { $$ = 1 + $2; }
1369 | TMULT innerModsList pointers { $$ = 1 + $3; }
1373 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1376 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1377 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1380 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1382 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1385 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1386 | paramList TCOMMA { storeLoc (); } paramDecl
1387 { $$ = uentryList_add ($1, $4); }
1390 : IsType completeTypeSpecifier optNamedDecl IsType
1392 if (isFlipOldStyle ())
1394 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1400 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1402 | newId /* its an old-style declaration */
1404 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1408 llparseerror (message ("Inconsistent function parameter syntax: %q",
1409 idDecl_unparse (tparam)));
1413 $$ = makeCurrentParam (tparam);
1414 idDecl_free (tparam);
1419 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1422 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1424 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1427 : /* empty */ { $$ = ctype_unknown; }
1431 : IsType TLPAREN NotType abstractDecl TRPAREN
1432 { $$ = ctype_expectFunction ($4); }
1433 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1434 | TLSQBR constantExpr TRSQBR
1435 { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
1436 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1437 | abstractDeclBase TLSQBR constantExpr TRSQBR
1438 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
1439 | IsType TLPAREN TRPAREN
1440 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1441 | IsType TLPAREN paramTypeList TRPAREN
1442 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1443 | abstractDeclBase IsType TLPAREN TRPAREN
1444 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1445 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1446 { $$ = ctype_makeParamsFunction ($1, $4); }
1463 : iterDefStmtList { $$ = $1; }
1470 | iterDefStmtList iterDefStmt
1471 { $$ = exprNode_concat ($1, $2); }
1473 iterDefIterationStmt
1474 : iterWhilePred iterDefStmtList
1475 { $$ = exprNode_while ($1, $2); }
1476 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1477 { $$ = exprNode_doWhile ($2, $5); }
1478 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1479 { $$ = exprNode_doWhile ($2, $5); }
1480 | forPred iterDefStmt
1481 { $$ = exprNode_for ($1, $2); }
1484 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1485 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1487 { $$ = exprNode_forPred ($3, $5, $8);
1488 context_enterForClause ($5); }
1491 : ITER_NAME CreateInnerScope TLPAREN
1492 { setProcessingIterVars ($1); }
1494 { $$ = exprNode_iterStart ($1, $5); }
1495 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1501 | openScope initializerList { $$ = $1; DPRINTF (("def stmt: %s", exprNode_unparse ($$))); }
1506 | iterDefIterationStmt
1509 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1510 | error { $$ = exprNode_makeError (); }
1513 : ifPred { exprNode_checkIfPred ($1); } iterDefStmt
1514 { /* don't: context_exitTrueClause ($1, $2); */
1515 $$ = exprNode_if ($1, $3);
1519 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1522 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1537 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1539 | error { $$ = exprNode_makeError (); }
1542 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1543 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
1546 ** We allow more than one QFALLTHROUGH token to support mixed lint/splint markers.
1549 optExtraFallThroughs
1551 | QFALLTHROUGH optExtraFallThroughs { ; }
1553 /* Note that we can semantically check that the object to the case is
1554 indeed constant. In this case, we may not want to go through this effort */
1557 : CASE constantExpr { context_enterCaseClause ($2); }
1558 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
1559 | QFALLTHROUGH optExtraFallThroughs CASE constantExpr { context_enterCaseClause ($4); }
1560 TCOLON { $$ = exprNode_caseMarker ($4, TRUE); }
1563 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1564 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1565 | QFALLTHROUGH optExtraFallThroughs DEFAULT { context_enterCaseClause (exprNode_undefined); }
1566 TCOLON { $$ = exprNode_defaultMarker ($3, TRUE); }
1569 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1570 | CreateInnerScope compoundStmtAux
1571 { $$ = $2; context_exitInner ($2); }
1574 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1577 : { context_enterInnerContext (); }
1580 : { context_exitInnerPlain (); }
1582 CreateStructInnerScope
1583 : { context_enterStructInnerContext (); }
1585 DeleteStructInnerScope
1586 : { context_exitStructInnerContext (); }
1588 DeleteInnerScopeSafe
1589 : { context_exitInnerSafe (); }
1592 : TRBRACE { $$ = exprNode_createTok ($1); }
1593 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1594 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1595 | stmtList QNOTREACHED TRBRACE
1596 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1597 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1598 | initializerList QNOTREACHED TRBRACE
1599 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1600 | initializerList stmtList TRBRACE
1601 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1602 | initializerList stmtList QNOTREACHED TRBRACE
1603 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1604 lltok_getLoc ($3)));
1608 : TLBRACE compoundStmtRest
1609 { $$ = exprNode_makeBlock ($2); }
1613 { $$ = exprNode_createTok ($2); }
1614 | TLBRACE stmtListErr TRBRACE
1615 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1616 | TLBRACE initializerList TRBRACE
1617 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1618 | TLBRACE initializerList stmtList TRBRACE
1619 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1623 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1626 : initializer { $$ = $1; }
1627 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1631 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1634 : TSEMI { $$ = exprNode_createTok ($1); }
1635 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1638 : TSEMI { $$ = exprNode_createTok ($1); }
1639 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1640 | expr { $$ = exprNode_checkExpr ($1); }
1643 : CIF TLPAREN expr TRPAREN
1645 exprNode_produceGuards ($3); context_enterTrueClause ($3);
1646 exprNode_checkIfPred ($3);
1651 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1652 ** { $$ = $3; context_enterTrueClause (); }
1658 context_exitTrueClause ($1, $2);
1659 $$ = exprNode_if ($1, $2);
1661 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
1663 context_exitClause ($1, $2, $5);
1664 $$ = exprNode_ifelse ($1, $2, $5);
1666 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1667 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1670 : WHILE TLPAREN expr TRPAREN
1671 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1672 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1675 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1678 : ITER_NAME { context_enterIterClause (); }
1679 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1681 compoundStmt endIter DeleteInnerScope
1683 $$ = exprNode_iter ($1, $6, $8, $9);
1688 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1689 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1690 { $$ = exprNodeList_push ($1, $4); }
1693 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1694 | id { $$ = exprNode_iterId ($1); }
1695 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1697 if (uentry_isValid (ue))
1699 $$ = exprNode_iterId (ue);
1703 $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1706 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1709 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1714 | cconstantExpr CCONSTANT { $$ = exprNode_combineLiterals ($1, $2); }
1718 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1722 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1723 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1724 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1725 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1726 { $$ = exprNode_vaArg ($1, $3, $5); }
1727 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
1728 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
1729 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1730 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1734 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1735 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1736 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1737 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1738 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1739 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1740 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1741 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1742 | sizeofExpr { $$ = $1; }
1746 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1750 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1751 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1752 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1756 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1757 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1761 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1762 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1766 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1767 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1768 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1769 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1772 : relationalIterExpr
1773 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1774 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1778 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1782 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1787 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1791 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1795 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1799 | orExpr TQUEST { context_enterTrueClause ($1); }
1800 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1801 { $$ = exprNode_cond ($1, $4, $7); }
1804 : conditionalIterExpr
1805 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1806 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1807 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1808 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1809 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1810 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1811 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1812 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1813 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1814 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1815 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1818 : ITER_ENDNAME { $$ = $1; }
1819 | /* empty */ { $$ = uentry_undefined; }
1822 : DO { context_enterDoWhileClause (); $$ = $1; }
1826 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1827 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
1828 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1830 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1833 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1834 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1835 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1836 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1837 { $$ = exprNode_doWhile ($2, $5); }
1838 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1841 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1842 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1843 | QINNERCONTINUE CONTINUE TSEMI
1844 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1845 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1846 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1847 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1848 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1849 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1850 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1851 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1862 | ITER_NAME { $$ = uentry_getName ($1); }
1863 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1864 | id { $$ = uentry_getName ($1); }
1865 | TYPE_NAME_OR_ID { $$ = $1; }
1869 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1873 /*@-redecl@*/ /*@-namechecks@*/
1874 extern char *yytext;
1875 /*@=redecl@*/ /*@=namechecks@*/
1877 # include "bison.reset"
1879 void yyerror (/*@unused@*/ char *s)
1881 static bool givehint = FALSE;
1883 if (context_inIterDef ())
1885 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1886 context_inFunctionName ()));
1888 else if (context_inIterEnd ())
1890 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1891 context_inFunctionName ()));
1893 else if (context_inMacro ())
1895 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1896 context_inFunctionName ()));
1898 if (context_inUnknownMacro ())
1902 llhint (cstring_makeLiteral
1903 ("Precede macro definition with /*@notfunction@*/ "
1904 "to suppress checking and force expansion"));
1910 context_exitAllClausesQuiet ();
1914 llparseerror (cstring_undefined);