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