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

idDecl.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 ** idDecl.c
00026 */
00027 
00028 # include "lclintMacros.nf"
00029 # include "basic.h"
00030 
00031 /*@only@*/ idDecl
00032   idDecl_create (/*@only@*/ cstring s, /*@only@*/ qtype t)
00033 {
00034   idDecl d = (idDecl) dmalloc (sizeof (*d));
00035 
00036   d->id = s;
00037   d->typ = t;
00038 
00039   return (d);
00040 }
00041 
00042 void
00043 idDecl_free (idDecl t)
00044 {
00045   if (idDecl_isDefined (t))
00046     {
00047       cstring_free (t->id);
00048       qtype_free (t->typ);
00049       sfree (t);
00050     }
00051 }
00052 
00053 cstring
00054 idDecl_unparse (idDecl d)
00055 {
00056   if (idDecl_isDefined (d))
00057     {
00058       return (message ("%s : %q", d->id, qtype_unparse (d->typ)));
00059     }
00060   else
00061     {
00062       return (cstring_makeLiteral ("<undefined id>"));
00063     }
00064 }
00065 
00066 /*@observer@*/ cstring
00067 idDecl_observeId (idDecl d)
00068 {
00069   if (idDecl_isDefined (d))
00070     {
00071       return (d->id);
00072     }
00073   else
00074     {
00075       return cstring_undefined;
00076     }
00077 }
00078 
00079 qtype
00080 idDecl_getTyp (idDecl d)
00081 {
00082   llassert (idDecl_isDefined (d));
00083 
00084   return d->typ;
00085 }
00086 
00087 ctype
00088 idDecl_getCtype (idDecl d)
00089 {
00090   if (idDecl_isDefined (d))
00091     {
00092       return (qtype_getType (d->typ));
00093     }
00094   else
00095     {
00096       return ctype_unknown;
00097     }
00098 }
00099 
00100 qualList
00101 idDecl_getQuals (idDecl d)
00102 {
00103   if (idDecl_isDefined (d))
00104     {
00105       return (qtype_getQuals (d->typ));
00106     }
00107   else
00108     {
00109       return qualList_undefined;
00110     }
00111 }
00112 
00113 void
00114 idDecl_addQual (idDecl d, qual q)
00115 {
00116   llassert (idDecl_isDefined (d));
00117 
00118   (void) qtype_addQual (d->typ, q);
00119 }
00120 
00121 void
00122 idDecl_setTyp (idDecl d, qtype c)
00123 {
00124   llassert (idDecl_isDefined (d));
00125 
00126   qtype_free (d->typ);
00127   d->typ = c;
00128 }
00129 
00130 idDecl
00131 idDecl_replaceCtype (/*@returned@*/ idDecl d, ctype c)
00132 {
00133   llassert (idDecl_isDefined (d));
00134 
00135   qtype_setType (d->typ, c);
00136   return d;
00137 }
00138 
00139 idDecl
00140 idDecl_fixBase (/*@returned@*/ idDecl t, qtype b)
00141 {
00142   llassert (idDecl_isDefined (t));
00143 
00144   t->typ = qtype_newQbase (t->typ, b);
00145   return t;
00146 }
00147 
00148 idDecl
00149 idDecl_fixParamBase (/*@returned@*/ idDecl t, qtype b)
00150 {
00151   qtype q;
00152   ctype c;
00153 
00154   llassert (idDecl_isDefined (t));
00155 
00156   q = qtype_newQbase (t->typ, b);
00157   c = qtype_getType (q);
00158 
00159   /*
00160   ** For some reason, C adds an implicit pointer to function
00161   ** parameters.  It is "optional" syntax.
00162   */
00163 
00164   if (ctype_isFunction (c) && !ctype_isPointer (c))
00165     {
00166       qtype_setType (q, ctype_makePointer (c));
00167     }
00168 
00169   t->typ = q;
00170   /* LCLint thinks t->typ is kept. */
00171   /*@-compmempass@*/ return t; /*@=compmempass@*/
00172 }
00173 
00174 idDecl
00175 idDecl_expectFunction (/*@returned@*/ idDecl d)
00176 {
00177   llassert (idDecl_isDefined (d));
00178 
00179   qtype_setType (d->typ, ctype_expectFunction (qtype_getType (d->typ)));
00180   return d;
00181 }

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