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