Modified the lldb_private::Type clang type resolving code to handle three
cases when getting the clang type:
- need only a forward declaration
- need a clang type that can be used for layout (members and args/return types)
- need a full clang type

This allows us to partially parse the clang types and be as lazy as possible.
The first case is when we just need to declare a type and we will complete it
later. The forward declaration happens only for class/union/structs and enums.
The layout type allows us to resolve the full clang type _except_ if we have
any modifiers on a pointer or reference (both R and L value). In this case
when we are adding members or function args or return types, we only need to
know how the type will be laid out and we can defer completing the pointee
type until we later need it. The last type means we need a full definition for
the clang type.

Did some renaming of some enumerations to get rid of the old "DC" prefix (which
stands for DebugCore which is no longer around).

Modified the clang namespace support to be almost ready to be fed to the
expression parser. I made a new ClangNamespaceDecl class that can carry around
the AST and the namespace decl so we can copy it into the expression AST. I
modified the symbol vendor and symbol file plug-ins to use this new class.

llvm-svn: 118976
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 5deeb90..f3abd9e 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1158,7 +1158,7 @@
                             accessibility = default_accessibility;
                         member_accessibilities.push_back(accessibility);
 
-                        GetClangASTContext().AddFieldToRecordType (class_clang_type, name, member_type->GetClangType(), accessibility, bit_size);
+                        GetClangASTContext().AddFieldToRecordType (class_clang_type, name, member_type->GetClangLayoutType(), accessibility, bit_size);
                     }
                 }
             }
@@ -1226,16 +1226,16 @@
                         }
                     }
 
-                    Type *base_class_dctype = ResolveTypeUID(encoding_uid);
-                    assert(base_class_dctype);
+                    Type *base_class_type = ResolveTypeUID(encoding_uid);
+                    assert(base_class_type);
                     
                     if (class_language == eLanguageTypeObjC)
                     {
-                        GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_dctype->GetClangType());
+                        GetClangASTContext().SetObjCSuperClass(class_clang_type, base_class_type->GetClangType());
                     }
                     else
                     {
-                        base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_dctype->GetClangType(), accessibility, is_virtual, is_base_of_class));
+                        base_classes.push_back (GetClangASTContext().CreateBaseClassSpecifier (base_class_type->GetClangType(), accessibility, is_virtual, is_base_of_class));
                         assert(base_classes.back());
                     }
                 }
@@ -2100,36 +2100,42 @@
 }
 
 
-clang::NamespaceDecl *
+ClangNamespaceDecl
 SymbolFileDWARF::FindNamespace (const SymbolContext& sc, 
                                 const ConstString &name)
 {
+    ClangNamespaceDecl namespace_decl;
     DWARFDebugInfo* info = DebugInfo();
-    if (info == NULL)
-        return 0;
-
-    // Index if we already haven't to make sure the compile units
-    // get indexed and make their global DIE index list
-    if (!m_indexed)
-        Index ();
-
-    DWARFCompileUnit* curr_cu = NULL;
-    DWARFCompileUnit* prev_cu = NULL;
-    const DWARFDebugInfoEntry* die = NULL;
-    std::vector<NameToDIE::Info> die_info_array;
-    const size_t num_matches = m_namespace_index.Find (name, die_info_array);
-    for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
+    if (info)
     {
-        curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
-        
-        if (curr_cu != prev_cu)
-            curr_cu->ExtractDIEsIfNeeded (false);
+        // Index if we already haven't to make sure the compile units
+        // get indexed and make their global DIE index list
+        if (!m_indexed)
+            Index ();
 
-        die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
+        DWARFCompileUnit* curr_cu = NULL;
+        DWARFCompileUnit* prev_cu = NULL;
+        const DWARFDebugInfoEntry* die = NULL;
+        std::vector<NameToDIE::Info> die_info_array;
+        const size_t num_matches = m_namespace_index.Find (name, die_info_array);
+        for (size_t i=0; i<num_matches; ++i, prev_cu = curr_cu)
+        {
+            curr_cu = info->GetCompileUnitAtIndex(die_info_array[i].cu_idx);
+            
+            if (curr_cu != prev_cu)
+                curr_cu->ExtractDIEsIfNeeded (false);
 
-        return ResolveNamespaceDIE (curr_cu, die);
+            die = curr_cu->GetDIEAtIndexUnchecked(die_info_array[i].die_idx);
+
+            clang::NamespaceDecl *clang_namespace_decl = ResolveNamespaceDIE (curr_cu, die);
+            if (clang_namespace_decl)
+            {
+                namespace_decl.SetASTContext (GetClangASTContext().getASTContext());
+                namespace_decl.SetNamespaceDecl (clang_namespace_decl);
+            }
+        }
     }
-    return NULL;
+    return namespace_decl;
 }
 
 uint32_t
@@ -2700,6 +2706,10 @@
             DWARFDebugInfoEntry::Attributes attributes;
             const char *type_name_cstr = NULL;
             ConstString type_name_const_str;
+            Type::ResolveState resolve_state = Type::eResolveStateUnresolved;
+            size_t byte_size = 0;
+            Declaration decl;
+
             Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
             clang_type_t clang_type = NULL;
 
@@ -2719,9 +2729,7 @@
                     m_die_to_type[die] = DIE_IS_BEING_PARSED;
 
                     const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
-                    Declaration decl;
                     uint32_t encoding = 0;
-                    size_t byte_size = 0;
                     lldb::user_id_t encoding_uid = LLDB_INVALID_UID;
 
                     if (num_attributes > 0)
@@ -2758,47 +2766,21 @@
                     switch (tag)
                     {
                     default:
+                        break;
+
                     case DW_TAG_base_type:
+                        resolve_state = Type::eResolveStateFull;
                         clang_type = ast.GetBuiltinTypeForDWARFEncodingAndBitSize (type_name_cstr, 
                                                                                    encoding, 
                                                                                    byte_size * 8);
                         break;
 
-                    case DW_TAG_pointer_type:
-                        // The encoding_uid will be embedded into the
-                        // Type object and will be looked up when the Type::GetClangType()
-                        encoding_data_type = Type::eEncodingIsPointerUID;
-                        break;
-
-                    case DW_TAG_reference_type:
-                        // The encoding_uid will be embedded into the
-                        // Type object and will be looked up when the Type::GetClangType()
-                        encoding_data_type = Type::eEncodingIsLValueReferenceUID;
-                        break;
-
-                    case DW_TAG_typedef:
-                        // The encoding_uid will be embedded into the
-                        // Type object and will be looked up when the Type::GetClangType()
-                        encoding_data_type = Type::eEncodingIsTypedefUID;
-                        break;
-
-                    case DW_TAG_const_type:
-                        // The encoding_uid will be embedded into the
-                        // Type object and will be looked up when the Type::GetClangType()
-                        encoding_data_type = Type::eEncodingIsConstUID; //ClangASTContext::AddConstModifier (clang_type);
-                        break;
-
-                    case DW_TAG_restrict_type:
-                        // The encoding_uid will be embedded into the
-                        // Type object and will be looked up when the Type::GetClangType()
-                        encoding_data_type = Type::eEncodingIsRestrictUID; //ClangASTContext::AddRestrictModifier (clang_type);
-                        break;
-
-                    case DW_TAG_volatile_type:
-                        // The encoding_uid will be embedded into the
-                        // Type object and will be looked up when the Type::GetClangType()
-                        encoding_data_type = Type::eEncodingIsVolatileUID; //ClangASTContext::AddVolatileModifier (clang_type);
-                        break;
+                    case DW_TAG_pointer_type:   encoding_data_type = Type::eEncodingIsPointerUID;           break;
+                    case DW_TAG_reference_type: encoding_data_type = Type::eEncodingIsLValueReferenceUID;   break;
+                    case DW_TAG_typedef:        encoding_data_type = Type::eEncodingIsTypedefUID;           break;
+                    case DW_TAG_const_type:     encoding_data_type = Type::eEncodingIsConstUID;             break;
+                    case DW_TAG_restrict_type:  encoding_data_type = Type::eEncodingIsRestrictUID;          break;
+                    case DW_TAG_volatile_type:  encoding_data_type = Type::eEncodingIsVolatileUID;          break;
                     }
 
                     if (type_name_cstr != NULL && sc.comp_unit != NULL && 
@@ -2811,14 +2793,18 @@
                         if (type_name_const_str == g_objc_type_name_id)
                         {
                             clang_type = ast.GetBuiltInType_objc_id();
+                            resolve_state = Type::eResolveStateFull;
+
                         }
                         else if (type_name_const_str == g_objc_type_name_Class)
                         {
                             clang_type = ast.GetBuiltInType_objc_Class();
+                            resolve_state = Type::eResolveStateFull;
                         }
                         else if (type_name_const_str == g_objc_type_name_selector)
                         {
                             clang_type = ast.GetBuiltInType_objc_selector();
+                            resolve_state = Type::eResolveStateFull;
                         }
                     }
                         
@@ -2831,7 +2817,7 @@
                                              encoding_data_type, 
                                              &decl, 
                                              clang_type, 
-                                             clang_type == NULL));
+                                             resolve_state));
                     
                     m_die_to_type[die] = type_sp.get();
 
@@ -2853,10 +2839,8 @@
                     // Set a bit that lets us know that we are currently parsing this
                     m_die_to_type[die] = DIE_IS_BEING_PARSED;
 
-                    size_t byte_size = 0;
                     LanguageType class_language = eLanguageTypeUnknown;
                     //bool struct_is_class = false;
-                    Declaration decl;
                     const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
                     if (num_attributes > 0)
                     {
@@ -2974,7 +2958,6 @@
                     // parameters in any class methods need it for the clang 
                     // types for function prototypes. 
                     m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
-                    const bool is_forward_decl = die->HasChildren();
                     type_sp.reset (new Type (die->GetOffset(), 
                                              this, 
                                              type_name_const_str, 
@@ -2984,7 +2967,7 @@
                                              Type::eEncodingIsUID, 
                                              &decl, 
                                              clang_type, 
-                                             is_forward_decl));
+                                             Type::eResolveStateForward));
                     
                     m_die_to_type[die] = type_sp.get();
 
@@ -3013,9 +2996,7 @@
                     // Set a bit that lets us know that we are currently parsing this
                     m_die_to_type[die] = DIE_IS_BEING_PARSED;
 
-                    size_t byte_size = 0;
                     lldb::user_id_t encoding_uid = DW_INVALID_OFFSET;
-                    Declaration decl;
 
                     const size_t num_attributes = die->GetAttributes(this, dwarf_cu, NULL, attributes);
                     if (num_attributes > 0)
@@ -3086,7 +3067,7 @@
                                                  Type::eEncodingIsUID,
                                                  &decl, 
                                                  clang_type, 
-                                                 true));
+                                                 Type::eResolveStateForward));
                         
                         m_die_to_type[die] = type_sp.get();
 
@@ -3111,7 +3092,6 @@
 
                     const char *mangled = NULL;
                     dw_offset_t type_die_offset = DW_INVALID_OFFSET;
-                    Declaration decl;
                     bool is_variadic = false;
                     bool is_inline = false;
                     bool is_static = false;
@@ -3202,7 +3182,7 @@
                         func_type = ResolveTypeUID(type_die_offset);
 
                     if (func_type)
-                        return_clang_type = func_type->GetClangForwardType();
+                        return_clang_type = func_type->GetClangLayoutType();
                     else
                         return_clang_type = ast.GetBuiltInType_void();
 
@@ -3339,7 +3319,7 @@
                                              Type::eEncodingIsUID, 
                                              &decl, 
                                              clang_type, 
-                                             false));
+                                             Type::eResolveStateFull));
                     
                     m_die_to_type[die] = type_sp.get();
                     assert(type_sp.get());
@@ -3351,9 +3331,7 @@
                     // Set a bit that lets us know that we are currently parsing this
                     m_die_to_type[die] = DIE_IS_BEING_PARSED;
 
-                    size_t byte_size = 0;
                     lldb::user_id_t type_die_offset = DW_INVALID_OFFSET;
-                    Declaration decl;
                     int64_t first_index = 0;
                     uint32_t byte_stride = 0;
                     uint32_t bit_stride = 0;
@@ -3432,11 +3410,12 @@
                                                      empty_name, 
                                                      array_element_bit_stride / 8, 
                                                      NULL, 
-                                                     LLDB_INVALID_UID, 
+                                                     type_die_offset, 
                                                      Type::eEncodingIsUID, 
                                                      &decl, 
                                                      clang_type, 
-                                                     false));
+                                                     Type::eResolveStateFull));
+                            type_sp->SetEncodingType (element_type);
                             m_die_to_type[die] = type_sp.get();
                         }
                     }
@@ -3471,14 +3450,14 @@
                         Type *pointee_type = ResolveTypeUID(type_die_offset);
                         Type *class_type = ResolveTypeUID(containing_type_die_offset);
                         
-                        clang_type_t pointee_clang_type = pointee_type->GetClangType();
-                        clang_type_t class_clang_type = class_type->GetClangType();
+                        clang_type_t pointee_clang_type = pointee_type->GetClangForwardType();
+                        clang_type_t class_clang_type = class_type->GetClangLayoutType();
 
                         clang_type = ast.CreateMemberPointerType(pointee_clang_type, 
                                                                  class_clang_type);
 
-                        size_t byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(), 
-                                                                               clang_type) / 8;
+                        byte_size = ClangASTType::GetClangTypeBitWidth (ast.getASTContext(), 
+                                                                       clang_type) / 8;
 
                         type_sp.reset( new Type (die->GetOffset(), 
                                                  this, 
@@ -3489,7 +3468,7 @@
                                                  Type::eEncodingIsUID, 
                                                  NULL, 
                                                  clang_type, 
-                                                 false));
+                                                 Type::eResolveStateForward));
                         m_die_to_type[die] = type_sp.get();
                     }
                                             
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
index a92fbdd..1106b24 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -110,7 +110,7 @@
     virtual uint32_t        FindTypes (const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, bool append, uint32_t max_matches, lldb_private::TypeList& types);
 //  virtual uint32_t        FindTypes(const lldb_private::SymbolContext& sc, const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb::Type::Encoding encoding, lldb::user_id_t udt_uid, lldb_private::TypeList& types);
     virtual lldb_private::TypeList *GetTypeList ();
-    virtual clang::NamespaceDecl *
+    virtual lldb_private::ClangNamespaceDecl
             FindNamespace (const lldb_private::SymbolContext& sc, 
                            const lldb_private::ConstString &name);
 
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
index 7d4607e..a8f3763 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp
@@ -953,11 +953,11 @@
 //}
 
 
-clang::NamespaceDecl *
+ClangNamespaceDecl
 SymbolFileDWARFDebugMap::FindNamespace (const lldb_private::SymbolContext& sc, 
                                         const lldb_private::ConstString &name)
 {
-    clang::NamespaceDecl *matching_namespace = NULL;
+    ClangNamespaceDecl matching_namespace;
     SymbolFileDWARF *oso_dwarf;
 
     if (sc.comp_unit)
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
index 88aceb2..5ab88dc 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h
@@ -71,7 +71,7 @@
     virtual uint32_t        FindFunctions (const lldb_private::RegularExpression& regex, bool append, lldb_private::SymbolContextList& sc_list);
     virtual uint32_t        FindTypes (const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, bool append, uint32_t max_matches, lldb_private::TypeList& types);
 //  virtual uint32_t        FindTypes (const lldb_private::SymbolContext& sc, const RegularExpression& regex, bool append, uint32_t max_matches, Type::Encoding encoding, lldb::user_id_t udt_uid, TypeList& types);
-    virtual clang::NamespaceDecl *
+    virtual lldb_private::ClangNamespaceDecl
             FindNamespace (const lldb_private::SymbolContext& sc, 
                            const lldb_private::ConstString &name);