patterns: Fixed eval_depth default and preprocessor errors

This commit is contained in:
WerWolv
2021-03-15 08:11:19 +01:00
parent 2326e090af
commit f34b946ea9
5 changed files with 26 additions and 20 deletions

View File

@@ -119,7 +119,7 @@ namespace hex::lang {
if (replaceValue.empty())
throwPreprocessorError("no value given in #define directive", lineNumber);
this->m_defines.emplace(defineName, replaceValue);
this->m_defines.emplace(defineName, replaceValue, lineNumber);
} else if (code.substr(offset, 6) == "pragma") {
offset += 6;
@@ -151,7 +151,7 @@ namespace hex::lang {
if (pragmaValue.empty())
throwPreprocessorError("missing value in #pragma directive", lineNumber);
this->m_pragmas.emplace(pragmaKey, pragmaValue);
this->m_pragmas.emplace(pragmaKey, pragmaValue, lineNumber);
} else
throwPreprocessorError("unknown preprocessor directive", lineNumber);
} else if (code.substr(offset, 2) == "//") {
@@ -181,13 +181,13 @@ namespace hex::lang {
if (initialRun) {
// Apply defines
std::vector<std::pair<std::string, std::string>> sortedDefines;
std::vector<std::tuple<std::string, std::string, u32>> sortedDefines;
std::copy(this->m_defines.begin(), this->m_defines.end(), std::back_inserter(sortedDefines));
std::sort(sortedDefines.begin(), sortedDefines.end(), [](const auto &left, const auto &right) {
return left.first.size() > right.first.size();
return std::get<0>(left).size() > std::get<0>(right).size();
});
for (const auto &[define, value] : sortedDefines) {
for (const auto &[define, value, defineLine] : sortedDefines) {
s32 index = 0;
while((index = output.find(define, index)) != std::string::npos) {
output.replace(index, define.length(), value);
@@ -196,12 +196,12 @@ namespace hex::lang {
}
// Handle pragmas
for (const auto &[type, value] : this->m_pragmas) {
for (const auto &[type, value, pragmaLine] : this->m_pragmas) {
if (this->m_pragmaHandlers.contains(type)) {
if (!this->m_pragmaHandlers[type](value))
throwPreprocessorError(hex::format("invalid value provided to '{0}' #pragma directive", type.c_str()), lineNumber);
throwPreprocessorError(hex::format("invalid value provided to '{0}' #pragma directive", type.c_str()), pragmaLine);
} else
throwPreprocessorError(hex::format("no #pragma handler registered for type {0}", type.c_str()), lineNumber);
throwPreprocessorError(hex::format("no #pragma handler registered for type {0}", type.c_str()), pragmaLine);
}
}
} catch (PreprocessorError &e) {