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