2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2001 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 lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://www.splint.org
29 ** Yacc/Bison grammar for extended ANSI C used by LCLint.
31 ** original grammar by Nate Osgood ---
32 ** hacrat@catfish.lcs.mit.edu Mon Jun 14 13:06:32 1993
34 ** changes for LCLint --- 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 "lclintMacros.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 lclint 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
311 /*%type <expr> lclintassertion*/
322 : externalDef { context_checkGlobalScope (); }
323 | externalDefs externalDef { context_checkGlobalScope (); }
326 : fcnDef optSemi { uentry_clearDecl (); }
327 | constantDecl { uentry_clearDecl (); }
328 | fcnDecl { uentry_clearDecl (); }
329 | iterDecl { uentry_clearDecl (); }
330 | macroDef { uentry_clearDecl (); }
331 | initializer { uentry_checkDecl (); exprNode_free ($1); }
332 | error { uentry_clearDecl (); }
335 : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
336 { checkConstant ($2, $4); }
337 | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
338 { checkValueConstant ($2, $4, $8) ; }
341 : QFUNCTION { context_enterFunctionHeader (); } plainFcn optSemi QENDMACRO
343 declareStaticFunction ($3); context_quietExitFunction ();
344 context_exitFunctionHeader ();
350 qtype qint = qtype_create (ctype_int);
351 $$ = idDecl_fixBase ($1, qint);
354 | completeTypeSpecifier NotType plainNamedDecl
355 { $$ = idDecl_fixBase ($3, $1); }
359 | pointers plainNamedDeclBase
360 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
363 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
364 | IsType TLPAREN NotType namedDecl IsType TRPAREN
365 { $$ = idDecl_expectFunction ($4); }
366 | namedDeclBase TLSQBR TRSQBR
367 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
368 | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
370 exprNode_findValue($4);
371 if (exprNode_hasValue ($4))
373 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), exprNode_getLongValue ($4)));
377 $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1)));
380 | namedDeclBase PushType TLPAREN TRPAREN
381 { setCurrentParams (uentryList_missingParams); }
383 { /* need to support globals and modifies here! */
384 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
385 uentryList_makeMissingParams ());
387 $$ = idDecl_replaceCtype ($1, ct);
388 idDecl_addClauses ($$, $6);
390 /*drl 7/25/01 added*/
391 setImplictfcnConstraints();
393 | namedDeclBase PushType TLPAREN genericParamList TRPAREN
394 { setCurrentParams ($4); }
396 { setImplictfcnConstraints ();
397 clearCurrentParams ();
398 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
399 idDecl_addClauses ($$, $7);
404 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
405 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
406 { $$ = idDecl_expectFunction ($4); }
407 | plainNamedDeclBase TLSQBR TRSQBR
408 { $$ = idDecl_replaceCtype ($1, ctype_makeArray (idDecl_getCtype ($1))); }
409 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
413 if (exprNode_hasValue ($4)
414 && multiVal_isInt (exprNode_getValue ($4)))
416 value = (int) multiVal_forceInt (exprNode_getValue ($4));
423 $$ = idDecl_replaceCtype ($1, ctype_makeFixedArray (idDecl_getCtype ($1), value));
425 | plainNamedDeclBase PushType TLPAREN TRPAREN
426 { setCurrentParams (uentryList_missingParams); }
429 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
430 uentryList_makeMissingParams ());
432 $$ = idDecl_replaceCtype ($1, ct);
433 idDecl_addClauses ($$, $6);
436 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
437 { setCurrentParams ($4); }
440 clearCurrentParams ();
441 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
442 idDecl_addClauses ($$, $7);
447 : QITER newId TLPAREN genericParamList TRPAREN
448 { setCurrentParams ($4); } functionClausesPlain
449 { clearCurrentParams (); } optSemi QENDMACRO
450 { declareCIter ($2, $4); }
453 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); }
454 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); }
455 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); }
456 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); }
459 : fcnDefHdrAux { clabstract_declareFunction ($1); }
462 : metaStateSpecifier TASSIGN metaStateExpression
463 { $$ = metaStateConstraint_create ($1, $3); }
466 : BufConstraintSrefExpr { cscanner_expectingMetaStateName (); } TCOLON metaStateName
467 { cscanner_clearExpectingMetaStateName ();
468 $$ = metaStateSpecifier_create ($1, $4); }
469 | CTOK_ELIPSIS { cscanner_expectingMetaStateName (); } TCOLON metaStateName
470 { cscanner_clearExpectingMetaStateName ();
471 $$ = metaStateSpecifier_createElipsis ($4); }
474 : metaStateSpecifier { $$ = metaStateExpression_create ($1); }
475 | metaStateSpecifier TBAR metaStateExpression { $$ = metaStateExpression_createMerge ($1, $3); }
483 : BufConstraint TCAND BufConstraintList { $$ = constraintList_add ($3, $1); }
484 | BufConstraint { $$ = constraintList_single ($1); }
487 : BufConstraintExpr relationalOp BufConstraintExpr {
488 $$ = makeConstraintParse3 ($1, $2, $3);
489 DPRINTF(("Done BufConstraint1\n")); }
502 | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3); DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
503 | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
504 DPRINTF( ("Got BufConstraintExpr BINary Op ") );
505 $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
508 : BufConstraintSrefExpr { $$ = constraintExpr_makeTermsRef ($1);}
509 | CCONSTANT { $$ = constraintExpr_makeIntLiteral (exprNode_getLongValue ($1)); }
511 BufConstraintSrefExpr
513 { /*@-onlytrans@*/ $$ = checkbufferConstraintClausesId ($1); /*@=onlytrans@*/ /*@i523@*/ }
515 { $$ = fixStateClausesId ($1); }
516 | BufConstraintSrefExpr TLSQBR TRSQBR
517 { $$ = sRef_makeAnyArrayFetch ($1); }
518 | BufConstraintSrefExpr TLSQBR CCONSTANT TRSQBR
522 t = cstring_toCharsSafe (exprNode_unparse($3));
525 $$ = sRef_makeArrayFetchKnown ($1, exprNode_getLongValue ($3));
527 | TMULT BufConstraintSrefExpr
528 { $$ = sRef_constructPointer ($2); }
529 | TLPAREN BufConstraintSrefExpr TRPAREN
531 | BufConstraintSrefExpr TDOT newId
532 { cstring_markOwned ($3); $$ = sRef_buildField ($1, $3); }
533 | BufConstraintSrefExpr ARROW_OP newId
534 { cstring_markOwned ($3); $$ = sRef_makeArrow ($1, $3); }
537 | BufConstraintTerm TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
538 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
539 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
540 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
541 $$ = sRef_buildField ($1, $3); }
557 ** Function clauses can appear in any order.
561 : { $$ = functionClauseList_new (); }
562 | functionClause functionClauses
563 { $$ = functionClauseList_prepend ($2, $1); }
566 ** Inside macro definitions, there are no end macros.
571 { $$ = functionClauseList_new (); }
572 | functionClausePlain functionClausesPlain
573 { $$ = functionClauseList_prepend ($2, $1); }
576 : globalsClause { $$ = functionClause_createGlobals ($1); }
577 | modifiesClause { $$ = functionClause_createModifies ($1); }
578 | nomodsClause { $$ = functionClause_createModifies ($1); }
579 | stateClause { $$ = functionClause_createState ($1); }
580 | conditionClause { $$ = $1; }
581 | warnClause { $$ = functionClause_createWarn ($1); }
584 : globalsClausePlain { $$ = functionClause_createGlobals ($1); }
585 | modifiesClausePlain { $$ = functionClause_createModifies ($1); }
586 | nomodsClause { $$ = functionClause_createModifies ($1); }
587 | stateClausePlain { $$ = functionClause_createState ($1); }
588 | conditionClausePlain { $$ = $1; }
589 | warnClausePlain { $$ = functionClause_createWarn ($1); }
592 : globalsClausePlain QENDMACRO { $$ = $1; }
595 : QGLOBALS { setProcessingGlobalsList (); }
598 unsetProcessingGlobals ();
599 $$ = globalsClause_create ($1, $3);
603 : QNOMODS { $$ = modifiesClause_createNoMods ($1); }
606 : modifiesClausePlain QENDMACRO { $$ = $1; }
611 context_setProtectVars (); enterParamsTemp ();
612 sRef_setGlobalScopeSafe ();
617 sRef_clearGlobalScopeSafe ();
618 context_releaseVars ();
619 $$ = modifiesClause_create ($1, $3);
624 { $$ = flagSpec_createPlain ($1); }
625 | flagId TBAR flagSpec
626 { $$ = flagSpec_createOr ($1, $3); }
633 | /* empty */ { $$ = warnClause_undefined; }
636 : warnClausePlain QENDMACRO { $$ = $1; }
639 : QWARN flagSpec cconstantExpr
641 llassert (exprNode_knownStringValue ($3));
642 $$ = warnClause_create ($1, $2, cstring_copy (multiVal_forceString (exprNode_getValue ($3))));
646 { $$ = warnClause_create ($1, $2, cstring_undefined); }
649 : globIdListExpr { $$ = globSet_single ($1); }
650 | globIdList TCOMMA globIdListExpr { $$ = globSet_insert ($1, $3); }
653 : optGlobQuals globId { $$ = clabstract_createGlobal ($2, $1); }
656 : /* empty */ { $$ = qualList_undefined; }
657 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
660 : id { $$ = uentry_getSref ($1); }
661 | NEW_IDENTIFIER { $$ = clabstract_unrecognizedGlobal ($1); }
662 | initializer { $$ = clabstract_checkGlobal ($1); }
665 : QUNDEF { $$ = qual_createUndef (); }
666 | QKILLED { $$ = qual_createKilled (); }
667 | QOUT { $$ = qual_createOut (); }
668 | QIN { $$ = qual_createIn (); }
669 | QPARTIAL { $$ = qual_createPartial (); }
685 qtype qint = qtype_create (ctype_int);
686 $$ = idDecl_fixBase ($1, qint);
689 | completeTypeSpecifier NotType namedDecl
690 { $$ = idDecl_fixBase ($3, $1); }
693 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
696 exprNode_checkFunctionBody ($3); $$ = $3;
697 context_exitInner ($3);
699 | { context_enterOldStyleScope (); } initializerList
700 { oldStyleDoneParams (); context_enterInnerContext (); }
703 exprNode_checkFunctionBody ($4);
704 $$ = $4; /* oldstyle */
705 context_exitInner ($4);
711 context_setFunctionDefined (exprNode_loc ($2));
712 exprNode_checkFunction (context_getHeader (), $2);
715 context_exitFunction ();
719 : modList optSemi { $$ = $1; }
720 | optSemi { $$ = sRefSet_new (); }
723 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
724 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
725 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
726 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
727 | TMULT modListExpr { $$ = modListPointer ($2); }
728 | TLPAREN modListExpr TRPAREN { $$ = $2; }
729 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
730 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
734 : modListExpr { $$ = $1; }
735 | cconstantExpr { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
739 : modListExpr { $$ = sRefSet_single ($1); }
740 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
744 { $$ = checkStateClausesId ($1); }
746 { $$ = fixStateClausesId ($1); }
747 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
748 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
749 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
750 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
751 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
752 $$ = sRef_buildField ($1, $3); }
753 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
754 $$ = sRef_makeArrow ($1, $3); }
757 : /* empty */ { $$ = sRefSet_undefined }
762 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
763 else { $$ = sRefSet_undefined; }
765 | specClauseList TCOMMA specClauseListExpr
766 { if (sRef_isValid ($3))
768 $$ = sRefSet_insert ($1, $3);
777 : id { $$ = exprNode_fromIdentifier ($1); }
778 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
780 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
781 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
782 | QEXTENSION { $$ = exprNode_makeError (); }
786 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
787 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
788 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
789 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
790 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
791 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
792 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
793 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
796 : assignExpr { $$ = exprNodeList_singleton ($1); }
797 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
801 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
802 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
803 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
804 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
805 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
806 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
807 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
808 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
809 | sizeofExpr { $$ = $1; }
810 | offsetofExpr { $$ = $1; }
813 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); }
814 | newId { $$ = cstringList_single ($1); }
817 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
818 { $$ = exprNode_offsetof ($4, $7); }
821 : IsType { context_setProtectVars (); }
822 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
825 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); }
826 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); }
827 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); }
828 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); }
832 | TLPAREN typeExpression TRPAREN castExpr
833 { $$ = exprNode_cast ($1, $4, $2); }
837 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
838 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
839 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
843 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
844 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
848 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
849 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
853 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
854 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
855 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
856 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
860 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
861 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
865 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
869 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
874 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
879 { exprNode_produceGuards ($1);
880 context_enterAndClause ($1);
884 $$ = exprNode_op ($1, $4, $2);
885 context_exitAndClause ($$, $4);
892 exprNode_produceGuards ($1);
893 context_enterOrClause ($1);
897 $$ = exprNode_op ($1, $4, $2);
898 context_exitOrClause ($$, $4);
903 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
904 { context_enterFalseClause ($1); } conditionalExpr
905 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
909 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
910 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
911 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
912 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
913 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
914 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
915 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
916 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
917 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
918 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
919 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
923 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
926 : /* empty */ { $$ = exprNode_undefined; }
932 /* instance_orTypeDecl_and_possible_initialization */
935 : instanceDecl { $$ = $1; }
936 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
937 | typeDecl { $$ = exprNode_makeError (); }
940 : completeTypeSpecifier IsType TSEMI
941 { $$ = exprNode_makeError (); }
943 ** This causes r/r conflicts with function definitions.
944 ** Instead we need to snarf one first. (gack)
946 ** | completeTypeSpecifier { setProcessingVars ($1); }
948 ** namedInitializerList IsType TSEMI
949 ** { unsetProcessingVars (); }
952 ** the solution is pretty ugly:
954 | completeTypeSpecifier NotType namedDecl NotType
956 setProcessingVars ($1);
957 processNamedDecl ($3);
959 IsType optDeclarators TSEMI IsType
961 unsetProcessingVars ();
962 $$ = exprNode_makeEmptyInitialization ($3);
963 DPRINTF (("Empty initialization: %s", exprNode_unparse ($$)));
965 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
966 { setProcessingVars ($1); processNamedDecl ($3); }
967 IsType init optDeclarators TSEMI IsType
968 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
969 unsetProcessingVars ();
975 processNamedDecl ($1);
976 $$ = exprNode_makeEmptyInitialization ($1);
978 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
979 { $$ = exprNode_makeInitialization ($1, $6); }
982 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
983 NotType namedInitializerList IsType optWarnClause TSEMI
984 { clabstract_declareType ($5, $7); }
985 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
986 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
989 : { g_expectingTypeName = TRUE; }
992 : { g_expectingTypeName = TRUE; context_pushLoc (); }
995 : namedInitializerListAux IsType { $$ = $1; }
997 namedInitializerListAux
998 : namedInitializer { $$ = exprNodeList_singleton ($1); }
999 | namedInitializerList TCOMMA NotType namedInitializer { $$ = exprNodeList_push ($1, $4); }
1002 : /* empty */ { $$ = exprNode_makeError (); }
1003 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
1007 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1008 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); }
1013 { $$ = exprNodeList_singleton ($1); }
1014 | initList TCOMMA init
1015 { $$ = exprNodeList_push ($1, $3); }
1018 ** need to do the storage class global hack so tags are
1019 ** declared with the right storage class.
1023 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1024 | QINLINE { $$ = qual_createInline (); }
1025 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1026 | QAUTO { $$ = qual_createAuto (); }
1027 | QREGISTER { $$ = qual_createRegister (); }
1029 nullterminatedQualifier:
1030 QNULLTERMINATED IsType { $$ = qual_createNullTerminated (); }
1033 : stateClausePlain QENDMACRO { $$ = $1; }
1038 context_setProtectVars ();
1040 sRef_setGlobalScopeSafe ();
1042 specClauseList optSemi IsType
1045 sRef_clearGlobalScopeSafe ();
1046 context_releaseVars ();
1047 $$ = stateClause_createPlain ($1, $4);
1051 : conditionClausePlain QENDMACRO { $$ = $1; }
1053 startConditionClause
1054 : conditionTag NotType { $$ = $1; context_enterFunctionHeader (); }
1056 conditionClausePlain
1057 : startConditionClause stateQualifier
1059 context_exitFunctionHeader ();
1060 context_setProtectVars ();
1062 sRef_setGlobalScopeSafe ();
1064 optSpecClauseList optSemi IsType
1067 sRef_clearGlobalScopeSafe ();
1068 context_releaseVars ();
1069 $$ = functionClause_createState (stateClause_create ($1, $2, $4));
1071 | startConditionClause
1073 context_setProtectVars ();
1075 sRef_setGlobalScopeSafe ();
1077 functionConstraint optSemi IsType
1079 context_exitFunctionHeader ();
1081 sRef_clearGlobalScopeSafe ();
1082 context_releaseVars ();
1083 DPRINTF (("done optGlobBufConstraintsAux\n"));
1085 if (lltok_isEnsures ($1))
1087 $$ = functionClause_createEnsures ($3);
1089 else if (lltok_isRequires ($1))
1091 $$ = functionClause_createRequires ($3);
1098 DPRINTF (("FunctionclauseS: %s", functionClause_unparse ($$)));
1102 : BufConstraintList { $$ = functionConstraint_createBufferConstraint ($1); }
1103 | metaStateConstraint { $$ = functionConstraint_createMetaStateConstraint ($1); DPRINTF (("Made constraint: %s", functionConstraint_unparse ($$))); }
1106 : QEXITS { $$ = qual_createExits (); }
1107 | QMAYEXIT { $$ = qual_createMayExit (); }
1108 | QTRUEEXIT { $$ = qual_createTrueExit (); }
1109 | QFALSEEXIT { $$ = qual_createFalseExit (); }
1110 | QNEVEREXIT { $$ = qual_createNeverExit (); }
1113 : QCHECKED { $$ = qual_createChecked (); }
1114 | QCHECKMOD { $$ = qual_createCheckMod (); }
1115 | QUNCHECKED { $$ = qual_createUnchecked (); }
1116 | QCHECKEDSTRICT { $$ = qual_createCheckedStrict (); }
1119 : QOWNED { $$ = qual_createOwned (); }
1120 | QDEPENDENT { $$ = qual_createDependent (); }
1121 | QYIELD { $$ = qual_createYield (); }
1122 | QTEMP { $$ = qual_createTemp (); }
1123 | QONLY { $$ = qual_createOnly (); }
1124 | QKEEP { $$ = qual_createKeep (); }
1125 | QKEPT { $$ = qual_createKept (); }
1126 | QSHARED { $$ = qual_createShared (); }
1127 | QUNIQUE { $$ = qual_createUnique (); }
1128 | QNULL { $$ = qual_createNull (); }
1129 | QISNULL { $$ = qual_createIsNull (); }
1130 | QRELNULL { $$ = qual_createRelNull (); }
1131 | QNOTNULL { $$ = qual_createNotNull (); }
1132 | QEXPOSED { $$ = qual_createExposed (); }
1133 | QOBSERVER { $$ = qual_createObserver (); }
1134 | QNULLTERMINATED { $$ = qual_createNullTerminated (); }
1135 | CANNOTATION { $$ = qual_createMetaState ($1); }
1139 : QRETURNED { $$ = qual_createReturned (); }
1140 | QSEF { $$ = qual_createSef (); }
1143 : QUNUSED { $$ = qual_createUnused (); }
1144 | QEXTERNAL { $$ = qual_createExternal (); }
1147 : QTRUENULL { $$ = qual_createTrueNull (); }
1148 | QFALSENULL { $$ = qual_createFalseNull (); }
1151 : QABSTRACT { $$ = qual_createAbstract (); }
1152 | QCONCRETE { $$ = qual_createConcrete (); }
1153 | QMUTABLE { $$ = qual_createMutable (); }
1154 | QIMMUTABLE { $$ = qual_createImmutable (); }
1157 : QREFCOUNTED { $$ = qual_createRefCounted (); }
1158 | QREFS { $$ = qual_createRefs (); }
1159 | QKILLREF { $$ = qual_createKillRef (); }
1160 | QRELDEF { $$ = qual_createRelDef (); }
1161 | QNEWREF { $$ = qual_createNewRef (); }
1162 | QTEMPREF { $$ = qual_createTempRef (); }
1165 : QSHORT { $$ = qual_createShort (); }
1166 | QLONG { $$ = qual_createLong (); }
1167 | QSIGNED { $$ = qual_createSigned (); }
1168 | QUNSIGNED { $$ = qual_createUnsigned (); }
1171 : QOUT { $$ = qual_createOut (); }
1172 | QIN { $$ = qual_createIn (); }
1173 | QPARTIAL { $$ = qual_createPartial (); }
1174 | QSPECIAL { $$ = qual_createSpecial (); }
1177 : QCONST IsType { $$ = qual_createConst (); }
1178 | QVOLATILE IsType { $$ = qual_createVolatile (); }
1179 | definedQualifier IsType { $$ = $1; }
1180 | stateQualifier IsType { $$ = $1; }
1181 | exitsQualifier IsType { $$ = $1; }
1182 | paramQualifier IsType { $$ = $1; }
1183 | checkQualifier IsType { $$ = $1; }
1184 | returnQualifier IsType { $$ = $1; }
1185 | visibilityQualifier IsType { $$ = $1; }
1186 | typedefQualifier IsType { $$ = $1; }
1187 | refcountQualifier IsType { $$ = $1; }
1190 ** This is copied into the mtgrammar!
1200 | QANYTYPE NotType { $$ = ctype_unknown; }
1201 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
1202 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1203 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
1207 | typeModifier NotType { $$ = ctype_fromQual ($1); }
1210 : IsType completeTypeSpecifier IsType
1211 { $$ = qtype_resolve ($2); }
1213 completeTypeSpecifier
1214 : completeTypeSpecifierAux { $$ = $1; }
1215 | completeTypeSpecifierAux QALT altType QENDMACRO
1216 { $$ = qtype_mergeAlt ($1, $3); }
1220 | typeExpression TCOMMA altType
1221 { $$ = qtype_mergeAlt ($1, $3); }
1223 completeTypeSpecifierAux
1224 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1225 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1226 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
1229 : /* empty */ { $$ = qtype_unknown (); }
1230 | completeTypeSpecifier { $$ = $1; }
1233 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1234 CreateStructInnerScope
1235 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1237 { $$ = declareStruct ($3, $8); }
1238 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1239 CreateStructInnerScope
1240 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1242 { $$ = declareUnion ($3, $8); }
1243 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
1244 { $$ = declareStruct ($3, uentryList_new ()); }
1245 | NotType CUNION newId IsType TLBRACE TRBRACE
1246 { $$ = declareUnion ($3, uentryList_new ()); }
1247 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1248 CreateStructInnerScope
1249 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1251 { $$ = declareUnnamedStruct ($7); }
1252 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1253 CreateStructInnerScope structDeclList DeleteStructInnerScope
1254 { sRef_clearGlobalScopeSafe (); }
1256 { $$ = declareUnnamedUnion ($7); }
1257 | NotType CSTRUCT IsType TLBRACE TRBRACE
1258 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
1259 | NotType CUNION IsType TLBRACE TRBRACE
1260 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
1261 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
1262 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
1265 : { g_expectingTypeName = FALSE; }
1269 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1270 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1273 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
1274 { $$ = fixUentryList ($3, $1); }
1275 | completeTypeSpecifier IsType TSEMI
1276 { $$ = fixUnnamedDecl ($1); }
1279 : structNamedDecl NotType
1280 { $$ = idDeclList_singleton ($1); }
1281 | structNamedDeclList TCOMMA structNamedDecl NotType
1282 { $$ = idDeclList_add ($1, $3); }
1284 structNamedDecl /* hack to get around namespace problems */
1285 : namedDecl { $$ = $1; }
1286 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1287 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1288 /* Need the IsType in case there is a cast in the constant expression. */
1291 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1292 { $$ = declareUnnamedEnum ($4); }
1293 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1294 { context_popLoc (); $$ = declareEnum ($3, $6); }
1295 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1299 { $$ = enumNameList_single ($1); }
1300 | enumeratorList TCOMMA enumerator
1301 { $$ = enumNameList_push ($1, $3); }
1302 | enumeratorList TCOMMA
1306 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1307 usymtab_supGlobalEntry (ue);
1310 | newId TASSIGN IsType constantExpr
1311 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1312 usymtab_supGlobalEntry (ue);
1318 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1319 | pointers TYPE_NAME
1321 qtype qt = qtype_unknown ();
1323 qtype_adjustPointers ($1, qt);
1324 $$ = idDecl_create (cstring_copy (LastIdentifier ()), qt);
1326 | pointers optNamedDecl
1327 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1331 | pointers namedDeclBase
1332 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1335 : paramTypeList { $$ = handleParamTypeList ($1); }
1336 | NotType paramIdList { $$ = handleParamIdList ($2); }
1339 : QCONST { /* ignored for now */; }
1344 | innerModsList innerMods { ; }
1348 | TMULT innerModsList { $$ = 1; }
1349 | TMULT pointers { $$ = 1 + $2; }
1350 | TMULT innerModsList pointers { $$ = 1 + $3; }
1354 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1357 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1358 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1361 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1363 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1366 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1367 | paramList TCOMMA { storeLoc (); } paramDecl
1368 { $$ = uentryList_add ($1, $4); }
1371 : IsType completeTypeSpecifier optNamedDecl IsType
1373 if (isFlipOldStyle ())
1375 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1381 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1383 | newId /* its an old-style declaration */
1385 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1389 llparseerror (message ("Inconsistent function parameter syntax: %q",
1390 idDecl_unparse (tparam)));
1394 $$ = makeCurrentParam (tparam);
1395 idDecl_free (tparam);
1400 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1403 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1405 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1408 : /* empty */ { $$ = ctype_unknown; }
1412 : IsType TLPAREN NotType abstractDecl TRPAREN
1413 { $$ = ctype_expectFunction ($4); }
1414 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
1415 | TLSQBR constantExpr TRSQBR
1416 { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
1417 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeArray ($1); }
1418 | abstractDeclBase TLSQBR constantExpr TRSQBR
1419 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
1420 | IsType TLPAREN TRPAREN
1421 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1422 | IsType TLPAREN paramTypeList TRPAREN
1423 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1424 | abstractDeclBase IsType TLPAREN TRPAREN
1425 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1426 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1427 { $$ = ctype_makeParamsFunction ($1, $4); }
1441 /* | lclintassertion {$$ = $1; printf ("Doing stmt lclintassertion\n"); }*/
1445 : QSETBUFFERSIZE id CCONSTANT QENDMACRO { printf(" QSETBUFFERSIZE id CCONSTANT HEllo World\n"); uentry_setBufferSize($2, $3); $$ = exprNode_createTok ($4);
1447 | QSETSTRINGLENGTH id CCONSTANT QENDMACRO { printf(" QSETSTRINGLENGTH id CCONSTANT HEllo World\n"); uentry_setStringLength($2, $3); $$ = exprNode_createTok ($4);
1449 | QTESTINRANGE id CCONSTANT QENDMACRO {printf(" QTESTINRANGE\n"); uentry_testInRange($2, $3); $$ = exprNode_createTok ($4);
1452 /* | QSETBUFFERSIZE id id {$$ = $2; printf(" QSETBUFFERSIZE id id HEllo World\n");} */
1455 : iterDefStmtList { $$ = $1; }
1462 | iterDefStmtList iterDefStmt
1463 { $$ = exprNode_concat ($1, $2); }
1465 iterDefIterationStmt
1466 : iterWhilePred iterDefStmtList
1467 { $$ = exprNode_while ($1, $2); }
1468 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1469 { $$ = exprNode_doWhile ($2, $5); }
1470 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1471 { $$ = exprNode_doWhile ($2, $5); }
1472 | forPred iterDefStmt
1473 { $$ = exprNode_for ($1, $2); }
1476 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1477 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1479 { $$ = exprNode_forPred ($3, $5, $8);
1480 context_enterForClause ($5); }
1483 : ITER_NAME CreateInnerScope TLPAREN
1484 { setProcessingIterVars ($1); }
1486 { $$ = exprNode_iterStart ($1, $5); }
1487 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1493 | openScope initializerList { $$ = $1; DPRINTF (("def stmt: %s", exprNode_unparse ($$))); }
1498 | iterDefIterationStmt
1501 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1502 | error { $$ = exprNode_makeError (); }
1505 : ifPred { exprNode_checkIfPred ($1); } iterDefStmt
1506 { /* don't: context_exitTrueClause ($1, $2); */
1507 $$ = exprNode_if ($1, $3);
1511 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1514 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1529 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1531 | error { $$ = exprNode_makeError (); }
1534 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1535 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
1538 ** We allow more than one QFALLTHROUGH token to support mixed lint/splint markers.
1541 optExtraFallThroughs
1543 | QFALLTHROUGH optExtraFallThroughs { ; }
1545 /* Note that we can semantically check that the object to the case is
1546 indeed constant. In this case, we may not want to go through this effort */
1549 : CASE constantExpr { context_enterCaseClause ($2); }
1550 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
1551 | QFALLTHROUGH optExtraFallThroughs CASE constantExpr { context_enterCaseClause ($4); }
1552 TCOLON { $$ = exprNode_caseMarker ($4, TRUE); }
1555 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1556 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
1557 | QFALLTHROUGH optExtraFallThroughs DEFAULT { context_enterCaseClause (exprNode_undefined); }
1558 TCOLON { $$ = exprNode_defaultMarker ($3, TRUE); }
1561 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1562 | CreateInnerScope compoundStmtAux
1563 { $$ = $2; context_exitInner ($2); }
1566 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1569 : { context_enterInnerContext (); }
1572 : { context_exitInnerPlain (); }
1574 CreateStructInnerScope
1575 : { context_enterStructInnerContext (); }
1577 DeleteStructInnerScope
1578 : { context_exitStructInnerContext (); }
1580 DeleteInnerScopeSafe
1581 : { context_exitInnerSafe (); }
1584 : TRBRACE { $$ = exprNode_createTok ($1); }
1585 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1586 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1587 | stmtList QNOTREACHED TRBRACE
1588 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1589 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1590 | initializerList QNOTREACHED TRBRACE
1591 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1592 | initializerList stmtList TRBRACE
1593 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1594 | initializerList stmtList QNOTREACHED TRBRACE
1595 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1596 lltok_getLoc ($3)));
1600 : TLBRACE compoundStmtRest
1601 { $$ = exprNode_makeBlock ($2); }
1605 { $$ = exprNode_createTok ($2); }
1606 | TLBRACE stmtListErr TRBRACE
1607 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1608 | TLBRACE initializerList TRBRACE
1609 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1610 | TLBRACE initializerList stmtList TRBRACE
1611 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1615 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1618 : initializer { $$ = $1; }
1619 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1623 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
1626 : TSEMI { $$ = exprNode_createTok ($1); }
1627 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1630 : TSEMI { $$ = exprNode_createTok ($1); }
1631 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
1632 | expr { $$ = exprNode_checkExpr ($1); }
1635 : CIF TLPAREN expr TRPAREN
1637 exprNode_produceGuards ($3); context_enterTrueClause ($3);
1638 exprNode_checkIfPred ($3);
1643 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1644 ** { $$ = $3; context_enterTrueClause (); }
1650 context_exitTrueClause ($1, $2);
1651 $$ = exprNode_if ($1, $2);
1653 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
1655 context_exitClause ($1, $2, $5);
1656 $$ = exprNode_ifelse ($1, $2, $5);
1658 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1659 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1662 : WHILE TLPAREN expr TRPAREN
1663 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1664 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1667 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1670 : ITER_NAME { context_enterIterClause (); }
1671 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1673 compoundStmt endIter DeleteInnerScope
1675 $$ = exprNode_iter ($1, $6, $8, $9);
1680 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1681 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1682 { $$ = exprNodeList_push ($1, $4); }
1685 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1686 | id { $$ = exprNode_iterId ($1); }
1687 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1689 if (uentry_isValid (ue))
1691 $$ = exprNode_iterId (ue);
1695 $$ = exprNode_iterNewId (cstring_copy (LastIdentifier ()));
1698 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1701 ** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1706 | cconstantExpr CCONSTANT { $$ = exprNode_combineLiterals ($1, $2); }
1710 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1714 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1715 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1716 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1717 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1718 { $$ = exprNode_vaArg ($1, $3, $5); }
1719 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
1720 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
1721 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1722 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1726 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1727 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1728 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1729 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1730 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1731 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1732 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1733 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1734 | sizeofExpr { $$ = $1; }
1738 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1742 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1743 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1744 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1748 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1749 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1753 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1754 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1758 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1759 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1760 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1761 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1764 : relationalIterExpr
1765 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1766 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1770 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1774 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1779 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1783 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1787 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1791 | orExpr TQUEST { context_enterTrueClause ($1); }
1792 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1793 { $$ = exprNode_cond ($1, $4, $7); }
1796 : conditionalIterExpr
1797 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1798 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1799 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1800 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1801 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1802 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1803 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1804 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1805 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1806 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1807 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1810 : ITER_ENDNAME { $$ = $1; }
1811 | /* empty */ { $$ = uentry_undefined; }
1814 : DO { context_enterDoWhileClause (); $$ = $1; }
1818 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1819 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
1820 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1822 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1825 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1826 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1827 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
1828 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1829 { $$ = exprNode_doWhile ($2, $5); }
1830 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1833 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1834 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1835 | QINNERCONTINUE CONTINUE TSEMI
1836 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1837 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1838 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1839 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1840 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1841 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1842 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1843 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1854 | ITER_NAME { $$ = uentry_getName ($1); }
1855 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1856 | id { $$ = uentry_getName ($1); }
1857 | TYPE_NAME_OR_ID { $$ = $1; }
1861 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
1865 /*@-redecl@*/ /*@-namechecks@*/
1866 extern char *yytext;
1867 /*@=redecl@*/ /*@=namechecks@*/
1869 # include "bison.reset"
1871 void yyerror (/*@unused@*/ char *s)
1873 static bool givehint = FALSE;
1875 if (context_inIterDef ())
1877 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1878 context_inFunctionName ()));
1880 else if (context_inIterEnd ())
1882 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1883 context_inFunctionName ()));
1885 else if (context_inMacro ())
1887 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1888 context_inFunctionName ()));
1890 if (context_inUnknownMacro ())
1894 llhint (cstring_makeLiteral
1895 ("Precede macro definition with /*@notfunction@*/ "
1896 "to suppress checking and force expansion"));
1902 context_exitAllClausesQuiet ();
1906 llparseerror (cstring_undefined);