| 34 | |
| 35 | namespace { |
| 36 | bool HandleExprCommand(std::vector<std::string> const& args, |
| 37 | cmExecutionStatus& status) |
| 38 | { |
| 39 | if ((args.size() != 3) && (args.size() != 5)) { |
| 40 | status.SetError("EXPR called with incorrect arguments."); |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | enum class NumericFormat |
| 45 | { |
| 46 | UNINITIALIZED, |
| 47 | DECIMAL, |
| 48 | HEXADECIMAL, |
| 49 | }; |
| 50 | |
| 51 | std::string const& outputVariable = args[1]; |
| 52 | std::string const& expression = args[2]; |
| 53 | size_t argumentIndex = 3; |
| 54 | NumericFormat outputFormat = NumericFormat::UNINITIALIZED; |
| 55 | |
| 56 | status.GetMakefile().AddDefinition(outputVariable, "ERROR"); |
| 57 | |
| 58 | if (argumentIndex < args.size()) { |
| 59 | std::string const messageHint = "sub-command EXPR "; |
| 60 | std::string const& option = args[argumentIndex++]; |
| 61 | if (option == "OUTPUT_FORMAT") { |
| 62 | if (argumentIndex < args.size()) { |
| 63 | std::string const& argument = args[argumentIndex++]; |
| 64 | if (argument == "DECIMAL") { |
| 65 | outputFormat = NumericFormat::DECIMAL; |
| 66 | } else if (argument == "HEXADECIMAL") { |
| 67 | outputFormat = NumericFormat::HEXADECIMAL; |
| 68 | } else { |
| 69 | std::string error = messageHint + "value \"" + argument + |
| 70 | "\" for option \"" + option + "\" is invalid."; |
| 71 | status.SetError(error); |
| 72 | return false; |
| 73 | } |
| 74 | } else { |
| 75 | std::string error = |
| 76 | messageHint + "missing argument for option \"" + option + "\"."; |
| 77 | status.SetError(error); |
| 78 | return false; |
| 79 | } |
| 80 | } else { |
| 81 | std::string error = |
| 82 | messageHint + "option \"" + option + "\" is unknown."; |
| 83 | status.SetError(error); |
| 84 | return false; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (outputFormat == NumericFormat::UNINITIALIZED) { |
| 89 | outputFormat = NumericFormat::DECIMAL; |
| 90 | } |
| 91 | |
| 92 | cmExprParserHelper helper; |
| 93 | if (!helper.ParseString(expression.c_str(), 0)) { |
no test coverage detected
searching dependent graphs…