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