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/Expression/ClangExpressionDeclMap.cpp b/lldb/source/Expression/ClangExpressionDeclMap.cpp
index 2c66a0a..b719e06 100644
--- a/lldb/source/Expression/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Expression/ClangExpressionDeclMap.cpp
@@ -201,10 +201,10 @@
         if (target == NULL)
             return false;
 
-        ASTContext *context(target->GetScratchClangASTContext()->getASTContext());
+        ClangASTContext *context(target->GetScratchClangASTContext());
 
-        TypeFromUser user_type(m_ast_importer->DeportType(context,
-                                                          parser_type.GetASTContext(),
+        TypeFromUser user_type(m_ast_importer->DeportType(context->getASTContext(),
+                                                          parser_type.GetTypeSystem()->AsClangASTContext()->getASTContext(),
                                                           parser_type.GetOpaqueQualType()),
                                context);
 
@@ -241,10 +241,10 @@
     if (target == NULL)
         return false;
 
-    ASTContext *context(target->GetScratchClangASTContext()->getASTContext());
+    ClangASTContext *context(target->GetScratchClangASTContext());
 
-    TypeFromUser user_type(m_ast_importer->DeportType(context,
-                                                      parser_type.GetASTContext(),
+    TypeFromUser user_type(m_ast_importer->DeportType(context->getASTContext(),
+                                                      parser_type.GetTypeSystem()->AsClangASTContext()->getASTContext(),
                                                       parser_type.GetOpaqueQualType()),
                            context);
 
@@ -1038,7 +1038,7 @@
                 QualType class_qual_type(class_decl->getTypeForDecl(), 0);
 
                 TypeFromUser class_user_type (class_qual_type.getAsOpaquePtr(),
-                                              &class_decl->getASTContext());
+                                              ClangASTContext::GetASTContext(&class_decl->getASTContext()));
 
                 if (log)
                 {
@@ -1076,7 +1076,7 @@
                     QualType class_pointer_type = method_decl->getASTContext().getPointerType(class_qual_type);
 
                     TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
-                                                &method_decl->getASTContext());
+                                                ClangASTContext::GetASTContext(&method_decl->getASTContext()));
 
                     m_struct_vars->m_object_pointer_type = self_user_type;
                 }
@@ -1166,7 +1166,7 @@
                     return; // This is unlikely, but we have seen crashes where this occurred
 
                 TypeFromUser class_user_type(QualType(interface_type, 0).getAsOpaquePtr(),
-                                             &method_decl->getASTContext());
+                                             ClangASTContext::GetASTContext(&method_decl->getASTContext()));
 
                 if (log)
                 {
@@ -1183,7 +1183,7 @@
                     QualType class_pointer_type = method_decl->getASTContext().getObjCObjectPointerType(QualType(interface_type, 0));
 
                     TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
-                                                &method_decl->getASTContext());
+                                                ClangASTContext::GetASTContext(&method_decl->getASTContext()));
 
                     m_struct_vars->m_object_pointer_type = self_user_type;
                 }
@@ -1193,7 +1193,7 @@
                     QualType class_type = method_decl->getASTContext().getObjCClassType();
 
                     TypeFromUser self_user_type(class_type.getAsOpaquePtr(),
-                                                &method_decl->getASTContext());
+                                                ClangASTContext::GetASTContext(&method_decl->getASTContext()));
 
                     m_struct_vars->m_object_pointer_type = self_user_type;
                 }
@@ -1222,11 +1222,11 @@
 
                     ClangASTType self_clang_type = self_type->GetClangFullType();
 
-                    if (self_clang_type.IsObjCClassType())
+                    if (ClangASTContext::IsObjCClassType(self_clang_type))
                     {
                         return;
                     }
-                    else if (self_clang_type.IsObjCObjectPointerType())
+                    else if (ClangASTContext::IsObjCObjectPointerType(self_clang_type))
                     {
                         self_clang_type = self_clang_type.GetPointeeType();
 
@@ -1748,7 +1748,7 @@
     if (is_reference)
         var_decl = context.AddVarDecl(pt);
     else
-        var_decl = context.AddVarDecl(pt.GetLValueReferenceType());
+        var_decl = context.AddVarDecl(ClangASTContext::GetLValueReferenceType(pt));
 
     std::string decl_name(context.m_decl_name.getAsString());
     ConstString entity_name(decl_name.c_str());
@@ -1792,7 +1792,7 @@
         return;
     }
 
-    NamedDecl *var_decl = context.AddVarDecl(parser_type.GetLValueReferenceType());
+    NamedDecl *var_decl = context.AddVarDecl(ClangASTContext::GetLValueReferenceType(parser_type));
 
     pvar_sp->EnableParserVars(GetParserID());
     ClangExpressionVariable::ParserVars *parser_vars = pvar_sp->GetParserVars(GetParserID());
@@ -1824,8 +1824,8 @@
 
     ASTContext *scratch_ast_context = target->GetScratchClangASTContext()->getASTContext();
 
-    TypeFromUser user_type (ClangASTContext::GetBasicType(scratch_ast_context, eBasicTypeVoid).GetPointerType().GetLValueReferenceType());
-    TypeFromParser parser_type (ClangASTContext::GetBasicType(m_ast_context, eBasicTypeVoid).GetPointerType().GetLValueReferenceType());
+    TypeFromUser user_type (ClangASTContext::GetLValueReferenceType(ClangASTContext::GetBasicType(scratch_ast_context, eBasicTypeVoid).GetPointerType()));
+    TypeFromParser parser_type (ClangASTContext::GetLValueReferenceType(ClangASTContext::GetBasicType(m_ast_context, eBasicTypeVoid).GetPointerType()));
     NamedDecl *var_decl = context.AddVarDecl(parser_type);
 
     std::string decl_name(context.m_decl_name.getAsString());
@@ -1867,7 +1867,7 @@
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
     Target *target = m_parser_vars->m_exe_ctx.GetTargetPtr();
 
-    ASTContext *scratch_ast_context = target->GetScratchClangASTContext()->getASTContext();
+    ClangASTContext *scratch_ast_context = target->GetScratchClangASTContext();
 
     for (size_t index = 0, num_entities = m_found_entities.GetSize();
          index < num_entities;
@@ -1896,9 +1896,9 @@
             }
 
             QualType var_type = var_decl->getType();
-            TypeFromParser parser_type(var_type.getAsOpaquePtr(), &var_decl->getASTContext());
+            TypeFromParser parser_type(var_type.getAsOpaquePtr(), ClangASTContext::GetASTContext(&var_decl->getASTContext()));
 
-            lldb::clang_type_t copied_type = m_ast_importer->CopyType(scratch_ast_context, &var_decl->getASTContext(), var_type.getAsOpaquePtr());
+            lldb::clang_type_t copied_type = m_ast_importer->CopyType(scratch_ast_context->getASTContext(), &var_decl->getASTContext(), var_type.getAsOpaquePtr());
 
             if (!copied_type)
             {
@@ -2136,15 +2136,17 @@
         const bool is_attr_used = true;
         const bool is_artificial = false;
 
-        copied_clang_type.AddMethodToCXXRecordType ("$__lldb_expr",
-                                                    method_type,
-                                                    lldb::eAccessPublic,
-                                                    is_virtual,
-                                                    is_static,
-                                                    is_inline,
-                                                    is_explicit,
-                                                    is_attr_used,
-                                                    is_artificial);
+        ClangASTContext::GetASTContext(m_ast_context)->
+            AddMethodToCXXRecordType (copied_clang_type.GetOpaqueQualType(),
+                                      "$__lldb_expr",
+                                      method_type,
+                                      lldb::eAccessPublic,
+                                      is_virtual,
+                                      is_static,
+                                      is_inline,
+                                      is_explicit,
+                                      is_attr_used,
+                                      is_artificial);
     }
 
     return TypeFromParser(copied_clang_type);