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