aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/ASTUnit.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-12-04 08:17:33 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-12-04 08:17:33 +0000
commitf772d1e2a5688572d07f42896a50ac57a4a41fe8 (patch)
treec2ced2fd641831faaac78b2855214f2ce6069753 /lib/Frontend/ASTUnit.cpp
parentf13876fac1eb2d384732779a7709575d4ecf27b6 (diff)
ASTUnit/CIndex: Explicitly track the top-level decls when using an ASTUnit made
from a source file. - This allows CIndex to avoid iterating over all the top-level decls when using a PCH, which means we deserialize far fewer decls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90559 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/ASTUnit.cpp')
-rw-r--r--lib/Frontend/ASTUnit.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 2afbcd133e..8c2731b895 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -180,13 +180,30 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
namespace {
-class NullAction : public ASTFrontendAction {
+class TopLevelDeclTrackerConsumer : public ASTConsumer {
+ ASTUnit &Unit;
+
+public:
+ TopLevelDeclTrackerConsumer(ASTUnit &_Unit) : Unit(_Unit) {}
+
+ void HandleTopLevelDecl(DeclGroupRef D) {
+ for (DeclGroupRef::iterator it = D.begin(), ie = D.end(); it != ie; ++it)
+ Unit.getTopLevelDecls().push_back(*it);
+ }
+};
+
+class TopLevelDeclTrackerAction : public ASTFrontendAction {
+public:
+ ASTUnit &Unit;
+
virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef InFile) {
- return new ASTConsumer();
+ return new TopLevelDeclTrackerConsumer(Unit);
}
public:
+ TopLevelDeclTrackerAction(ASTUnit &_Unit) : Unit(_Unit) {}
+
virtual bool hasCodeCompletionSupport() const { return false; }
};
@@ -198,7 +215,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(const CompilerInvocation &CI,
// Create the compiler instance to use for building the AST.
CompilerInstance Clang;
llvm::OwningPtr<ASTUnit> AST;
- NullAction Act;
+ llvm::OwningPtr<TopLevelDeclTrackerAction> Act;
Clang.getInvocation() = CI;
@@ -237,11 +254,12 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(const CompilerInvocation &CI,
// Create the preprocessor.
Clang.createPreprocessor();
- if (!Act.BeginSourceFile(Clang, Clang.getFrontendOpts().Inputs[0].second,
+ Act.reset(new TopLevelDeclTrackerAction(*AST));
+ if (!Act->BeginSourceFile(Clang, Clang.getFrontendOpts().Inputs[0].second,
/*IsAST=*/false))
goto error;
- Act.Execute();
+ Act->Execute();
// Steal the created target, context, and preprocessor, and take back the
// source and file managers.
@@ -251,7 +269,7 @@ ASTUnit *ASTUnit::LoadFromCompilerInvocation(const CompilerInvocation &CI,
Clang.takeFileManager();
AST->Target.reset(Clang.takeTarget());
- Act.EndSourceFile();
+ Act->EndSourceFile();
Clang.takeDiagnosticClient();
Clang.takeDiagnostics();