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