[cfe-commits] r68832 - in /cfe/trunk: include/clang/Lex/Preprocessor.h lib/Frontend/PCHReader.cpp lib/Lex/Preprocessor.cpp test/PCH/variables.c test/PCH/variables.h tools/clang-cc/clang-cc.cpp

Chris Lattner sabre at nondot.org
Fri Apr 10 15:13:17 PDT 2009


Author: lattner
Date: Fri Apr 10 17:13:17 2009
New Revision: 68832

URL: http://llvm.org/viewvc/llvm-project?rev=68832&view=rev
Log:
do a dance with predefines, and finally enable reading of macros from
PCH.  This works now, except for limitations not being able to do things
with identifiers.  The basic example in the testcase works though.

Modified:
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/test/PCH/variables.c
    cfe/trunk/test/PCH/variables.h
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=68832&r1=68831&r2=68832&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri Apr 10 17:13:17 2009
@@ -788,7 +788,7 @@
 public:
   virtual ~PreprocessorFactory();
   virtual Preprocessor* CreatePreprocessor() = 0;  
-  virtual bool FinishInitialization(Preprocessor *PP);
+  virtual bool FinishInitialization(Preprocessor *PP, bool usesPCH);
 };
   
 }  // end namespace clang

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=68832&r1=68831&r2=68832&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Apr 10 17:13:17 2009
@@ -271,11 +271,7 @@
       }
 
       // Finally, install the macro.
-      II = II;
-#if 0
-      // FIXME: Do this when predefines buffer is worked out.
       PP.setMacroInfo(II, MI);
-#endif
 
       // Remember that we saw this macro last so that we add the tokens that
       // form its body to it.
@@ -466,6 +462,12 @@
   // Load the translation unit declaration
   ReadDeclRecord(DeclOffsets[0], 0);
 
+  // If everything looks like it will be ok, then the PCH file load succeeded.
+  // Since the PCH file contains everything that is in the preprocessor's
+  // predefines buffer (and we validated that they are the same) clear out the
+  // predefines buffer so that it doesn't get processed again.
+  PP.setPredefines("");
+  
   return false;
 }
 

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=68832&r1=68831&r2=68832&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Fri Apr 10 17:13:17 2009
@@ -45,7 +45,7 @@
 
 PreprocessorFactory::~PreprocessorFactory() {}
 
-bool PreprocessorFactory::FinishInitialization(Preprocessor *PP) {
+bool PreprocessorFactory::FinishInitialization(Preprocessor *PP, bool UsesPCH) {
   return false;
 }
 

Modified: cfe/trunk/test/PCH/variables.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/variables.c?rev=68832&r1=68831&r2=68832&view=diff

==============================================================================
--- cfe/trunk/test/PCH/variables.c (original)
+++ cfe/trunk/test/PCH/variables.c Fri Apr 10 17:13:17 2009
@@ -8,3 +8,6 @@
 
 //double VeryHappy; // FIXME: xpected-error{{redefinition}}
 
+
+int Q = A_MACRO_IN_THE_PCH;
+

Modified: cfe/trunk/test/PCH/variables.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/variables.h?rev=68832&r1=68831&r2=68832&view=diff

==============================================================================
--- cfe/trunk/test/PCH/variables.h (original)
+++ cfe/trunk/test/PCH/variables.h Fri Apr 10 17:13:17 2009
@@ -10,3 +10,4 @@
 #define MAKE_HAPPY(X) X##Happy
 int MAKE_HAPPY(Very);
 
+#define A_MACRO_IN_THE_PCH 492

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=68832&r1=68831&r2=68832&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Fri Apr 10 17:13:17 2009
@@ -1442,7 +1442,7 @@
 ///
 static bool InitializePreprocessor(Preprocessor &PP,
                                    bool InitializeSourceMgr, 
-                                   const std::string &InFile) {
+                                   const std::string &InFile, bool UsesPCH) {
   FileManager &FileMgr = PP.getFileManager();
   
   // Figure out where to get and map in the main file.
@@ -1476,6 +1476,11 @@
     }
   }
 
+  // If the file is using PCH, then the PCH will include all the predefines, no
+  // need to install them now.
+  if (UsesPCH)
+    return false;
+  
   std::vector<char> PredefineBuffer;
   
   // Install things like __POWERPC__, __GNUC__, etc into the macro table.
@@ -1765,10 +1770,9 @@
     return PP.take();
   }
 
-  virtual bool FinishInitialization(Preprocessor *PP) {
-    if (InitializePreprocessor(*PP, InitializeSourceMgr, InFile)) {
+  virtual bool FinishInitialization(Preprocessor *PP, bool UsesPCH) {
+    if (InitializePreprocessor(*PP, InitializeSourceMgr, InFile, UsesPCH))
       return true;
-    }
     
     /// FIXME: PP can only handle one callback
     if (ProgAction != PrintPreprocessedInput) {
@@ -2097,7 +2101,7 @@
       // than earlier) because this initialization creates new source
       // location entries in the source manager, which must come after
       // the source location entries for the PCH file.
-      if (PPF.FinishInitialization(&PP))
+      if (PPF.FinishInitialization(&PP, true /*uses PCH*/))
         return;
     }
 
@@ -2308,7 +2312,7 @@
       continue;
 
     if (ImplicitIncludePCH.empty()
-        && PPFactory.FinishInitialization(PP.get()))
+        && PPFactory.FinishInitialization(PP.get(), false))
       continue;
 
     // Create the HTMLDiagnosticsClient if we are using one.  Otherwise,





More information about the cfe-commits mailing list