Implementing an Options class for EvaluateExpression() in order to make the signature more compact and make it easy to 'just run an expression'

llvm-svn: 163239
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index ca45191..b94a0ce 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -1082,17 +1082,14 @@
             Host::SetCrashDescriptionWithFormat ("SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s",
                                                  expr, fetch_dynamic_value, frame_description.GetString().c_str());
 #endif
-            const bool coerce_to_id = false;
-            const bool keep_in_memory = false;
-
+            Target::EvaluateExpressionOptions options;
+            options.SetUnwindOnError(unwind_on_error)
+            .SetUseDynamic(fetch_dynamic_value);
+            
             exe_results = target->EvaluateExpression (expr, 
                                                       frame,
-                                                      eExecutionPolicyOnlyWhenNeeded,
-                                                      coerce_to_id,
-                                                      unwind_on_error, 
-                                                      keep_in_memory, 
-                                                      fetch_dynamic_value, 
-                                                      expr_value_sp);
+                                                      expr_value_sp,
+                                                      options);
             expr_result.SetSP(expr_value_sp);
 #ifdef LLDB_CONFIGURATION_DEBUG
             Host::SetCrashDescription (NULL);
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 21f24a2..46f5e07 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -732,14 +732,12 @@
             Target* target = exe_ctx.GetTargetPtr();
             if (target)
             {
+                Target::EvaluateExpressionOptions options;
+                options.SetKeepInMemory(true);
                 target->EvaluateExpression (expression,
                                             exe_ctx.GetFramePtr(),
-                                            eExecutionPolicyOnlyWhenNeeded,
-                                            false, // coerce to id
-                                            true, // unwind on error
-                                            true, // keep in memory
-                                            eNoDynamicValues,
-                                            new_value_sp);
+                                            new_value_sp,
+                                            options);
                 if (new_value_sp)
                 {
                     new_value_sp->SetName(ConstString(name));
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index d192c07..23c9dc1 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -298,15 +298,17 @@
             break;
         }
         
+        Target::EvaluateExpressionOptions options;
+        options.SetCoerceToId(m_command_options.print_object)
+        .SetUnwindOnError(m_command_options.unwind_on_error)
+        .SetKeepInMemory(keep_in_memory)
+        .SetUseDynamic(use_dynamic)
+        .SetSingleThreadTimeoutUsec(0);
+        
         exe_results = target->EvaluateExpression (expr, 
                                                   m_interpreter.GetExecutionContext().GetFramePtr(),
-                                                  eExecutionPolicyOnlyWhenNeeded,
-                                                  m_command_options.print_object,
-                                                  m_command_options.unwind_on_error,
-                                                  keep_in_memory, 
-                                                  use_dynamic, 
                                                   result_valobj_sp,
-                                                  0 /* no timeout */);
+                                                  options);
         
         if (exe_results == eExecutionInterrupted && !m_command_options.unwind_on_error)
         {
diff --git a/lldb/source/Commands/CommandObjectWatchpoint.cpp b/lldb/source/Commands/CommandObjectWatchpoint.cpp
index ff59e31..f7f4b69 100644
--- a/lldb/source/Commands/CommandObjectWatchpoint.cpp
+++ b/lldb/source/Commands/CommandObjectWatchpoint.cpp
@@ -1201,18 +1201,16 @@
         }
 
         // Use expression evaluation to arrive at the address to watch.
-        const bool coerce_to_id = true;
-        const bool unwind_on_error = true;
-        const bool keep_in_memory = false;
+        Target::EvaluateExpressionOptions options;
+        options.SetCoerceToId(false)
+        .SetUnwindOnError(true)
+        .SetKeepInMemory(false)
+        .SetSingleThreadTimeoutUsec(0);
+        
         ExecutionResults expr_result = target->EvaluateExpression (expr_str.c_str(), 
                                                                    frame, 
-                                                                   eExecutionPolicyOnlyWhenNeeded,
-                                                                   coerce_to_id,
-                                                                   unwind_on_error, 
-                                                                   keep_in_memory, 
-                                                                   eNoDynamicValues, 
                                                                    valobj_sp,
-                                                                   0 /* no timeout */);
+                                                                   options);
         if (expr_result != eExecutionCompleted) {
             result.GetErrorStream().Printf("error: expression evaluation of address to watch failed\n");
             result.GetErrorStream().Printf("expression evaluated: %s\n", expr_str.c_str());
diff --git a/lldb/source/Core/CXXFormatterFunctions.cpp b/lldb/source/Core/CXXFormatterFunctions.cpp
index e022d74..4646a09 100644
--- a/lldb/source/Core/CXXFormatterFunctions.cpp
+++ b/lldb/source/Core/CXXFormatterFunctions.cpp
@@ -42,14 +42,17 @@
     StackFrame* stack_frame = exe_ctx.GetFramePtr();
     if (!target || !stack_frame)
         return false;
+    
+    Target::EvaluateExpressionOptions options;
+    options.SetCoerceToId(false)
+    .SetUnwindOnError(true)
+    .SetKeepInMemory(true)
+    .SetUseDynamic(lldb::eDynamicCanRunTarget);
+    
     target->EvaluateExpression(expr.GetData(),
                                stack_frame,
-                               eExecutionPolicyOnlyWhenNeeded,
-                               false,
-                               true,
-                               true,
-                               lldb::eDynamicCanRunTarget,
-                               result_sp);
+                               result_sp,
+                               options);
     if (!result_sp)
         return false;
     value = result_sp->GetValueAsUnsigned(0);
@@ -364,14 +367,17 @@
         StackFrame* stack_frame = exe_ctx.GetFramePtr();
         if (!target || !stack_frame)
             return false;
+        
+        Target::EvaluateExpressionOptions options;
+        options.SetCoerceToId(false)
+        .SetUnwindOnError(true)
+        .SetKeepInMemory(true)
+        .SetUseDynamic(lldb::eDynamicCanRunTarget);
+        
         target->EvaluateExpression(expr.GetData(),
                                    stack_frame,
-                                   eExecutionPolicyOnlyWhenNeeded,
-                                   false,
-                                   true,
-                                   true,
-                                   lldb::eDynamicCanRunTarget,
-                                   result_sp);
+                                   result_sp,
+                                   options);
         if (!result_sp)
             return false;
         stream.Printf("%s",result_sp->GetSummaryAsCString());
diff --git a/lldb/source/Interpreter/CommandInterpreter.cpp b/lldb/source/Interpreter/CommandInterpreter.cpp
index bbd18b9..18db69c 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1193,19 +1193,19 @@
                     target = Host::GetDummyTarget(GetDebugger()).get();
                 if (target)
                 {
-                    const bool coerce_to_id = false;
-                    const bool unwind_on_error = true;
-                    const bool keep_in_memory = false;
                     ValueObjectSP expr_result_valobj_sp;
+                    
+                    Target::EvaluateExpressionOptions options;
+                    options.SetCoerceToId(false)
+                    .SetUnwindOnError(true)
+                    .SetKeepInMemory(false)
+                    .SetSingleThreadTimeoutUsec(0);
+                    
                     ExecutionResults expr_result = target->EvaluateExpression (expr_str.c_str(), 
-                                                                               exe_ctx.GetFramePtr(), 
-                                                                               eExecutionPolicyOnlyWhenNeeded,
-                                                                               coerce_to_id,
-                                                                               unwind_on_error, 
-                                                                               keep_in_memory, 
-                                                                               eNoDynamicValues, 
+                                                                               exe_ctx.GetFramePtr(),
                                                                                expr_result_valobj_sp,
-                                                                               0 /* no timeout */);
+                                                                               options);
+                    
                     if (expr_result == eExecutionCompleted)
                     {
                         Scalar scalar;
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 23c8678..bfd222a 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -1606,19 +1606,12 @@
 (
     const char *expr_cstr,
     StackFrame *frame,
-    lldb_private::ExecutionPolicy execution_policy,
-    bool coerce_to_id,
-    bool unwind_on_error,
-    bool keep_in_memory,
-    lldb::DynamicValueType use_dynamic,
     lldb::ValueObjectSP &result_valobj_sp,
-    uint32_t single_thread_timeout_usec
+    const EvaluateExpressionOptions& options
 )
 {
     ExecutionResults execution_results = eExecutionSetupError;
 
-    result_valobj_sp.reset();
-
     if (expr_cstr == NULL || expr_cstr[0] == '\0')
         return execution_results;
 
@@ -1645,7 +1638,7 @@
         if (::strcspn (expr_cstr, "()+*&|!~<=/^%,?") == expr_cstr_len)
         {
             result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr, 
-                                                                         use_dynamic, 
+                                                                         options.GetUseDynamic(),
                                                                          expr_path_options, 
                                                                          var_sp, 
                                                                          error);
@@ -1679,9 +1672,9 @@
         }
         else
         {
-            if (use_dynamic != lldb::eNoDynamicValues)
+            if (options.GetUseDynamic() != lldb::eNoDynamicValues)
             {
-                ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
+                ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(options.GetUseDynamic());
                 if (dynamic_sp)
                     result_valobj_sp = dynamic_sp;
             }
@@ -1735,14 +1728,14 @@
             const char *prefix = GetExpressionPrefixContentsAsCString();
                     
             execution_results = ClangUserExpression::Evaluate (exe_ctx, 
-                                                               execution_policy,
+                                                               options.GetExecutionPolicy(),
                                                                lldb::eLanguageTypeUnknown,
-                                                               coerce_to_id ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny,
-                                                               unwind_on_error,
+                                                               options.DoesCoerceToId() ? ClangUserExpression::eResultTypeId : ClangUserExpression::eResultTypeAny,
+                                                               options.DoesUnwindOnError(),
                                                                expr_cstr, 
                                                                prefix, 
                                                                result_valobj_sp,
-                                                               single_thread_timeout_usec);
+                                                               options.GetSingleThreadTimeoutUsec());
         }
     }