[cfe-commits] r38744 - in /cfe/cfe/trunk: Lex/Lexer.cpp Lex/MacroExpander.cpp Lex/Preprocessor.cpp test/Preprocessor/macro_fn_lparen_scan2.c
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:24:16 PDT 2007
Author: sabre
Date: Wed Jul 11 11:24:16 2007
New Revision: 38744
URL: http://llvm.org/viewvc/llvm-project?rev=38744&view=rev
Log:
Simplify identifier lookup in raw mode, implementing Preprocessor/macro_fn_lparen_scan2.c.
Added:
cfe/cfe/trunk/test/Preprocessor/macro_fn_lparen_scan2.c (with props)
Modified:
cfe/cfe/trunk/Lex/Lexer.cpp
cfe/cfe/trunk/Lex/MacroExpander.cpp
cfe/cfe/trunk/Lex/Preprocessor.cpp
Modified: cfe/cfe/trunk/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Lexer.cpp?rev=38744&r1=38743&r2=38744&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/cfe/trunk/Lex/Lexer.cpp Wed Jul 11 11:24:16 2007
@@ -359,6 +359,10 @@
FormTokenWithChars(Result, CurPtr);
Result.SetKind(tok::identifier);
+ // If we are in raw mode, return this identifier raw. There is no need to
+ // look up identifier information or attempt to macro expand it.
+ if (LexingRawMode) return;
+
// Fill in Result.IdentifierInfo, looking up the identifier in the
// identifier table.
PP.LookUpIdentifierInfo(Result, IdStart);
Modified: cfe/cfe/trunk/Lex/MacroExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/MacroExpander.cpp?rev=38744&r1=38743&r2=38744&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/MacroExpander.cpp (original)
+++ cfe/cfe/trunk/Lex/MacroExpander.cpp Wed Jul 11 11:24:16 2007
@@ -508,6 +508,15 @@
++CurToken;
Tok = Result;
} while (!isAtEnd() && (*MacroTokens)[CurToken].getKind() == tok::hashhash);
+
+ // Now that we got the result token, it will be subject to expansion. Since
+ // token pasting re-lexes the result token in raw mode, identifier information
+ // isn't looked up. As such, if the result is an identifier, look up id info.
+ if (Tok.getKind() == tok::identifier) {
+ // Look up the identifier info for the token. We disabled identifier lookup
+ // by saying we're skipping contents, so we need to do this manually.
+ Tok.SetIdentifierInfo(PP.LookUpIdentifierInfo(Tok));
+ }
}
/// isNextTokenLParen - If the next token lexed will pop this macro off the
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38744&r1=38743&r2=38744&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:24:16 2007
@@ -971,12 +971,9 @@
/// identifier. This callback looks up the identifier in the map and/or
/// potentially macro expands it or turns it into a named token (like 'for').
void Preprocessor::HandleIdentifier(LexerToken &Identifier) {
- if (Identifier.getIdentifierInfo() == 0) {
- // If we are skipping tokens (because we are in a #if 0 block), there will
- // be no identifier info, just return the token.
- assert(isSkipping() && "Token isn't an identifier?");
- return;
- }
+ assert(Identifier.getIdentifierInfo() &&
+ "Can't handle identifiers without identifier info!");
+
IdentifierInfo &II = *Identifier.getIdentifierInfo();
// If this identifier was poisoned, and if it was not produced from a macro
Added: cfe/cfe/trunk/test/Preprocessor/macro_fn_lparen_scan2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/test/Preprocessor/macro_fn_lparen_scan2.c?rev=38744&view=auto
==============================================================================
--- cfe/cfe/trunk/test/Preprocessor/macro_fn_lparen_scan2.c (added)
+++ cfe/cfe/trunk/test/Preprocessor/macro_fn_lparen_scan2.c Wed Jul 11 11:24:16 2007
@@ -0,0 +1,7 @@
+// RUN: clang -E %s | grep 'FUNC (3+1);'
+
+#define F(a) a
+#define FUNC(a) (a+1)
+
+F(FUNC) FUNC (3); /* final token sequence is FUNC(3+1) */
+
Propchange: cfe/cfe/trunk/test/Preprocessor/macro_fn_lparen_scan2.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/cfe/trunk/test/Preprocessor/macro_fn_lparen_scan2.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
More information about the cfe-commits
mailing list