From 556aeac2df593ec97b3fd1b59b510970a84eaff8 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 16 Sep 2024 12:09:27 -0700 Subject: [PATCH] drop code for handling undefines Since 0.12 dropped support for undefines, we can remove the code to support it as well. --- src/cps/loader.cpp | 12 +++--------- src/cps/loader.hpp | 8 ++------ src/cps/printer.cpp | 8 +++----- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/cps/loader.cpp b/src/cps/loader.cpp index 37cc26a..9617a42 100644 --- a/src/cps/loader.cpp +++ b/src/cps/loader.cpp @@ -279,17 +279,11 @@ namespace cps::loader { } // namespace - Define::Define(std::string name_) : name{std::move(name_)}, value{}, define{true} {}; - Define::Define(std::string name_, std::string value_) - : name{std::move(name_)}, value{std::move(value_)}, define{true} {}; - Define::Define(std::string name_, bool define_) : name{std::move(name_)}, value{}, define{define_} {}; - - bool Define::is_undefine() const { return !define; } - - bool Define::is_define() const { return define && value.empty(); } + Define::Define(std::string name_) : name{std::move(name_)}, value{std::nullopt} {}; + Define::Define(std::string name_, std::string value_) : name{std::move(name_)}, value{std::move(value_)} {}; std::string Define::get_name() const { return name; } - std::string Define::get_value() const { return value; } + std::optional Define::get_value() const { return value; } Configuration::Configuration() = default; Configuration::Configuration(LangValues cflags) : compile_flags{std::move(cflags)} {}; diff --git a/src/cps/loader.hpp b/src/cps/loader.hpp index 1c39b68..5b68d4b 100644 --- a/src/cps/loader.hpp +++ b/src/cps/loader.hpp @@ -47,17 +47,13 @@ namespace cps::loader { public: Define(std::string name); Define(std::string name, std::string value); - Define(std::string name, bool define); - bool is_undefine() const; - bool is_define() const; std::string get_name() const; - std::string get_value() const; + std::optional get_value() const; private: std::string name; - std::string value; - bool define; + std::optional value; }; using LangValues = std::unordered_map>; diff --git a/src/cps/printer.cpp b/src/cps/printer.cpp index a413f89..01dd9da 100644 --- a/src/cps/printer.cpp +++ b/src/cps/printer.cpp @@ -40,12 +40,10 @@ namespace cps::printer { if (auto && f = r.definitions.find(loader::KnownLanguages::c); f != r.definitions.end() && !f->second.empty()) { auto && transformer = [](auto && d) { - if (d.is_define()) { - return fmt::format("-D{}", d.get_name()); - } else if (d.is_undefine()) { - return fmt::format("-U{}", d.get_name()); + if (auto && v = d.get_value()) { + return fmt::format("-D{}={}", d.get_name(), v.value()); } else { - return fmt::format("-D{}={}", d.get_name(), d.get_value()); + return fmt::format("-D{}", d.get_name()); } }; args.reserve(args.size() + f->second.size());