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