Simplified Parser::createWithLocation().

In all but one case the function was called with the default argument value.
And when it was location, the location should be valid (see Parser::parseElementaryOperation()).
This commit is contained in:
a3d4 2020-02-05 22:13:03 +01:00
parent dd7a5c3386
commit 7fecab07a8
2 changed files with 5 additions and 12 deletions

View File

@ -206,8 +206,8 @@ Statement Parser::parseStatement()
elementary = parseElementaryOperation(); elementary = parseElementaryOperation();
} }
Assignment assignment = Assignment assignment;
createWithLocation<Assignment>(std::get<Identifier>(elementary).location); assignment.location = std::get<Identifier>(elementary).location;
assignment.variableNames = std::move(variableNames); assignment.variableNames = std::move(variableNames);
expectToken(Token::AssemblyAssign); expectToken(Token::AssemblyAssign);

View File

@ -60,18 +60,11 @@ public:
protected: protected:
using ElementaryOperation = std::variant<Literal, Identifier, FunctionCall>; using ElementaryOperation = std::variant<Literal, Identifier, FunctionCall>;
/// Creates an inline assembly node with the given source location. /// Creates an inline assembly node with the current source location.
template <class T> T createWithLocation(langutil::SourceLocation const& _loc = {}) const template <class T> T createWithLocation() const
{ {
T r; T r;
r.location = _loc; r.location = location();
if (!r.location.hasText())
{
r.location.start = position();
r.location.end = endPosition();
}
if (!r.location.source)
r.location.source = m_scanner->charStream();
return r; return r;
} }
langutil::SourceLocation location() const { return {position(), endPosition(), m_scanner->charStream()}; } langutil::SourceLocation location() const { return {position(), endPosition(), m_scanner->charStream()}; }