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