Allow individual ValueObjects to pick their preferred display language
authorEnrico Granata <egranata@apple.com>
Wed, 21 Jan 2015 01:47:13 +0000 (01:47 +0000)
committerEnrico Granata <egranata@apple.com>
Wed, 21 Jan 2015 01:47:13 +0000 (01:47 +0000)
Most of the time, we can use context information just fine to choose a language (i.e. the language of the frame that the root object was defined in, if any); but in some cases, synthetic children may be fabricated as root frame-less entities, and then we wouldn't know any better

This patch allows (internal) synthetic child providers to set a display language on the children they generate, should they so choose

llvm-svn: 226634

lldb/include/lldb/Core/ValueObject.h
lldb/source/Core/ValueObject.cpp

index fa96c89..402a0f8 100644 (file)
@@ -875,6 +875,9 @@ public:
     virtual lldb::LanguageType
     GetPreferredDisplayLanguage ();
     
+    void
+    SetPreferredDisplayLanguage (lldb::LanguageType);
+    
     lldb::TypeSummaryImplSP
     GetSummaryFormat()
     {
@@ -1106,6 +1109,8 @@ protected:
     
     llvm::SmallVector<uint8_t, 16> m_value_checksum;
     
+    lldb::LanguageType m_preferred_display_language;
+    
     bool                m_value_is_valid:1,
                         m_value_did_change:1,
                         m_children_count_valid:1,
index fa5fb14..3b9a7ab 100644 (file)
@@ -99,6 +99,7 @@ ValueObject::ValueObject (ValueObject &parent) :
     m_user_id_of_forced_summary(),
     m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
     m_value_checksum(),
+    m_preferred_display_language(lldb::eLanguageTypeUnknown),
     m_value_is_valid (false),
     m_value_did_change (false),
     m_children_count_valid (false),
@@ -149,6 +150,7 @@ ValueObject::ValueObject (ExecutionContextScope *exe_scope,
     m_user_id_of_forced_summary(),
     m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
     m_value_checksum(),
+    m_preferred_display_language(lldb::eLanguageTypeUnknown),
     m_value_is_valid (false),
     m_value_did_change (false),
     m_children_count_valid (false),
@@ -4181,24 +4183,33 @@ ValueObject::GetFormat () const
 lldb::LanguageType
 ValueObject::GetPreferredDisplayLanguage ()
 {
-    lldb::LanguageType type = lldb::eLanguageTypeUnknown;
-    if (GetRoot())
+    lldb::LanguageType type = m_preferred_display_language;
+    if (m_preferred_display_language == lldb::eLanguageTypeUnknown)
     {
-        if (GetRoot() == this)
+        if (GetRoot())
         {
-            if (StackFrameSP frame_sp = GetFrameSP())
+            if (GetRoot() == this)
             {
-                const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
-                if (CompileUnit* cu = sc.comp_unit)
-                    type = cu->GetLanguage();
+                if (StackFrameSP frame_sp = GetFrameSP())
+                {
+                    const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
+                    if (CompileUnit* cu = sc.comp_unit)
+                        type = cu->GetLanguage();
+                }
+            }
+            else
+            {
+                type = GetRoot()->GetPreferredDisplayLanguage();
             }
-        }
-        else
-        {
-            type = GetRoot()->GetPreferredDisplayLanguage();
         }
     }
-    return type;
+    return (m_preferred_display_language = type); // only compute it once
+}
+
+void
+ValueObject::SetPreferredDisplayLanguage (lldb::LanguageType lt)
+{
+    m_preferred_display_language = lt;
 }
 
 bool