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

qtype.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 ** qtype.c
00026 **
00027 ** Qualified types: a type qualifier list, and a ctype.
00028 ** qtypes are mutable
00029 */
00030 
00031 # include "lclintMacros.nf"
00032 # include "basic.h"
00033 
00034 /*@notnull@*/ qtype qtype_create (ctype c)
00035 {
00036   qtype q = (qtype) dmalloc (sizeof (*q));
00037 
00038   q->type = c;
00039   q->quals = qualList_new ();
00040   return q;
00041 }
00042 
00043 void qtype_free (/*@only@*/ qtype q)
00044 {
00045   if (qtype_isDefined (q))
00046     {
00047       qualList_free (q->quals);
00048       sfree (q);
00049     }
00050 }
00051 
00052 qtype qtype_unknown ()
00053 {
00054   return (qtype_create (ctype_unknown));
00055 }
00056 
00057 qtype qtype_addQual (qtype qt, qual q)
00058 {
00059   if (qtype_isDefined (qt))
00060     {
00061       qt->quals = qualList_add (qt->quals, q);
00062     }
00063 
00064   return qt;
00065 }
00066 
00067 # ifndef NOLCL
00068 qtype qtype_addQualList (/*@returned@*/ qtype qt, qualList ql)
00069 {
00070   if (qtype_isDefined (qt))
00071     {
00072       qt->quals = qualList_appendList (qt->quals, ql);
00073     }
00074 
00075   return qt;
00076 }
00077 # endif
00078 
00079 static void checkAltQuals (qtype q)
00080 {
00081   if (qtype_isDefined (q))
00082     {
00083       qualList badQuals = qualList_undefined;
00084       
00085       qualList_elements (q->quals, qu)
00086         {
00087           if (!qual_isCQual (qu) && !qual_isImplied (qu))
00088             {
00089               badQuals = qualList_add (badQuals, qu);
00090             }
00091         } end_qualList_elements ;
00092       
00093       if (!qualList_isEmpty (badQuals))
00094         {
00095           voptgenerror (FLG_SYNTAX,
00096                         message 
00097                         ("Alternate type cannot use annotations %q: %q",
00098                          qualList_unparse (badQuals),
00099                          qtype_unparse (q)),
00100                         g_currentloc);
00101         }
00102     }
00103 }
00104 
00105 # ifndef NOLCL
00106 qtype qtype_mergeImplicitAlt (/*@returned@*/ qtype q1, /*@only@*/ qtype q2)
00107 {
00108   if (qtype_isDefined (q1) && qtype_isDefined (q2))
00109     {
00110       q1->type = ctype_makeConj (q1->type, q2->type);
00111       
00112       if (!qualList_isEmpty (q2->quals))
00113         {
00114           checkAltQuals (q2);
00115         }
00116     }
00117 
00118   qtype_free (q2);
00119   return q1;
00120 }
00121 # endif
00122 
00123 qtype qtype_mergeAlt (/*@returned@*/ qtype q1, /*@only@*/ qtype q2)
00124 {
00125   if (qtype_isDefined (q1) && qtype_isDefined (q2))
00126     {
00127       if (context_getFlag (FLG_IMPCONJ))
00128         {
00129           q1->type = ctype_makeConj (q1->type, q2->type);
00130         }
00131       else
00132         {
00133           q1->type = ctype_makeExplicitConj (q1->type, q2->type);
00134         }
00135 
00136       
00137       if (!qualList_isEmpty (q2->quals))
00138         {
00139           checkAltQuals (q2);
00140         }
00141     }
00142   
00143   qtype_free (q2);
00144   return q1;
00145 }
00146 
00147 qtype qtype_combine (/*@returned@*/ qtype q1, ctype ct)
00148 {
00149   if (qtype_isDefined (q1))
00150     {
00151       /* ct is modifier (or q1->type is unknown) */
00152       q1->type = ctype_combine (q1->type, ct); 
00153     }
00154 
00155   return q1;
00156 }
00157 
00158 qtype qtype_resolve (/*@returned@*/ qtype q)
00159 {
00160   if (qtype_isDefined (q))
00161     {
00162       q->type = ctype_resolve (q->type);
00163     }
00164 
00165   return q;
00166 }
00167 
00168 cstring qtype_unparse (qtype q)
00169 {
00170   if (qtype_isDefined (q))
00171     {
00172       return (message ("%q%s", qualList_unparse (q->quals), 
00173                        ctype_unparse (q->type)));
00174     }
00175   else
00176     {
00177       return (cstring_makeLiteral ("<undefined>"));
00178     }
00179 }
00180 
00181 qtype qtype_newBase (/*@returned@*/ qtype q, ctype ct)
00182 {
00183   if (qtype_isDefined (q))
00184     {
00185       q->type = ctype_newBase (ct, q->type);
00186     }
00187 
00188   return q;
00189 }
00190 
00191 qtype qtype_newQbase (qtype q1, qtype q2)
00192 {
00193   if (qtype_isDefined (q1) && qtype_isDefined (q2))
00194     {
00195       q1->type = ctype_newBase (q1->type, q2->type);
00196       q1->quals = qualList_appendList (q1->quals, q2->quals);
00197     }
00198 
00199   return q1;
00200 }
00201 
00202 void qtype_adjustPointers (int n, qtype q)
00203 {
00204   if (qtype_isDefined (q))
00205     {
00206       q->type = ctype_adjustPointers (n, q->type);
00207     }
00208 }
00209 
00210 # ifndef NOLCL
00211 qtype qtype_copy (qtype q)
00212 {
00213   if (qtype_isDefined (q))
00214     {
00215       qtype r = qtype_create (q->type);
00216       
00217       qualList_free (r->quals);
00218       r->quals = qualList_copy (q->quals);
00219       return r;
00220     }
00221   else
00222     {
00223       return qtype_undefined;
00224     }
00225 }
00226 # endif

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