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