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 "filelocStack.h"
00031
00032 static filelocStack
00033 filelocStack_newEmpty (void)
00034 {
00035 filelocStack s = (filelocStack) dmalloc (sizeof (*s));
00036
00037 s->nelements = 0;
00038 s->free = filelocStackBASESIZE;
00039 s->elements = (fileloc *) dmalloc (sizeof (*s->elements) * filelocStackBASESIZE);
00040
00041 return (s);
00042 }
00043
00044 filelocStack
00045 filelocStack_new ()
00046 {
00047 return (filelocStack_newEmpty ());
00048 }
00049
00050 static void
00051 filelocStack_grow ( filelocStack s)
00052 {
00053 o_fileloc *oldelements = s->elements;
00054 int i;
00055
00056 s->free += filelocStackBASESIZE;
00057 s->elements = (fileloc *) dmalloc (sizeof (*s->elements)
00058 * (s->nelements + s->free));
00059
00060 for (i = 0; i < s->nelements; i++)
00061 {
00062 s->elements[i] = oldelements[i];
00063 }
00064
00065 sfree (oldelements);
00066 }
00067
00068 static void
00069 filelocStack_push ( filelocStack s, fileloc el)
00070
00071 {
00072 llassert (filelocStack_isDefined (s));
00073
00074 if (s->free <= 0)
00075 {
00076 filelocStack_grow (s);
00077 }
00078
00079 s->free--;
00080 s->elements[s->nelements] = el;
00081 s->nelements++;
00082 }
00083
00084 fileloc filelocStack_nextTop (filelocStack s)
00085 {
00086 llassert (filelocStack_isDefined (s) && s->nelements > 1);
00087
00088 return (s->elements[s->nelements - 2]);
00089 }
00090
00091 void filelocStack_clear (filelocStack s)
00092 {
00093 if (filelocStack_isDefined (s))
00094 {
00095 int i;
00096
00097 for (i = 0; i < s->nelements; i++)
00098 {
00099 fileloc_free (s->elements[i]);
00100 }
00101
00102 s->free += s->nelements;
00103 s->nelements = 0;
00104 }
00105 }
00106
00107
00108
00109
00110
00111 bool filelocStack_popPushFile (filelocStack s, fileloc el)
00112 {
00113 int i;
00114
00115 llassert (filelocStack_isDefined (s));
00116
00117 for (i = s->nelements - 1; i >= 0; i--)
00118 {
00119 if (fileloc_sameBaseFile (s->elements[i], el))
00120 {
00121 int j;
00122
00123 for (j = i; j < s->nelements; j++)
00124 {
00125 fileloc_free (s->elements[j]);
00126 }
00127
00128 s->elements[i] = el;
00129 s->nelements = i + 1;
00130 return FALSE;
00131 }
00132 }
00133
00134 filelocStack_push (s, el);
00135 return TRUE;
00136 }
00137
00138 cstring
00139 filelocStack_unparse (filelocStack s)
00140 {
00141 int i;
00142 cstring st = cstring_makeLiteral ("[");
00143
00144 if (filelocStack_isDefined (s))
00145 {
00146 for (i = s->nelements - 1; i >= 0; i--)
00147 {
00148 if (i == s->nelements - 1)
00149 {
00150 st = message ("%q %q", st, fileloc_unparse (s->elements[i]));
00151 }
00152 else
00153 {
00154 st = message ("%q, %q", st, fileloc_unparse (s->elements[i]));
00155 }
00156 }
00157 }
00158
00159 st = message ("%q ]", st);
00160 return st;
00161 }
00162
00163 int filelocStack_includeDepth (filelocStack s)
00164 {
00165 int depth = 0;
00166 int i;
00167
00168 if (filelocStack_isDefined (s))
00169 {
00170
00171 for (i = s->nelements - 1; i > 0; i--)
00172 {
00173 if (!fileloc_isSpecialFile (s->elements[i]))
00174 {
00175 depth++;
00176 }
00177 }
00178 }
00179
00180 return depth;
00181 }
00182
00183 void
00184 filelocStack_printIncludes (filelocStack s)
00185 {
00186 if (filelocStack_isDefined (s))
00187 {
00188 int i;
00189 bool prep = context_isPreprocessing ();
00190
00191 if (prep)
00192 {
00193
00194 context_clearPreprocessing ();
00195 }
00196
00197
00198 for (i = s->nelements - 3; i >= 0; i--)
00199 {
00200 if (i == 0 || !fileloc_isSpecialFile (s->elements[i]))
00201 {
00202 llgenindentmsg (cstring_makeLiteral ("Include site"),
00203 s->elements[i]);
00204 }
00205 }
00206
00207 if (prep)
00208 {
00209 context_setPreprocessing ();
00210 }
00211 }
00212 }
00213
00214 void
00215 filelocStack_free ( filelocStack s)
00216 {
00217 if (filelocStack_isDefined (s))
00218 {
00219 int i;
00220 for (i = 0; i < s->nelements; i++)
00221 {
00222 fileloc_free (s->elements[i]);
00223 }
00224
00225 sfree (s->elements);
00226 sfree (s);
00227 }
00228 }
00229
00230
00231
00232
00233
00234