aboutsummaryrefslogtreecommitdiff
path: root/Lex/Preprocessor.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-07-14 21:54:03 +0000
committerChris Lattner <sabre@nondot.org>2007-07-14 21:54:03 +0000
commitb5e240fa9e852b758032b28488a083c546cf6123 (patch)
tree3f62f355d91e09e81eef6ad2d4d8026066f7ef99 /Lex/Preprocessor.cpp
parentd5e0d9854c9e400ecf729e1023cd331f5ebe1355 (diff)
split function-like and object-like macro body parsing to make the
code more obvious. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39859 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Lex/Preprocessor.cpp')
-rw-r--r--Lex/Preprocessor.cpp60
1 files changed, 36 insertions, 24 deletions
diff --git a/Lex/Preprocessor.cpp b/Lex/Preprocessor.cpp
index d18a2f9813..795230120d 100644
--- a/Lex/Preprocessor.cpp
+++ b/Lex/Preprocessor.cpp
@@ -1789,36 +1789,48 @@ void Preprocessor::HandleDefineDirective(LexerToken &DefineTok,
Ident__VA_ARGS__->setIsPoisoned(false);
// Read the rest of the macro body.
- 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 (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);
- continue;
}
- // Get the next token of the macro.
- LexUnexpandedToken(Tok);
-
- // Not a macro arg identifier?
- if (!Tok.getIdentifierInfo() ||
- MI->getArgumentNum(Tok.getIdentifierInfo()) == -1) {
- Diag(Tok, diag::err_pp_stringize_not_parameter);
- delete MI;
+ } 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) {
+ // Get the next token of the macro.
+ LexUnexpandedToken(Tok);
+ continue;
+ }
- // Disable __VA_ARGS__ again.
- Ident__VA_ARGS__->setIsPoisoned(true);
- return;
- }
-
- // Things look ok, add the param name token to the macro.
- MI->AddTokenToBody(Tok);
+ // Get the next token of the macro.
+ LexUnexpandedToken(Tok);
+
+ // Not a macro arg identifier?
+ if (!Tok.getIdentifierInfo() ||
+ MI->getArgumentNum(Tok.getIdentifierInfo()) == -1) {
+ Diag(Tok, diag::err_pp_stringize_not_parameter);
+ delete MI;
+
+ // Disable __VA_ARGS__ again.
+ Ident__VA_ARGS__->setIsPoisoned(true);
+ return;
+ }
+
+ // Things look ok, add the param name token to the macro.
+ MI->AddTokenToBody(Tok);
- // Get the next token of the macro.
- LexUnexpandedToken(Tok);
+ // Get the next token of the macro.
+ LexUnexpandedToken(Tok);
+ }
}
// Disable __VA_ARGS__ again.