2008-02-06 08:23:21 +08:00
|
|
|
//===--- ParseAST.cpp - Provide the clang::ParseAST method ----------------===//
|
2006-08-17 14:28:25 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-08-17 14:28:25 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-02-06 08:23:21 +08:00
|
|
|
// This file implements the clang::ParseAST method.
|
2006-08-17 14:28:25 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-02-06 08:23:21 +08:00
|
|
|
#include "clang/Sema/ParseAST.h"
|
2009-04-19 13:30:08 +08:00
|
|
|
#include "Sema.h"
|
2009-04-20 23:53:59 +08:00
|
|
|
#include "clang/Sema/SemaConsumer.h"
|
Lazy deserialization of the declaration chains associated with
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
2009-04-22 06:25:48 +08:00
|
|
|
#include "clang/Sema/ExternalSemaSource.h"
|
2007-09-16 06:56:56 +08:00
|
|
|
#include "clang/AST/ASTConsumer.h"
|
2009-04-14 08:24:19 +08:00
|
|
|
#include "clang/AST/ExternalASTSource.h"
|
2008-08-11 12:54:23 +08:00
|
|
|
#include "clang/AST/Stmt.h"
|
2006-08-17 14:28:25 +08:00
|
|
|
#include "clang/Parse/Parser.h"
|
2009-04-19 13:30:08 +08:00
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
2006-08-17 14:28:25 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Public interface to the file
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-09-16 06:56:56 +08:00
|
|
|
/// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
|
2009-03-28 12:13:34 +08:00
|
|
|
/// the file is parsed. This inserts the parsed decls into the translation unit
|
|
|
|
/// held by Ctx.
|
2008-10-17 00:54:18 +08:00
|
|
|
///
|
2009-01-28 12:29:29 +08:00
|
|
|
void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
|
2009-04-15 00:27:31 +08:00
|
|
|
ASTContext &Ctx, bool PrintStats,
|
|
|
|
bool CompleteTranslationUnit) {
|
2007-09-16 06:56:56 +08:00
|
|
|
// Collect global stats on Decls/Stmts (until we have a module streamer).
|
|
|
|
if (PrintStats) {
|
|
|
|
Decl::CollectingStats(true);
|
|
|
|
Stmt::CollectingStats(true);
|
|
|
|
}
|
2009-01-28 12:29:29 +08:00
|
|
|
|
2009-04-15 00:27:31 +08:00
|
|
|
Sema S(PP, Ctx, *Consumer, CompleteTranslationUnit);
|
2008-05-27 12:23:47 +08:00
|
|
|
Parser P(PP, S);
|
2008-02-06 08:15:02 +08:00
|
|
|
PP.EnterMainSourceFile();
|
|
|
|
|
|
|
|
// Initialize the parser.
|
|
|
|
P.Initialize();
|
2007-09-16 06:56:56 +08:00
|
|
|
|
2009-03-28 12:13:34 +08:00
|
|
|
Consumer->Initialize(Ctx);
|
2007-09-16 06:56:56 +08:00
|
|
|
|
2009-04-20 23:53:59 +08:00
|
|
|
if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer))
|
|
|
|
SC->InitializeSema(S);
|
|
|
|
|
Lazy deserialization of the declaration chains associated with
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
2009-04-22 06:25:48 +08:00
|
|
|
if (ExternalASTSource *External = Ctx.getExternalSource()) {
|
|
|
|
if (ExternalSemaSource *ExternalSema =
|
|
|
|
dyn_cast<ExternalSemaSource>(External))
|
|
|
|
ExternalSema->InitializeSema(S);
|
|
|
|
|
|
|
|
External->StartTranslationUnit(Consumer);
|
|
|
|
}
|
2009-04-14 08:24:19 +08:00
|
|
|
|
2009-03-30 00:50:03 +08:00
|
|
|
Parser::DeclGroupPtrTy ADecl;
|
2008-05-20 08:43:19 +08:00
|
|
|
|
2008-02-06 08:15:02 +08:00
|
|
|
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.
|
2009-03-30 00:50:03 +08:00
|
|
|
if (ADecl)
|
|
|
|
Consumer->HandleTopLevelDecl(ADecl.getAsVal<DeclGroupRef>());
|
2008-02-06 08:15:02 +08:00
|
|
|
};
|
2008-07-03 02:32:45 +08:00
|
|
|
|
2009-03-28 12:13:34 +08:00
|
|
|
Consumer->HandleTranslationUnit(Ctx);
|
2007-10-27 03:46:17 +08:00
|
|
|
|
2007-09-16 06:56:56 +08:00
|
|
|
if (PrintStats) {
|
|
|
|
fprintf(stderr, "\nSTATISTICS:\n");
|
2008-02-06 08:15:02 +08:00
|
|
|
P.getActions().PrintStats();
|
2009-03-28 12:13:34 +08:00
|
|
|
Ctx.PrintStats();
|
2007-09-16 06:56:56 +08:00
|
|
|
Decl::PrintStats();
|
|
|
|
Stmt::PrintStats();
|
2007-11-03 14:24:16 +08:00
|
|
|
Consumer->PrintStats();
|
2007-09-16 06:56:56 +08:00
|
|
|
|
|
|
|
Decl::CollectingStats(false);
|
|
|
|
Stmt::CollectingStats(false);
|
|
|
|
}
|
|
|
|
}
|