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