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