Label* SymbolTable::getLabel(const std::wstring& symbol, unsigned int file, unsigned int section) { if (isValidSymbolName(symbol) == false) return NULL; int actualSection = section; setFileSectionValues(symbol,file,section); SymbolKey key = { symbol, file, section }; // find label, create new one if it doesn't exist auto it = symbols.find(key); if (it == symbols.end()) { SymbolInfo value = { LabelSymbol, labels.size() }; symbols[key] = value; Label* result = new Label(symbol); if (section == actualSection) result->setSection(section); // local, set section of parent else result->setSection(actualSection+1); // global, set section of children labels.push_back(result); return result; } // make sure not to match symbols that aren't labels if (it->second.type != LabelSymbol) return NULL; return labels[it->second.index]; }
bool SymbolTable::symbolExists(const std::wstring& symbol, unsigned int file, unsigned int section) { if (isValidSymbolName(symbol) == false) return false; setFileSectionValues(symbol,file,section); SymbolKey key = { symbol, file, section }; auto it = symbols.find(key); return it != symbols.end(); }
bool SymbolTable::findEquation(const std::wstring& name, int file, int section, size_t& dest) { setFileSectionValues(name,file,section); SymbolKey key = { name, file, section }; auto it = symbols.find(key); if (it == symbols.end() || it->second.type != EquationSymbol) return false; dest = it->second.index; return true; }
bool SymbolTable::addEquation(const std::wstring& name, int file, int section, size_t referenceIndex) { if (isValidSymbolName(name) == false) return false; if (symbolExists(name,file,section)) return false; setFileSectionValues(name,file,section); SymbolKey key = { name, file, section }; SymbolInfo value = { EquationSymbol, referenceIndex }; symbols[key] = value; equationsCount++; return true; }
bool SymbolTable::addEquation(const std::wstring& name, unsigned int file, unsigned int section, std::wstring& replacement) { if (isValidSymbolName(name) == false) return false; if (symbolExists(name,file,section)) return false; setFileSectionValues(name,file,section); SymbolKey key = { name, file, section }; SymbolInfo value = { EquationSymbol, equations.size() }; symbols[key] = value; Equation equation = { name, replacement, file, section }; equations.push_back(equation); return true; }