]> andersk Git - splint.git/blob - src/mttok.c
Merged code tree with Dave Evans's version. Many changes to numberous to list....
[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 = "state"; 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_CLAUSE:         lit = "clause"; break;
52     case MT_ANNOTATIONS:    lit = "annotations"; break;
53     case MT_ARROW:          lit = "==>"; break;
54     case MT_MERGE:          lit = "merge"; break;
55     case MT_TRANSFERS:      lit = "transfers"; break;
56     case MT_PRECONDITIONS:  lit = "preconditions"; break;
57     case MT_POSTCONDITIONS: lit = "postconditions"; break;
58     case MT_ERROR:          lit = "error"; break;
59     case MT_PLUS:           lit = "+"; break;
60     case MT_STAR:           lit = "*"; break;
61     case MT_LPAREN:         lit = "("; break;
62     case MT_RPAREN:         lit = ")"; break;
63     case MT_LBRACE:         lit = "{"; break;
64     case MT_RBRACE:         lit = "}"; break;
65     case MT_LBRACKET:       lit = "["; break;
66     case MT_RBRACKET:       lit = "]"; break;
67     case MT_COMMA:          lit =","; break;
68     case MT_BAR:            lit = "|"; break;
69     case MT_CHAR: lit = "char"; break;
70     case MT_INT: lit = "int"; break; 
71     case MT_FLOAT: lit = "float"; break;
72     case MT_DOUBLE: lit = "double"; break;
73     case MT_VOID: lit = "void"; break;
74     case MT_ANYTYPE: lit = "anytype"; break;
75     case MT_INTEGRALTYPE: lit = "integraltype"; break;
76     case MT_UNSIGNEDINTEGRALTYPE: lit = "unsignedintegraltype"; break;
77     case MT_SIGNEDINTEGRALTYPE: lit = "signedintegraltype"; break; 
78     case MT_CONST: lit = "const"; break;
79     case MT_VOLATILE: lit = "volatile"; break;
80
81     case MT_IDENT:          return (message ("identifier: <%s>", tok->text)); 
82     case MT_STRINGLIT:      return (message ("literal: <%s>", tok->text)); 
83     case MT_BADTOK:         lit = "<error token>"; break;
84     default:
85       DPRINTF (("Bad token: [%d]", tok->tok));
86       BADBRANCH;
87       /* BADDEFAULT; */
88     }
89   
90   return cstring_makeLiteral (lit);
91 }
92
93 mttok
94 mttok_create (int tok, cstring text, fileloc loc)
95 {
96   mttok l = (mttok) dmalloc (sizeof (*l));
97
98   l->tok = tok;
99   l->text = text;
100   l->loc = loc;
101
102   return (l);
103 }
104
105 fileloc mttok_stealLoc (mttok t)
106 {
107   fileloc res = t->loc;
108   t->loc = fileloc_undefined;
109   return res;
110 }
111
112 void mttok_free (mttok t) 
113 {
114   fileloc_free (t->loc);
115   cstring_free (t->text);
116   sfree (t);
117 }
118
119 bool mttok_isIdentifier (mttok t)
120 {
121   return ((t)->tok == MT_IDENT);
122 }
This page took 0.05309 seconds and 5 git commands to generate.