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