From: Zachary Turner Date: Fri, 18 Nov 2016 19:23:39 +0000 (+0000) Subject: Re-add the StringRef interface changes for Variable. X-Git-Tag: llvmorg-4.0.0-rc1~4170 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2a3d10ae613af37491fd81747ec418d2d93635b0;p=platform%2Fupstream%2Fllvm.git Re-add the StringRef interface changes for Variable. This concludes the changes I originally tried to make and then had to back out. This way if anything is still broken, it should be easier to bisect it back to a more specific changeset. llvm-svn: 287367 --- diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index da7c7db..14fd8f9 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -394,7 +394,7 @@ public: GetExpressionPathFormat = eGetExpressionPathFormatDereferencePointers); lldb::ValueObjectSP GetValueForExpressionPath( - const char *expression, + llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop = nullptr, ExpressionPathEndResultType *final_value_type = nullptr, const GetValueForExpressionPathOptions &options = @@ -1002,7 +1002,8 @@ private: virtual CompilerType MaybeCalculateCompleteType(); lldb::ValueObjectSP GetValueForExpressionPath_Impl( - const char *expression_cstr, ExpressionPathScanEndReason *reason_to_stop, + llvm::StringRef expression_cstr, + ExpressionPathScanEndReason *reason_to_stop, ExpressionPathEndResultType *final_value_type, const GetValueForExpressionPathOptions &options, ExpressionPathAftermath *final_task_on_target); diff --git a/lldb/include/lldb/Symbol/Variable.h b/lldb/include/lldb/Symbol/Variable.h index 24b020d..3324989 100644 --- a/lldb/include/lldb/Symbol/Variable.h +++ b/lldb/include/lldb/Symbol/Variable.h @@ -98,7 +98,7 @@ public: VariableList &var_list); static Error GetValuesForVariableExpressionPath( - const char *variable_expr_path, ExecutionContextScope *scope, + llvm::StringRef variable_expr_path, ExecutionContextScope *scope, GetVariableCallback callback, void *baton, VariableList &variable_list, ValueObjectList &valobj_list); diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 75749e7..d8870d6 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -2166,7 +2166,7 @@ void ValueObject::GetExpressionPath(Stream &s, bool qualify_cxx_base_classes, } ValueObjectSP ValueObject::GetValueForExpressionPath( - const char *expression, ExpressionPathScanEndReason *reason_to_stop, + llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop, ExpressionPathEndResultType *final_value_type, const GetValueForExpressionPathOptions &options, ExpressionPathAftermath *final_task_on_target) { @@ -2234,16 +2234,16 @@ ValueObjectSP ValueObject::GetValueForExpressionPath( } ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( - const char *expression_cstr2, ExpressionPathScanEndReason *reason_to_stop, + llvm::StringRef expression, ExpressionPathScanEndReason *reason_to_stop, ExpressionPathEndResultType *final_result, const GetValueForExpressionPathOptions &options, ExpressionPathAftermath *what_next) { ValueObjectSP root = GetSP(); - if (!root.get()) - return ValueObjectSP(); + if (!root) + return nullptr; - llvm::StringRef remainder(expression_cstr2); + llvm::StringRef remainder = expression; while (true) { llvm::StringRef temp_expression = remainder; @@ -2565,7 +2565,7 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( pointee_compiler_type_info.Test(eTypeIsScalar)) { Error error; root = root->Dereference(error); - if (error.Fail() || !root.get()) { + if (error.Fail() || !root) { *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; @@ -2588,7 +2588,7 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( root = root->GetSyntheticValue()->GetChildAtIndex(index, true); } else root = root->GetSyntheticArrayMember(index, true); - if (!root.get()) { + if (!root) { *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; @@ -2602,7 +2602,7 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( } } else if (root_compiler_type_info.Test(eTypeIsScalar)) { root = root->GetSyntheticBitFieldChild(index, index, true); - if (!root.get()) { + if (!root) { *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; @@ -2617,7 +2617,7 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( } } else if (root_compiler_type_info.Test(eTypeIsVector)) { root = root->GetChildAtIndex(index, true); - if (!root.get()) { + if (!root) { *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; @@ -2645,14 +2645,14 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( // if we are here, then root itself is a synthetic VO.. should be good // to go - if (!root.get()) { + if (!root) { *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing; *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; return nullptr; } root = root->GetChildAtIndex(index, true); - if (!root.get()) { + if (!root) { *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; @@ -2689,7 +2689,7 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( eTypeIsScalar)) // expansion only works for scalars { root = root->GetSyntheticBitFieldChild(low_index, high_index, true); - if (!root.get()) { + if (!root) { *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild; *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; @@ -2710,7 +2710,7 @@ ValueObjectSP ValueObject::GetValueForExpressionPath_Impl( pointee_compiler_type_info.Test(eTypeIsScalar)) { Error error; root = root->Dereference(error); - if (error.Fail() || !root.get()) { + if (error.Fail() || !root) { *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed; *final_result = ValueObject::eExpressionPathEndResultTypeInvalid; diff --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp index 90d77e9..90e3f1d 100644 --- a/lldb/source/Symbol/Variable.cpp +++ b/lldb/source/Symbol/Variable.cpp @@ -331,119 +331,127 @@ bool Variable::IsInScope(StackFrame *frame) { } Error Variable::GetValuesForVariableExpressionPath( - const char *variable_expr_path, ExecutionContextScope *scope, + llvm::StringRef variable_expr_path, ExecutionContextScope *scope, GetVariableCallback callback, void *baton, VariableList &variable_list, ValueObjectList &valobj_list) { Error error; - if (variable_expr_path && callback) { - switch (variable_expr_path[0]) { - case '*': { - error = Variable::GetValuesForVariableExpressionPath( - variable_expr_path + 1, scope, callback, baton, variable_list, - valobj_list); - if (error.Success()) { - for (uint32_t i = 0; i < valobj_list.GetSize();) { - Error tmp_error; - ValueObjectSP valobj_sp( - valobj_list.GetValueObjectAtIndex(i)->Dereference(tmp_error)); - if (tmp_error.Fail()) { - variable_list.RemoveVariableAtIndex(i); - valobj_list.RemoveValueObjectAtIndex(i); - } else { - valobj_list.SetValueObjectAtIndex(i, valobj_sp); - ++i; - } - } + if (!callback || variable_expr_path.empty()) { + error.SetErrorString("unknown error"); + return error; + } + + switch (variable_expr_path.front()) { + case '*': + error = Variable::GetValuesForVariableExpressionPath( + variable_expr_path.drop_front(), scope, callback, baton, variable_list, + valobj_list); + if (error.Fail()) { + error.SetErrorString("unknown error"); + return error; + } + for (uint32_t i = 0; i < valobj_list.GetSize();) { + Error tmp_error; + ValueObjectSP valobj_sp( + valobj_list.GetValueObjectAtIndex(i)->Dereference(tmp_error)); + if (tmp_error.Fail()) { + variable_list.RemoveVariableAtIndex(i); + valobj_list.RemoveValueObjectAtIndex(i); } else { - error.SetErrorString("unknown error"); + valobj_list.SetValueObjectAtIndex(i, valobj_sp); + ++i; } - return error; - } break; - - case '&': { - error = Variable::GetValuesForVariableExpressionPath( - variable_expr_path + 1, scope, callback, baton, variable_list, - valobj_list); - if (error.Success()) { - for (uint32_t i = 0; i < valobj_list.GetSize();) { - Error tmp_error; - ValueObjectSP valobj_sp( - valobj_list.GetValueObjectAtIndex(i)->AddressOf(tmp_error)); - if (tmp_error.Fail()) { - variable_list.RemoveVariableAtIndex(i); - valobj_list.RemoveValueObjectAtIndex(i); - } else { - valobj_list.SetValueObjectAtIndex(i, valobj_sp); - ++i; - } + } + return error; + case '&': { + error = Variable::GetValuesForVariableExpressionPath( + variable_expr_path.drop_front(), scope, callback, baton, variable_list, + valobj_list); + if (error.Success()) { + for (uint32_t i = 0; i < valobj_list.GetSize();) { + Error tmp_error; + ValueObjectSP valobj_sp( + valobj_list.GetValueObjectAtIndex(i)->AddressOf(tmp_error)); + if (tmp_error.Fail()) { + variable_list.RemoveVariableAtIndex(i); + valobj_list.RemoveValueObjectAtIndex(i); + } else { + valobj_list.SetValueObjectAtIndex(i, valobj_sp); + ++i; } - } else { - error.SetErrorString("unknown error"); } + } else { + error.SetErrorString("unknown error"); + } + return error; + } break; + + default: { + static RegularExpression g_regex( + llvm::StringRef("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)")); + RegularExpression::Match regex_match(1); + std::string variable_name; + variable_list.Clear(); + if (!g_regex.Execute(variable_expr_path, ®ex_match)) { + error.SetErrorStringWithFormat( + "unable to extract a variable name from '%s'", variable_expr_path); return error; - } break; - - default: { - static RegularExpression g_regex( - llvm::StringRef("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)")); - RegularExpression::Match regex_match(1); - if (g_regex.Execute(llvm::StringRef::withNullAsEmpty(variable_expr_path), - ®ex_match)) { - std::string variable_name; - if (regex_match.GetMatchAtIndex(variable_expr_path, 1, variable_name)) { - variable_list.Clear(); - if (callback(baton, variable_name.c_str(), variable_list)) { - uint32_t i = 0; - while (i < variable_list.GetSize()) { - VariableSP var_sp(variable_list.GetVariableAtIndex(i)); - ValueObjectSP valobj_sp; - if (var_sp) { - ValueObjectSP variable_valobj_sp( - ValueObjectVariable::Create(scope, var_sp)); - if (variable_valobj_sp) { - const char *variable_sub_expr_path = - variable_expr_path + variable_name.size(); - if (*variable_sub_expr_path) { - ValueObject::ExpressionPathScanEndReason reason_to_stop; - ValueObject::ExpressionPathEndResultType final_value_type; - ValueObject::GetValueForExpressionPathOptions options; - ValueObject::ExpressionPathAftermath final_task_on_target; - - valobj_sp = variable_valobj_sp->GetValueForExpressionPath( - variable_sub_expr_path, &reason_to_stop, - &final_value_type, options, &final_task_on_target); - if (!valobj_sp) { - error.SetErrorStringWithFormat( - "invalid expression path '%s' for variable '%s'", - variable_sub_expr_path, - var_sp->GetName().GetCString()); - } - } else { - // Just the name of a variable with no extras - valobj_sp = variable_valobj_sp; - } - } - } - - if (!var_sp || !valobj_sp) { - variable_list.RemoveVariableAtIndex(i); - } else { - valobj_list.Append(valobj_sp); - ++i; - } - } + } + if (!regex_match.GetMatchAtIndex(variable_expr_path, 1, variable_name)) { + error.SetErrorStringWithFormat( + "unable to extract a variable name from '%s'", variable_expr_path); + return error; + } + if (!callback(baton, variable_name.c_str(), variable_list)) { + error.SetErrorString("unknown error"); + return error; + } + uint32_t i = 0; + while (i < variable_list.GetSize()) { + VariableSP var_sp(variable_list.GetVariableAtIndex(i)); + ValueObjectSP valobj_sp; + if (!var_sp) { + variable_list.RemoveVariableAtIndex(i); + continue; + } + ValueObjectSP variable_valobj_sp( + ValueObjectVariable::Create(scope, var_sp)); + if (!variable_valobj_sp) { + variable_list.RemoveVariableAtIndex(i); + continue; + } - if (variable_list.GetSize() > 0) { - error.Clear(); - return error; - } - } + llvm::StringRef variable_sub_expr_path = + variable_expr_path.drop_front(variable_name.size()); + if (!variable_sub_expr_path.empty()) { + ValueObject::ExpressionPathScanEndReason reason_to_stop; + ValueObject::ExpressionPathEndResultType final_value_type; + ValueObject::GetValueForExpressionPathOptions options; + ValueObject::ExpressionPathAftermath final_task_on_target; + + valobj_sp = variable_valobj_sp->GetValueForExpressionPath( + variable_sub_expr_path, &reason_to_stop, &final_value_type, options, + &final_task_on_target); + if (!valobj_sp) { + error.SetErrorStringWithFormat( + "invalid expression path '%s' for variable '%s'", + variable_sub_expr_path, var_sp->GetName().GetCString()); + variable_list.RemoveVariableAtIndex(i); + continue; } + } else { + // Just the name of a variable with no extras + valobj_sp = variable_valobj_sp; } - error.SetErrorStringWithFormat( - "unable to extract a variable name from '%s'", variable_expr_path); - } break; + + valobj_list.Append(valobj_sp); + ++i; + } + + if (variable_list.GetSize() > 0) { + error.Clear(); + return error; } + } break; } error.SetErrorString("unknown error"); return error;