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