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