diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-04-13 01:29:17 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-04-13 01:29:17 +0000 | 
| commit | 0af3ba17486de80987f8f22f5d418cef781a471c (patch) | |
| tree | b8fa061796bbaae27e8510974f1fbe5924ff483b /clang/lib/Lex | |
| parent | 0d6c061401d9b06cbcdc1cb3511d3b5332cee3d8 (diff) | |
| download | bcm5719-llvm-0af3ba17486de80987f8f22f5d418cef781a471c.tar.gz bcm5719-llvm-0af3ba17486de80987f8f22f5d418cef781a471c.zip  | |
implement the microsoft/gnu "__COUNTER__" macro: rdar://4329310
llvm-svn: 68933
Diffstat (limited to 'clang/lib/Lex')
| -rw-r--r-- | clang/lib/Lex/PPMacroExpansion.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 3 | 
2 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index b23311af192..797a5bf6f2c 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/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/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 097b4542b6e..2c9b0b937a2 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/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;  | 

