[cfe-commits] r39859 - /cfe/trunk/Lex/Preprocessor.cpp
Chris Lattner
sabre at nondot.org
Sat Jul 14 14:54:04 PDT 2007
Author: lattner
Date: Sat Jul 14 16:54:03 2007
New Revision: 39859
URL: http://llvm.org/viewvc/llvm-project?rev=39859&view=rev
Log:
split function-like and object-like macro body parsing to make the
code more obvious.
Modified:
cfe/trunk/Lex/Preprocessor.cpp
Modified: cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Preprocessor.cpp?rev=39859&r1=39858&r2=39859&view=diff
==============================================================================
--- cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/Lex/Preprocessor.cpp Sat Jul 14 16:54:03 2007
@@ -1789,36 +1789,48 @@
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.
More information about the cfe-commits
mailing list