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