From 5e3208317922d20a5b3b760df872a589d87bf94d Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 20 Feb 2015 15:52:30 +0100 Subject: Parsing of array types and basic implementation. --- AST.h | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'AST.h') diff --git a/AST.h b/AST.h index 064457d3..594f8f4b 100644 --- a/AST.h +++ b/AST.h @@ -441,7 +441,7 @@ public: virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - TypeName const* getTypeName() const { return m_typeName.get(); } + TypeName* getTypeName() { return m_typeName.get(); } ASTPointer const& getValue() const { return m_value; } /// Returns the declared or inferred type. Can be an empty pointer if no type was explicitly @@ -588,7 +588,7 @@ public: /// Retrieve the element of the type hierarchy this node refers to. Can return an empty shared /// pointer until the types have been resolved using the @ref NameAndTypeResolver. /// If it returns an empty shared pointer after that, this indicates that the type was not found. - virtual std::shared_ptr toType() const = 0; + virtual std::shared_ptr toType() = 0; }; /** @@ -605,7 +605,7 @@ public: } virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - virtual std::shared_ptr toType() const override { return Type::fromElementaryTypeName(m_type); } + virtual std::shared_ptr toType() override { return Type::fromElementaryTypeName(m_type); } Token::Value getTypeName() const { return m_type; } @@ -623,7 +623,7 @@ public: TypeName(_location), m_name(_name), m_referencedDeclaration(nullptr) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - virtual std::shared_ptr toType() const override { return Type::fromUserDefinedTypeName(*this); } + virtual std::shared_ptr toType() override { return Type::fromUserDefinedTypeName(*this); } ASTString const& getName() const { return *m_name; } void setReferencedDeclaration(Declaration const& _referencedDeclaration) { m_referencedDeclaration = &_referencedDeclaration; } @@ -646,7 +646,7 @@ public: TypeName(_location), m_keyType(_keyType), m_valueType(_valueType) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - virtual std::shared_ptr toType() const override { return Type::fromMapping(*this); } + virtual TypePointer toType() override { return Type::fromMapping(*m_keyType, *m_valueType); } ElementaryTypeName const& getKeyType() const { return *m_keyType; } TypeName const& getValueType() const { return *m_valueType; } @@ -656,6 +656,27 @@ private: ASTPointer m_valueType; }; +/** + * An array type, can be "typename[]" or "typename[]". + */ +class ArrayTypeName: public TypeName +{ +public: + ArrayTypeName(Location const& _location, ASTPointer const& _baseType, + ASTPointer const& _length): + TypeName(_location), m_baseType(_baseType), m_length(_length) {} + virtual void accept(ASTVisitor& _visitor) override; + virtual void accept(ASTConstVisitor& _visitor) const override; + virtual std::shared_ptr toType() override { return Type::fromArrayTypeName(*m_baseType, m_length.get()); } + + TypeName const& getBaseType() const { return *m_baseType; } + Expression const* getLength() const { return m_length.get(); } + +private: + ASTPointer m_baseType; + ASTPointer m_length; ///< Length of the array, might be empty. +}; + /// @} /// Statements -- cgit v1.2.3