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