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