[coco] Mark mutable fields as private (#1560)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Wed, 19 Sep 2018 04:20:12 +0000 (13:20 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 19 Sep 2018 04:20:12 +0000 (13:20 +0900)
This commit marks deps, reads, and updates methods in Bag as private
after renaming.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/include/coco/IR/Bag.h
contrib/coco/core/src/IR/Dep.cpp
contrib/coco/core/src/IR/Read.cpp
contrib/coco/core/src/IR/Update.cpp

index 296f9fe..de433d8 100644 (file)
@@ -88,13 +88,27 @@ public:
   // NOTE Unlike replaceWith(b), replaceAllDepsWith(b) has no restriction
   void replaceAllDepsWith(Bag *);
 
-public:
+private:
+  // "mutable_" prefix is deliberately introduced below to avoid resolution issue.
+  //
+  // Let's assume that two "deps" are overloaded in Bag as follows:
+  // class Bag
+  // {
+  // private:
+  //   DepSet *deps(void); <-- 1
+  // public:
+  //   const DepSet *deps(void) const; <-- 2
+  // };
+  //
+  // C++ compiler tries to invoke method 1 unless a bag itself is const. Thus, any "deps" calls
+  // over non-const bags except those calls from friend classes will introduce build error.
+
   // WARN Only Dep is allowed to access this method
-  DepSet *deps(void) { return &_deps; }
+  DepSet *mutable_deps(void) { return &_deps; }
   // WARN Only Read is allowed to access this method
-  ReadSet *reads(void) { return &_reads; }
+  ReadSet *mutable_reads(void) { return &_reads; }
   // WARN Only Update is allowed to access this method
-  UpdateSet *updates(void) { return &_updates; }
+  UpdateSet *mutable_updates(void) { return &_updates; }
 
 private:
   // WARN Only Input is allowed to access this method
index 4dccba8..22d18d4 100644 (file)
@@ -16,7 +16,7 @@ void Dep::bag(Bag *bag)
     // TODO Remove unnecessary indentation
     {
       assert(_bag->deps()->find(this) != _bag->deps()->end());
-      _bag->deps()->erase(this);
+      _bag->mutable_deps()->erase(this);
     }
 
     // Reset _bag
@@ -33,7 +33,7 @@ void Dep::bag(Bag *bag)
     // Create bag <-> dep link
     // TODO Remove unnecessary indentation
     {
-      _bag->deps()->insert(this);
+      _bag->mutable_deps()->insert(this);
     }
   }
 
index 10f04af..c3e626d 100644 (file)
@@ -17,7 +17,7 @@ void Read::bag(Bag *bag)
   {
     // TODO Remove unnecessary indentation
     {
-      _bag->reads()->erase(this);
+      _bag->mutable_reads()->erase(this);
     }
     _bag = nullptr;
   }
@@ -29,7 +29,7 @@ void Read::bag(Bag *bag)
     _bag = bag;
     // TODO Remove unnecessary indentation
     {
-      _bag->reads()->insert(this);
+      _bag->mutable_reads()->insert(this);
     }
   }
 
index 57a8435..4695c4f 100644 (file)
@@ -17,7 +17,7 @@ void Update::bag(Bag *bag)
   {
     // TODO Remove unnecessary indentation
     {
-      _bag->updates()->erase(this);
+      _bag->mutable_updates()->erase(this);
     }
     _bag = nullptr;
   }
@@ -29,7 +29,7 @@ void Update::bag(Bag *bag)
     _bag = bag;
     // TODO Remove unnecessary indentation
     {
-      _bag->updates()->insert(this);
+      _bag->mutable_updates()->insert(this);
     }
   }