First step in getting LLDB ready to support multiple different type systems.

This is the work done by Ryan Brown from http://reviews.llvm.org/D8712 that makes a TypeSystem class and abstracts types to be able to use a type system.

All tests pass on MacOSX and passed on linux the last time this was submitted. 

llvm-svn: 244679
diff --git a/lldb/source/DataFormatters/CXXFormatterFunctions.cpp b/lldb/source/DataFormatters/CXXFormatterFunctions.cpp
index 6bf1d56..73da5ce 100644
--- a/lldb/source/DataFormatters/CXXFormatterFunctions.cpp
+++ b/lldb/source/DataFormatters/CXXFormatterFunctions.cpp
@@ -312,7 +312,8 @@
     if (data_addr == 0 || data_addr == LLDB_INVALID_ADDRESS)
         return false;
 
-    clang::ASTContext* ast = valobj.GetClangType().GetASTContext();
+    ClangASTContext* lldb_ast = valobj.GetClangType().GetTypeSystem()->AsClangASTContext();
+    clang::ASTContext* ast = lldb_ast ? lldb_ast->getASTContext() : nullptr;
     
     if (!ast)
         return false;
diff --git a/lldb/source/DataFormatters/CoreMedia.cpp b/lldb/source/DataFormatters/CoreMedia.cpp
index 5c33c0b..172bdf0 100644
--- a/lldb/source/DataFormatters/CoreMedia.cpp
+++ b/lldb/source/DataFormatters/CoreMedia.cpp
@@ -21,7 +21,9 @@
 bool
 lldb_private::formatters::CMTimeSummaryProvider (ValueObject& valobj, Stream& stream, const TypeSummaryOptions& options)
 {
-    ClangASTContext *ast_ctx = ClangASTContext::GetASTContext(valobj.GetClangType().GetASTContext());
+    if (!valobj.GetClangType().IsValid())
+        return false;
+    ClangASTContext *ast_ctx = valobj.GetClangType().GetTypeSystem()->AsClangASTContext();
     if (!ast_ctx)
         return false;
     
diff --git a/lldb/source/DataFormatters/FormatManager.cpp b/lldb/source/DataFormatters/FormatManager.cpp
index d10c59b..7e9f9b4 100644
--- a/lldb/source/DataFormatters/FormatManager.cpp
+++ b/lldb/source/DataFormatters/FormatManager.cpp
@@ -171,7 +171,7 @@
                                    bool did_strip_typedef,
                                    bool root_level)
 {
-    clang_type = clang_type.RemoveFastQualifiers();
+    clang_type = ClangASTContext::RemoveFastQualifiers(clang_type);
     ConstString type_name(clang_type.GetConstTypeName());
     if (valobj.GetBitfieldBitSize() > 0)
     {
@@ -201,7 +201,7 @@
         if (non_ref_type.IsTypedefType())
         {
             ClangASTType deffed_referenced_type = non_ref_type.GetTypedefedType();
-            deffed_referenced_type = is_rvalue_ref ? deffed_referenced_type.GetRValueReferenceType() : deffed_referenced_type.GetLValueReferenceType();
+            deffed_referenced_type = is_rvalue_ref ? ClangASTContext::GetRValueReferenceType(deffed_referenced_type) : ClangASTContext::GetLValueReferenceType(deffed_referenced_type);
             GetPossibleMatches(valobj,
                                deffed_referenced_type,
                                reason | lldb_private::eFormatterChoiceCriterionNavigatedTypedefs,
diff --git a/lldb/source/DataFormatters/LibCxxInitializerList.cpp b/lldb/source/DataFormatters/LibCxxInitializerList.cpp
index 0dcef98..1f79f00 100644
--- a/lldb/source/DataFormatters/LibCxxInitializerList.cpp
+++ b/lldb/source/DataFormatters/LibCxxInitializerList.cpp
@@ -101,7 +101,7 @@
     m_num_elements = 0;
     m_children.clear();
     lldb::TemplateArgumentKind kind;
-    m_element_type = m_backend.GetClangType().GetTemplateArgument(0, kind);
+    m_element_type = ClangASTContext::GetTemplateArgument(m_backend.GetClangType(), 0, kind);
     if (kind != lldb::eTemplateArgumentKindType || false == m_element_type.IsValid())
         return false;
     
diff --git a/lldb/source/DataFormatters/LibCxxList.cpp b/lldb/source/DataFormatters/LibCxxList.cpp
index 17e460d..0430a8f 100644
--- a/lldb/source/DataFormatters/LibCxxList.cpp
+++ b/lldb/source/DataFormatters/LibCxxList.cpp
@@ -336,10 +336,10 @@
     if (list_type.IsReferenceType())
         list_type = list_type.GetNonReferenceType();
 
-    if (list_type.GetNumTemplateArguments() == 0)
+    if (ClangASTContext::GetNumTemplateArguments(list_type) == 0)
         return false;
     lldb::TemplateArgumentKind kind;
-    m_element_type = list_type.GetTemplateArgument(0, kind);
+    m_element_type = ClangASTContext::GetTemplateArgument(list_type, 0, kind);
     m_head = impl_sp->GetChildMemberWithName(ConstString("__next_"), true).get();
     m_tail = impl_sp->GetChildMemberWithName(ConstString("__prev_"), true).get();
     return false;
diff --git a/lldb/source/DataFormatters/LibCxxMap.cpp b/lldb/source/DataFormatters/LibCxxMap.cpp
index 2ff6232..2782a3b0 100644
--- a/lldb/source/DataFormatters/LibCxxMap.cpp
+++ b/lldb/source/DataFormatters/LibCxxMap.cpp
@@ -279,7 +279,7 @@
 bool
 lldb_private::formatters::LibcxxStdMapSyntheticFrontEnd::GetDataType()
 {
-    if (m_element_type.GetOpaqueQualType() && m_element_type.GetASTContext())
+    if (m_element_type.GetOpaqueQualType() && m_element_type.GetTypeSystem())
         return true;
     m_element_type.Clear();
     ValueObjectSP deref;
diff --git a/lldb/source/DataFormatters/LibStdcpp.cpp b/lldb/source/DataFormatters/LibStdcpp.cpp
index 2b3bcb5..16ee2c1 100644
--- a/lldb/source/DataFormatters/LibStdcpp.cpp
+++ b/lldb/source/DataFormatters/LibStdcpp.cpp
@@ -79,10 +79,10 @@
     m_pair_address += (is_64bit ? 32 : 16);
     
     ClangASTType my_type(valobj_sp->GetClangType());
-    if (my_type.GetNumTemplateArguments() >= 1)
+    if (ClangASTContext::GetNumTemplateArguments(my_type) >= 1)
     {
         TemplateArgumentKind kind;
-        ClangASTType pair_type = my_type.GetTemplateArgument(0, kind);
+        ClangASTType pair_type = ClangASTContext::GetTemplateArgument(my_type, 0, kind);
         if (kind != eTemplateArgumentKindType && kind != eTemplateArgumentKindTemplate && kind != eTemplateArgumentKindTemplateExpansion)
             return false;
         m_pair_type = pair_type;
diff --git a/lldb/source/DataFormatters/NSArray.cpp b/lldb/source/DataFormatters/NSArray.cpp
index 640982e..0e665bd 100644
--- a/lldb/source/DataFormatters/NSArray.cpp
+++ b/lldb/source/DataFormatters/NSArray.cpp
@@ -528,11 +528,11 @@
     m_items (0),
     m_data_ptr (0)
 {
-    if (valobj_sp)
+    if (valobj_sp && valobj_sp->GetClangType().IsValid())
     {
-        clang::ASTContext *ast = valobj_sp->GetClangType().GetASTContext();
+        ClangASTContext *ast = valobj_sp->GetClangType().GetTypeSystem()->AsClangASTContext();
         if (ast)
-            m_id_type = ClangASTType(ast, ast->ObjCBuiltinIdTy);
+            m_id_type = ClangASTType(ast->getASTContext(), ast->getASTContext()->ObjCBuiltinIdTy);
     }
 }
 
diff --git a/lldb/source/DataFormatters/NSDictionary.cpp b/lldb/source/DataFormatters/NSDictionary.cpp
index 30bc3ac..30e9d34 100644
--- a/lldb/source/DataFormatters/NSDictionary.cpp
+++ b/lldb/source/DataFormatters/NSDictionary.cpp
@@ -44,11 +44,11 @@
             
             if (clang_type)
             {
-                clang_type.StartTagDeclarationDefinition();
+                ClangASTContext::StartTagDeclarationDefinition(clang_type);
                 ClangASTType id_clang_type = target_ast_context->GetBasicType (eBasicTypeObjCID);
-                clang_type.AddFieldToRecordType("key", id_clang_type, lldb::eAccessPublic, 0);
-                clang_type.AddFieldToRecordType("value", id_clang_type, lldb::eAccessPublic, 0);
-                clang_type.CompleteTagDeclarationDefinition();
+                ClangASTContext::AddFieldToRecordType(clang_type, "key", id_clang_type, lldb::eAccessPublic, 0);
+                ClangASTContext::AddFieldToRecordType(clang_type, "value", id_clang_type, lldb::eAccessPublic, 0);
+                ClangASTContext::CompleteTagDeclarationDefinition(clang_type);
             }
         }
     }
diff --git a/lldb/source/DataFormatters/NSIndexPath.cpp b/lldb/source/DataFormatters/NSIndexPath.cpp
index 363bd5c..4d6f2c5 100644
--- a/lldb/source/DataFormatters/NSIndexPath.cpp
+++ b/lldb/source/DataFormatters/NSIndexPath.cpp
@@ -49,7 +49,10 @@
     {
         m_impl.Clear();
         
-        m_ast_ctx = ClangASTContext::GetASTContext(m_backend.GetClangType().GetASTContext());
+        TypeSystem* type_system = m_backend.GetClangType().GetTypeSystem();
+        if (!type_system)
+            return false;
+        m_ast_ctx = type_system->AsClangASTContext();
         if (!m_ast_ctx)
             return false;
         
diff --git a/lldb/source/DataFormatters/VectorType.cpp b/lldb/source/DataFormatters/VectorType.cpp
index 316d7b5..666e68c 100644
--- a/lldb/source/DataFormatters/VectorType.cpp
+++ b/lldb/source/DataFormatters/VectorType.cpp
@@ -232,7 +232,7 @@
                 ClangASTType parent_type(m_backend.GetClangType());
                 ClangASTType element_type;
                 parent_type.IsVectorType(&element_type, nullptr);
-                m_child_type = ::GetClangTypeForFormat(m_parent_format, element_type, ClangASTContext::GetASTContext(parent_type.GetASTContext()));
+                m_child_type = ::GetClangTypeForFormat(m_parent_format, element_type, parent_type.GetTypeSystem()->AsClangASTContext());
                 m_num_children = ::CalculateNumChildren(parent_type,
                                                         m_child_type);
                 m_item_format = GetItemFormatForFormat(m_parent_format,