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"
30 # include "mtincludes.h"
32 static /*@exits@*/ void mterror (char *);
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 */);
38 # define YYPRINT(file, type, value) yyprint (file, type, value)
42 # include "bison.head"
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;
61 mtMergeItem mtmergeitem;
62 mtMergeClauseList mtmergeclauselist;
63 mtMergeClause mtmergeclause;
64 mtTransferClauseList mttransferclauselist;
65 mtTransferClause mttransferclause;
66 mtTransferAction mttransferaction;
67 mtLoseReferenceList mtlosereferencelist;
68 mtLoseReference mtlosereference;
70 /*@only@*/ cstringList cstringlist;
72 /*@only@*/ qtype qtyp;
76 /* Don't forget to enter all tokens in mtscanner.c */
77 %token <tok> MT_BADTOK
80 %token <tok> MT_STATE MT_GLOBAL
82 %token <tok> MT_CONTEXT
85 %token <tok> MT_DEFAULTS MT_DEFAULT
86 %token <tok> MT_REFERENCE MT_PARAMETER MT_CLAUSE
88 %token <tok> MT_ANNOTATIONS
92 %token <tok> MT_TRANSFERS MT_PRECONDITIONS MT_POSTCONDITIONS
93 %token <tok> MT_LOSEREFERENCE
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
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
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
148 : MT_STATE declarationNode MT_END
149 { mtreader_processDeclaration ($2); }
150 | MT_GLOBAL MT_STATE declarationNode MT_END
151 { mtreader_processGlobalDeclaration ($3); }
154 : MT_IDENT declarationPieces
155 { $$ = mtDeclarationNode_create ($1, $2); }
158 : { $$ = mtDeclarationPieces_create (); }
159 | declarationPiece declarationPieces
160 { $$ = mtDeclarationPieces_append ($2, $1); }
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); }
175 : MT_CONTEXT contextSelection { $$ = $2; }
176 /* ??? should it be a list? */
179 : /* empty */ { $$ = mtContextNode_createAny (); }
183 : MT_PARAMETER optType { $$ = mtContextNode_createParameter ($2); }
184 | MT_REFERENCE optType { $$ = mtContextNode_createReference ($2); }
185 | MT_CLAUSE optType { $$ = mtContextNode_createClause ($2); }
188 ** Wish I could share the C grammar here...cut-and-paste instead.
192 : /* empty */ { $$ = ctype_unknown; }
193 | typeExpression { DPRINTF (("Type: %s", qtype_unparse ($1))); $$ = qtype_getType ($1); }
197 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
200 : completeTypeAux { $$ = $1; }
201 | completeType MT_BAR typeExpression
202 { $$ = qtype_mergeAlt ($1, $3); }
205 : typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
208 : /* empty */ { $$ = qtype_unknown (); }
209 | completeType { $$ = $1; }
213 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
215 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
218 : MT_STAR { $$ = 1; }
219 | MT_STAR innerModsList { $$ = 1; }
220 | MT_STAR pointers { $$ = 1 + $2; }
221 | MT_STAR innerModsList pointers { $$ = 1 + $3; }
224 : MT_CONST { /* ignored for now */; }
229 | innerModsList innerMods { ; }
232 : MT_LPAREN abstractDecl MT_RPAREN { $$ = ctype_expectFunction ($2); }
233 | MT_LBRACKET MT_RBRACKET { $$ = ctype_makeArray (ctype_unknown); }
234 | abstractDeclBase MT_LBRACKET MT_RBRACKET { $$ = ctype_makeArray ($1); }
236 | abstractDeclBase MT_LBRACKET constantExpr MT_RBRACKET
237 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
241 : MT_CHAR { $$ = ctype_char; }
242 | MT_INT { $$ = ctype_int; }
243 | MT_FLOAT { $$ = ctype_float; }
244 | MT_DOUBLE { $$ = ctype_double; }
245 | MT_VOID { $$ = ctype_void; }
246 | MT_ANYTYPE { $$ = ctype_unknown; }
247 | MT_INTEGRALTYPE { $$ = ctype_anyintegral; }
248 | MT_UNSIGNEDINTEGRALTYPE { $$ = ctype_unsignedintegral; }
249 | MT_SIGNEDINTEGRALTYPE { $$ = ctype_signedintegral; }
253 | typeModifier NotType { $$ = ctype_fromQual ($1); } */
256 : MT_IDENT { $$ = mtscanner_lookupType ($1); }
259 : MT_ONEOF valuesList { $$ = mtValuesNode_create ($2); }
262 : MT_IDENT { $$ = cstringList_single (mttok_getText ($1)); }
263 | MT_IDENT MT_COMMA valuesList
264 { $$ = cstringList_prepend ($3, mttok_getText ($1)); }
267 : MT_DEFAULT valueChoice { $$ = $2; }
270 : MT_DEFAULTS defaultDeclarationList { $$ = mtDefaultsNode_create ($1, $2); }
272 defaultDeclarationList
273 : contextSelection MT_ARROW valueChoice
274 { $$ = mtDefaultsDeclList_single (mtDefaultsDecl_create ($1, $3)); }
275 | contextSelection MT_ARROW valueChoice defaultDeclarationList
276 { $$ = mtDefaultsDeclList_prepend ($4, mtDefaultsDecl_create ($1, $3)); }
278 annotationsDeclaration
279 : MT_ANNOTATIONS annotationsDeclarationList { $$ = mtAnnotationsNode_create ($2); }
281 annotationsDeclarationList
282 : annotationDeclaration { $$ = mtAnnotationList_single ($1); }
283 | annotationDeclaration annotationsDeclarationList
284 { $$ = mtAnnotationList_prepend ($2, $1); }
286 annotationDeclaration
287 : MT_IDENT optContextSelection MT_ARROW valueChoice
288 { $$ = mtAnnotationDecl_create ($1, $2, $4); }
291 : MT_MERGE mergeClauses { $$ = mtMergeNode_create ($2); }
294 : mergeClause { $$ = mtMergeClauseList_single ($1); }
295 | mergeClause mergeClauses { $$ = mtMergeClauseList_prepend ($2, $1); }
298 : mergeItem MT_PLUS mergeItem MT_ARROW transferAction
299 { $$ = mtMergeClause_create ($1, $3, $5); }
302 : valueChoice { $$ = mtMergeItem_createValue ($1); }
303 | MT_STAR { $$ = mtMergeItem_createStar ($1); }
305 preconditionsDeclaration
306 : MT_PRECONDITIONS transferClauses { $$ = $2; }
308 postconditionsDeclaration
309 : MT_POSTCONDITIONS transferClauses { $$ = $2; }
312 : MT_TRANSFERS transferClauses { $$ = $2; }
314 loseReferenceDeclaration
315 : MT_LOSEREFERENCE lostClauses { $$ = $2; }
318 : lostClause { $$ = mtLoseReferenceList_single ($1); }
319 | lostClause lostClauses { $$ = mtLoseReferenceList_prepend ($2, $1); }
322 : valueChoice MT_ARROW errorAction { $$ = mtLoseReference_create ($1, $3); }
325 : transferClause { $$ = mtTransferClauseList_single ($1); }
326 | transferClause transferClauses { $$ = mtTransferClauseList_prepend ($2, $1); }
329 : valueChoice MT_AS valueChoice MT_ARROW transferAction
330 { $$ = mtTransferClause_create ($1, $3, $5); }
333 : valueChoice { $$ = mtTransferAction_createValue ($1); }
334 | errorAction { $$ = $1; }
337 : MT_ERROR { $$ = mtTransferAction_createError ($1); }
338 | MT_ERROR MT_STRINGLIT { $$ = mtTransferAction_createErrorMessage ($2); }
341 : MT_IDENT { $$ = $1; }
345 # include "bison.reset"
349 static void mterror (char *s)
353 ("There has been a problem in the .mts parser."));
356 static void yyprint (FILE *file, int type, YYSTYPE value)
358 cstring tname = mttok_unparse (value.tok);
359 fprintf (file, " (%s)", cstring_toCharsSafe (tname));
360 cstring_free (tname);