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