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: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
25 ** mttok.c - based on lltok.c
28 # include "splintMacros.nf"
30 # include "mtgrammar.h"
33 mttok_unparse (mttok tok
)
39 case EOF
: lit
= "<EOF>"; break;
40 case MT_STATE
: lit
= "attribute"; break;
41 case MT_GLOBAL
: lit
= "global"; break;
42 case MT_CONTEXT
: lit
= "context"; break;
43 case MT_ONEOF
: lit
= "oneof"; break;
44 case MT_AS
: lit
= "as"; break;
45 case MT_END
: lit
= "end"; break;
46 case MT_DEFAULTS
: lit
= "defaults"; break;
47 case MT_DEFAULT
: lit
= "default"; break;
48 case MT_REFERENCE
: lit
= "reference"; break;
49 case MT_PARAMETER
: lit
= "parameter"; break;
50 case MT_RESULT
: lit
= "result"; break;
51 case MT_CLAUSE
: lit
= "clause"; break;
52 case MT_LITERAL
: lit
= "literal"; break;
53 case MT_NULL
: lit
= "null"; break;
54 case MT_ANNOTATIONS
: lit
= "annotations"; break;
55 case MT_ARROW
: lit
= "==>"; break;
56 case MT_MERGE
: lit
= "merge"; break;
57 case MT_TRANSFERS
: lit
= "transfers"; break;
58 case MT_PRECONDITIONS
: lit
= "preconditions"; break;
59 case MT_POSTCONDITIONS
: lit
= "postconditions"; break;
60 case MT_LOSEREFERENCE
: lit
= "losereference"; break;
61 case MT_ERROR
: lit
= "error"; break;
62 case MT_PLUS
: lit
= "+"; break;
63 case MT_STAR
: lit
= "*"; break;
64 case MT_LPAREN
: lit
= "("; break;
65 case MT_RPAREN
: lit
= ")"; break;
66 case MT_LBRACE
: lit
= "{"; break;
67 case MT_RBRACE
: lit
= "}"; break;
68 case MT_LBRACKET
: lit
= "["; break;
69 case MT_RBRACKET
: lit
= "]"; break;
70 case MT_COMMA
: lit
= ","; break;
71 case MT_BAR
: lit
= "|"; break;
72 case MT_CHAR
: lit
= "char"; break;
73 case MT_INT
: lit
= "int"; break;
74 case MT_FLOAT
: lit
= "float"; break;
75 case MT_DOUBLE
: lit
= "double"; break;
76 case MT_VOID
: lit
= "void"; break;
77 case MT_ANYTYPE
: lit
= "anytype"; break;
78 case MT_INTEGRALTYPE
: lit
= "integraltype"; break;
79 case MT_UNSIGNEDINTEGRALTYPE
: lit
= "unsignedintegraltype"; break;
80 case MT_SIGNEDINTEGRALTYPE
: lit
= "signedintegraltype"; break;
81 case MT_CONST
: lit
= "const"; break;
82 case MT_VOLATILE
: lit
= "volatile"; break;
83 case MT_RESTRICT
: lit
= "restrict"; break;
85 case MT_IDENT
: return (message ("identifier: <%s>", tok
->text
));
86 case MT_STRINGLIT
: return (message ("literal: <%s>", tok
->text
));
87 case MT_BADTOK
: lit
= "<error token>"; break;
89 DPRINTF (("Bad token: [%d]", tok
->tok
));
93 return cstring_makeLiteral (lit
);
97 mttok_create (int tok
, cstring text
, fileloc loc
)
99 mttok l
= (mttok
) dmalloc (sizeof (*l
));
108 fileloc
mttok_stealLoc (mttok t
)
110 fileloc res
= t
->loc
;
111 t
->loc
= fileloc_undefined
;
115 void mttok_free (mttok t
)
117 fileloc_free (t
->loc
);
118 cstring_free (t
->text
);
123 bool mttok_isError (mttok t
)
125 return ((t
)->tok
== MT_ERROR
);
127 # endif /* DEADCODE */
129 bool mttok_isIdentifier (mttok t
)
131 return ((t
)->tok
== MT_IDENT
);