summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-07-20 04:16:23 +0000
committerChris Lattner <sabre@nondot.org>2006-07-20 04:16:23 +0000
commit0f1f50517b8a921c75e398b055726568e6d40d19 (patch)
treed0756ac89f342f3be4bdd83598a4d24422df766f
parent9100cff7014d619fd5d3e9ef40018ee80f2a27a8 (diff)
downloadbcm5719-llvm-0f1f50517b8a921c75e398b055726568e6d40d19.tar.gz
bcm5719-llvm-0f1f50517b8a921c75e398b055726568e6d40d19.zip
Simplify identifier lookup in raw mode, implementing Preprocessor/macro_fn_lparen_scan2.c.
llvm-svn: 38744
-rw-r--r--clang/Lex/Lexer.cpp4
-rw-r--r--clang/Lex/MacroExpander.cpp9
-rw-r--r--clang/Lex/Preprocessor.cpp9
-rw-r--r--clang/test/Preprocessor/macro_fn_lparen_scan2.c7
4 files changed, 23 insertions, 6 deletions
diff --git a/clang/Lex/Lexer.cpp b/clang/Lex/Lexer.cpp
index a9905f33916..81ccbca7b83 100644
--- a/clang/Lex/Lexer.cpp
+++ b/clang/Lex/Lexer.cpp
@@ -359,6 +359,10 @@ FinishIdentifier:
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);
diff --git a/clang/Lex/MacroExpander.cpp b/clang/Lex/MacroExpander.cpp
index d68e36f45e1..d65448759b6 100644
--- a/clang/Lex/MacroExpander.cpp
+++ b/clang/Lex/MacroExpander.cpp
@@ -508,6 +508,15 @@ void MacroExpander::PasteTokens(LexerToken &Tok) {
++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
diff --git a/clang/Lex/Preprocessor.cpp b/clang/Lex/Preprocessor.cpp
index f302b677097..1a6a620dd56 100644
--- a/clang/Lex/Preprocessor.cpp
+++ b/clang/Lex/Preprocessor.cpp
@@ -971,12 +971,9 @@ IdentifierInfo *Preprocessor::LookUpIdentifierInfo(LexerToken &Identifier,
/// 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
diff --git a/clang/test/Preprocessor/macro_fn_lparen_scan2.c b/clang/test/Preprocessor/macro_fn_lparen_scan2.c
new file mode 100644
index 00000000000..38c0b5c35d0
--- /dev/null
+++ b/clang/test/Preprocessor/macro_fn_lparen_scan2.c
@@ -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) */
+
OpenPOWER on IntegriCloud