base: Cleanup Debug::CompoundFlag
authorAndreas Sandberg <andreas.sandberg@arm.com>
Fri, 4 Sep 2020 14:10:53 +0000 (15:10 +0100)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Mon, 7 Sep 2020 08:42:07 +0000 (08:42 +0000)
Compound flags are currently constructed using a constructor with a
finite set of arguments that default to nullptr that refer to child
flags. C++11 introduces two cleaner ways to achieve the same thing,
variadic templates and initializer_list. Use an initializer list to
pass dependent flags.

Change-Id: Iadcd04986ab20efccfae9b92b26c079b9612262e
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34115
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/SConscript
src/base/debug.hh

index d9cde285b008d6a03df79a0d3233333e1b1c0c41..4b6db448ceed5f07aafa98c15613da31bfb136ed 100644 (file)
@@ -1071,15 +1071,12 @@ namespace Debug {
         if not compound:
             code('SimpleFlag $name("$name", "$desc");')
         else:
-            comp_code('CompoundFlag $name("$name", "$desc",')
+            comp_code('CompoundFlag $name("$name", "$desc", {')
             comp_code.indent()
-            last = len(compound) - 1
-            for i,flag in enumerate(compound):
-                if i != last:
-                    comp_code('&$flag,')
-                else:
-                    comp_code('&$flag);')
+            for flag in compound:
+                comp_code('&$flag,')
             comp_code.dedent()
+            comp_code('});')
 
     code.append(comp_code)
     code()
index 7c9834ce7ac5a50916f66e8fb03cf9bfdf130d3d..479a830716b0ab90b7f4a6eb0f209cd6e03f765a 100644 (file)
@@ -30,6 +30,7 @@
 #ifndef __BASE_DEBUG_HH__
 #define __BASE_DEBUG_HH__
 
+#include <initializer_list>
 #include <map>
 #include <string>
 #include <vector>
@@ -87,31 +88,13 @@ class CompoundFlag : public Flag
   protected:
     std::vector<Flag *> _kids;
 
-    void
-    addFlag(Flag *f)
-    {
-        if (f != nullptr)
-            _kids.push_back(f);
-    }
-
   public:
+    template<typename... Args>
     CompoundFlag(const char *name, const char *desc,
-        Flag *f00 = nullptr, Flag *f01 = nullptr,
-        Flag *f02 = nullptr, Flag *f03 = nullptr,
-        Flag *f04 = nullptr, Flag *f05 = nullptr,
-        Flag *f06 = nullptr, Flag *f07 = nullptr,
-        Flag *f08 = nullptr, Flag *f09 = nullptr,
-        Flag *f10 = nullptr, Flag *f11 = nullptr,
-        Flag *f12 = nullptr, Flag *f13 = nullptr,
-        Flag *f14 = nullptr, Flag *f15 = nullptr,
-        Flag *f16 = nullptr, Flag *f17 = nullptr,
-        Flag *f18 = nullptr, Flag *f19 = nullptr)
-        : Flag(name, desc)
+                 std::initializer_list<Flag *> flags)
+        : Flag(name, desc),
+          _kids(flags)
     {
-        addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04);
-        addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09);
-        addFlag(f10); addFlag(f11); addFlag(f12); addFlag(f13); addFlag(f14);
-        addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19);
     }
 
     std::vector<Flag *> kids() { return _kids; }