From e5bb46d2744624a662c5802e59952aff945337fa Mon Sep 17 00:00:00 2001 From: qining Date: Thu, 11 Aug 2016 19:32:43 -0400 Subject: [PATCH] Add getter for pointee, element type --- source/opt/types.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/opt/types.h b/source/opt/types.h index 59bfe64..20654e7 100644 --- a/source/opt/types.h +++ b/source/opt/types.h @@ -86,7 +86,7 @@ class Type { // A bunch of methods for casting this type to a given type. Returns this if the // cast can be done, nullptr otherwise. -#define DeclareCastMethod(target) \ +#define DeclareCastMethod(target) \ virtual target* As##target() { return nullptr; } \ virtual const target* As##target() const { return nullptr; } DeclareCastMethod(Void); @@ -159,6 +159,7 @@ class Vector : public Type { bool IsSame(Type* that) const override; std::string str() const override; + const Type* element_type() const { return element_type_; } Vector* AsVector() override { return this; } const Vector* AsVector() const override { return this; } @@ -175,6 +176,7 @@ class Matrix : public Type { bool IsSame(Type* that) const override; std::string str() const override; + const Type* element_type() const { return element_type_; } Matrix* AsMatrix() override { return this; } const Matrix* AsMatrix() const override { return this; } @@ -230,6 +232,7 @@ class Array : public Type { bool IsSame(Type* that) const override; std::string str() const override; + const Type* element_type() const { return element_type_; } Array* AsArray() override { return this; } const Array* AsArray() const override { return this; } @@ -246,6 +249,7 @@ class RuntimeArray : public Type { bool IsSame(Type* that) const override; std::string str() const override; + const Type* element_type() const { return element_type_; } RuntimeArray* AsRuntimeArray() override { return this; } const RuntimeArray* AsRuntimeArray() const override { return this; } @@ -298,6 +302,7 @@ class Pointer : public Type { bool IsSame(Type* that) const override; std::string str() const override; + const Type* pointee_type() const { return pointee_type_; } Pointer* AsPointer() override { return this; } const Pointer* AsPointer() const override { return this; } -- 2.7.4