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