UserDefinedValueType: from simple name to canonical name.

This commit is contained in:
hrkrshnn 2021-09-14 17:31:00 +02:00
parent 0fa24c786b
commit de01822999
5 changed files with 28 additions and 25 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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.");

View File

@ -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; }

View File

@ -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