diff options
Diffstat (limited to 'source/Symbol/Variable.cpp')
-rw-r--r-- | source/Symbol/Variable.cpp | 123 |
1 files changed, 54 insertions, 69 deletions
diff --git a/source/Symbol/Variable.cpp b/source/Symbol/Variable.cpp index 29a7a5191f61..3f3d7c198f15 100644 --- a/source/Symbol/Variable.cpp +++ b/source/Symbol/Variable.cpp @@ -35,14 +35,12 @@ using namespace lldb; using namespace lldb_private; -// Variable constructor -Variable::Variable( - lldb::user_id_t uid, const char *name, - const char *mangled, // The mangled or fully qualified name of the variable. - const lldb::SymbolFileTypeSP &symfile_type_sp, ValueType scope, - SymbolContextScope *context, const RangeList &scope_range, - Declaration *decl_ptr, const DWARFExpression &location, bool external, - bool artificial, bool static_member) +Variable::Variable(lldb::user_id_t uid, const char *name, const char *mangled, + const lldb::SymbolFileTypeSP &symfile_type_sp, + ValueType scope, SymbolContextScope *context, + const RangeList &scope_range, Declaration *decl_ptr, + const DWARFExpression &location, bool external, + bool artificial, bool static_member) : UserID(uid), m_name(name), m_mangled(ConstString(mangled)), m_symfile_type_sp(symfile_type_sp), m_scope(scope), m_owner_scope(context), m_scope_range(scope_range), @@ -50,14 +48,22 @@ Variable::Variable( m_artificial(artificial), m_loc_is_const_data(false), m_static_member(static_member) {} -// Destructor Variable::~Variable() {} lldb::LanguageType Variable::GetLanguage() const { - SymbolContext variable_sc; - m_owner_scope->CalculateSymbolContext(&variable_sc); - if (variable_sc.comp_unit) - return variable_sc.comp_unit->GetLanguage(); + lldb::LanguageType lang = m_mangled.GuessLanguage(); + if (lang != lldb::eLanguageTypeUnknown) + return lang; + + if (auto *func = m_owner_scope->CalculateSymbolContextFunction()) { + if ((lang = func->GetLanguage()) != lldb::eLanguageTypeUnknown) + return lang; + } else if (auto *comp_unit = + m_owner_scope->CalculateSymbolContextCompileUnit()) { + if ((lang = comp_unit->GetLanguage()) != lldb::eLanguageTypeUnknown) + return lang; + } + return lldb::eLanguageTypeUnknown; } @@ -381,21 +387,15 @@ Status Variable::GetValuesForVariableExpressionPath( default: { static RegularExpression g_regex( llvm::StringRef("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)")); - RegularExpression::Match regex_match(1); - std::string variable_name; + llvm::SmallVector<llvm::StringRef, 2> matches; 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.str().c_str()); - return error; - } - if (!regex_match.GetMatchAtIndex(variable_expr_path, 1, variable_name)) { + if (!g_regex.Execute(variable_expr_path, &matches)) { error.SetErrorStringWithFormat( "unable to extract a variable name from '%s'", variable_expr_path.str().c_str()); return error; } + std::string variable_name = matches[1].str(); if (!callback(baton, variable_name.c_str(), variable_list)) { error.SetErrorString("unknown error"); return error; @@ -485,24 +485,21 @@ static void PrivateAutoComplete( StackFrame *frame, llvm::StringRef partial_path, const llvm::Twine &prefix_path, // Anything that has been resolved already will be in here - const CompilerType &compiler_type, - StringList &matches, bool &word_complete); + const CompilerType &compiler_type, CompletionRequest &request); static void PrivateAutoCompleteMembers( StackFrame *frame, const std::string &partial_member_name, llvm::StringRef partial_path, const llvm::Twine &prefix_path, // Anything that has been resolved already will be in here - const CompilerType &compiler_type, - StringList &matches, bool &word_complete); + const CompilerType &compiler_type, CompletionRequest &request); static void PrivateAutoCompleteMembers( StackFrame *frame, const std::string &partial_member_name, llvm::StringRef partial_path, const llvm::Twine &prefix_path, // Anything that has been resolved already will be in here - const CompilerType &compiler_type, - StringList &matches, bool &word_complete) { + const CompilerType &compiler_type, CompletionRequest &request) { // We are in a type parsing child members const uint32_t num_bases = compiler_type.GetNumDirectBaseClasses(); @@ -512,9 +509,9 @@ static void PrivateAutoCompleteMembers( CompilerType base_class_type = compiler_type.GetDirectBaseClassAtIndex(i, nullptr); - PrivateAutoCompleteMembers( - frame, partial_member_name, partial_path, prefix_path, - base_class_type.GetCanonicalType(), matches, word_complete); + PrivateAutoCompleteMembers(frame, partial_member_name, partial_path, + prefix_path, + base_class_type.GetCanonicalType(), request); } } @@ -525,9 +522,9 @@ static void PrivateAutoCompleteMembers( CompilerType vbase_class_type = compiler_type.GetVirtualBaseClassAtIndex(i, nullptr); - PrivateAutoCompleteMembers( - frame, partial_member_name, partial_path, prefix_path, - vbase_class_type.GetCanonicalType(), matches, word_complete); + PrivateAutoCompleteMembers(frame, partial_member_name, partial_path, + prefix_path, + vbase_class_type.GetCanonicalType(), request); } } @@ -548,9 +545,9 @@ static void PrivateAutoCompleteMembers( frame, partial_path, prefix_path + member_name, // Anything that has been resolved // already will be in here - member_compiler_type.GetCanonicalType(), matches, word_complete); + member_compiler_type.GetCanonicalType(), request); } else { - matches.AppendString((prefix_path + member_name).str()); + request.AddCompletion((prefix_path + member_name).str()); } } } @@ -561,8 +558,7 @@ static void PrivateAutoComplete( StackFrame *frame, llvm::StringRef partial_path, const llvm::Twine &prefix_path, // Anything that has been resolved already will be in here - const CompilerType &compiler_type, - StringList &matches, bool &word_complete) { + const CompilerType &compiler_type, CompletionRequest &request) { // printf ("\nPrivateAutoComplete()\n\tprefix_path = '%s'\n\tpartial_path = // '%s'\n", prefix_path.c_str(), partial_path.c_str()); std::string remaining_partial_path; @@ -583,15 +579,14 @@ static void PrivateAutoComplete( case eTypeClassReference: case eTypeClassTypedef: case eTypeClassVector: { - matches.AppendString(prefix_path.str()); - word_complete = matches.GetSize() == 1; + request.AddCompletion(prefix_path.str()); } break; case eTypeClassClass: case eTypeClassStruct: case eTypeClassUnion: if (prefix_path.str().back() != '.') - matches.AppendString((prefix_path + ".").str()); + request.AddCompletion((prefix_path + ".").str()); break; case eTypeClassObjCObject: @@ -601,10 +596,9 @@ static void PrivateAutoComplete( case eTypeClassPointer: { bool omit_empty_base_classes = true; if (compiler_type.GetNumChildren(omit_empty_base_classes, nullptr) > 0) - matches.AppendString((prefix_path + "->").str()); + request.AddCompletion((prefix_path + "->").str()); else { - matches.AppendString(prefix_path.str()); - word_complete = true; + request.AddCompletion(prefix_path.str()); } } break; } @@ -618,7 +612,7 @@ static void PrivateAutoComplete( const size_t num_variables = variable_list->GetSize(); for (size_t i = 0; i < num_variables; ++i) { Variable *variable = variable_list->GetVariableAtIndex(i).get(); - matches.AppendString(variable->GetName().AsCString()); + request.AddCompletion(variable->GetName().AsCString()); } } } @@ -629,14 +623,14 @@ static void PrivateAutoComplete( case '*': if (prefix_path.str().empty()) { PrivateAutoComplete(frame, partial_path.substr(1), "*", compiler_type, - matches, word_complete); + request); } break; case '&': if (prefix_path.isTriviallyEmpty()) { PrivateAutoComplete(frame, partial_path.substr(1), std::string("&"), - compiler_type, matches, word_complete); + compiler_type, request); } break; @@ -648,14 +642,14 @@ static void PrivateAutoComplete( CompilerType pointee_type(compiler_type.GetPointeeType()); if (partial_path.size() > 2 && partial_path[2]) { // If there is more after the "->", then search deeper - PrivateAutoComplete( - frame, partial_path.substr(2), prefix_path + "->", - pointee_type.GetCanonicalType(), matches, word_complete); + PrivateAutoComplete(frame, partial_path.substr(2), + prefix_path + "->", + pointee_type.GetCanonicalType(), request); } else { // Nothing after the "->", so list all members PrivateAutoCompleteMembers( frame, std::string(), std::string(), prefix_path + "->", - pointee_type.GetCanonicalType(), matches, word_complete); + pointee_type.GetCanonicalType(), request); } } break; default: @@ -673,14 +667,13 @@ static void PrivateAutoComplete( if (partial_path.size() > 1 && partial_path[1]) { // If there is more after the ".", then search deeper PrivateAutoComplete(frame, partial_path.substr(1), - prefix_path + ".", compiler_type, matches, - word_complete); + prefix_path + ".", compiler_type, request); } else { // Nothing after the ".", so list all members PrivateAutoCompleteMembers(frame, std::string(), partial_path, prefix_path + ".", compiler_type, - matches, word_complete); + request); } break; default: @@ -706,8 +699,7 @@ static void PrivateAutoComplete( if (compiler_type.IsValid()) { PrivateAutoCompleteMembers(frame, token, remaining_partial_path, - prefix_path, compiler_type, matches, - word_complete); + prefix_path, compiler_type, request); } else if (frame) { // We haven't found our variable yet const bool get_file_globals = true; @@ -736,13 +728,12 @@ static void PrivateAutoComplete( frame, remaining_partial_path, prefix_path + token, // Anything that has been resolved // already will be in here - variable_compiler_type.GetCanonicalType(), matches, - word_complete); + variable_compiler_type.GetCanonicalType(), request); } else { - matches.AppendString((prefix_path + variable_name).str()); + request.AddCompletion((prefix_path + variable_name).str()); } } else if (remaining_partial_path.empty()) { - matches.AppendString((prefix_path + variable_name).str()); + request.AddCompletion((prefix_path + variable_name).str()); } } } @@ -753,16 +744,10 @@ static void PrivateAutoComplete( } } -size_t Variable::AutoComplete(const ExecutionContext &exe_ctx, - CompletionRequest &request) { +void Variable::AutoComplete(const ExecutionContext &exe_ctx, + CompletionRequest &request) { CompilerType compiler_type; - bool word_complete = false; - StringList matches; PrivateAutoComplete(exe_ctx.GetFramePtr(), request.GetCursorArgumentPrefix(), - "", compiler_type, matches, word_complete); - request.SetWordComplete(word_complete); - request.AddCompletions(matches); - - return request.GetNumberOfMatches(); + "", compiler_type, request); } |