forked from OSchip/llvm-project
Simplify identifier lookup in raw mode, implementing Preprocessor/macro_fn_lparen_scan2.c.
llvm-svn: 38744
This commit is contained in:
parent
9100cff701
commit
0f1f50517b
|
@ -359,6 +359,10 @@ FinishIdentifier:
|
||||||
FormTokenWithChars(Result, CurPtr);
|
FormTokenWithChars(Result, CurPtr);
|
||||||
Result.SetKind(tok::identifier);
|
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
|
// Fill in Result.IdentifierInfo, looking up the identifier in the
|
||||||
// identifier table.
|
// identifier table.
|
||||||
PP.LookUpIdentifierInfo(Result, IdStart);
|
PP.LookUpIdentifierInfo(Result, IdStart);
|
||||||
|
|
|
@ -508,6 +508,15 @@ void MacroExpander::PasteTokens(LexerToken &Tok) {
|
||||||
++CurToken;
|
++CurToken;
|
||||||
Tok = Result;
|
Tok = Result;
|
||||||
} while (!isAtEnd() && (*MacroTokens)[CurToken].getKind() == tok::hashhash);
|
} 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
|
/// isNextTokenLParen - If the next token lexed will pop this macro off the
|
||||||
|
|
|
@ -971,12 +971,9 @@ IdentifierInfo *Preprocessor::LookUpIdentifierInfo(LexerToken &Identifier,
|
||||||
/// identifier. This callback looks up the identifier in the map and/or
|
/// 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').
|
/// potentially macro expands it or turns it into a named token (like 'for').
|
||||||
void Preprocessor::HandleIdentifier(LexerToken &Identifier) {
|
void Preprocessor::HandleIdentifier(LexerToken &Identifier) {
|
||||||
if (Identifier.getIdentifierInfo() == 0) {
|
assert(Identifier.getIdentifierInfo() &&
|
||||||
// If we are skipping tokens (because we are in a #if 0 block), there will
|
"Can't handle identifiers without identifier info!");
|
||||||
// be no identifier info, just return the token.
|
|
||||||
assert(isSkipping() && "Token isn't an identifier?");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
IdentifierInfo &II = *Identifier.getIdentifierInfo();
|
IdentifierInfo &II = *Identifier.getIdentifierInfo();
|
||||||
|
|
||||||
// If this identifier was poisoned, and if it was not produced from a macro
|
// If this identifier was poisoned, and if it was not produced from a macro
|
||||||
|
|
|
@ -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) */
|
||||||
|
|
Loading…
Reference in New Issue