]>
Commit | Line | Data |
---|---|---|
28bf4b0b | 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 | ** mtgrammar.y | |
21 | ** | |
22 | ** Grammar for .mts files. | |
23 | */ | |
24 | ||
25 | %{ | |
26 | ||
27 | # include "bison.reset" | |
28 | # include "lclintMacros.nf" | |
29 | # include "llbasic.h" | |
28bf4b0b | 30 | |
b7b694d6 | 31 | # ifndef __LCLINT__ |
32 | extern ctype mtscanner_lookupType (mttok p_tok) /*@modifies p_tok@*/ ; | |
33 | # endif | |
34 | ||
35 | /*@i523 can't include these here | |
36 | # include "mtgrammar.h" | |
37 | # include "mtscanner.h" | |
38 | */ | |
39 | ||
28bf4b0b | 40 | static /*@exits@*/ void mterror (char *); |
41 | ||
42 | /*@-noparams@*/ /* Can't list params since YYSTYPE isn't defined yet. */ | |
43 | static void yyprint (/*FILE *p_file, int p_type, YYSTYPE p_value */); | |
44 | /*@=noparams@*/ | |
45 | ||
46 | # define YYPRINT(file, type, value) yyprint (file, type, value) | |
47 | ||
48 | # define YYDEBUG 1 | |
49 | ||
50 | # include "bison.head" | |
51 | ||
52 | %} | |
53 | ||
54 | %pure_parser | |
55 | ||
56 | %union { | |
57 | mttok tok; | |
58 | mtDeclarationNode mtdecl; | |
59 | mtDeclarationPiece mtpiece; | |
60 | mtDeclarationPieces mtpieces; | |
61 | mtContextNode mtcontext; | |
62 | mtValuesNode mtvalues; | |
63 | mtDefaultsNode mtdefaults; | |
64 | mtDefaultsDeclList mtdeflist; | |
65 | mtAnnotationsNode mtannotations; | |
66 | mtAnnotationList mtannotlist; | |
67 | mtAnnotationDecl mtannotdecl; | |
68 | mtMergeNode mtmerge; | |
69 | mtMergeItem mtmergeitem; | |
70 | mtMergeClauseList mtmergeclauselist; | |
71 | mtMergeClause mtmergeclause; | |
72 | mtTransferClauseList mttransferclauselist; | |
73 | mtTransferClause mttransferclause; | |
74 | mtTransferAction mttransferaction; | |
75 | mtLoseReferenceList mtlosereferencelist; | |
76 | mtLoseReference mtlosereference; | |
77 | ||
78 | /*@only@*/ cstringList cstringlist; | |
79 | ctype ctyp; | |
80 | /*@only@*/ qtype qtyp; | |
81 | int count; | |
82 | } | |
83 | ||
84 | /* Don't forget to enter all tokens in mtscanner.c */ | |
85 | %token <tok> MT_BADTOK | |
86 | ||
87 | %token <tok> MT_END | |
88 | %token <tok> MT_STATE MT_GLOBAL | |
89 | ||
90 | %token <tok> MT_CONTEXT | |
91 | %token <tok> MT_ONEOF | |
92 | ||
93 | %token <tok> MT_DEFAULTS MT_DEFAULT | |
12f2ffe9 | 94 | %token <tok> MT_REFERENCE MT_PARAMETER MT_RESULT MT_CLAUSE MT_LITERAL MT_NULL |
28bf4b0b | 95 | |
96 | %token <tok> MT_ANNOTATIONS | |
97 | %token <tok> MT_ARROW | |
98 | ||
99 | %token <tok> MT_MERGE | |
100 | %token <tok> MT_TRANSFERS MT_PRECONDITIONS MT_POSTCONDITIONS | |
101 | %token <tok> MT_LOSEREFERENCE | |
102 | ||
103 | %token <tok> MT_AS | |
104 | %token <tok> MT_ERROR | |
105 | ||
106 | %token <tok> MT_PLUS MT_STAR MT_BAR | |
107 | %token <tok> MT_LPAREN MT_RPAREN | |
108 | %token <tok> MT_LBRACKET MT_RBRACKET | |
109 | %token <tok> MT_LBRACE MT_RBRACE | |
110 | %token <tok> MT_COMMA | |
111 | ||
112 | %token <tok> MT_CHAR MT_INT MT_FLOAT MT_DOUBLE MT_VOID MT_ANYTYPE MT_INTEGRALTYPE MT_UNSIGNEDINTEGRALTYPE | |
113 | %token <tok> MT_SIGNEDINTEGRALTYPE | |
114 | %token <tok> MT_CONST MT_VOLATILE | |
115 | %token <tok> MT_STRINGLIT | |
116 | %token <tok> MT_IDENT | |
117 | ||
118 | %type <count> pointers | |
119 | %type <ctyp> optType typeSpecifier typeName abstractDecl abstractDeclBase | |
120 | %type <qtyp> typeExpression | |
121 | %type <qtyp> completeType completeTypeAux optCompleteType | |
122 | %type <mtpiece> declarationPiece | |
123 | %type <mtcontext> contextDeclaration | |
124 | %type <mtcontext> contextSelection optContextSelection | |
125 | %type <mtvalues> valuesDeclaration | |
126 | %type <tok> defaultNode | |
127 | %type <mtdefaults> defaultsDeclaration | |
128 | %type <mtdeflist> defaultDeclarationList | |
129 | %type <mtannotations> annotationsDeclaration | |
130 | %type <mtannotlist> annotationsDeclarationList | |
131 | %type <mtannotdecl> annotationDeclaration | |
132 | %type <mtmerge> mergeDeclaration | |
133 | %type <mtmergeitem> mergeItem | |
134 | %type <mtmergeclauselist> mergeClauses | |
135 | %type <mtmergeclause> mergeClause | |
136 | %type <mttransferclauselist> transfersDeclaration transferClauses preconditionsDeclaration postconditionsDeclaration | |
137 | %type <mttransferclause> transferClause | |
138 | %type <mttransferaction> transferAction errorAction | |
139 | %type <mtlosereferencelist> loseReferenceDeclaration lostClauses | |
140 | %type <mtlosereference> lostClause | |
141 | %type <cstringlist> valuesList | |
142 | %type <mtdecl> declarationNode | |
143 | %type <mtpieces> declarationPieces | |
144 | %type <tok> valueChoice | |
145 | ||
146 | ||
147 | %start file | |
148 | ||
149 | %% | |
150 | ||
151 | file | |
152 | : {} | |
153 | | mtsDeclaration {} | |
154 | ||
155 | mtsDeclaration | |
156 | : MT_STATE declarationNode MT_END | |
157 | { mtreader_processDeclaration ($2); } | |
158 | | MT_GLOBAL MT_STATE declarationNode MT_END | |
159 | { mtreader_processGlobalDeclaration ($3); } | |
160 | ||
161 | declarationNode | |
162 | : MT_IDENT declarationPieces | |
163 | { $$ = mtDeclarationNode_create ($1, $2); } | |
164 | ||
165 | declarationPieces | |
166 | : { $$ = mtDeclarationPieces_create (); } | |
167 | | declarationPiece declarationPieces | |
168 | { $$ = mtDeclarationPieces_append ($2, $1); } | |
169 | ||
170 | declarationPiece | |
171 | : contextDeclaration { $$ = mtDeclarationPiece_createContext ($1); } | |
172 | | valuesDeclaration { $$ = mtDeclarationPiece_createValues ($1); } | |
173 | | defaultsDeclaration { $$ = mtDeclarationPiece_createDefaults ($1); } | |
174 | | defaultNode { $$ = mtDeclarationPiece_createValueDefault ($1); } | |
175 | | annotationsDeclaration { $$ = mtDeclarationPiece_createAnnotations ($1); } | |
176 | | mergeDeclaration { $$ = mtDeclarationPiece_createMerge ($1); } | |
177 | | transfersDeclaration { $$ = mtDeclarationPiece_createTransfers ($1); } | |
178 | | preconditionsDeclaration { $$ = mtDeclarationPiece_createPreconditions ($1); } | |
179 | | postconditionsDeclaration { $$ = mtDeclarationPiece_createPostconditions ($1); } | |
180 | | loseReferenceDeclaration { $$ = mtDeclarationPiece_createLosers ($1); } | |
181 | ||
182 | contextDeclaration | |
183 | : MT_CONTEXT contextSelection { $$ = $2; } | |
184 | /* ??? should it be a list? */ | |
185 | ||
186 | optContextSelection | |
187 | : /* empty */ { $$ = mtContextNode_createAny (); } | |
188 | | contextSelection | |
189 | ||
190 | contextSelection | |
191 | : MT_PARAMETER optType { $$ = mtContextNode_createParameter ($2); } | |
192 | | MT_REFERENCE optType { $$ = mtContextNode_createReference ($2); } | |
b072092f | 193 | | MT_RESULT optType { $$ = mtContextNode_createResult ($2); } |
28bf4b0b | 194 | | MT_CLAUSE optType { $$ = mtContextNode_createClause ($2); } |
12f2ffe9 | 195 | | MT_LITERAL optType { $$ = mtContextNode_createLiteral ($2); } |
196 | | MT_NULL optType { $$ = mtContextNode_createNull ($2); } | |
28bf4b0b | 197 | |
198 | /* | |
199 | ** Wish I could share the C grammar here...cut-and-paste instead. | |
200 | */ | |
201 | ||
202 | optType | |
203 | : /* empty */ { $$ = ctype_unknown; } | |
204 | | typeExpression { DPRINTF (("Type: %s", qtype_unparse ($1))); $$ = qtype_getType ($1); } | |
205 | ||
206 | typeExpression | |
207 | : completeType | |
208 | | completeType abstractDecl { $$ = qtype_newBase ($1, $2); } | |
209 | ||
210 | completeType | |
211 | : completeTypeAux { $$ = $1; } | |
212 | | completeType MT_BAR typeExpression | |
213 | { $$ = qtype_mergeAlt ($1, $3); } | |
214 | ||
215 | completeTypeAux | |
216 | : typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); } | |
217 | ||
218 | optCompleteType | |
219 | : /* empty */ { $$ = qtype_unknown (); } | |
220 | | completeType { $$ = $1; } | |
221 | ||
222 | ||
223 | abstractDecl | |
224 | : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); } | |
225 | | abstractDeclBase | |
226 | | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); } | |
227 | ||
228 | pointers | |
229 | : MT_STAR { $$ = 1; } | |
230 | | MT_STAR innerModsList { $$ = 1; } | |
231 | | MT_STAR pointers { $$ = 1 + $2; } | |
232 | | MT_STAR innerModsList pointers { $$ = 1 + $3; } | |
233 | ||
234 | innerMods | |
235 | : MT_CONST { /* ignored for now */; } | |
236 | | MT_VOLATILE { ; } | |
237 | ||
238 | innerModsList | |
239 | : innerMods { ; } | |
240 | | innerModsList innerMods { ; } | |
241 | ||
242 | abstractDeclBase | |
243 | : MT_LPAREN abstractDecl MT_RPAREN { $$ = ctype_expectFunction ($2); } | |
244 | | MT_LBRACKET MT_RBRACKET { $$ = ctype_makeArray (ctype_unknown); } | |
245 | | abstractDeclBase MT_LBRACKET MT_RBRACKET { $$ = ctype_makeArray ($1); } | |
246 | /* | |
247 | | abstractDeclBase MT_LBRACKET constantExpr MT_RBRACKET | |
248 | { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); } | |
249 | */ | |
250 | ||
251 | typeSpecifier | |
252 | : MT_CHAR { $$ = ctype_char; } | |
253 | | MT_INT { $$ = ctype_int; } | |
254 | | MT_FLOAT { $$ = ctype_float; } | |
255 | | MT_DOUBLE { $$ = ctype_double; } | |
256 | | MT_VOID { $$ = ctype_void; } | |
257 | | MT_ANYTYPE { $$ = ctype_unknown; } | |
258 | | MT_INTEGRALTYPE { $$ = ctype_anyintegral; } | |
259 | | MT_UNSIGNEDINTEGRALTYPE { $$ = ctype_unsignedintegral; } | |
260 | | MT_SIGNEDINTEGRALTYPE { $$ = ctype_signedintegral; } | |
261 | | typeName | |
262 | /* | suSpc | |
263 | | enumSpc | |
264 | | typeModifier NotType { $$ = ctype_fromQual ($1); } */ | |
265 | ||
266 | typeName | |
267 | : MT_IDENT { $$ = mtscanner_lookupType ($1); } | |
268 | ||
269 | valuesDeclaration | |
270 | : MT_ONEOF valuesList { $$ = mtValuesNode_create ($2); } | |
271 | ||
272 | valuesList | |
273 | : MT_IDENT { $$ = cstringList_single (mttok_getText ($1)); } | |
274 | | MT_IDENT MT_COMMA valuesList | |
275 | { $$ = cstringList_prepend ($3, mttok_getText ($1)); } | |
276 | ||
277 | defaultNode | |
278 | : MT_DEFAULT valueChoice { $$ = $2; } | |
279 | ||
280 | defaultsDeclaration | |
281 | : MT_DEFAULTS defaultDeclarationList { $$ = mtDefaultsNode_create ($1, $2); } | |
282 | ||
283 | defaultDeclarationList | |
284 | : contextSelection MT_ARROW valueChoice | |
285 | { $$ = mtDefaultsDeclList_single (mtDefaultsDecl_create ($1, $3)); } | |
286 | | contextSelection MT_ARROW valueChoice defaultDeclarationList | |
287 | { $$ = mtDefaultsDeclList_prepend ($4, mtDefaultsDecl_create ($1, $3)); } | |
288 | ||
289 | annotationsDeclaration | |
290 | : MT_ANNOTATIONS annotationsDeclarationList { $$ = mtAnnotationsNode_create ($2); } | |
291 | ||
292 | annotationsDeclarationList | |
293 | : annotationDeclaration { $$ = mtAnnotationList_single ($1); } | |
294 | | annotationDeclaration annotationsDeclarationList | |
295 | { $$ = mtAnnotationList_prepend ($2, $1); } | |
296 | ||
297 | annotationDeclaration | |
298 | : MT_IDENT optContextSelection MT_ARROW valueChoice | |
299 | { $$ = mtAnnotationDecl_create ($1, $2, $4); } | |
300 | ||
301 | mergeDeclaration | |
302 | : MT_MERGE mergeClauses { $$ = mtMergeNode_create ($2); } | |
303 | ||
304 | mergeClauses | |
305 | : mergeClause { $$ = mtMergeClauseList_single ($1); } | |
306 | | mergeClause mergeClauses { $$ = mtMergeClauseList_prepend ($2, $1); } | |
307 | ||
308 | mergeClause | |
309 | : mergeItem MT_PLUS mergeItem MT_ARROW transferAction | |
310 | { $$ = mtMergeClause_create ($1, $3, $5); } | |
311 | ||
312 | mergeItem | |
313 | : valueChoice { $$ = mtMergeItem_createValue ($1); } | |
314 | | MT_STAR { $$ = mtMergeItem_createStar ($1); } | |
315 | ||
316 | preconditionsDeclaration | |
317 | : MT_PRECONDITIONS transferClauses { $$ = $2; } | |
318 | ||
319 | postconditionsDeclaration | |
320 | : MT_POSTCONDITIONS transferClauses { $$ = $2; } | |
321 | ||
322 | transfersDeclaration | |
323 | : MT_TRANSFERS transferClauses { $$ = $2; } | |
324 | ||
325 | loseReferenceDeclaration | |
326 | : MT_LOSEREFERENCE lostClauses { $$ = $2; } | |
327 | ||
328 | lostClauses | |
329 | : lostClause { $$ = mtLoseReferenceList_single ($1); } | |
330 | | lostClause lostClauses { $$ = mtLoseReferenceList_prepend ($2, $1); } | |
331 | ||
332 | lostClause | |
333 | : valueChoice MT_ARROW errorAction { $$ = mtLoseReference_create ($1, $3); } | |
334 | ||
335 | transferClauses | |
336 | : transferClause { $$ = mtTransferClauseList_single ($1); } | |
337 | | transferClause transferClauses { $$ = mtTransferClauseList_prepend ($2, $1); } | |
338 | ||
339 | transferClause | |
340 | : valueChoice MT_AS valueChoice MT_ARROW transferAction | |
341 | { $$ = mtTransferClause_create ($1, $3, $5); } | |
342 | ||
343 | transferAction | |
344 | : valueChoice { $$ = mtTransferAction_createValue ($1); } | |
345 | | errorAction { $$ = $1; } | |
346 | ||
347 | errorAction | |
348 | : MT_ERROR { $$ = mtTransferAction_createError ($1); } | |
349 | | MT_ERROR MT_STRINGLIT { $$ = mtTransferAction_createErrorMessage ($2); } | |
350 | ||
351 | valueChoice | |
b072092f | 352 | : MT_IDENT |
28bf4b0b | 353 | |
354 | %% | |
355 | ||
356 | # include "bison.reset" | |
357 | ||
358 | extern char *yytext; | |
359 | ||
360 | static void mterror (char *s) | |
361 | { | |
b072092f | 362 | |
363 | if (s != NULL) | |
364 | { | |
365 | llparseerror | |
366 | (message ("Parse error in meta-state file: %s", cstring_fromChars (s))); | |
367 | } | |
368 | else | |
369 | { | |
370 | llparseerror | |
371 | (message ("Parse error in meta-state file")); | |
372 | } | |
373 | ||
28bf4b0b | 374 | } |
375 | ||
376 | static void yyprint (FILE *file, int type, YYSTYPE value) | |
377 | { | |
378 | cstring tname = mttok_unparse (value.tok); | |
379 | fprintf (file, " (%s)", cstring_toCharsSafe (tname)); | |
380 | cstring_free (tname); | |
381 | } | |
382 | ||
383 | ||
384 | ||
385 |