MCPcopy Create free account
hub / github.com/Kitware/CMake / HandleExprCommand

Function HandleExprCommand

Source/cmMathCommand.cxx:36–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35namespace {
36bool 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)) {

Callers 1

cmMathCommandFunction · 0.85

Calls 11

c_strMethod · 0.80
snprintfFunction · 0.50
sizeMethod · 0.45
SetErrorMethod · 0.45
AddDefinitionMethod · 0.45
GetMakefileMethod · 0.45
ParseStringMethod · 0.45
GetErrorMethod · 0.45
GetResultMethod · 0.45
emptyMethod · 0.45
IssueMessageMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…