From b14bcd9123b515c8e3919943b40cc4860996db75 Mon Sep 17 00:00:00 2001 From: Regina Pfeifer Date: Thu, 22 Aug 2019 22:55:58 +0200 Subject: cmListCommand: Use cmSubcommandTable --- Source/cmListCommand.cxx | 154 +++++++++++++---------------------------------- 1 file changed, 43 insertions(+), 111 deletions(-) diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 3c41f4a..ad75490 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -16,6 +16,7 @@ #include #include "cm_memory.hxx" +#include "cm_static_string_view.hxx" #include "cmAlgorithms.h" #include "cmExecutionStatus.h" @@ -26,121 +27,16 @@ #include "cmRange.h" #include "cmStringAlgorithms.h" #include "cmStringReplaceHelper.h" +#include "cmSubcommandTable.h" #include "cmSystemTools.h" namespace { -bool HandleLengthCommand(std::vector const& args, - cmExecutionStatus& status); -bool HandleGetCommand(std::vector const& args, - cmExecutionStatus& status); -bool HandleAppendCommand(std::vector const& args, - cmMakefile& makefile); -bool HandlePrependCommand(std::vector const& args, - cmMakefile& makefile); -bool HandlePopBackCommand(std::vector const& args, - cmMakefile& makefile); -bool HandlePopFrontCommand(std::vector const& args, - cmMakefile& makefile); -bool HandleFindCommand(std::vector const& args, - cmExecutionStatus& status); -bool HandleInsertCommand(std::vector const& args, - cmExecutionStatus& status); -bool HandleJoinCommand(std::vector const& args, - cmExecutionStatus& status); -bool HandleRemoveAtCommand(std::vector const& args, - cmExecutionStatus& status); -bool HandleRemoveItemCommand(std::vector const& args, - cmExecutionStatus& status); -bool HandleRemoveDuplicatesCommand(std::vector const& args, - cmExecutionStatus& status); -bool HandleTransformCommand(std::vector const& args, - cmExecutionStatus& status); -bool HandleSortCommand(std::vector const& args, - cmExecutionStatus& status); -bool HandleSublistCommand(std::vector const& args, - cmExecutionStatus& status); -bool HandleReverseCommand(std::vector const& args, - cmExecutionStatus& status); -bool HandleFilterCommand(std::vector const& args, - cmExecutionStatus& status); + bool FilterRegex(std::vector const& args, bool includeMatches, std::string const& listName, std::vector& varArgsExpanded, cmExecutionStatus& status); -bool GetList(std::vector& list, const std::string& var, - const cmMakefile& makefile); -bool GetListString(std::string& listString, const std::string& var, - const cmMakefile& makefile); -} - -bool cmListCommand(std::vector const& args, - cmExecutionStatus& status) -{ - if (args.size() < 2) { - status.SetError("must be called with at least two arguments."); - return false; - } - - const std::string& subCommand = args[0]; - if (subCommand == "LENGTH") { - return HandleLengthCommand(args, status); - } - if (subCommand == "GET") { - return HandleGetCommand(args, status); - } - if (subCommand == "APPEND") { - return HandleAppendCommand(args, status.GetMakefile()); - } - if (subCommand == "PREPEND") { - return HandlePrependCommand(args, status.GetMakefile()); - } - if (subCommand == "POP_BACK") { - return HandlePopBackCommand(args, status.GetMakefile()); - } - if (subCommand == "POP_FRONT") { - return HandlePopFrontCommand(args, status.GetMakefile()); - } - if (subCommand == "FIND") { - return HandleFindCommand(args, status); - } - if (subCommand == "INSERT") { - return HandleInsertCommand(args, status); - } - if (subCommand == "JOIN") { - return HandleJoinCommand(args, status); - } - if (subCommand == "REMOVE_AT") { - return HandleRemoveAtCommand(args, status); - } - if (subCommand == "REMOVE_ITEM") { - return HandleRemoveItemCommand(args, status); - } - if (subCommand == "REMOVE_DUPLICATES") { - return HandleRemoveDuplicatesCommand(args, status); - } - if (subCommand == "TRANSFORM") { - return HandleTransformCommand(args, status); - } - if (subCommand == "SORT") { - return HandleSortCommand(args, status); - } - if (subCommand == "SUBLIST") { - return HandleSublistCommand(args, status); - } - if (subCommand == "REVERSE") { - return HandleReverseCommand(args, status); - } - if (subCommand == "FILTER") { - return HandleFilterCommand(args, status); - } - - std::string e = "does not recognize sub-command " + subCommand; - status.SetError(e); - return false; -} - -namespace { bool GetListString(std::string& listString, const std::string& var, const cmMakefile& makefile) { @@ -276,7 +172,7 @@ bool HandleGetCommand(std::vector const& args, } bool HandleAppendCommand(std::vector const& args, - cmMakefile& makefile) + cmExecutionStatus& status) { assert(args.size() >= 2); @@ -285,6 +181,7 @@ bool HandleAppendCommand(std::vector const& args, return true; } + cmMakefile& makefile = status.GetMakefile(); std::string const& listName = args[1]; // expand the variable std::string listString; @@ -301,7 +198,7 @@ bool HandleAppendCommand(std::vector const& args, } bool HandlePrependCommand(std::vector const& args, - cmMakefile& makefile) + cmExecutionStatus& status) { assert(args.size() >= 2); @@ -310,6 +207,7 @@ bool HandlePrependCommand(std::vector const& args, return true; } + cmMakefile& makefile = status.GetMakefile(); std::string const& listName = args[1]; // expand the variable std::string listString; @@ -327,10 +225,11 @@ bool HandlePrependCommand(std::vector const& args, } bool HandlePopBackCommand(std::vector const& args, - cmMakefile& makefile) + cmExecutionStatus& status) { assert(args.size() >= 2); + cmMakefile& makefile = status.GetMakefile(); auto ai = args.cbegin(); ++ai; // Skip subcommand name std::string const& listName = *ai++; @@ -374,10 +273,11 @@ bool HandlePopBackCommand(std::vector const& args, } bool HandlePopFrontCommand(std::vector const& args, - cmMakefile& makefile) + cmExecutionStatus& status) { assert(args.size() >= 2); + cmMakefile& makefile = status.GetMakefile(); auto ai = args.cbegin(); ++ai; // Skip subcommand name std::string const& listName = *ai++; @@ -1566,4 +1466,36 @@ bool FilterRegex(std::vector const& args, bool includeMatches, status.GetMakefile().AddDefinition(listName, value); return true; } + +} // namespace + +bool cmListCommand(std::vector const& args, + cmExecutionStatus& status) +{ + if (args.size() < 2) { + status.SetError("must be called with at least two arguments."); + return false; + } + + static cmSubcommandTable const subcommand{ + { "LENGTH"_s, HandleLengthCommand }, + { "GET"_s, HandleGetCommand }, + { "APPEND"_s, HandleAppendCommand }, + { "PREPEND"_s, HandlePrependCommand }, + { "POP_BACK"_s, HandlePopBackCommand }, + { "POP_FRONT"_s, HandlePopFrontCommand }, + { "FIND"_s, HandleFindCommand }, + { "INSERT"_s, HandleInsertCommand }, + { "JOIN"_s, HandleJoinCommand }, + { "REMOVE_AT"_s, HandleRemoveAtCommand }, + { "REMOVE_ITEM"_s, HandleRemoveItemCommand }, + { "REMOVE_DUPLICATES"_s, HandleRemoveDuplicatesCommand }, + { "TRANSFORM"_s, HandleTransformCommand }, + { "SORT"_s, HandleSortCommand }, + { "SUBLIST"_s, HandleSublistCommand }, + { "REVERSE"_s, HandleReverseCommand }, + { "FILTER"_s, HandleFilterCommand }, + }; + + return subcommand(args[0], args, status); } -- cgit v0.12