public:
ASTDumper() : DeclPrinter() {}
- void Initialize(ASTContext &Context, unsigned MainFileID) {
+ void Initialize(ASTContext &Context) {
SM = &Context.getSourceManager();
}
class ASTViewer : public ASTConsumer {
SourceManager *SM;
public:
- void Initialize(ASTContext &Context, unsigned MainFileID) {
+ void Initialize(ASTContext &Context) {
SM = &Context.getSourceManager();
}
class LivenessVisitor : public CFGVisitor {
SourceManager *SM;
public:
- virtual void Initialize(ASTContext &Context, unsigned MainFileID) {
+ virtual void Initialize(ASTContext &Context) {
SM = &Context.getSourceManager();
}
ASTContext *Ctx;
public:
DeadStoreVisitor(Diagnostic &diags) : Diags(diags) {}
- virtual void Initialize(ASTContext &Context, unsigned MainFileID) {
+ virtual void Initialize(ASTContext &Context) {
Ctx = &Context;
}
ASTContext *Ctx;
public:
UninitValsVisitor(Diagnostic &diags) : Diags(diags) {}
- virtual void Initialize(ASTContext &Context, unsigned MainFileID) {
+ virtual void Initialize(ASTContext &Context) {
Ctx = &Context;
}
LLVMEmitter(Diagnostic &diags, const LangOptions &LO)
: Diags(diags)
, Features(LO) {}
- virtual void Initialize(ASTContext &Context, unsigned MainFileID) {
+ virtual void Initialize(ASTContext &Context) {
Ctx = &Context;
M = new llvm::Module("foo");
M->setTargetTriple(Ctx->Target.getTargetTriple());
const LangOptions &LO)
: Diags(diags), TU(LO), FName(F) {}
- virtual void Initialize(ASTContext &Context, unsigned MainFileID) {
+ virtual void Initialize(ASTContext &Context) {
TU.setContext(&Context);
}
}
}
-/// FindExpectedDiags - Lex the file to finds all of the expected errors and
-/// warnings.
-static void FindExpectedDiags(Preprocessor &PP, unsigned MainFileID,
+/// FindExpectedDiags - Lex the main source file to find all of the
+// expected errors and warnings.
+static void FindExpectedDiags(Preprocessor &PP,
DiagList &ExpectedErrors,
DiagList &ExpectedWarnings) {
// Return comments as tokens, this is how we find expected diagnostics.
PP.SetCommentRetentionState(true, true);
// Enter the cave.
- PP.EnterMainSourceFile(MainFileID);
+ PP.EnterMainSourceFile();
// Turn off all warnings from relexing or preprocessing.
PP.getDiagnostics().setWarnOnExtensions(false);
/// CheckASTConsumer - Implement diagnostic checking for AST consumers.
-bool clang::CheckASTConsumer(Preprocessor &PP, unsigned MainFileID,
- ASTConsumer* C) {
+bool clang::CheckASTConsumer(Preprocessor &PP, ASTConsumer* C) {
+
// Parse the AST and run the consumer, ultimately deleting C.
- ParseAST(PP, MainFileID, C);
+ ParseAST(PP, C);
// Gather the set of expected diagnostics.
DiagList ExpectedErrors, ExpectedWarnings;
- FindExpectedDiags(PP, MainFileID, ExpectedErrors, ExpectedWarnings);
+ FindExpectedDiags(PP, ExpectedErrors, ExpectedWarnings);
// Check that the expected diagnostics occurred.
return CheckResults(PP, ExpectedErrors, ExpectedWarnings);
/// DoPrintPreprocessedInput - This implements -E mode.
///
-void clang::DoPrintPreprocessedInput(unsigned MainFileID, Preprocessor &PP) {
+void clang::DoPrintPreprocessedInput(Preprocessor &PP) {
// Inform the preprocessor whether we want it to retain comments or not, due
// to -C or -CC.
PP.SetCommentRetentionState(EnableCommentOutput, EnableMacroCommentOutput);
// After we have configured the preprocessor, enter the main file.
// Start parsing the specified input file.
- PP.EnterMainSourceFile(MainFileID);
+ PP.EnterMainSourceFile();
// Consume all of the tokens that come from the predefines buffer. Those
// should not be emitted into the output and are guaranteed to be at the
static const int OBJC_ABI_VERSION =7 ;
public:
- void Initialize(ASTContext &context, unsigned mainFileID) {
+ void Initialize(ASTContext &context) {
Context = &context;
SM = &Context->getSourceManager();
MsgSendFunctionDecl = 0;
SuperStructDecl = 0;
// Get the ID and start/end of the main file.
- MainFileID = mainFileID;
+ MainFileID = SM->getMainFileID();
const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID);
MainFileStart = MainBuf->getBufferStart();
MainFileEnd = MainBuf->getBufferEnd();
"extern Protocol *objc_getProtocol(const char *);\n"
"#include <objc/objc.h>\n";
- Rewrite.InsertText(SourceLocation::getFileLoc(mainFileID, 0),
+ Rewrite.InsertText(SourceLocation::getFileLoc(MainFileID, 0),
s, strlen(s));
}
~SerializationTest();
- virtual void Initialize(ASTContext& context, unsigned) {
+ virtual void Initialize(ASTContext& context) {
TU.setContext(&context);
}
// Basic Parser driver
//===----------------------------------------------------------------------===//
-static void ParseFile(Preprocessor &PP, MinimalAction *PA, unsigned MainFileID){
+static void ParseFile(Preprocessor &PP, MinimalAction *PA){
Parser P(PP, *PA);
- PP.EnterMainSourceFile(MainFileID);
+ PP.EnterMainSourceFile();
// Parsing the specified input file.
P.ParseTranslationUnit();
case DumpTokens: { // Token dump mode.
Token Tok;
// Start parsing the specified input file.
- PP.EnterMainSourceFile(MainFileID);
+ PP.EnterMainSourceFile();
do {
PP.Lex(Tok);
PP.DumpToken(Tok, true);
case RunPreprocessorOnly: { // Just lex as fast as we can, no output.
Token Tok;
// Start parsing the specified input file.
- PP.EnterMainSourceFile(MainFileID);
+ PP.EnterMainSourceFile();
do {
PP.Lex(Tok);
} while (Tok.isNot(tok::eof));
}
case PrintPreprocessedInput: // -E mode.
- DoPrintPreprocessedInput(MainFileID, PP);
+ DoPrintPreprocessedInput(PP);
ClearSourceMgr = true;
break;
case ParseNoop: // -parse-noop
- ParseFile(PP, new MinimalAction(PP.getIdentifierTable()), MainFileID);
+ ParseFile(PP, new MinimalAction(PP.getIdentifierTable()));
ClearSourceMgr = true;
break;
case ParsePrintCallbacks:
- ParseFile(PP, CreatePrintParserActionsAction(PP.getIdentifierTable()),
- MainFileID);
+ ParseFile(PP, CreatePrintParserActionsAction(PP.getIdentifierTable()));
ClearSourceMgr = true;
break;
if (Consumer) {
if (VerifyDiagnostics)
- exit(CheckASTConsumer(PP, MainFileID, Consumer));
+ exit(CheckASTConsumer(PP, Consumer));
// This deletes Consumer.
- ParseAST(PP, MainFileID, Consumer, Stats);
+ ParseAST(PP, Consumer, Stats);
}
if (Stats) {
exit (1);
}
- // FIXME: only work on consumers that do not require MainFileID.
- Consumer->Initialize(*TU->getContext(), 0);
+ Consumer->Initialize(*TU->getContext());
for (TranslationUnit::iterator I=TU->begin(), E=TU->end(); I!=E; ++I)
Consumer->HandleTopLevelDecl(*I);
class SourceManager;
/// DoPrintPreprocessedInput - Implement -E mode.
-void DoPrintPreprocessedInput(unsigned MainFileID, Preprocessor &PP);
+void DoPrintPreprocessedInput(Preprocessor &PP);
/// CreatePrintParserActionsAction - Return the actions implementation that
/// implements the -parse-print-callbacks option.
MinimalAction *CreatePrintParserActionsAction(IdentifierTable &);
/// EmitLLVMFromASTs - Implement -emit-llvm, which generates llvm IR from C.
-void EmitLLVMFromASTs(Preprocessor &PP, unsigned MainFileID,
- bool PrintStats);
+void EmitLLVMFromASTs(Preprocessor &PP, bool PrintStats);
/// CheckASTConsumer - Implement diagnostic checking for AST consumers.
-bool CheckASTConsumer(Preprocessor &PP, unsigned MainFileID, ASTConsumer* C);
+bool CheckASTConsumer(Preprocessor &PP, ASTConsumer* C);
} // end namespace clang
/// EnterMainSourceFile - Enter the specified FileID as the main source file,
/// which implicitly adds the builting defines etc.
-void Preprocessor::EnterMainSourceFile(unsigned MainFileID) {
+void Preprocessor::EnterMainSourceFile() {
+
+ unsigned MainFileID = SourceMgr.getMainFileID();
+
// Enter the main file source buffer.
EnterSourceFile(MainFileID, 0);
class ASTStreamer {
Parser P;
public:
- ASTStreamer(Preprocessor &pp, ASTContext &ctxt, unsigned MainFileID)
+ ASTStreamer(Preprocessor &pp, ASTContext &ctxt)
: P(pp, *new Sema(pp, ctxt)) {
- pp.EnterMainSourceFile(MainFileID);
+
+ pp.EnterMainSourceFile();
// Initialize the parser.
P.Initialize();
/// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
/// the file is parsed. This takes ownership of the ASTConsumer and
/// ultimately deletes it.
-void clang::ParseAST(Preprocessor &PP, unsigned MainFileID,
- ASTConsumer *Consumer, bool PrintStats) {
+void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
// Collect global stats on Decls/Stmts (until we have a module streamer).
if (PrintStats) {
Decl::CollectingStats(true);
ASTContext Context(PP.getSourceManager(), PP.getTargetInfo(),
PP.getIdentifierTable(), PP.getSelectorTable());
- ASTStreamer Streamer(PP, Context, MainFileID);
+ ASTStreamer Streamer(PP, Context);
- Consumer->Initialize(Context, MainFileID);
+ Consumer->Initialize(Context);
while (Decl *D = Streamer.ReadTopLevelDecl())
Consumer->HandleTopLevelDecl(D);
virtual ~ASTConsumer();
/// Initialize - This is called to initialize the consumer, providing the
- /// ASTContext and the file ID of the primary file.
- virtual void Initialize(ASTContext &Context, unsigned MainFileID) {}
+ /// ASTContext.
+ virtual void Initialize(ASTContext &Context) {}
/// HandleTopLevelDecl - Handle the specified top-level declaration. This is
/// called by HandleTopLevelDeclaration to process every top-level Decl*.
/// EnterMainSourceFile - Enter the specified FileID as the main source file,
/// which implicitly adds the builtin defines etc.
- void EnterMainSourceFile(unsigned CurFileID);
-
+ void EnterMainSourceFile();
/// EnterSourceFile - Add a source file to the top of the include stack and
/// start lexing tokens from it instead of the current buffer. If isMainFile
/// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
/// the file is parsed. This takes ownership of the ASTConsumer and
/// ultimately deletes it.
- void ParseAST(Preprocessor &pp, unsigned MainFileID,
- ASTConsumer *C, bool PrintStats = false);
+ void ParseAST(Preprocessor &pp, ASTConsumer *C, bool PrintStats = false);
} // end namespace clang
#endif