]> andersk Git - splint.git/blob - src/mttok.c
*** empty log message ***
[splint.git] / src / mttok.c
1 /*
2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2001 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.
19 **
20 ** For information on lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
23 */
24 /*
25 ** mttok.c - based on lltok.c
26 */
27
28 # include "lclintMacros.nf"
29 # include "basic.h"
30
31 # include "mtgrammar.h"
32
33 cstring
34 mttok_unparse (mttok tok)
35 {
36   char *lit;
37
38   switch (tok->tok)
39     {
40     case EOF:               lit = "<EOF>"; break;
41     case MT_STATE:          lit = "attribute"; break;
42     case MT_GLOBAL:         lit = "global"; break;
43     case MT_CONTEXT:        lit = "context"; break;
44     case MT_ONEOF:          lit = "oneof"; break;
45     case MT_AS:             lit = "as"; break;
46     case MT_END:            lit = "end"; break;
47     case MT_DEFAULTS:       lit = "defaults"; break;
48     case MT_DEFAULT:        lit = "default"; break;
49     case MT_REFERENCE:      lit = "reference"; break;
50     case MT_PARAMETER:      lit = "parameter"; break;
51     case MT_RESULT:         lit = "result"; break;
52     case MT_CLAUSE:         lit = "clause"; break;
53     case MT_ANNOTATIONS:    lit = "annotations"; break;
54     case MT_ARROW:          lit = "==>"; break;
55     case MT_MERGE:          lit = "merge"; break;
56     case MT_TRANSFERS:      lit = "transfers"; break;
57     case MT_PRECONDITIONS:  lit = "preconditions"; break;
58     case MT_POSTCONDITIONS: lit = "postconditions"; break;
59     case MT_ERROR:          lit = "error"; break;
60     case MT_PLUS:           lit = "+"; break;
61     case MT_STAR:           lit = "*"; break;
62     case MT_LPAREN:         lit = "("; break;
63     case MT_RPAREN:         lit = ")"; break;
64     case MT_LBRACE:         lit = "{"; break;
65     case MT_RBRACE:         lit = "}"; break;
66     case MT_LBRACKET:       lit = "["; break;
67     case MT_RBRACKET:       lit = "]"; break;
68     case MT_COMMA:          lit =","; break;
69     case MT_BAR:            lit = "|"; break;
70     case MT_CHAR: lit = "char"; break;
71     case MT_INT: lit = "int"; break; 
72     case MT_FLOAT: lit = "float"; break;
73     case MT_DOUBLE: lit = "double"; break;
74     case MT_VOID: lit = "void"; break;
75     case MT_ANYTYPE: lit = "anytype"; break;
76     case MT_INTEGRALTYPE: lit = "integraltype"; break;
77     case MT_UNSIGNEDINTEGRALTYPE: lit = "unsignedintegraltype"; break;
78     case MT_SIGNEDINTEGRALTYPE: lit = "signedintegraltype"; break; 
79     case MT_CONST: lit = "const"; break;
80     case MT_VOLATILE: lit = "volatile"; break;
81
82     case MT_IDENT:          return (message ("identifier: <%s>", tok->text)); 
83     case MT_STRINGLIT:      return (message ("literal: <%s>", tok->text)); 
84     case MT_BADTOK:         lit = "<error token>"; break;
85     default:
86       DPRINTF (("Bad token: [%d]", tok->tok));
87       BADBRANCH;
88       /* BADDEFAULT; */
89     }
90   
91   return cstring_makeLiteral (lit);
92 }
93
94 mttok
95 mttok_create (int tok, cstring text, fileloc loc)
96 {
97   mttok l = (mttok) dmalloc (sizeof (*l));
98
99   l->tok = tok;
100   l->text = text;
101   l->loc = loc;
102
103   return (l);
104 }
105
106 fileloc mttok_stealLoc (mttok t)
107 {
108   fileloc res = t->loc;
109   t->loc = fileloc_undefined;
110   return res;
111 }
112
113 void mttok_free (mttok t) 
114 {
115   fileloc_free (t->loc);
116   cstring_free (t->text);
117   sfree (t);
118 }
119
120 bool mttok_isError (mttok t)
121 {
122   return ((t)->tok == MT_ERROR);
123 }
124
125 bool mttok_isIdentifier (mttok t)
126 {
127   return ((t)->tok == MT_IDENT);
128 }
This page took 0.056266 seconds and 5 git commands to generate.