diff options
author | Itamar <itamar8910@gmail.com> | 2021-03-29 16:52:35 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-06 21:51:58 +0200 |
commit | 3295609aea3cbd1d0de4d347634b12ce0762185b (patch) | |
tree | f5d246b8dfe770d08eb495c44569c07650628cb6 /Userland/Libraries/LibCpp/AST.h | |
parent | 29b6915db90cd9e22c7e873171e53edda535fca7 (diff) | |
download | serenity-3295609aea3cbd1d0de4d347634b12ce0762185b.zip |
LibCpp: Add AST::Name
A Name node is basically an identifier with an optional scope,
e.g Core::File.
Diffstat (limited to 'Userland/Libraries/LibCpp/AST.h')
-rw-r--r-- | Userland/Libraries/LibCpp/AST.h | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/Userland/Libraries/LibCpp/AST.h b/Userland/Libraries/LibCpp/AST.h index 487c2c094a..9634d40ebc 100644 --- a/Userland/Libraries/LibCpp/AST.h +++ b/Userland/Libraries/LibCpp/AST.h @@ -43,6 +43,7 @@ class FunctionDefinition; class Type; class Parameter; class Statement; +class Name; class ASTNode : public RefCounted<ASTNode> { public: @@ -76,6 +77,7 @@ public: virtual bool is_function_call() const { return false; } virtual bool is_type() const { return false; } virtual bool is_declaration() const { return false; } + virtual bool is_name() const {return false;} protected: ASTNode(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename) @@ -212,7 +214,6 @@ class Type : public ASTNode { public: virtual ~Type() override = default; virtual const char* class_name() const override { return "Type"; } - const StringView& name() const { return m_name; } virtual void dump(size_t indent) const override; virtual bool is_type() const override { return true; } virtual bool is_templatized() const { return false; } @@ -222,7 +223,7 @@ public: { } - StringView m_name; + RefPtr<Name> m_name; Vector<StringView> m_qualifiers; }; @@ -341,6 +342,23 @@ public: StringView m_name; }; +class Name : public Expression { +public: + virtual ~Name() override = default; + virtual const char* class_name() const override { return "Name"; } + virtual void dump(size_t indent) const override; + virtual bool is_name() const override {return true;} + + Name(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename) + : Expression(parent, start, end, filename) + { + } + String full_name() const; + + RefPtr<Identifier> m_name; + NonnullRefPtrVector<Identifier> m_scope; +}; + class NumericLiteral : public Expression { public: virtual ~NumericLiteral() override = default; @@ -453,7 +471,7 @@ public: virtual void dump(size_t indent) const override; virtual bool is_function_call() const override { return true; } - StringView m_name; + RefPtr<Name> m_name; NonnullRefPtrVector<Expression> m_arguments; }; @@ -577,7 +595,7 @@ public: virtual bool is_member_expression() const override { return true; } RefPtr<Expression> m_object; - RefPtr<Identifier> m_property; + RefPtr<Expression> m_property; }; class ForStatement : public Statement { |