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