diff options
Diffstat (limited to 'lldb/source/Interpreter')
-rw-r--r-- | lldb/source/Interpreter/CommandInterpreter.cpp | 15 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionArgParser.cpp | 16 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupArchitecture.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupBoolean.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupFile.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupFormat.cpp | 10 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupOutputFile.cpp | 6 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupPlatform.cpp | 18 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupString.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupUInt64.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupUUID.cpp | 4 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp | 40 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupVariable.cpp | 18 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionGroupWatchpoint.cpp | 22 | ||||
-rw-r--r-- | lldb/source/Interpreter/OptionValueEnumeration.cpp | 20 | ||||
-rw-r--r-- | lldb/source/Interpreter/Options.cpp | 27 |
16 files changed, 104 insertions, 106 deletions
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp index 6cc5da58363..77fdeb1d848 100644 --- a/lldb/source/Interpreter/CommandInterpreter.cpp +++ b/lldb/source/Interpreter/CommandInterpreter.cpp @@ -76,22 +76,21 @@ using namespace lldb_private; static const char *k_white_space = " \t\v"; -static PropertyDefinition g_properties[] = { +static constexpr PropertyDefinition g_properties[] = { {"expand-regex-aliases", OptionValue::eTypeBoolean, true, false, nullptr, - nullptr, "If true, regular expression alias commands will show the " + {}, "If true, regular expression alias commands will show the " "expanded command that will be executed. This can be used to " "debug new regular expression alias commands."}, - {"prompt-on-quit", OptionValue::eTypeBoolean, true, true, nullptr, nullptr, + {"prompt-on-quit", OptionValue::eTypeBoolean, true, true, nullptr, {}, "If true, LLDB will prompt you before quitting if there are any live " "processes being debugged. If false, LLDB will quit without asking in any " "case."}, {"stop-command-source-on-error", OptionValue::eTypeBoolean, true, true, - nullptr, nullptr, "If true, LLDB will stop running a 'command source' " - "script upon encountering an error."}, - {"space-repl-prompts", OptionValue::eTypeBoolean, true, false, nullptr, - nullptr, + nullptr, {}, "If true, LLDB will stop running a 'command source' " + "script upon encountering an error."}, + {"space-repl-prompts", OptionValue::eTypeBoolean, true, false, nullptr, {}, "If true, blank lines will be printed between between REPL submissions."}, - {nullptr, OptionValue::eTypeInvalid, true, 0, nullptr, nullptr, nullptr}}; + {nullptr, OptionValue::eTypeInvalid, true, 0, nullptr, {}, nullptr}}; enum { ePropertyExpandRegexAliases = 0, diff --git a/lldb/source/Interpreter/OptionArgParser.cpp b/lldb/source/Interpreter/OptionArgParser.cpp index 3bd3af8fc50..b0565b706c5 100644 --- a/lldb/source/Interpreter/OptionArgParser.cpp +++ b/lldb/source/Interpreter/OptionArgParser.cpp @@ -46,10 +46,10 @@ char OptionArgParser::ToChar(llvm::StringRef s, char fail_value, } int64_t OptionArgParser::ToOptionEnum(llvm::StringRef s, - OptionEnumValueElement *enum_values, + const OptionEnumValues &enum_values, int32_t fail_value, Status &error) { error.Clear(); - if (!enum_values) { + if (enum_values.empty()) { error.SetErrorString("invalid enumeration argument"); return fail_value; } @@ -59,16 +59,18 @@ int64_t OptionArgParser::ToOptionEnum(llvm::StringRef s, return fail_value; } - for (int i = 0; enum_values[i].string_value != nullptr; i++) { - llvm::StringRef this_enum(enum_values[i].string_value); + for (const auto &enum_value : enum_values) { + llvm::StringRef this_enum(enum_value.string_value); if (this_enum.startswith(s)) - return enum_values[i].value; + return enum_value.value; } StreamString strm; strm.PutCString("invalid enumeration value, valid values are: "); - for (int i = 0; enum_values[i].string_value != nullptr; i++) { - strm.Printf("%s\"%s\"", i > 0 ? ", " : "", enum_values[i].string_value); + bool is_first = true; + for (const auto &enum_value : enum_values) { + strm.Printf("%s\"%s\"", + is_first ? is_first = false,"" : ", ", enum_value.string_value); } error.SetErrorString(strm.GetString()); return fail_value; diff --git a/lldb/source/Interpreter/OptionGroupArchitecture.cpp b/lldb/source/Interpreter/OptionGroupArchitecture.cpp index bbd69b8f13f..42eafc9872d 100644 --- a/lldb/source/Interpreter/OptionGroupArchitecture.cpp +++ b/lldb/source/Interpreter/OptionGroupArchitecture.cpp @@ -18,9 +18,9 @@ OptionGroupArchitecture::OptionGroupArchitecture() : m_arch_str() {} OptionGroupArchitecture::~OptionGroupArchitecture() {} -static OptionDefinition g_option_table[] = { +static constexpr OptionDefinition g_option_table[] = { {LLDB_OPT_SET_1, false, "arch", 'a', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeArchitecture, + nullptr, {}, 0, eArgTypeArchitecture, "Specify the architecture for the target."}, }; diff --git a/lldb/source/Interpreter/OptionGroupBoolean.cpp b/lldb/source/Interpreter/OptionGroupBoolean.cpp index e3759f2e60a..37c63f65995 100644 --- a/lldb/source/Interpreter/OptionGroupBoolean.cpp +++ b/lldb/source/Interpreter/OptionGroupBoolean.cpp @@ -32,7 +32,7 @@ OptionGroupBoolean::OptionGroupBoolean(uint32_t usage_mask, bool required, m_option_definition.option_has_arg = no_argument_toggle_default ? OptionParser::eNoArgument : OptionParser::eRequiredArgument; - m_option_definition.enum_values = nullptr; + m_option_definition.enum_values = {}; m_option_definition.completion_type = 0; m_option_definition.argument_type = eArgTypeBoolean; m_option_definition.usage_text = usage_text; diff --git a/lldb/source/Interpreter/OptionGroupFile.cpp b/lldb/source/Interpreter/OptionGroupFile.cpp index d45f00a6661..72ec4cbb847 100644 --- a/lldb/source/Interpreter/OptionGroupFile.cpp +++ b/lldb/source/Interpreter/OptionGroupFile.cpp @@ -30,7 +30,7 @@ OptionGroupFile::OptionGroupFile(uint32_t usage_mask, bool required, m_option_definition.short_option = short_option; m_option_definition.validator = nullptr; m_option_definition.option_has_arg = OptionParser::eRequiredArgument; - m_option_definition.enum_values = nullptr; + m_option_definition.enum_values = {}; m_option_definition.completion_type = completion_type; m_option_definition.argument_type = argument_type; m_option_definition.usage_text = usage_text; @@ -61,7 +61,7 @@ OptionGroupFileList::OptionGroupFileList( m_option_definition.short_option = short_option; m_option_definition.validator = nullptr; m_option_definition.option_has_arg = OptionParser::eRequiredArgument; - m_option_definition.enum_values = nullptr; + m_option_definition.enum_values = {}; m_option_definition.completion_type = completion_type; m_option_definition.argument_type = argument_type; m_option_definition.usage_text = usage_text; diff --git a/lldb/source/Interpreter/OptionGroupFormat.cpp b/lldb/source/Interpreter/OptionGroupFormat.cpp index b64c1932481..6345a633635 100644 --- a/lldb/source/Interpreter/OptionGroupFormat.cpp +++ b/lldb/source/Interpreter/OptionGroupFormat.cpp @@ -27,18 +27,18 @@ OptionGroupFormat::OptionGroupFormat(lldb::Format default_format, OptionGroupFormat::~OptionGroupFormat() {} -static OptionDefinition g_option_table[] = { +static constexpr OptionDefinition g_option_table[] = { {LLDB_OPT_SET_1, false, "format", 'f', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeFormat, + nullptr, {}, 0, eArgTypeFormat, "Specify a format to be used for display."}, {LLDB_OPT_SET_2, false, "gdb-format", 'G', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeGDBFormat, + nullptr, {}, 0, eArgTypeGDBFormat, "Specify a format using a GDB format specifier string."}, {LLDB_OPT_SET_3, false, "size", 's', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeByteSize, + nullptr, {}, 0, eArgTypeByteSize, "The size in bytes to use when displaying with the selected format."}, {LLDB_OPT_SET_4, false, "count", 'c', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeCount, + nullptr, {}, 0, eArgTypeCount, "The number of total items to display."}, }; diff --git a/lldb/source/Interpreter/OptionGroupOutputFile.cpp b/lldb/source/Interpreter/OptionGroupOutputFile.cpp index fd406494ea9..143a29333b6 100644 --- a/lldb/source/Interpreter/OptionGroupOutputFile.cpp +++ b/lldb/source/Interpreter/OptionGroupOutputFile.cpp @@ -25,12 +25,12 @@ OptionGroupOutputFile::~OptionGroupOutputFile() {} static const uint32_t SHORT_OPTION_APND = 0x61706e64; // 'apnd' -static OptionDefinition g_option_table[] = { +static constexpr OptionDefinition g_option_table[] = { {LLDB_OPT_SET_1, false, "outfile", 'o', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeFilename, + nullptr, {}, 0, eArgTypeFilename, "Specify a path for capturing command output."}, {LLDB_OPT_SET_1, false, "append-outfile", SHORT_OPTION_APND, - OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, + OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Append to the file specified with '--outfile <path>'."}, }; diff --git a/lldb/source/Interpreter/OptionGroupPlatform.cpp b/lldb/source/Interpreter/OptionGroupPlatform.cpp index 47974276c8c..c0d24a556eb 100644 --- a/lldb/source/Interpreter/OptionGroupPlatform.cpp +++ b/lldb/source/Interpreter/OptionGroupPlatform.cpp @@ -65,21 +65,21 @@ void OptionGroupPlatform::OptionParsingStarting( m_os_version = llvm::VersionTuple(); } -static OptionDefinition g_option_table[] = { +static constexpr OptionDefinition g_option_table[] = { {LLDB_OPT_SET_ALL, false, "platform", 'p', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypePlatform, "Specify name of the platform to " - "use for this target, creating the " - "platform if necessary."}, + nullptr, {}, 0, eArgTypePlatform, "Specify name of the platform to " + "use for this target, creating the " + "platform if necessary."}, {LLDB_OPT_SET_ALL, false, "version", 'v', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeNone, + nullptr, {}, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting."}, {LLDB_OPT_SET_ALL, false, "build", 'b', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeNone, + nullptr, {}, 0, eArgTypeNone, "Specify the initial SDK build number."}, {LLDB_OPT_SET_ALL, false, "sysroot", 'S', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeFilename, "Specify the SDK root directory " - "that contains a root of all " - "remote system files."}}; + nullptr, {}, 0, eArgTypeFilename, "Specify the SDK root directory " + "that contains a root of all " + "remote system files."}}; llvm::ArrayRef<OptionDefinition> OptionGroupPlatform::GetDefinitions() { llvm::ArrayRef<OptionDefinition> result(g_option_table); diff --git a/lldb/source/Interpreter/OptionGroupString.cpp b/lldb/source/Interpreter/OptionGroupString.cpp index 1a161945a17..badcfbecdc3 100644 --- a/lldb/source/Interpreter/OptionGroupString.cpp +++ b/lldb/source/Interpreter/OptionGroupString.cpp @@ -31,7 +31,7 @@ OptionGroupString::OptionGroupString(uint32_t usage_mask, bool required, m_option_definition.short_option = short_option; m_option_definition.validator = nullptr; m_option_definition.option_has_arg = OptionParser::eRequiredArgument; - m_option_definition.enum_values = nullptr; + m_option_definition.enum_values = {}; m_option_definition.completion_type = completion_type; m_option_definition.argument_type = argument_type; m_option_definition.usage_text = usage_text; diff --git a/lldb/source/Interpreter/OptionGroupUInt64.cpp b/lldb/source/Interpreter/OptionGroupUInt64.cpp index ae4828c3e92..252308b681f 100644 --- a/lldb/source/Interpreter/OptionGroupUInt64.cpp +++ b/lldb/source/Interpreter/OptionGroupUInt64.cpp @@ -31,7 +31,7 @@ OptionGroupUInt64::OptionGroupUInt64(uint32_t usage_mask, bool required, m_option_definition.short_option = short_option; m_option_definition.validator = nullptr; m_option_definition.option_has_arg = OptionParser::eRequiredArgument; - m_option_definition.enum_values = nullptr; + m_option_definition.enum_values = {}; m_option_definition.completion_type = completion_type; m_option_definition.argument_type = argument_type; m_option_definition.usage_text = usage_text; diff --git a/lldb/source/Interpreter/OptionGroupUUID.cpp b/lldb/source/Interpreter/OptionGroupUUID.cpp index bf02d1b660c..b58f269d608 100644 --- a/lldb/source/Interpreter/OptionGroupUUID.cpp +++ b/lldb/source/Interpreter/OptionGroupUUID.cpp @@ -22,9 +22,9 @@ OptionGroupUUID::OptionGroupUUID() : m_uuid() {} OptionGroupUUID::~OptionGroupUUID() {} -static OptionDefinition g_option_table[] = { +static constexpr OptionDefinition g_option_table[] = { {LLDB_OPT_SET_1, false, "uuid", 'u', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeNone, "A module UUID value."}, + nullptr, {}, 0, eArgTypeNone, "A module UUID value."}, }; llvm::ArrayRef<OptionDefinition> OptionGroupUUID::GetDefinitions() { diff --git a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp index 54b45c29c70..d4314316c85 100644 --- a/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp +++ b/lldb/source/Interpreter/OptionGroupValueObjectDisplay.cpp @@ -28,46 +28,44 @@ OptionGroupValueObjectDisplay::OptionGroupValueObjectDisplay() {} OptionGroupValueObjectDisplay::~OptionGroupValueObjectDisplay() {} -static OptionDefinition g_option_table[] = { +static const OptionDefinition g_option_table[] = { {LLDB_OPT_SET_1, false, "dynamic-type", 'd', - OptionParser::eRequiredArgument, nullptr, g_dynamic_value_types, 0, + OptionParser::eRequiredArgument, nullptr, GetDynamicValueTypes(), 0, eArgTypeNone, "Show the object as its full dynamic type, not its static " "type, if available."}, {LLDB_OPT_SET_1, false, "synthetic-type", 'S', - OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, + OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "Show the object obeying its synthetic provider, if available."}, {LLDB_OPT_SET_1, false, "depth", 'D', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeCount, "Set the max recurse depth when " - "dumping aggregate types (default is " - "infinity)."}, + nullptr, {}, 0, eArgTypeCount, "Set the max recurse depth when dumping " + "aggregate types (default is infinity)."}, {LLDB_OPT_SET_1, false, "flat", 'F', OptionParser::eNoArgument, nullptr, - nullptr, 0, eArgTypeNone, "Display results in a flat format that uses " - "expression paths for each variable or member."}, + {}, 0, eArgTypeNone, "Display results in a flat format that uses " + "expression paths for each variable or member."}, {LLDB_OPT_SET_1, false, "location", 'L', OptionParser::eNoArgument, nullptr, - nullptr, 0, eArgTypeNone, "Show variable location information."}, + {}, 0, eArgTypeNone, "Show variable location information."}, {LLDB_OPT_SET_1, false, "object-description", 'O', - OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, + OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Print as an Objective-C object."}, {LLDB_OPT_SET_1, false, "ptr-depth", 'P', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeCount, "The number of pointers to be " - "traversed when dumping values " - "(default is zero)."}, + nullptr, {}, 0, eArgTypeCount, "The number of pointers to be traversed " + "when dumping values (default is zero)."}, {LLDB_OPT_SET_1, false, "show-types", 'T', OptionParser::eNoArgument, - nullptr, nullptr, 0, eArgTypeNone, + nullptr, {}, 0, eArgTypeNone, "Show variable types when dumping values."}, {LLDB_OPT_SET_1, false, "no-summary-depth", 'Y', - OptionParser::eOptionalArgument, nullptr, nullptr, 0, eArgTypeCount, + OptionParser::eOptionalArgument, nullptr, {}, 0, eArgTypeCount, "Set the depth at which omitting summary information stops (default is " "1)."}, {LLDB_OPT_SET_1, false, "raw-output", 'R', OptionParser::eNoArgument, - nullptr, nullptr, 0, eArgTypeNone, "Don't use formatting options."}, + nullptr, {}, 0, eArgTypeNone, "Don't use formatting options."}, {LLDB_OPT_SET_1, false, "show-all-children", 'A', OptionParser::eNoArgument, - nullptr, nullptr, 0, eArgTypeNone, + nullptr, {}, 0, eArgTypeNone, "Ignore the upper bound on the number of children to show."}, {LLDB_OPT_SET_1, false, "validate", 'V', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeBoolean, "Show results of type validators."}, + nullptr, {}, 0, eArgTypeBoolean, "Show results of type validators."}, {LLDB_OPT_SET_1, false, "element-count", 'Z', - OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeCount, + OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeCount, "Treat the result of the expression as if its type is an array of this " "many values."}}; @@ -86,8 +84,8 @@ Status OptionGroupValueObjectDisplay::SetOptionValue( switch (short_option) { case 'd': { int32_t result; - result = OptionArgParser::ToOptionEnum(option_arg, g_dynamic_value_types, 2, - error); + result = OptionArgParser::ToOptionEnum(option_arg, GetDynamicValueTypes(), + 2, error); if (error.Success()) use_dynamic = (lldb::DynamicValueType)result; } break; diff --git a/lldb/source/Interpreter/OptionGroupVariable.cpp b/lldb/source/Interpreter/OptionGroupVariable.cpp index 7b7a62be874..1bcddb4b49f 100644 --- a/lldb/source/Interpreter/OptionGroupVariable.cpp +++ b/lldb/source/Interpreter/OptionGroupVariable.cpp @@ -24,31 +24,31 @@ using namespace lldb_private; // if you add any options here, remember to update the counters in // OptionGroupVariable::GetNumDefinitions() -static OptionDefinition g_variable_options[] = { +static constexpr OptionDefinition g_variable_options[] = { {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-args", 'a', - OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, + OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Omit function arguments."}, {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "no-locals", 'l', - OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, + OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Omit local variables."}, {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-globals", 'g', - OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, + OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Show the current frame source file global and static variables."}, {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "show-declaration", 'c', - OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, + OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Show variable declaration information (source file and line where the " "variable was declared)."}, {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "regex", 'r', - OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeRegularExpression, + OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeRegularExpression, "The <variable-name> argument for name lookups are regular expressions."}, {LLDB_OPT_SET_1 | LLDB_OPT_SET_2, false, "scope", 's', - OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, + OptionParser::eNoArgument, nullptr, {}, 0, eArgTypeNone, "Show variable scope (argument, local, global, static)."}, {LLDB_OPT_SET_1, false, "summary", 'y', OptionParser::eRequiredArgument, - nullptr, nullptr, 0, eArgTypeName, + nullptr, {}, 0, eArgTypeName, "Specify the summary that the variable output should use."}, {LLDB_OPT_SET_2, false, "summary-string", 'z', - OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeName, + OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeName, "Specify a summary string to use to format the variable output."}, }; diff --git a/lldb/source/Interpreter/OptionGroupWatchpoint.cpp b/lldb/source/Interpreter/OptionGroupWatchpoint.cpp index 0431fefaa7f..6cfcf1861fa 100644 --- a/lldb/source/Interpreter/OptionGroupWatchpoint.cpp +++ b/lldb/source/Interpreter/OptionGroupWatchpoint.cpp @@ -20,33 +20,31 @@ using namespace lldb; using namespace lldb_private; -static OptionEnumValueElement g_watch_type[] = { +static constexpr OptionEnumValueElement g_watch_type[] = { {OptionGroupWatchpoint::eWatchRead, "read", "Watch for read"}, {OptionGroupWatchpoint::eWatchWrite, "write", "Watch for write"}, {OptionGroupWatchpoint::eWatchReadWrite, "read_write", - "Watch for read/write"}, - {0, nullptr, nullptr}}; + "Watch for read/write"} }; -static OptionEnumValueElement g_watch_size[] = { +static constexpr OptionEnumValueElement g_watch_size[] = { {1, "1", "Watch for byte size of 1"}, {2, "2", "Watch for byte size of 2"}, {4, "4", "Watch for byte size of 4"}, - {8, "8", "Watch for byte size of 8"}, - {0, nullptr, nullptr}}; + {8, "8", "Watch for byte size of 8"} }; -static OptionDefinition g_option_table[] = { +static constexpr OptionDefinition g_option_table[] = { {LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument, - nullptr, g_watch_type, 0, eArgTypeWatchType, + nullptr, OptionEnumValues(g_watch_type), 0, eArgTypeWatchType, "Specify the type of watching to perform."}, {LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument, - nullptr, g_watch_size, 0, eArgTypeByteSize, + nullptr, OptionEnumValues(g_watch_size), 0, eArgTypeByteSize, "Number of bytes to use to watch a region."}}; bool OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size) { - for (uint32_t i = 0; i < llvm::array_lengthof(g_watch_size); ++i) { - if (g_watch_size[i].value == 0) + for (const auto& size : g_watch_size) { + if (0 == size.value) break; - if (watch_size == g_watch_size[i].value) + if (watch_size == size.value) return true; } return false; diff --git a/lldb/source/Interpreter/OptionValueEnumeration.cpp b/lldb/source/Interpreter/OptionValueEnumeration.cpp index c7cbcab7fcc..25e85c662a7 100644 --- a/lldb/source/Interpreter/OptionValueEnumeration.cpp +++ b/lldb/source/Interpreter/OptionValueEnumeration.cpp @@ -19,7 +19,7 @@ using namespace lldb; using namespace lldb_private; OptionValueEnumeration::OptionValueEnumeration( - const OptionEnumValueElement *enumerators, enum_type value) + const OptionEnumValues &enumerators, enum_type value) : OptionValue(), m_current_value(value), m_default_value(value), m_enumerations() { SetEnumerations(enumerators); @@ -91,18 +91,16 @@ Status OptionValueEnumeration::SetValueFromString(llvm::StringRef value, } void OptionValueEnumeration::SetEnumerations( - const OptionEnumValueElement *enumerators) { + const OptionEnumValues &enumerators) { m_enumerations.Clear(); - if (enumerators) { - for (size_t i = 0; enumerators[i].string_value != nullptr; ++i) { - ConstString const_enumerator_name(enumerators[i].string_value); - EnumeratorInfo enumerator_info = {enumerators[i].value, - enumerators[i].usage}; - m_enumerations.Append(const_enumerator_name, - enumerator_info); - } - m_enumerations.Sort(); + + for (const auto &enumerator : enumerators) { + ConstString const_enumerator_name(enumerator.string_value); + EnumeratorInfo enumerator_info = {enumerator.value, enumerator.usage}; + m_enumerations.Append(const_enumerator_name, enumerator_info); } + + m_enumerations.Sort(); } lldb::OptionValueSP OptionValueEnumeration::DeepCopy() const { diff --git a/lldb/source/Interpreter/Options.cpp b/lldb/source/Interpreter/Options.cpp index c9567e91f6b..bdea5b4180e 100644 --- a/lldb/source/Interpreter/Options.cpp +++ b/lldb/source/Interpreter/Options.cpp @@ -601,15 +601,17 @@ void Options::GenerateOptionUsage(Stream &strm, CommandObject *cmd, if (opt_defs[i].usage_text) OutputFormattedUsageText(strm, opt_defs[i], screen_width); - if (opt_defs[i].enum_values != nullptr) { + if (!opt_defs[i].enum_values.empty()) { strm.Indent(); strm.Printf("Values: "); - for (int k = 0; opt_defs[i].enum_values[k].string_value != nullptr; - k++) { - if (k == 0) - strm.Printf("%s", opt_defs[i].enum_values[k].string_value); + bool is_first = true; + for (const auto &enum_value : opt_defs[i].enum_values) { + if (is_first) { + strm.Printf("%s", enum_value.string_value); + is_first = false; + } else - strm.Printf(" | %s", opt_defs[i].enum_values[k].string_value); + strm.Printf(" | %s", enum_value.string_value); } strm.EOL(); } @@ -770,17 +772,18 @@ bool Options::HandleOptionArgumentCompletion( // See if this is an enumeration type option, and if so complete it here: - OptionEnumValueElement *enum_values = opt_defs[opt_defs_index].enum_values; - if (enum_values != nullptr) { + const auto &enum_values = opt_defs[opt_defs_index].enum_values; + if (!enum_values.empty()) { bool return_value = false; std::string match_string( request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos), request.GetParsedLine().GetArgumentAtIndex(opt_arg_pos) + request.GetCursorCharPosition()); - for (int i = 0; enum_values[i].string_value != nullptr; i++) { - if (strstr(enum_values[i].string_value, match_string.c_str()) == - enum_values[i].string_value) { - request.AddCompletion(enum_values[i].string_value); + + for (const auto &enum_value : enum_values) { + if (strstr(enum_value.string_value, match_string.c_str()) == + enum_value.string_value) { + request.AddCompletion(enum_value.string_value); return_value = true; } } |