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