2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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@*/ ;
42 # include "bison.head"
47 %define api.prefix
{mt
}
52 mtDeclarationNode mtdecl
;
53 mtDeclarationPiece mtpiece
;
54 mtDeclarationPieces mtpieces
;
55 mtContextNode mtcontext
;
56 mtValuesNode mtvalues
;
57 mtDefaultsNode mtdefaults
;
58 mtDefaultsDeclList mtdeflist
;
59 mtAnnotationsNode mtannotations
;
60 mtAnnotationList mtannotlist
;
61 mtAnnotationDecl mtannotdecl
;
63 mtMergeItem mtmergeitem
;
64 mtMergeClauseList mtmergeclauselist
;
65 mtMergeClause mtmergeclause
;
66 mtTransferClauseList mttransferclauselist
;
67 mtTransferClause mttransferclause
;
68 mtTransferAction mttransferaction
;
69 mtLoseReferenceList mtlosereferencelist
;
70 mtLoseReference mtlosereference
;
72 /*@only@*/ cstringList cstringlist
;
74 /*@only@*/ qtype qtyp
;
80 extern
int mtlex
(MTSTYPE
*p_mtlval
) /*@modifies internalState, p_mtlval@*/ ;
82 static /*@noreturn@*/ void mterror
(char *);
83 static void mtprint
(FILE *file
, int type
, MTSTYPE value
);
84 # define YYPRINT(file, type, value) mtprint (file, type, value)
87 /* Don't forget to enter all tokens in mtscanner.c */
88 %token
<tok
> MT_BADTOK
91 %token
<tok
> MT_STATE MT_GLOBAL
93 %token
<tok
> MT_CONTEXT
96 %token
<tok
> MT_DEFAULTS MT_DEFAULT
97 %token
<tok
> MT_REFERENCE MT_PARAMETER MT_RESULT MT_CLAUSE MT_LITERAL MT_NULL
99 %token
<tok
> MT_ANNOTATIONS
100 %token
<tok
> MT_ARROW
102 %token
<tok
> MT_MERGE
103 %token
<tok
> MT_TRANSFERS MT_PRECONDITIONS MT_POSTCONDITIONS
104 %token
<tok
> MT_LOSEREFERENCE
107 %token
<tok
> MT_ERROR
109 %token
<tok
> MT_PLUS MT_STAR MT_BAR
110 %token
<tok
> MT_LPAREN MT_RPAREN
111 %token
<tok
> MT_LBRACKET MT_RBRACKET
112 %token
<tok
> MT_LBRACE MT_RBRACE
113 %token
<tok
> MT_COMMA
115 %token
<tok
> MT_CHAR MT_INT MT_FLOAT MT_DOUBLE MT_VOID MT_ANYTYPE MT_INTEGRALTYPE MT_UNSIGNEDINTEGRALTYPE
116 %token
<tok
> MT_SIGNEDINTEGRALTYPE
117 %token
<tok
> MT_CONST MT_VOLATILE MT_RESTRICT
118 %token
<tok
> MT_STRINGLIT
119 %token
<tok
> MT_IDENT
121 %type
<pointers
> pointers
122 %type
<ctyp
> optType typeSpecifier typeName abstractDecl abstractDeclBase
123 %type
<qtyp
> typeExpression
124 %type
<qtyp
> completeType completeTypeAux optCompleteType
125 %type
<mtpiece
> declarationPiece
126 %type
<mtcontext
> contextDeclaration
127 %type
<mtcontext
> contextSelection optContextSelection
128 %type
<mtvalues
> valuesDeclaration
129 %type
<tok
> defaultNode
130 %type
<mtdefaults
> defaultsDeclaration
131 %type
<mtdeflist
> defaultDeclarationList
132 %type
<mtannotations
> annotationsDeclaration
133 %type
<mtannotlist
> annotationsDeclarationList
134 %type
<mtannotdecl
> annotationDeclaration
135 %type
<mtmerge
> mergeDeclaration
136 %type
<mtmergeitem
> mergeItem
137 %type
<mtmergeclauselist
> mergeClauses
138 %type
<mtmergeclause
> mergeClause
139 %type
<mttransferclauselist
> transfersDeclaration transferClauses preconditionsDeclaration postconditionsDeclaration
140 %type
<mttransferclause
> transferClause
141 %type
<mttransferaction
> transferAction errorAction
142 %type
<mtlosereferencelist
> loseReferenceDeclaration lostClauses
143 %type
<mtlosereference
> lostClause
144 %type
<cstringlist
> valuesList
145 %type
<mtdecl
> declarationNode
146 %type
<mtpieces
> declarationPieces
147 %type
<tok
> valueChoice
148 %type
<quals
> innerModsList
149 %type
<qual
> innerMods
161 : MT_STATE declarationNode MT_END
162 { mtreader_processDeclaration
($2); }
163 | MT_GLOBAL MT_STATE declarationNode MT_END
164 { mtreader_processGlobalDeclaration
($3); }
168 : MT_IDENT declarationPieces
169 { $$
= mtDeclarationNode_create
($1, $2); }
173 : { $$
= mtDeclarationPieces_create
(); }
174 | declarationPiece declarationPieces
175 { $$
= mtDeclarationPieces_append
($2, $1); }
179 : contextDeclaration
{ $$
= mtDeclarationPiece_createContext
($1); }
180 | valuesDeclaration
{ $$
= mtDeclarationPiece_createValues
($1); }
181 | defaultsDeclaration
{ $$
= mtDeclarationPiece_createDefaults
($1); }
182 | defaultNode
{ $$
= mtDeclarationPiece_createValueDefault
($1); }
183 | annotationsDeclaration
{ $$
= mtDeclarationPiece_createAnnotations
($1); }
184 | mergeDeclaration
{ $$
= mtDeclarationPiece_createMerge
($1); }
185 | transfersDeclaration
{ $$
= mtDeclarationPiece_createTransfers
($1); }
186 | preconditionsDeclaration
{ $$
= mtDeclarationPiece_createPreconditions
($1); }
187 | postconditionsDeclaration
{ $$
= mtDeclarationPiece_createPostconditions
($1); }
188 | loseReferenceDeclaration
{ $$
= mtDeclarationPiece_createLosers
($1); }
192 : MT_CONTEXT contextSelection
{ $$
= $2; }
193 /* ??? should it be a list? */
197 : /* empty */ { $$
= mtContextNode_createAny
(); }
202 : MT_PARAMETER optType
{ $$
= mtContextNode_createParameter
($2); }
203 | MT_REFERENCE optType
{ $$
= mtContextNode_createReference
($2); }
204 | MT_RESULT optType
{ $$
= mtContextNode_createResult
($2); }
205 | MT_CLAUSE optType
{ $$
= mtContextNode_createClause
($2); }
206 | MT_LITERAL optType
{ $$
= mtContextNode_createLiteral
($2); }
207 | MT_NULL optType
{ $$
= mtContextNode_createNull
($2); }
211 ** Wish I could share the C grammar here...cut-and-paste instead.
215 : /* empty */ { $$
= ctype_unknown
; }
216 | typeExpression
{ DPRINTF
(("Type: %s", qtype_unparse
($1))); $$
= qtype_getType
($1); }
221 | completeType abstractDecl
{ $$
= qtype_newBase
($1, $2); }
225 : completeTypeAux
{ $$
= $1; }
226 | completeType MT_BAR typeExpression
227 { $$
= qtype_mergeAlt
($1, $3); }
231 : typeSpecifier optCompleteType
{ $$
= qtype_combine
($2, $1); }
235 : /* empty */ { $$
= qtype_unknown
(); }
236 | completeType
{ $$
= $1; }
240 : pointers
{ $$
= ctype_adjustPointers
($1, ctype_unknown
); }
242 | pointers abstractDeclBase
{ $$
= ctype_adjustPointers
($1, $2); }
246 : MT_STAR
{ $$
= pointers_createMt
($1); }
247 | MT_STAR innerModsList
{ $$
= pointers_createModsMt
($1, $2); }
248 | MT_STAR pointers
{ $$
= pointers_extend
(pointers_createMt
($1), $2); }
249 | MT_STAR innerModsList pointers
{ $$
= pointers_extend
(pointers_createModsMt
($1, $2), $3); }
253 : MT_CONST
{ $$
= qual_createConst
(); }
254 | MT_VOLATILE
{ $$
= qual_createVolatile
(); }
255 | MT_RESTRICT
{ $$
= qual_createRestrict
(); }
259 : innerMods
{ $$
= qualList_single
($1); }
260 | innerModsList innerMods
{ $$
= qualList_add
($1, $2); }
264 : MT_LPAREN abstractDecl MT_RPAREN
{ $$
= ctype_expectFunction
($2); }
265 | MT_LBRACKET MT_RBRACKET
{ $$
= ctype_makeArray
(ctype_unknown
); }
266 | abstractDeclBase MT_LBRACKET MT_RBRACKET
{ $$
= ctype_makeArray
($1); }
268 | abstractDeclBase MT_LBRACKET constantExpr MT_RBRACKET
269 { $$ = ctype_makeFixedArray ($1, exprNode_getLongValue ($3)); }
274 : MT_CHAR
{ $$
= ctype_char
; }
275 | MT_INT
{ $$
= ctype_int
; }
276 | MT_FLOAT
{ $$
= ctype_float
; }
277 | MT_DOUBLE
{ $$
= ctype_double
; }
278 | MT_VOID
{ $$
= ctype_void
; }
279 | MT_ANYTYPE
{ $$
= ctype_unknown
; }
280 | MT_INTEGRALTYPE
{ $$
= ctype_anyintegral
; }
281 | MT_UNSIGNEDINTEGRALTYPE
{ $$
= ctype_unsignedintegral
; }
282 | MT_SIGNEDINTEGRALTYPE
{ $$
= ctype_signedintegral
; }
286 | typeModifier NotType { $$ = ctype_fromQual ($1); } */
290 : MT_IDENT
{ $$
= mtscanner_lookupType
($1); }
294 : MT_ONEOF valuesList
{ $$
= mtValuesNode_create
($2); }
298 : MT_IDENT
{ $$
= cstringList_single
(mttok_getText
($1)); }
299 | MT_IDENT MT_COMMA valuesList
300 { $$
= cstringList_prepend
($3, mttok_getText
($1)); }
304 : MT_DEFAULT valueChoice
{ $$
= $2; }
308 : MT_DEFAULTS defaultDeclarationList
{ $$
= mtDefaultsNode_create
($1, $2); }
311 defaultDeclarationList
312 : contextSelection MT_ARROW valueChoice
313 { $$
= mtDefaultsDeclList_single
(mtDefaultsDecl_create
($1, $3)); }
314 | contextSelection MT_ARROW valueChoice defaultDeclarationList
315 { $$
= mtDefaultsDeclList_prepend
($4, mtDefaultsDecl_create
($1, $3)); }
318 annotationsDeclaration
319 : MT_ANNOTATIONS annotationsDeclarationList
{ $$
= mtAnnotationsNode_create
($2); }
322 annotationsDeclarationList
323 : annotationDeclaration
{ $$
= mtAnnotationList_single
($1); }
324 | annotationDeclaration annotationsDeclarationList
325 { $$
= mtAnnotationList_prepend
($2, $1); }
328 annotationDeclaration
329 : MT_IDENT optContextSelection MT_ARROW valueChoice
330 { $$
= mtAnnotationDecl_create
($1, $2, $4); }
334 : MT_MERGE mergeClauses
{ $$
= mtMergeNode_create
($2); }
338 : mergeClause
{ $$
= mtMergeClauseList_single
($1); }
339 | mergeClause mergeClauses
{ $$
= mtMergeClauseList_prepend
($2, $1); }
343 : mergeItem MT_PLUS mergeItem MT_ARROW transferAction
344 { $$
= mtMergeClause_create
($1, $3, $5); }
348 : valueChoice
{ $$
= mtMergeItem_createValue
($1); }
349 | MT_STAR
{ $$
= mtMergeItem_createStar
($1); }
352 preconditionsDeclaration
353 : MT_PRECONDITIONS transferClauses
{ $$
= $2; }
356 postconditionsDeclaration
357 : MT_POSTCONDITIONS transferClauses
{ $$
= $2; }
361 : MT_TRANSFERS transferClauses
{ $$
= $2; }
364 loseReferenceDeclaration
365 : MT_LOSEREFERENCE lostClauses
{ $$
= $2; }
369 : lostClause
{ $$
= mtLoseReferenceList_single
($1); }
370 | lostClause lostClauses
{ $$
= mtLoseReferenceList_prepend
($2, $1); }
374 : valueChoice MT_ARROW errorAction
{ $$
= mtLoseReference_create
($1, $3); }
378 : transferClause
{ $$
= mtTransferClauseList_single
($1); }
379 | transferClause transferClauses
{ $$
= mtTransferClauseList_prepend
($2, $1); }
383 : valueChoice MT_AS valueChoice MT_ARROW transferAction
384 { $$
= mtTransferClause_create
($1, $3, $5); }
388 : valueChoice
{ $$
= mtTransferAction_createValue
($1); }
389 | errorAction
{ $$
= $1; }
393 : MT_ERROR
{ $$
= mtTransferAction_createError
($1); }
394 | MT_ERROR MT_STRINGLIT
{ $$
= mtTransferAction_createErrorMessage
($2); }
403 # include "bison.reset"
414 (message
("Parse error in meta-state file: %s", cstring_fromChars
(s
)));
419 (message
("Parse error in meta-state file"));
425 mtprint
(FILE *file
, int type
, MTSTYPE value
)
427 cstring tname
= mttok_unparse
(value.tok
);
428 fprintf
(file
, " (%s)", cstring_toCharsSafe
(tname
));
429 cstring_free
(tname
);