@@ -275,47 +275,29 @@ Interpreter::Visit(const UnaryOpNode *node) {
275275llvm::Expected<lldb::ValueObjectSP>
276276Interpreter::Visit (const ArraySubscriptNode *node) {
277277 auto lhs_or_err = Evaluate (node->GetBase ());
278- if (!lhs_or_err) {
278+ if (!lhs_or_err)
279279 return lhs_or_err;
280- }
281280 lldb::ValueObjectSP base = *lhs_or_err;
282- const llvm::APInt *index = node->GetIndex ();
283-
284- Status error;
285- if (base->GetCompilerType ().IsReferenceType ()) {
286- base = base->Dereference (error);
287- if (error.Fail ())
288- return error.ToError ();
289- }
290281
291282 // Check to see if 'base' has a synthetic value; if so, try using that.
292- uint64_t child_idx = index->getZExtValue ();
293- if (base->HasSyntheticValue ()) {
294- lldb::ValueObjectSP synthetic = base->GetSyntheticValue ();
295- if (synthetic && synthetic != base) {
296- uint32_t num_children = synthetic->GetNumChildrenIgnoringErrors ();
297- // Verify that the 'index' is not out-of-range for the declared type.
298- if (child_idx >= num_children) {
299- auto message = llvm::formatv (
300- " array index {0} is not valid for \" ({1}) {2}\" " , child_idx,
301- base->GetTypeName ().AsCString (" <invalid type>" ),
302- base->GetName ().AsCString ());
303- return llvm::make_error<DILDiagnosticError>(m_expr, message,
304- node->GetLocation ());
305- }
306-
307- if (static_cast <uint32_t >(child_idx) <
308- synthetic->GetNumChildrenIgnoringErrors ()) {
309- lldb::ValueObjectSP child_valobj_sp =
310- synthetic->GetChildAtIndex (child_idx);
311- if (child_valobj_sp) {
312- return child_valobj_sp;
313- }
314- }
283+ uint64_t child_idx = node->GetIndex ();
284+ if (lldb::ValueObjectSP synthetic = base->GetSyntheticValue ()) {
285+ uint32_t num_children = synthetic->GetNumChildrenIgnoringErrors ();
286+ // Verify that the 'index' is not out-of-range for the declared type.
287+ if (child_idx >= num_children) {
288+ std::string message = llvm::formatv (
289+ " array index {0} is not valid for \" ({1}) {2}\" " , child_idx,
290+ base->GetTypeName ().AsCString (" <invalid type>" ),
291+ base->GetName ().AsCString ());
292+ return llvm::make_error<DILDiagnosticError>(m_expr, message,
293+ node->GetLocation ());
315294 }
295+ if (lldb::ValueObjectSP child_valobj_sp =
296+ synthetic->GetChildAtIndex (child_idx))
297+ return child_valobj_sp;
316298 }
317299
318- auto base_type = base->GetCompilerType ();
300+ auto base_type = base->GetCompilerType (). GetNonReferenceType () ;
319301 if (!base_type.IsPointerType () && !base_type.IsArrayType ())
320302 return llvm::make_error<DILDiagnosticError>(
321303 m_expr, " subscripted value is not an array or pointer" ,
@@ -326,12 +308,11 @@ Interpreter::Visit(const ArraySubscriptNode *node) {
326308 node->GetLocation ());
327309
328310 if (base_type.IsArrayType ()) {
329- uint32_t num_children = base->GetNumChildrenIgnoringErrors ();
330- if (child_idx < num_children)
331- return base->GetChildAtIndex (child_idx);
311+ if (lldb::ValueObjectSP child_valobj_sp = base->GetChildAtIndex (child_idx))
312+ return child_valobj_sp;
332313 }
333314
334- int64_t signed_child_idx = index-> getSExtValue ();
315+ int64_t signed_child_idx = node-> GetIndex ();
335316 return base->GetSyntheticArrayMember (signed_child_idx, true );
336317}
337318
0 commit comments