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 "llbasic.h"
00030 # include "osd.h"
00031 # include "tokentable.h"
00032
00033 static long unsigned MaxToken;
00034 static o_ltoken *TokenTable;
00035
00036 static void AllocTokenTable (void) ;
00037
00038 ltoken
00039 LSLInsertToken (ltokenCode cod, lsymbol sym, lsymbol rTxt, bool def)
00040 {
00041 while (sym >= MaxToken)
00042 {
00043 AllocTokenTable ();
00044 }
00045
00046 llassert (TokenTable != NULL);
00047
00048 if (ltoken_isUndefined (TokenTable[sym]))
00049 {
00050 TokenTable[sym] = ltoken_create (cod, sym);
00051 ltoken_setRawText (TokenTable[sym], rTxt);
00052 ltoken_setDefined (TokenTable[sym], def);
00053 }
00054
00055 return TokenTable[sym];
00056 }
00057
00058 void
00059 LSLUpdateToken (ltokenCode cod, lsymbol sym, bool def)
00060 {
00061 llassert (TokenTable != NULL);
00062
00063 if (!ltoken_isUndefined (TokenTable[sym]))
00064 {
00065 ltoken_setCode (TokenTable[sym], cod);
00066 ltoken_setDefined (TokenTable[sym], def);
00067 }
00068 else
00069 {
00070 llfatalbug (message ("LSLUpdateToken: token not in table: %d, text: %s",
00071 (int) cod, cstring_fromChars (lsymbol_toChars (sym))));
00072 }
00073 }
00074
00075 void
00076 LSLSetTokenHasSyn (lsymbol sym, bool syn)
00077 {
00078 llassert (TokenTable != NULL);
00079
00080 if (!ltoken_isUndefined (TokenTable[sym]))
00081 {
00082 ltoken_setHasSyn (TokenTable[sym], syn);
00083 }
00084 else
00085 {
00086 llbuglit ("LSLSetTokenHasSyn: null token");
00087 }
00088 }
00089
00090 ltoken LSLGetToken (lsymbol sym)
00091 {
00092 llassert (TokenTable != NULL);
00093
00094 if (!((sym < MaxToken) || (!ltoken_isUndefined (TokenTable[sym]))))
00095 {
00096 llcontbuglit ("LSLGetToken: bad argument");
00097 return TokenTable[0];
00098 }
00099
00100 return TokenTable[sym];
00101 }
00102
00103 ltoken
00104 LSLReserveToken (ltokenCode cod, char *txt)
00105 {
00106 lsymbol sym;
00107
00108 sym = lsymbol_fromChars (txt);
00109
00110
00111
00112
00113
00114 return LSLInsertToken (cod, sym, lsymbol_undefined, TRUE);
00115 }
00116
00117 static void
00118 AllocTokenTable (void)
00119 {
00120 long unsigned oldSize, newSize;
00121 long unsigned int i;
00122
00123 oldSize = MaxToken;
00124
00125 if (oldSize == 0)
00126 {
00127 newSize = INITTOKENTABLE;
00128 llassert (TokenTable == NULL);
00129 TokenTable = (ltoken *) dmalloc (newSize * sizeof (*TokenTable));
00130 }
00131 else
00132 {
00133 o_ltoken *oldTokenTable = TokenTable;
00134
00135 newSize = (long unsigned) (DELTATOKENTABLE * oldSize);
00136 TokenTable = (ltoken *) dmalloc (newSize * sizeof (*TokenTable));
00137
00138 llassert (oldSize > 0);
00139 llassert (oldTokenTable != NULL);
00140
00141 for (i = 0; i < oldSize; i++)
00142 {
00143 TokenTable[i] = oldTokenTable[i];
00144 }
00145
00146 sfree (oldTokenTable);
00147 }
00148
00149
00150 for (i = oldSize; i < newSize; i++)
00151 {
00152 TokenTable[i] = ltoken_undefined;
00153 }
00154
00155
00156 MaxToken = newSize;
00157 }
00158
00159 void
00160 ltokenTableInit (void)
00161 {
00162 MaxToken = 0;
00163 }
00164
00165 void
00166 ltokenTableCleanup (void)
00167 {
00168 if (TokenTable != NULL)
00169 {
00170 long unsigned i;
00171
00172 for (i = 0; i < MaxToken; i++)
00173 {
00174 ltoken_free (TokenTable[i]);
00175 }
00176
00177 sfree (TokenTable);
00178 TokenTable = NULL;
00179 }
00180 }