]> andersk Git - splint.git/blob - src/structNames.c
Removed the unused data type environmentTable.
[splint.git] / src / structNames.c
1 /*
2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2000 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 ** structNames.c
26 **
27 ** Hacks to fit tags into the same namespace.
28 */
29
30 # include "lclintMacros.nf"
31 # include "basic.h"
32 # include "structNames.h"
33
34 /*@constant char MARKCHAR_STRUCT; @*/
35 # define MARKCHAR_STRUCT '@'
36
37 /*@constant char MARKCHAR_UNION; @*/
38 # define MARKCHAR_UNION  '$'
39
40 /*@constant char MARKCHAR_ENUM; @*/
41 # define MARKCHAR_ENUM   '&'
42
43 /*@constant char MARKCHAR_PARAM; @*/
44 # define MARKCHAR_PARAM  '%'
45
46 /*@only@*/ cstring fixTagName (cstring s)
47 {
48   if (isFakeTag (s))
49     {
50       switch (cstring_firstChar (s))
51         {
52         case MARKCHAR_STRUCT: return (cstring_makeLiteral ("struct"));
53         case MARKCHAR_UNION:  return (cstring_makeLiteral ("union"));
54         case MARKCHAR_ENUM:   return (cstring_makeLiteral ("enum"));
55         default:         return (message ("<bad tag name: %s>", s));
56           /* BADDEFAULT; */
57         }
58     }
59   else
60     {
61       if (cstring_isDefined (s)) {
62         switch (cstring_firstChar (s))
63           {
64           case MARKCHAR_STRUCT:
65             return (message ("struct %s", cstring_suffix (s, 1)));
66           case MARKCHAR_UNION: 
67             return (message ("union %s", cstring_suffix (s, 1)));
68           case MARKCHAR_ENUM:   
69             return (message ("enum %s", cstring_suffix (s, 1)));
70             BADDEFAULT;
71           }
72       } else {
73         return (cstring_makeLiteral ("<missing tag name>"));
74       }
75     }
76 }
77
78 cstring makeParam (cstring s)
79 {
80   if (cstring_length(s) > 0 && cstring_firstChar (s) == MARKCHAR_PARAM)
81     {
82       llbug (message ("makeParam: %s\n", s));
83     }
84
85   if (cstring_isUndefined (s))
86     {
87       return cstring_undefined;
88     }
89
90   return (cstring_prependChar (MARKCHAR_PARAM, s));  
91 }
92
93 /*@observer@*/ cstring fixParamName (cstring s)
94 {
95   if (cstring_length(s) < 1)
96     {
97       return cstring_undefined;
98     }
99
100   if (cstring_firstChar (s) != MARKCHAR_PARAM)
101     {
102       llbug (message ("fixParamName (no #): %s", s));
103     }
104
105   return (cstring_suffix (s, 1));
106 }
107
108 cstring makeStruct (cstring s)
109 {
110   if (cstring_firstChar (s) == '@')
111     {
112       llbug (message ("makeStruct: %s\n", s));
113     }
114
115   return (cstring_prependChar (MARKCHAR_STRUCT, s));
116 }
117
118 cstring makeUnion (cstring s)
119 {
120   return (cstring_prependChar (MARKCHAR_UNION, s));
121 }
122
123 cstring makeEnum (cstring s)
124 {
125   return (cstring_prependChar (MARKCHAR_ENUM, s));
126 }
127
128 static unsigned int tagno = 1;
129
130 void setTagNo (unsigned int n)
131 {
132   if (n > tagno)
133     tagno = n;
134 }
135
136 bool isFakeTag (cstring s)
137 {
138   int length = cstring_length (s);
139
140   return ((length >= 1 && cstring_firstChar (s) == '!')
141           || (length >= 2 && cstring_getChar (s, 2) == '!'));
142 }
143
144 cstring fakeTag ()
145 {
146   tagno++;
147
148   return (message ("!%u", tagno));
149 }
150
151
152
153
154
This page took 0.194996 seconds and 5 git commands to generate.