summaryrefslogtreecommitdiffstats
path: root/lldb/source/Interpreter/Args.cpp
diff options
context:
space:
mode:
authorTodd Fiala <todd.fiala@gmail.com>2016-08-11 23:51:28 +0000
committerTodd Fiala <todd.fiala@gmail.com>2016-08-11 23:51:28 +0000
commite1cfbc79420fee0b71bad62f8d413b68a0eca91e (patch)
treeab91f6f91be4051731e37ed69ca9ff8c7bdad1ff /lldb/source/Interpreter/Args.cpp
parent1602421c852d9d7fddbe8c5f014d7861a7848865 (diff)
downloadbcm5719-llvm-e1cfbc79420fee0b71bad62f8d413b68a0eca91e.tar.gz
bcm5719-llvm-e1cfbc79420fee0b71bad62f8d413b68a0eca91e.zip
Decoupled Options from CommandInterpreter.
Options used to store a reference to the CommandInterpreter instance in the base Options class. This made it impossible to parse options independent of a CommandInterpreter. This change removes the reference from the base class. Instead, it modifies the options-parsing-related methods to take an ExecutionContext pointer, which the options may inspect if they need to do so. Closes https://reviews.llvm.org/D23416 Reviewers: clayborg, jingham llvm-svn: 278440
Diffstat (limited to 'lldb/source/Interpreter/Args.cpp')
-rw-r--r--lldb/source/Interpreter/Args.cpp45
1 files changed, 38 insertions, 7 deletions
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp
index d90ef1d256a..3e5b55a482a 100644
--- a/lldb/source/Interpreter/Args.cpp
+++ b/lldb/source/Interpreter/Args.cpp
@@ -550,7 +550,8 @@ Args::SetArguments (const char **argv)
Error
-Args::ParseOptions (Options &options)
+Args::ParseOptions (Options &options, ExecutionContext *execution_context,
+ PlatformSP platform_sp, bool require_validation)
{
StreamString sstr;
Error error;
@@ -622,17 +623,47 @@ Args::ParseOptions (Options &options)
if (long_options_index >= 0 && long_options[long_options_index].definition)
{
const OptionDefinition *def = long_options[long_options_index].definition;
- CommandInterpreter &interpreter = options.GetInterpreter();
+
+ if (!platform_sp)
+ {
+ // User did not pass in an explicit platform. Try to grab
+ // from the execution context.
+ TargetSP target_sp = execution_context ?
+ execution_context->GetTargetSP() : TargetSP();
+ platform_sp = target_sp ?
+ target_sp->GetPlatform() : PlatformSP();
+ }
OptionValidator *validator = def->validator;
- if (validator && !validator->IsValid(*interpreter.GetPlatform(true), interpreter.GetExecutionContext()))
+
+ if (!platform_sp && require_validation)
{
- error.SetErrorStringWithFormat("Option \"%s\" invalid. %s", def->long_option, def->validator->LongConditionString());
+ // Caller requires validation but we cannot validate as we
+ // don't have the mandatory platform against which to
+ // validate.
+ error.SetErrorString("cannot validate options: "
+ "no platform available");
+ return error;
}
- else
+
+ bool validation_failed = false;
+ if (platform_sp)
{
- error = options.SetOptionValue(long_options_index,
- (def->option_has_arg == OptionParser::eNoArgument) ? nullptr : OptionParser::GetOptionArgument());
+ // Ensure we have an execution context, empty or not.
+ ExecutionContext dummy_context;
+ ExecutionContext *exe_ctx_p =
+ execution_context ? execution_context : &dummy_context;
+ if (validator && !validator->IsValid(*platform_sp, *exe_ctx_p))
+ {
+ validation_failed = true;
+ error.SetErrorStringWithFormat("Option \"%s\" invalid. %s", def->long_option, def->validator->LongConditionString());
+ }
}
+
+ // As long as validation didn't fail, we set the option value.
+ if (!validation_failed)
+ error = options.SetOptionValue(long_options_index,
+ (def->option_has_arg == OptionParser::eNoArgument) ? nullptr : OptionParser::GetOptionArgument(),
+ execution_context);
}
else
{
OpenPOWER on IntegriCloud