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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-01-28 12:29:29 +08:00
|
|
|
#include <llvm/ADT/OwningPtr.h>
|
2008-02-06 08:23:21 +08:00
|
|
|
#include "clang/Sema/ParseAST.h"
|
2007-09-16 06:56:56 +08:00
|
|
|
#include "clang/AST/ASTConsumer.h"
|
2008-08-11 12:54:23 +08:00
|
|
|
#include "clang/AST/Stmt.h"
|
2008-05-20 08:43:19 +08:00
|
|
|
#include "clang/AST/TranslationUnit.h"
|
2006-11-10 12:58:55 +08:00
|
|
|
#include "Sema.h"
|
2006-08-17 14:28:25 +08:00
|
|
|
#include "clang/Parse/Parser.h"
|
|
|
|
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 09:37:17 +08:00
|
|
|
/// the file is parsed. This inserts the parsed decls into TU.
|
2008-10-17 00:54:18 +08:00
|
|
|
///
|
2009-01-28 12:29:29 +08:00
|
|
|
void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
|
2009-03-28 09:37:17 +08:00
|
|
|
TranslationUnit &TU, bool PrintStats) {
|
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-03-28 09:37:17 +08:00
|
|
|
Sema S(PP, TU.getContext(), *Consumer);
|
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 10:18:25 +08:00
|
|
|
Consumer->Initialize(TU.getContext());
|
2007-09-16 06:56:56 +08:00
|
|
|
|
2008-02-06 08:15:02 +08:00
|
|
|
Parser::DeclTy *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.
|
2008-05-20 08:43:19 +08:00
|
|
|
if (ADecl) {
|
|
|
|
Decl* D = static_cast<Decl*>(ADecl);
|
|
|
|
Consumer->HandleTopLevelDecl(D);
|
|
|
|
}
|
2008-02-06 08:15:02 +08:00
|
|
|
};
|
2008-07-03 02:32:45 +08:00
|
|
|
|
2009-03-28 12:11:33 +08:00
|
|
|
Consumer->HandleTranslationUnit(TU.getContext());
|
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 09:37:17 +08:00
|
|
|
TU.getContext().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);
|
|
|
|
}
|
|
|
|
}
|