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