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