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