1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 1999, 2001 SIL International. All rights reserved.
Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.
File: GrcManager.cpp
Responsibility: Sharon Correll
Last reviewed: Not yet.
Description:
Implements the main object that manages the compliation process.
-------------------------------------------------------------------------------*//*:End Ignore*/
/***********************************************************************************************
Include files
***********************************************************************************************/
#include "main.h"
#ifdef _MSC_VER
#pragma hdrstop
#endif
#undef THIS_FILE
DEFINE_THIS_FILE
/***********************************************************************************************
Forward declarations
***********************************************************************************************/
/***********************************************************************************************
Local Constants and static variables
***********************************************************************************************/
GrcManager g_cman;
/***********************************************************************************************
Methods: General
***********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Constructor
----------------------------------------------------------------------------------------------*/
GrcManager::GrcManager()
{
Init();
}
void GrcManager::Init()
{
m_prndr = new GdlRenderer();
m_prndr->SetLineAndFile(GrpLineAndFile(1, 1, ""));
m_psymtbl = new GrcSymbolTable(true);
m_venv.resize(1);
// Temporary structures used during parsing:
m_mtbGlyphAttrs = new GrcMasterTable;
m_mtbFeatures = new GrcMasterTable;
m_mvlNameStrings = new GrcMasterValueList;
m_pgax = NULL;
m_plclist = NULL;
m_prgvpglfcFsmClasses = NULL;
m_fOutputDebugFiles = false;
m_fOutputDebugXml = false;
m_fBasicJust = false;
m_nNameTblStart = -1;
m_fxdSilfTableVersion = 0;
m_fxdGlocTableVersion = 0;
m_fxdGlatTableVersion = 0;
m_fxdFeatTableVersion = 0;
m_fxdSillTableVersion = 0;
}
/*----------------------------------------------------------------------------------------------
Destructor
----------------------------------------------------------------------------------------------*/
GrcManager::~GrcManager()
{
Clear();
}
void GrcManager::Clear()
{
if (m_prgvpglfcFsmClasses)
delete[] m_prgvpglfcFsmClasses;
size_t i;
for (i = 0; i < m_vpexpModified.size(); ++i)
delete m_vpexpModified[i];
m_vpexpModified.clear();
if (m_pgax)
delete m_pgax;
if (m_plclist)
delete m_plclist;
if (m_prndr)
delete m_prndr;
if (m_mtbGlyphAttrs)
delete m_mtbGlyphAttrs;
if (m_mtbFeatures)
delete m_mtbFeatures;
if (m_mvlNameStrings)
delete m_mvlNameStrings;
if (m_psymtbl)
delete m_psymtbl;
for (i = 0; i < this->m_vplcls.size(); i++)
delete m_vplcls[i];
m_vplcls.clear();
for (i = 0; i < m_vpfeatInput.size(); ++i)
delete m_vpfeatInput[i];
}
/***********************************************************************************************
Methods: Getters and setters
***********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Return the number of justification levels.
----------------------------------------------------------------------------------------------*/
int GrcManager::NumJustLevels()
{
int cRet = m_nMaxJLevel;
if (cRet == -1)
cRet = 1; // no levels specified
else if (cRet == -2)
cRet = 0; // no justification
else
cRet++; // to account for level 0
cRet = min(cRet, 4);
return cRet;
}
/***********************************************************************************************
Methods: Parser
***********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Push a new environment corresponding to a table statement. Records an error if the
string is not a valid table name.
----------------------------------------------------------------------------------------------*/
GrcEnv * GrcManager::PushTableEnv(GrpLineAndFile & lnf, std::string staTableName)
{
Symbol psymTable = SymbolTable()->FindSymbol(staTableName);
if (!psymTable || !psymTable->FitsSymbolType(ksymtTable))
{
g_errorList.AddError(1181, NULL,
"Invalid table name: ",
staTableName,
lnf);
return PushGeneralEnv(lnf); // just push a copy of current env
}
else
{
GrcEnv * penvPrev = &(m_venv[m_venv.size() - 1]);
Symbol psymPrevTable = penvPrev->Table();
int nPrevPass = penvPrev->Pass();
std::pair<Symbol, int> hmpair;
hmpair.first = psymPrevTable;
hmpair.second = nPrevPass;
m_hmpsymnCurrPass.insert(hmpair);
//m_hmpsymnCurrPass.Insert(psymPrevTable, nPrevPass, true);
GrcEnv * penvNew = PushEnvAux();
penvNew->SetTable(psymTable);
int nPass = 0;
std::map<Symbol, int>::iterator hmit = m_hmpsymnCurrPass.find(psymTable);
if (hmit != m_hmpsymnCurrPass.end())
nPass = hmit->second;
//m_hmpsymnCurrPass.Retrieve(psymTable, &nPass);
penvNew->SetPass(nPass);
return penvNew;
}
}
/*----------------------------------------------------------------------------------------------
Push a new environment corresponding to a pass statement.
----------------------------------------------------------------------------------------------*/
GrcEnv * GrcManager::PushPassEnv(GrpLineAndFile & lnf, int nPass)
{
GrcEnv * penvNew = PushEnvAux();
penvNew->SetPass(nPass);
Symbol psymTable = penvNew->Table();
std::pair<Symbol, int> hmpair;
hmpair.first = psymTable;
hmpair.second = nPass;
m_hmpsymnCurrPass.insert(hmpair);
//m_hmpsymnCurrPass.Insert(psymTable, nPass, true);
if (!psymTable->FitsSymbolType(ksymtTableRule))
{
g_errorList.AddError(1182, NULL,
psymTable->FullName(),
" table cannot hold passes",
lnf);
}
return penvNew;
}
/*----------------------------------------------------------------------------------------------
Push a new environment corresponding to an environment statement.
----------------------------------------------------------------------------------------------*/
GrcEnv * GrcManager::PushGeneralEnv(GrpLineAndFile & /*lnf*/)
{
return PushEnvAux();
}
/*----------------------------------------------------------------------------------------------
Push a new environment initialized from the previous one. Return a pointer to the new one.
----------------------------------------------------------------------------------------------*/
GrcEnv * GrcManager::PushEnvAux()
{
GrcEnv envToCopy(m_venv.back()); // make a local copy, because the act of pushing can cause
// the vector to resize, losing the item to copy
m_venv.push_back(envToCopy);
return &(m_venv.back());
}
/*----------------------------------------------------------------------------------------------
Pop the top environment. Return a pointer to the new top.
Arguments:
nLine - line number
staStmt - for error message: "table", "pass", "environment"
----------------------------------------------------------------------------------------------*/
GrcEnv * GrcManager::PopEnv(GrpLineAndFile & lnf, std::string staStmt)
{
// There should never be less than one environment on the stack, since the recipient
// is initialized with one.
if (m_venv.size() <= 1)
{
g_errorList.AddError(1183, NULL,
"End",
staStmt,
" encountered without balancing ",
staStmt,
" statement",
lnf);
return &(m_venv.back());
}
m_venv.pop_back();
GrcEnv * penv = &(m_venv.back());
Symbol psymTable = penv->Table();
int nPass = penv->Pass();
m_hmpsymnCurrPass.erase(psymTable);
std::pair<Symbol, int> hmpair;
hmpair.first = psymTable;
hmpair.second = nPass;
m_hmpsymnCurrPass.insert(hmpair);
//m_hmpsymnCurrPass.Insert(psymTable, nPass, true); // true: overwrite previous value
return penv;
}
/*----------------------------------------------------------------------------------------------
Add a class with the given name.
----------------------------------------------------------------------------------------------*/
GdlGlyphClassDefn * GrcManager::AddGlyphClass(GrpLineAndFile const& lnf, std::string staClassName)
{
GrcStructName xns(staClassName);
Symbol psymClass = m_psymtbl->AddClassSymbol(xns, lnf);
GdlGlyphClassDefn * pglfc = dynamic_cast<GdlGlyphClassDefn*>(psymClass->Data());
Assert(pglfc);
m_prndr->AddGlyphClass(pglfc);
pglfc->SetName(staClassName);
return pglfc;
}
/*----------------------------------------------------------------------------------------------
Add an anonymous class; assign it a generated name.
----------------------------------------------------------------------------------------------*/
GdlGlyphClassDefn * GrcManager::AddAnonymousClass(GrpLineAndFile const& lnf)
{
Symbol psymClass = m_psymtbl->AddAnonymousClassSymbol(lnf);
GdlGlyphClassDefn * pglfc = dynamic_cast<GdlGlyphClassDefn*>(psymClass->Data());
Assert(pglfc);
m_prndr->AddGlyphClass(pglfc);
pglfc->SetName(std::string(psymClass->FieldAt(0)));
return pglfc;
}
/*----------------------------------------------------------------------------------------------
Set up the GDL objects from the master tables.
----------------------------------------------------------------------------------------------*/
void GrcManager::ProcessMasterTables()
{
m_mtbFeatures->SetupFeatures();
m_mtbGlyphAttrs->SetupGlyphAttrs();
m_mvlNameStrings->SetupNameDefns(m_prndr->NameAssignmentsMap());
}
/***********************************************************************************************
Methods: For test procedures
***********************************************************************************************/
/*----------------------------------------------------------------------------------------------
Delete the context of the GrcManager and reinitialize so we can use it for another
test procedure.
----------------------------------------------------------------------------------------------*/
void GrcManager::test_Recycle()
{
Clear();
Init();
}
|