This is the meat of the code to add Clang modules
authorSean Callanan <scallanan@apple.com>
Fri, 5 Dec 2014 01:21:59 +0000 (01:21 +0000)
committerSean Callanan <scallanan@apple.com>
Fri, 5 Dec 2014 01:21:59 +0000 (01:21 +0000)
support to LLDB.  It includes the following:

- Changed DeclVendor to TypeVendor.
- Made the ObjCLanguageRuntime provide a DeclVendor
  rather than a TypeVendor.
- Changed the consumers of TypeVendors to use
  DeclVendors instead.
- Provided a few convenience functions on
  ClangASTContext to make that easier.

llvm-svn: 223433

16 files changed:
lldb/include/lldb/Symbol/ClangASTContext.h
lldb/include/lldb/Symbol/DeclVendor.h [moved from lldb/include/lldb/Symbol/TypeVendor.h with 53% similarity]
lldb/include/lldb/Target/ObjCLanguageRuntime.h
lldb/include/lldb/Target/Target.h
lldb/lldb.xcodeproj/project.pbxproj
lldb/source/API/SBTarget.cpp
lldb/source/Expression/ClangModulesDeclVendor.cpp [new file with mode: 0644]
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.cpp [moved from lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeVendor.cpp with 93% similarity]
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCDeclVendor.h [moved from lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeVendor.h with 70% similarity]
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV1.h
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCTypeEncodingParser.cpp
lldb/source/Symbol/ClangASTContext.cpp
lldb/source/Target/Target.cpp

index 331bc6e..a9096fe 100644 (file)
@@ -212,10 +212,13 @@ public:
                  ClangASTType type2,
                  bool ignore_qualifiers = false);
     
-    ClangASTType
+    static ClangASTType
+    GetTypeForDecl (clang::NamedDecl *decl);
+    
+    static ClangASTType
     GetTypeForDecl (clang::TagDecl *decl);
     
-    ClangASTType
+    static ClangASTType
     GetTypeForDecl (clang::ObjCInterfaceDecl *objc_decl);
     
     template <typename RecordDeclType>
similarity index 53%
rename from lldb/include/lldb/Symbol/TypeVendor.h
rename to lldb/include/lldb/Symbol/DeclVendor.h
index 559b21e..ffba71c 100644 (file)
@@ -1,4 +1,4 @@
-//===-- TypeVendor.h --------------------------------------------*- C++ -*-===//
+//===-- DeclVendor.h --------------------------------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,52 +7,64 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef liblldb_TypeVendor_h_
-#define liblldb_TypeVendor_h_
+#ifndef liblldb_DeclVendor_h_
+#define liblldb_DeclVendor_h_
 
 #include "lldb/Core/ClangForward.h"
 
+#include <vector>
+
 namespace lldb_private {
     
 //----------------------------------------------------------------------
-// The type vendor class is intended as a generic interface to search
-// for Clang types that are not necessarily backed by a specific symbol
-// file.
+// The Decl vendor class is intended as a generic interface to search
+// for named declarations that are not necessarily backed by a specific
+// symbol file.
 //----------------------------------------------------------------------
-class TypeVendor
+class DeclVendor
 {
 public:
     //------------------------------------------------------------------
     // Constructors and Destructors
     //------------------------------------------------------------------
-    TypeVendor()
+    DeclVendor()
     {
     }
     
     virtual
-    ~TypeVendor()
+    ~DeclVendor()
     {
     }
     
+    //------------------------------------------------------------------
+    /// Look up the set of Decls that the DeclVendor currently knows about
+    /// matching a given name.
+    ///
+    /// @param[in] name
+    ///     The name to look for.
+    ///
+    /// @param[in] append
+    ///     If true, FindDecls will clear "decls" when it starts.
+    ///
+    /// @param[in] max_matches
+    ///     The maximum number of Decls to return.  UINT32_MAX means "as
+    ///     many as possible."
+    ///
+    /// @return
+    ///     The number of Decls added to decls; will not exceed
+    ///     max_matches.
+    //------------------------------------------------------------------
     virtual uint32_t
-    FindTypes (const ConstString &name,
+    FindDecls (const ConstString &name,
                bool append,
                uint32_t max_matches,
-               std::vector <ClangASTType> &types) = 0;
-    
-    virtual clang::ASTContext *
-    GetClangASTContext () = 0;
-
-protected:
-    //------------------------------------------------------------------
-    // Classes that inherit from TypeVendor can see and modify these
-    //------------------------------------------------------------------
+               std::vector <clang::NamedDecl*> &decls) = 0;
     
 private:
     //------------------------------------------------------------------
-    // For TypeVendor only
+    // For DeclVendor only
     //------------------------------------------------------------------
-    DISALLOW_COPY_AND_ASSIGN (TypeVendor);
+    DISALLOW_COPY_AND_ASSIGN (DeclVendor);
 };
     
     
index cda7fa9..a3fee91 100644 (file)
@@ -21,8 +21,8 @@
 #include "lldb/lldb-private.h"
 #include "lldb/Core/PluginInterface.h"
 #include "lldb/Symbol/ClangASTType.h"
+#include "lldb/Symbol/DeclVendor.h"
 #include "lldb/Symbol/Type.h"
-#include "lldb/Symbol/TypeVendor.h"
 #include "lldb/Target/LanguageRuntime.h"
 
 namespace lldb_private {
@@ -385,8 +385,8 @@ public:
     virtual ObjCISA
     GetParentClass(ObjCISA isa);
     
-    virtual TypeVendor *
-    GetTypeVendor()
+    virtual DeclVendor *
+    GetDeclVendor()
     {
         return NULL;
     }
index 10b33f7..b09e325 100644 (file)
@@ -26,6 +26,7 @@
 #include "lldb/Core/Event.h"
 #include "lldb/Core/ModuleList.h"
 #include "lldb/Core/UserSettingsController.h"
+#include "lldb/Expression/ClangModulesDeclVendor.h"
 #include "lldb/Expression/ClangPersistentVariables.h"
 #include "lldb/Interpreter/Args.h"
 #include "lldb/Interpreter/OptionValueBoolean.h"
@@ -1346,6 +1347,9 @@ public:
 
     SourceManager &
     GetSourceManager ();
+    
+    ClangModulesDeclVendor *
+    GetClangModulesDeclVendor ();
 
     //------------------------------------------------------------------
     // Methods.
@@ -1383,6 +1387,7 @@ protected:
     std::unique_ptr<ClangASTContext> m_scratch_ast_context_ap;
     std::unique_ptr<ClangASTSource> m_scratch_ast_source_ap;
     std::unique_ptr<ClangASTImporter> m_ast_importer_ap;
+    std::unique_ptr<ClangModulesDeclVendor> m_clang_modules_decl_vendor_ap;
     ClangPersistentVariables m_persistent_variables;      ///< These are the persistent variables associated with this process for the expression parser.
 
     std::unique_ptr<SourceManager> m_source_manager_ap;
index b568946..e03b0c1 100644 (file)
                490A36C2180F0E9300BA31F8 /* PlatformWindows.h in Headers */ = {isa = PBXBuildFile; fileRef = 490A36BE180F0E6F00BA31F8 /* PlatformWindows.h */; };
                490A966B1628C3BF00F0002E /* SBDeclaration.h in Headers */ = {isa = PBXBuildFile; fileRef = 9452573816262CEF00325455 /* SBDeclaration.h */; settings = {ATTRIBUTES = (Public, ); }; };
                494260DA14579144003C1C78 /* VerifyDecl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 494260D914579144003C1C78 /* VerifyDecl.cpp */; };
+               4959511D1A1BC49500F6F8FC /* ClangModulesDeclVendor.h in Headers */ = {isa = PBXBuildFile; fileRef = 4959511B1A1BC48100F6F8FC /* ClangModulesDeclVendor.h */; };
+               4959511F1A1BC4BC00F6F8FC /* ClangModulesDeclVendor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4959511E1A1BC4BC00F6F8FC /* ClangModulesDeclVendor.cpp */; };
                4966DCC4148978A10028481B /* ClangExternalASTSourceCommon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4966DCC3148978A10028481B /* ClangExternalASTSourceCommon.cpp */; };
                49A1CAC51430E8DE00306AC9 /* ExpressionSourceCode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49A1CAC31430E8BD00306AC9 /* ExpressionSourceCode.cpp */; };
                49A71FE7141FFA5C00D59478 /* IRInterpreter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 496B01581406DE8900F830D5 /* IRInterpreter.cpp */; };
                49A71FE8141FFACF00D59478 /* DataEncoder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 268ED0A4140FF54200DE830F /* DataEncoder.cpp */; };
                49D8FB3913B5598F00411094 /* ClangASTImporter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49D8FB3513B558DE00411094 /* ClangASTImporter.cpp */; };
-               49DA65031485C92A005FF180 /* AppleObjCTypeVendor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49DA65021485C92A005FF180 /* AppleObjCTypeVendor.cpp */; };
+               49DA65031485C92A005FF180 /* AppleObjCDeclVendor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49DA65021485C92A005FF180 /* AppleObjCDeclVendor.cpp */; };
                49DCF6FE170E6B4A0092F75E /* IRMemoryMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49DCF6FD170E6B4A0092F75E /* IRMemoryMap.cpp */; };
                49DCF702170E70120092F75E /* Materializer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49DCF700170E70120092F75E /* Materializer.cpp */; };
                4C3ADCD61810D88B00357218 /* BreakpointResolverFileRegex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CAA56141422D986001FFA01 /* BreakpointResolverFileRegex.cpp */; };
                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>"; };
+               4959511B1A1BC48100F6F8FC /* ClangModulesDeclVendor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangModulesDeclVendor.h; path = include/lldb/Expression/ClangModulesDeclVendor.h; sourceTree = "<group>"; };
+               4959511E1A1BC4BC00F6F8FC /* ClangModulesDeclVendor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangModulesDeclVendor.cpp; path = source/Expression/ClangModulesDeclVendor.cpp; 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>"; };
                49A1CAC31430E8BD00306AC9 /* ExpressionSourceCode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ExpressionSourceCode.cpp; path = source/Expression/ExpressionSourceCode.cpp; sourceTree = "<group>"; };
                49A8A39F11D568A300AD3B68 /* ASTResultSynthesizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ASTResultSynthesizer.cpp; path = source/Expression/ASTResultSynthesizer.cpp; sourceTree = "<group>"; };
                49A8A3A311D568BF00AD3B68 /* ASTResultSynthesizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASTResultSynthesizer.h; path = include/lldb/Expression/ASTResultSynthesizer.h; sourceTree = "<group>"; };
-               49B01A2D15F67B1700666829 /* TypeVendor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = TypeVendor.h; path = include/lldb/Symbol/TypeVendor.h; sourceTree = "<group>"; };
+               49B01A2D15F67B1700666829 /* DeclVendor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DeclVendor.h; path = include/lldb/Symbol/DeclVendor.h; sourceTree = "<group>"; };
                49BB309511F79450001A4197 /* TaggedASTType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TaggedASTType.h; path = include/lldb/Symbol/TaggedASTType.h; sourceTree = "<group>"; };
                49C66B1C17011A43004D1922 /* IRMemoryMap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = IRMemoryMap.h; path = include/lldb/Expression/IRMemoryMap.h; sourceTree = "<group>"; };
                49CF9829122C70BD007A0B96 /* IRDynamicChecks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = IRDynamicChecks.cpp; path = source/Expression/IRDynamicChecks.cpp; sourceTree = "<group>"; };
                49D7072811B5AD11001AD875 /* ClangASTSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangASTSource.cpp; path = source/Expression/ClangASTSource.cpp; sourceTree = "<group>"; };
                49D8FB3513B558DE00411094 /* ClangASTImporter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClangASTImporter.cpp; path = source/Symbol/ClangASTImporter.cpp; sourceTree = "<group>"; };
                49D8FB3713B5594900411094 /* ClangASTImporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ClangASTImporter.h; path = include/lldb/Symbol/ClangASTImporter.h; sourceTree = "<group>"; };
-               49DA65021485C92A005FF180 /* AppleObjCTypeVendor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppleObjCTypeVendor.cpp; sourceTree = "<group>"; };
-               49DA65041485C942005FF180 /* AppleObjCTypeVendor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppleObjCTypeVendor.h; sourceTree = "<group>"; };
+               49DA65021485C92A005FF180 /* AppleObjCDeclVendor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = AppleObjCDeclVendor.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
+               49DA65041485C942005FF180 /* AppleObjCDeclVendor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppleObjCDeclVendor.h; sourceTree = "<group>"; };
                49DCF6FD170E6B4A0092F75E /* IRMemoryMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = IRMemoryMap.cpp; path = source/Expression/IRMemoryMap.cpp; sourceTree = "<group>"; };
                49DCF6FF170E6FD90092F75E /* Materializer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Materializer.h; path = include/lldb/Expression/Materializer.h; sourceTree = "<group>"; };
                49DCF700170E70120092F75E /* Materializer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Materializer.cpp; path = source/Expression/Materializer.cpp; sourceTree = "<group>"; };
                4CCA643E13B40B82003BDF98 /* ItaniumABILanguageRuntime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ItaniumABILanguageRuntime.h; sourceTree = "<group>"; };
                4CCA644213B40B82003BDF98 /* AppleObjCRuntime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppleObjCRuntime.cpp; sourceTree = "<group>"; };
                4CCA644313B40B82003BDF98 /* AppleObjCRuntime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppleObjCRuntime.h; sourceTree = "<group>"; };
-               4CCA644413B40B82003BDF98 /* AppleObjCRuntimeV1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppleObjCRuntimeV1.cpp; sourceTree = "<group>"; };
-               4CCA644513B40B82003BDF98 /* AppleObjCRuntimeV1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppleObjCRuntimeV1.h; sourceTree = "<group>"; };
-               4CCA644613B40B82003BDF98 /* AppleObjCRuntimeV2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppleObjCRuntimeV2.cpp; sourceTree = "<group>"; };
-               4CCA644713B40B82003BDF98 /* AppleObjCRuntimeV2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppleObjCRuntimeV2.h; sourceTree = "<group>"; };
+               4CCA644413B40B82003BDF98 /* AppleObjCRuntimeV1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = AppleObjCRuntimeV1.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
+               4CCA644513B40B82003BDF98 /* AppleObjCRuntimeV1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = AppleObjCRuntimeV1.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
+               4CCA644613B40B82003BDF98 /* AppleObjCRuntimeV2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = AppleObjCRuntimeV2.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
+               4CCA644713B40B82003BDF98 /* AppleObjCRuntimeV2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = AppleObjCRuntimeV2.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
                4CCA644813B40B82003BDF98 /* AppleObjCTrampolineHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppleObjCTrampolineHandler.cpp; sourceTree = "<group>"; };
                4CCA644913B40B82003BDF98 /* AppleObjCTrampolineHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppleObjCTrampolineHandler.h; sourceTree = "<group>"; };
                4CCA644A13B40B82003BDF98 /* AppleThreadPlanStepThroughObjCTrampoline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppleThreadPlanStepThroughObjCTrampoline.cpp; sourceTree = "<group>"; };
                94CD7D0719A3FB8600908B7C /* AppleObjCClassDescriptorV2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppleObjCClassDescriptorV2.h; sourceTree = "<group>"; };
                94CD7D0819A3FBA300908B7C /* AppleObjCClassDescriptorV2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppleObjCClassDescriptorV2.cpp; sourceTree = "<group>"; };
                94CD7D0A19A3FBC300908B7C /* AppleObjCTypeEncodingParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppleObjCTypeEncodingParser.h; sourceTree = "<group>"; };
-               94CD7D0B19A3FBCE00908B7C /* AppleObjCTypeEncodingParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AppleObjCTypeEncodingParser.cpp; sourceTree = "<group>"; };
+               94CD7D0B19A3FBCE00908B7C /* AppleObjCTypeEncodingParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = AppleObjCTypeEncodingParser.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
                94D0B10A16D5535900EA9C70 /* LibCxx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibCxx.cpp; path = source/DataFormatters/LibCxx.cpp; sourceTree = "<group>"; };
                94D0B10B16D5535900EA9C70 /* LibStdcpp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LibStdcpp.cpp; path = source/DataFormatters/LibStdcpp.cpp; sourceTree = "<group>"; };
                94D6A0A716CEB55F00833B6E /* NSArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NSArray.cpp; path = source/DataFormatters/NSArray.cpp; sourceTree = "<group>"; };
                9A9831041125FC5800A56CB0 /* SBProcess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBProcess.h; path = include/lldb/API/SBProcess.h; sourceTree = "<group>"; };
                9A9831051125FC5800A56CB0 /* SBSourceManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBSourceManager.cpp; path = source/API/SBSourceManager.cpp; sourceTree = "<group>"; };
                9A9831061125FC5800A56CB0 /* SBSourceManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBSourceManager.h; path = include/lldb/API/SBSourceManager.h; sourceTree = "<group>"; };
-               9A9831071125FC5800A56CB0 /* SBTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBTarget.cpp; path = source/API/SBTarget.cpp; sourceTree = "<group>"; };
+               9A9831071125FC5800A56CB0 /* SBTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = SBTarget.cpp; path = source/API/SBTarget.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
                9A9831081125FC5800A56CB0 /* SBTarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBTarget.h; path = include/lldb/API/SBTarget.h; sourceTree = "<group>"; };
                9A9831091125FC5800A56CB0 /* SBThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBThread.cpp; path = source/API/SBThread.cpp; sourceTree = "<group>"; };
                9A98310A1125FC5800A56CB0 /* SBThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBThread.h; path = include/lldb/API/SBThread.h; sourceTree = "<group>"; };
                                26BC7F1510F1B8EC00F91463 /* CompileUnit.cpp */,
                                26BC7C5810F1B6E900F91463 /* Declaration.h */,
                                26BC7F1610F1B8EC00F91463 /* Declaration.cpp */,
+                               49B01A2D15F67B1700666829 /* DeclVendor.h */,
                                26BC7C5910F1B6E900F91463 /* DWARFCallFrameInfo.h */,
                                26BC7F1710F1B8EC00F91463 /* DWARFCallFrameInfo.cpp */,
                                26BC7C5A10F1B6E900F91463 /* Function.h */,
                                26BC7F2010F1B8EC00F91463 /* Type.cpp */,
                                26BC7C6610F1B6E900F91463 /* TypeList.h */,
                                26BC7F2110F1B8EC00F91463 /* TypeList.cpp */,
-                               49B01A2D15F67B1700666829 /* TypeVendor.h */,
                                269FF07F12494F8E00225026 /* UnwindPlan.h */,
                                961FABB91235DE1600F93A47 /* UnwindPlan.cpp */,
                                269FF08112494FC200225026 /* UnwindTable.h */,
                                49445C2512245E3600C11A81 /* ClangExpressionParser.cpp */,
                                26BC7DC110F1B79500F91463 /* ClangExpressionVariable.h */,
                                26BC7ED610F1B86700F91463 /* ClangExpressionVariable.cpp */,
+                               4959511B1A1BC48100F6F8FC /* ClangModulesDeclVendor.h */,
+                               4959511E1A1BC4BC00F6F8FC /* ClangModulesDeclVendor.cpp */,
                                49D4FE821210B5FB00CDB854 /* ClangPersistentVariables.h */,
                                49D4FE871210B61C00CDB854 /* ClangPersistentVariables.cpp */,
                                49445E341225AB6A00C11A81 /* ClangUserExpression.h */,
                                4CCA644913B40B82003BDF98 /* AppleObjCTrampolineHandler.h */,
                                94CD7D0A19A3FBC300908B7C /* AppleObjCTypeEncodingParser.h */,
                                94CD7D0B19A3FBCE00908B7C /* AppleObjCTypeEncodingParser.cpp */,
-                               49DA65041485C942005FF180 /* AppleObjCTypeVendor.h */,
-                               49DA65021485C92A005FF180 /* AppleObjCTypeVendor.cpp */,
+                               49DA65041485C942005FF180 /* AppleObjCDeclVendor.h */,
+                               49DA65021485C92A005FF180 /* AppleObjCDeclVendor.cpp */,
                                4CCA644A13B40B82003BDF98 /* AppleThreadPlanStepThroughObjCTrampoline.cpp */,
                                4CCA644B13B40B82003BDF98 /* AppleThreadPlanStepThroughObjCTrampoline.h */,
                        );
                                2697A39515E404BA003E682C /* OptionValueArch.h in Headers */,
                                26474CBF18D0CB2D0073DEBA /* RegisterContextMach_i386.h in Headers */,
                                26474CC118D0CB2D0073DEBA /* RegisterContextMach_x86_64.h in Headers */,
+                               4959511D1A1BC49500F6F8FC /* ClangModulesDeclVendor.h in Headers */,
                                4C73152219B7D71700F865A4 /* Iterable.h in Headers */,
                                2698699D15E6CBD0002415FF /* OperatingSystemPython.h in Headers */,
                                232CB618191E00CD00EF39FC /* NativeBreakpointList.h in Headers */,
                                26680205115FD0ED008E1FE4 /* Frameworks */,
                                261B5A7511C3FA6F00AABD0A /* Fixup Framework Headers */,
                                9A19ACE2116563A700E0D453 /* Finish swig wrapper classes (lldb) */,
+                               4959511A1A1ACE9500F6F8FC /* Install Clang compiler headers */,
                                ED4AFF44199C2207004FFDC6 /* CopyFiles */,
                        );
                        buildRules = (
                        shellPath = /bin/sh;
                        shellScript = "$SRCROOT/scripts/build-swig-wrapper-classes.sh $SRCROOT $TARGET_BUILD_DIR $CONFIGURATION_BUILD_DIR \"\"\n";
                };
+               4959511A1A1ACE9500F6F8FC /* Install Clang compiler headers */ = {
+                       isa = PBXShellScriptBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       inputPaths = (
+                               "$(BUILT_PRODUCTS_DIR)/LLDB.framework/Resources/Clang",
+                       );
+                       name = "Install Clang compiler headers";
+                       outputPaths = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+                       shellPath = /bin/sh;
+                       shellScript = "/usr/bin/python $SRCROOT/scripts/package-clang-headers.py $TARGET_BUILD_DIR $LLVM_BUILD_DIR/$CURRENT_ARCH/$LLVM_CONFIGURATION";
+               };
                4C3326CA18B2A2B800EB5DD7 /* ShellScript */ = {
                        isa = PBXShellScriptBuildPhase;
                        buildActionMask = 2147483647;
                                2689002413353DDE00698AC0 /* CommandObjectSettings.cpp in Sources */,
                                2689002513353DDE00698AC0 /* CommandObjectSource.cpp in Sources */,
                                2689002613353DDE00698AC0 /* CommandObjectSyntax.cpp in Sources */,
+                               4959511F1A1BC4BC00F6F8FC /* ClangModulesDeclVendor.cpp in Sources */,
                                26BC179918C7F2B300D2196D /* JITLoader.cpp in Sources */,
                                2689002713353DDE00698AC0 /* CommandObjectTarget.cpp in Sources */,
                                2689002813353DDE00698AC0 /* CommandObjectThread.cpp in Sources */,
                                26EFC4CD18CFAF0D00865D87 /* ObjectFileJIT.cpp in Sources */,
                                49A1CAC51430E8DE00306AC9 /* ExpressionSourceCode.cpp in Sources */,
                                494260DA14579144003C1C78 /* VerifyDecl.cpp in Sources */,
-                               49DA65031485C92A005FF180 /* AppleObjCTypeVendor.cpp in Sources */,
+                               49DA65031485C92A005FF180 /* AppleObjCDeclVendor.cpp in Sources */,
                                4966DCC4148978A10028481B /* ClangExternalASTSourceCommon.cpp in Sources */,
                                26A527C114E24F5F00F3A14A /* ProcessMachCore.cpp in Sources */,
                                26A527C314E24F5F00F3A14A /* ThreadMachCore.cpp in Sources */,
index 92c27df..8b3f615 100644 (file)
@@ -2315,14 +2315,19 @@ SBTarget::FindFirstType (const char* typename_cstr)
             
             if (objc_language_runtime)
             {
-                TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
+                DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
                 
-                if (objc_type_vendor)
+                if (objc_decl_vendor)
                 {
-                    std::vector <ClangASTType> types;
+                    std::vector <clang::NamedDecl *> decls;
                     
-                    if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0)
-                        return SBType(types[0]);
+                    if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
+                    {
+                        if (ClangASTType type = ClangASTContext::GetTypeForDecl(decls[0]))
+                        {
+                            return SBType(type);
+                        }
+                    }
                 }
             }
         }
@@ -2388,17 +2393,20 @@ SBTarget::FindTypes (const char* typename_cstr)
             
             if (objc_language_runtime)
             {
-                TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor();
+                DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor();
                 
-                if (objc_type_vendor)
+                if (objc_decl_vendor)
                 {
-                    std::vector <ClangASTType> types;
+                    std::vector <clang::NamedDecl *> decls;
                     
-                    if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types))
+                    if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0)
                     {
-                        for (ClangASTType &type : types)
+                        for (clang::NamedDecl *decl : decls)
                         {
-                            sb_type_list.Append(SBType(type));
+                            if (ClangASTType type = ClangASTContext::GetTypeForDecl(decl))
+                            {
+                                sb_type_list.Append(SBType(type));
+                            }
                         }
                     }
                 }
diff --git a/lldb/source/Expression/ClangModulesDeclVendor.cpp b/lldb/source/Expression/ClangModulesDeclVendor.cpp
new file mode 100644 (file)
index 0000000..6eebea2
--- /dev/null
@@ -0,0 +1,370 @@
+//===-- ClangModulesDeclVendor.cpp ------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "ClangModulesDeclVendor.h"
+
+#include "lldb/Core/StreamString.h"
+#include "lldb/Host/FileSpec.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/Target.h"
+
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Serialization/ASTReader.h"
+
+using namespace lldb_private;
+
+namespace {
+    // Any Clang compiler requires a consumer for diagnostics.  This one stores them as strings
+    // so we can provide them to the user in case a module failed to load.
+    class StoringDiagnosticConsumer : public clang::DiagnosticConsumer
+    {
+    public:
+        StoringDiagnosticConsumer ();
+        void
+        HandleDiagnostic (clang::DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &info);
+        
+        void
+        ClearDiagnostics ();
+        
+        void
+        DumpDiagnostics (Stream &error_stream);
+    private:
+        typedef std::pair<clang::DiagnosticsEngine::Level, std::string> IDAndDiagnostic;
+        std::vector<IDAndDiagnostic> m_diagnostics;
+        Log * m_log;
+    };
+    
+    // The private implementation of our ClangModulesDeclVendor.  Contains all the Clang state required
+    // to load modules.
+    class ClangModulesDeclVendorImpl : public ClangModulesDeclVendor
+    {
+    public:
+        ClangModulesDeclVendorImpl(llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> &diagnostics_engine,
+                                   llvm::IntrusiveRefCntPtr<clang::CompilerInvocation> &compiler_invocation,
+                                   std::unique_ptr<clang::CompilerInstance> &&compiler_instance,
+                                   std::unique_ptr<clang::Parser> &&parser);
+        
+        virtual bool
+        AddModule(std::vector<llvm::StringRef> &path,
+                  Stream &error_stream);
+        
+        virtual uint32_t
+        FindDecls (const ConstString &name,
+                   bool append,
+                   uint32_t max_matches,
+                   std::vector <clang::NamedDecl*> &decls);
+        
+        ~ClangModulesDeclVendorImpl();
+        
+    private:
+        clang::ModuleLoadResult
+        DoGetModule(clang::ModuleIdPath path, bool make_visible);
+        
+        llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine>  m_diagnostics_engine;
+        llvm::IntrusiveRefCntPtr<clang::CompilerInvocation> m_compiler_invocation;
+        std::unique_ptr<clang::CompilerInstance>            m_compiler_instance;
+        std::unique_ptr<clang::Parser>                      m_parser;
+    };
+}
+
+StoringDiagnosticConsumer::StoringDiagnosticConsumer ()
+{
+    m_log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
+}
+
+void
+StoringDiagnosticConsumer::HandleDiagnostic (clang::DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &info)
+{
+    llvm::SmallVector<char, 256> diagnostic_string;
+    
+    info.FormatDiagnostic(diagnostic_string);
+    
+    m_diagnostics.push_back(IDAndDiagnostic(DiagLevel, std::string(diagnostic_string.data(), diagnostic_string.size())));
+}
+
+void
+StoringDiagnosticConsumer::ClearDiagnostics ()
+{
+    m_diagnostics.clear();
+}
+
+void
+StoringDiagnosticConsumer::DumpDiagnostics (Stream &error_stream)
+{
+    for (IDAndDiagnostic &diag : m_diagnostics)
+    {
+        switch (diag.first)
+        {
+            default:
+                error_stream.PutCString(diag.second.c_str());
+                break;
+            case clang::DiagnosticsEngine::Level::Ignored:
+                break;
+        }
+    }
+}
+
+static FileSpec
+GetResourceDir ()
+{
+    static FileSpec g_cached_resource_dir;
+    
+    static std::once_flag g_once_flag;
+    
+    std::call_once(g_once_flag, [](){
+        HostInfo::GetLLDBPath (lldb::ePathTypeClangDir, g_cached_resource_dir);
+    });
+    
+    return g_cached_resource_dir;
+}
+
+
+ClangModulesDeclVendor::ClangModulesDeclVendor()
+{
+}
+
+ClangModulesDeclVendor::~ClangModulesDeclVendor()
+{
+}
+
+ClangModulesDeclVendorImpl::ClangModulesDeclVendorImpl(llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> &diagnostics_engine,
+                                                       llvm::IntrusiveRefCntPtr<clang::CompilerInvocation> &compiler_invocation,
+                                                       std::unique_ptr<clang::CompilerInstance> &&compiler_instance,
+                                                       std::unique_ptr<clang::Parser> &&parser) :
+    ClangModulesDeclVendor(),
+    m_diagnostics_engine(diagnostics_engine),
+    m_compiler_invocation(compiler_invocation),
+    m_compiler_instance(std::move(compiler_instance)),
+    m_parser(std::move(parser))
+{
+}
+
+bool
+ClangModulesDeclVendorImpl::AddModule(std::vector<llvm::StringRef> &path,
+                                      Stream &error_stream)
+{
+    // Fail early.
+    
+    if (m_compiler_instance->hadModuleLoaderFatalFailure())
+    {
+        error_stream.PutCString("error: Couldn't load a module because the module loader is in a fatal state.\n");
+        return false;
+    }
+    
+    if (!m_compiler_instance->getPreprocessor().getHeaderSearchInfo().lookupModule(path[0]))
+    {
+        error_stream.Printf("error: Header search couldn't locate module %s\n", path[0].str().c_str());
+        return false;
+    }
+    
+    llvm::SmallVector<std::pair<clang::IdentifierInfo *, clang::SourceLocation>, 4> clang_path;
+    
+    {
+        size_t source_loc_counter = 0;
+        clang::SourceManager &source_manager = m_compiler_instance->getASTContext().getSourceManager();
+        
+        for (llvm::StringRef &component : path)
+        {
+            clang_path.push_back(std::make_pair(&m_compiler_instance->getASTContext().Idents.get(component),
+                                                source_manager.getLocForStartOfFile(source_manager.getMainFileID()).getLocWithOffset(source_loc_counter++)));
+        }
+    }
+    
+    StoringDiagnosticConsumer *diagnostic_consumer = static_cast<StoringDiagnosticConsumer *>(m_compiler_instance->getDiagnostics().getClient());
+    
+    diagnostic_consumer->ClearDiagnostics();
+    
+    clang::Module *top_level_module = DoGetModule(clang_path.front(), false);
+    
+    if (!top_level_module)
+    {
+        diagnostic_consumer->DumpDiagnostics(error_stream);
+        error_stream.Printf("error: Couldn't load top-level module %s\n", path[0].str().c_str());
+        return false;
+    }
+    
+    clang::Module *submodule = top_level_module;
+    
+    for (size_t ci = 1; ci < path.size(); ++ci)
+    {
+        llvm::StringRef &component = path[ci];
+        submodule = submodule->findSubmodule(component.str());
+        if (!submodule)
+        {
+            diagnostic_consumer->DumpDiagnostics(error_stream);
+            error_stream.Printf("error: Couldn't load submodule %s\n", component.str().c_str());
+            return false;
+        }
+    }
+    
+    clang::Module *requested_module = DoGetModule(clang_path, true);
+    
+    return (requested_module != nullptr);
+}
+
+// ClangImporter::lookupValue
+
+uint32_t
+ClangModulesDeclVendorImpl::FindDecls (const ConstString &name,
+                                       bool append,
+                                       uint32_t max_matches,
+                                       std::vector <clang::NamedDecl*> &decls)
+{
+    if (!append)
+        decls.clear();
+    
+    clang::IdentifierInfo &ident = m_compiler_instance->getASTContext().Idents.get(name.GetStringRef());
+    
+    clang::LookupResult lookup_result(m_compiler_instance->getSema(),
+                                      clang::DeclarationName(&ident),
+                                      clang::SourceLocation(),
+                                      clang::Sema::LookupOrdinaryName);
+    
+    m_compiler_instance->getSema().LookupName(lookup_result, m_compiler_instance->getSema().getScopeForContext(m_compiler_instance->getASTContext().getTranslationUnitDecl()));
+    
+    uint32_t num_matches = 0;
+    
+    for (clang::NamedDecl *named_decl : lookup_result)
+    {
+        if (num_matches >= max_matches)
+            return num_matches;
+        
+        decls.push_back(named_decl);
+        ++num_matches;
+    }
+    
+    return num_matches;
+}
+
+ClangModulesDeclVendorImpl::~ClangModulesDeclVendorImpl()
+{
+}
+
+clang::ModuleLoadResult
+ClangModulesDeclVendorImpl::DoGetModule(clang::ModuleIdPath path,
+                                        bool make_visible)
+{
+    clang::Module::NameVisibilityKind visibility = make_visible ? clang::Module::AllVisible : clang::Module::Hidden;
+    
+    const bool is_inclusion_directive = false;
+    
+    return m_compiler_instance->loadModule(path.front().second, path, visibility, is_inclusion_directive);
+}
+
+static const char *ModuleImportBufferName = "LLDBModulesMemoryBuffer";
+
+lldb_private::ClangModulesDeclVendor *
+ClangModulesDeclVendor::Create(Target &target)
+{
+    // FIXME we should insure programmatically that the expression parser's compiler and the modules runtime's
+    // compiler are both initialized in the same way â€“ preferably by the same code.
+    
+    if (!target.GetPlatform()->SupportsModules())
+        return nullptr;
+    
+    const ArchSpec &arch = target.GetArchitecture();
+    
+    std::vector<std::string> compiler_invocation_arguments =
+    {
+        "-fmodules",
+        "-fcxx-modules",
+        "-fsyntax-only",
+        "-femit-all-decls",
+        "-target", arch.GetTriple().str(),
+        "-fmodules-validate-system-headers",
+        "-Werror=non-modular-include-in-framework-module"
+    };
+    
+    target.GetPlatform()->AddClangModuleCompilationOptions(compiler_invocation_arguments);
+
+    compiler_invocation_arguments.push_back(ModuleImportBufferName);
+
+    // Add additional search paths with { "-I", path } or { "-F", path } here.
+   
+    {
+        llvm::SmallString<128> DefaultModuleCache;
+        const bool erased_on_reboot = false;
+        llvm::sys::path::system_temp_directory(erased_on_reboot, DefaultModuleCache);
+        llvm::sys::path::append(DefaultModuleCache, "org.llvm.clang");
+        llvm::sys::path::append(DefaultModuleCache, "ModuleCache");
+        std::string module_cache_argument("-fmodules-cache-path=");
+        module_cache_argument.append(DefaultModuleCache.str().str());
+        compiler_invocation_arguments.push_back(module_cache_argument);
+    }
+    
+    {
+        FileSpec clang_resource_dir = GetResourceDir();
+        
+        if (clang_resource_dir.IsDirectory())
+        {
+            compiler_invocation_arguments.push_back("-resource-dir");
+            compiler_invocation_arguments.push_back(clang_resource_dir.GetPath());
+        }
+    }
+    
+    llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> diagnostics_engine = clang::CompilerInstance::createDiagnostics(new clang::DiagnosticOptions,
+                                                                                                                       new StoringDiagnosticConsumer);
+    
+    std::vector<const char *> compiler_invocation_argument_cstrs;
+    
+    for (const std::string &arg : compiler_invocation_arguments) {
+        compiler_invocation_argument_cstrs.push_back(arg.c_str());
+    }
+    
+    llvm::IntrusiveRefCntPtr<clang::CompilerInvocation> invocation(clang::createInvocationFromCommandLine(compiler_invocation_argument_cstrs, diagnostics_engine));
+    
+    if (!invocation)
+        return nullptr;
+    
+    std::unique_ptr<llvm::MemoryBuffer> source_buffer = llvm::MemoryBuffer::getMemBuffer("extern int __lldb __attribute__((unavailable));",
+                                                                                         ModuleImportBufferName);
+    
+    invocation->getPreprocessorOpts().addRemappedFile(ModuleImportBufferName, source_buffer.release());
+    
+    std::unique_ptr<clang::CompilerInstance> instance(new clang::CompilerInstance);
+    
+    instance->setDiagnostics(diagnostics_engine.get());
+    instance->setInvocation(invocation.get());
+    
+    std::unique_ptr<clang::FrontendAction> action(new clang::SyntaxOnlyAction);
+    
+    instance->setTarget(clang::TargetInfo::CreateTargetInfo(*diagnostics_engine, instance->getInvocation().TargetOpts));
+    
+    if (!instance->hasTarget())
+        return nullptr;
+    
+    instance->getTarget().adjust(instance->getLangOpts());
+    
+    if (!action->BeginSourceFile(*instance, instance->getFrontendOpts().Inputs[0]))
+        return nullptr;
+    
+    instance->getPreprocessor().enableIncrementalProcessing();
+    
+    instance->createModuleManager();
+    
+    instance->createSema(action->getTranslationUnitKind(), nullptr);
+    
+    const bool skipFunctionBodies = false;
+    std::unique_ptr<clang::Parser> parser(new clang::Parser(instance->getPreprocessor(), instance->getSema(), skipFunctionBodies));
+    
+    instance->getPreprocessor().EnterMainSourceFile();
+    parser->Initialize();
+    
+    clang::Parser::DeclGroupPtrTy parsed;
+    
+    while (!parser->ParseTopLevelDecl(parsed));
+    
+    return new ClangModulesDeclVendorImpl (diagnostics_engine, invocation, std::move(instance), std::move(parser));
+}
@@ -1,4 +1,4 @@
-//===-- AppleObjCSymbolVendor.cpp -------------------------------*- C++ -*-===//
+//===-- AppleObjCDeclVendor.cpp ---------------------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "AppleObjCTypeVendor.h"
+#include "AppleObjCDeclVendor.h"
 
 #include "lldb/Core/Log.h"
 #include "lldb/Core/Module.h"
@@ -25,8 +25,8 @@ using namespace lldb_private;
 class lldb_private::AppleObjCExternalASTSource : public ClangExternalASTSourceCommon
 {
 public:
-    AppleObjCExternalASTSource (AppleObjCTypeVendor &type_vendor) :
-        m_type_vendor(type_vendor)
+    AppleObjCExternalASTSource (AppleObjCDeclVendor &decl_vendor) :
+        m_decl_vendor(decl_vendor)
     {
     }
 
@@ -57,7 +57,7 @@ public:
 
             clang::ObjCInterfaceDecl *non_const_interface_decl = const_cast<clang::ObjCInterfaceDecl*>(interface_decl);
 
-            if (!m_type_vendor.FinishDecl(non_const_interface_decl))
+            if (!m_decl_vendor.FinishDecl(non_const_interface_decl))
                 break;
 
             clang::DeclContext::lookup_const_result result = non_const_interface_decl->lookup(name);
@@ -129,7 +129,7 @@ public:
             dumper.ToLog(log, "    [CT] ");
         }
 
-        m_type_vendor.FinishDecl(interface_decl);
+        m_decl_vendor.FinishDecl(interface_decl);
 
         if (log)
         {
@@ -153,16 +153,16 @@ public:
 
     void StartTranslationUnit (clang::ASTConsumer *Consumer)
     {
-        clang::TranslationUnitDecl *translation_unit_decl = m_type_vendor.m_ast_ctx.getASTContext()->getTranslationUnitDecl();
+        clang::TranslationUnitDecl *translation_unit_decl = m_decl_vendor.m_ast_ctx.getASTContext()->getTranslationUnitDecl();
         translation_unit_decl->setHasExternalVisibleStorage();
         translation_unit_decl->setHasExternalLexicalStorage();
     }
 private:
-    AppleObjCTypeVendor                                    &m_type_vendor;
+    AppleObjCDeclVendor                                    &m_decl_vendor;
 };
 
-AppleObjCTypeVendor::AppleObjCTypeVendor(ObjCLanguageRuntime &runtime) :
-    TypeVendor(),
+AppleObjCDeclVendor::AppleObjCDeclVendor(ObjCLanguageRuntime &runtime) :
+    DeclVendor(),
     m_runtime(runtime),
     m_ast_ctx(runtime.GetProcess()->GetTarget().GetArchitecture().GetTriple().getTriple().c_str()),
     m_type_realizer_sp(m_runtime.GetEncodingToType())
@@ -173,7 +173,7 @@ AppleObjCTypeVendor::AppleObjCTypeVendor(ObjCLanguageRuntime &runtime) :
 }
 
 clang::ObjCInterfaceDecl*
-AppleObjCTypeVendor::GetDeclForISA(ObjCLanguageRuntime::ObjCISA isa)
+AppleObjCDeclVendor::GetDeclForISA(ObjCLanguageRuntime::ObjCISA isa)
 {
     ISAToInterfaceMap::const_iterator iter = m_isa_to_interface.find(isa);
     
@@ -421,7 +421,7 @@ private:
 };
 
 bool
-AppleObjCTypeVendor::FinishDecl(clang::ObjCInterfaceDecl *interface_decl)
+AppleObjCDeclVendor::FinishDecl(clang::ObjCInterfaceDecl *interface_decl)
 {
     Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));  // FIXME - a more appropriate log channel?
     
@@ -534,7 +534,7 @@ AppleObjCTypeVendor::FinishDecl(clang::ObjCInterfaceDecl *interface_decl)
     {
         ASTDumper method_dumper ((clang::Decl*)interface_decl);
         
-        log->Printf("[AppleObjCTypeVendor::FinishDecl] Finishing Objective-C interface for %s", descriptor->GetClassName().AsCString());
+        log->Printf("[AppleObjCDeclVendor::FinishDecl] Finishing Objective-C interface for %s", descriptor->GetClassName().AsCString());
     }
     
     
@@ -548,7 +548,7 @@ AppleObjCTypeVendor::FinishDecl(clang::ObjCInterfaceDecl *interface_decl)
     {
         ASTDumper method_dumper ((clang::Decl*)interface_decl);
         
-        log->Printf("[AppleObjCTypeVendor::FinishDecl] Finished Objective-C interface");
+        log->Printf("[AppleObjCDeclVendor::FinishDecl] Finished Objective-C interface");
         
         method_dumper.ToLog(log, "  [AOTV::FD] ");
     }
@@ -557,10 +557,10 @@ AppleObjCTypeVendor::FinishDecl(clang::ObjCInterfaceDecl *interface_decl)
 }
 
 uint32_t
-AppleObjCTypeVendor::FindTypes (const ConstString &name,
+AppleObjCDeclVendor::FindDecls (const ConstString &name,
                                 bool append,
                                 uint32_t max_matches,
-                                std::vector <ClangASTType> &types)
+                                std::vector <clang::NamedDecl *> &decls)
 {
     static unsigned int invocation_id = 0;
     unsigned int current_id = invocation_id++;
@@ -568,14 +568,14 @@ AppleObjCTypeVendor::FindTypes (const ConstString &name,
     Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));  // FIXME - a more appropriate log channel?
     
     if (log)
-        log->Printf("AppleObjCTypeVendor::FindTypes [%u] ('%s', %s, %u, )",
+        log->Printf("AppleObjCDeclVendor::FindTypes [%u] ('%s', %s, %u, )",
                     current_id,
                     (const char*)name.AsCString(),
                     append ? "true" : "false",
                     max_matches);
     
     if (!append)
-        types.clear();
+        decls.clear();
     
     uint32_t ret = 0;
     
@@ -592,12 +592,11 @@ AppleObjCTypeVendor::FindTypes (const ConstString &name,
         
         if (!lookup_result.empty())
         {
-            if (const clang::ObjCInterfaceDecl *result_iface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(lookup_result[0]))
+            if (clang::ObjCInterfaceDecl *result_iface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(lookup_result[0]))
             {
-                clang::QualType result_iface_type = ast_ctx->getObjCInterfaceType(result_iface_decl);
-                
                 if (log)
                 {
+                    clang::QualType result_iface_type = ast_ctx->getObjCInterfaceType(result_iface_decl);
                     ASTDumper dumper(result_iface_type);
                     
                     uint64_t isa_value = LLDB_INVALID_ADDRESS;
@@ -611,7 +610,7 @@ AppleObjCTypeVendor::FindTypes (const ConstString &name,
                                 isa_value);
                 }
                     
-                types.push_back(ClangASTType(ast_ctx, result_iface_type.getAsOpaquePtr()));
+                decls.push_back(result_iface_decl);
                 ret++;
                 break;
             }
@@ -655,10 +654,9 @@ AppleObjCTypeVendor::FindTypes (const ConstString &name,
             break;
         }
         
-        clang::QualType new_iface_type = ast_ctx->getObjCInterfaceType(iface_decl);
-        
         if (log)
         {
+            clang::QualType new_iface_type = ast_ctx->getObjCInterfaceType(iface_decl);
             ASTDumper dumper(new_iface_type);
             log->Printf("AOCTV::FT [%u] Created %s (isa 0x%" PRIx64 ")",
                         current_id,
@@ -666,7 +664,7 @@ AppleObjCTypeVendor::FindTypes (const ConstString &name,
                         (uint64_t)isa);
         }
         
-        types.push_back(ClangASTType(ast_ctx, new_iface_type.getAsOpaquePtr()));
+        decls.push_back(iface_decl);
         ret++;
         break;
     } while (0);
@@ -1,4 +1,4 @@
-//===-- AppleObjCSymbolVendor.h ---------------------------------*- C++ -*-===//
+//===-- AppleObjCDeclVendor.h -----------------------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,8 +7,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef liblldb_AppleObjCSymbolVendor_h_
-#define liblldb_AppleObjCSymbolVendor_h_
+#ifndef liblldb_AppleObjCDeclVendor_h_
+#define liblldb_AppleObjCDeclVendor_h_
 
 // C Includes
 // C++ Includes
 // Project includes
 #include "lldb/lldb-private.h"
 #include "lldb/Symbol/ClangASTContext.h"
-#include "lldb/Symbol/TypeVendor.h"
+#include "lldb/Symbol/DeclVendor.h"
 #include "lldb/Target/ObjCLanguageRuntime.h"
 
 namespace lldb_private {
 
 class AppleObjCExternalASTSource;
     
-class AppleObjCTypeVendor : public TypeVendor
+class AppleObjCDeclVendor : public DeclVendor
 {
 public:
-    AppleObjCTypeVendor(ObjCLanguageRuntime &runtime);
+    AppleObjCDeclVendor(ObjCLanguageRuntime &runtime);
     
     virtual uint32_t
-    FindTypes (const ConstString &name,
+    FindDecls (const ConstString &name,
                bool append,
                uint32_t max_matches,
-               std::vector <ClangASTType> &types);
-    
-    virtual clang::ASTContext *
-    GetClangASTContext ()
-    {
-        return m_ast_ctx.getASTContext();
-    }
-    
+               std::vector <clang::NamedDecl *> &decls);
+        
     friend class AppleObjCExternalASTSource;
 private:
     clang::ObjCInterfaceDecl   *GetDeclForISA(ObjCLanguageRuntime::ObjCISA isa);
@@ -61,4 +55,4 @@ private:
 
 } // namespace lldb_private
 
-#endif  // liblldb_AppleObjCSymbolVendor_h_
+#endif  // liblldb_AppleObjCDeclVendor_h_
index 0a8c1fc..792886f 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "AppleObjCRuntimeV1.h"
 #include "AppleObjCTrampolineHandler.h"
-#include "AppleObjCTypeVendor.h"
+#include "AppleObjCDeclVendor.h"
 
 #include "clang/AST/Type.h"
 
@@ -445,11 +445,11 @@ AppleObjCRuntimeV1::UpdateISAToDescriptorMapIfNeeded()
     }
 }
 
-TypeVendor *
-AppleObjCRuntimeV1::GetTypeVendor()
+DeclVendor *
+AppleObjCRuntimeV1::GetDeclVendor()
 {
-    if (!m_type_vendor_ap.get())
-        m_type_vendor_ap.reset(new AppleObjCTypeVendor(*this));
+    if (!m_decl_vendor_ap.get())
+        m_decl_vendor_ap.reset(new AppleObjCDeclVendor(*this));
     
-    return m_type_vendor_ap.get();
+    return m_decl_vendor_ap.get();
 }
index 3977548..f98f065 100644 (file)
@@ -138,8 +138,8 @@ public:
     virtual void
     UpdateISAToDescriptorMapIfNeeded();
     
-    virtual TypeVendor *
-    GetTypeVendor();
+    virtual DeclVendor *
+    GetDeclVendor();
 
 protected:
     virtual lldb::BreakpointResolverSP
@@ -188,7 +188,7 @@ protected:
     
     HashTableSignature m_hash_signature;
     lldb::addr_t m_isa_hash_table_ptr;
-    std::unique_ptr<TypeVendor> m_type_vendor_ap;
+    std::unique_ptr<DeclVendor> m_decl_vendor_ap;
 private:
     AppleObjCRuntimeV1(Process *process);
 };
index 2401952..9522dd5 100644 (file)
 #include "AppleObjCRuntimeV2.h"
 #include "AppleObjCClassDescriptorV2.h"
 #include "AppleObjCTypeEncodingParser.h"
-#include "AppleObjCTypeVendor.h"
+#include "AppleObjCDeclVendor.h"
 #include "AppleObjCTrampolineHandler.h"
 
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclObjC.h"
 
 #include <vector>
 
@@ -346,7 +347,7 @@ AppleObjCRuntimeV2::AppleObjCRuntimeV2 (Process *process,
     m_get_shared_cache_class_info_code(),
     m_get_shared_cache_class_info_args (LLDB_INVALID_ADDRESS),
     m_get_shared_cache_class_info_args_mutex (Mutex::eMutexTypeNormal),
-    m_type_vendor_ap (),
+    m_decl_vendor_ap (),
     m_isa_hash_table_ptr (LLDB_INVALID_ADDRESS),
     m_hash_signature (),
     m_has_object_getClass (false),
@@ -401,12 +402,12 @@ AppleObjCRuntimeV2::GetDynamicTypeAndAddress (ValueObject &in_value,
                 else
                 {
                     // try to go for a ClangASTType at least
-                    TypeVendor* vendor = GetTypeVendor();
+                    DeclVendor* vendor = GetDeclVendor();
                     if (vendor)
                     {
-                        std::vector<ClangASTType> types;
-                        if (vendor->FindTypes(class_name, false, 1, types) && types.size() && types.at(0).IsValid())
-                            class_type_or_name.SetClangASTType(types.at(0));
+                        std::vector<clang::NamedDecl*> decls;
+                        if (vendor->FindDecls(class_name, false, 1, decls) && decls.size())
+                            class_type_or_name.SetClangASTType(ClangASTContext::GetTypeForDecl(decls[0]));
                     }
                 }
             }
@@ -1576,13 +1577,13 @@ AppleObjCRuntimeV2::GetActualTypeName(ObjCLanguageRuntime::ObjCISA isa)
     return ObjCLanguageRuntime::GetActualTypeName(isa);
 }
 
-TypeVendor *
-AppleObjCRuntimeV2::GetTypeVendor()
+DeclVendor *
+AppleObjCRuntimeV2::GetDeclVendor()
 {
-    if (!m_type_vendor_ap.get())
-        m_type_vendor_ap.reset(new AppleObjCTypeVendor(*this));
+    if (!m_decl_vendor_ap.get())
+        m_decl_vendor_ap.reset(new AppleObjCDeclVendor(*this));
     
-    return m_type_vendor_ap.get();
+    return m_decl_vendor_ap.get();
 }
 
 lldb::addr_t
index 15e7810..2ad5acb 100644 (file)
@@ -99,8 +99,8 @@ public:
     virtual ClassDescriptorSP
     GetClassDescriptorFromISA (ObjCISA isa);
     
-    virtual TypeVendor *
-    GetTypeVendor();
+    virtual DeclVendor *
+    GetDeclVendor();
     
     virtual lldb::addr_t
     LookupRuntimeSymbol (const ConstString &name);
@@ -280,7 +280,7 @@ private:
     lldb::addr_t                            m_get_shared_cache_class_info_args;
     Mutex                                   m_get_shared_cache_class_info_args_mutex;
 
-    std::unique_ptr<TypeVendor>               m_type_vendor_ap;
+    std::unique_ptr<DeclVendor>               m_decl_vendor_ap;
     lldb::addr_t                            m_isa_hash_table_ptr;
     HashTableSignature                      m_hash_signature;
     bool                                    m_has_object_getClass;
index bfabda9..197bdc0 100644 (file)
@@ -240,23 +240,22 @@ AppleObjCTypeEncodingParser::BuildObjCObjectPointerType (clang::ASTContext &ast_
                 name.erase(less_than_pos);
         }
         
-        TypeVendor *type_vendor = m_runtime.GetTypeVendor();
+        DeclVendor *decl_vendor = m_runtime.GetDeclVendor();
         
-        assert (type_vendor); // how are we parsing type encodings for expressions if a type vendor isn't in play?
-        assert (type_vendor->GetClangASTContext() == &ast_ctx); // it doesn't make sense for us to be looking in other places
+        assert (decl_vendor); // how are we parsing type encodings for expressions if a type vendor isn't in play?
         
         const bool append = false;
         const uint32_t max_matches = 1;
-        std::vector<ClangASTType> types;
+        std::vector<clang::NamedDecl *> decls;
         
-        uint32_t num_types = type_vendor->FindTypes(ConstString(name),
+        uint32_t num_types = decl_vendor->FindDecls(ConstString(name),
                                                     append,
                                                     max_matches,
-                                                    types);
+                                                    decls);
 
         assert(num_types); // how can a type be mentioned in runtime type signatures and not be in the runtime?
-
-        return types[0].GetPointerType().GetQualType();
+        
+        return ClangASTContext::GetTypeForDecl(decls[0]).GetPointerType().GetQualType();
     }
     else
     {
index 15027fb..5db40a0 100644 (file)
@@ -1132,6 +1132,16 @@ ClangASTContext::AreTypesSame (ClangASTType type1,
     return ast->hasSameType (type1_qual, type2_qual);
 }
 
+ClangASTType
+ClangASTContext::GetTypeForDecl (clang::NamedDecl *decl)
+{
+    if (clang::ObjCInterfaceDecl *interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl))
+        return GetTypeForDecl(interface_decl);
+    if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl))
+        return GetTypeForDecl(tag_decl);
+    return ClangASTType();
+}
+
 
 ClangASTType
 ClangASTContext::GetTypeForDecl (TagDecl *decl)
@@ -1139,7 +1149,7 @@ ClangASTContext::GetTypeForDecl (TagDecl *decl)
     // No need to call the getASTContext() accessor (which can create the AST
     // if it isn't created yet, because we can't have created a decl in this
     // AST if our AST didn't already exist...
-    ASTContext *ast = m_ast_ap.get();
+    ASTContext *ast = &decl->getASTContext();
     if (ast)
         return ClangASTType (ast, ast->getTagDeclType(decl).getAsOpaquePtr());
     return ClangASTType();
@@ -1151,7 +1161,7 @@ ClangASTContext::GetTypeForDecl (ObjCInterfaceDecl *decl)
     // No need to call the getASTContext() accessor (which can create the AST
     // if it isn't created yet, because we can't have created a decl in this
     // AST if our AST didn't already exist...
-    ASTContext *ast = m_ast_ap.get();
+    ASTContext *ast = &decl->getASTContext();
     if (ast)
         return ClangASTType (ast, ast->getObjCInterfaceType(decl).getAsOpaquePtr());
     return ClangASTType();
index 7ee1936..02125f9 100644 (file)
@@ -2028,6 +2028,22 @@ Target::GetSourceManager ()
     return *m_source_manager_ap;
 }
 
+ClangModulesDeclVendor *
+Target::GetClangModulesDeclVendor ()
+{
+    static Mutex s_clang_modules_decl_vendor_mutex; // If this is contended we can make it per-target
+    
+    {
+        Mutex::Locker clang_modules_decl_vendor_locker(s_clang_modules_decl_vendor_mutex);
+        
+        if (!m_clang_modules_decl_vendor_ap)
+        {
+            m_clang_modules_decl_vendor_ap.reset(ClangModulesDeclVendor::Create(*this));
+        }
+    }
+    
+    return m_clang_modules_decl_vendor_ap.get();
+}
 
 Target::StopHookSP
 Target::CreateStopHook ()