namespace clang {
-class ASTContext;
class SourceManager;
+class Preprocessor;
+class ASTContext;
/// \brief Writes a precompiled header containing the contents of a
/// translation unit.
unsigned NextTypeID;
void WriteSourceManagerBlock(SourceManager &SourceMgr);
+ void WritePreprocessor(Preprocessor &PP);
void WriteType(const Type *T);
void WriteTypesBlock(ASTContext &Context);
uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
PCHWriter(llvm::BitstreamWriter &S);
/// \brief Write a precompiled header for the given AST context.
- void WritePCH(ASTContext &Context);
+ void WritePCH(ASTContext &Context, Preprocessor &PP);
/// \brief Emit a source location.
void AddSourceLocation(SourceLocation Loc, RecordData &Record);
S.ExitBlock();
}
+/// \brief Writes the block containing the serialized form of the
+/// preprocessor.
+///
+void PCHWriter::WritePreprocessor(Preprocessor &PP) {
+}
+
+
/// \brief Write the representation of a type to the PCH stream.
void PCHWriter::WriteType(const Type *T) {
pch::ID &ID = TypeIDs[T];
PCHWriter::PCHWriter(llvm::BitstreamWriter &S)
: S(S), NextTypeID(pch::NUM_PREDEF_TYPE_IDS) { }
-void PCHWriter::WritePCH(ASTContext &Context) {
+void PCHWriter::WritePCH(ASTContext &Context, Preprocessor &PP) {
// Emit the file header.
S.Emit((unsigned)'C', 8);
S.Emit((unsigned)'P', 8);
// Write the remaining PCH contents.
S.EnterSubblock(pch::PCH_BLOCK_ID, 2);
WriteSourceManagerBlock(Context.getSourceManager());
+ WritePreprocessor(PP);
WriteTypesBlock(Context);
WriteDeclsBlock(Context);
S.ExitBlock();
Diagnostic &Diags,
const LangOptions &Features,
const CompileOptions &CompileOpts,
- const std::string& InFile,
- const std::string& OutFile);
+ const std::string &InFile,
+ const std::string &OutFile);
ASTConsumer* CreateHTMLPrinter(const std::string &OutFile, Diagnostic &D,
- Preprocessor *PP, PreprocessorFactory* PPF);
+ Preprocessor *PP, PreprocessorFactory *PPF);
ASTConsumer *CreateSerializationTest(Diagnostic &Diags,
- FileManager& FMgr);
+ FileManager &FMgr);
-ASTConsumer *CreateASTSerializer(const std::string& InFile,
- const std::string& EmitDir,
+ASTConsumer *CreateASTSerializer(const std::string &InFile,
+ const std::string &EmitDir,
Diagnostic &Diags);
-ASTConsumer *CreatePCHGenerator(Diagnostic &Diags,
- const LangOptions &Features,
- const std::string& InFile,
- const std::string& OutFile);
+ASTConsumer *CreatePCHGenerator(Preprocessor &PP,
+ const std::string &OutFile);
-ASTConsumer *CreateBlockRewriter(const std::string& InFile,
- const std::string& OutFile,
+ASTConsumer *CreateBlockRewriter(const std::string &InFile,
+ const std::string &OutFile,
Diagnostic &Diags,
const LangOptions &LangOpts);
ASTConsumer *CreateInheritanceViewer(const std::string& clsname);
-ASTConsumer* CreateAnalysisConsumer(Diagnostic &diags, Preprocessor* pp,
- PreprocessorFactory* ppf,
- const LangOptions& lopts,
- const std::string& output);
+ASTConsumer* CreateAnalysisConsumer(Diagnostic &diags, Preprocessor *pp,
+ PreprocessorFactory *ppf,
+ const LangOptions &lopts,
+ const std::string &output);
} // end clang namespace
//
//===----------------------------------------------------------------------===//
+#include "ASTConsumers.h"
#include "clang/Frontend/PCHWriter.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ASTConsumer.h"
+#include "clang/Lex/Preprocessor.h"
#include "llvm/Bitcode/BitstreamWriter.h"
#include "llvm/System/Path.h"
#include "llvm/Support/Compiler.h"
namespace {
class VISIBILITY_HIDDEN PCHGenerator : public ASTConsumer {
- Diagnostic &Diags;
+ Preprocessor &PP;
std::string OutFile;
public:
- explicit PCHGenerator(Diagnostic &Diags, const std::string &OutFile)
- : Diags(Diags), OutFile(OutFile) { }
+ explicit PCHGenerator(Preprocessor &PP, const std::string &OutFile)
+ : PP(PP), OutFile(OutFile) { }
virtual void HandleTranslationUnit(ASTContext &Ctx);
};
}
void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
- if (Diags.hasErrorOccurred())
+ if (PP.getDiagnostics().hasErrorOccurred())
return;
// Write the PCH contents into a buffer
PCHWriter Writer(Stream);
// Emit the PCH file
- Writer.WritePCH(Ctx);
+ Writer.WritePCH(Ctx, PP);
// Open up the PCH file.
std::string ErrMsg;
Out.flush();
}
-namespace clang {
-
-ASTConsumer *CreatePCHGenerator(Diagnostic &Diags,
- const LangOptions &Features,
- const std::string& InFile,
- const std::string& OutFile) {
- return new PCHGenerator(Diags, OutFile);
-}
-
+ASTConsumer *clang::CreatePCHGenerator(Preprocessor &PP,
+ const std::string &OutFile) {
+ return new PCHGenerator(PP, OutFile);
}
return CreateASTSerializer(InFile, OutputFile, Diag);
case GeneratePCH:
- return CreatePCHGenerator(Diag, LangOpts, InFile, OutputFile);
+ assert(PP && "Generate PCH doesn't work from serialized file yet");
+ return CreatePCHGenerator(*PP, OutputFile);
case RewriteObjC:
return CreateCodeRewriterTest(InFile, OutputFile, Diag, LangOpts);