]> andersk Git - splint.git/blame - src/cgrammar.y
Fixed bug which would cause splint to crash if it was started with the -i flags and...
[splint.git] / src / cgrammar.y
CommitLineData
885824d3 1/*;-*-C-*-;
11db3170 2** Splint - annotation-assisted static program checker
1b8ae690 3** Copyright (C) 1994-2002 University of Virginia,
11db3170 4** Massachusetts Institute of Technology
5**
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.
10**
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.
15**
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.
19**
155af98d 20** For information on splint: info@splint.org
21** To report a bug: splint-bug@splint.org
11db3170 22** For more information: http://www.splint.org
885824d3 23*/
24%{
25/*
26**
27** cgrammar.y
28**
1b8ae690 29** Yacc/Bison grammar for extended ANSI C used by Splint.
885824d3 30**
31** original grammar by Nate Osgood ---
32** hacrat@catfish.lcs.mit.edu Mon Jun 14 13:06:32 1993
33**
1b8ae690 34** changes for Splint --- handle typedef names correctly
885824d3 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
39**
40** production names are cryptic, so more productions fit on one line
41**
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
45*/
46
47/*@=allmacros@*/
48
49extern int yylex ();
b37cf05e 50extern void yyerror (char *);
885824d3 51
1b8ae690 52# include "splintMacros.nf"
885824d3 53# include "basic.h"
08eb3d0e 54# include "cscanner.h"
885824d3 55# include "cgrammar.h"
56# include "exprChecks.h"
57
58/*@-allmacros@*/
59/*@-matchfields@*/
60
61# define SHOWCSYM FALSE
885824d3 62
63/*
64** This is necessary, or else when the bison-generated code #include's malloc.h,
65** there will be a parse error.
66**
67** Unfortunately, it means the error checking on malloc, etc. is lost for allocations
68** in bison-generated files under Win32.
69*/
70
71# ifdef WIN32
72# undef malloc
73# undef calloc
74# undef realloc
75# endif
76
77%}
78
79%union
80{
28bf4b0b 81 lltok tok;
82 int count;
83 qual typequal;
84 qualList tquallist;
85 ctype ctyp;
990ec868 86 /*@dependent@*/ sRef sr;
b37cf05e 87 /*@only@*/ sRef osr;
28bf4b0b 88
89 /*@only@*/ functionClauseList funcclauselist;
90 /*@only@*/ functionClause funcclause;
91 /*@only@*/ flagSpec flagspec;
92 /*@only@*/ globalsClause globsclause;
93 /*@only@*/ modifiesClause modsclause;
94 /*@only@*/ warnClause warnclause;
95 /*@only@*/ stateClause stateclause;
f9264521 96 /*@only@*/ pointers pointers;
3814599d 97 /*@only@*/ functionConstraint fcnconstraint;
98
08eb3d0e 99 /*@only@*/ metaStateConstraint msconstraint;
100 /*@only@*/ metaStateSpecifier msspec;
101 /*@only@*/ metaStateExpression msexpr;
102 /*@observer@*/ metaStateInfo msinfo;
103
28bf4b0b 104 /*@only@*/ sRefList srlist;
105 /*@only@*/ globSet globset;
106 /*@only@*/ qtype qtyp;
107 /*@only@*/ cstring cname;
108 /*@observer@*/ annotationInfo annotation;
109 /*@only@*/ idDecl ntyp;
110 /*@only@*/ idDeclList ntyplist;
111 /*@only@*/ uentryList flist;
112 /*@owned@*/ uentryList entrylist;
113 /*@observer@*/ /*@dependent@*/ uentry entry;
114 /*@only@*/ uentry oentry;
115 /*@only@*/ exprNode expr;
116 /*@only@*/ enumNameList enumnamelist;
e83c79ec 117 /*@only@*/ exprNodeList exprlist;
28bf4b0b 118 /*@only@*/ sRefSet srset;
119 /*@only@*/ cstringList cstringlist;
08eb3d0e 120
103db890 121 /*drl
122 added 1/19/2001
123 */
124 constraint con;
125 constraintList conL;
126 constraintExpr conE;
28bf4b0b 127 /* drl */
885824d3 128}
129
130/* standard C tokens */
131
132%token <tok> BADTOK SKIPTOK
133%token <tok> CTOK_ELIPSIS CASE DEFAULT CIF CELSE SWITCH WHILE DO CFOR
134%token <tok> GOTO CONTINUE BREAK RETURN
135%token <tok> TSEMI TLBRACE TRBRACE TCOMMA TCOLON TASSIGN TLPAREN
136%token <tok> TRPAREN TLSQBR TRSQBR TDOT TAMPERSAND TEXCL TTILDE
137%token <tok> TMINUS TPLUS TMULT TDIV TPERCENT TLT TGT TCIRC TBAR TQUEST
abd7f895 138%token <tok> CSIZEOF CALIGNOF CTYPEOF ARROW_OP CTYPEDEF COFFSETOF
885824d3 139%token <tok> INC_OP DEC_OP LEFT_OP RIGHT_OP
140%token <tok> LE_OP GE_OP EQ_OP NE_OP AND_OP OR_OP
141%token <tok> MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN SUB_ASSIGN
142%token <tok> LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN XOR_ASSIGN OR_ASSIGN
143%token <tok> CSTRUCT CUNION CENUM
144%token <tok> VA_ARG VA_DCL
28bf4b0b 145%token <tok> QWARN
885824d3 146%token <tok> QGLOBALS
147%token <tok> QMODIFIES
148%token <tok> QNOMODS
149%token <tok> QCONSTANT
150%token <tok> QFUNCTION
151%token <tok> QITER
152%token <tok> QDEFINES
153%token <tok> QUSES
154%token <tok> QALLOCATES
155%token <tok> QSETS
156%token <tok> QRELEASES
157%token <tok> QPRECLAUSE
86d93ed3 158%token <tok> QPOSTCLAUSE
159%token <tok> QINVARIANT
885824d3 160%token <tok> QALT
161%token <tok> QUNDEF QKILLED
162%token <tok> QENDMACRO
163
1b8ae690 164/* additional tokens introduced by splint pre-processor. */
885824d3 165%token <tok> LLMACRO LLMACROITER LLMACROEND TENDMACRO
166
167/* break comments: */
168%token <tok> QSWITCHBREAK QLOOPBREAK QINNERBREAK QSAFEBREAK
169%token <tok> QINNERCONTINUE
170
171/* case fall-through marker: */
172%token <tok> QFALLTHROUGH
173
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
180
181/* not-reached marker: (used like a label) */
182%token <tok> QNOTREACHED
183
184/* type qualifiers: */
f9264521 185%token <tok> QCONST QRESTRICT QVOLATILE QINLINE QEXTENSION QEXTERN QSTATIC QAUTO QREGISTER
885824d3 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
197
93307a76 198%token <tok> QNULLTERMINATED
11ed4f45 199%token <tok> QSETBUFFERSIZE
200%token <tok> QSETSTRINGLENGTH
93307a76 201%token <tok> QMAXSET
202%token <tok> QMAXREAD
a0a162cd 203%token <tok> QTESTINRANGE
11ed4f45 204
dcaf75ea 205%token <tok> TCAND
93307a76 206
207
885824d3 208/* identifiers, literals */
209%token <entry> IDENTIFIER
210%token <cname> NEW_IDENTIFIER TYPE_NAME_OR_ID
28bf4b0b 211%token <annotation> CANNOTATION
212%token <expr> CCONSTANT
213%type <cname> flagId
214%type <flagspec> flagSpec
215%type <expr> cconstantExpr
885824d3 216%token <entry> ITER_NAME ITER_ENDNAME
217%type <entry> endIter
28bf4b0b 218
219%type <funcclauselist> functionClauses functionClausesPlain
220%type <funcclause> functionClause functionClause functionClausePlain
221
222%type <globsclause> globalsClause globalsClausePlain
223%type <modsclause> modifiesClause modifiesClausePlain nomodsClause
e83c79ec 224%type <warnclause> warnClause warnClausePlain optWarnClause
d9a28762 225%type <funcclause> conditionClause conditionClausePlain
28bf4b0b 226%type <stateclause> stateClause stateClausePlain
08eb3d0e 227%type <msconstraint> metaStateConstraint
3814599d 228%type <fcnconstraint> functionConstraint
08eb3d0e 229%type <msspec> metaStateSpecifier
230%type <msexpr> metaStateExpression
28bf4b0b 231
232%type <sr> globId globIdListExpr
233%type <globset> globIdList
234
885824d3 235%token <ctyp> TYPE_NAME
08eb3d0e 236%token <msinfo> METASTATE_NAME
237%type <msinfo> metaStateName
885824d3 238%type <cname> enumerator newId /*@-varuse@*/ /* yacc declares yytranslate here */
f9264521 239%type <pointers> pointers /*@=varuse@*/
885824d3 240
d9a28762 241%type <tok> doHeader stateTag conditionTag startConditionClause
28bf4b0b 242%type <typequal> exitsQualifier checkQualifier stateQualifier
243 paramQualifier returnQualifier visibilityQualifier
244 typedefQualifier refcountQualifier definedQualifier
885824d3 245
246/* type construction */
247%type <ctyp> abstractDecl abstractDeclBase optAbstractDeclBase
248%type <ctyp> suSpc enumSpc typeName typeSpecifier
249
250%type <ntyp> namedDecl namedDeclBase optNamedDecl
251%type <ntyp> plainNamedDecl plainNamedDeclBase
252%type <ntyp> structNamedDecl
253%type <ntyp> fcnDefHdrAux plainFcn
254
255%type <oentry> paramDecl
256%type <entry> id
257
258%type <ntyplist> structNamedDeclList
259
260%type <entrylist> genericParamList paramTypeList paramList idList paramIdList
e83c79ec 261%type <exprlist> argumentExprList iterArgList
262%type <exprlist> initList namedInitializerList namedInitializerListAux
885824d3 263%type <flist> structDeclList structDecl
28bf4b0b 264%type <srset> locModifies modList specClauseList optSpecClauseList
885824d3 265%type <sr> mExpr modListExpr specClauseListExpr
93307a76 266
267/*drl*/
08eb3d0e 268%type <con> BufConstraint
93307a76 269%type <tok> relationalOp
270%type <tok> BufBinaryOp
271%type <tok> bufferModifier
272
103db890 273%type <conE> BufConstraintExpr
93307a76 274
103db890 275%type <conE> BufConstraintTerm
276%type <sr> BufConstraintSrefExpr
93307a76 277
3814599d 278%type <conL> BufConstraintList
93307a76 279
86d93ed3 280%type <conL> optStructInvariant
281
93307a76 282%type <tok> BufUnaryOp
283
86d93ed3 284/*drl 1/6/2002 either /\ or && */
285%type <tok> constraintSeperator
286
885824d3 287%type <enumnamelist> enumeratorList
288%type <cstringlist> fieldDesignator
289
290%type <expr> sizeofExpr sizeofExprAux offsetofExpr
291%type <expr> openScope closeScope
292%type <expr> instanceDecl namedInitializer optDeclarators
293%type <expr> primaryExpr postfixExpr primaryIterExpr postfixIterExpr
294%type <expr> unaryExpr castExpr timesExpr plusExpr
295%type <expr> unaryIterExpr castIterExpr timesIterExpr plusIterExpr
296%type <expr> shiftExpr relationalExpr equalityExpr bitandExpr
297%type <expr> xorExpr bitorExpr andExpr
298%type <expr> orExpr conditionalExpr assignExpr
299%type <expr> shiftIterExpr relationalIterExpr equalityIterExpr bitandIterExpr
300%type <expr> xorIterExpr bitorIterExpr andIterExpr
301%type <expr> orIterExpr conditionalIterExpr assignIterExpr iterArgExpr
302%type <expr> expr optExpr constantExpr
303%type <expr> init macroBody iterBody endBody partialIterStmt iterSelectionStmt
304%type <expr> stmt stmtList fcnBody iterStmt iterDefStmt iterDefStmtList
305%type <expr> labeledStmt caseStmt defaultStmt
306%type <expr> compoundStmt compoundStmtAux compoundStmtRest compoundStmtAuxErr
307%type <expr> expressionStmt selectionStmt iterationStmt jumpStmt iterDefIterationStmt
308%type <expr> stmtErr stmtListErr compoundStmtErr expressionStmtErr
abd7f895 309%type <expr> iterationStmtErr initializerList typeInitializerList initializer
310%type <expr> ifPred whilePred forPred iterWhilePred typeInitializer
885824d3 311
1214340e 312%type <expr> designator designatorList designation
313
f9264521 314%type <typequal> storageSpecifier typeQualifier typeModifier globQual innerMods
315%type <tquallist> optGlobQuals innerModsList
885824d3 316%type <qtyp> completeType completeTypeSpecifier optCompleteType
317%type <qtyp> completeTypeSpecifierAux altType typeExpression
318
319%start file
320
321%%
322
323file
324 :
325 | externalDefs
326
327externalDefs
b7e84605 328 : externalDef { context_checkGlobalScope (); }
329 | externalDefs externalDef { context_checkGlobalScope (); }
885824d3 330
331externalDef
332 : fcnDef optSemi { uentry_clearDecl (); }
333 | constantDecl { uentry_clearDecl (); }
334 | fcnDecl { uentry_clearDecl (); }
335 | iterDecl { uentry_clearDecl (); }
336 | macroDef { uentry_clearDecl (); }
337 | initializer { uentry_checkDecl (); exprNode_free ($1); }
6fcd0b1e 338 | TSEMI { uentry_clearDecl (); lltok_free ($1); /* evans 2002-02-08: okay to have a null statement */ }
885824d3 339 | error { uentry_clearDecl (); }
340
341constantDecl
342 : QCONSTANT completeTypeSpecifier NotType namedDecl NotType optSemi IsType QENDMACRO
6fcd0b1e 343 { checkConstant ($2, $4); lltok_free2 ($1, $8); }
885824d3 344 | QCONSTANT completeTypeSpecifier NotType namedDecl NotType TASSIGN IsType init optDeclarators optSemi QENDMACRO
6fcd0b1e 345 { checkValueConstant ($2, $4, $8); lltok_free3 ($1, $6, $11); }
885824d3 346
347fcnDecl
28bf4b0b 348 : QFUNCTION { context_enterFunctionHeader (); } plainFcn optSemi QENDMACRO
349 {
350 declareStaticFunction ($3); context_quietExitFunction ();
351 context_exitFunctionHeader ();
6fcd0b1e 352 lltok_free2 ($1, $5); /*!*/
28bf4b0b 353 }
885824d3 354
355plainFcn
356 : plainNamedDecl
357 {
358 qtype qint = qtype_create (ctype_int);
359 $$ = idDecl_fixBase ($1, qint);
360 qtype_free (qint);
361 }
362 | completeTypeSpecifier NotType plainNamedDecl
363 { $$ = idDecl_fixBase ($3, $1); }
364
365plainNamedDecl
366 : plainNamedDeclBase
367 | pointers plainNamedDeclBase
368 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
369
370namedDeclBase
371 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
372 | IsType TLPAREN NotType namedDecl IsType TRPAREN
6fcd0b1e 373 { $$ = idDecl_expectFunction ($4); lltok_free2 ($2, $6); }
885824d3 374 | namedDeclBase TLSQBR TRSQBR
6fcd0b1e 375 { $$ = idDecl_replaceCtype ($1, ctype_makeInnerArray (idDecl_getCtype ($1))); lltok_free2 ($2, $3); }
885824d3 376 | namedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
e5f31c00 377 {
e8b84478 378 exprNode_findValue ($4);
379 idDecl_notExpectingFunction ($1);
380
7534721d 381 if (exprNode_hasValue ($4))
382 {
077d4458 383 $$ = idDecl_replaceCtype ($1, ctype_makeInnerFixedArray (idDecl_getCtype ($1),
384 exprNode_getLongValue ($4)));
7534721d 385 }
386 else
387 {
393e573f 388 $$ = idDecl_replaceCtype ($1, ctype_makeInnerArray (idDecl_getCtype ($1)));
7534721d 389 }
6fcd0b1e 390
391 lltok_free2 ($2, $5);
885824d3 392 }
393 | namedDeclBase PushType TLPAREN TRPAREN
28bf4b0b 394 { setCurrentParams (uentryList_missingParams); }
395 functionClauses
885824d3 396 { /* need to support globals and modifies here! */
397 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
398 uentryList_makeMissingParams ());
28bf4b0b 399
885824d3 400 $$ = idDecl_replaceCtype ($1, ct);
28bf4b0b 401 idDecl_addClauses ($$, $6);
d30bc0c7 402 context_popLoc ();
403 /*drl 7/25/01 added*/
404 setImplictfcnConstraints();
6fcd0b1e 405 lltok_free2 ($3, $4);
885824d3 406 }
407 | namedDeclBase PushType TLPAREN genericParamList TRPAREN
28bf4b0b 408 { setCurrentParams ($4); }
409 functionClauses
470b7798 410 { setImplictfcnConstraints ();
411 clearCurrentParams ();
885824d3 412 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
28bf4b0b 413 idDecl_addClauses ($$, $7);
4ab867d6 414 context_popLoc ();
6fcd0b1e 415 lltok_free2 ($3, $5);
885824d3 416 }
417
418plainNamedDeclBase
419 : newId { $$ = idDecl_create ($1, qtype_unknown ()); }
420 | IsType TLPAREN NotType plainNamedDecl IsType TRPAREN
6fcd0b1e 421 { $$ = idDecl_expectFunction ($4); lltok_free2 ($2, $6); }
885824d3 422 | plainNamedDeclBase TLSQBR TRSQBR
6fcd0b1e 423 { $$ = idDecl_replaceCtype ($1, ctype_makeInnerArray (idDecl_getCtype ($1)));
424 lltok_free2 ($2, $3);
425 }
885824d3 426 | plainNamedDeclBase TLSQBR IsType constantExpr TRSQBR NotType
427 {
428 int value;
429
430 if (exprNode_hasValue ($4)
431 && multiVal_isInt (exprNode_getValue ($4)))
432 {
433 value = (int) multiVal_forceInt (exprNode_getValue ($4));
434 }
435 else
436 {
437 value = 0;
438 }
439
393e573f 440 $$ = idDecl_replaceCtype ($1, ctype_makeInnerFixedArray (idDecl_getCtype ($1), value));
6fcd0b1e 441 lltok_free2 ($2, $5);
885824d3 442 }
443 | plainNamedDeclBase PushType TLPAREN TRPAREN
28bf4b0b 444 { setCurrentParams (uentryList_missingParams); }
445 functionClausesPlain
446 {
885824d3 447 ctype ct = ctype_makeFunction (idDecl_getCtype ($1),
448 uentryList_makeMissingParams ());
28bf4b0b 449
885824d3 450 $$ = idDecl_replaceCtype ($1, ct);
28bf4b0b 451 idDecl_addClauses ($$, $6);
885824d3 452 context_popLoc ();
6fcd0b1e 453 lltok_free2 ($3, $4);
885824d3 454 }
455 | plainNamedDeclBase PushType TLPAREN genericParamList TRPAREN
28bf4b0b 456 { setCurrentParams ($4); }
457 functionClausesPlain
458 {
459 clearCurrentParams ();
885824d3 460 $$ = idDecl_replaceCtype ($1, ctype_makeFunction (idDecl_getCtype ($1), $4));
28bf4b0b 461 idDecl_addClauses ($$, $7);
885824d3 462 context_popLoc ();
6fcd0b1e 463 lltok_free ($3);
464 /*!! lltok_free2 ($3, $5); */
885824d3 465 }
466
467iterDecl
468 : QITER newId TLPAREN genericParamList TRPAREN
28bf4b0b 469 { setCurrentParams ($4); } functionClausesPlain
885824d3 470 { clearCurrentParams (); } optSemi QENDMACRO
6fcd0b1e 471 { declareCIter ($2, $4);
472 lltok_free3 ($1, $3, $5);
473 }
885824d3 474
475macroDef
6fcd0b1e 476 : LLMACRO macroBody TENDMACRO { exprNode_checkMacroBody ($2); lltok_free2 ($1, $3); }
477 | LLMACROITER iterBody TENDMACRO { exprNode_checkIterBody ($2); lltok_free2 ($1, $3); }
478 | LLMACROEND endBody TENDMACRO { exprNode_checkIterEnd ($2); lltok_free2 ($1, $3);}
479 | LLMACRO TENDMACRO /* no stmt */ { exprChecks_checkEmptyMacroBody (); lltok_free2 ($1, $2); }
885824d3 480
481fcnDefHdr
08eb3d0e 482 : fcnDefHdrAux { clabstract_declareFunction ($1); }
483
484metaStateConstraint
485 : metaStateSpecifier TASSIGN metaStateExpression
6fcd0b1e 486 { $$ = metaStateConstraint_create ($1, $3); lltok_free ($2); }
08eb3d0e 487
488metaStateSpecifier
3814599d 489 : BufConstraintSrefExpr { cscanner_expectingMetaStateName (); } TCOLON metaStateName
6970c11b 490 { cscanner_clearExpectingMetaStateName ();
6fcd0b1e 491 $$ = metaStateSpecifier_create ($1, $4);
492 lltok_free ($3);
493 }
6970c11b 494 | CTOK_ELIPSIS { cscanner_expectingMetaStateName (); } TCOLON metaStateName
495 { cscanner_clearExpectingMetaStateName ();
6fcd0b1e 496 $$ = metaStateSpecifier_createElipsis ($4);
497 lltok_free2 ($1, $3);
498 }
08eb3d0e 499
500metaStateExpression
501: metaStateSpecifier { $$ = metaStateExpression_create ($1); }
6fcd0b1e 502| metaStateSpecifier TBAR metaStateExpression { $$ = metaStateExpression_createMerge ($1, $3); lltok_free ($2); }
08eb3d0e 503
504metaStateName
505: METASTATE_NAME
93307a76 506
507/*drl*/
508
86d93ed3 509constraintSeperator
510: TCAND
511| AND_OP
512
93307a76 513BufConstraintList
86d93ed3 514: BufConstraint constraintSeperator BufConstraintList { $$ = constraintList_add ($3, $1); }
3814599d 515| BufConstraint { $$ = constraintList_single ($1); }
93307a76 516
517BufConstraint
dcaf75ea 518: BufConstraintExpr relationalOp BufConstraintExpr {
93307a76 519 $$ = makeConstraintParse3 ($1, $2, $3);
ef2aa32a 520 DPRINTF(("Done BufConstraint1\n")); }
93307a76 521
522bufferModifier
523 : QMAXSET
d9a28762 524 | QMAXREAD
93307a76 525
526relationalOp
527 : GE_OP
528 | LE_OP
529 | EQ_OP
530
531BufConstraintExpr
532 : BufConstraintTerm
34f0c5e7 533 | BufUnaryOp TLPAREN BufConstraintExpr TRPAREN {$$ = constraintExpr_parseMakeUnaryOp ($1, $3); DPRINTF( ("Got BufConstraintExpr UNary Op ") ); }
93307a76 534 | TLPAREN BufConstraintExpr BufBinaryOp BufConstraintExpr TRPAREN {
34f0c5e7 535 DPRINTF( ("Got BufConstraintExpr BINary Op ") );
93307a76 536 $$ = constraintExpr_parseMakeBinaryOp ($2, $3, $4); }
537
538BufConstraintTerm
b9904f57 539 : BufConstraintSrefExpr { $$ = constraintExpr_makeTermsRef ($1);}
540 | CCONSTANT { $$ = constraintExpr_makeIntLiteral (exprNode_getLongValue ($1)); }
103db890 541
542BufConstraintSrefExpr
08eb3d0e 543: id
544 { /*@-onlytrans@*/ $$ = checkbufferConstraintClausesId ($1); /*@=onlytrans@*/ /*@i523@*/ }
545| NEW_IDENTIFIER
546 { $$ = fixStateClausesId ($1); }
547| BufConstraintSrefExpr TLSQBR TRSQBR
548 { $$ = sRef_makeAnyArrayFetch ($1); }
549| BufConstraintSrefExpr TLSQBR CCONSTANT TRSQBR
550 {
551 /*
552 char *t; int c;
553 t = cstring_toCharsSafe (exprNode_unparse($3));
554 c = atoi( t );
555 */
556 $$ = sRef_makeArrayFetchKnown ($1, exprNode_getLongValue ($3));
557 }
558| TMULT BufConstraintSrefExpr
559 { $$ = sRef_constructPointer ($2); }
560| TLPAREN BufConstraintSrefExpr TRPAREN
561 { $$ = $2; }
562| BufConstraintSrefExpr TDOT newId
563 { cstring_markOwned ($3); $$ = sRef_buildField ($1, $3); }
564| BufConstraintSrefExpr ARROW_OP newId
565 { cstring_markOwned ($3); $$ = sRef_makeArrow ($1, $3); }
103db890 566
567/*
568| BufConstraintTerm TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
569 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
570 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
571 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
572 $$ = sRef_buildField ($1, $3); }
573*/
574
93307a76 575/*BufConstraintExpr
576: BufConstraintTerm
577*/
578
579BufUnaryOp
580: bufferModifier
581;
582
583BufBinaryOp
584 : TPLUS
585| TMINUS
586;
28bf4b0b 587/*
588** Function clauses can appear in any order.
589*/
93307a76 590
28bf4b0b 591functionClauses
592 : { $$ = functionClauseList_new (); }
593 | functionClause functionClauses
594 { $$ = functionClauseList_prepend ($2, $1); }
93307a76 595
28bf4b0b 596/*
597** Inside macro definitions, there are no end macros.
598*/
93307a76 599
28bf4b0b 600functionClausesPlain
601 :
602 { $$ = functionClauseList_new (); }
603 | functionClausePlain functionClausesPlain
604 { $$ = functionClauseList_prepend ($2, $1); }
605
606functionClause
607 : globalsClause { $$ = functionClause_createGlobals ($1); }
608 | modifiesClause { $$ = functionClause_createModifies ($1); }
609 | nomodsClause { $$ = functionClause_createModifies ($1); }
610 | stateClause { $$ = functionClause_createState ($1); }
d9a28762 611 | conditionClause { $$ = $1; }
28bf4b0b 612 | warnClause { $$ = functionClause_createWarn ($1); }
613
614functionClausePlain
615 : globalsClausePlain { $$ = functionClause_createGlobals ($1); }
616 | modifiesClausePlain { $$ = functionClause_createModifies ($1); }
617 | nomodsClause { $$ = functionClause_createModifies ($1); }
618 | stateClausePlain { $$ = functionClause_createState ($1); }
d9a28762 619 | conditionClausePlain { $$ = $1; }
28bf4b0b 620 | warnClausePlain { $$ = functionClause_createWarn ($1); }
621
622globalsClause
623 : globalsClausePlain QENDMACRO { $$ = $1; }
624
625globalsClausePlain
626 : QGLOBALS { setProcessingGlobalsList (); }
627 globIdList optSemi
628 {
629 unsetProcessingGlobals ();
630 $$ = globalsClause_create ($1, $3);
631 }
93307a76 632
28bf4b0b 633nomodsClause
634 : QNOMODS { $$ = modifiesClause_createNoMods ($1); }
93307a76 635
28bf4b0b 636modifiesClause
637 : modifiesClausePlain QENDMACRO { $$ = $1; }
38496f11 638
28bf4b0b 639modifiesClausePlain
640 : QMODIFIES
641 {
642 context_setProtectVars (); enterParamsTemp ();
643 sRef_setGlobalScopeSafe ();
644 }
645 locModifies
646 {
647 exitParamsTemp ();
648 sRef_clearGlobalScopeSafe ();
649 context_releaseVars ();
650 $$ = modifiesClause_create ($1, $3);
651 }
93307a76 652
28bf4b0b 653flagSpec
654 : flagId
655 { $$ = flagSpec_createPlain ($1); }
656 | flagId TBAR flagSpec
657 { $$ = flagSpec_createOr ($1, $3); }
885824d3 658
28bf4b0b 659flagId
660 : NEW_IDENTIFIER
885824d3 661
e83c79ec 662optWarnClause
663 : warnClause
664 | /* empty */ { $$ = warnClause_undefined; }
665
28bf4b0b 666warnClause
667 : warnClausePlain QENDMACRO { $$ = $1; }
668
669warnClausePlain
670 : QWARN flagSpec cconstantExpr
6970c11b 671 {
672 llassert (exprNode_knownStringValue ($3));
673 $$ = warnClause_create ($1, $2, cstring_copy (multiVal_forceString (exprNode_getValue ($3))));
674 exprNode_free ($3);
675 }
28bf4b0b 676 | QWARN flagSpec
6970c11b 677 { $$ = warnClause_create ($1, $2, cstring_undefined); }
885824d3 678
885824d3 679globIdList
28bf4b0b 680 : globIdListExpr { $$ = globSet_single ($1); }
681 | globIdList TCOMMA globIdListExpr { $$ = globSet_insert ($1, $3); }
885824d3 682
683globIdListExpr
28bf4b0b 684 : optGlobQuals globId { $$ = clabstract_createGlobal ($2, $1); }
685
686optGlobQuals
687 : /* empty */ { $$ = qualList_undefined; }
688 | globQual optGlobQuals { $$ = qualList_add ($2, $1); }
885824d3 689
690globId
691 : id { $$ = uentry_getSref ($1); }
28bf4b0b 692 | NEW_IDENTIFIER { $$ = clabstract_unrecognizedGlobal ($1); }
693 | initializer { $$ = clabstract_checkGlobal ($1); }
885824d3 694
695globQual
696 : QUNDEF { $$ = qual_createUndef (); }
697 | QKILLED { $$ = qual_createKilled (); }
698 | QOUT { $$ = qual_createOut (); }
699 | QIN { $$ = qual_createIn (); }
700 | QPARTIAL { $$ = qual_createPartial (); }
701
28bf4b0b 702stateTag
885824d3 703 : QDEFINES
704 | QUSES
705 | QALLOCATES
706 | QSETS
707 | QRELEASES
708
28bf4b0b 709conditionTag
885824d3 710 : QPRECLAUSE
711 | QPOSTCLAUSE
712
885824d3 713fcnDefHdrAux
714 : namedDecl
715 {
01a8227e 716 /**!!! deal with fred; fred (int); declarations! **/
717 qtype qint = qtype_create (ctype_int);
885824d3 718 $$ = idDecl_fixBase ($1, qint);
719 qtype_free (qint);
720 }
721 | completeTypeSpecifier NotType namedDecl
722 { $$ = idDecl_fixBase ($3, $1); }
723
724fcnBody
725 : TLBRACE { checkDoneParams (); context_enterInnerContext (); }
726 compoundStmtRest
727 {
728 exprNode_checkFunctionBody ($3); $$ = $3;
729 context_exitInner ($3);
730 }
7ebcc5bb 731 | { context_enterOldStyleScope (); } initializerList
732 { oldStyleDoneParams (); context_enterInnerContext (); }
885824d3 733 compoundStmt
734 {
7ebcc5bb 735 exprNode_checkFunctionBody ($4);
736 $$ = $4; /* oldstyle */
737 context_exitInner ($4);
885824d3 738 }
739
740fcnDef
741 : fcnDefHdr fcnBody
742 {
743 context_setFunctionDefined (exprNode_loc ($2));
dfd82dce 744 exprNode_checkFunction (context_getHeader (), $2);
4cccc6ad 745 /* DRL 8 8 2000 */
746
885824d3 747 context_exitFunction ();
748 }
749
750locModifies
885824d3 751 : modList optSemi { $$ = $1; }
752 | optSemi { $$ = sRefSet_new (); }
753
754modListExpr
755 : id { $$ = uentry_getSref ($1); checkModifiesId ($1); }
756 | NEW_IDENTIFIER { $$ = fixModifiesId ($1); }
757 | modListExpr TLSQBR TRSQBR { $$ = modListArrayFetch ($1, sRef_undefined); }
758 | modListExpr TLSQBR mExpr TRSQBR { $$ = modListArrayFetch ($1, $3); }
759 | TMULT modListExpr { $$ = modListPointer ($2); }
760 | TLPAREN modListExpr TRPAREN { $$ = $2; }
761 | modListExpr TDOT newId { $$ = modListFieldAccess ($1, $3); }
762 | modListExpr ARROW_OP newId { $$ = modListArrowAccess ($1, $3); }
763
764
765mExpr
28bf4b0b 766 : modListExpr { $$ = $1; }
767 | cconstantExpr { $$ = sRef_makeUnknown (); /* sRef_makeConstant ($1); ? */ }
885824d3 768 /* arithmetic? */
769
770modList
771 : modListExpr { $$ = sRefSet_single ($1); }
772 | modList TCOMMA modListExpr { $$ = sRefSet_insert ($1, $3); }
773
774specClauseListExpr
775 : id
28bf4b0b 776 { $$ = checkStateClausesId ($1); }
885824d3 777 | NEW_IDENTIFIER
28bf4b0b 778 { $$ = fixStateClausesId ($1); }
885824d3 779 | specClauseListExpr TLSQBR TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
780 | specClauseListExpr TLSQBR mExpr TRSQBR { $$ = sRef_makeAnyArrayFetch ($1); }
781 | TMULT specClauseListExpr { $$ = sRef_constructPointer ($2); }
782 | TLPAREN specClauseListExpr TRPAREN { $$ = $2; }
783 | specClauseListExpr TDOT newId { cstring_markOwned ($3);
784 $$ = sRef_buildField ($1, $3); }
785 | specClauseListExpr ARROW_OP newId { cstring_markOwned ($3);
786 $$ = sRef_makeArrow ($1, $3); }
787
28bf4b0b 788optSpecClauseList
789 : /* empty */ { $$ = sRefSet_undefined }
790 | specClauseList
791
885824d3 792specClauseList
793 : specClauseListExpr
794 { if (sRef_isValid ($1)) { $$ = sRefSet_single ($1); }
795 else { $$ = sRefSet_undefined; }
796 }
797 | specClauseList TCOMMA specClauseListExpr
798 { if (sRef_isValid ($3))
799 {
800 $$ = sRefSet_insert ($1, $3);
801 }
802 else
803 {
804 $$ = $1;
805 }
806 }
807
808primaryExpr
809 : id { $$ = exprNode_fromIdentifier ($1); }
810 | NEW_IDENTIFIER { $$ = exprNode_fromUIO ($1); }
28bf4b0b 811 | cconstantExpr
885824d3 812 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
813 | TYPE_NAME_OR_ID { $$ = exprNode_fromIdentifier (coerceId ($1)); }
814 | QEXTENSION { $$ = exprNode_makeError (); }
abd7f895 815 | TLPAREN { exprChecks_inCompoundStatementExpression (); }
816 compoundStmt TRPAREN
817 { exprChecks_leaveCompoundStatementExpression (); $$ = exprNode_compoundStatementExpression ($1, $3); }
885824d3 818
819postfixExpr
820 : primaryExpr
821 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
822 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
823 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
824 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN { $$ = exprNode_vaArg ($1, $3, $5); }
28bf4b0b 825 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
826 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
885824d3 827 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
828 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
abd7f895 829 | TLPAREN typeExpression TRPAREN TLBRACE typeInitializerList optComma TRBRACE
830 { /* added for C99 */ $$ = exprNode_undefined; /*@i87 no checking */ }
831
885824d3 832argumentExprList
833 : assignExpr { $$ = exprNodeList_singleton ($1); }
834 | argumentExprList TCOMMA assignExpr { $$ = exprNodeList_push ($1, $3); }
835
836unaryExpr
837 : postfixExpr
838 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
839 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
840 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
841 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
842 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
843 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
844 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
845 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
846 | sizeofExpr { $$ = $1; }
847 | offsetofExpr { $$ = $1; }
848
849fieldDesignator
6fcd0b1e 850 : fieldDesignator TDOT newId { $$ = cstringList_add ($1, $3); lltok_free ($2); }
851 | fieldDesignator TLSQBR expr TRSQBR { $$ = $1; lltok_free2 ($2, $4); }
ce7034f0 852 /* evans 2002-07-02: offsetof designators can use array indexes */
853 | newId { $$ = cstringList_single ($1); }
885824d3 854
855offsetofExpr
856 : COFFSETOF IsType TLPAREN typeExpression NotType TCOMMA fieldDesignator TRPAREN IsType
6fcd0b1e 857 { $$ = exprNode_offsetof ($4, $7);
858 lltok_free3 ($1, $3, $6); lltok_free ($8); }
885824d3 859
860sizeofExpr
861 : IsType { context_setProtectVars (); }
862 sizeofExprAux { context_sizeofReleaseVars (); $$ = $3; }
863
864sizeofExprAux
6fcd0b1e 865 : CSIZEOF TLPAREN typeExpression TRPAREN { $$ = exprNode_sizeofType ($3); lltok_free3 ($1, $2, $4); }
866 | CSIZEOF unaryExpr { $$ = exprNode_sizeofExpr ($2); lltok_free ($1); }
867 | CALIGNOF TLPAREN typeExpression TRPAREN { $$ = exprNode_alignofType ($3); lltok_free3 ($1, $2, $4); }
868 | CALIGNOF unaryExpr { $$ = exprNode_alignofExpr ($2); lltok_free ($1); }
885824d3 869
870castExpr
871 : unaryExpr
872 | TLPAREN typeExpression TRPAREN castExpr
6fcd0b1e 873 { $$ = exprNode_cast ($1, $4, $2); lltok_free ($3); }
885824d3 874
875timesExpr
876 : castExpr
877 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
878 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
879 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
880
881plusExpr
882 : timesExpr
883 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
884 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
885
886shiftExpr
887 : plusExpr
888 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
889 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
890
891relationalExpr
892 : shiftExpr
893 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
894 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
895 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
896 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
897
898equalityExpr
899 : relationalExpr
900 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
901 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
902
903bitandExpr
904 : equalityExpr
905 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
906
907xorExpr
908 : bitandExpr
909 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
910;
911
912bitorExpr
913 : xorExpr
914 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
915
916andExpr
917 : bitorExpr
918 | andExpr AND_OP
919 { exprNode_produceGuards ($1);
920 context_enterAndClause ($1);
921 }
922 bitorExpr
923 {
924 $$ = exprNode_op ($1, $4, $2);
925 context_exitAndClause ($$, $4);
926 }
927
928orExpr
929 : andExpr
930 | orExpr OR_OP
931 {
932 exprNode_produceGuards ($1);
933 context_enterOrClause ($1);
934 }
935 andExpr
936 {
937 $$ = exprNode_op ($1, $4, $2);
938 context_exitOrClause ($$, $4);
939 }
940
941conditionalExpr
942 : orExpr
943 | orExpr TQUEST { exprNode_produceGuards ($1); context_enterTrueClause ($1); } expr TCOLON
944 { context_enterFalseClause ($1); } conditionalExpr
945 { $$ = exprNode_cond ($1, $4, $7); context_exitClause ($1, $4, $7); }
946
947assignExpr
948 : conditionalExpr
949 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
950 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
951 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
952 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
953 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
954 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
955 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
956 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
957 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
958 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
959 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
960
961expr
962 : assignExpr
963 | expr TCOMMA assignExpr { $$ = exprNode_comma ($1, $3); }
964
965optExpr
966 : /* empty */ { $$ = exprNode_undefined; }
967 | expr
968
969constantExpr
970 : conditionalExpr
971
972/* instance_orTypeDecl_and_possible_initialization */
973
974initializer
975 : instanceDecl { $$ = $1; }
976 | VA_DCL { doVaDcl (); $$ = exprNode_makeError (); }
977 | typeDecl { $$ = exprNode_makeError (); }
978
979instanceDecl
28bf4b0b 980 : completeTypeSpecifier IsType TSEMI
f9264521 981 { $$ = exprNode_makeError (); }
982 /*
885824d3 983 ** This causes r/r conflicts with function definitions.
984 ** Instead we need to snarf one first. (gack)
985 **
986 ** | completeTypeSpecifier { setProcessingVars ($1); }
987 ** NotType
988 ** namedInitializerList IsType TSEMI
989 ** { unsetProcessingVars (); }
990 **;
991 **
992 ** the solution is pretty ugly:
993 */
994 | completeTypeSpecifier NotType namedDecl NotType
995 {
28bf4b0b 996 setProcessingVars ($1);
997 processNamedDecl ($3);
998 }
999 IsType optDeclarators TSEMI IsType
1000 {
1001 unsetProcessingVars ();
1002 $$ = exprNode_makeEmptyInitialization ($3);
1003 DPRINTF (("Empty initialization: %s", exprNode_unparse ($$)));
1004 }
885824d3 1005 | completeTypeSpecifier NotType namedDecl NotType TASSIGN
28bf4b0b 1006 { setProcessingVars ($1); processNamedDecl ($3); }
885824d3 1007 IsType init optDeclarators TSEMI IsType
1008 { $$ = exprNode_concat ($9, exprNode_makeInitialization ($3, $8));
1009 unsetProcessingVars ();
1010 }
28bf4b0b 1011
885824d3 1012namedInitializer
28bf4b0b 1013 : namedDecl NotType
1014 {
1015 processNamedDecl ($1);
1016 $$ = exprNode_makeEmptyInitialization ($1);
1017 }
885824d3 1018 | namedDecl NotType TASSIGN { processNamedDecl ($1); } IsType init
1019 { $$ = exprNode_makeInitialization ($1, $6); }
1020
885824d3 1021typeDecl
1022 : CTYPEDEF completeTypeSpecifier { setProcessingTypedef ($2); }
e83c79ec 1023 NotType namedInitializerList IsType optWarnClause TSEMI
1024 { clabstract_declareType ($5, $7); }
885824d3 1025 | CTYPEDEF completeTypeSpecifier IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
1026 | CTYPEDEF namedInitializerList IsType TSEMI { /* in the ANSI grammar, semantics unclear */ }
1027
1028IsType
1029 : { g_expectingTypeName = TRUE; }
1030
1031PushType
1032 : { g_expectingTypeName = TRUE; context_pushLoc (); }
1033
1034namedInitializerList
e83c79ec 1035 : namedInitializerListAux IsType { $$ = $1; }
885824d3 1036
1037namedInitializerListAux
e83c79ec 1038 : namedInitializer { $$ = exprNodeList_singleton ($1); }
1039 | namedInitializerList TCOMMA NotType namedInitializer { $$ = exprNodeList_push ($1, $4); }
885824d3 1040
1041optDeclarators
1042 : /* empty */ { $$ = exprNode_makeError (); }
1043 | optDeclarators TCOMMA NotType namedInitializer { $$ = exprNode_concat ($1, $4); }
1044
1045init
28bf4b0b 1046 : assignExpr
6fcd0b1e 1047 | TLBRACE initList TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); lltok_free ($3); }
1048 | TLBRACE initList TCOMMA TRBRACE { $$ = exprNode_makeInitBlock ($1, $2); lltok_free2 ($3, $4); }
1214340e 1049 | designation init { $$ = exprNode_undefined; }
1050
1051/*
1052** Splint parses these (added in ISO C99), but no checking yet...
1053*/
1054
1055designation
1056 : designatorList TASSIGN { $$ = $1; }
1057 | newId TCOLON { $$ = exprNode_undefined;
1058 /* gcc extension, obsolete since 2.5 */ }
1059
1060designatorList
1061 : designator { $$ = exprNode_undefined; }
1062 | designatorList designator { $$ = exprNode_undefined; }
885824d3 1063
1214340e 1064designator
1065 : TLSQBR constantExpr TRSQBR { $$ = exprNode_undefined; }
1066 | TDOT newId { $$ = exprNode_undefined; }
885824d3 1067
1068initList
1069 : init
1070 { $$ = exprNodeList_singleton ($1); }
1071 | initList TCOMMA init
1072 { $$ = exprNodeList_push ($1, $3); }
1073
1074/*
1075** need to do the storage class global hack so tags are
1076** declared with the right storage class.
1077*/
1078
1079storageSpecifier
1080 : QEXTERN { setStorageClass (SCEXTERN); $$ = qual_createExtern (); }
1081 | QINLINE { $$ = qual_createInline (); }
1082 | QSTATIC { setStorageClass (SCSTATIC); $$ = qual_createStatic (); }
1083 | QAUTO { $$ = qual_createAuto (); }
1084 | QREGISTER { $$ = qual_createRegister (); }
1085
28bf4b0b 1086stateClause
1087 : stateClausePlain QENDMACRO { $$ = $1; }
1088
1089stateClausePlain
1090 : stateTag NotType
1091 {
1092 context_setProtectVars ();
1093 enterParamsTemp ();
1094 sRef_setGlobalScopeSafe ();
1095 }
1096 specClauseList optSemi IsType
1097 {
1098 exitParamsTemp ();
1099 sRef_clearGlobalScopeSafe ();
1100 context_releaseVars ();
1101 $$ = stateClause_createPlain ($1, $4);
1102 }
1103
1104conditionClause
1105 : conditionClausePlain QENDMACRO { $$ = $1; }
1106
d9a28762 1107startConditionClause
1108: conditionTag NotType { $$ = $1; context_enterFunctionHeader (); }
1109
28bf4b0b 1110conditionClausePlain
d9a28762 1111 : startConditionClause stateQualifier
28bf4b0b 1112 {
1113 context_exitFunctionHeader ();
1114 context_setProtectVars ();
1115 enterParamsTemp ();
1116 sRef_setGlobalScopeSafe ();
1117 }
1118 optSpecClauseList optSemi IsType
1119 {
1120 exitParamsTemp ();
1121 sRef_clearGlobalScopeSafe ();
1122 context_releaseVars ();
d9a28762 1123 $$ = functionClause_createState (stateClause_create ($1, $2, $4));
1124 }
1125 | startConditionClause
1126 {
1127 context_setProtectVars ();
1128 enterParamsTemp ();
1129 sRef_setGlobalScopeSafe ();
1130 }
3814599d 1131 functionConstraint optSemi IsType
d9a28762 1132 {
1133 context_exitFunctionHeader ();
1134 exitParamsTemp ();
1135 sRef_clearGlobalScopeSafe ();
1136 context_releaseVars ();
1137 DPRINTF (("done optGlobBufConstraintsAux\n"));
1138
1139 if (lltok_isEnsures ($1))
1140 {
1141 $$ = functionClause_createEnsures ($3);
1142 }
1143 else if (lltok_isRequires ($1))
1144 {
1145 $$ = functionClause_createRequires ($3);
1146 }
1147 else
1148 {
1149 BADBRANCH;
1150 }
ba45e1e4 1151
1152 DPRINTF (("FunctionclauseS: %s", functionClause_unparse ($$)));
08eb3d0e 1153 }
08eb3d0e 1154
3814599d 1155functionConstraint
1156 : BufConstraintList { $$ = functionConstraint_createBufferConstraint ($1); }
ba45e1e4 1157 | metaStateConstraint { $$ = functionConstraint_createMetaStateConstraint ($1); DPRINTF (("Made constraint: %s", functionConstraint_unparse ($$))); }
28bf4b0b 1158
1159exitsQualifier
1160 : QEXITS { $$ = qual_createExits (); }
1161 | QMAYEXIT { $$ = qual_createMayExit (); }
1162 | QTRUEEXIT { $$ = qual_createTrueExit (); }
1163 | QFALSEEXIT { $$ = qual_createFalseExit (); }
1164 | QNEVEREXIT { $$ = qual_createNeverExit (); }
1165
1166checkQualifier
1167 : QCHECKED { $$ = qual_createChecked (); }
1168 | QCHECKMOD { $$ = qual_createCheckMod (); }
1169 | QUNCHECKED { $$ = qual_createUnchecked (); }
1170 | QCHECKEDSTRICT { $$ = qual_createCheckedStrict (); }
1171
1172stateQualifier
1173 : QOWNED { $$ = qual_createOwned (); }
1174 | QDEPENDENT { $$ = qual_createDependent (); }
1175 | QYIELD { $$ = qual_createYield (); }
1176 | QTEMP { $$ = qual_createTemp (); }
1177 | QONLY { $$ = qual_createOnly (); }
1178 | QKEEP { $$ = qual_createKeep (); }
1179 | QKEPT { $$ = qual_createKept (); }
1180 | QSHARED { $$ = qual_createShared (); }
1181 | QUNIQUE { $$ = qual_createUnique (); }
1182 | QNULL { $$ = qual_createNull (); }
1183 | QISNULL { $$ = qual_createIsNull (); }
1184 | QRELNULL { $$ = qual_createRelNull (); }
1185 | QNOTNULL { $$ = qual_createNotNull (); }
1186 | QEXPOSED { $$ = qual_createExposed (); }
1187 | QOBSERVER { $$ = qual_createObserver (); }
e26e911c 1188 | QNULLTERMINATED { $$ = qual_createNullTerminated (); }
28bf4b0b 1189 | CANNOTATION { $$ = qual_createMetaState ($1); }
1190
e26e911c 1191
28bf4b0b 1192paramQualifier
1193 : QRETURNED { $$ = qual_createReturned (); }
1194 | QSEF { $$ = qual_createSef (); }
1195
1196visibilityQualifier
1197 : QUNUSED { $$ = qual_createUnused (); }
1198 | QEXTERNAL { $$ = qual_createExternal (); }
1199
1200returnQualifier
1201 : QTRUENULL { $$ = qual_createTrueNull (); }
1202 | QFALSENULL { $$ = qual_createFalseNull (); }
1203
1204typedefQualifier
1205 : QABSTRACT { $$ = qual_createAbstract (); }
1206 | QCONCRETE { $$ = qual_createConcrete (); }
1207 | QMUTABLE { $$ = qual_createMutable (); }
1208 | QIMMUTABLE { $$ = qual_createImmutable (); }
1209
1210refcountQualifier
1211 : QREFCOUNTED { $$ = qual_createRefCounted (); }
1212 | QREFS { $$ = qual_createRefs (); }
1213 | QKILLREF { $$ = qual_createKillRef (); }
1214 | QRELDEF { $$ = qual_createRelDef (); }
1215 | QNEWREF { $$ = qual_createNewRef (); }
1216 | QTEMPREF { $$ = qual_createTempRef (); }
11ed4f45 1217
885824d3 1218typeModifier
1219 : QSHORT { $$ = qual_createShort (); }
1220 | QLONG { $$ = qual_createLong (); }
1221 | QSIGNED { $$ = qual_createSigned (); }
1222 | QUNSIGNED { $$ = qual_createUnsigned (); }
1223
28bf4b0b 1224definedQualifier
1225 : QOUT { $$ = qual_createOut (); }
1226 | QIN { $$ = qual_createIn (); }
1227 | QPARTIAL { $$ = qual_createPartial (); }
1228 | QSPECIAL { $$ = qual_createSpecial (); }
1229
1230typeQualifier
1231 : QCONST IsType { $$ = qual_createConst (); }
1232 | QVOLATILE IsType { $$ = qual_createVolatile (); }
f9264521 1233 | QRESTRICT IsType { $$ = qual_createRestrict (); }
28bf4b0b 1234 | definedQualifier IsType { $$ = $1; }
1235 | stateQualifier IsType { $$ = $1; }
1236 | exitsQualifier IsType { $$ = $1; }
1237 | paramQualifier IsType { $$ = $1; }
1238 | checkQualifier IsType { $$ = $1; }
1239 | returnQualifier IsType { $$ = $1; }
1240 | visibilityQualifier IsType { $$ = $1; }
1241 | typedefQualifier IsType { $$ = $1; }
1242 | refcountQualifier IsType { $$ = $1; }
1243
1244/*
1245** This is copied into the mtgrammar!
1246*/
1247
885824d3 1248typeSpecifier
1249 : CGCHAR NotType
1250 | CINT NotType
1251 | CBOOL NotType
1252 | CGFLOAT NotType
1253 | CDOUBLE NotType
1254 | CVOID NotType
d5047b91 1255 | QANYTYPE NotType { $$ = ctype_makeAnytype (); }
885824d3 1256 | QINTEGRALTYPE NotType { $$ = ctype_anyintegral; }
1257 | QUNSIGNEDINTEGRALTYPE NotType { $$ = ctype_unsignedintegral; }
1258 | QSIGNEDINTEGRALTYPE NotType { $$ = ctype_signedintegral; }
1259 | typeName NotType
1260 | suSpc NotType
1261 | enumSpc NotType
02b84d4b 1262 | typeModifier NotType { $$ = ctype_fromQual ($1); }
885824d3 1263
1264completeType
1265 : IsType completeTypeSpecifier IsType
1266 { $$ = qtype_resolve ($2); }
1267
1268completeTypeSpecifier
1269 : completeTypeSpecifierAux { $$ = $1; }
1270 | completeTypeSpecifierAux QALT altType QENDMACRO
1271 { $$ = qtype_mergeAlt ($1, $3); }
1272
1273altType
1274 : typeExpression
1275 | typeExpression TCOMMA altType
1276 { $$ = qtype_mergeAlt ($1, $3); }
1277
1278completeTypeSpecifierAux
1279 : storageSpecifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1280 | typeQualifier optCompleteType { $$ = qtype_addQual ($2, $1); }
1281 | typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
1282
1283optCompleteType
1284 : /* empty */ { $$ = qtype_unknown (); }
1285 | completeTypeSpecifier { $$ = $1; }
1286
86d93ed3 1287
1288optStructInvariant
1289: /* empty */ { $$ = constraintList_undefined; }
d9daf826 1290/* drl commenting before a CVS commit
86d93ed3 1291 | QINVARIANT BufConstraintList QENDMACRO { $$ = $2 }
1292*/
885824d3 1293suSpc
1294 : NotType CSTRUCT newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1295 CreateStructInnerScope
86d93ed3 1296 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
885824d3 1297 TRBRACE
288cbc5c 1298 optStructInvariant
d9daf826 1299 { ctype ct; ct = declareStruct ($3, $8); setGlobalStructInfo(ct, $12); $$ = ct; }
885824d3 1300 | NotType CUNION newId IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1301 CreateStructInnerScope
1302 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1303 TRBRACE
1304 { $$ = declareUnion ($3, $8); }
1305 | NotType CSTRUCT newId IsType TLBRACE TRBRACE
1306 { $$ = declareStruct ($3, uentryList_new ()); }
1307 | NotType CUNION newId IsType TLBRACE TRBRACE
1308 { $$ = declareUnion ($3, uentryList_new ()); }
1309 | NotType CSTRUCT IsType TLBRACE { sRef_setGlobalScopeSafe (); }
1310 CreateStructInnerScope
1311 structDeclList DeleteStructInnerScope { sRef_clearGlobalScopeSafe (); }
1312 TRBRACE
1313 { $$ = declareUnnamedStruct ($7); }
28bf4b0b 1314 | NotType CUNION IsType TLBRACE { sRef_setGlobalScopeSafe (); }
c8dda690 1315 CreateStructInnerScope structDeclList DeleteStructInnerScope
1316 { sRef_clearGlobalScopeSafe (); }
885824d3 1317 TRBRACE
1318 { $$ = declareUnnamedUnion ($7); }
1319 | NotType CSTRUCT IsType TLBRACE TRBRACE
1320 { $$ = ctype_createUnnamedStruct (uentryList_new ()); }
288cbc5c 1321 | NotType CUNION IsType TLBRACE TRBRACE
885824d3 1322 { $$ = ctype_createUnnamedUnion (uentryList_new ()); }
1323 | NotType CSTRUCT newId NotType { $$ = handleStruct ($3); }
288cbc5c 1324 | NotType CUNION newId NotType { $$ = handleUnion ($3); }
885824d3 1325
1326NotType
1327 : { g_expectingTypeName = FALSE; }
1328
1329structDeclList
1330 : structDecl
1331 | macroDef { $$ = uentryList_undefined; /* bogus! */ }
1332 | structDeclList structDecl { $$ = uentryList_mergeFields ($1, $2); }
1333
1334structDecl
1335 : completeTypeSpecifier NotType structNamedDeclList IsType TSEMI
1336 { $$ = fixUentryList ($3, $1); }
1337 | completeTypeSpecifier IsType TSEMI
1338 { $$ = fixUnnamedDecl ($1); }
1339
1340structNamedDeclList
1341 : structNamedDecl NotType
1342 { $$ = idDeclList_singleton ($1); }
1343 | structNamedDeclList TCOMMA structNamedDecl NotType
1344 { $$ = idDeclList_add ($1, $3); }
1345
1346structNamedDecl /* hack to get around namespace problems */
1347 : namedDecl { $$ = $1; }
1348 | TCOLON IsType constantExpr { $$ = idDecl_undefined; }
1349 | namedDecl TCOLON IsType constantExpr { $$ = $1; }
1350 /* Need the IsType in case there is a cast in the constant expression. */
1351
1352enumSpc
1353 : NotType CENUM TLBRACE enumeratorList TRBRACE IsType
1354 { $$ = declareUnnamedEnum ($4); }
1355 | NotType CENUM newId TLBRACE { context_pushLoc (); } enumeratorList TRBRACE IsType
1356 { context_popLoc (); $$ = declareEnum ($3, $6); }
1357 | NotType CENUM newId IsType { $$ = handleEnum ($3); }
1358
1359enumeratorList
1360 : enumerator
1361 { $$ = enumNameList_single ($1); }
1362 | enumeratorList TCOMMA enumerator
1363 { $$ = enumNameList_push ($1, $3); }
1364 | enumeratorList TCOMMA
1365
1366enumerator
1367 : newId
1368 { uentry ue = uentry_makeEnumConstant ($1, ctype_unknown);
1369 usymtab_supGlobalEntry (ue);
1370 $$ = $1;
1371 }
1372 | newId TASSIGN IsType constantExpr
1373 { uentry ue = uentry_makeEnumInitializedConstant ($1, ctype_unknown, $4);
1374 usymtab_supGlobalEntry (ue);
1375 $$ = $1;
1376 }
1377
1378optNamedDecl
1379 : namedDeclBase
1380 | optAbstractDeclBase { $$ = idDecl_create (cstring_undefined, qtype_create ($1)); }
1381 | pointers TYPE_NAME
1382 {
1383 qtype qt = qtype_unknown ();
885824d3 1384 qtype_adjustPointers ($1, qt);
6fcd0b1e 1385 $$ = idDecl_create (cstring_copy (cscanner_observeLastIdentifier ()), qt);
885824d3 1386 }
1387 | pointers optNamedDecl
1388 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1389
1390namedDecl
1391 : namedDeclBase
1392 | pointers namedDeclBase
1393 { $$ = $2; qtype_adjustPointers ($1, idDecl_getTyp ($$)); }
1394
1395genericParamList
1396 : paramTypeList { $$ = handleParamTypeList ($1); }
1397 | NotType paramIdList { $$ = handleParamIdList ($2); }
1398
1399innerMods
f9264521 1400 : QCONST { $$ = qual_createConst (); }
1401 | QRESTRICT { $$ = qual_createRestrict (); }
1402 | QVOLATILE { $$ = qual_createVolatile (); }
885824d3 1403
1404innerModsList
f9264521 1405 : innerMods { $$ = qualList_single ($1); }
1406 | innerModsList innerMods { $$ = qualList_add ($1, $2); }
885824d3 1407
1408pointers
f9264521 1409 : TMULT { $$ = pointers_create ($1); }
1410 | TMULT innerModsList { $$ = pointers_createMods ($1, $2); }
1411 | TMULT pointers { $$ = pointers_extend (pointers_create ($1), $2); }
1412 | TMULT innerModsList pointers { $$ = pointers_extend (pointers_createMods ($1, $2), $3); }
885824d3 1413
1414paramIdList
1415 : idList
1416 | idList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1417
1418idList
1419 : newId { $$ = uentryList_single (uentry_makeVariableLoc ($1, ctype_int)); }
1420 | idList TCOMMA newId { $$ = uentryList_add ($1, uentry_makeVariableLoc ($3, ctype_int)); }
1421
1422paramTypeList
1423 : CTOK_ELIPSIS { $$ = uentryList_single (uentry_makeElipsisMarker ()); }
1424 | paramList
1425 | paramList TCOMMA CTOK_ELIPSIS { $$ = uentryList_add ($1, uentry_makeElipsisMarker ()); }
1426
1427paramList
1428 : { storeLoc (); } paramDecl { $$ = uentryList_single ($2); }
1429 | paramList TCOMMA { storeLoc (); } paramDecl
1430 { $$ = uentryList_add ($1, $4); }
1431
1432paramDecl
1433 : IsType completeTypeSpecifier optNamedDecl IsType
1434 {
1435 if (isFlipOldStyle ())
1436 {
1437 llparseerror (cstring_makeLiteral ("Inconsistent function parameter syntax (mixing old and new style declaration)"));
1438 }
1439 else
1440 {
1441 setNewStyle ();
1442 }
1443 $$ = makeCurrentParam (idDecl_fixParamBase ($3, $2));
1444 }
1445 | newId /* its an old-style declaration */
1446 {
1447 idDecl tparam = idDecl_create ($1, qtype_unknown ());
1448
1449 if (isNewStyle ())
1450 {
1451 llparseerror (message ("Inconsistent function parameter syntax: %q",
1452 idDecl_unparse (tparam)));
1453 }
1454
1455 setFlipOldStyle ();
1456 $$ = makeCurrentParam (tparam);
1457 idDecl_free (tparam);
1458 }
1459
1460typeExpression
1461 : completeType
1462 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
1463
1464abstractDecl
1465 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
1466 | abstractDeclBase
1467 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
1468
1469optAbstractDeclBase
1470 : /* empty */ { $$ = ctype_unknown; }
1471 | abstractDeclBase
1472
1473abstractDeclBase
1474 : IsType TLPAREN NotType abstractDecl TRPAREN
1475 { $$ = ctype_expectFunction ($4); }
1476 | TLSQBR TRSQBR { $$ = ctype_makeArray (ctype_unknown); }
a0a162cd 1477 | TLSQBR constantExpr TRSQBR
1478 { $$ = ctype_makeFixedArray (ctype_unknown, exprNode_getLongValue ($2)); }
393e573f 1479 | abstractDeclBase TLSQBR TRSQBR { $$ = ctype_makeInnerArray ($1); }
a0a162cd 1480 | abstractDeclBase TLSQBR constantExpr TRSQBR
077d4458 1481 { $$ = ctype_makeInnerFixedArray ($1, exprNode_getLongValue ($3)); }
885824d3 1482 | IsType TLPAREN TRPAREN
1483 { $$ = ctype_makeFunction (ctype_unknown, uentryList_makeMissingParams ()); }
1484 | IsType TLPAREN paramTypeList TRPAREN
1485 { $$ = ctype_makeParamsFunction (ctype_unknown, $3); }
1486 | abstractDeclBase IsType TLPAREN TRPAREN
1487 { $$ = ctype_makeFunction ($1, uentryList_makeMissingParams ()); }
1488 | abstractDeclBase IsType TLPAREN paramTypeList TRPAREN
1489 { $$ = ctype_makeParamsFunction ($1, $4); }
1490
1491/* statement */
1492
1493stmt
1494 : labeledStmt
1495 | caseStmt
1496 | defaultStmt
1497 | compoundStmt
1498 | expressionStmt
1499 | selectionStmt
1500 | iterationStmt
1501 | iterStmt
1502 | jumpStmt
11ed4f45 1503
86d93ed3 1504
885824d3 1505iterBody
1506 : iterDefStmtList { $$ = $1; }
1507
1508endBody
1509 : iterBody
1510
1511iterDefStmtList
1512 : iterDefStmt
1513 | iterDefStmtList iterDefStmt
1514 { $$ = exprNode_concat ($1, $2); }
1515
1516iterDefIterationStmt
1517 : iterWhilePred iterDefStmtList
1518 { $$ = exprNode_while ($1, $2); }
1519 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
1520 { $$ = exprNode_doWhile ($2, $5); }
1521 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1522 { $$ = exprNode_doWhile ($2, $5); }
1523 | forPred iterDefStmt
1524 { $$ = exprNode_for ($1, $2); }
1525
1526forPred
1527 : CFOR TLPAREN optExpr TSEMI optExpr TSEMI
1528 { context_setProtectVars (); } optExpr { context_sizeofReleaseVars (); }
1529 TRPAREN
1530 { $$ = exprNode_forPred ($3, $5, $8);
1531 context_enterForClause ($5); }
1532
1533partialIterStmt
1534 : ITER_NAME CreateInnerScope TLPAREN
1535 { setProcessingIterVars ($1); }
1536 iterArgList TRPAREN
1537 { $$ = exprNode_iterStart ($1, $5); }
1538 | ITER_ENDNAME { $$ = exprNode_createId ($1); }
1539
1540iterDefStmt
1541 : labeledStmt
1542 | caseStmt
1543 | defaultStmt
28bf4b0b 1544 | openScope initializerList { $$ = $1; DPRINTF (("def stmt: %s", exprNode_unparse ($$))); }
885824d3 1545 | openScope
1546 | closeScope
1547 | expressionStmt
1548 | iterSelectionStmt
1549 | iterDefIterationStmt
1550 | partialIterStmt
1551 | jumpStmt
1552 | TLPAREN iterDefStmt TRPAREN { $$ = $2; }
1553 | error { $$ = exprNode_makeError (); }
1554
1555iterSelectionStmt
2e127cb8 1556 : ifPred { exprNode_checkIfPred ($1); } iterDefStmt
885824d3 1557 { /* don't: context_exitTrueClause ($1, $2); */
2e127cb8 1558 $$ = exprNode_if ($1, $3);
885824d3 1559 }
1560
1561openScope
1562 : CreateInnerScope TLBRACE { $$ = exprNode_createTok ($2); }
1563
1564closeScope
1565 : DeleteInnerScopeSafe TRBRACE { $$ = exprNode_createTok ($2); }
1566
1567macroBody
1568 : stmtErr
1569 | stmtListErr
1570
1571stmtErr
1572 : labeledStmt
1573 | caseStmt
1574 | defaultStmt
1575 | compoundStmtErr
1576 | expressionStmtErr
1577 | selectionStmt
1578 | iterStmt
1579 | iterationStmtErr
1580 | TLPAREN stmtErr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1581 | jumpStmt
1582 | error { $$ = exprNode_makeError (); }
1583
1584labeledStmt
a0a162cd 1585 : newId TCOLON { $$ = exprNode_labelMarker ($1); }
1586 | QNOTREACHED stmt { $$ = exprNode_notReached ($2); }
885824d3 1587
fafc64cf 1588/*
1589** We allow more than one QFALLTHROUGH token to support mixed lint/splint markers.
1590*/
1591
1592optExtraFallThroughs
1593 : /* empty */ { ; }
1594 | QFALLTHROUGH optExtraFallThroughs { ; }
1595
885824d3 1596/* Note that we can semantically check that the object to the case is
1597 indeed constant. In this case, we may not want to go through this effort */
1598
1599caseStmt
1600 : CASE constantExpr { context_enterCaseClause ($2); }
1601 TCOLON { $$ = exprNode_caseMarker ($2, FALSE); }
fafc64cf 1602 | QFALLTHROUGH optExtraFallThroughs CASE constantExpr { context_enterCaseClause ($4); }
1603 TCOLON { $$ = exprNode_caseMarker ($4, TRUE); }
885824d3 1604
1605defaultStmt
1606 : DEFAULT { context_enterCaseClause (exprNode_undefined); }
1607 TCOLON { $$ = exprNode_defaultMarker ($1, FALSE); }
fafc64cf 1608 | QFALLTHROUGH optExtraFallThroughs DEFAULT { context_enterCaseClause (exprNode_undefined); }
1609 TCOLON { $$ = exprNode_defaultMarker ($3, TRUE); }
885824d3 1610
1611compoundStmt
1612 : TLPAREN compoundStmt TRPAREN { $$ = $2; }
1613 | CreateInnerScope compoundStmtAux
1614 { $$ = $2; context_exitInner ($2); }
1615
1616compoundStmtErr
1617 : CreateInnerScope compoundStmtAuxErr DeleteInnerScope { $$ = $2; }
1618
1619CreateInnerScope
1620 : { context_enterInnerContext (); }
1621
1622DeleteInnerScope
1623 : { context_exitInnerPlain (); }
1624
1625CreateStructInnerScope
1626 : { context_enterStructInnerContext (); }
1627
1628DeleteStructInnerScope
1629 : { context_exitStructInnerContext (); }
1630
1631DeleteInnerScopeSafe
1632 : { context_exitInnerSafe (); }
1633
1634compoundStmtRest
1635 : TRBRACE { $$ = exprNode_createTok ($1); }
1636 | QNOTREACHED TRBRACE { $$ = exprNode_notReached (exprNode_createTok ($2)); }
1637 | stmtList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1638 | stmtList QNOTREACHED TRBRACE
1639 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1640 | initializerList TRBRACE { $$ = exprNode_updateLocation ($1, lltok_getLoc ($2)); }
1641 | initializerList QNOTREACHED TRBRACE
1642 { $$ = exprNode_notReached (exprNode_updateLocation ($1, lltok_getLoc ($3))); }
1643 | initializerList stmtList TRBRACE
1644 { $$ = exprNode_updateLocation (exprNode_concat ($1, $2), lltok_getLoc ($3)); }
1645 | initializerList stmtList QNOTREACHED TRBRACE
1646 { $$ = exprNode_notReached (exprNode_updateLocation (exprNode_concat ($1, $2),
1647 lltok_getLoc ($3)));
1648 }
1649
885824d3 1650compoundStmtAux
1651 : TLBRACE compoundStmtRest
1652 { $$ = exprNode_makeBlock ($2); }
1653
1654compoundStmtAuxErr
1655 : TLBRACE TRBRACE
1656 { $$ = exprNode_createTok ($2); }
1657 | TLBRACE stmtListErr TRBRACE
1658 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1659 | TLBRACE initializerList TRBRACE
1660 { $$ = exprNode_updateLocation ($2, lltok_getLoc ($3)); }
1661 | TLBRACE initializerList stmtList TRBRACE
1662 { $$ = exprNode_updateLocation (exprNode_concat ($2, $3), lltok_getLoc ($4)); }
1663
1664stmtListErr
1665 : stmtErr
1666 | stmtListErr stmtErr { $$ = exprNode_concat ($1, $2); }
1667
1668initializerList
1669 : initializer { $$ = $1; }
1670 | initializerList initializer { $$ = exprNode_concat ($1, $2); }
1671
abd7f895 1672typeInitializerList
1673 : typeInitializer { $$ = $1; }
1674 | typeInitializerList TCOMMA typeInitializer { $$ = exprNode_concat ($1, $3); }
1675
1676typeInitializer
1677 : assignExpr { $$ = $1; }
1678 | TLBRACE typeInitializerList optComma TRBRACE { $$ = $2; }
1679
885824d3 1680stmtList
a0a162cd 1681 : stmt { $$ = $1; }
1682 | stmtList stmt { $$ = exprNode_concat ($1, $2); }
885824d3 1683
1684expressionStmt
1685 : TSEMI { $$ = exprNode_createTok ($1); }
4cccc6ad 1686 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
885824d3 1687
1688expressionStmtErr
1689 : TSEMI { $$ = exprNode_createTok ($1); }
4cccc6ad 1690 | expr TSEMI { $$ = exprNode_statement ($1, $2); }
885824d3 1691 | expr { $$ = exprNode_checkExpr ($1); }
1692
1693ifPred
1694 : CIF TLPAREN expr TRPAREN
2e127cb8 1695 {
1696 exprNode_produceGuards ($3); context_enterTrueClause ($3);
1697 exprNode_checkIfPred ($3);
1698 $$ = $3;
1699 }
1700
885824d3 1701 /*
1702 ** not ANSI: | CIF TLPAREN compoundStmt TRPAREN
1703 ** { $$ = $3; context_enterTrueClause (); }
1704 */
1705
1706selectionStmt
1707 : ifPred stmt
1708 {
1709 context_exitTrueClause ($1, $2);
1710 $$ = exprNode_if ($1, $2);
1711 }
2e127cb8 1712 | ifPred stmt CELSE { context_enterFalseClause ($1); } stmt
885824d3 1713 {
1714 context_exitClause ($1, $2, $5);
1715 $$ = exprNode_ifelse ($1, $2, $5);
1716 }
1717 | SWITCH TLPAREN expr { context_enterSwitch ($3); }
1718 TRPAREN stmt { $$ = exprNode_switch ($3, $6); }
1719
1720whilePred
1721 : WHILE TLPAREN expr TRPAREN
1722 { $$ = exprNode_whilePred ($3); context_enterWhileClause ($3); }
1723 /* not ANSI: | WHILE TLPAREN compoundStmt TRPAREN stmt { $$ = exprNode_while ($3, $5); } */
1724
1725iterWhilePred
1726 : WHILE TLPAREN expr TRPAREN { $$ = exprNode_whilePred($3); }
1727
1728iterStmt
1729 : ITER_NAME { context_enterIterClause (); }
1730 CreateInnerScope TLPAREN { setProcessingIterVars ($1); }
1731 iterArgList TRPAREN
1732 compoundStmt endIter DeleteInnerScope
1733 {
1734 $$ = exprNode_iter ($1, $6, $8, $9);
1735
1736 }
1737
1738iterArgList
1739 : iterArgExpr { $$ = exprNodeList_singleton ($1); }
1740 | iterArgList { nextIterParam (); } TCOMMA iterArgExpr
1741 { $$ = exprNodeList_push ($1, $4); }
1742
1743iterArgExpr
1744 : assignIterExpr { $$ = exprNode_iterExpr ($1); }
1745 | id { $$ = exprNode_iterId ($1); }
1746 | TYPE_NAME_OR_ID { uentry ue = coerceIterId ($1);
1747
1748 if (uentry_isValid (ue))
1749 {
1750 $$ = exprNode_iterId (ue);
1751 }
1752 else
1753 {
6fcd0b1e 1754 $$ = exprNode_iterNewId (cstring_copy (cscanner_observeLastIdentifier ()));
885824d3 1755 }
1756 }
1757 | NEW_IDENTIFIER { $$ = exprNode_iterNewId ($1); }
1758
1759/*
1760** everything is the same, EXCEPT it cannot be a NEW_IDENTIFIER
1761*/
1762
28bf4b0b 1763cconstantExpr
1764 : CCONSTANT
1765 | cconstantExpr CCONSTANT { $$ = exprNode_combineLiterals ($1, $2); }
1766
885824d3 1767primaryIterExpr
28bf4b0b 1768 : cconstantExpr
885824d3 1769 | TLPAREN expr TRPAREN { $$ = exprNode_addParens ($1, $2); }
1770
1771postfixIterExpr
1772 : primaryIterExpr
1773 | postfixExpr TLSQBR expr TRSQBR { $$ = exprNode_arrayFetch ($1, $3); }
1774 | postfixExpr TLPAREN TRPAREN { $$ = exprNode_functionCall ($1, exprNodeList_new ()); }
1775 | postfixExpr TLPAREN argumentExprList TRPAREN { $$ = exprNode_functionCall ($1, $3); }
1776 | VA_ARG TLPAREN assignExpr TCOMMA typeExpression TRPAREN
1777 { $$ = exprNode_vaArg ($1, $3, $5); }
28bf4b0b 1778 | postfixExpr NotType TDOT newId IsType { $$ = exprNode_fieldAccess ($1, $3, $4); }
1779 | postfixExpr NotType ARROW_OP newId IsType { $$ = exprNode_arrowAccess ($1, $3, $4); }
885824d3 1780 | postfixExpr INC_OP { $$ = exprNode_postOp ($1, $2); }
1781 | postfixExpr DEC_OP { $$ = exprNode_postOp ($1, $2); }
1782
1783unaryIterExpr
1784 : postfixIterExpr
1785 | INC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1786 | DEC_OP unaryExpr { $$ = exprNode_preOp ($2, $1); }
1787 | TAMPERSAND castExpr { $$ = exprNode_preOp ($2, $1); }
1788 | TMULT castExpr { $$ = exprNode_preOp ($2, $1); }
1789 | TPLUS castExpr { $$ = exprNode_preOp ($2, $1); }
1790 | TMINUS castExpr { $$ = exprNode_preOp ($2, $1); }
1791 | TTILDE castExpr { $$ = exprNode_preOp ($2, $1); }
1792 | TEXCL castExpr { $$ = exprNode_preOp ($2, $1); }
1793 | sizeofExpr { $$ = $1; }
1794
1795castIterExpr
1796 : unaryIterExpr
1797 | TLPAREN typeExpression TRPAREN castExpr { $$ = exprNode_cast ($1, $4, $2); }
1798
1799timesIterExpr
1800 : castIterExpr
1801 | timesExpr TMULT castExpr { $$ = exprNode_op ($1, $3, $2); }
1802 | timesExpr TDIV castExpr { $$ = exprNode_op ($1, $3, $2); }
1803 | timesExpr TPERCENT castExpr { $$ = exprNode_op ($1, $3, $2); }
1804
1805plusIterExpr
1806 : timesIterExpr
1807 | plusExpr TPLUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1808 | plusExpr TMINUS timesExpr { $$ = exprNode_op ($1, $3, $2); }
1809
1810shiftIterExpr
1811 : plusIterExpr
1812 | shiftExpr LEFT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1813 | shiftExpr RIGHT_OP plusExpr { $$ = exprNode_op ($1, $3, $2); }
1814
1815relationalIterExpr
1816 : shiftIterExpr
1817 | relationalExpr TLT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1818 | relationalExpr TGT shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1819 | relationalExpr LE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1820 | relationalExpr GE_OP shiftExpr { $$ = exprNode_op ($1, $3, $2); }
1821
1822equalityIterExpr
1823 : relationalIterExpr
1824 | equalityExpr EQ_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1825 | equalityExpr NE_OP relationalExpr { $$ = exprNode_op ($1, $3, $2); }
1826
1827bitandIterExpr
1828 : equalityIterExpr
1829 | bitandExpr TAMPERSAND equalityExpr { $$ = exprNode_op ($1, $3, $2); }
1830
1831xorIterExpr
1832 : bitandIterExpr
1833 | xorExpr TCIRC bitandExpr { $$ = exprNode_op ($1, $3, $2); }
1834;
1835
1836bitorIterExpr
1837 : xorIterExpr
1838 | bitorExpr TBAR xorExpr { $$ = exprNode_op ($1, $3, $2); }
1839
1840andIterExpr
1841 : bitorIterExpr
1842 | andExpr AND_OP bitorExpr { $$ = exprNode_op ($1, $3, $2); }
1843
1844orIterExpr
1845 : andIterExpr
1846 | orExpr OR_OP andExpr { $$ = exprNode_op ($1, $3, $2); }
1847
1848conditionalIterExpr
1849 : orIterExpr
1850 | orExpr TQUEST { context_enterTrueClause ($1); }
1851 expr TCOLON { context_enterFalseClause ($1); } conditionalExpr
1852 { $$ = exprNode_cond ($1, $4, $7); }
1853
1854assignIterExpr
1855 : conditionalIterExpr
1856 | unaryExpr TASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1857 | unaryExpr MUL_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1858 | unaryExpr DIV_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1859 | unaryExpr MOD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1860 | unaryExpr ADD_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1861 | unaryExpr SUB_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1862 | unaryExpr LEFT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1863 | unaryExpr RIGHT_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1864 | unaryExpr AND_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1865 | unaryExpr XOR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1866 | unaryExpr OR_ASSIGN assignExpr { $$ = exprNode_assign ($1, $3, $2); }
1867
1868endIter
1869 : ITER_ENDNAME { $$ = $1; }
1870 | /* empty */ { $$ = uentry_undefined; }
1871
1872doHeader
1873 : DO { context_enterDoWhileClause (); $$ = $1; }
1874
1875iterationStmt
1876 : whilePred stmt
1877 { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1878 | doHeader stmt WHILE TLPAREN expr TRPAREN TSEMI
4cccc6ad 1879 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
885824d3 1880 | forPred stmt
1881 { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1882
1883iterationStmtErr
1884 : whilePred stmtErr { $$ = exprNode_while ($1, $2); context_exitWhileClause ($1, $2); }
1885 | doHeader stmtErr WHILE TLPAREN expr TRPAREN TSEMI
4cccc6ad 1886 { $$ = exprNode_statement (exprNode_doWhile ($2, $5), $7); }
885824d3 1887 | doHeader stmtErr WHILE TLPAREN expr TRPAREN
1888 { $$ = exprNode_doWhile ($2, $5); }
1889 | forPred stmtErr { $$ = exprNode_for ($1, $2); context_exitForClause ($1, $2); }
1890
1891jumpStmt
1892 : GOTO newId TSEMI { $$ = exprNode_goto ($2); }
1893 | CONTINUE TSEMI { $$ = exprNode_continue ($1, BADTOK); }
1894 | QINNERCONTINUE CONTINUE TSEMI
1895 { $$ = exprNode_continue ($1, QINNERCONTINUE); }
1896 | BREAK TSEMI { $$ = exprNode_break ($1, BADTOK); }
1897 | QSWITCHBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSWITCHBREAK); }
1898 | QLOOPBREAK BREAK TSEMI { $$ = exprNode_break ($2, QLOOPBREAK); }
1899 | QINNERBREAK BREAK TSEMI { $$ = exprNode_break ($2, QINNERBREAK); }
1900 | QSAFEBREAK BREAK TSEMI { $$ = exprNode_break ($2, QSAFEBREAK); }
1901 | RETURN TSEMI { $$ = exprNode_nullReturn ($1); }
1902 | RETURN expr TSEMI { $$ = exprNode_return ($2); }
1903
1904optSemi
1905 :
1906 | TSEMI { ; }
1907
abd7f895 1908optComma
1909 :
1910 | TCOMMA { ; }
1911
885824d3 1912id
1913 : IDENTIFIER
1914
1915newId
1916 : NEW_IDENTIFIER
1917 | ITER_NAME { $$ = uentry_getName ($1); }
1918 | ITER_ENDNAME { $$ = uentry_getName ($1); }
1919 | id { $$ = uentry_getName ($1); }
1920 | TYPE_NAME_OR_ID { $$ = $1; }
1921
1922typeName
1923 : TYPE_NAME
1924 | TYPE_NAME_OR_ID { $$ = ctype_unknown; }
abd7f895 1925 | CTYPEOF TLPAREN expr TRPAREN { $$ = exprNode_getType ($3); exprNode_free ($3); }
1926 | CTYPEOF TLPAREN typeExpression TRPAREN { $$ = qtype_getType ($3); }
885824d3 1927
1928%%
1929
60eced23 1930/*@-redecl@*/ /*@-namechecks@*/
885824d3 1931extern char *yytext;
60eced23 1932/*@=redecl@*/ /*@=namechecks@*/
885824d3 1933
1934# include "bison.reset"
1935
1936void yyerror (/*@unused@*/ char *s)
1937{
1938 static bool givehint = FALSE;
1939
1940 if (context_inIterDef ())
1941 {
1942 llerror (FLG_SYNTAX, message ("Iter syntax not parseable: %s",
1943 context_inFunctionName ()));
1944 }
1945 else if (context_inIterEnd ())
1946 {
1947 llerror (FLG_SYNTAX, message ("Iter finalizer syntax not parseable: %s",
1948 context_inFunctionName ()));
1949 }
1950 else if (context_inMacro ())
1951 {
1952 llerror (FLG_SYNTAX, message ("Macro syntax not parseable: %s",
1953 context_inFunctionName ()));
1954
b7e84605 1955 if (context_inUnknownMacro ())
885824d3 1956 {
1957 if (!givehint)
1958 {
1959 llhint (cstring_makeLiteral
1960 ("Precede macro definition with /*@notfunction@*/ "
1961 "to suppress checking and force expansion"));
1962 givehint = TRUE;
1963 }
1964 }
1965
6fcd0b1e 1966 cscanner_swallowMacro ();
28bf4b0b 1967 context_exitAllClausesQuiet ();
885824d3 1968 }
1969 else
1970 {
1971 llparseerror (cstring_undefined);
1972 }
1973}
1974
1975
11ed4f45 1976
1977
28bf4b0b 1978
1979
1980
11ed4f45 1981
1982
1983
1984
1985
This page took 2.267973 seconds and 5 git commands to generate.