[cfe-commits] r123723 - in /cfe/trunk: include/clang/AST/ASTImporter.h lib/AST/ASTImporter.cpp lib/Frontend/ASTMerge.cpp
Douglas Gregor
dgregor at apple.com
Mon Jan 17 19:11:38 PST 2011
Author: dgregor
Date: Mon Jan 17 21:11:38 2011
New Revision: 123723
URL: http://llvm.org/viewvc/llvm-project?rev=123723&view=rev
Log:
Introduce the notion of a "minimal" import of ASTs, to better support LLDB.
Modified:
cfe/trunk/include/clang/AST/ASTImporter.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/Frontend/ASTMerge.cpp
Modified: cfe/trunk/include/clang/AST/ASTImporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTImporter.h?rev=123723&r1=123722&r2=123723&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTImporter.h (original)
+++ cfe/trunk/include/clang/AST/ASTImporter.h Mon Jan 17 21:11:38 2011
@@ -46,6 +46,9 @@
/// \brief The file managers we're importing to and from.
FileManager &ToFileManager, &FromFileManager;
+ /// \brief Whether to perform a minimal import.
+ bool Minimal;
+
/// \brief Mapping from the already-imported types in the "from" context
/// to the corresponding types in the "to" context.
llvm::DenseMap<Type *, Type *> ImportedTypes;
@@ -71,11 +74,29 @@
NonEquivalentDeclSet NonEquivalentDecls;
public:
+ /// \brief Create a new AST importer.
+ ///
+ /// \param ToContext The context we'll be importing into.
+ ///
+ /// \param ToFileManager The file manager we'll be importing into.
+ ///
+ /// \param FromContext The context we'll be importing from.
+ ///
+ /// \param FromFileManager The file manager we'll be importing into.
+ ///
+ /// \param MinimalImport If true, the importer will attempt to import
+ /// as little as it can, e.g., by importing declarations as forward
+ /// declarations that can be completed at a later point.
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
- ASTContext &FromContext, FileManager &FromFileManager);
+ ASTContext &FromContext, FileManager &FromFileManager,
+ bool MinimalImport);
virtual ~ASTImporter();
+ /// \brief Whether the importer will perform a minimal import, creating
+ /// to-be-completed forward declarations when possible.
+ bool isMinimalImport() const { return Minimal; }
+
/// \brief Import the given type from the "from" context into the "to"
/// context.
///
@@ -169,6 +190,12 @@
/// context.
FileID Import(FileID);
+ /// \brief Import the definition of the given declaration, including all of
+ /// the declarations it contains.
+ ///
+ /// This routine is intended to be used
+ void ImportDefinition(Decl *From);
+
/// \brief Cope with a name conflict when importing a declaration into the
/// given context.
///
@@ -225,12 +252,13 @@
/// \brief Note that we have imported the "from" declaration by mapping it
/// to the (potentially-newly-created) "to" declaration.
///
- /// \returns \p To
- Decl *Imported(Decl *From, Decl *To);
+ /// Subclasses can override this function to observe all of the \c From ->
+ /// \c To declaration mappings as they are imported.
+ virtual Decl *Imported(Decl *From, Decl *To);
/// \brief Determine whether the given types are structurally
/// equivalent.
- bool IsStructurallyEquivalent(QualType From, QualType To);
+ bool IsStructurallyEquivalent(QualType From, QualType To);
};
}
Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=123723&r1=123722&r2=123723&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Jan 17 21:11:38 2011
@@ -83,7 +83,7 @@
SourceLocation &Loc);
void ImportDeclarationNameLoc(const DeclarationNameInfo &From,
DeclarationNameInfo& To);
- void ImportDeclContext(DeclContext *FromDC);
+ void ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
bool ImportDefinition(RecordDecl *From, RecordDecl *To);
TemplateParameterList *ImportTemplateParameterList(
TemplateParameterList *Params);
@@ -1713,7 +1713,15 @@
}
}
-void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC) {
+void ASTNodeImporter::ImportDeclContext(DeclContext *FromDC, bool ForceImport) {
+ if (Importer.isMinimalImport() && !ForceImport) {
+ if (DeclContext *ToDC = Importer.ImportContext(FromDC)) {
+ ToDC->setHasExternalLexicalStorage();
+ ToDC->setHasExternalVisibleStorage();
+ }
+ return;
+ }
+
for (DeclContext::decl_iterator From = FromDC->decls_begin(),
FromEnd = FromDC->decls_end();
From != FromEnd;
@@ -3897,9 +3905,12 @@
}
ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,
- ASTContext &FromContext, FileManager &FromFileManager)
+ ASTContext &FromContext, FileManager &FromFileManager,
+ bool MinimalImport)
: ToContext(ToContext), FromContext(FromContext),
- ToFileManager(ToFileManager), FromFileManager(FromFileManager) {
+ ToFileManager(ToFileManager), FromFileManager(FromFileManager),
+ Minimal(MinimalImport)
+{
ImportedDecls[FromContext.getTranslationUnitDecl()]
= ToContext.getTranslationUnitDecl();
}
@@ -4163,6 +4174,17 @@
return ToID;
}
+void ASTImporter::ImportDefinition(Decl *From) {
+ Decl *To = Import(From);
+ if (!To)
+ return;
+
+ if (DeclContext *FromDC = cast<DeclContext>(From)) {
+ ASTNodeImporter Importer(*this);
+ Importer.ImportDeclContext(FromDC, true);
+ }
+}
+
DeclarationName ASTImporter::Import(DeclarationName FromName) {
if (!FromName)
return DeclarationName();
Modified: cfe/trunk/lib/Frontend/ASTMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTMerge.cpp?rev=123723&r1=123722&r2=123723&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTMerge.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTMerge.cpp Mon Jan 17 21:11:38 2011
@@ -52,7 +52,8 @@
ASTImporter Importer(CI.getASTContext(),
CI.getFileManager(),
Unit->getASTContext(),
- Unit->getFileManager());
+ Unit->getFileManager(),
+ /*MinimalImport=*/false);
TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
for (DeclContext::decl_iterator D = TU->decls_begin(),
More information about the cfe-commits
mailing list