2 ** Copyright (c) Massachusetts Institute of Technology 1994-1998.
3 ** All Rights Reserved.
4 ** Unpublished rights reserved under the copyright laws of
7 ** THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 ** OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
10 ** This code is distributed freely and may be used freely under the
11 ** following conditions:
13 ** 1. This notice may not be removed or altered.
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).
22 ** Grammar for .mts files.
27 # include "bison.reset"
28 # include "lclintMacros.nf"
32 extern ctype mtscanner_lookupType (mttok p_tok) /*@modifies p_tok@*/ ;
35 /*@i523@*/ /* can't include these here
36 # include "mtgrammar.h"
37 # include "mtscanner.h"
40 static /*@exits@*/ void mterror (char *);
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 */);
46 # define YYPRINT(file, type, value) yyprint (file, type, value)
50 # include "bison.head"
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;
69 mtMergeItem mtmergeitem;
70 mtMergeClauseList mtmergeclauselist;
71 mtMergeClause mtmergeclause;
72 mtTransferClauseList mttransferclauselist;
73 mtTransferClause mttransferclause;
74 mtTransferAction mttransferaction;
75 mtLoseReferenceList mtlosereferencelist;
76 mtLoseReference mtlosereference;
78 /*@only@*/ cstringList cstringlist;
80 /*@only@*/ qtype qtyp;
84 /* Don't forget to enter all tokens in mtscanner.c */
85 %token <tok> MT_BADTOK
88 %token <tok> MT_STATE MT_GLOBAL
90 %token <tok> MT_CONTEXT
93 %token <tok> MT_DEFAULTS MT_DEFAULT
94 %token <tok> MT_REFERENCE MT_PARAMETER MT_RESULT MT_CLAUSE MT_LITERAL MT_NULL
96 %token <tok> MT_ANNOTATIONS
100 %token <tok> MT_TRANSFERS MT_PRECONDITIONS MT_POSTCONDITIONS
101 %token <tok> MT_LOSEREFERENCE
104 %token <tok> MT_ERROR
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
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
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
156 : MT_STATE declarationNode MT_END
157 { mtreader_processDeclaration ($2); }
158 | MT_GLOBAL MT_STATE declarationNode MT_END
159 { mtreader_processGlobalDeclaration ($3); }
162 : MT_IDENT declarationPieces
163 { $$ = mtDeclarationNode_create ($1, $2); }
166 : { $$ = mtDeclarationPieces_create (); }
167 | declarationPiece declarationPieces
168 { $$ = mtDeclarationPieces_append ($2, $1); }
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); }
183 : MT_CONTEXT contextSelection { $$ = $2; }
184 /* ??? should it be a list? */
187 : /* empty */ { $$ = mtContextNode_createAny (); }
191 : MT_PARAMETER optType { $$ = mtContextNode_createParameter ($2); }
192 | MT_REFERENCE optType { $$ = mtContextNode_createReference ($2); }
193 | MT_RESULT optType { $$ = mtContextNode_createResult ($2); }
194 | MT_CLAUSE optType { $$ = mtContextNode_createClause ($2); }
195 | MT_LITERAL optType { $$ = mtContextNode_createLiteral ($2); }
196 | MT_NULL optType { $$ = mtContextNode_createNull ($2); }
199 ** Wish I could share the C grammar here...cut-and-paste instead.
203 : /* empty */ { $$ = ctype_unknown; }
204 | typeExpression { DPRINTF (("Type: %s", qtype_unparse ($1))); $$ = qtype_getType ($1); }
208 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
211 : completeTypeAux { $$ = $1; }
212 | completeType MT_BAR typeExpression
213 { $$ = qtype_mergeAlt ($1, $3); }
216 : typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
219 : /* empty */ { $$ = qtype_unknown (); }
220 | completeType { $$ = $1; }
224 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
226 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
229 : MT_STAR { $$ = 1; }
230 | MT_STAR innerModsList { $$ = 1; }
231 | MT_STAR pointers { $$ = 1 + $2; }
232 | MT_STAR innerModsList pointers { $$ = 1 + $3; }
235 : MT_CONST { /* ignored for now */; }
240 | innerModsList innerMods { ; }
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); }
247 | abstractDeclBase MT_LBRACKET constantExpr MT_RBRACKET
248 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
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; }
264 | typeModifier NotType { $$ = ctype_fromQual ($1); } */
267 : MT_IDENT { $$ = mtscanner_lookupType ($1); }
270 : MT_ONEOF valuesList { $$ = mtValuesNode_create ($2); }
273 : MT_IDENT { $$ = cstringList_single (mttok_getText ($1)); }
274 | MT_IDENT MT_COMMA valuesList
275 { $$ = cstringList_prepend ($3, mttok_getText ($1)); }
278 : MT_DEFAULT valueChoice { $$ = $2; }
281 : MT_DEFAULTS defaultDeclarationList { $$ = mtDefaultsNode_create ($1, $2); }
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)); }
289 annotationsDeclaration
290 : MT_ANNOTATIONS annotationsDeclarationList { $$ = mtAnnotationsNode_create ($2); }
292 annotationsDeclarationList
293 : annotationDeclaration { $$ = mtAnnotationList_single ($1); }
294 | annotationDeclaration annotationsDeclarationList
295 { $$ = mtAnnotationList_prepend ($2, $1); }
297 annotationDeclaration
298 : MT_IDENT optContextSelection MT_ARROW valueChoice
299 { $$ = mtAnnotationDecl_create ($1, $2, $4); }
302 : MT_MERGE mergeClauses { $$ = mtMergeNode_create ($2); }
305 : mergeClause { $$ = mtMergeClauseList_single ($1); }
306 | mergeClause mergeClauses { $$ = mtMergeClauseList_prepend ($2, $1); }
309 : mergeItem MT_PLUS mergeItem MT_ARROW transferAction
310 { $$ = mtMergeClause_create ($1, $3, $5); }
313 : valueChoice { $$ = mtMergeItem_createValue ($1); }
314 | MT_STAR { $$ = mtMergeItem_createStar ($1); }
316 preconditionsDeclaration
317 : MT_PRECONDITIONS transferClauses { $$ = $2; }
319 postconditionsDeclaration
320 : MT_POSTCONDITIONS transferClauses { $$ = $2; }
323 : MT_TRANSFERS transferClauses { $$ = $2; }
325 loseReferenceDeclaration
326 : MT_LOSEREFERENCE lostClauses { $$ = $2; }
329 : lostClause { $$ = mtLoseReferenceList_single ($1); }
330 | lostClause lostClauses { $$ = mtLoseReferenceList_prepend ($2, $1); }
333 : valueChoice MT_ARROW errorAction { $$ = mtLoseReference_create ($1, $3); }
336 : transferClause { $$ = mtTransferClauseList_single ($1); }
337 | transferClause transferClauses { $$ = mtTransferClauseList_prepend ($2, $1); }
340 : valueChoice MT_AS valueChoice MT_ARROW transferAction
341 { $$ = mtTransferClause_create ($1, $3, $5); }
344 : valueChoice { $$ = mtTransferAction_createValue ($1); }
345 | errorAction { $$ = $1; }
348 : MT_ERROR { $$ = mtTransferAction_createError ($1); }
349 | MT_ERROR MT_STRINGLIT { $$ = mtTransferAction_createErrorMessage ($2); }
356 # include "bison.reset"
360 static void mterror (char *s)
366 (message ("Parse error in meta-state file: %s", cstring_fromChars (s)));
371 (message ("Parse error in meta-state file"));
376 static void yyprint (FILE *file, int type, YYSTYPE value)
378 cstring tname = mttok_unparse (value.tok);
379 fprintf (file, " (%s)", cstring_toCharsSafe (tname));
380 cstring_free (tname);