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