Simplify identifier lookup in raw mode, implementing Preprocessor/macro_fn_lparen_scan2.c.

llvm-svn: 38744
This commit is contained in:
Chris Lattner 2006-07-20 04:16:23 +00:00
parent 9100cff701
commit 0f1f50517b
4 changed files with 23 additions and 6 deletions

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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) */