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