Provide generic access to type definition for user-defined types.

This commit is contained in:
chriseth 2022-03-09 10:41:57 +01:00
parent 145186f68c
commit 7bd6cba79c
2 changed files with 26 additions and 0 deletions

View File

@ -2341,6 +2341,11 @@ TypeResult StructType::interfaceType(bool _inLibrary) const
return *m_interfaceType_library;
}
Declaration const* StructType::typeDefinition() const
{
return &structDefinition();
}
BoolResult StructType::validForLocation(DataLocation _loc) const
{
for (auto const& member: m_struct.members())
@ -2473,6 +2478,11 @@ Type const* EnumType::encodingType() const
return TypeProvider::uint(8);
}
Declaration const* EnumType::typeDefinition() const
{
return &enumDefinition();
}
TypeResult EnumType::unaryOperatorResult(Token _operator) const
{
return _operator == Token::Delete ? TypeProvider::emptyTuple() : nullptr;
@ -2541,6 +2551,11 @@ Type const& UserDefinedValueType::underlyingType() const
return *type;
}
Declaration const* UserDefinedValueType::typeDefinition() const
{
return &m_definition;
}
string UserDefinedValueType::richIdentifier() const
{
return "t_userDefinedValueType" + parenthesizeIdentifier(m_definition.name()) + to_string(m_definition.id());

View File

@ -369,6 +369,10 @@ public:
/// are returned without modification.
virtual TypeResult interfaceType(bool /*_inLibrary*/) const { return nullptr; }
/// @returns the declaration of a user defined type (enum, struct, user defined value type).
/// Returns nullptr otherwise.
virtual Declaration const* typeDefinition() const { return nullptr; }
/// Clears all internally cached values (if any).
virtual void clearCache() const;
@ -1004,6 +1008,8 @@ public:
Type const* encodingType() const override;
TypeResult interfaceType(bool _inLibrary) const override;
Declaration const* typeDefinition() const override;
BoolResult validForLocation(DataLocation _loc) const override;
bool recursive() const;
@ -1069,6 +1075,8 @@ public:
return _inLibrary ? this : encodingType();
}
Declaration const* typeDefinition() const override;
EnumDefinition const& enumDefinition() const { return m_enum; }
/// @returns the value that the string has in the Enum
unsigned int memberValue(ASTString const& _member) const;
@ -1101,6 +1109,9 @@ public:
TypeResult binaryOperatorResult(Token, Type const*) const override { return nullptr; }
Type const* encodingType() const override { return &underlyingType(); }
TypeResult interfaceType(bool /* _inLibrary */) const override {return &underlyingType(); }
Declaration const* typeDefinition() const override;
std::string richIdentifier() const override;
bool operator==(Type const& _other) const override;