summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/AST/ASTImporter.h7
-rw-r--r--clang/lib/AST/ASTImporter.cpp10
2 files changed, 15 insertions, 2 deletions
diff --git a/clang/include/clang/AST/ASTImporter.h b/clang/include/clang/AST/ASTImporter.h
index 7cd6499be37..01ec13470e6 100644
--- a/clang/include/clang/AST/ASTImporter.h
+++ b/clang/include/clang/AST/ASTImporter.h
@@ -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);
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index dc3281afba4..16fd7e6184e 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -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());
}
OpenPOWER on IntegriCloud