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