1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 12:37:45 +00:00

LibCpp: Differentiate between Type and NamedType

This adds a new ASTNode type called 'NamedType' which inherits from
the Type node.

Previously every Type node had a name field, but it was not logically
accurate. For example, pointer types do not have a name
(the pointed-to type may have one).
This commit is contained in:
Itamar 2021-06-26 15:34:23 +03:00 committed by Ali Mohammad Pur
parent 10cad8a874
commit d7aa831a43
5 changed files with 55 additions and 29 deletions

View file

@ -198,19 +198,35 @@ class Type : public ASTNode {
public:
virtual ~Type() override = default;
virtual const char* class_name() const override { return "Type"; }
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
virtual bool is_type() const override { return true; }
virtual bool is_templatized() const { return false; }
virtual String to_string() const;
virtual bool is_named_type() const { return false; }
virtual String to_string() const = 0;
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
bool m_is_auto { false };
Vector<StringView> m_qualifiers;
protected:
Type(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename)
: ASTNode(parent, start, end, filename)
{
}
};
class NamedType : public Type {
public:
virtual ~NamedType() override = default;
virtual const char* class_name() const override { return "NamedType"; }
virtual String to_string() const override;
virtual bool is_named_type() const override { return true; }
NamedType(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename)
: Type(parent, start, end, filename)
{
}
bool m_is_auto { false };
RefPtr<Name> m_name;
Vector<StringView> m_qualifiers;
};
class Pointer : public Type {