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