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

Method Evaluate

Source/cmGeneratorExpressionNode.cxx:1871–2448  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1869 bool AcceptsArbitraryContentParameter() const override { return true; }
1870
1871 std::string Evaluate(
1872 std::vector<std::string> const& parameters, cm::GenEx::Evaluation* eval,
1873 GeneratorExpressionContent const* content,
1874 cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
1875 {
1876 static std::unordered_map<
1877 cm::string_view,
1878 std::function<std::string(cm::GenEx::Evaluation*,
1879 GeneratorExpressionContent const*,
1880 Arguments&)>>
1881 listCommands{
1882 { "LENGTH"_s,
1883 [](cm::GenEx::Evaluation* ev, GeneratorExpressionContent const* cnt,
1884 Arguments& args) -> std::string {
1885 if (CheckListParameters(ev, cnt, "LENGTH"_s, args)) {
1886 return std::to_string(GetList(args.front()).size());
1887 }
1888 return std::string{};
1889 } },
1890 { "GET"_s,
1891 [](cm::GenEx::Evaluation* ev, GeneratorExpressionContent const* cnt,
1892 Arguments& args) -> std::string {
1893 if (CheckListParametersEx(ev, cnt, "GET"_s, args.size(), 2,
1894 false)) {
1895 auto list = GetList(args.front());
1896 if (list.empty()) {
1897 reportError(ev, cnt->GetOriginalExpression(),
1898 "given empty list");
1899 return std::string{};
1900 }
1901
1902 std::vector<cmList::index_type> indexes;
1903 if (!GetNumericArguments(ev, cnt, args.advance(1), indexes,
1904 cmList::ExpandElements::Yes)) {
1905 return std::string{};
1906 }
1907 try {
1908 return list.get_items(indexes.begin(), indexes.end())
1909 .to_string();
1910 } catch (std::out_of_range& e) {
1911 reportError(ev, cnt->GetOriginalExpression(), e.what());
1912 return std::string{};
1913 }
1914 }
1915 return std::string{};
1916 } },
1917 { "JOIN"_s,
1918 [](cm::GenEx::Evaluation* ev, GeneratorExpressionContent const* cnt,
1919 Arguments& args) -> std::string {
1920 if (CheckListParameters(ev, cnt, "JOIN"_s, args, 2)) {
1921 return GetList(args.front()).join(args[1]);
1922 }
1923 return std::string{};
1924 } },
1925 { "SUBLIST"_s,
1926 [](cm::GenEx::Evaluation* ev, GeneratorExpressionContent const* cnt,
1927 Arguments& args) -> std::string {
1928 if (CheckListParameters(ev, cnt, "SUBLIST"_s, args, 3)) {

Callers

nothing calls this directly

Calls 15

CheckListParametersFunction · 0.85
to_stringFunction · 0.85
CheckListParametersExFunction · 0.85
reportErrorFunction · 0.85
GetNumericArgumentsFunction · 0.85
appendFunction · 0.85
GetNumericArgumentFunction · 0.85
moveFunction · 0.85
cmHasPrefixFunction · 0.85
GetOriginalExpressionMethod · 0.80
to_stringMethod · 0.80
get_itemsMethod · 0.80

Tested by

no test coverage detected