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