mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-01 15:56:08 +00:00

identifiers from a precompiled header. This patch changes the primary name lookup method for entities within a precompiled header. Previously, we would load all of the names of declarations at translation unit scope into a large DenseMap (inside the TranslationUnitDecl's DeclContext), and then perform a special "last resort" lookup into this DeclContext when we knew there was a PCH file (see Sema::LookupName). Now, when we see an identifier named for the first time, we load all of the declarations with that name that are visible from the translation unit into the IdentifierInfo's chain of declarations. Thus, the explicit "look into the translation unit's DeclContext" code is gone, and Sema effectively uses the same IdentifierInfo-based name lookup mechanism whether we are using a PCH file or not. This approach should help PCH scale with the size of the input program rather than the size of the PCH file. The "Hello, World!" application with Carbon.h as a PCH file now loads 20% of the identifiers in the PCH file rather than 85% of the identifiers. 90% of the 20% of identifiers loaded are actually loaded when we deserialize the preprocessor state. The next step is to make the preprocessor load macros lazily, which should drastically reduce the number of types, declarations, and identifiers loaded for "Hello, World". llvm-svn: 69737
86 lines
2.7 KiB
C++
86 lines
2.7 KiB
C++
//===--- ParseAST.cpp - Provide the clang::ParseAST method ----------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the clang::ParseAST method.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/Sema/ParseAST.h"
|
|
#include "Sema.h"
|
|
#include "clang/Sema/SemaConsumer.h"
|
|
#include "clang/Sema/ExternalSemaSource.h"
|
|
#include "clang/AST/ASTConsumer.h"
|
|
#include "clang/AST/ExternalASTSource.h"
|
|
#include "clang/AST/Stmt.h"
|
|
#include "clang/Parse/Parser.h"
|
|
#include "llvm/ADT/OwningPtr.h"
|
|
using namespace clang;
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Public interface to the file
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
|
|
/// the file is parsed. This inserts the parsed decls into the translation unit
|
|
/// held by Ctx.
|
|
///
|
|
void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
|
|
ASTContext &Ctx, bool PrintStats,
|
|
bool CompleteTranslationUnit) {
|
|
// Collect global stats on Decls/Stmts (until we have a module streamer).
|
|
if (PrintStats) {
|
|
Decl::CollectingStats(true);
|
|
Stmt::CollectingStats(true);
|
|
}
|
|
|
|
Sema S(PP, Ctx, *Consumer, CompleteTranslationUnit);
|
|
Parser P(PP, S);
|
|
PP.EnterMainSourceFile();
|
|
|
|
// Initialize the parser.
|
|
P.Initialize();
|
|
|
|
Consumer->Initialize(Ctx);
|
|
|
|
if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer))
|
|
SC->InitializeSema(S);
|
|
|
|
if (ExternalASTSource *External = Ctx.getExternalSource()) {
|
|
if (ExternalSemaSource *ExternalSema =
|
|
dyn_cast<ExternalSemaSource>(External))
|
|
ExternalSema->InitializeSema(S);
|
|
|
|
External->StartTranslationUnit(Consumer);
|
|
}
|
|
|
|
Parser::DeclGroupPtrTy ADecl;
|
|
|
|
while (!P.ParseTopLevelDecl(ADecl)) { // Not end of file.
|
|
// If we got a null return and something *was* parsed, ignore it. This
|
|
// is due to a top-level semicolon, an action override, or a parse error
|
|
// skipping something.
|
|
if (ADecl)
|
|
Consumer->HandleTopLevelDecl(ADecl.getAsVal<DeclGroupRef>());
|
|
};
|
|
|
|
Consumer->HandleTranslationUnit(Ctx);
|
|
|
|
if (PrintStats) {
|
|
fprintf(stderr, "\nSTATISTICS:\n");
|
|
P.getActions().PrintStats();
|
|
Ctx.PrintStats();
|
|
Decl::PrintStats();
|
|
Stmt::PrintStats();
|
|
Consumer->PrintStats();
|
|
|
|
Decl::CollectingStats(false);
|
|
Stmt::CollectingStats(false);
|
|
}
|
|
}
|