]> granicus.if.org Git - clang/commitdiff
Cache imported types
authorDouglas Gregor <dgregor@apple.com>
Mon, 8 Feb 2010 15:18:58 +0000 (15:18 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 8 Feb 2010 15:18:58 +0000 (15:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95543 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ASTImporter.h
lib/AST/ASTImporter.cpp

index 7cd6499be37ffe1818fbac75aec5e60e3790bf3a..01ec13470e654f2ab21c9053a1bcde50618c1bd4 100644 (file)
@@ -17,6 +17,7 @@
 #include "clang/AST/Type.h"
 #include "clang/AST/DeclarationName.h"
 #include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/DenseMap.h"
 
 namespace clang {
   class ASTContext;
@@ -38,7 +39,11 @@ namespace clang {
     /// \brief The diagnostics object that we should use to emit diagnostics
     /// within the context we're importing to and from.
     Diagnostic &ToDiags, &FromDiags;
-          
+    
+    /// \brief Mapping from the already-imported types in the "from" context
+    /// to the corresponding types in the "to" context.
+    llvm::DenseMap<Type *, Type *> ImportedTypes;
+    
   public:
     ASTImporter(ASTContext &ToContext, Diagnostic &ToDiags,
                 ASTContext &FromContext, Diagnostic &FromDiags);
index dc3281afba4bdeb38fc67af9cd4ff48592895c95..16fd7e6184e8121ae8a894ddd1120f5e79d59984 100644 (file)
@@ -434,13 +434,21 @@ QualType ASTImporter::Import(QualType FromT) {
   if (FromT.isNull())
     return QualType();
   
-  // FIXME: Cache type mappings?
+  // Check whether we've already imported this type.  
+  llvm::DenseMap<Type *, Type *>::iterator Pos
+    = ImportedTypes.find(FromT.getTypePtr());
+  if (Pos != ImportedTypes.end())
+    return ToContext.getQualifiedType(Pos->second, FromT.getQualifiers());
   
+  // Import the type
   ASTNodeImporter Importer(*this);
   QualType ToT = Importer.Visit(FromT.getTypePtr());
   if (ToT.isNull())
     return ToT;
   
+  // Record the imported type.
+  ImportedTypes[FromT.getTypePtr()] = ToT.getTypePtr();
+  
   return ToContext.getQualifiedType(ToT, FromT.getQualifiers());
 }