mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
UserDefinedValueType: from simple name to canonical name.
This commit is contained in:
parent
0fa24c786b
commit
de01822999
@ -612,13 +612,31 @@ bool DeclarationRegistrationHelper::visitNode(ASTNode& _node)
|
||||
|
||||
if (auto* declaration = dynamic_cast<Declaration*>(&_node))
|
||||
registerDeclaration(*declaration);
|
||||
|
||||
if (auto* annotation = dynamic_cast<TypeDeclarationAnnotation*>(&_node.annotation()))
|
||||
{
|
||||
string canonicalName = dynamic_cast<Declaration const&>(_node).name();
|
||||
solAssert(!canonicalName.empty(), "");
|
||||
|
||||
for (
|
||||
ASTNode const* scope = m_currentScope;
|
||||
scope != nullptr;
|
||||
scope = m_scopes[scope]->enclosingNode()
|
||||
)
|
||||
if (auto decl = dynamic_cast<Declaration const*>(scope))
|
||||
{
|
||||
solAssert(!decl->name().empty(), "");
|
||||
canonicalName = decl->name() + "." + canonicalName;
|
||||
}
|
||||
|
||||
annotation->canonicalName = canonicalName;
|
||||
}
|
||||
|
||||
if (dynamic_cast<ScopeOpener const*>(&_node))
|
||||
enterNewSubScope(_node);
|
||||
|
||||
if (auto* variableScope = dynamic_cast<VariableScope*>(&_node))
|
||||
m_currentFunction = variableScope;
|
||||
if (auto* annotation = dynamic_cast<TypeDeclarationAnnotation*>(&_node.annotation()))
|
||||
annotation->canonicalName = currentCanonicalName();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -668,23 +686,4 @@ void DeclarationRegistrationHelper::registerDeclaration(Declaration& _declaratio
|
||||
solAssert(_declaration.annotation().contract == m_currentContract, "");
|
||||
}
|
||||
|
||||
string DeclarationRegistrationHelper::currentCanonicalName() const
|
||||
{
|
||||
string ret;
|
||||
for (
|
||||
ASTNode const* scope = m_currentScope;
|
||||
scope != nullptr;
|
||||
scope = m_scopes[scope]->enclosingNode()
|
||||
)
|
||||
{
|
||||
if (auto decl = dynamic_cast<Declaration const*>(scope))
|
||||
{
|
||||
if (!ret.empty())
|
||||
ret = "." + ret;
|
||||
ret = decl->name() + ret;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -176,9 +176,6 @@ private:
|
||||
|
||||
static bool isOverloadedFunction(Declaration const& _declaration1, Declaration const& _declaration2);
|
||||
|
||||
/// @returns the canonical name of the current scope.
|
||||
std::string currentCanonicalName() const;
|
||||
|
||||
std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& m_scopes;
|
||||
ASTNode const* m_currentScope = nullptr;
|
||||
VariableScope* m_currentFunction = nullptr;
|
||||
|
@ -341,6 +341,11 @@ Type const* UserDefinedValueTypeDefinition::type() const
|
||||
return TypeProvider::typeType(TypeProvider::userDefinedValueType(*this));
|
||||
}
|
||||
|
||||
TypeDeclarationAnnotation& UserDefinedValueTypeDefinition::annotation() const
|
||||
{
|
||||
return initAnnotation<TypeDeclarationAnnotation>();
|
||||
}
|
||||
|
||||
Type const* StructDefinition::type() const
|
||||
{
|
||||
solAssert(annotation().recursive.has_value(), "Requested struct type before DeclarationTypeChecker.");
|
||||
|
@ -750,6 +750,8 @@ public:
|
||||
|
||||
Type const* type() const override;
|
||||
|
||||
TypeDeclarationAnnotation& annotation() const override;
|
||||
|
||||
TypeName const* underlyingType() const { return m_underlyingType.get(); }
|
||||
bool isVisibleViaContractTypeAccess() const override { return true; }
|
||||
|
||||
|
@ -2555,7 +2555,7 @@ bool UserDefinedValueType::operator==(Type const& _other) const
|
||||
|
||||
string UserDefinedValueType::toString(bool /* _short */) const
|
||||
{
|
||||
return "user defined type " + definition().name();
|
||||
return "user defined type " + *definition().annotation().canonicalName;
|
||||
}
|
||||
|
||||
vector<tuple<string, Type const*>> UserDefinedValueType::makeStackItems() const
|
||||
|
Loading…
Reference in New Issue
Block a user