Added ClangExternalASTSourceCommon, a local superclass
for all our external AST sources that lets us associate
arbitrary flags with the types we put into the AST
contexts.  Also added an API on ClangASTContext that
allows access to these flags given only an ASTContext
and a type.

Because we don't have access to RTTI, and because at
some point in the future we might encounter external
AST sources that we didn't make (so they don't subclass
ClangExternalASTSourceCommon) I added a magic number
that we check before doing anything else, so that we
can catch that problem as soon as it appears.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@145748 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Symbol/ClangASTContext.cpp b/source/Symbol/ClangASTContext.cpp
index 8ad8c83..d156dae 100644
--- a/source/Symbol/ClangASTContext.cpp
+++ b/source/Symbol/ClangASTContext.cpp
@@ -61,6 +61,7 @@
 #include "lldb/Core/Log.h"
 #include "lldb/Core/RegularExpression.h"
 #include "lldb/Expression/ASTDumper.h"
+#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
 #include "lldb/Symbol/VerifyDecl.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Process.h"
@@ -5767,6 +5768,36 @@
     return qual_type.getQualifiers().getCVRQualifiers();
 }
 
+uint64_t
+GetTypeFlags(clang::ASTContext *ast, lldb::clang_type_t clang_type)
+{
+    assert (clang_type);
+    
+    clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+    
+    if (!external_ast_source)
+        return 0;
+    
+    ClangExternalASTSourceCommon *common_ast_source = static_cast<ClangExternalASTSourceCommon*>(external_ast_source);
+    
+    return common_ast_source->GetMetadata((uintptr_t)clang_type);
+}
+
+void
+SetTypeFlags(clang::ASTContext *ast, lldb::clang_type_t clang_type, uint64_t flags)
+{
+    assert (clang_type);
+    
+    clang::ExternalASTSource *external_ast_source = ast->getExternalSource();
+    
+    if (!external_ast_source)
+        return;
+    
+    ClangExternalASTSourceCommon *common_ast_source = static_cast<ClangExternalASTSourceCommon*>(external_ast_source);
+    
+    return common_ast_source->SetMetadata((uintptr_t)clang_type, flags);
+}
+
 bool
 ClangASTContext::GetCompleteType (clang::ASTContext *ast, lldb::clang_type_t clang_type)
 {
diff --git a/source/Symbol/ClangExternalASTSourceCommon.cpp b/source/Symbol/ClangExternalASTSourceCommon.cpp
new file mode 100644
index 0000000..d5b7d57
--- /dev/null
+++ b/source/Symbol/ClangExternalASTSourceCommon.cpp
@@ -0,0 +1,40 @@
+//===-- ClangExternalASTSourceCommon.cpp ------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
+
+using namespace lldb_private;
+
+#define ClangExternalASTSourceCommon_MAGIC  (0x00112233aabbccddull)
+
+ClangExternalASTSourceCommon::ClangExternalASTSourceCommon() : clang::ExternalASTSource()
+{
+    m_magic = ClangExternalASTSourceCommon_MAGIC;
+}
+
+uint64_t ClangExternalASTSourceCommon::GetMetadata (uintptr_t object)
+{
+    assert (m_magic == ClangExternalASTSourceCommon_MAGIC);
+    
+    return m_metadata[object];
+}
+
+void ClangExternalASTSourceCommon::SetMetadata (uintptr_t object, uint64_t metadata)
+{
+    assert (m_magic == ClangExternalASTSourceCommon_MAGIC);
+    
+    m_metadata[object] = metadata;
+}
+
+bool ClangExternalASTSourceCommon::HasMetadata (uintptr_t object)
+{
+    assert (m_magic == ClangExternalASTSourceCommon_MAGIC);
+
+    return m_metadata.find(object) != m_metadata.end();
+}
\ No newline at end of file