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 "llbasic.h"
00033 # include "lcltokentable.h"
00034
00035 static long unsigned MaxToken;
00036 static o_ltoken *LCLTokenTable = NULL;
00037
00038 static void AllocTokenTable (void)
00039
00040 ;
00041
00042 ltoken
00043 LCLInsertToken (ltokenCode cod, lsymbol sym, lsymbol rTxt,
00044 bool isPredefined)
00045 {
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 setCodePoint ();
00056
00057 while (sym >= MaxToken)
00058 {
00059 setCodePoint ();
00060
00061 AllocTokenTable ();
00062 }
00063
00064 llassert (LCLTokenTable != NULL);
00065
00066 if (ltoken_isUndefined (LCLTokenTable[sym]))
00067 {
00068 LCLTokenTable[sym] = ltoken_create (cod, sym);
00069 ltoken_setRawText (LCLTokenTable[sym], rTxt);
00070 ltoken_setDefined (LCLTokenTable[sym], isPredefined);
00071 return LCLTokenTable[sym];
00072 }
00073
00074 return LCLTokenTable[sym];
00075 }
00076
00077 void LCLUpdateToken (ltokenCode cod, lsymbol sym, bool def)
00078 {
00079 llassert (LCLTokenTable != NULL);
00080
00081 if (!ltoken_isUndefined (LCLTokenTable[sym]))
00082 {
00083 ltoken_setCode (LCLTokenTable[sym], cod);
00084 ltoken_setDefined (LCLTokenTable[sym], def);
00085 }
00086 else
00087 {
00088 llfatalbug (message ("LCLUpdateToken: %s",
00089 cstring_fromChars (lsymbol_toChars (sym))));
00090 }
00091 }
00092
00093 void LCLSetTokenHasSyn (lsymbol sym, bool syn)
00094 {
00095 llassert (LCLTokenTable != NULL);
00096
00097 if (!ltoken_isUndefined (LCLTokenTable[sym]))
00098 {
00099 ltoken_setHasSyn (LCLTokenTable[sym], syn);
00100 }
00101 else
00102 {
00103 llfatalbug (message ("LCLSetTokenHasSyn: null token (%d)", (int)sym));
00104 }
00105 }
00106
00107 ltoken LCLGetToken (lsymbol sym)
00108 {
00109 llassert (LCLTokenTable != NULL);
00110 llassert (sym < MaxToken);
00111
00112 return LCLTokenTable[sym];
00113 }
00114
00115 #if 0
00116 bool LCLTokenTableContainsToken (ltoken tok)
00117 {
00118 unsigned long i;
00119
00120 if (LCLTokenTable != NULL) {
00121 for (i = 0; i < MaxToken; i++) {
00122 if (LCLTokenTable[i] == tok) {
00123 return TRUE;
00124 }
00125 }
00126 }
00127
00128 return FALSE;
00129 }
00130 # endif
00131
00132 ltoken
00133 LCLReserveToken (ltokenCode cod, char *txt)
00134 {
00135
00136
00137
00138
00139
00140 lsymbol sym;
00141
00142 setCodePoint ();
00143 sym = lsymbol_fromChars (txt);
00144
00145
00146
00147
00148
00149 return (LCLInsertToken (cod, sym, lsymbol_undefined, TRUE));
00150 }
00151
00152 static void
00153 AllocTokenTable (void)
00154 {
00155 long unsigned oldSize, newSize;
00156 long unsigned int i;
00157
00158 oldSize = MaxToken;
00159
00160 if (oldSize == 0)
00161 {
00162 newSize = INITTOKENTABLE;
00163 llassert (LCLTokenTable == NULL);
00164 LCLTokenTable = (ltoken *) dmalloc (newSize * sizeof (*LCLTokenTable));
00165 }
00166 else
00167 {
00168 o_ltoken *oldLCLTokenTable = LCLTokenTable;
00169
00170 llassert (oldLCLTokenTable != NULL);
00171
00172 newSize = (long unsigned) (DELTATOKENTABLE * oldSize);
00173 LCLTokenTable = (ltoken *) dmalloc (newSize * sizeof (*LCLTokenTable));
00174
00175 for (i = 0; i < oldSize; i++)
00176 {
00177 LCLTokenTable[i] = oldLCLTokenTable[i];
00178 }
00179
00180 sfree (oldLCLTokenTable);
00181 }
00182
00183 MaxToken = newSize;
00184
00185
00186 for (i = oldSize; i < newSize; i++)
00187 {
00188 LCLTokenTable[i] = ltoken_undefined;
00189 }
00190
00191 }
00192
00193 void
00194 LCLTokenTableInit (void)
00195 {
00196 MaxToken = 0;
00197 }
00198
00199 void
00200 LCLTokenTableCleanup (void)
00201 {
00202
00203 if (LCLTokenTable != NULL)
00204 {
00205 long unsigned i;
00206
00207 for (i = 0; i < MaxToken; i++)
00208 {
00209 ltoken tok = LCLTokenTable[i];
00210
00211 LCLTokenTable[i] = NULL;
00212 ltoken_free (tok);
00213
00214 }
00215
00216 sfree (LCLTokenTable);
00217 LCLTokenTable = NULL;
00218 }
00219
00220 }
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230