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