Introduce the notion of "type summary options" as flags that can be passed down to individual summary formatters to alter their behavior in a formatter-dependent way
Two flags are introduced:
- preferred display language (as in, ObjC vs. C++)
- summary capping (as in, should a limit be put to the amount of data retrieved)

The meaning - if any - of these options is for individual formatters to establish
The topic of a subsequent commit will be to actually wire these through to individual data formatters

llvm-svn: 221482
diff --git a/lldb/include/lldb/API/SBDefines.h b/lldb/include/lldb/API/SBDefines.h
index 244bd47..b59b795 100644
--- a/lldb/include/lldb/API/SBDefines.h
+++ b/lldb/include/lldb/API/SBDefines.h
@@ -83,6 +83,7 @@
 class LLDB_API SBTypeMemberFunction;
 class LLDB_API SBTypeNameSpecifier;
 class LLDB_API SBTypeSummary;
+class LLDB_API SBTypeSummaryOptions;
 #ifndef LLDB_DISABLE_PYTHON
 class LLDB_API SBTypeSynthetic;
 #endif
diff --git a/lldb/include/lldb/API/SBTypeSummary.h b/lldb/include/lldb/API/SBTypeSummary.h
index 67a8607..48128b0 100644
--- a/lldb/include/lldb/API/SBTypeSummary.h
+++ b/lldb/include/lldb/API/SBTypeSummary.h
@@ -15,6 +15,56 @@
 #ifndef LLDB_DISABLE_PYTHON
 
 namespace lldb {
+    class SBTypeSummaryOptions
+    {
+    public:
+        SBTypeSummaryOptions();
+
+        SBTypeSummaryOptions (const lldb::SBTypeSummaryOptions &rhs);
+        
+        ~SBTypeSummaryOptions ();
+        
+        bool
+        IsValid ();
+        
+        lldb::LanguageType
+        GetLanguage ();
+        
+        lldb::TypeSummaryCapping
+        GetCapping ();
+        
+        void
+        SetLanguage (lldb::LanguageType);
+        
+        void
+        SetCapping (lldb::TypeSummaryCapping);
+        
+    protected:
+        friend class SBValue;
+        
+        lldb_private::TypeSummaryOptions *
+        operator->();
+        
+        const lldb_private::TypeSummaryOptions *
+        operator->() const;
+        
+        lldb_private::TypeSummaryOptions *
+        get ();
+        
+        lldb_private::TypeSummaryOptions &
+        ref();
+        
+        const lldb_private::TypeSummaryOptions &
+        ref() const;
+        
+        SBTypeSummaryOptions (const lldb_private::TypeSummaryOptions *lldb_object_ptr);
+        
+        void
+        SetOptions (const lldb_private::TypeSummaryOptions *lldb_object_ptr);
+        
+    private:
+        std::unique_ptr<lldb_private::TypeSummaryOptions> m_opaque_ap;
+    };
     
     class SBTypeSummary
     {
diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h
index 2d415c1..42a2a6b 100644
--- a/lldb/include/lldb/API/SBValue.h
+++ b/lldb/include/lldb/API/SBValue.h
@@ -91,6 +91,9 @@
     GetSummary ();
     
     const char *
+    GetSummary (lldb::SBTypeSummaryOptions& options);
+    
+    const char *
     GetObjectDescription ();
     
     const char *
diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h
index 2ec379e..992d9a1 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -612,6 +612,14 @@
     GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
                          std::string& destination);
     
+    const char *
+    GetSummaryAsCString (const TypeSummaryOptions& options);
+    
+    bool
+    GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
+                         std::string& destination,
+                         const TypeSummaryOptions& options);
+    
     std::pair<TypeValidatorResult, std::string>
     GetValidationStatus ();
     
@@ -852,6 +860,10 @@
         m_format = format;
     }
     
+    
+    virtual lldb::LanguageType
+    GetPreferredDisplayLanguage ();
+    
     lldb::TypeSummaryImplSP
     GetSummaryFormat()
     {
diff --git a/lldb/include/lldb/Core/ValueObjectConstResult.h b/lldb/include/lldb/Core/ValueObjectConstResult.h
index dd87fc8..a1d6181 100644
--- a/lldb/include/lldb/Core/ValueObjectConstResult.h
+++ b/lldb/include/lldb/Core/ValueObjectConstResult.h
@@ -126,6 +126,9 @@
     
     virtual lldb::ValueObjectSP
     GetDynamicValue (lldb::DynamicValueType valueType);
+    
+    virtual lldb::LanguageType
+    GetPreferredDisplayLanguage ();
 
 protected:
     virtual bool
diff --git a/lldb/include/lldb/DataFormatters/TypeSummary.h b/lldb/include/lldb/DataFormatters/TypeSummary.h
index 6994943..3d59740 100644
--- a/lldb/include/lldb/DataFormatters/TypeSummary.h
+++ b/lldb/include/lldb/DataFormatters/TypeSummary.h
@@ -28,6 +28,32 @@
 #include "lldb/Symbol/Type.h"
 
 namespace lldb_private {
+    class TypeSummaryOptions
+    {
+    public:
+        TypeSummaryOptions ();
+        TypeSummaryOptions (const TypeSummaryOptions& rhs);
+        
+        TypeSummaryOptions&
+        operator = (const TypeSummaryOptions& rhs);
+        
+        lldb::LanguageType
+        GetLanguage () const;
+        
+        lldb::TypeSummaryCapping
+        GetCapping () const;
+        
+        TypeSummaryOptions&
+        SetLanguage (lldb::LanguageType);
+        
+        TypeSummaryOptions&
+        SetCapping (lldb::TypeSummaryCapping);
+        
+        ~TypeSummaryOptions() = default;
+    private:
+        lldb::LanguageType m_lang;
+        lldb::TypeSummaryCapping m_capping;
+    };
     
     class TypeSummaryImpl
     {
diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h
index 1186464..026924d 100644
--- a/lldb/include/lldb/lldb-enumerations.h
+++ b/lldb/include/lldb/lldb-enumerations.h
@@ -907,6 +907,14 @@
         eTypeIsComplex          = (1u << 20),
         eTypeIsSigned           = (1u << 21)
     } TypeFlags;
+    
+    //----------------------------------------------------------------------
+    // Whether a summary should cap how much data it returns to users or not
+    //----------------------------------------------------------------------
+    typedef enum TypeSummaryCapping {
+        eTypeSummaryCapped = true,
+        eTypeSummaryUncapped = false
+    } TypeSummaryCapping;
 
 } // namespace lldb
 
diff --git a/lldb/include/lldb/lldb-forward.h b/lldb/include/lldb/lldb-forward.h
index c3e093f..cdd402b 100644
--- a/lldb/include/lldb/lldb-forward.h
+++ b/lldb/include/lldb/lldb-forward.h
@@ -207,6 +207,7 @@
 class   StringList;
 struct  StringSummaryFormat;
 class   TypeSummaryImpl;
+class   TypeSummaryOptions;
 class   Symbol;
 class   SymbolContext;
 class   SymbolContextList;
diff --git a/lldb/scripts/Python/interface/SBTypeSummary.i b/lldb/scripts/Python/interface/SBTypeSummary.i
index 9d6a001..9242561 100644
--- a/lldb/scripts/Python/interface/SBTypeSummary.i
+++ b/lldb/scripts/Python/interface/SBTypeSummary.i
@@ -8,7 +8,31 @@
 //===----------------------------------------------------------------------===//
 
 namespace lldb {
-    
+    class SBTypeSummaryOptions
+    {
+    public:
+        SBTypeSummaryOptions();
+        
+        SBTypeSummaryOptions (const lldb::SBTypeSummaryOptions &rhs);
+        
+        ~SBTypeSummaryOptions ();
+        
+        bool
+        IsValid ();
+        
+        lldb::LanguageType
+        GetLanguage ();
+        
+        lldb::TypeSummaryCapping
+        GetCapping ();
+        
+        void
+        SetLanguage (lldb::LanguageType);
+        
+        void
+        SetCapping (lldb::TypeSummaryCapping);
+    };
+
     %feature("docstring",
     "Represents a summary that can be associated to one or more types.
     ") SBTypeSummary;
diff --git a/lldb/scripts/Python/interface/SBValue.i b/lldb/scripts/Python/interface/SBValue.i
index 15b39fd..db78039 100644
--- a/lldb/scripts/Python/interface/SBValue.i
+++ b/lldb/scripts/Python/interface/SBValue.i
@@ -122,6 +122,9 @@
     GetSummary ();
     
     const char *
+    GetSummary (lldb::SBTypeSummaryOptions& options);
+    
+    const char *
     GetObjectDescription ();
     
     const char *
diff --git a/lldb/source/API/SBTypeSummary.cpp b/lldb/source/API/SBTypeSummary.cpp
index aaa09c2..8a235bf 100644
--- a/lldb/source/API/SBTypeSummary.cpp
+++ b/lldb/source/API/SBTypeSummary.cpp
@@ -20,6 +20,103 @@
 
 #ifndef LLDB_DISABLE_PYTHON
 
+SBTypeSummaryOptions::SBTypeSummaryOptions()
+{
+    m_opaque_ap.reset(new TypeSummaryOptions());
+}
+
+SBTypeSummaryOptions::SBTypeSummaryOptions (const lldb::SBTypeSummaryOptions &rhs)
+{
+    if (rhs.m_opaque_ap)
+        m_opaque_ap.reset(new TypeSummaryOptions(*rhs.m_opaque_ap.get()));
+    else
+        m_opaque_ap.reset(new TypeSummaryOptions());
+}
+
+SBTypeSummaryOptions::~SBTypeSummaryOptions ()
+{
+}
+
+bool
+SBTypeSummaryOptions::IsValid()
+{
+    return m_opaque_ap.get();
+}
+
+lldb::LanguageType
+SBTypeSummaryOptions::GetLanguage ()
+{
+    if (IsValid())
+        return m_opaque_ap->GetLanguage();
+    return lldb::eLanguageTypeUnknown;
+}
+
+lldb::TypeSummaryCapping
+SBTypeSummaryOptions::GetCapping ()
+{
+    if (IsValid())
+        return m_opaque_ap->GetCapping();
+    return eTypeSummaryCapped;
+}
+
+void
+SBTypeSummaryOptions::SetLanguage (lldb::LanguageType l)
+{
+    if (IsValid())
+        m_opaque_ap->SetLanguage(l);
+}
+
+void
+SBTypeSummaryOptions::SetCapping (lldb::TypeSummaryCapping c)
+{
+    if (IsValid())
+        m_opaque_ap->SetCapping(c);
+}
+
+lldb_private::TypeSummaryOptions *
+SBTypeSummaryOptions::operator->()
+{
+    return m_opaque_ap.get();
+}
+
+const lldb_private::TypeSummaryOptions *
+SBTypeSummaryOptions::operator->() const
+{
+    return m_opaque_ap.get();
+}
+
+lldb_private::TypeSummaryOptions *
+SBTypeSummaryOptions::get ()
+{
+    return m_opaque_ap.get();
+}
+
+lldb_private::TypeSummaryOptions &
+SBTypeSummaryOptions::ref()
+{
+    return *m_opaque_ap.get();
+}
+
+const lldb_private::TypeSummaryOptions &
+SBTypeSummaryOptions::ref() const
+{
+    return *m_opaque_ap.get();
+}
+
+SBTypeSummaryOptions::SBTypeSummaryOptions (const lldb_private::TypeSummaryOptions *lldb_object_ptr)
+{
+    SetOptions(lldb_object_ptr);
+}
+
+void
+SBTypeSummaryOptions::SetOptions (const lldb_private::TypeSummaryOptions *lldb_object_ptr)
+{
+    if (lldb_object_ptr)
+        m_opaque_ap.reset(new TypeSummaryOptions(*lldb_object_ptr));
+    else
+        m_opaque_ap.reset(new TypeSummaryOptions());
+}
+
 SBTypeSummary::SBTypeSummary() :
 m_opaque_sp()
 {
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index d22f611..1b7c48c 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -640,6 +640,29 @@
     }
     return cstr;
 }
+
+const char *
+SBValue::GetSummary (lldb::SBTypeSummaryOptions& options)
+{
+    Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    const char *cstr = NULL;
+    ValueLocker locker;
+    lldb::ValueObjectSP value_sp(GetSP(locker));
+    if (value_sp)
+    {
+        cstr = value_sp->GetSummaryAsCString(options.ref());
+    }
+    if (log)
+    {
+        if (cstr)
+            log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
+                         static_cast<void*>(value_sp.get()), cstr);
+        else
+            log->Printf ("SBValue(%p)::GetSummary() => NULL",
+                         static_cast<void*>(value_sp.get()));
+    }
+    return cstr;
+}
 #endif // LLDB_DISABLE_PYTHON
 
 const char *
diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index e6c7d48..e09049d 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -44,6 +44,7 @@
 
 #include "lldb/Symbol/ClangASTType.h"
 #include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/CompileUnit.h"
 #include "lldb/Symbol/Type.h"
 
 #include "lldb/Target/ExecutionContext.h"
@@ -841,6 +842,14 @@
 ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
                                   std::string& destination)
 {
+    return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions());
+}
+
+bool
+ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
+                                  std::string& destination,
+                                  const TypeSummaryOptions& options)
+{
     destination.clear();
 
     // ideally we would like to bail out if passing NULL, but if we do so
@@ -925,10 +934,17 @@
 const char *
 ValueObject::GetSummaryAsCString ()
 {
+    return GetSummaryAsCString(TypeSummaryOptions());
+}
+
+const char *
+ValueObject::GetSummaryAsCString (const TypeSummaryOptions& options)
+{
     if (UpdateValueIfNeeded(true) && m_summary_str.empty())
     {
         GetSummaryAsCString(GetSummaryFormat().get(),
-                            m_summary_str);
+                            m_summary_str,
+                            options);
     }
     if (m_summary_str.empty())
         return NULL;
@@ -4133,6 +4149,29 @@
     return m_format;
 }
 
+lldb::LanguageType
+ValueObject::GetPreferredDisplayLanguage ()
+{
+    lldb::LanguageType type = lldb::eLanguageTypeUnknown;
+    if (GetRoot())
+    {
+        if (GetRoot() == this)
+        {
+            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();
+        }
+    }
+    return type;
+}
+
 bool
 ValueObject::CanProvideValue ()
 {
diff --git a/lldb/source/Core/ValueObjectConstResult.cpp b/lldb/source/Core/ValueObjectConstResult.cpp
index 64ee330..b88830f 100644
--- a/lldb/source/Core/ValueObjectConstResult.cpp
+++ b/lldb/source/Core/ValueObjectConstResult.cpp
@@ -359,3 +359,8 @@
     return ValueObjectSP();
 }
 
+lldb::LanguageType
+ValueObjectConstResult::GetPreferredDisplayLanguage ()
+{
+    return lldb::eLanguageTypeUnknown;
+}
diff --git a/lldb/source/DataFormatters/TypeSummary.cpp b/lldb/source/DataFormatters/TypeSummary.cpp
index e5d8017..c782719 100644
--- a/lldb/source/DataFormatters/TypeSummary.cpp
+++ b/lldb/source/DataFormatters/TypeSummary.cpp
@@ -34,6 +34,50 @@
 using namespace lldb;
 using namespace lldb_private;
 
+TypeSummaryOptions::TypeSummaryOptions () :
+    m_lang(eLanguageTypeUnknown),
+    m_capping(eTypeSummaryCapped)
+{}
+
+TypeSummaryOptions::TypeSummaryOptions (const TypeSummaryOptions& rhs) :
+    m_lang(rhs.m_lang),
+    m_capping(rhs.m_capping)
+{}
+
+TypeSummaryOptions&
+TypeSummaryOptions::operator = (const TypeSummaryOptions& rhs)
+{
+    m_lang = rhs.m_lang;
+    m_capping = rhs.m_capping;
+    return *this;
+}
+
+lldb::LanguageType
+TypeSummaryOptions::GetLanguage () const
+{
+    return m_lang;
+}
+
+lldb::TypeSummaryCapping
+TypeSummaryOptions::GetCapping () const
+{
+    return m_capping;
+}
+
+TypeSummaryOptions&
+TypeSummaryOptions::SetLanguage (lldb::LanguageType lang)
+{
+    m_lang = lang;
+    return *this;
+}
+
+TypeSummaryOptions&
+TypeSummaryOptions::SetCapping (lldb::TypeSummaryCapping cap)
+{
+    m_capping = cap;
+    return *this;
+}
+
 TypeSummaryImpl::TypeSummaryImpl (const TypeSummaryImpl::Flags& flags) :
 m_flags(flags)
 {