2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: splint@cs.virginia.edu
21 ** To report a bug: splint-bug@cs.virginia.edu
22 ** For more information: http://www.splint.org
27 ** Grammar for .mts files.
32 # include "bison.reset"
33 # include "splintMacros.nf"
37 extern ctype mtscanner_lookupType (mttok p_tok) /*@modifies p_tok@*/ ;
40 /*@i523@*/ /* can't include these here
41 # include "mtgrammar.h"
42 # include "mtscanner.h"
45 static /*@exits@*/ void mterror (char *);
47 /*@-noparams@*/ /* Can't list params since YYSTYPE isn't defined yet. */
48 static void yyprint (/*FILE *p_file, int p_type, YYSTYPE p_value */);
51 # define YYPRINT(file, type, value) yyprint (file, type, value)
55 # include "bison.head"
63 mtDeclarationNode mtdecl;
64 mtDeclarationPiece mtpiece;
65 mtDeclarationPieces mtpieces;
66 mtContextNode mtcontext;
67 mtValuesNode mtvalues;
68 mtDefaultsNode mtdefaults;
69 mtDefaultsDeclList mtdeflist;
70 mtAnnotationsNode mtannotations;
71 mtAnnotationList mtannotlist;
72 mtAnnotationDecl mtannotdecl;
74 mtMergeItem mtmergeitem;
75 mtMergeClauseList mtmergeclauselist;
76 mtMergeClause mtmergeclause;
77 mtTransferClauseList mttransferclauselist;
78 mtTransferClause mttransferclause;
79 mtTransferAction mttransferaction;
80 mtLoseReferenceList mtlosereferencelist;
81 mtLoseReference mtlosereference;
83 /*@only@*/ cstringList cstringlist;
85 /*@only@*/ qtype qtyp;
89 /* Don't forget to enter all tokens in mtscanner.c */
90 %token <tok> MT_BADTOK
93 %token <tok> MT_STATE MT_GLOBAL
95 %token <tok> MT_CONTEXT
98 %token <tok> MT_DEFAULTS MT_DEFAULT
99 %token <tok> MT_REFERENCE MT_PARAMETER MT_RESULT MT_CLAUSE MT_LITERAL MT_NULL
101 %token <tok> MT_ANNOTATIONS
102 %token <tok> MT_ARROW
104 %token <tok> MT_MERGE
105 %token <tok> MT_TRANSFERS MT_PRECONDITIONS MT_POSTCONDITIONS
106 %token <tok> MT_LOSEREFERENCE
109 %token <tok> MT_ERROR
111 %token <tok> MT_PLUS MT_STAR MT_BAR
112 %token <tok> MT_LPAREN MT_RPAREN
113 %token <tok> MT_LBRACKET MT_RBRACKET
114 %token <tok> MT_LBRACE MT_RBRACE
115 %token <tok> MT_COMMA
117 %token <tok> MT_CHAR MT_INT MT_FLOAT MT_DOUBLE MT_VOID MT_ANYTYPE MT_INTEGRALTYPE MT_UNSIGNEDINTEGRALTYPE
118 %token <tok> MT_SIGNEDINTEGRALTYPE
119 %token <tok> MT_CONST MT_VOLATILE
120 %token <tok> MT_STRINGLIT
121 %token <tok> MT_IDENT
123 %type <count> pointers
124 %type <ctyp> optType typeSpecifier typeName abstractDecl abstractDeclBase
125 %type <qtyp> typeExpression
126 %type <qtyp> completeType completeTypeAux optCompleteType
127 %type <mtpiece> declarationPiece
128 %type <mtcontext> contextDeclaration
129 %type <mtcontext> contextSelection optContextSelection
130 %type <mtvalues> valuesDeclaration
131 %type <tok> defaultNode
132 %type <mtdefaults> defaultsDeclaration
133 %type <mtdeflist> defaultDeclarationList
134 %type <mtannotations> annotationsDeclaration
135 %type <mtannotlist> annotationsDeclarationList
136 %type <mtannotdecl> annotationDeclaration
137 %type <mtmerge> mergeDeclaration
138 %type <mtmergeitem> mergeItem
139 %type <mtmergeclauselist> mergeClauses
140 %type <mtmergeclause> mergeClause
141 %type <mttransferclauselist> transfersDeclaration transferClauses preconditionsDeclaration postconditionsDeclaration
142 %type <mttransferclause> transferClause
143 %type <mttransferaction> transferAction errorAction
144 %type <mtlosereferencelist> loseReferenceDeclaration lostClauses
145 %type <mtlosereference> lostClause
146 %type <cstringlist> valuesList
147 %type <mtdecl> declarationNode
148 %type <mtpieces> declarationPieces
149 %type <tok> valueChoice
161 : MT_STATE declarationNode MT_END
162 { mtreader_processDeclaration ($2); }
163 | MT_GLOBAL MT_STATE declarationNode MT_END
164 { mtreader_processGlobalDeclaration ($3); }
167 : MT_IDENT declarationPieces
168 { $$ = mtDeclarationNode_create ($1, $2); }
171 : { $$ = mtDeclarationPieces_create (); }
172 | declarationPiece declarationPieces
173 { $$ = mtDeclarationPieces_append ($2, $1); }
176 : contextDeclaration { $$ = mtDeclarationPiece_createContext ($1); }
177 | valuesDeclaration { $$ = mtDeclarationPiece_createValues ($1); }
178 | defaultsDeclaration { $$ = mtDeclarationPiece_createDefaults ($1); }
179 | defaultNode { $$ = mtDeclarationPiece_createValueDefault ($1); }
180 | annotationsDeclaration { $$ = mtDeclarationPiece_createAnnotations ($1); }
181 | mergeDeclaration { $$ = mtDeclarationPiece_createMerge ($1); }
182 | transfersDeclaration { $$ = mtDeclarationPiece_createTransfers ($1); }
183 | preconditionsDeclaration { $$ = mtDeclarationPiece_createPreconditions ($1); }
184 | postconditionsDeclaration { $$ = mtDeclarationPiece_createPostconditions ($1); }
185 | loseReferenceDeclaration { $$ = mtDeclarationPiece_createLosers ($1); }
188 : MT_CONTEXT contextSelection { $$ = $2; }
189 /* ??? should it be a list? */
192 : /* empty */ { $$ = mtContextNode_createAny (); }
196 : MT_PARAMETER optType { $$ = mtContextNode_createParameter ($2); }
197 | MT_REFERENCE optType { $$ = mtContextNode_createReference ($2); }
198 | MT_RESULT optType { $$ = mtContextNode_createResult ($2); }
199 | MT_CLAUSE optType { $$ = mtContextNode_createClause ($2); }
200 | MT_LITERAL optType { $$ = mtContextNode_createLiteral ($2); }
201 | MT_NULL optType { $$ = mtContextNode_createNull ($2); }
204 ** Wish I could share the C grammar here...cut-and-paste instead.
208 : /* empty */ { $$ = ctype_unknown; }
209 | typeExpression { DPRINTF (("Type: %s", qtype_unparse ($1))); $$ = qtype_getType ($1); }
213 | completeType abstractDecl { $$ = qtype_newBase ($1, $2); }
216 : completeTypeAux { $$ = $1; }
217 | completeType MT_BAR typeExpression
218 { $$ = qtype_mergeAlt ($1, $3); }
221 : typeSpecifier optCompleteType { $$ = qtype_combine ($2, $1); }
224 : /* empty */ { $$ = qtype_unknown (); }
225 | completeType { $$ = $1; }
229 : pointers { $$ = ctype_adjustPointers ($1, ctype_unknown); }
231 | pointers abstractDeclBase { $$ = ctype_adjustPointers ($1, $2); }
234 : MT_STAR { $$ = 1; }
235 | MT_STAR innerModsList { $$ = 1; }
236 | MT_STAR pointers { $$ = 1 + $2; }
237 | MT_STAR innerModsList pointers { $$ = 1 + $3; }
240 : MT_CONST { /* ignored for now */; }
245 | innerModsList innerMods { ; }
248 : MT_LPAREN abstractDecl MT_RPAREN { $$ = ctype_expectFunction ($2); }
249 | MT_LBRACKET MT_RBRACKET { $$ = ctype_makeArray (ctype_unknown); }
250 | abstractDeclBase MT_LBRACKET MT_RBRACKET { $$ = ctype_makeArray ($1); }
252 | abstractDeclBase MT_LBRACKET constantExpr MT_RBRACKET
253 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
257 : MT_CHAR { $$ = ctype_char; }
258 | MT_INT { $$ = ctype_int; }
259 | MT_FLOAT { $$ = ctype_float; }
260 | MT_DOUBLE { $$ = ctype_double; }
261 | MT_VOID { $$ = ctype_void; }
262 | MT_ANYTYPE { $$ = ctype_unknown; }
263 | MT_INTEGRALTYPE { $$ = ctype_anyintegral; }
264 | MT_UNSIGNEDINTEGRALTYPE { $$ = ctype_unsignedintegral; }
265 | MT_SIGNEDINTEGRALTYPE { $$ = ctype_signedintegral; }
269 | typeModifier NotType { $$ = ctype_fromQual ($1); } */
272 : MT_IDENT { $$ = mtscanner_lookupType ($1); }
275 : MT_ONEOF valuesList { $$ = mtValuesNode_create ($2); }
278 : MT_IDENT { $$ = cstringList_single (mttok_getText ($1)); }
279 | MT_IDENT MT_COMMA valuesList
280 { $$ = cstringList_prepend ($3, mttok_getText ($1)); }
283 : MT_DEFAULT valueChoice { $$ = $2; }
286 : MT_DEFAULTS defaultDeclarationList { $$ = mtDefaultsNode_create ($1, $2); }
288 defaultDeclarationList
289 : contextSelection MT_ARROW valueChoice
290 { $$ = mtDefaultsDeclList_single (mtDefaultsDecl_create ($1, $3)); }
291 | contextSelection MT_ARROW valueChoice defaultDeclarationList
292 { $$ = mtDefaultsDeclList_prepend ($4, mtDefaultsDecl_create ($1, $3)); }
294 annotationsDeclaration
295 : MT_ANNOTATIONS annotationsDeclarationList { $$ = mtAnnotationsNode_create ($2); }
297 annotationsDeclarationList
298 : annotationDeclaration { $$ = mtAnnotationList_single ($1); }
299 | annotationDeclaration annotationsDeclarationList
300 { $$ = mtAnnotationList_prepend ($2, $1); }
302 annotationDeclaration
303 : MT_IDENT optContextSelection MT_ARROW valueChoice
304 { $$ = mtAnnotationDecl_create ($1, $2, $4); }
307 : MT_MERGE mergeClauses { $$ = mtMergeNode_create ($2); }
310 : mergeClause { $$ = mtMergeClauseList_single ($1); }
311 | mergeClause mergeClauses { $$ = mtMergeClauseList_prepend ($2, $1); }
314 : mergeItem MT_PLUS mergeItem MT_ARROW transferAction
315 { $$ = mtMergeClause_create ($1, $3, $5); }
318 : valueChoice { $$ = mtMergeItem_createValue ($1); }
319 | MT_STAR { $$ = mtMergeItem_createStar ($1); }
321 preconditionsDeclaration
322 : MT_PRECONDITIONS transferClauses { $$ = $2; }
324 postconditionsDeclaration
325 : MT_POSTCONDITIONS transferClauses { $$ = $2; }
328 : MT_TRANSFERS transferClauses { $$ = $2; }
330 loseReferenceDeclaration
331 : MT_LOSEREFERENCE lostClauses { $$ = $2; }
334 : lostClause { $$ = mtLoseReferenceList_single ($1); }
335 | lostClause lostClauses { $$ = mtLoseReferenceList_prepend ($2, $1); }
338 : valueChoice MT_ARROW errorAction { $$ = mtLoseReference_create ($1, $3); }
341 : transferClause { $$ = mtTransferClauseList_single ($1); }
342 | transferClause transferClauses { $$ = mtTransferClauseList_prepend ($2, $1); }
345 : valueChoice MT_AS valueChoice MT_ARROW transferAction
346 { $$ = mtTransferClause_create ($1, $3, $5); }
349 : valueChoice { $$ = mtTransferAction_createValue ($1); }
350 | errorAction { $$ = $1; }
353 : MT_ERROR { $$ = mtTransferAction_createError ($1); }
354 | MT_ERROR MT_STRINGLIT { $$ = mtTransferAction_createErrorMessage ($2); }
361 # include "bison.reset"
365 static void mterror (char *s)
371 (message ("Parse error in meta-state file: %s", cstring_fromChars (s)));
376 (message ("Parse error in meta-state file"));
381 static void yyprint (FILE *file, int type, YYSTYPE value)
383 cstring tname = mttok_unparse (value.tok);
384 fprintf (file, " (%s)", cstring_toCharsSafe (tname));
385 cstring_free (tname);