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