Cleaned up a unused member variable in Debugger.

Added the start of Host specific launch services, though it currently isn't
hookup up to anything. We want to be able to launch a process and use the
native launch services to launch an app like it would be launched by the
user double clicking on the app. We also eventually want to be able to run
a command line app in a newly spawned terminal to avoid terminal sharing.

Fixed an issue with the new DWARF forward type declaration stuff. A crasher
was found that was happening when trying to properly expand the forward
declarations.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@115213 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Core/Debugger.cpp b/source/Core/Debugger.cpp
index 5ad5227..8be3da0 100644
--- a/source/Core/Debugger.cpp
+++ b/source/Core/Debugger.cpp
@@ -155,8 +155,7 @@
     m_command_interpreter_ap (new CommandInterpreter (*this, eScriptLanguageDefault, false)),
     m_exe_ctx (),
     m_input_readers (),
-    m_input_reader_data (),
-    m_use_external_editor(false)
+    m_input_reader_data ()
 {
     m_command_interpreter_ap->Initialize ();
 }
diff --git a/source/Host/macosx/Host.mm b/source/Host/macosx/Host.mm
index 05e8833..e3379d0 100644
--- a/source/Host/macosx/Host.mm
+++ b/source/Host/macosx/Host.mm
@@ -12,11 +12,13 @@
 #include "lldb/Core/Log.h"
 
 #include "cfcpp/CFCBundle.h"
+#include "cfcpp/CFCMutableDictionary.h"
 #include "cfcpp/CFCReleaser.h"
 #include "cfcpp/CFCString.h"
 
 #include <objc/objc-auto.h>
 
+#include <ApplicationServices/ApplicationServices.h>
 #include <Carbon/Carbon.h>
 #include <Foundation/Foundation.h>
 
@@ -112,8 +114,44 @@
   return false;
 }
 
+lldb::pid_t
+Host::LaunchApplication (const FileSpec &app_file_spec)
+{
+    char app_path[PATH_MAX];
+    app_file_spec.GetPath(app_path, sizeof(app_path));
+
+    LSApplicationParameters app_params;
+    ::bzero (&app_params, sizeof (app_params));
+    app_params.flags = kLSLaunchDefaults | 
+                       kLSLaunchDontAddToRecents | 
+                       kLSLaunchDontSwitch |
+                       kLSLaunchNewInstance;// | 0x00001000;
+    
+    FSRef app_fsref;
+    CFCString app_cfstr (app_path, kCFStringEncodingUTF8);
+    
+    OSStatus error = ::FSPathMakeRef ((const UInt8 *)app_path, &app_fsref, false);
+    
+    // If we found the app, then store away the name so we don't have to re-look it up.
+    if (error != noErr)
+        return LLDB_INVALID_PROCESS_ID;
+    
+    app_params.application = &app_fsref;
+
+    ProcessSerialNumber psn;
+
+    error = ::LSOpenApplication (&app_params, &psn);
+
+    if (error != noErr)
+        return LLDB_INVALID_PROCESS_ID;
+
+    ::pid_t pid = LLDB_INVALID_PROCESS_ID;
+    error = ::GetProcessPID(&psn, &pid);
+    return pid;
+}
+
 bool
-Host::OpenFileInExternalEditor (FileSpec &file_spec, uint32_t line_no)
+Host::OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no)
 {
     // We attach this to an 'odoc' event to specify a particular selection
     typedef struct {
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index f0c33f6..d84fedd 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -366,6 +366,7 @@
     return error;
 }
 
+//#define LAUNCH_WITH_LAUNCH_SERVICES 1
 //----------------------------------------------------------------------
 // Process Control
 //----------------------------------------------------------------------
@@ -381,10 +382,18 @@
     const char *stderr_path
 )
 {
+    Error error;
+#if defined (LAUNCH_WITH_LAUNCH_SERVICES)
+    FileSpec app_file_spec (argv[0]);
+    pid_t pid = Host::LaunchApplication (app_file_spec);
+    if (pid != LLDB_INVALID_PROCESS_ID)
+        error = DoAttachToProcessWithID (pid);
+    else
+        error.SetErrorString("failed");
+#else
     //  ::LogSetBitMask (GDBR_LOG_DEFAULT);
     //  ::LogSetOptions (LLDB_LOG_OPTION_THREADSAFE | LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD);
     //  ::LogSetLogFile ("/dev/stdout");
-    Error error;
 
     ObjectFile * object_file = module->GetObjectFile();
     if (object_file)
@@ -497,9 +506,9 @@
         SetID(LLDB_INVALID_PROCESS_ID);
         error.SetErrorStringWithFormat("Failed to get object file from '%s' for arch %s.\n", module->GetFileSpec().GetFilename().AsCString(), module->GetArchitecture().AsCString());
     }
-
-    // Return the process ID we have
+#endif
     return error;
+
 }
 
 
@@ -621,9 +630,13 @@
 void
 ProcessGDBRemote::DidLaunch ()
 {
+#if defined (LAUNCH_WITH_LAUNCH_SERVICES)
+    DidAttach ();
+#else
     DidLaunchOrAttach ();
     if (m_dynamic_loader_ap.get())
         m_dynamic_loader_ap->DidLaunch();
+#endif
 }
 
 Error
diff --git a/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 6b735d2..0452ea3 100644
--- a/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2444,7 +2444,7 @@
             DWARFDebugInfoEntry::Attributes attributes;
             const char *type_name_cstr = NULL;
             ConstString type_name_dbstr;
-            Type::EncodingUIDType encoding_uid_type = Type::eIsTypeWithUID;
+            Type::EncodingDataType encoding_data_type = Type::eEncodingIsUID;
             clang_type_t clang_type = NULL;
 
             TypeList* type_list = m_obj_file->GetModule()->GetTypeList();
@@ -2508,37 +2508,37 @@
                     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_uid_type = Type::ePointerToTypeWithUID;
+                        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_uid_type = Type::eLValueReferenceToTypeWithUID;
+                        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_uid_type = Type::eTypedefToTypeWithUID;
+                        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_uid_type = Type::eIsConstTypeWithUID; //ClangASTContext::AddConstModifier (clang_type);
+                        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_uid_type = Type::eIsRestrictTypeWithUID; //ClangASTContext::AddRestrictModifier (clang_type);
+                        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_uid_type = Type::eIsVolatileTypeWithUID; //ClangASTContext::AddVolatileModifier (clang_type);
+                        encoding_data_type = Type::eEncodingIsVolatileUID; //ClangASTContext::AddVolatileModifier (clang_type);
                         break;
                     }
 
@@ -2563,7 +2563,7 @@
                         }
                     }
                         
-                    type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, byte_size, NULL, encoding_uid, encoding_uid_type, &decl, clang_type));
+                    type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, byte_size, NULL, encoding_uid, encoding_data_type, &decl, clang_type, clang_type == NULL));
 
                     m_die_to_type[die] = type_sp.get();
 
@@ -2679,21 +2679,27 @@
                     // parameters in any class methods need it for the clang 
                     // types for function prototypes. 
                     m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
-                    type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, byte_size, NULL, LLDB_INVALID_UID, Type::eIsTypeWithUID, &decl, clang_type));
+                    type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, byte_size, NULL, LLDB_INVALID_UID, Type::eEncodingIsUID, &decl, clang_type, true));
 
                     m_die_to_type[die] = type_sp.get();
 
-                    // Leave this as a forward declaration until we need
-                    // to know the details of the type. lldb_private::Type
-                    // will automatically call the SymbolFile virtual function
-                    // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
-                    // When the definition needs to be defined.
-                    if (clang_type_was_created)
+                    if (die->HasChildren() == false)
                     {
+                        // No children for this struct/union/class, lets finish it
+                        type_list->GetClangASTContext().StartTagDeclarationDefinition (clang_type);
+                        type_list->GetClangASTContext().CompleteTagDeclarationDefinition (clang_type);
+                    }
+                    else if (clang_type_was_created)
+                    {
+                        // Leave this as a forward declaration until we need
+                        // to know the details of the type. lldb_private::Type
+                        // will automatically call the SymbolFile virtual function
+                        // "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition(Type *)"
+                        // When the definition needs to be defined.
                         m_forward_decl_die_to_clang_type[die] = clang_type;
                         m_forward_decl_clang_type_to_die[clang_type] = die;
                     }
-
+                    
                 }
                 break;
 
@@ -2760,7 +2766,7 @@
                         }
 
                         m_die_to_decl_ctx[die] = ClangASTContext::GetDeclContextForType (clang_type);
-                        type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, byte_size, NULL, encoding_uid, Type::eIsTypeWithUID, &decl, clang_type));
+                        type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, byte_size, NULL, encoding_uid, Type::eEncodingIsUID, &decl, clang_type, true));
 
                         m_die_to_type[die] = type_sp.get();
 
@@ -2972,7 +2978,7 @@
                                     type_list->GetClangASTContext().SetFunctionParameters (function_decl, &function_param_decls.front(), function_param_decls.size());
                             }
                         }
-                        type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, 0, NULL, LLDB_INVALID_UID, Type::eIsTypeWithUID, &decl, clang_type));
+                        type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, 0, NULL, LLDB_INVALID_UID, Type::eEncodingIsUID, &decl, clang_type, false));
 
                         m_die_to_type[die] = type_sp.get();
                         assert(type_sp.get());
@@ -3057,7 +3063,7 @@
                                 array_element_bit_stride = array_element_bit_stride * num_elements;
                             }
                             ConstString empty_name;
-                            type_sp.reset( new Type(die->GetOffset(), this, empty_name, array_element_bit_stride / 8, NULL, LLDB_INVALID_UID, Type::eIsTypeWithUID, &decl, clang_type));
+                            type_sp.reset( new Type(die->GetOffset(), this, empty_name, array_element_bit_stride / 8, NULL, LLDB_INVALID_UID, Type::eEncodingIsUID, &decl, clang_type, false));
                             m_die_to_type[die] = type_sp.get();
                         }
                     }
@@ -3099,7 +3105,7 @@
 
                         size_t byte_size = ClangASTType::GetClangTypeBitWidth (type_list->GetClangASTContext().getASTContext(), clang_type) / 8;
 
-                        type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, byte_size, NULL, LLDB_INVALID_UID, Type::eIsTypeWithUID, NULL, clang_type));
+                        type_sp.reset( new Type(die->GetOffset(), this, type_name_dbstr, byte_size, NULL, LLDB_INVALID_UID, Type::eEncodingIsUID, NULL, clang_type, false));
                         m_die_to_type[die] = type_sp.get();
                     }
                                             
diff --git a/source/Symbol/Function.cpp b/source/Symbol/Function.cpp
index 41a708c..52b1356 100644
--- a/source/Symbol/Function.cpp
+++ b/source/Symbol/Function.cpp
@@ -414,7 +414,7 @@
     // Null out everything below the CompUnit 'cause we don't actually know these.
 
     size_t bit_size = ClangASTType::GetClangTypeBitWidth ((GetType()->GetClangASTContext().getASTContext()), fun_return_qualtype.getAsOpaquePtr());
-    Type return_type (0, GetType()->GetSymbolFile(), fun_return_name, bit_size, sc.comp_unit, 0, Type::eTypeUIDSynthetic, Declaration(), fun_return_qualtype.getAsOpaquePtr());
+    Type return_type (0, GetType()->GetSymbolFile(), fun_return_name, bit_size, sc.comp_unit, 0, Type::eEncodingIsSyntheticUID, Declaration(), fun_return_qualtype.getAsOpaquePtr(), false);
     return return_type;
 }
 
@@ -455,7 +455,7 @@
         // Null out everything below the CompUnit 'cause we don't actually know these.
 
         size_t bit_size = ClangASTType::GetClangTypeBitWidth ((GetType()->GetClangASTContext().getASTContext()), arg_qualtype.getAsOpaquePtr());
-        Type arg_type (0, GetType()->GetSymbolFile(), arg_return_name, bit_size, sc.comp_unit, 0, Type::eTypeUIDSynthetic, Declaration(), arg_qualtype.getAsOpaquePtr());
+        Type arg_type (0, GetType()->GetSymbolFile(), arg_return_name, bit_size, sc.comp_unit, 0, Type::eEncodingIsSyntheticUID, Declaration(), arg_qualtype.getAsOpaquePtr(), false);
         return arg_type;
     }
 
diff --git a/source/Symbol/Type.cpp b/source/Symbol/Type.cpp
index a4f0410..4605dff 100644
--- a/source/Symbol/Type.cpp
+++ b/source/Symbol/Type.cpp
@@ -33,22 +33,24 @@
     lldb::user_id_t uid,
     SymbolFile* symbol_file,
     const ConstString &name,
-    uint64_t byte_size,
+    uint32_t byte_size,
     SymbolContextScope *context,
-    lldb::user_id_t encoding_uid,
-    EncodingUIDType encoding_uid_type,
+    uintptr_t encoding_data,
+    EncodingDataType encoding_data_type,
     const Declaration& decl,
-    clang_type_t clang_type
+    clang_type_t clang_type,
+    bool is_forward_decl
 ) :
     UserID (uid),
     m_name (name),
-    m_byte_size (byte_size),
     m_symbol_file (symbol_file),
     m_context (context),
-    m_encoding_uid (encoding_uid),
-    m_encoding_uid_type (encoding_uid_type),
+    m_byte_size (byte_size),
+    m_encoding_data_type (encoding_data_type),
+    m_encoding_data (encoding_data),
     m_decl (decl),
-    m_clang_qual_type (clang_type)
+    m_clang_qual_type (clang_type),
+    m_is_forward_decl (is_forward_decl)
 {
 }
 
@@ -58,10 +60,11 @@
     m_byte_size (0),
     m_symbol_file (NULL),
     m_context (),
-    m_encoding_uid (0),
-    m_encoding_uid_type (eTypeInvalid),
+    m_encoding_data (0),
+    m_encoding_data_type (eEncodingInvalid),
     m_decl (),
-    m_clang_qual_type (NULL)
+    m_clang_qual_type (NULL),
+    m_is_forward_decl (false)
 {
 }
 
@@ -76,7 +79,7 @@
         m_byte_size = rhs.m_byte_size;
         m_symbol_file = rhs.m_symbol_file;
         m_context = rhs.m_context;
-        m_encoding_uid = rhs.m_encoding_uid;
+        m_encoding_data = rhs.m_encoding_data;
         m_decl = rhs.m_decl;
         m_clang_qual_type = rhs.m_clang_qual_type;
     }
@@ -105,19 +108,21 @@
         ClangASTType::DumpTypeDescription (GetClangAST(), m_clang_qual_type, s);
         *s << '"';
     }
-    else if (m_encoding_uid != LLDB_INVALID_UID)
+    else if (m_encoding_data != LLDB_INVALID_UID)
     {
-        s->Printf(", type_uid = 0x%8.8x", m_encoding_uid);
-        switch (m_encoding_uid_type)
+        s->Printf(", type_uid = 0x%8.8x", m_encoding_data);
+        switch (m_encoding_data_type)
         {
-        case eIsTypeWithUID: s->PutCString(" (unresolved type)"); break;
-        case eIsConstTypeWithUID: s->PutCString(" (unresolved const type)"); break;
-        case eIsRestrictTypeWithUID: s->PutCString(" (unresolved restrict type)"); break;
-        case eIsVolatileTypeWithUID: s->PutCString(" (unresolved volatile type)"); break;
-        case eTypedefToTypeWithUID: s->PutCString(" (unresolved typedef)"); break;
-        case ePointerToTypeWithUID: s->PutCString(" (unresolved pointer)"); break;
-        case eLValueReferenceToTypeWithUID: s->PutCString(" (unresolved L value reference)"); break;
-        case eRValueReferenceToTypeWithUID: s->PutCString(" (unresolved R value reference)"); break;
+        case eEncodingIsUID: s->PutCString(" (unresolved type)"); break;
+        case eEncodingIsConstUID: s->PutCString(" (unresolved const type)"); break;
+        case eEncodingIsRestrictUID: s->PutCString(" (unresolved restrict type)"); break;
+        case eEncodingIsVolatileUID: s->PutCString(" (unresolved volatile type)"); break;
+        case eEncodingIsTypedefUID: s->PutCString(" (unresolved typedef)"); break;
+        case eEncodingIsPointerUID: s->PutCString(" (unresolved pointer)"); break;
+        case eEncodingIsLValueReferenceUID: s->PutCString(" (unresolved L value reference)"); break;
+        case eEncodingIsRValueReferenceUID: s->PutCString(" (unresolved R value reference)"); break;
+        case eEncodingIsSyntheticUID: s->PutCString(" (synthetic type)"); break;
+        case eEncodingIsTypePtr: s->PutCString(" (Type *)"); break;
         }
     }    
 }
@@ -151,19 +156,21 @@
 
         ClangASTType::DumpTypeDescription (GetClangAST(), m_clang_qual_type, s);
     }
-    else if (m_encoding_uid != LLDB_INVALID_UID)
+    else if (m_encoding_data != LLDB_INVALID_UID)
     {
-        *s << ", type_uid = " << m_encoding_uid;
-        switch (m_encoding_uid_type)
+        *s << ", type_data = " << (uint64_t)m_encoding_data;
+        switch (m_encoding_data_type)
         {
-        case eIsTypeWithUID: s->PutCString(" (unresolved type)"); break;
-        case eIsConstTypeWithUID: s->PutCString(" (unresolved const type)"); break;
-        case eIsRestrictTypeWithUID: s->PutCString(" (unresolved restrict type)"); break;
-        case eIsVolatileTypeWithUID: s->PutCString(" (unresolved volatile type)"); break;
-        case eTypedefToTypeWithUID: s->PutCString(" (unresolved typedef)"); break;
-        case ePointerToTypeWithUID: s->PutCString(" (unresolved pointer)"); break;
-        case eLValueReferenceToTypeWithUID: s->PutCString(" (unresolved L value reference)"); break;
-        case eRValueReferenceToTypeWithUID: s->PutCString(" (unresolved R value reference)"); break;
+        case eEncodingIsUID: s->PutCString(" (unresolved type)"); break;
+        case eEncodingIsConstUID: s->PutCString(" (unresolved const type)"); break;
+        case eEncodingIsRestrictUID: s->PutCString(" (unresolved restrict type)"); break;
+        case eEncodingIsVolatileUID: s->PutCString(" (unresolved volatile type)"); break;
+        case eEncodingIsTypedefUID: s->PutCString(" (unresolved typedef)"); break;
+        case eEncodingIsPointerUID: s->PutCString(" (unresolved pointer)"); break;
+        case eEncodingIsLValueReferenceUID: s->PutCString(" (unresolved L value reference)"); break;
+        case eEncodingIsRValueReferenceUID: s->PutCString(" (unresolved R value reference)"); break;
+        case eEncodingIsSyntheticUID: s->PutCString(" (synthetic type)"); break;
+        case eEncodingIsTypePtr: s->PutCString(" (Type *)"); break;
         }
     }
 
@@ -241,16 +248,16 @@
 {
     if (m_byte_size == 0)
     {
-        switch (m_encoding_uid_type)
+        switch (m_encoding_data_type)
         {
-        case eIsTypeWithUID:
-        case eIsConstTypeWithUID:
-        case eIsRestrictTypeWithUID:
-        case eIsVolatileTypeWithUID:
-        case eTypedefToTypeWithUID:
-            if (m_encoding_uid != LLDB_INVALID_UID)
+        case eEncodingIsUID:
+        case eEncodingIsConstUID:
+        case eEncodingIsRestrictUID:
+        case eEncodingIsVolatileUID:
+        case eEncodingIsTypedefUID:
+            if (m_encoding_data != LLDB_INVALID_UID)
             {
-                Type *encoding_type = m_symbol_file->ResolveTypeUID (m_encoding_uid);
+                Type *encoding_type = m_symbol_file->ResolveTypeUID (m_encoding_data);
                 if (encoding_type)
                     m_byte_size = encoding_type->GetByteSize();
             }
@@ -262,9 +269,9 @@
             break;
 
         // If we are a pointer or reference, then this is just a pointer size;
-        case ePointerToTypeWithUID:
-        case eLValueReferenceToTypeWithUID:
-        case eRValueReferenceToTypeWithUID:
+        case eEncodingIsPointerUID:
+        case eEncodingIsLValueReferenceUID:
+        case eEncodingIsRValueReferenceUID:
             m_byte_size = GetTypeList()->GetClangASTContext().GetPointerBitSize() / 8;
             break;
         }
@@ -400,113 +407,132 @@
 bool
 lldb_private::Type::ResolveClangType (bool forward_decl_is_ok)
 {
+//    static int g_depth = 0;
+//    g_depth++;
+//    printf ("%.*sType::ResolveClangType (forward = %i) uid = 0x%8.8x, name = %s\n", g_depth, "", forward_decl_is_ok, m_uid, m_name.AsCString()); 
+    Type *encoding_type = NULL;
     if (m_clang_qual_type == NULL)
     {
         TypeList *type_list = GetTypeList();
-        if (m_encoding_uid != LLDB_INVALID_UID)
+        if (m_encoding_data != LLDB_INVALID_UID)
         {
-            Type *encoding_type = m_symbol_file->ResolveTypeUID(m_encoding_uid);
+            encoding_type = m_symbol_file->ResolveTypeUID(m_encoding_data);
             if (encoding_type)
             {
-
-                switch (m_encoding_uid_type)
+                switch (m_encoding_data_type)
                 {
-                case eIsTypeWithUID:
+                case eEncodingIsUID:
                     m_clang_qual_type = encoding_type->GetClangType();
                     break;
 
-                case eIsConstTypeWithUID:
-                    m_clang_qual_type = ClangASTContext::AddConstModifier (encoding_type->GetClangType(forward_decl_is_ok));
+                case eEncodingIsConstUID:
+                    m_clang_qual_type = ClangASTContext::AddConstModifier (encoding_type->GetClangType(true));
                     break;
 
-                case eIsRestrictTypeWithUID:
-                    m_clang_qual_type = ClangASTContext::AddRestrictModifier (encoding_type->GetClangType(forward_decl_is_ok));
+                case eEncodingIsRestrictUID:
+                    m_clang_qual_type = ClangASTContext::AddRestrictModifier (encoding_type->GetClangType(true));
                     break;
 
-                case eIsVolatileTypeWithUID:
-                    m_clang_qual_type = ClangASTContext::AddVolatileModifier (encoding_type->GetClangType(forward_decl_is_ok));
+                case eEncodingIsVolatileUID:
+                    m_clang_qual_type = ClangASTContext::AddVolatileModifier (encoding_type->GetClangType(true));
                     break;
 
-                case eTypedefToTypeWithUID:
-                    m_clang_qual_type = type_list->CreateClangTypedefType (this, encoding_type, forward_decl_is_ok);
+                case eEncodingIsTypedefUID:
+                    m_clang_qual_type = type_list->CreateClangTypedefType (this, encoding_type, true);
                     // Clear the name so it can get fully qualified in case the
                     // typedef is in a namespace.
                     m_name.Clear();
                     break;
 
-                case ePointerToTypeWithUID:
-                    m_clang_qual_type = type_list->CreateClangPointerType (encoding_type, forward_decl_is_ok);
+                case eEncodingIsPointerUID:
+                    m_clang_qual_type = type_list->CreateClangPointerType (encoding_type, true);
                     break;
 
-                case eLValueReferenceToTypeWithUID:
-                    m_clang_qual_type = type_list->CreateClangLValueReferenceType (encoding_type, forward_decl_is_ok);
+                case eEncodingIsLValueReferenceUID:
+                    m_clang_qual_type = type_list->CreateClangLValueReferenceType (encoding_type, true);
                     break;
 
-                case eRValueReferenceToTypeWithUID:
-                    m_clang_qual_type = type_list->CreateClangRValueReferenceType (encoding_type, forward_decl_is_ok);
+                case eEncodingIsRValueReferenceUID:
+                    m_clang_qual_type = type_list->CreateClangRValueReferenceType (encoding_type, true);
                     break;
 
                 default:
-                    assert(!"Unhandled encoding_uid_type.");
+                    assert(!"Unhandled encoding_data_type.");
                     break;
                 }
+                
+                if (encoding_type)
+                {
+                    m_encoding_data_type = eEncodingIsTypePtr;
+                    m_encoding_data = (uintptr_t)encoding_type;
+                }
             }
-            // Return here since we won't need to check if this is a forward 
-            // declaration below since we already obeyed this above.
-            return m_clang_qual_type != NULL;
         }
         else
         {
             // We have no encoding type, return void?
             clang_type_t void_clang_type = type_list->GetClangASTContext().GetBuiltInType_void();
-            switch (m_encoding_uid_type)
+            switch (m_encoding_data_type)
             {
-            case eIsTypeWithUID:
+            case eEncodingIsUID:
                 m_clang_qual_type = void_clang_type;
                 break;
 
-            case eIsConstTypeWithUID:
+            case eEncodingIsConstUID:
                 m_clang_qual_type = ClangASTContext::AddConstModifier (void_clang_type);
                 break;
 
-            case eIsRestrictTypeWithUID:
+            case eEncodingIsRestrictUID:
                 m_clang_qual_type = ClangASTContext::AddRestrictModifier (void_clang_type);
                 break;
 
-            case eIsVolatileTypeWithUID:
+            case eEncodingIsVolatileUID:
                 m_clang_qual_type = ClangASTContext::AddVolatileModifier (void_clang_type);
                 break;
 
-            case eTypedefToTypeWithUID:
+            case eEncodingIsTypedefUID:
                 m_clang_qual_type = type_list->GetClangASTContext().CreateTypedefType (m_name.AsCString(), void_clang_type, NULL);
                 break;
 
-            case ePointerToTypeWithUID:
+            case eEncodingIsPointerUID:
                 m_clang_qual_type = type_list->GetClangASTContext().CreatePointerType (void_clang_type);
                 break;
 
-            case eLValueReferenceToTypeWithUID:
+            case eEncodingIsLValueReferenceUID:
                 m_clang_qual_type = type_list->GetClangASTContext().CreateLValueReferenceType (void_clang_type);
                 break;
 
-            case eRValueReferenceToTypeWithUID:
+            case eEncodingIsRValueReferenceUID:
                 m_clang_qual_type = type_list->GetClangASTContext().CreateRValueReferenceType (void_clang_type);
                 break;
 
             default:
-                assert(!"Unhandled encoding_uid_type.");
+                assert(!"Unhandled encoding_data_type.");
                 break;
             }
         }
     }
     
     // Check if we have a forward reference to a class/struct/union/enum?
-    if (!forward_decl_is_ok && !ClangASTType::IsDefined (m_clang_qual_type))
+    if (m_is_forward_decl && m_clang_qual_type && !forward_decl_is_ok)
     {
-        // We have a forward declaration, we need to resolve it to a complete
-        // definition.
-        m_symbol_file->ResolveClangOpaqueTypeDefinition (m_clang_qual_type);
+        m_is_forward_decl = false;
+        if (!ClangASTType::IsDefined (m_clang_qual_type))
+        {
+            // We have a forward declaration, we need to resolve it to a complete
+            // definition.
+            m_symbol_file->ResolveClangOpaqueTypeDefinition (m_clang_qual_type);
+        }
+        else
+        {
+            if (encoding_type == NULL)
+                encoding_type = GetEncodingType ();
+            if (encoding_type != NULL)
+                encoding_type->ResolveClangType (forward_decl_is_ok);
+        }
     }
+//    if (g_depth > 0)
+//        --g_depth;
     return m_clang_qual_type != NULL;
 }