2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2000 University of Virginia,
4 ** Massachusetts Institute of Technology
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.
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.
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 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
27 ** Hacks to fit tags into the same namespace.
30 # include "lclintMacros.nf"
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 /*@only@*/ cstring fixTagName (cstring s)
50 switch (cstring_firstChar (s))
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));
61 if (cstring_isDefined (s)) {
62 switch (cstring_firstChar (s))
65 return (message ("struct %s", cstring_suffix (s, 1)));
67 return (message ("union %s", cstring_suffix (s, 1)));
69 return (message ("enum %s", cstring_suffix (s, 1)));
73 return (cstring_makeLiteral ("<missing tag name>"));
78 cstring makeParam (cstring s)
80 if (cstring_length(s) > 0 && cstring_firstChar (s) == MARKCHAR_PARAM)
82 llbug (message ("makeParam: %s\n", s));
85 if (cstring_isUndefined (s))
87 return cstring_undefined;
90 return (cstring_prependChar (MARKCHAR_PARAM, s));
93 /*@observer@*/ cstring fixParamName (cstring s)
95 if (cstring_length(s) < 1)
97 return cstring_undefined;
100 if (cstring_firstChar (s) != MARKCHAR_PARAM)
102 llbug (message ("fixParamName (no #): %s", s));
105 return (cstring_suffix (s, 1));
108 cstring makeStruct (cstring s)
110 if (cstring_firstChar (s) == '@')
112 llbug (message ("makeStruct: %s\n", s));
115 return (cstring_prependChar (MARKCHAR_STRUCT, s));
118 cstring makeUnion (cstring s)
120 return (cstring_prependChar (MARKCHAR_UNION, s));
123 cstring makeEnum (cstring s)
125 return (cstring_prependChar (MARKCHAR_ENUM, s));
128 static unsigned int tagno = 1;
130 void setTagNo (unsigned int n)
136 bool isFakeTag (cstring s)
138 int length = cstring_length (s);
140 return ((length >= 1 && cstring_firstChar (s) == '!')
141 || (length >= 2 && cstring_getChar (s, 2) == '!'));
148 return (message ("!%u", tagno));