Fix error in define expression crash

This commit is contained in:
Jan 2022-09-07 22:00:18 +02:00
parent b3dbf4a104
commit bba6fd9d4e
4 changed files with 7 additions and 7 deletions

View File

@ -277,9 +277,9 @@ bool DefinesStreamProxy::MatchUndefDirective(const ParserLine& line, const unsig
return true;
}
std::unique_ptr<ISimpleExpression> DefinesStreamProxy::ParseExpression(std::string expressionString) const
std::unique_ptr<ISimpleExpression> DefinesStreamProxy::ParseExpression(std::shared_ptr<std::string> fileName, int lineNumber, std::string expressionString) const
{
ParserLine pseudoLine(nullptr, 1, std::move(expressionString));
ParserLine pseudoLine(std::move(fileName), lineNumber, std::move(expressionString));
ExpandDefinedExpressions(pseudoLine);
ExpandDefines(pseudoLine);
@ -314,7 +314,7 @@ bool DefinesStreamProxy::MatchIfDirective(const ParserLine& line, const unsigned
if (expressionString.empty())
throw ParsingException(CreatePos(line, currentPos), "Cannot if without an expression.");
const auto expression = ParseExpression(expressionString);
const auto expression = ParseExpression(line.m_filename, line.m_line_number, expressionString);
if (!expression)
throw ParsingException(CreatePos(line, currentPos), "Failed to parse if expression");
@ -356,7 +356,7 @@ bool DefinesStreamProxy::MatchElIfDirective(const ParserLine& line, const unsign
if (expressionString.empty())
throw ParsingException(CreatePos(line, currentPos), "Cannot elif without an expression.");
const auto expression = ParseExpression(expressionString);
const auto expression = ParseExpression(line.m_filename, line.m_line_number, expressionString);
if (!expression)
throw ParsingException(CreatePos(line, currentPos), "Failed to parse elif expression");

View File

@ -91,7 +91,7 @@ public:
void ExpandDefines(ParserLine& line) const;
_NODISCARD std::unique_ptr<ISimpleExpression> ParseExpression(std::string expressionString) const;
_NODISCARD std::unique_ptr<ISimpleExpression> ParseExpression(std::shared_ptr<std::string> fileName, int lineNumber, std::string expressionString) const;
ParserLine NextLine() override;
bool IncludeFile(const std::string& filename) override;

View File

@ -41,7 +41,7 @@ bool SetDefineStreamProxy::MatchSetDirective(const ParserLine& line, const unsig
if (expressionString.empty())
throw ParsingException(CreatePos(line, currentPosition), "Cannot set without an expression.");
const auto expression = m_defines_proxy->ParseExpression(expressionString);
const auto expression = m_defines_proxy->ParseExpression(line.m_filename, line.m_line_number, expressionString);
if (!expression)
throw ParsingException(CreatePos(line, currentPosition), "Failed to parse set expression");

View File

@ -110,7 +110,7 @@ bool TemplatingStreamProxy::MatchFilenameDirective(const ParserLine& line, const
if (expressionString.empty())
throw ParsingException(CreatePos(line, currentPosition), "Cannot pragma filename without an expression.");
const auto expression = m_defines_proxy->ParseExpression(expressionString);
const auto expression = m_defines_proxy->ParseExpression(line.m_filename, line.m_line_number, expressionString);
if (!expression)
throw ParsingException(CreatePos(line, currentPosition), "Failed to parse pragma filename expression");