From e9075be4f9b4b70170ab0eb0ae5ea6f728597dd8 Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Fri, 4 Sep 2020 15:10:53 +0100 Subject: [PATCH] base: Cleanup Debug::CompoundFlag 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 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34115 Reviewed-by: Jason Lowe-Power Reviewed-by: Gabe Black Maintainer: Jason Lowe-Power Tested-by: kokoro --- src/SConscript | 11 ++++------- src/base/debug.hh | 27 +++++---------------------- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/src/SConscript b/src/SConscript index d9cde285b..4b6db448c 100644 --- a/src/SConscript +++ b/src/SConscript @@ -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() diff --git a/src/base/debug.hh b/src/base/debug.hh index 7c9834ce7..479a83071 100644 --- a/src/base/debug.hh +++ b/src/base/debug.hh @@ -30,6 +30,7 @@ #ifndef __BASE_DEBUG_HH__ #define __BASE_DEBUG_HH__ +#include #include #include #include @@ -87,31 +88,13 @@ class CompoundFlag : public Flag protected: std::vector _kids; - void - addFlag(Flag *f) - { - if (f != nullptr) - _kids.push_back(f); - } - public: + template 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 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 kids() { return _kids; } -- 2.30.2