Fixed up the SBValue::GetExpressionPath() to be more correct under more
circumstances.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@123957 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/API/SBType.cpp b/source/API/SBType.cpp
index ca3fe6d..1a1beae 100644
--- a/source/API/SBType.cpp
+++ b/source/API/SBType.cpp
@@ -113,6 +113,7 @@
     uint32_t child_bitfield_bit_size = 0;
     uint32_t child_bitfield_bit_offset = 0;
     bool child_is_base_class = false;
+    bool child_is_deref_of_parent = false;
 
     if (IsValid ())
     {
@@ -128,7 +129,8 @@
                                                                       child_byte_offset,
                                                                       child_bitfield_bit_size,
                                                                       child_bitfield_bit_offset,
-                                                                      child_is_base_class);
+                                                                      child_is_base_class,
+                                                                      child_is_deref_of_parent);
         
     }
     
@@ -142,6 +144,7 @@
         member.m_bit_size = child_bitfield_bit_size;
         member.m_bit_offset = child_bitfield_bit_offset;
         member.m_is_base_class = child_is_base_class;
+        member.m_is_deref_of_paremt = child_is_deref_of_parent;
     }
     else
     {
diff --git a/source/Core/ValueObject.cpp b/source/Core/ValueObject.cpp
index a492b72..89fc8b3 100644
--- a/source/Core/ValueObject.cpp
+++ b/source/Core/ValueObject.cpp
@@ -64,7 +64,8 @@
     m_value_did_change (false),
     m_children_count_valid (false),
     m_old_value_valid (false),
-    m_pointers_point_to_load_addrs (false)
+    m_pointers_point_to_load_addrs (false),
+    m_is_deref_of_parent (false)
 {
 }
 
@@ -367,6 +368,8 @@
     uint32_t child_bitfield_bit_size = 0;
     uint32_t child_bitfield_bit_offset = 0;
     bool child_is_base_class = false;
+    bool child_is_deref_of_parent = false;
+
     const bool transparent_pointers = synthetic_array_member == false;
     clang::ASTContext *clang_ast = GetClangAST();
     clang_type_t clang_type = GetClangType();
@@ -382,7 +385,8 @@
                                                                   child_byte_offset,
                                                                   child_bitfield_bit_size,
                                                                   child_bitfield_bit_offset,
-                                                                  child_is_base_class);
+                                                                  child_is_base_class,
+                                                                  child_is_deref_of_parent);
     if (child_clang_type && child_byte_size)
     {
         if (synthetic_index)
@@ -400,7 +404,8 @@
                                                child_byte_offset,
                                                child_bitfield_bit_size,
                                                child_bitfield_bit_offset,
-                                               child_is_base_class));
+                                               child_is_base_class,
+                                               child_is_deref_of_parent));
         if (m_pointers_point_to_load_addrs)
             valobj_sp->SetPointersPointToLoadAddrs (m_pointers_point_to_load_addrs);
     }
@@ -931,47 +936,90 @@
     return true;
 }
 
+bool
+ValueObject::GetBaseClassPath (Stream &s)
+{
+    if (IsBaseClass())
+    {
+        bool parent_had_base_class = m_parent && m_parent->GetBaseClassPath (s);
+        clang_type_t clang_type = GetClangType();
+        std::string cxx_class_name;
+        bool this_had_base_class = ClangASTContext::GetCXXClassName (clang_type, cxx_class_name);
+        if (this_had_base_class)
+        {
+            if (parent_had_base_class)
+                s.PutCString("::");
+            s.PutCString(cxx_class_name.c_str());
+        }
+        return parent_had_base_class || this_had_base_class;
+    }
+    return false;
+}
+
+
+ValueObject *
+ValueObject::GetNonBaseClassParent()
+{
+    if (m_parent)
+    {
+        if (m_parent->IsBaseClass())
+            return m_parent->GetNonBaseClassParent();
+        else
+            return m_parent;
+    }
+    return NULL;
+}
 
 void
 ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes)
 {
+    const bool is_deref_of_parent = IsDereferenceOfParent ();
+    
+    if (is_deref_of_parent)
+        s.PutCString("*(");
+
     if (m_parent)
-    {
         m_parent->GetExpressionPath (s, qualify_cxx_base_classes);
-        clang_type_t parent_clang_type = m_parent->GetClangType();
-        if (parent_clang_type)
+    
+    if (!IsBaseClass())
+    {
+        if (!is_deref_of_parent)
         {
-            if (ClangASTContext::IsPointerType(parent_clang_type))
+            ValueObject *non_base_class_parent = GetNonBaseClassParent();
+            if (non_base_class_parent)
             {
-                s.PutCString("->");
+                clang_type_t non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
+                if (non_base_class_parent_clang_type)
+                {
+                    const uint32_t non_base_class_parent_type_info = ClangASTContext::GetTypeInfo (non_base_class_parent_clang_type, NULL, NULL);
+                    
+                    if (non_base_class_parent_type_info & ClangASTContext::eTypeIsPointer)
+                    {
+                        s.PutCString("->");
+                    }
+                    else if ((non_base_class_parent_type_info & ClangASTContext::eTypeHasChildren) &&
+                        !(non_base_class_parent_type_info & ClangASTContext::eTypeIsArray))
+                    {
+                        s.PutChar('.');
+                    }
+                }
             }
-            else if (ClangASTContext::IsAggregateType (parent_clang_type))
+
+            const char *name = GetName().GetCString();
+            if (name)
             {
-                if (ClangASTContext::IsArrayType (parent_clang_type) == false &&
-                    m_parent->IsBaseClass() == false)
-                    s.PutChar('.');
+                if (qualify_cxx_base_classes)
+                {
+                    if (GetBaseClassPath (s))
+                        s.PutCString("::");
+                }
+                s.PutCString(name);
             }
         }
     }
     
-    if (IsBaseClass())
-    {
-        if (qualify_cxx_base_classes)
-        {
-            clang_type_t clang_type = GetClangType();
-            std::string cxx_class_name;
-            if (ClangASTContext::GetCXXClassName (clang_type, cxx_class_name))
-            {
-                s << cxx_class_name.c_str() << "::";
-            }
-        }
-    }
-    else
-    {
-        const char *name = GetName().GetCString();
-        if (name)
-            s.PutCString(name);    
-    }
+    if (is_deref_of_parent)
+        s.PutChar(')');
 }
 
 void
@@ -1012,7 +1060,7 @@
             s.Indent();
 
             // Always show the type for the top level items.
-            if (show_types || curr_depth == 0)
+            if (show_types || (curr_depth == 0 && !flat_output))
                 s.Printf("(%s) ", valobj->GetTypeName().AsCString("<invalid type>"));
 
 
@@ -1223,6 +1271,7 @@
         uint32_t child_bitfield_bit_size = 0;
         uint32_t child_bitfield_bit_offset = 0;
         bool child_is_base_class = false;
+        bool child_is_deref_of_parent = false;
         const bool transparent_pointers = false;
         clang::ASTContext *clang_ast = GetClangAST();
         clang_type_t clang_type = GetClangType();
@@ -1238,7 +1287,8 @@
                                                                       child_byte_offset,
                                                                       child_bitfield_bit_size,
                                                                       child_bitfield_bit_offset,
-                                                                      child_is_base_class);
+                                                                      child_is_base_class,
+                                                                      child_is_deref_of_parent);
         if (child_clang_type && child_byte_size)
         {
             ConstString child_name;
@@ -1253,7 +1303,8 @@
                                                    child_byte_offset,
                                                    child_bitfield_bit_size,
                                                    child_bitfield_bit_offset,
-                                                   child_is_base_class));
+                                                   child_is_base_class,
+                                                   child_is_deref_of_parent));
         }
     }
 
diff --git a/source/Core/ValueObjectChild.cpp b/source/Core/ValueObjectChild.cpp
index 09bae2f..bf896ab 100644
--- a/source/Core/ValueObjectChild.cpp
+++ b/source/Core/ValueObjectChild.cpp
@@ -34,7 +34,8 @@
     int32_t byte_offset,
     uint32_t bitfield_bit_size,
     uint32_t bitfield_bit_offset,
-    bool is_base_class
+    bool is_base_class,
+    bool is_deref_of_parent
 ) :
     ValueObject (parent),
     m_clang_ast (clang_ast),
@@ -43,7 +44,8 @@
     m_byte_offset (byte_offset),
     m_bitfield_bit_size (bitfield_bit_size),
     m_bitfield_bit_offset (bitfield_bit_offset),
-    m_is_base_class (is_base_class)
+    m_is_base_class (is_base_class),
+    m_is_deref_of_parent (is_deref_of_parent)
 {
     m_name = name;
 }
diff --git a/source/Symbol/ClangASTContext.cpp b/source/Symbol/ClangASTContext.cpp
index b1cd6c5..9988d08 100644
--- a/source/Symbol/ClangASTContext.cpp
+++ b/source/Symbol/ClangASTContext.cpp
@@ -2373,7 +2373,8 @@
     int32_t &child_byte_offset,
     uint32_t &child_bitfield_bit_size,
     uint32_t &child_bitfield_bit_offset,
-    bool &child_is_base_class
+    bool &child_is_base_class,
+    bool &child_is_deref_of_parent
 )
 {
     if (parent_clang_type)
@@ -2389,7 +2390,8 @@
                                          child_byte_offset,
                                          child_bitfield_bit_size,
                                          child_bitfield_bit_offset,
-                                         child_is_base_class);
+                                         child_is_base_class, 
+                                         child_is_deref_of_parent);
     return NULL;
 }
 
@@ -2407,7 +2409,8 @@
     int32_t &child_byte_offset,
     uint32_t &child_bitfield_bit_size,
     uint32_t &child_bitfield_bit_offset,
-    bool &child_is_base_class
+    bool &child_is_base_class,
+    bool &child_is_deref_of_parent
 )
 {
     if (parent_clang_type == NULL)
@@ -2612,6 +2615,8 @@
 
                 if (transparent_pointers && ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr()))
                 {
+                    child_is_deref_of_parent = false;
+                    bool tmp_child_is_deref_of_parent = false;
                     return GetChildClangTypeAtIndex (ast,
                                                      parent_name,
                                                      pointer_type->getPointeeType().getAsOpaquePtr(),
@@ -2623,10 +2628,12 @@
                                                      child_byte_offset,
                                                      child_bitfield_bit_size,
                                                      child_bitfield_bit_offset,
-                                                     child_is_base_class);
+                                                     child_is_base_class,
+                                                     tmp_child_is_deref_of_parent);
                 }
                 else
                 {
+                    child_is_deref_of_parent = true;
                     if (parent_name)
                     {
                         child_name.assign(1, '*');
@@ -2681,6 +2688,8 @@
 
                 if (transparent_pointers && ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr()))
                 {
+                    child_is_deref_of_parent = false;
+                    bool tmp_child_is_deref_of_parent = false;
                     return GetChildClangTypeAtIndex (ast,
                                                      parent_name,
                                                      pointer_type->getPointeeType().getAsOpaquePtr(),
@@ -2692,10 +2701,13 @@
                                                      child_byte_offset,
                                                      child_bitfield_bit_size,
                                                      child_bitfield_bit_offset,
-                                                     child_is_base_class);
+                                                     child_is_base_class,
+                                                     tmp_child_is_deref_of_parent);
                 }
                 else
                 {
+                    child_is_deref_of_parent = true;
+
                     if (parent_name)
                     {
                         child_name.assign(1, '*');
@@ -2723,6 +2735,8 @@
                 clang_type_t pointee_clang_type = pointee_type.getAsOpaquePtr();
                 if (transparent_pointers && ClangASTContext::IsAggregateType (pointee_clang_type))
                 {
+                    child_is_deref_of_parent = false;
+                    bool tmp_child_is_deref_of_parent = false;
                     return GetChildClangTypeAtIndex (ast,
                                                      parent_name,
                                                      pointee_clang_type,
@@ -2734,7 +2748,8 @@
                                                      child_byte_offset,
                                                      child_bitfield_bit_size,
                                                      child_bitfield_bit_offset,
-                                                     child_is_base_class);
+                                                     child_is_base_class,
+                                                     tmp_child_is_deref_of_parent);
                 }
                 else
                 {
@@ -2769,7 +2784,8 @@
                                              child_byte_offset,
                                              child_bitfield_bit_size,
                                              child_bitfield_bit_offset,
-                                             child_is_base_class);
+                                             child_is_base_class,
+                                             child_is_deref_of_parent);
             break;
 
         default:
diff --git a/source/Symbol/Type.cpp b/source/Symbol/Type.cpp
index 2fca2ad..0590a1d 100644
--- a/source/Symbol/Type.cpp
+++ b/source/Symbol/Type.cpp
@@ -559,50 +559,6 @@
     }
     return m_clang_type != NULL;
 }
-
-clang_type_t 
-lldb_private::Type::GetChildClangTypeAtIndex
-(
-    const char *parent_name,
-    uint32_t idx,
-    bool transparent_pointers,
-    bool omit_empty_base_classes,
-    ConstString& name,
-    uint32_t &child_byte_size,
-    int32_t &child_byte_offset,
-    uint32_t &child_bitfield_bit_size,
-    uint32_t &child_bitfield_bit_offset,
-    bool &child_is_base_class
-)
-{
-    clang_type_t child_qual_type = NULL;
-    
-    if (GetClangType())
-    {
-        std::string name_str;
-        child_qual_type = GetClangASTContext().GetChildClangTypeAtIndex (parent_name,
-                                                                         m_clang_type,
-                                                                         idx,
-                                                                         transparent_pointers,
-                                                                         omit_empty_base_classes,
-                                                                         name_str,
-                                                                         child_byte_size,
-                                                                         child_byte_offset,
-                                                                         child_bitfield_bit_size,
-                                                                         child_bitfield_bit_offset,
-                                                                         child_is_base_class);
-        
-        if (child_qual_type)
-        {
-            if (!name_str.empty())
-                name.SetCString(name_str.c_str());
-            else
-                name.Clear();
-        }
-    }
-    return child_qual_type;
-}
-
 uint32_t
 lldb_private::Type::GetEncodingMask ()
 {