]> granicus.if.org Git - clang/commitdiff
emit tokens, constify the Preprocessor passed down into PCH writer.
authorChris Lattner <sabre@nondot.org>
Fri, 10 Apr 2009 18:08:30 +0000 (18:08 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 10 Apr 2009 18:08:30 +0000 (18:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68798 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/PCHWriter.h
lib/Frontend/PCHWriter.cpp
tools/clang-cc/ASTConsumers.h
tools/clang-cc/GeneratePCH.cpp

index a560857be217a319411779ac0b802f422046838b..41aa91ddf196e3f80b6f1a227ebd00d4bc124140 100644 (file)
@@ -77,7 +77,7 @@ class PCHWriter {
   pch::TypeID NextTypeID;
 
   void WriteSourceManagerBlock(SourceManager &SourceMgr);
-  void WritePreprocessor(Preprocessor &PP);
+  void WritePreprocessor(const Preprocessor &PP);
   void WriteType(const Type *T);
   void WriteTypesBlock(ASTContext &Context);
   uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);
@@ -92,7 +92,7 @@ public:
   PCHWriter(llvm::BitstreamWriter &S);
   
   /// \brief Write a precompiled header for the given AST context.
-  void WritePCH(ASTContext &Context, Preprocessor &PP);
+  void WritePCH(ASTContext &Context, const Preprocessor &PP);
 
   /// \brief Emit a source location.
   void AddSourceLocation(SourceLocation Loc, RecordData &Record);
index 05447dcd6ac8f5f369b97e0c05bbf3209083e5f4..255ce8bf8d77b728a3ab04f6b61068c56919f6de 100644 (file)
@@ -479,7 +479,7 @@ void PCHWriter::WriteSourceManagerBlock(SourceManager &SourceMgr) {
 /// \brief Writes the block containing the serialized form of the
 /// preprocessor.
 ///
-void PCHWriter::WritePreprocessor(Preprocessor &PP) {
+void PCHWriter::WritePreprocessor(const Preprocessor &PP) {
   // Enter the preprocessor block.
   S.EnterSubblock(pch::PREPROCESSOR_BLOCK_ID, 3);
   
@@ -527,7 +527,29 @@ void PCHWriter::WritePreprocessor(Preprocessor &PP) {
     S.EmitRecord(Code, Record);
     Record.clear();
 
-    // FIXME: Emit the tokens array.
+    // Emit the tokens array.
+    for (unsigned TokNo = 0, e = MI->getNumTokens(); TokNo != e; ++TokNo) {
+      // Note that we know that the preprocessor does not have any annotation
+      // tokens in it because they are created by the parser, and thus can't be
+      // in a macro definition.
+      const Token &Tok = MI->getReplacementToken(TokNo);
+      
+      Record.push_back(Tok.getLocation().getRawEncoding());
+      Record.push_back(Tok.getLength());
+
+      // FIXME: Output the identifier Info ID #!
+      // FIXME: When reading literal tokens, reconstruct the literal pointer if
+      // it is needed.
+      Record.push_back((intptr_t)Tok.getIdentifierInfo());
+      
+      // FIXME: Should translate token kind to a stable encoding.
+      Record.push_back(Tok.getKind());
+      // FIXME: Should translate token flags to a stable encoding.
+      Record.push_back(Tok.getFlags());
+      
+      S.EmitRecord(pch::PP_TOKEN, Record);
+      Record.clear();
+    }
     
   }
   
@@ -719,7 +741,7 @@ void PCHWriter::WriteDeclsBlock(ASTContext &Context) {
 PCHWriter::PCHWriter(llvm::BitstreamWriter &S) 
   : S(S), NextTypeID(pch::NUM_PREDEF_TYPE_IDS) { }
 
-void PCHWriter::WritePCH(ASTContext &Context, Preprocessor &PP) {
+void PCHWriter::WritePCH(ASTContext &Context, const Preprocessor &PP) {
   // Emit the file header.
   S.Emit((unsigned)'C', 8);
   S.Emit((unsigned)'P', 8);
index d433d05b02f93a32499b78fcb6765d1fc84cd969..7c37266e46e8fc858a674f6f4e0938f368ce305f 100644 (file)
@@ -68,7 +68,7 @@ ASTConsumer *CreateASTSerializer(const std::string &InFile,
                                  const std::string &EmitDir,
                                  Diagnostic &Diags);
   
-ASTConsumer *CreatePCHGenerator(Preprocessor &PP,
+ASTConsumer *CreatePCHGenerator(const Preprocessor &PP,
                                 const std::string &OutFile);
 
 ASTConsumer *CreateBlockRewriter(const std::string &InFile,
index a850c582e8164fabfa891b6ddc156f43b4cec2d2..9b8651408678b472037f0a9c16cda3b10a46ed9d 100644 (file)
@@ -29,11 +29,11 @@ using namespace llvm;
 
 namespace {
   class VISIBILITY_HIDDEN PCHGenerator : public ASTConsumer {
-    Preprocessor &PP;
+    const Preprocessor &PP;
     std::string OutFile;
 
   public:
-    explicit PCHGenerator(Preprocessor &PP, const std::string &OutFile)
+    explicit PCHGenerator(const Preprocessor &PP, const std::string &OutFile)
       : PP(PP), OutFile(OutFile) { }
 
     virtual void HandleTranslationUnit(ASTContext &Ctx);
@@ -68,7 +68,7 @@ void PCHGenerator::HandleTranslationUnit(ASTContext &Ctx) {
   Out.flush();
 }
 
-ASTConsumer *clang::CreatePCHGenerator(Preprocessor &PP,
+ASTConsumer *clang::CreatePCHGenerator(const Preprocessor &PP,
                                        const std::string &OutFile) {
   return new PCHGenerator(PP, OutFile);
 }