mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fill out originLocation with nativeLocation when importing Yul AST
This commit is contained in:
parent
d23754eafd
commit
fc7e8c56dc
@ -409,6 +409,7 @@ bool ControlFlowBuilder::visit(InlineAssembly const& _inlineAssembly)
|
|||||||
void ControlFlowBuilder::visit(yul::Statement const& _statement)
|
void ControlFlowBuilder::visit(yul::Statement const& _statement)
|
||||||
{
|
{
|
||||||
solAssert(m_currentNode && m_inlineAssembly, "");
|
solAssert(m_currentNode && m_inlineAssembly, "");
|
||||||
|
solAssert(nativeLocationOf(_statement) == originLocationOf(_statement), "");
|
||||||
m_currentNode->location = langutil::SourceLocation::smallestCovering(m_currentNode->location, nativeLocationOf(_statement));
|
m_currentNode->location = langutil::SourceLocation::smallestCovering(m_currentNode->location, nativeLocationOf(_statement));
|
||||||
ASTWalker::visit(_statement);
|
ASTWalker::visit(_statement);
|
||||||
}
|
}
|
||||||
@ -496,14 +497,15 @@ void ControlFlowBuilder::operator()(yul::Identifier const& _identifier)
|
|||||||
solAssert(m_currentNode && m_inlineAssembly, "");
|
solAssert(m_currentNode && m_inlineAssembly, "");
|
||||||
auto const& externalReferences = m_inlineAssembly->annotation().externalReferences;
|
auto const& externalReferences = m_inlineAssembly->annotation().externalReferences;
|
||||||
if (externalReferences.count(&_identifier))
|
if (externalReferences.count(&_identifier))
|
||||||
{
|
|
||||||
if (auto const* declaration = dynamic_cast<VariableDeclaration const*>(externalReferences.at(&_identifier).declaration))
|
if (auto const* declaration = dynamic_cast<VariableDeclaration const*>(externalReferences.at(&_identifier).declaration))
|
||||||
|
{
|
||||||
|
solAssert(nativeLocationOf(_identifier) == originLocationOf(_identifier), "");
|
||||||
m_currentNode->variableOccurrences.emplace_back(
|
m_currentNode->variableOccurrences.emplace_back(
|
||||||
*declaration,
|
*declaration,
|
||||||
VariableOccurrence::Kind::Access,
|
VariableOccurrence::Kind::Access,
|
||||||
nativeLocationOf(_identifier)
|
nativeLocationOf(_identifier)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControlFlowBuilder::operator()(yul::Assignment const& _assignment)
|
void ControlFlowBuilder::operator()(yul::Assignment const& _assignment)
|
||||||
@ -514,11 +516,14 @@ void ControlFlowBuilder::operator()(yul::Assignment const& _assignment)
|
|||||||
for (auto const& variable: _assignment.variableNames)
|
for (auto const& variable: _assignment.variableNames)
|
||||||
if (externalReferences.count(&variable))
|
if (externalReferences.count(&variable))
|
||||||
if (auto const* declaration = dynamic_cast<VariableDeclaration const*>(externalReferences.at(&variable).declaration))
|
if (auto const* declaration = dynamic_cast<VariableDeclaration const*>(externalReferences.at(&variable).declaration))
|
||||||
|
{
|
||||||
|
solAssert(nativeLocationOf(variable) == originLocationOf(variable), "");
|
||||||
m_currentNode->variableOccurrences.emplace_back(
|
m_currentNode->variableOccurrences.emplace_back(
|
||||||
*declaration,
|
*declaration,
|
||||||
VariableOccurrence::Kind::Assignment,
|
VariableOccurrence::Kind::Assignment,
|
||||||
nativeLocationOf(variable)
|
nativeLocationOf(variable)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControlFlowBuilder::operator()(yul::FunctionCall const& _functionCall)
|
void ControlFlowBuilder::operator()(yul::FunctionCall const& _functionCall)
|
||||||
|
@ -201,9 +201,13 @@ bool ReferencesResolver::visit(Return const& _return)
|
|||||||
|
|
||||||
void ReferencesResolver::operator()(yul::FunctionDefinition const& _function)
|
void ReferencesResolver::operator()(yul::FunctionDefinition const& _function)
|
||||||
{
|
{
|
||||||
|
solAssert(nativeLocationOf(_function) == originLocationOf(_function), "");
|
||||||
validateYulIdentifierName(_function.name, nativeLocationOf(_function));
|
validateYulIdentifierName(_function.name, nativeLocationOf(_function));
|
||||||
for (yul::TypedName const& varName: _function.parameters + _function.returnVariables)
|
for (yul::TypedName const& varName: _function.parameters + _function.returnVariables)
|
||||||
|
{
|
||||||
|
solAssert(nativeLocationOf(varName) == originLocationOf(varName), "");
|
||||||
validateYulIdentifierName(varName.name, nativeLocationOf(varName));
|
validateYulIdentifierName(varName.name, nativeLocationOf(varName));
|
||||||
|
}
|
||||||
|
|
||||||
bool wasInsideFunction = m_yulInsideFunction;
|
bool wasInsideFunction = m_yulInsideFunction;
|
||||||
m_yulInsideFunction = true;
|
m_yulInsideFunction = true;
|
||||||
@ -213,6 +217,8 @@ void ReferencesResolver::operator()(yul::FunctionDefinition const& _function)
|
|||||||
|
|
||||||
void ReferencesResolver::operator()(yul::Identifier const& _identifier)
|
void ReferencesResolver::operator()(yul::Identifier const& _identifier)
|
||||||
{
|
{
|
||||||
|
solAssert(nativeLocationOf(_identifier) == originLocationOf(_identifier), "");
|
||||||
|
|
||||||
static set<string> suffixes{"slot", "offset", "length"};
|
static set<string> suffixes{"slot", "offset", "length"};
|
||||||
string suffix;
|
string suffix;
|
||||||
for (string const& s: suffixes)
|
for (string const& s: suffixes)
|
||||||
@ -275,9 +281,9 @@ void ReferencesResolver::operator()(yul::VariableDeclaration const& _varDecl)
|
|||||||
{
|
{
|
||||||
for (auto const& identifier: _varDecl.variables)
|
for (auto const& identifier: _varDecl.variables)
|
||||||
{
|
{
|
||||||
|
solAssert(nativeLocationOf(identifier) == originLocationOf(identifier), "");
|
||||||
validateYulIdentifierName(identifier.name, nativeLocationOf(identifier));
|
validateYulIdentifierName(identifier.name, nativeLocationOf(identifier));
|
||||||
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
auto declarations = m_resolver.nameFromCurrentScope(identifier.name.str());
|
auto declarations = m_resolver.nameFromCurrentScope(identifier.name.str());
|
||||||
!declarations.empty()
|
!declarations.empty()
|
||||||
|
@ -55,7 +55,10 @@ T AsmJsonImporter::createAsmNode(Json::Value const& _node)
|
|||||||
T r;
|
T r;
|
||||||
SourceLocation nativeLocation = createSourceLocation(_node);
|
SourceLocation nativeLocation = createSourceLocation(_node);
|
||||||
yulAssert(nativeLocation.hasText(), "Invalid source location in Asm AST");
|
yulAssert(nativeLocation.hasText(), "Invalid source location in Asm AST");
|
||||||
r.debugData = DebugData::create(nativeLocation);
|
// TODO: We should add originLocation to the AST.
|
||||||
|
// While it's not included, we'll use nativeLocation for it because we only support importing
|
||||||
|
// inline assembly as a part of a Solidity AST and there these locations are always the same.
|
||||||
|
r.debugData = DebugData::create(nativeLocation, nativeLocation);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user