Some consistency changes to library & headers flags.
[splint-patched.git] / src / structNames.c
blob18ac4e7731c0e989a465ac905df4cf9d1532b4b1
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 ** structNames.c
27 ** Hacks to fit tags into the same namespace.
30 # include "splintMacros.nf"
31 # include "basic.h"
32 # include "structNames.h"
34 /*@constant char MARKCHAR_STRUCT; @*/
35 # define MARKCHAR_STRUCT '@'
37 /*@constant char MARKCHAR_UNION; @*/
38 # define MARKCHAR_UNION '$'
40 /*@constant char MARKCHAR_ENUM; @*/
41 # define MARKCHAR_ENUM '&'
43 /*@constant char MARKCHAR_PARAM; @*/
44 # define MARKCHAR_PARAM '%'
46 /*@observer@*/ cstring plainTagName (cstring s)
48 llassert (!isFakeTag (s));
50 return cstring_suffix (s, 1);
53 /*@only@*/ cstring fixTagName (cstring s)
55 if (isFakeTag (s))
57 switch (cstring_firstChar (s))
59 case MARKCHAR_STRUCT: return (cstring_makeLiteral ("struct"));
60 case MARKCHAR_UNION: return (cstring_makeLiteral ("union"));
61 case MARKCHAR_ENUM: return (cstring_makeLiteral ("enum"));
62 default: return (message ("<bad tag name: %s>", s));
65 else
67 if (cstring_isDefined (s)) {
68 switch (cstring_firstChar (s))
70 case MARKCHAR_STRUCT:
71 return (message ("struct %s", cstring_suffix (s, 1)));
72 case MARKCHAR_UNION:
73 return (message ("union %s", cstring_suffix (s, 1)));
74 case MARKCHAR_ENUM:
75 return (message ("enum %s", cstring_suffix (s, 1)));
76 BADDEFAULT;
78 } else {
79 return (cstring_makeLiteral ("<missing tag name>"));
84 cstring makeParam (cstring s)
86 if (cstring_length(s) > 0 && cstring_firstChar (s) == MARKCHAR_PARAM)
88 llbug (message ("makeParam: %s\n", s));
91 if (cstring_isUndefined (s))
93 return cstring_undefined;
96 return (cstring_prependChar (MARKCHAR_PARAM, s));
99 /*@observer@*/ cstring fixParamName (cstring s)
101 if (cstring_length(s) < 1)
103 return cstring_undefined;
106 if (cstring_firstChar (s) != MARKCHAR_PARAM)
108 llbug (message ("fixParamName (no #): %s", s));
111 return (cstring_suffix (s, 1));
114 cstring makeStruct (cstring s)
116 if (cstring_firstChar (s) == '@')
118 llbug (message ("makeStruct: %s\n", s));
121 return (cstring_prependChar (MARKCHAR_STRUCT, s));
124 cstring makeUnion (cstring s)
126 return (cstring_prependChar (MARKCHAR_UNION, s));
129 cstring makeEnum (cstring s)
131 return (cstring_prependChar (MARKCHAR_ENUM, s));
134 static unsigned int tagno = 1;
136 void setTagNo (unsigned int n)
138 if (n > tagno)
139 tagno = n;
142 bool isFakeTag (cstring s)
144 size_t length = cstring_length (s);
146 return ((length >= 1 && cstring_firstChar (s) == '!')
147 || (length >= 2 && cstring_getChar (s, 2) == '!'));
150 cstring fakeTag (void)
152 tagno++;
154 return (message ("!%u", tagno));