split function-like and object-like macro body parsing to make the

code more obvious.

llvm-svn: 39859
This commit is contained in:
Chris Lattner 2007-07-14 21:54:03 +00:00
parent e97cd7e65c
commit a3834341c5
1 changed files with 37 additions and 25 deletions

View File

@ -1789,12 +1789,23 @@ void Preprocessor::HandleDefineDirective(LexerToken &DefineTok,
Ident__VA_ARGS__->setIsPoisoned(false);
// Read the rest of the macro body.
if (MI->isObjectLike()) {
// Object-like macros are very simple, just read their body.
while (Tok.getKind() != tok::eom) {
MI->AddTokenToBody(Tok);
// Get the next token of the macro.
LexUnexpandedToken(Tok);
}
} else {
// Otherwise, read the body of a function-like macro. This has to validate
// the # (stringize) operator.
while (Tok.getKind() != tok::eom) {
MI->AddTokenToBody(Tok);
// Check C99 6.10.3.2p1: ensure that # operators are followed by macro
// parameters in function-like macro expansions.
if (Tok.getKind() != tok::hash || MI->isObjectLike()) {
if (Tok.getKind() != tok::hash) {
// Get the next token of the macro.
LexUnexpandedToken(Tok);
continue;
@ -1820,6 +1831,7 @@ void Preprocessor::HandleDefineDirective(LexerToken &DefineTok,
// Get the next token of the macro.
LexUnexpandedToken(Tok);
}
}
// Disable __VA_ARGS__ again.
Ident__VA_ARGS__->setIsPoisoned(true);