[coco] Instr::Visitor as abstract class (instead of interface) (#1605)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 20 Sep 2018 23:51:58 +0000 (08:51 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 20 Sep 2018 23:51:58 +0000 (08:51 +0900)
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 <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Instr.h

index 0d29872..3d31077 100644 (file)
@@ -47,19 +47,24 @@ public:
 #undef INSTR
 
 public:
-  template <typename T> struct Visitor
+  /**
+   * @brief Instr visitor interface
+   *
+   * WARN Use this interface only for coco-internal classes
+   *      (to minimize changes upon Instr extension)
+   */
+  template <typename T> 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 <typename T> struct DefaultVisitor : public Visitor<T>
+  template <typename T> struct Visitor : public IVisitor<T>
   {
-    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 <typename T> using DefaultVisitor = Visitor<T>;
+
 public:
-  template <typename T> T accept(Visitor<T> *v) const
+  template <typename T> T accept(IVisitor<T> *v) const
   {
 #define INSTR(Name)          \
   if (auto ins = as##Name()) \
@@ -80,8 +88,8 @@ public:
     throw std::runtime_error{"unreachable"};
   }
 
-  template <typename T> T accept(Visitor<T> &v) const { return accept(&v); }
-  template <typename T> T accept(Visitor<T> &&v) const { return accept(&v); }
+  template <typename T> T accept(IVisitor<T> &v) const { return accept(&v); }
+  template <typename T> T accept(IVisitor<T> &&v) const { return accept(&v); }
 
 public:
   struct Mutator