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();
}
Assignment assignment =
createWithLocation<Assignment>(std::get<Identifier>(elementary).location);
Assignment assignment;
assignment.location = std::get<Identifier>(elementary).location;
assignment.variableNames = std::move(variableNames);
expectToken(Token::AssemblyAssign);

View File

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