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