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