diff --git a/src/cps/loader.cpp b/src/cps/loader.cpp index 2ff54be..37d20f5 100644 --- a/src/cps/loader.cpp +++ b/src/cps/loader.cpp @@ -284,17 +284,12 @@ namespace cps::loader { } // namespace - Define::Define(std::string name_) : name{std::move(name_)}, value{}, define{true} {}; + 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_)}, 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(); } + : 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 3b933e1..d949b25 100644 --- a/src/cps/loader.hpp +++ b/src/cps/loader.hpp @@ -49,17 +49,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 47859cf..01dd9da 100644 --- a/src/cps/printer.cpp +++ b/src/cps/printer.cpp @@ -37,14 +37,13 @@ namespace cps::printer { } if (conf.defines) { - if (auto && f = r.definitions.find(loader::KnownLanguages::c); f != r.definitions.end() && !f->second.empty()) { + 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());