summaryrefslogtreecommitdiff
path: root/TypeIdentifier.hh
diff options
context:
space:
mode:
authorNagi5Yeq <wu@x-nagi.com>2020-05-31 04:03:00 +0800
committerNagi5Yeq <wu@x-nagi.com>2020-05-31 04:03:00 +0800
commitbd44c9eaef1f4dcbbd98d4489885566b6c7e5138 (patch)
treed664ec481b99e04386c47526b56085320edd9cde /TypeIdentifier.hh
parentfd21f31e654a97027799f0fdf3518fd639415121 (diff)
support for type alias
Diffstat (limited to 'TypeIdentifier.hh')
-rw-r--r--TypeIdentifier.hh62
1 files changed, 62 insertions, 0 deletions
diff --git a/TypeIdentifier.hh b/TypeIdentifier.hh
new file mode 100644
index 0000000..c939dcc
--- /dev/null
+++ b/TypeIdentifier.hh
@@ -0,0 +1,62 @@
+#ifndef PCC_TYPEIDENTIFIER_HH
+#define PCC_TYPEIDENTIFIER_HH
+
+#include "Context.hh"
+#include "Type.hh"
+
+namespace pcc {
+
+// since TypeAlias returns std::shared_ptr<Type> instead of llvm::Value*, we
+// won't use CodeGen() override.
+class TypeIdentifier {
+ public:
+ TypeIdentifier(Context* context, std::shared_ptr<Type> type = nullptr);
+ virtual std::shared_ptr<Type> GetType() = 0;
+
+ protected:
+ Context* context_;
+ std::shared_ptr<Type> type_;
+};
+
+class TrivialTypeIdentifier : public TypeIdentifier {
+ public:
+ TrivialTypeIdentifier(Context* context, std::shared_ptr<Type> type);
+ virtual std::shared_ptr<Type> GetType() override;
+};
+
+class AliasTypeIdentifier : public TypeIdentifier {
+ public:
+ AliasTypeIdentifier(Context* context, std::string&& alias);
+ virtual std::shared_ptr<Type> GetType() override;
+
+ protected:
+ std::string alias_;
+};
+
+// for pointers and arrays, so that we can create pointers to other alias type
+class PointerTypeIdentifier : public TypeIdentifier {
+ public:
+ PointerTypeIdentifier(Context* context,
+ std::shared_ptr<TypeIdentifier> ElementType);
+ virtual std::shared_ptr<Type> GetType() override;
+
+ protected:
+ std::shared_ptr<TypeIdentifier> ElementType_;
+};
+
+class ArrayTypeIdentifier : public TypeIdentifier {
+ public:
+ ArrayTypeIdentifier(Context* context,
+ std::shared_ptr<TypeIdentifier> ElementType,
+ std::shared_ptr<ExprNode> start,
+ std::shared_ptr<ExprNode> end);
+ virtual std::shared_ptr<Type> GetType() override;
+
+ protected:
+ std::shared_ptr<TypeIdentifier> ElementType_;
+ std::shared_ptr<ExprNode> start_;
+ std::shared_ptr<ExprNode> end_;
+};
+} // namespace pcc
+
+#endif // !PCC_TYPEIDENTIFIER_HH