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 # include "lclintMacros.nf"
00029 # include "basic.h"
00030 # include "filelocList.h"
00031
00032
00033
00034
00035
00036
00037 filelocList
00038 filelocList_new ()
00039 {
00040 return (filelocList_undefined);
00041 }
00042
00043 static filelocList
00044 filelocList_newEmpty (void)
00045 {
00046 filelocList s = (filelocList) dmalloc (sizeof (*s));
00047
00048 s->nelements = 0;
00049 s->free = filelocListBASESIZE;
00050 s->elements = (fileloc *) dmalloc (sizeof (*s->elements) * filelocListBASESIZE);
00051
00052 return (s);
00053 }
00054
00055 static void
00056 filelocList_grow ( filelocList s)
00057 {
00058 int i;
00059 o_fileloc *oldelements = s->elements;
00060
00061 s->free += filelocListBASESIZE;
00062 s->elements = (fileloc *) dmalloc (sizeof (*s->elements)
00063 * (s->nelements + s->free));
00064
00065 for (i = 0; i < s->nelements; i++)
00066 {
00067 s->elements[i] = oldelements[i];
00068 }
00069
00070 sfree (oldelements);
00071 }
00072
00073 filelocList
00074 filelocList_append ( filelocList s, filelocList t)
00075 {
00076 llassert (NOALIAS (s, t));
00077
00078 if (filelocList_isUndefined (t) || filelocList_isEmpty (t)) return s;
00079
00080 if (filelocList_isUndefined (s))
00081 {
00082 s = filelocList_newEmpty ();
00083 }
00084
00085 filelocList_elements (t, fl)
00086 {
00087
00088
00089
00090 s = filelocList_add (s, fl);
00091
00092 } end_filelocList_elements;
00093
00094 sfree (t->elements);
00095 sfree (t);
00096
00097 return s;
00098 }
00099
00100 filelocList
00101 filelocList_addUndefined ( filelocList s)
00102 {
00103 if (filelocList_isUndefined (s)
00104 || s->nelements == 0
00105 || fileloc_isDefined (s->elements[0]))
00106 {
00107 return (filelocList_add (s, fileloc_undefined));
00108 }
00109 else
00110 {
00111 return s;
00112 }
00113 }
00114
00115 static bool filelocList_hasUndefinedLoc (filelocList s)
00116 {
00117 return (filelocList_isDefined (s)
00118 && s->nelements > 0
00119 && fileloc_isUndefined (s->elements[0]));
00120 }
00121
00122 filelocList
00123 filelocList_addDifferentFile ( filelocList s,
00124 fileloc where,
00125 fileloc loc)
00126 {
00127 if (filelocList_hasUndefinedLoc (s) || filelocList_size (s) >= 2)
00128 {
00129 return s;
00130 }
00131 else
00132 {
00133 if (fileloc_sameModule (where, loc))
00134 {
00135 if (filelocList_isEmpty (s))
00136 {
00137 return filelocList_add (s, fileloc_copy (loc));
00138 }
00139 else
00140 {
00141 return s;
00142 }
00143 }
00144 else
00145 {
00146 return filelocList_addUndefined (s);
00147 }
00148 }
00149 }
00150
00151 filelocList
00152 filelocList_add ( filelocList s, fileloc el)
00153 {
00154 if (filelocList_isUndefined (s))
00155 {
00156 s = filelocList_newEmpty ();
00157 }
00158
00159 if (s->free <= 0)
00160 {
00161 filelocList_grow (s);
00162 }
00163
00164 s->free--;
00165 s->elements[s->nelements] = el;
00166
00167 if (fileloc_isUndefined (el))
00168 {
00169 s->elements[s->nelements] = s->elements[0];
00170 s->elements[0] = fileloc_undefined;
00171 }
00172
00173 s->nelements++;
00174 return s;
00175 }
00176
00177 cstring
00178 filelocList_unparse (filelocList s)
00179 {
00180 int i;
00181 cstring st = cstring_makeLiteral ("[");
00182
00183 if (filelocList_isDefined (s))
00184 {
00185 for (i = 0; i < filelocList_size (s); i++)
00186 {
00187 if (i == 0)
00188 {
00189 st = message ("%q %q", st, fileloc_unparse (s->elements[i]));
00190 }
00191 else
00192 st = message ("%q, %q", st, fileloc_unparse (s->elements[i]));
00193 }
00194 }
00195
00196 st = message ("%q ]", st);
00197 return st;
00198 }
00199
00200 int filelocList_realSize (filelocList s)
00201 {
00202 int size = 0;
00203
00204 filelocList_elements (s, el)
00205 {
00206 if (fileloc_isDefined (el))
00207 {
00208 size++;
00209 }
00210 } end_filelocList_elements;
00211
00212 return size;
00213 }
00214
00215 cstring filelocList_unparseUses (filelocList s)
00216 {
00217 int i;
00218 int linelen = 0;
00219 int maxlen = context_getLineLen () - 3;
00220 cstring st = cstring_undefined;
00221 fileId lastFile = fileId_invalid;
00222
00223 if (filelocList_isDefined (s))
00224 {
00225 bool firstone = TRUE;
00226
00227 for (i = 0; i < filelocList_size (s); i++)
00228 {
00229 if (fileloc_isDefined (s->elements[i]))
00230 {
00231 if (firstone)
00232 {
00233 st = fileloc_unparse (s->elements[i]);
00234 lastFile = fileloc_fileId (s->elements[i]);
00235 linelen = 3 + cstring_length (st);
00236 firstone = FALSE;
00237 }
00238 else
00239 {
00240 if (fileId_equal (fileloc_fileId (s->elements[i]), lastFile))
00241 {
00242 if (linelen + 7 > maxlen)
00243 {
00244 st = message ("%q\n ", st);
00245 linelen = 6;
00246 }
00247 else
00248 {
00249 st = message ("%q, ", st);
00250 }
00251
00252 st = message ("%q%d,%d",
00253 st, fileloc_lineno (s->elements[i]),
00254 fileloc_column (s->elements[i]));
00255 linelen += 3 + int_log (fileloc_lineno (s->elements[i]))
00256 + int_log (fileloc_column (s->elements[i]));
00257 }
00258 else
00259 {
00260 cstring fl = fileloc_unparse (s->elements[i]);
00261 st = message ("%q\n %s", st, fl);
00262 lastFile = fileloc_fileId (s->elements[i]);
00263 linelen = 3 + cstring_length (fl);
00264 cstring_free (fl);
00265 }
00266 }
00267 }
00268 }
00269 }
00270
00271 return st;
00272 }
00273
00274 void
00275 filelocList_free ( filelocList s)
00276 {
00277 if (filelocList_isDefined (s))
00278 {
00279 int i;
00280 for (i = 0; i < s->nelements; i++)
00281 {
00282 fileloc_free (s->elements[i]);
00283 }
00284
00285 sfree (s->elements);
00286 sfree (s);
00287 }
00288 }
00289
00290
00291
00292
00293
00294