@@ -52,19 +52,15 @@ static lldb::VariableSP DILFindVariable(ConstString name,
5252 lldb::VariableSP exact_match;
5353 std::vector<lldb::VariableSP> possible_matches;
5454
55- typedef std::vector<lldb::VariableSP> collection;
56- typedef collection::iterator iterator;
57-
58- iterator pos, end = variable_list->end ();
59- for (pos = variable_list->begin (); pos != end; ++pos) {
60- llvm::StringRef str_ref_name = pos->get ()->GetName ().GetStringRef ();
55+ for (lldb::VariableSP var_sp : *variable_list) {
56+ llvm::StringRef str_ref_name = var_sp->GetName ().GetStringRef ();
6157 // Check for global vars, which might start with '::'.
6258 str_ref_name.consume_front (" ::" );
6359
6460 if (str_ref_name == name.GetStringRef ())
65- possible_matches.push_back (*pos );
66- else if (pos-> get () ->NameMatches (name))
67- possible_matches.push_back (*pos );
61+ possible_matches.push_back (var_sp );
62+ else if (var_sp ->NameMatches (name))
63+ possible_matches.push_back (var_sp );
6864 }
6965
7066 // Look for exact matches (favors local vars over global vars)
@@ -74,23 +70,21 @@ static lldb::VariableSP DILFindVariable(ConstString name,
7470 });
7571
7672 if (exact_match_it != possible_matches.end ())
77- exact_match = *exact_match_it;
78-
79- if (!exact_match)
80- // Look for a global var exact match.
81- for (auto var_sp : possible_matches) {
82- llvm::StringRef str_ref_name = var_sp->GetName ().GetStringRef ();
83- str_ref_name.consume_front (" ::" );
84- if (str_ref_name == name.GetStringRef ()) {
85- exact_match = var_sp;
86- break ;
87- }
88- }
73+ return *exact_match_it;
8974
90- if (!exact_match && possible_matches.size () == 1 )
91- exact_match = possible_matches[0 ];
75+ // Look for a global var exact match.
76+ for (auto var_sp : possible_matches) {
77+ llvm::StringRef str_ref_name = var_sp->GetName ().GetStringRef ();
78+ str_ref_name.consume_front (" ::" );
79+ if (str_ref_name == name.GetStringRef ())
80+ return var_sp;
81+ }
82+
83+ // If there's a single non-exact match, take it.
84+ if (possible_matches.size () == 1 )
85+ return possible_matches[0 ];
9286
93- return exact_match ;
87+ return nullptr ;
9488}
9589
9690std::unique_ptr<IdentifierInfo> LookupGlobalIdentifier (
@@ -239,17 +233,15 @@ Interpreter::Visit(const IdentifierNode *node) {
239233 identifier = LookupGlobalIdentifier (node->GetName (), m_exe_ctx_scope,
240234 m_target, use_dynamic);
241235 if (!identifier) {
242- std::string errMsg;
243- std::string name = node->GetName ();
244- errMsg = llvm::formatv (" use of undeclared identifier '{0}'" , name);
236+ std::string errMsg =
237+ llvm::formatv (" use of undeclared identifier '{0}'" , node->GetName ());
245238 Status error = Status (
246239 (uint32_t )ErrorCode::kUndeclaredIdentifier , lldb::eErrorTypeGeneric,
247240 FormatDiagnostics (m_expr, errMsg, node->GetLocation ()));
248241 return error.ToError ();
249242 }
250243 lldb::ValueObjectSP val;
251244 lldb::TargetSP target_sp;
252- Status error;
253245
254246 assert (identifier->GetKind () == IdentifierInfo::Kind::eValue &&
255247 " Unrecognized identifier kind" );
@@ -263,10 +255,6 @@ Interpreter::Visit(const IdentifierNode *node) {
263255 return error.ToError ();
264256 }
265257
266- target_sp = val->GetTargetSP ();
267- assert (target_sp && target_sp->IsValid () &&
268- " identifier doesn't resolve to a valid value" );
269-
270258 return val;
271259}
272260
0 commit comments