diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Frontend/PCHReader.cpp | 6 | ||||
-rw-r--r-- | lib/Frontend/PCHWriter.cpp | 10 | ||||
-rw-r--r-- | lib/Lex/PPMacroExpansion.cpp | 8 | ||||
-rw-r--r-- | lib/Lex/Preprocessor.cpp | 3 |
4 files changed, 22 insertions, 5 deletions
diff --git a/lib/Frontend/PCHReader.cpp b/lib/Frontend/PCHReader.cpp index b916deaa69..fa6ad6f0a0 100644 --- a/lib/Frontend/PCHReader.cpp +++ b/lib/Frontend/PCHReader.cpp @@ -318,7 +318,11 @@ bool PCHReader::ReadPreprocessorBlock() { switch (RecType) { default: // Default behavior: ignore unknown records. break; - + case pch::PP_COUNTER_VALUE: + if (!Record.empty()) + PP.setCounterValue(Record[0]); + break; + case pch::PP_MACRO_OBJECT_LIKE: case pch::PP_MACRO_FUNCTION_LIKE: { IdentifierInfo *II = DecodeIdentifierInfo(Record[0]); diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index 6faf37fb29..2cf932ce9b 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -567,6 +567,13 @@ void PCHWriter::WritePreprocessor(const Preprocessor &PP) { RecordData Record; + // If the preprocessor __COUNTER__ value has been bumped, remember it. + if (PP.getCounterValue() != 0) { + Record.push_back(PP.getCounterValue()); + S.EmitRecord(pch::PP_COUNTER_VALUE, Record); + Record.clear(); + } + // Loop over all the macro definitions that are live at the end of the file, // emitting each to the PP section. // FIXME: Eventually we want to emit an index so that we can lazily load @@ -627,9 +634,6 @@ void PCHWriter::WritePreprocessor(const Preprocessor &PP) { } - // TODO: someday when PP supports __COUNTER__, emit a record for its value if - // non-zero. - S.ExitBlock(); } diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index b23311af19..797a5bf6f2 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -55,6 +55,7 @@ void Preprocessor::RegisterBuiltinMacros() { Ident__FILE__ = RegisterBuiltinMacro("__FILE__"); Ident__DATE__ = RegisterBuiltinMacro("__DATE__"); Ident__TIME__ = RegisterBuiltinMacro("__TIME__"); + Ident__COUNTER__ = RegisterBuiltinMacro("__COUNTER__"); Ident_Pragma = RegisterBuiltinMacro("_Pragma"); // GCC Extensions. @@ -557,6 +558,13 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { TmpBuffer[Len] = '"'; // Replace the newline with a quote. Tok.setKind(tok::string_literal); CreateString(TmpBuffer, Len+1, Tok, Tok.getLocation()); + } else if (II == Ident__COUNTER__) { + Diag(Tok, diag::ext_pp_counter); + + // __COUNTER__ expands to a simple numeric value. + sprintf(TmpBuffer, "%u", CounterValue++); + Tok.setKind(tok::numeric_constant); + CreateString(TmpBuffer, strlen(TmpBuffer), Tok, Tok.getLocation()); } else { assert(0 && "Unknown identifier!"); } diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 097b4542b6..2c9b0b937a 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -53,7 +53,8 @@ Preprocessor::Preprocessor(Diagnostic &diags, const LangOptions &opts, SourceMgr(SM), HeaderInfo(Headers), Identifiers(opts, IILookup), CurPPLexer(0), CurDirLookup(0), Callbacks(0) { ScratchBuf = new ScratchBuffer(SourceMgr); - + CounterValue = 0; // __COUNTER__ starts at 0. + // Clear stats. NumDirectives = NumDefined = NumUndefined = NumPragma = 0; NumIf = NumElse = NumEndif = 0; |