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