Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

structNames.c

Go to the documentation of this file.
00001 /*
00002 ** LCLint - annotation-assisted static program checker
00003 ** Copyright (C) 1994-2000 University of Virginia,
00004 **         Massachusetts Institute of Technology
00005 **
00006 ** This program is free software; you can redistribute it and/or modify it
00007 ** under the terms of the GNU General Public License as published by the
00008 ** Free Software Foundation; either version 2 of the License, or (at your
00009 ** option) any later version.
00010 ** 
00011 ** This program is distributed in the hope that it will be useful, but
00012 ** WITHOUT ANY WARRANTY; without even the implied warranty of
00013 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 ** General Public License for more details.
00015 ** 
00016 ** The GNU General Public License is available from http://www.gnu.org/ or
00017 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00018 ** MA 02111-1307, USA.
00019 **
00020 ** For information on lclint: lclint-request@cs.virginia.edu
00021 ** To report a bug: lclint-bug@cs.virginia.edu
00022 ** For more information: http://lclint.cs.virginia.edu
00023 */
00024 /*
00025 ** structNames.c
00026 **
00027 ** Hacks to fit tags into the same namespace.
00028 */
00029 
00030 # include "lclintMacros.nf"
00031 # include "basic.h"
00032 # include "structNames.h"
00033 
00034 /*@constant char MARKCHAR_STRUCT; @*/
00035 # define MARKCHAR_STRUCT '@'
00036 
00037 /*@constant char MARKCHAR_UNION; @*/
00038 # define MARKCHAR_UNION  '$'
00039 
00040 /*@constant char MARKCHAR_ENUM; @*/
00041 # define MARKCHAR_ENUM   '&'
00042 
00043 /*@constant char MARKCHAR_PARAM; @*/
00044 # define MARKCHAR_PARAM  '%'
00045 
00046 /*@only@*/ cstring fixTagName (cstring s)
00047 {
00048   if (isFakeTag (s))
00049     {
00050       switch (cstring_firstChar (s))
00051         {
00052         case MARKCHAR_STRUCT: return (cstring_makeLiteral ("struct"));
00053         case MARKCHAR_UNION:  return (cstring_makeLiteral ("union"));
00054         case MARKCHAR_ENUM:   return (cstring_makeLiteral ("enum"));
00055         default:         return (message ("<bad tag name: %s>", s));
00056           /* BADDEFAULT; */
00057         }
00058     }
00059   else
00060     {
00061       if (cstring_isDefined (s)) {
00062         switch (cstring_firstChar (s))
00063           {
00064           case MARKCHAR_STRUCT:
00065             return (message ("struct %s", cstring_suffix (s, 1)));
00066           case MARKCHAR_UNION: 
00067             return (message ("union %s", cstring_suffix (s, 1)));
00068           case MARKCHAR_ENUM:   
00069             return (message ("enum %s", cstring_suffix (s, 1)));
00070             BADDEFAULT;
00071           }
00072       } else {
00073         return (cstring_makeLiteral ("<missing tag name>"));
00074       }
00075     }
00076 }
00077 
00078 cstring makeParam (cstring s)
00079 {
00080   if (cstring_length(s) > 0 && cstring_firstChar (s) == MARKCHAR_PARAM)
00081     {
00082       llbug (message ("makeParam: %s\n", s));
00083     }
00084 
00085   if (cstring_isUndefined (s))
00086     {
00087       return cstring_undefined;
00088     }
00089 
00090   return (cstring_prependChar (MARKCHAR_PARAM, s));  
00091 }
00092 
00093 /*@observer@*/ cstring fixParamName (cstring s)
00094 {
00095   if (cstring_length(s) < 1)
00096     {
00097       return cstring_undefined;
00098     }
00099 
00100   if (cstring_firstChar (s) != MARKCHAR_PARAM)
00101     {
00102       llbug (message ("fixParamName (no #): %s", s));
00103     }
00104 
00105   return (cstring_suffix (s, 1));
00106 }
00107 
00108 cstring makeStruct (cstring s)
00109 {
00110   if (cstring_firstChar (s) == '@')
00111     {
00112       llbug (message ("makeStruct: %s\n", s));
00113     }
00114 
00115   return (cstring_prependChar (MARKCHAR_STRUCT, s));
00116 }
00117 
00118 cstring makeUnion (cstring s)
00119 {
00120   return (cstring_prependChar (MARKCHAR_UNION, s));
00121 }
00122 
00123 cstring makeEnum (cstring s)
00124 {
00125   return (cstring_prependChar (MARKCHAR_ENUM, s));
00126 }
00127 
00128 static unsigned int tagno = 1;
00129 
00130 void setTagNo (unsigned int n)
00131 {
00132   if (n > tagno)
00133     tagno = n;
00134 }
00135 
00136 bool isFakeTag (cstring s)
00137 {
00138   int length = cstring_length (s);
00139 
00140   return ((length >= 1 && cstring_firstChar (s) == '!')
00141           || (length >= 2 && cstring_getChar (s, 2) == '!'));
00142 }
00143 
00144 cstring fakeTag ()
00145 {
00146   tagno++;
00147 
00148   return (message ("!%u", tagno));
00149 }
00150 
00151 
00152 
00153 
00154 

Generated at Fri Nov 3 18:57:45 2000 for LCLint by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000