Go back to having the clang driver create ASTContext explicitly, passing

it to Sema/ASTStreamer (separating the lifetime of ASTContext from
the lifetime of Sema). One day it might be useful to consider creating
a context object implicitly if one isn't provided (using default arguments in
Sema's constructor). At this point, adding this convenience isn't necessary.

llvm-svn: 39346
This commit is contained in:
Steve Naroff 2007-02-28 19:32:13 +00:00
parent 38d31b47b0
commit 2c055d2b2b
9 changed files with 28 additions and 34 deletions

View File

@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/ASTStreamer.h"
#include "clang/AST/ASTContext.h"
#include "Sema.h"
#include "clang/Parse/Action.h"
#include "clang/Parse/Parser.h"
@ -23,8 +24,8 @@ namespace {
Parser P;
std::vector<Decl*> LastInGroupList;
public:
ASTStreamer(Preprocessor &pp, unsigned MainFileID)
: P(pp, *new Sema(pp, LastInGroupList)) {
ASTStreamer(Preprocessor &pp, ASTContext &ctxt, unsigned MainFileID)
: P(pp, *new Sema(pp, ctxt, LastInGroupList)) {
pp.EnterSourceFile(MainFileID, 0, true);
// Initialize the parser.
@ -78,7 +79,6 @@ Decl *ASTStreamer::ReadTopLevelDecl() {
}
void ASTStreamer::PrintStats() const {
static_cast<Sema &>(P.getActions()).PrintStats();
}
//===----------------------------------------------------------------------===//
@ -88,8 +88,9 @@ void ASTStreamer::PrintStats() const {
/// ASTStreamer_Init - Create an ASTStreamer with the specified preprocessor
/// and FileID.
ASTStreamerTy *llvm::clang::ASTStreamer_Init(Preprocessor &pp,
ASTContext &ctxt,
unsigned MainFileID) {
return new ASTStreamer(pp, MainFileID);
return new ASTStreamer(pp, ctxt, MainFileID);
}
/// ASTStreamer_ReadTopLevelDecl - Parse and return one top-level declaration. This

View File

@ -18,14 +18,8 @@
using namespace llvm;
using namespace clang;
Sema::Sema(Preprocessor &pp, std::vector<Decl*> &prevInGroup)
: PP(pp),
Context(*new ASTContext(pp.getTargetInfo(), pp.getIdentifierTable())),
CurFunctionDecl(0), LastInGroupList(prevInGroup) {
}
void Sema::PrintStats() {
Context.PrintStats();
Sema::Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup)
: PP(pp), Context(ctxt), CurFunctionDecl(0), LastInGroupList(prevInGroup) {
}
//===----------------------------------------------------------------------===//

View File

@ -47,15 +47,13 @@ class Sema : public Action {
/// ASTStreamer.
std::vector<Decl*> &LastInGroupList;
public:
Sema(Preprocessor &pp, std::vector<Decl*> &prevInGroup);
Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
const LangOptions &getLangOptions() const;
void Diag(SourceLocation Loc, unsigned DiagID,
const std::string &Msg = std::string());
void PrintStats();
//===--------------------------------------------------------------------===//
// Type Analysis / Processing: SemaType.cpp.
//

View File

@ -803,13 +803,15 @@ static void ParseFile(Preprocessor &PP, MinimalAction *PA, unsigned MainFileID){
//===----------------------------------------------------------------------===//
static void BuildASTs(Preprocessor &PP, unsigned MainFileID) {
ASTStreamerTy *Streamer = ASTStreamer_Init(PP, MainFileID);
ASTContext Context(PP.getTargetInfo(), PP.getIdentifierTable());
ASTStreamerTy *Streamer = ASTStreamer_Init(PP, Context, MainFileID);
while (ASTStreamer_ReadTopLevelDecl(Streamer))
/* keep reading */;
if (Stats) {
std::cerr << "\nSTATISTICS:\n";
ASTStreamer_PrintStats(Streamer);
Context.PrintStats();
}
ASTStreamer_Terminate(Streamer);
@ -860,7 +862,8 @@ static void PrintTypeDefDecl(TypedefDecl *TD) {
}
static void PrintASTs(Preprocessor &PP, unsigned MainFileID) {
ASTStreamerTy *Streamer = ASTStreamer_Init(PP, MainFileID);
ASTContext Context(PP.getTargetInfo(), PP.getIdentifierTable());
ASTStreamerTy *Streamer = ASTStreamer_Init(PP, Context, MainFileID);
while (Decl *D = ASTStreamer_ReadTopLevelDecl(Streamer)) {
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
@ -875,6 +878,7 @@ static void PrintASTs(Preprocessor &PP, unsigned MainFileID) {
if (Stats) {
std::cerr << "\nSTATISTICS:\n";
ASTStreamer_PrintStats(Streamer);
Context.PrintStats();
}
ASTStreamer_Terminate(Streamer);

View File

@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/ASTStreamer.h"
#include "clang/AST/ASTContext.h"
#include "Sema.h"
#include "clang/Parse/Action.h"
#include "clang/Parse/Parser.h"
@ -23,8 +24,8 @@ namespace {
Parser P;
std::vector<Decl*> LastInGroupList;
public:
ASTStreamer(Preprocessor &pp, unsigned MainFileID)
: P(pp, *new Sema(pp, LastInGroupList)) {
ASTStreamer(Preprocessor &pp, ASTContext &ctxt, unsigned MainFileID)
: P(pp, *new Sema(pp, ctxt, LastInGroupList)) {
pp.EnterSourceFile(MainFileID, 0, true);
// Initialize the parser.
@ -78,7 +79,6 @@ Decl *ASTStreamer::ReadTopLevelDecl() {
}
void ASTStreamer::PrintStats() const {
static_cast<Sema &>(P.getActions()).PrintStats();
}
//===----------------------------------------------------------------------===//
@ -88,8 +88,9 @@ void ASTStreamer::PrintStats() const {
/// ASTStreamer_Init - Create an ASTStreamer with the specified preprocessor
/// and FileID.
ASTStreamerTy *llvm::clang::ASTStreamer_Init(Preprocessor &pp,
ASTContext &ctxt,
unsigned MainFileID) {
return new ASTStreamer(pp, MainFileID);
return new ASTStreamer(pp, ctxt, MainFileID);
}
/// ASTStreamer_ReadTopLevelDecl - Parse and return one top-level declaration. This

View File

@ -18,14 +18,8 @@
using namespace llvm;
using namespace clang;
Sema::Sema(Preprocessor &pp, std::vector<Decl*> &prevInGroup)
: PP(pp),
Context(*new ASTContext(pp.getTargetInfo(), pp.getIdentifierTable())),
CurFunctionDecl(0), LastInGroupList(prevInGroup) {
}
void Sema::PrintStats() {
Context.PrintStats();
Sema::Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup)
: PP(pp), Context(ctxt), CurFunctionDecl(0), LastInGroupList(prevInGroup) {
}
//===----------------------------------------------------------------------===//

View File

@ -47,15 +47,13 @@ class Sema : public Action {
/// ASTStreamer.
std::vector<Decl*> &LastInGroupList;
public:
Sema(Preprocessor &pp, std::vector<Decl*> &prevInGroup);
Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
const LangOptions &getLangOptions() const;
void Diag(SourceLocation Loc, unsigned DiagID,
const std::string &Msg = std::string());
void PrintStats();
//===--------------------------------------------------------------------===//
// Type Analysis / Processing: SemaType.cpp.
//

View File

@ -17,6 +17,7 @@
namespace llvm {
namespace clang {
class Preprocessor;
class ASTContext;
class Decl;
/// ASTStreamerTy - This is an opaque type used to reference ASTStreamer
@ -25,7 +26,8 @@ namespace clang {
/// ASTStreamer_Init - Create an ASTStreamer with the specified ASTContext
/// and FileID.
ASTStreamerTy *ASTStreamer_Init(Preprocessor &pp, unsigned MainFileID);
ASTStreamerTy *ASTStreamer_Init(Preprocessor &pp, ASTContext &ctxt,
unsigned MainFileID);
/// ASTStreamer_ReadTopLevelDecl - Parse and return one top-level declaration.
/// This returns null at end of file.

View File

@ -17,6 +17,7 @@
namespace llvm {
namespace clang {
class Preprocessor;
class ASTContext;
class Decl;
/// ASTStreamerTy - This is an opaque type used to reference ASTStreamer
@ -25,7 +26,8 @@ namespace clang {
/// ASTStreamer_Init - Create an ASTStreamer with the specified ASTContext
/// and FileID.
ASTStreamerTy *ASTStreamer_Init(Preprocessor &pp, unsigned MainFileID);
ASTStreamerTy *ASTStreamer_Init(Preprocessor &pp, ASTContext &ctxt,
unsigned MainFileID);
/// ASTStreamer_ReadTopLevelDecl - Parse and return one top-level declaration.
/// This returns null at end of file.