From c390f3d48946bad67bcc5cac1c91b4bae679285f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Aug 2019 22:34:12 -0400 Subject: [PATCH 1/5] driver: Add missing override specifiers where applicable Adds missing override specifiers to enforce correct virtual member function signatures. --- hecl/driver/ToolCook.hpp | 6 +++--- hecl/driver/ToolExtract.hpp | 4 ++-- hecl/driver/ToolHelp.hpp | 6 +++--- hecl/driver/ToolImage.hpp | 6 +++--- hecl/driver/ToolInit.hpp | 4 ++-- hecl/driver/ToolPackage.hpp | 6 +++--- hecl/driver/ToolSpec.hpp | 4 ++-- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/hecl/driver/ToolCook.hpp b/hecl/driver/ToolCook.hpp index 928bd50f3..051dec957 100644 --- a/hecl/driver/ToolCook.hpp +++ b/hecl/driver/ToolCook.hpp @@ -145,9 +145,9 @@ public: } } - hecl::SystemString toolName() const { return _SYS_STR("cook"); } + hecl::SystemString toolName() const override { return _SYS_STR("cook"); } - int run() { + int run() override { hecl::MultiProgressPrinter printer(true); hecl::ClientProcess cp(&printer); for (const hecl::ProjectPath& path : m_selectedItems) @@ -156,5 +156,5 @@ public: return 0; } - void cancel() { m_useProj->interruptCook(); } + void cancel() override { m_useProj->interruptCook(); } }; diff --git a/hecl/driver/ToolExtract.hpp b/hecl/driver/ToolExtract.hpp index eb3206e81..a1dc56afa 100644 --- a/hecl/driver/ToolExtract.hpp +++ b/hecl/driver/ToolExtract.hpp @@ -112,7 +112,7 @@ public: help.endWrap(); } - hecl::SystemString toolName() const { return _SYS_STR("extract"); } + hecl::SystemString toolName() const override { return _SYS_STR("extract"); } static void _recursivePrint(int level, hecl::Database::IDataSpec::ExtractReport& rep) { for (int l = 0; l < level; ++l) @@ -129,7 +129,7 @@ public: _recursivePrint(level + 1, child); } - int run() { + int run() override { if (m_specPasses.empty()) { if (XTERM_COLOR) fmt::print(fmt(_SYS_STR("" RED BOLD "NOTHING TO EXTRACT" NORMAL "\n"))); diff --git a/hecl/driver/ToolHelp.hpp b/hecl/driver/ToolHelp.hpp index 590cbf1ef..113595ea0 100644 --- a/hecl/driver/ToolHelp.hpp +++ b/hecl/driver/ToolHelp.hpp @@ -15,7 +15,7 @@ public: m_good = true; } - ~ToolHelp() {} + ~ToolHelp() override = default; static void Help(HelpOutput& help) { help.printBold( @@ -72,9 +72,9 @@ public: ho.go(); } - hecl::SystemString toolName() const { return _SYS_STR("help"); } + hecl::SystemString toolName() const override { return _SYS_STR("help"); } - int run() { + int run() override { ShowHelp(m_info.args.front()); return 0; } diff --git a/hecl/driver/ToolImage.hpp b/hecl/driver/ToolImage.hpp index 6644313b3..a5546ecdd 100644 --- a/hecl/driver/ToolImage.hpp +++ b/hecl/driver/ToolImage.hpp @@ -44,7 +44,7 @@ public: "provided a path within a project")); } - ~ToolImage() {} + ~ToolImage() override = default; static void Help(HelpOutput& help) { help.secHead(_SYS_STR("NAME")); @@ -71,9 +71,9 @@ public: help.endWrap(); } - hecl::SystemString toolName() const { return _SYS_STR("image"); } + hecl::SystemString toolName() const override { return _SYS_STR("image"); } - int run() { + int run() override { if (XTERM_COLOR) fmt::print(fmt(_SYS_STR("" GREEN BOLD "ABOUT TO IMAGE:" NORMAL "\n"))); else diff --git a/hecl/driver/ToolInit.hpp b/hecl/driver/ToolInit.hpp index 27adc5ad8..26f676ec1 100644 --- a/hecl/driver/ToolInit.hpp +++ b/hecl/driver/ToolInit.hpp @@ -36,7 +36,7 @@ public: m_dir = dir; } - int run() { + int run() override { if (!m_dir) return 1; size_t ErrorRef = logvisor::ErrorCount; @@ -73,5 +73,5 @@ public: help.endWrap(); } - hecl::SystemString toolName() const { return _SYS_STR("init"); } + hecl::SystemString toolName() const override { return _SYS_STR("init"); } }; diff --git a/hecl/driver/ToolPackage.hpp b/hecl/driver/ToolPackage.hpp index d5c42329d..983f16769 100644 --- a/hecl/driver/ToolPackage.hpp +++ b/hecl/driver/ToolPackage.hpp @@ -156,9 +156,9 @@ public: help.endWrap(); } - hecl::SystemString toolName() const { return _SYS_STR("package"); } + hecl::SystemString toolName() const override { return _SYS_STR("package"); } - int run() { + int run() override { if (XTERM_COLOR) fmt::print(fmt(_SYS_STR("" GREEN BOLD "ABOUT TO PACKAGE:" NORMAL "\n"))); else @@ -181,5 +181,5 @@ public: return 0; } - void cancel() { m_useProj->interruptCook(); } + void cancel() override { m_useProj->interruptCook(); } }; diff --git a/hecl/driver/ToolSpec.hpp b/hecl/driver/ToolSpec.hpp index 09515bfde..e6156f210 100644 --- a/hecl/driver/ToolSpec.hpp +++ b/hecl/driver/ToolSpec.hpp @@ -71,9 +71,9 @@ public: help.endWrap(); } - hecl::SystemString toolName() const { return _SYS_STR("spec"); } + hecl::SystemString toolName() const override { return _SYS_STR("spec"); } - int run() { + int run() override { if (!m_info.project) { for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY) { if (XTERM_COLOR) From 11364cbd53984d69453ecdb8f7c8f10efce2762a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Aug 2019 22:35:30 -0400 Subject: [PATCH 2/5] driver/ToolBase: Make operator bool() explicit Prevents error-prone conversions to bool. --- hecl/driver/ToolBase.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hecl/driver/ToolBase.hpp b/hecl/driver/ToolBase.hpp index 6a28a7251..1e6b82ca3 100644 --- a/hecl/driver/ToolBase.hpp +++ b/hecl/driver/ToolBase.hpp @@ -96,7 +96,7 @@ public: virtual hecl::SystemString toolName() const = 0; virtual int run() = 0; virtual void cancel() {} - inline operator bool() const { return m_good; } + explicit operator bool() const { return m_good; } }; class HelpOutput { From f746b30b03963160c7d341edd2bd8f11390904d8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Aug 2019 22:49:24 -0400 Subject: [PATCH 3/5] driver: Make tool constructors explicit Enforces being explicit when constructing instances of these types. --- hecl/driver/ToolBase.hpp | 4 ++-- hecl/driver/ToolCook.hpp | 2 +- hecl/driver/ToolExtract.hpp | 2 +- hecl/driver/ToolHelp.hpp | 2 +- hecl/driver/ToolImage.hpp | 2 +- hecl/driver/ToolInit.hpp | 2 +- hecl/driver/ToolPackage.hpp | 2 +- hecl/driver/ToolSpec.hpp | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hecl/driver/ToolBase.hpp b/hecl/driver/ToolBase.hpp index 1e6b82ca3..990c46b24 100644 --- a/hecl/driver/ToolBase.hpp +++ b/hecl/driver/ToolBase.hpp @@ -88,7 +88,7 @@ protected: } public: - ToolBase(const ToolPassInfo& info) : m_info(info) { + explicit ToolBase(const ToolPassInfo& info) : m_info(info) { hecl::VerbosityLevel = info.verbosityLevel; hecl::GuiMode = info.gui; } @@ -156,7 +156,7 @@ private: } public: - HelpOutput(HelpFunc helpFunc) + explicit HelpOutput(HelpFunc helpFunc) : m_sout(NULL), m_helpFunc(helpFunc), m_lineWidth(hecl::GuiMode ? 120 : hecl::ConsoleWidth()) {} void go() { diff --git a/hecl/driver/ToolCook.hpp b/hecl/driver/ToolCook.hpp index 051dec957..1f3e83702 100644 --- a/hecl/driver/ToolCook.hpp +++ b/hecl/driver/ToolCook.hpp @@ -13,7 +13,7 @@ class ToolCook final : public ToolBase { bool m_fast = false; public: - ToolCook(const ToolPassInfo& info) : ToolBase(info), m_useProj(info.project) { + explicit ToolCook(const ToolPassInfo& info) : ToolBase(info), m_useProj(info.project) { /* Check for recursive flag */ for (hecl::SystemChar arg : info.flags) if (arg == _SYS_STR('r')) diff --git a/hecl/driver/ToolExtract.hpp b/hecl/driver/ToolExtract.hpp index a1dc56afa..b1c1f617d 100644 --- a/hecl/driver/ToolExtract.hpp +++ b/hecl/driver/ToolExtract.hpp @@ -27,7 +27,7 @@ class ToolExtract final : public ToolBase { hecl::Database::Project* m_useProj = nullptr; public: - ToolExtract(const ToolPassInfo& info) : ToolBase(info) { + explicit ToolExtract(const ToolPassInfo& info) : ToolBase(info) { if (!m_info.args.size()) LogModule.report(logvisor::Fatal, fmt("hecl extract needs a source path as its first argument")); diff --git a/hecl/driver/ToolHelp.hpp b/hecl/driver/ToolHelp.hpp index 113595ea0..79045613a 100644 --- a/hecl/driver/ToolHelp.hpp +++ b/hecl/driver/ToolHelp.hpp @@ -7,7 +7,7 @@ class ToolHelp final : public ToolBase { public: - ToolHelp(const ToolPassInfo& info) : ToolBase(info) { + explicit ToolHelp(const ToolPassInfo& info) : ToolBase(info) { if (m_info.args.empty()) { LogModule.report(logvisor::Error, fmt("help requires a tool name argument")); return; diff --git a/hecl/driver/ToolImage.hpp b/hecl/driver/ToolImage.hpp index a5546ecdd..fcab3405a 100644 --- a/hecl/driver/ToolImage.hpp +++ b/hecl/driver/ToolImage.hpp @@ -15,7 +15,7 @@ class ToolImage final : public ToolBase { hecl::Database::Project* m_useProj; public: - ToolImage(const ToolPassInfo& info) : ToolBase(info), m_useProj(info.project) { + explicit ToolImage(const ToolPassInfo& info) : ToolBase(info), m_useProj(info.project) { if (!info.project) LogModule.report(logvisor::Fatal, fmt("hecl image must be ran within a project directory")); diff --git a/hecl/driver/ToolInit.hpp b/hecl/driver/ToolInit.hpp index 26f676ec1..90bd3f515 100644 --- a/hecl/driver/ToolInit.hpp +++ b/hecl/driver/ToolInit.hpp @@ -7,7 +7,7 @@ class ToolInit final : public ToolBase { const hecl::SystemString* m_dir = NULL; public: - ToolInit(const ToolPassInfo& info) : ToolBase(info) { + explicit ToolInit(const ToolPassInfo& info) : ToolBase(info) { hecl::Sstat theStat; const hecl::SystemString* dir; if (info.args.size()) diff --git a/hecl/driver/ToolPackage.hpp b/hecl/driver/ToolPackage.hpp index 983f16769..ebbb20f2d 100644 --- a/hecl/driver/ToolPackage.hpp +++ b/hecl/driver/ToolPackage.hpp @@ -59,7 +59,7 @@ class ToolPackage final : public ToolBase { } public: - ToolPackage(const ToolPassInfo& info) : ToolBase(info), m_useProj(info.project) { + explicit ToolPackage(const ToolPassInfo& info) : ToolBase(info), m_useProj(info.project) { if (!info.project) LogModule.report(logvisor::Fatal, fmt("hecl package must be ran within a project directory")); diff --git a/hecl/driver/ToolSpec.hpp b/hecl/driver/ToolSpec.hpp index e6156f210..ec96a4f25 100644 --- a/hecl/driver/ToolSpec.hpp +++ b/hecl/driver/ToolSpec.hpp @@ -8,7 +8,7 @@ class ToolSpec final : public ToolBase { enum Mode { MLIST = 0, MENABLE, MDISABLE } mode = MLIST; public: - ToolSpec(const ToolPassInfo& info) : ToolBase(info) { + explicit ToolSpec(const ToolPassInfo& info) : ToolBase(info) { if (info.args.empty()) return; From 789650d4c0542a950e8a878e5232fe17e08b546d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Aug 2019 22:51:04 -0400 Subject: [PATCH 4/5] driver/ToolBase: Convert typedef into using alias Same thing, but a little nicer to read. --- hecl/driver/ToolBase.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hecl/driver/ToolBase.hpp b/hecl/driver/ToolBase.hpp index 990c46b24..b154c52ba 100644 --- a/hecl/driver/ToolBase.hpp +++ b/hecl/driver/ToolBase.hpp @@ -101,7 +101,7 @@ public: class HelpOutput { public: - typedef void (*HelpFunc)(HelpOutput&); + using HelpFunc = void (*)(HelpOutput&); private: FILE* m_sout; From 19f49e071dbb04a184f1a0d1acacd1e678ceaf7f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 19 Aug 2019 22:52:33 -0400 Subject: [PATCH 5/5] driver: Use nullptr instead of NULL where applicable Same thing, but more typesafe, given all NULL is, is a literal 0. --- hecl/driver/ToolBase.hpp | 4 ++-- hecl/driver/ToolHelp.hpp | 2 +- hecl/driver/ToolInit.hpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hecl/driver/ToolBase.hpp b/hecl/driver/ToolBase.hpp index b154c52ba..d5f9502cd 100644 --- a/hecl/driver/ToolBase.hpp +++ b/hecl/driver/ToolBase.hpp @@ -104,7 +104,7 @@ public: using HelpFunc = void (*)(HelpOutput&); private: - FILE* m_sout; + FILE* m_sout = nullptr; HelpFunc m_helpFunc; int m_lineWidth; hecl::SystemString m_wrapBuffer; @@ -157,7 +157,7 @@ private: public: explicit HelpOutput(HelpFunc helpFunc) - : m_sout(NULL), m_helpFunc(helpFunc), m_lineWidth(hecl::GuiMode ? 120 : hecl::ConsoleWidth()) {} + : m_helpFunc(helpFunc), m_lineWidth(hecl::GuiMode ? 120 : hecl::ConsoleWidth()) {} void go() { #if _WIN32 diff --git a/hecl/driver/ToolHelp.hpp b/hecl/driver/ToolHelp.hpp index 79045613a..b698f5747 100644 --- a/hecl/driver/ToolHelp.hpp +++ b/hecl/driver/ToolHelp.hpp @@ -50,7 +50,7 @@ public: static void ShowHelp(const hecl::SystemString& toolName) { /* Select tool's help-text streamer */ - HelpOutput::HelpFunc helpFunc = NULL; + HelpOutput::HelpFunc helpFunc = nullptr; if (toolName == _SYS_STR("init")) helpFunc = ToolInit::Help; else if (toolName == _SYS_STR("spec")) diff --git a/hecl/driver/ToolInit.hpp b/hecl/driver/ToolInit.hpp index 90bd3f515..e799a2f76 100644 --- a/hecl/driver/ToolInit.hpp +++ b/hecl/driver/ToolInit.hpp @@ -4,7 +4,7 @@ #include class ToolInit final : public ToolBase { - const hecl::SystemString* m_dir = NULL; + const hecl::SystemString* m_dir = nullptr; public: explicit ToolInit(const ToolPassInfo& info) : ToolBase(info) {