diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-04-10 22:13:17 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-04-10 22:13:17 +0000 |
| commit | d959d753bc84c298aa9982752fc3335766b30b19 (patch) | |
| tree | bc8fb9e7da216088ca562788a180aebe0faaba56 /clang | |
| parent | e49adaf7f26509c0c5267e7a461b98f35ec78050 (diff) | |
| download | bcm5719-llvm-d959d753bc84c298aa9982752fc3335766b30b19.tar.gz bcm5719-llvm-d959d753bc84c298aa9982752fc3335766b30b19.zip | |
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.
llvm-svn: 68832
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/Lex/Preprocessor.h | 2 | ||||
| -rw-r--r-- | clang/lib/Frontend/PCHReader.cpp | 10 | ||||
| -rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 2 | ||||
| -rw-r--r-- | clang/test/PCH/variables.c | 3 | ||||
| -rw-r--r-- | clang/test/PCH/variables.h | 1 | ||||
| -rw-r--r-- | clang/tools/clang-cc/clang-cc.cpp | 16 |
6 files changed, 22 insertions, 12 deletions
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 0bf6126d587..656ebed8995 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -788,7 +788,7 @@ class PreprocessorFactory { public: virtual ~PreprocessorFactory(); virtual Preprocessor* CreatePreprocessor() = 0; - virtual bool FinishInitialization(Preprocessor *PP); + virtual bool FinishInitialization(Preprocessor *PP, bool usesPCH); }; } // end namespace clang diff --git a/clang/lib/Frontend/PCHReader.cpp b/clang/lib/Frontend/PCHReader.cpp index d5923086c7a..eaba610137d 100644 --- a/clang/lib/Frontend/PCHReader.cpp +++ b/clang/lib/Frontend/PCHReader.cpp @@ -271,11 +271,7 @@ bool PCHReader::ReadPreprocessorBlock() { } // 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 @@ bool PCHReader::ReadPCH(const std::string &FileName) { // 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; } diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index be47fcc8fe3..5735d017164 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -45,7 +45,7 @@ using namespace clang; PreprocessorFactory::~PreprocessorFactory() {} -bool PreprocessorFactory::FinishInitialization(Preprocessor *PP) { +bool PreprocessorFactory::FinishInitialization(Preprocessor *PP, bool UsesPCH) { return false; } diff --git a/clang/test/PCH/variables.c b/clang/test/PCH/variables.c index ffb9ec08c0e..aad40ceb916 100644 --- a/clang/test/PCH/variables.c +++ b/clang/test/PCH/variables.c @@ -8,3 +8,6 @@ double z; // expected-error{{redefinition}} //double VeryHappy; // FIXME: xpected-error{{redefinition}} + +int Q = A_MACRO_IN_THE_PCH; + diff --git a/clang/test/PCH/variables.h b/clang/test/PCH/variables.h index 4c5012d68ba..6bf82c44830 100644 --- a/clang/test/PCH/variables.h +++ b/clang/test/PCH/variables.h @@ -10,3 +10,4 @@ float z; #define MAKE_HAPPY(X) X##Happy int MAKE_HAPPY(Very); +#define A_MACRO_IN_THE_PCH 492 diff --git a/clang/tools/clang-cc/clang-cc.cpp b/clang/tools/clang-cc/clang-cc.cpp index a155ac8c06b..dfdc1953fea 100644 --- a/clang/tools/clang-cc/clang-cc.cpp +++ b/clang/tools/clang-cc/clang-cc.cpp @@ -1442,7 +1442,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI, /// 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 @@ static bool InitializePreprocessor(Preprocessor &PP, } } + // 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 @@ public: 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 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF, // 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 @@ int main(int argc, char **argv) { continue; if (ImplicitIncludePCH.empty() - && PPFactory.FinishInitialization(PP.get())) + && PPFactory.FinishInitialization(PP.get(), false)) continue; // Create the HTMLDiagnosticsClient if we are using one. Otherwise, |

