00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 # include "lclintMacros.nf"
00032 # include "basic.h"
00033
00034 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 ( 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 ( 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 ( qtype q1, 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 ( qtype q1, 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 ( qtype q1, ctype ct)
00148 {
00149 if (qtype_isDefined (q1))
00150 {
00151
00152 q1->type = ctype_combine (q1->type, ct);
00153 }
00154
00155 return q1;
00156 }
00157
00158 qtype qtype_resolve ( 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 ( 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