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