mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Refactoring yul source locations.
This commit is contained in:
+34
-18
@@ -21,8 +21,8 @@
|
||||
* Solidity inline assembly parser.
|
||||
*/
|
||||
|
||||
#include <libyul/AsmParser.h>
|
||||
#include <libyul/AST.h>
|
||||
#include <libyul/AsmParser.h>
|
||||
#include <libyul/Exceptions.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
@@ -40,6 +40,21 @@ using namespace solidity::util;
|
||||
using namespace solidity::langutil;
|
||||
using namespace solidity::yul;
|
||||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]]
|
||||
shared_ptr<DebugData const> updateLocationEndFrom(
|
||||
shared_ptr<DebugData const> const& _debugData,
|
||||
langutil::SourceLocation const& _location
|
||||
)
|
||||
{
|
||||
SourceLocation updatedLocation = _debugData->location;
|
||||
updatedLocation.end = _location.end;
|
||||
return make_shared<DebugData const>(updatedLocation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
unique_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner)
|
||||
{
|
||||
m_recursionDepth = 0;
|
||||
@@ -70,7 +85,7 @@ Block Parser::parseBlock()
|
||||
expectToken(Token::LBrace);
|
||||
while (currentToken() != Token::RBrace)
|
||||
block.statements.emplace_back(parseStatement());
|
||||
block.location.end = currentLocation().end;
|
||||
block.debugData = updateLocationEndFrom(block.debugData, currentLocation());
|
||||
advance();
|
||||
return block;
|
||||
}
|
||||
@@ -109,7 +124,7 @@ Statement Parser::parseStatement()
|
||||
fatalParserError(4904_error, "Case not allowed after default case.");
|
||||
if (_switch.cases.empty())
|
||||
fatalParserError(2418_error, "Switch statement without any cases.");
|
||||
_switch.location.end = _switch.cases.back().body.location.end;
|
||||
_switch.debugData = updateLocationEndFrom(_switch.debugData, _switch.cases.back().body.debugData->location);
|
||||
return Statement{move(_switch)};
|
||||
}
|
||||
case Token::For:
|
||||
@@ -150,13 +165,13 @@ Statement Parser::parseStatement()
|
||||
case Token::LParen:
|
||||
{
|
||||
Expression expr = parseCall(std::move(elementary));
|
||||
return ExpressionStatement{locationOf(expr), move(expr)};
|
||||
return ExpressionStatement{debugDataOf(expr), move(expr)};
|
||||
}
|
||||
case Token::Comma:
|
||||
case Token::AssemblyAssign:
|
||||
{
|
||||
Assignment assignment;
|
||||
assignment.location = locationOf(elementary);
|
||||
assignment.debugData = debugDataOf(elementary);
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -191,7 +206,7 @@ Statement Parser::parseStatement()
|
||||
expectToken(Token::AssemblyAssign);
|
||||
|
||||
assignment.value = make_unique<Expression>(parseExpression());
|
||||
assignment.location.end = locationOf(*assignment.value).end;
|
||||
assignment.debugData = updateLocationEndFrom(assignment.debugData, locationOf(*assignment.value));
|
||||
|
||||
return Statement{move(assignment)};
|
||||
}
|
||||
@@ -221,7 +236,7 @@ Case Parser::parseCase()
|
||||
else
|
||||
yulAssert(false, "Case or default case expected.");
|
||||
_case.body = parseBlock();
|
||||
_case.location.end = _case.body.location.end;
|
||||
_case.debugData = updateLocationEndFrom(_case.debugData, _case.body.debugData->location);
|
||||
return _case;
|
||||
}
|
||||
|
||||
@@ -241,7 +256,7 @@ ForLoop Parser::parseForLoop()
|
||||
forLoop.post = parseBlock();
|
||||
m_currentForLoopComponent = ForLoopComponent::ForLoopBody;
|
||||
forLoop.body = parseBlock();
|
||||
forLoop.location.end = forLoop.body.location.end;
|
||||
forLoop.debugData = updateLocationEndFrom(forLoop.debugData, forLoop.body.debugData->location);
|
||||
|
||||
m_currentForLoopComponent = outerForLoopComponent;
|
||||
|
||||
@@ -261,7 +276,7 @@ Expression Parser::parseExpression()
|
||||
if (m_dialect.builtin(_identifier.name))
|
||||
fatalParserError(
|
||||
7104_error,
|
||||
_identifier.location,
|
||||
_identifier.debugData->location,
|
||||
"Builtin function \"" + _identifier.name.str() + "\" must be called."
|
||||
);
|
||||
return move(_identifier);
|
||||
@@ -280,7 +295,7 @@ variant<Literal, Identifier> Parser::parseLiteralOrIdentifier()
|
||||
{
|
||||
case Token::Identifier:
|
||||
{
|
||||
Identifier identifier{currentLocation(), YulString{currentLiteral()}};
|
||||
Identifier identifier{DebugData::create(currentLocation()), YulString{currentLiteral()}};
|
||||
advance();
|
||||
return identifier;
|
||||
}
|
||||
@@ -311,7 +326,7 @@ variant<Literal, Identifier> Parser::parseLiteralOrIdentifier()
|
||||
}
|
||||
|
||||
Literal literal{
|
||||
currentLocation(),
|
||||
DebugData::create(currentLocation()),
|
||||
kind,
|
||||
YulString{currentLiteral()},
|
||||
kind == LiteralKind::Boolean ? m_dialect.boolType : m_dialect.defaultType
|
||||
@@ -320,7 +335,7 @@ variant<Literal, Identifier> Parser::parseLiteralOrIdentifier()
|
||||
if (currentToken() == Token::Colon)
|
||||
{
|
||||
expectToken(Token::Colon);
|
||||
literal.location.end = currentLocation().end;
|
||||
literal.debugData = updateLocationEndFrom(literal.debugData, currentLocation());
|
||||
literal.type = expectAsmIdentifier();
|
||||
}
|
||||
|
||||
@@ -352,10 +367,11 @@ VariableDeclaration Parser::parseVariableDeclaration()
|
||||
{
|
||||
expectToken(Token::AssemblyAssign);
|
||||
varDecl.value = make_unique<Expression>(parseExpression());
|
||||
varDecl.location.end = locationOf(*varDecl.value).end;
|
||||
varDecl.debugData = updateLocationEndFrom(varDecl.debugData, locationOf(*varDecl.value));
|
||||
}
|
||||
else
|
||||
varDecl.location.end = varDecl.variables.back().location.end;
|
||||
varDecl.debugData = updateLocationEndFrom(varDecl.debugData, varDecl.variables.back().debugData->location);
|
||||
|
||||
return varDecl;
|
||||
}
|
||||
|
||||
@@ -400,7 +416,7 @@ FunctionDefinition Parser::parseFunctionDefinition()
|
||||
m_insideFunction = true;
|
||||
funDef.body = parseBlock();
|
||||
m_insideFunction = preInsideFunction;
|
||||
funDef.location.end = funDef.body.location.end;
|
||||
funDef.debugData = updateLocationEndFrom(funDef.debugData, funDef.body.debugData->location);
|
||||
|
||||
m_currentForLoopComponent = outerForLoopComponent;
|
||||
return funDef;
|
||||
@@ -415,7 +431,7 @@ FunctionCall Parser::parseCall(variant<Literal, Identifier>&& _initialOp)
|
||||
|
||||
FunctionCall ret;
|
||||
ret.functionName = std::move(std::get<Identifier>(_initialOp));
|
||||
ret.location = ret.functionName.location;
|
||||
ret.debugData = ret.functionName.debugData;
|
||||
|
||||
expectToken(Token::LParen);
|
||||
if (currentToken() != Token::RParen)
|
||||
@@ -427,7 +443,7 @@ FunctionCall Parser::parseCall(variant<Literal, Identifier>&& _initialOp)
|
||||
ret.arguments.emplace_back(parseExpression());
|
||||
}
|
||||
}
|
||||
ret.location.end = currentLocation().end;
|
||||
ret.debugData = updateLocationEndFrom(ret.debugData, currentLocation());
|
||||
expectToken(Token::RParen);
|
||||
return ret;
|
||||
}
|
||||
@@ -440,7 +456,7 @@ TypedName Parser::parseTypedName()
|
||||
if (currentToken() == Token::Colon)
|
||||
{
|
||||
expectToken(Token::Colon);
|
||||
typedName.location.end = currentLocation().end;
|
||||
typedName.debugData = updateLocationEndFrom(typedName.debugData, currentLocation());
|
||||
typedName.type = expectAsmIdentifier();
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user