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