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