From 434d8843b2aa2509dd257a7ae29678dc29d5a97e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Fri, 21 Sep 2018 08:51:58 +0900 Subject: [PATCH] [coco] Instr::Visitor as abstract class (instead of interface) (#1605) This commit introduces pure virtual Instr::IVisitor interface, and revises Instr::Vistor as abstract class. This change aims to minimize changes upon Instr extension. Signed-off-by: Jonghyun Park --- contrib/coco/core/include/coco/IR/Instr.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/contrib/coco/core/include/coco/IR/Instr.h b/contrib/coco/core/include/coco/IR/Instr.h index 0d29872..3d31077 100644 --- a/contrib/coco/core/include/coco/IR/Instr.h +++ b/contrib/coco/core/include/coco/IR/Instr.h @@ -47,19 +47,24 @@ public: #undef INSTR public: - template struct Visitor + /** + * @brief Instr visitor interface + * + * WARN Use this interface only for coco-internal classes + * (to minimize changes upon Instr extension) + */ + template struct IVisitor { - virtual ~Visitor() = default; + virtual ~IVisitor() = default; #define INSTR(Name) virtual T visit(const Name *) = 0; #include "coco/IR/Instr.lst" #undef INSTR }; -public: - template struct DefaultVisitor : public Visitor + template struct Visitor : public IVisitor { - virtual ~DefaultVisitor() = default; + virtual ~Visitor() = default; #define INSTR(Name) \ T visit(const Name *) override { throw std::runtime_error{"NYI"}; } @@ -67,8 +72,11 @@ public: #undef INSTR }; + // Deprecated. Use Visitor instead + template using DefaultVisitor = Visitor; + public: - template T accept(Visitor *v) const + template T accept(IVisitor *v) const { #define INSTR(Name) \ if (auto ins = as##Name()) \ @@ -80,8 +88,8 @@ public: throw std::runtime_error{"unreachable"}; } - template T accept(Visitor &v) const { return accept(&v); } - template T accept(Visitor &&v) const { return accept(&v); } + template T accept(IVisitor &v) const { return accept(&v); } + template T accept(IVisitor &&v) const { return accept(&v); } public: struct Mutator -- 2.7.4