Moved OS dependent constants from constants.h to osd.h
[splint-patched.git] / src / mttok.c
blobb8739bb340cc842c720e460dca0ae792d2981f46
1 /*
2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 University of Virginia,
4 ** Massachusetts Institute of Technology
5 **
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.
10 **
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.
15 **
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"
29 # include "basic.h"
30 # include "mtgrammar.h"
32 cstring
33 mttok_unparse (mttok tok)
35 char *lit;
37 switch (tok->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_ERROR: lit = "error"; break;
61 case MT_PLUS: lit = "+"; break;
62 case MT_STAR: lit = "*"; break;
63 case MT_LPAREN: lit = "("; break;
64 case MT_RPAREN: lit = ")"; break;
65 case MT_LBRACE: lit = "{"; break;
66 case MT_RBRACE: lit = "}"; break;
67 case MT_LBRACKET: lit = "["; break;
68 case MT_RBRACKET: lit = "]"; break;
69 case MT_COMMA: lit =","; break;
70 case MT_BAR: lit = "|"; break;
71 case MT_CHAR: lit = "char"; break;
72 case MT_INT: lit = "int"; break;
73 case MT_FLOAT: lit = "float"; break;
74 case MT_DOUBLE: lit = "double"; break;
75 case MT_VOID: lit = "void"; break;
76 case MT_ANYTYPE: lit = "anytype"; break;
77 case MT_INTEGRALTYPE: lit = "integraltype"; break;
78 case MT_UNSIGNEDINTEGRALTYPE: lit = "unsignedintegraltype"; break;
79 case MT_SIGNEDINTEGRALTYPE: lit = "signedintegraltype"; break;
80 case MT_CONST: lit = "const"; break;
81 case MT_VOLATILE: lit = "volatile"; break;
83 case MT_IDENT: return (message ("identifier: <%s>", tok->text));
84 case MT_STRINGLIT: return (message ("literal: <%s>", tok->text));
85 case MT_BADTOK: lit = "<error token>"; break;
86 default:
87 DPRINTF (("Bad token: [%d]", tok->tok));
88 BADBRANCH;
89 /* BADDEFAULT; */
92 return cstring_makeLiteral (lit);
95 mttok
96 mttok_create (int tok, cstring text, fileloc loc)
98 mttok l = (mttok) dmalloc (sizeof (*l));
100 l->tok = tok;
101 l->text = text;
102 l->loc = loc;
104 return (l);
107 fileloc mttok_stealLoc (mttok t)
109 fileloc res = t->loc;
110 t->loc = fileloc_undefined;
111 return res;
114 void mttok_free (mttok t)
116 fileloc_free (t->loc);
117 cstring_free (t->text);
118 sfree (t);
121 bool mttok_isError (mttok t)
123 return ((t)->tok == MT_ERROR);
126 bool mttok_isIdentifier (mttok t)
128 return ((t)->tok == MT_IDENT);