[Lldb-commits] [lldb] r145748 - in /lldb/trunk: include/lldb/Expression/ClangASTSource.h include/lldb/Symbol/ClangASTContext.h include/lldb/Symbol/ClangExternalASTSourceCallbacks.h include/lldb/Symbol/ClangExternalASTSourceCommon.h lldb.xcodeproj/project.pbxproj source/Symbol/ClangASTContext.cpp source/Symbol/ClangExternalASTSourceCommon.cpp

Sean Callanan scallanan at apple.com
Fri Dec 2 19:15:29 PST 2011


Author: spyffe
Date: Fri Dec  2 21:15:28 2011
New Revision: 145748

URL: http://llvm.org/viewvc/llvm-project?rev=145748&view=rev
Log:
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.

Added:
    lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCommon.h
    lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp
Modified:
    lldb/trunk/include/lldb/Expression/ClangASTSource.h
    lldb/trunk/include/lldb/Symbol/ClangASTContext.h
    lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCallbacks.h
    lldb/trunk/lldb.xcodeproj/project.pbxproj
    lldb/trunk/source/Symbol/ClangASTContext.cpp

Modified: lldb/trunk/include/lldb/Expression/ClangASTSource.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangASTSource.h?rev=145748&r1=145747&r2=145748&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangASTSource.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangASTSource.h Fri Dec  2 21:15:28 2011
@@ -13,7 +13,7 @@
 #include <set>
 
 #include "clang/Basic/IdentifierTable.h"
-#include "clang/AST/ExternalASTSource.h"
+#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
 #include "lldb/Symbol/ClangASTImporter.h"
 #include "lldb/Target/Target.h"
 
@@ -31,7 +31,7 @@
 /// the actual lookups.
 //----------------------------------------------------------------------
 class ClangASTSource : 
-    public clang::ExternalASTSource,
+    public ClangExternalASTSourceCommon,
     public ClangASTImporter::NamespaceMapCompleter
 {
 public:
@@ -198,7 +198,7 @@
     /// Clang AST contexts like to own their AST sources, so this is a
     /// state-free proxy object.
     //----------------------------------------------------------------------
-    class ClangASTSourceProxy : public clang::ExternalASTSource
+    class ClangASTSourceProxy : public ClangExternalASTSourceCommon
     {
     public:
         ClangASTSourceProxy (ClangASTSource &original) :
@@ -213,7 +213,7 @@
             return m_original.FindExternalVisibleDeclsByName(DC, Name);
         }
         
-        virtual clang::ExternalLoadResult 
+        clang::ExternalLoadResult 
         FindExternalLexicalDecls (const clang::DeclContext *DC,
                                   bool (*isKindWeWant)(clang::Decl::Kind),
                                   llvm::SmallVectorImpl<clang::Decl*> &Decls)
@@ -221,13 +221,13 @@
             return m_original.FindExternalLexicalDecls(DC, isKindWeWant, Decls);
         }
         
-        virtual void
+        void
         CompleteType (clang::TagDecl *Tag)
         {
             return m_original.CompleteType(Tag);
         }
         
-        virtual void 
+        void 
         CompleteType (clang::ObjCInterfaceDecl *Class)
         {
             return m_original.CompleteType(Class);
@@ -237,6 +237,21 @@
         {
             return m_original.StartTranslationUnit(Consumer);
         }
+        
+        uint64_t GetMetadata(uintptr_t object)
+        {
+            return m_original.GetMetadata(object);
+        }
+        
+        void SetMetadata(uintptr_t object, uint64_t metadata)
+        {
+            return m_original.SetMetadata(object, metadata);
+        }
+        
+        bool HasMetadata(uintptr_t object)
+        {
+            return m_original.HasMetadata(object);
+        }
     private:
         ClangASTSource &m_original;
     };

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=145748&r1=145747&r2=145748&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Fri Dec  2 21:15:28 2011
@@ -849,6 +849,15 @@
     //------------------------------------------------------------------
     static unsigned
     GetTypeQualifiers(lldb::clang_type_t clang_type);
+    
+    //------------------------------------------------------------------
+    // Flags
+    //------------------------------------------------------------------
+    static uint64_t
+    GetTypeFlags(clang::ASTContext *ast, lldb::clang_type_t clang_type);
+    
+    static void
+    SetTypeFlags(clang::ASTContext *ast, lldb::clang_type_t clang_type, uint64_t flags);
 protected:
     //------------------------------------------------------------------
     // Classes that inherit from ClangASTContext can see and modify these

Modified: lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCallbacks.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCallbacks.h?rev=145748&r1=145747&r2=145748&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCallbacks.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCallbacks.h Fri Dec  2 21:15:28 2011
@@ -19,40 +19,15 @@
 
 // Other libraries and framework includes
 
-// Clang headers like to use NDEBUG inside of them to enable/disable debug 
-// releated features using "#ifndef NDEBUG" preprocessor blocks to do one thing
-// or another. This is bad because it means that if clang was built in release
-// mode, it assumes that you are building in release mode which is not always
-// the case. You can end up with functions that are defined as empty in header
-// files when NDEBUG is not defined, and this can cause link errors with the
-// clang .a files that you have since you might be missing functions in the .a
-// file. So we have to define NDEBUG when including clang headers to avoid any
-// mismatches. This is covered by rdar://problem/8691220
-
-#if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
-#define LLDB_DEFINED_NDEBUG_FOR_CLANG
-#define NDEBUG
-// Need to include assert.h so it is as clang would expect it to be (disabled)
-#include <assert.h>
-#endif
-
-#include "clang/AST/ExternalASTSource.h"
-
-#ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
-#undef NDEBUG
-#undef LLDB_DEFINED_NDEBUG_FOR_CLANG
-// Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
-#include <assert.h>
-#endif
-
 // Project includes
 #include "lldb/lldb-enumerations.h"
 #include "lldb/Core/ClangForward.h"
 #include "lldb/Symbol/ClangASTType.h"
+#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
 
 namespace lldb_private {
 
-class ClangExternalASTSourceCallbacks : public clang::ExternalASTSource 
+class ClangExternalASTSourceCallbacks : public ClangExternalASTSourceCommon
 {
 public:
 

Added: lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCommon.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCommon.h?rev=145748&view=auto
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCommon.h (added)
+++ lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCommon.h Fri Dec  2 21:15:28 2011
@@ -0,0 +1,62 @@
+//===-- ClangExternalASTSourceCommon.h --------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_ClangExternalASTSourceCommon_h
+#define liblldb_ClangExternalASTSourceCommon_h
+
+// Clang headers like to use NDEBUG inside of them to enable/disable debug 
+// releated features using "#ifndef NDEBUG" preprocessor blocks to do one thing
+// or another. This is bad because it means that if clang was built in release
+// mode, it assumes that you are building in release mode which is not always
+// the case. You can end up with functions that are defined as empty in header
+// files when NDEBUG is not defined, and this can cause link errors with the
+// clang .a files that you have since you might be missing functions in the .a
+// file. So we have to define NDEBUG when including clang headers to avoid any
+// mismatches. This is covered by rdar://problem/8691220
+
+#if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF)
+#define LLDB_DEFINED_NDEBUG_FOR_CLANG
+#define NDEBUG
+// Need to include assert.h so it is as clang would expect it to be (disabled)
+#include <assert.h>
+#endif
+
+#include "clang/AST/ExternalASTSource.h"
+
+#ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG
+#undef NDEBUG
+#undef LLDB_DEFINED_NDEBUG_FOR_CLANG
+// Need to re-include assert.h so it is as _we_ would expect it to be (enabled)
+#include <assert.h>
+#endif
+
+namespace lldb_private {
+
+class ClangExternalASTSourceCommon : public clang::ExternalASTSource 
+{
+public:
+    ClangExternalASTSourceCommon();
+    
+    virtual uint64_t GetMetadata(uintptr_t object);
+    virtual void SetMetadata(uintptr_t object, uint64_t metadata);
+    virtual bool HasMetadata(uintptr_t object);
+private:
+    typedef llvm::DenseMap<uintptr_t, uint64_t> MetadataMap;
+    
+    MetadataMap m_metadata;
+    uint64_t    m_magic;        ///< Because we don't have RTTI, we must take it
+                                ///< on faith that any valid ExternalASTSource that
+                                ///< we try to use the *Metadata APIs on inherits
+                                ///< from ClangExternalASTSourceCommon.  This magic
+                                ///< number exists to enforce that.
+};
+    
+};
+
+#endif

Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=145748&r1=145747&r2=145748&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Fri Dec  2 21:15:28 2011
@@ -387,6 +387,7 @@
 		26F5C32D10F3DFDD009D5894 /* libtermcap.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 26F5C32B10F3DFDD009D5894 /* libtermcap.dylib */; };
 		26F73062139D8FDB00FD51C7 /* History.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26F73061139D8FDB00FD51C7 /* History.cpp */; };
 		494260DA14579144003C1C78 /* VerifyDecl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 494260D914579144003C1C78 /* VerifyDecl.cpp */; };
+		4966DCC4148978A10028481B /* ClangExternalASTSourceCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4966DCC3148978A10028481B /* ClangExternalASTSourceCommon.cpp */; };
 		496B015B1406DEB100F830D5 /* IRInterpreter.h in Headers */ = {isa = PBXBuildFile; fileRef = 496B015A1406DEB100F830D5 /* IRInterpreter.h */; };
 		49A1CAC51430E8DE00306AC9 /* ExpressionSourceCode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49A1CAC31430E8BD00306AC9 /* ExpressionSourceCode.cpp */; };
 		49A71FE7141FFA5C00D59478 /* IRInterpreter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 496B01581406DE8900F830D5 /* IRInterpreter.cpp */; };
@@ -1147,8 +1148,10 @@
 		49445C2512245E3600C11A81 /* ClangExpressionParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangExpressionParser.cpp; path = source/Expression/ClangExpressionParser.cpp; sourceTree = "<group>"; };
 		49445C2912245E5500C11A81 /* ClangExpressionParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangExpressionParser.h; path = include/lldb/Expression/ClangExpressionParser.h; sourceTree = "<group>"; };
 		49445E341225AB6A00C11A81 /* ClangUserExpression.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangUserExpression.h; path = include/lldb/Expression/ClangUserExpression.h; sourceTree = "<group>"; };
+		495B38431489714C002708C5 /* ClangExternalASTSourceCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ClangExternalASTSourceCommon.h; path = include/lldb/Symbol/ClangExternalASTSourceCommon.h; sourceTree = "<group>"; };
 		495BBACB119A0DBE00418BEA /* PathMappingList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PathMappingList.cpp; path = source/Target/PathMappingList.cpp; sourceTree = "<group>"; };
 		495BBACF119A0DE700418BEA /* PathMappingList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PathMappingList.h; path = include/lldb/Target/PathMappingList.h; sourceTree = "<group>"; };
+		4966DCC3148978A10028481B /* ClangExternalASTSourceCommon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangExternalASTSourceCommon.cpp; path = source/Symbol/ClangExternalASTSourceCommon.cpp; sourceTree = "<group>"; };
 		496B01581406DE8900F830D5 /* IRInterpreter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = IRInterpreter.cpp; path = source/Expression/IRInterpreter.cpp; sourceTree = "<group>"; };
 		496B015A1406DEB100F830D5 /* IRInterpreter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IRInterpreter.h; path = include/lldb/Expression/IRInterpreter.h; sourceTree = "<group>"; };
 		497C86BD122823D800B54702 /* ClangUtilityFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangUtilityFunction.cpp; path = source/Expression/ClangUtilityFunction.cpp; sourceTree = "<group>"; };
@@ -2199,6 +2202,8 @@
 				49D8FB3513B558DE00411094 /* ClangASTImporter.cpp */,
 				49E45FA911F660DC008F7B28 /* ClangASTType.h */,
 				49E45FAD11F660FE008F7B28 /* ClangASTType.cpp */,
+				495B38431489714C002708C5 /* ClangExternalASTSourceCommon.h */,
+				4966DCC3148978A10028481B /* ClangExternalASTSourceCommon.cpp */,
 				26E6902E129C6BD500DDECD9 /* ClangExternalASTSourceCallbacks.h */,
 				26E69030129C6BEF00DDECD9 /* ClangExternalASTSourceCallbacks.cpp */,
 				266A42D7128E40040090CF7C /* ClangNamespaceDecl.h */,
@@ -3521,6 +3526,7 @@
 				49A1CAC51430E8DE00306AC9 /* ExpressionSourceCode.cpp in Sources */,
 				494260DA14579144003C1C78 /* VerifyDecl.cpp in Sources */,
 				49DA65031485C92A005FF180 /* AppleObjCSymbolVendor.cpp in Sources */,
+				4966DCC4148978A10028481B /* ClangExternalASTSourceCommon.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=145748&r1=145747&r2=145748&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Fri Dec  2 21:15:28 2011
@@ -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)
 {

Added: lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp?rev=145748&view=auto
==============================================================================
--- lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp (added)
+++ lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp Fri Dec  2 21:15:28 2011
@@ -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





More information about the lldb-commits mailing list