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