diff options
author | Gabor Bencze <b.gabor98@gmail.com> | 2019-08-04 16:35:43 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-08-20 18:42:19 (GMT) |
commit | 71724633a24fccfdf3d56a19176d8afe637be843 (patch) | |
tree | 2d21e3a116cc34aee647054ad8543568c7cbc2e1 | |
parent | 2b58ae75773ff826bb1c3e6c5a3bad31c5292f00 (diff) | |
download | CMake-71724633a24fccfdf3d56a19176d8afe637be843.zip CMake-71724633a24fccfdf3d56a19176d8afe637be843.tar.gz CMake-71724633a24fccfdf3d56a19176d8afe637be843.tar.bz2 |
cmCommand refactor: cmMathCommand
-rw-r--r-- | Source/cmCommands.cxx | 2 | ||||
-rw-r--r-- | Source/cmMathCommand.cxx | 37 | ||||
-rw-r--r-- | Source/cmMathCommand.h | 27 |
3 files changed, 25 insertions, 41 deletions
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 6dd3e92..68122af 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -148,7 +148,7 @@ void GetScriptingCommands(cmState* state) state->AddBuiltinCommand("macro", cmMacroCommand); state->AddBuiltinCommand("make_directory", cmMakeDirectoryCommand); state->AddBuiltinCommand("mark_as_advanced", cmMarkAsAdvancedCommand); - state->AddBuiltinCommand("math", cm::make_unique<cmMathCommand>()); + state->AddBuiltinCommand("math", cmMathCommand); state->AddBuiltinCommand("message", cm::make_unique<cmMessageCommand>()); state->AddBuiltinCommand("option", cm::make_unique<cmOptionCommand>()); state->AddBuiltinCommand("cmake_parse_arguments", diff --git a/Source/cmMathCommand.cxx b/Source/cmMathCommand.cxx index 48b9a27..83c22aa 100644 --- a/Source/cmMathCommand.cxx +++ b/Source/cmMathCommand.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmMathCommand.h" +#include "cmExecutionStatus.h" #include "cmExprParserHelper.h" #include "cmMakefile.h" #include "cmMessageType.h" @@ -9,28 +10,33 @@ #include <stdio.h> -class cmExecutionStatus; +namespace { +bool HandleExprCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); +} -bool cmMathCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +bool cmMathCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if (args.empty()) { - this->SetError("must be called with at least one argument."); + status.SetError("must be called with at least one argument."); return false; } const std::string& subCommand = args[0]; if (subCommand == "EXPR") { - return this->HandleExprCommand(args); + return HandleExprCommand(args, status); } std::string e = "does not recognize sub-command " + subCommand; - this->SetError(e); + status.SetError(e); return false; } -bool cmMathCommand::HandleExprCommand(std::vector<std::string> const& args) +namespace { +bool HandleExprCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { if ((args.size() != 3) && (args.size() != 5)) { - this->SetError("EXPR called with incorrect arguments."); + status.SetError("EXPR called with incorrect arguments."); return false; } @@ -46,7 +52,7 @@ bool cmMathCommand::HandleExprCommand(std::vector<std::string> const& args) size_t argumentIndex = 3; NumericFormat outputFormat = NumericFormat::UNINITIALIZED; - this->Makefile->AddDefinition(outputVariable, "ERROR"); + status.GetMakefile().AddDefinition(outputVariable, "ERROR"); if (argumentIndex < args.size()) { const std::string messageHint = "sub-command EXPR "; @@ -61,19 +67,19 @@ bool cmMathCommand::HandleExprCommand(std::vector<std::string> const& args) } else { std::string error = messageHint + "value \"" + argument + "\" for option \"" + option + "\" is invalid."; - this->SetError(error); + status.SetError(error); return false; } } else { std::string error = messageHint + "missing argument for option \"" + option + "\"."; - this->SetError(error); + status.SetError(error); return false; } } else { std::string error = messageHint + "option \"" + option + "\" is unknown."; - this->SetError(error); + status.SetError(error); return false; } } @@ -84,7 +90,7 @@ bool cmMathCommand::HandleExprCommand(std::vector<std::string> const& args) cmExprParserHelper helper; if (!helper.ParseString(expression.c_str(), 0)) { - this->SetError(helper.GetError()); + status.SetError(helper.GetError()); return false; } @@ -104,9 +110,10 @@ bool cmMathCommand::HandleExprCommand(std::vector<std::string> const& args) std::string const& w = helper.GetWarning(); if (!w.empty()) { - this->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w); + status.GetMakefile().IssueMessage(MessageType::AUTHOR_WARNING, w); } - this->Makefile->AddDefinition(outputVariable, buffer); + status.GetMakefile().AddDefinition(outputVariable, buffer); return true; } +} diff --git a/Source/cmMathCommand.h b/Source/cmMathCommand.h index 23633d3..ac1957c 100644 --- a/Source/cmMathCommand.h +++ b/Source/cmMathCommand.h @@ -8,33 +8,10 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; /// Mathematical expressions: math(EXPR ...) command. -class cmMathCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmMathCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - -protected: - bool HandleExprCommand(std::vector<std::string> const& args); -}; +bool cmMathCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif |