r179064 - Recognize function-like macro usages without semicolon in declaration context.
Alexander Kornienko
alexfh at google.com
Mon Apr 8 15:16:06 PDT 2013
Author: alexfh
Date: Mon Apr 8 17:16:06 2013
New Revision: 179064
URL: http://llvm.org/viewvc/llvm-project?rev=179064&view=rev
Log:
Recognize function-like macro usages without semicolon in declaration context.
Summary:
Preserve line breaks after function-like macro usages without
semicolon, e.g.:
QQQ(xxx)
class X {
};
Reviewers: djasper, klimek
Reviewed By: djasper
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D638
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=179064&r1=179063&r2=179064&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Apr 8 17:16:06 2013
@@ -71,7 +71,7 @@ public:
}
private:
- bool eof() { return Token.NewlinesBefore > 0 && Token.HasUnescapedNewline; }
+ bool eof() { return Token.HasUnescapedNewline; }
FormatToken createEOF() {
FormatToken FormatTok;
@@ -262,7 +262,6 @@ void UnwrappedLineParser::parsePPUnknown
void UnwrappedLineParser::parseStructuralElement() {
assert(!FormatTok.Tok.is(tok::l_brace));
- int TokenNumber = 0;
switch (FormatTok.Tok.getKind()) {
case tok::at:
nextToken();
@@ -297,7 +296,6 @@ void UnwrappedLineParser::parseStructura
return;
case tok::kw_inline:
nextToken();
- TokenNumber++;
if (FormatTok.Tok.is(tok::kw_namespace)) {
parseNamespace();
return;
@@ -347,7 +345,6 @@ void UnwrappedLineParser::parseStructura
break;
}
do {
- ++TokenNumber;
switch (FormatTok.Tok.getKind()) {
case tok::at:
nextToken();
@@ -384,9 +381,20 @@ void UnwrappedLineParser::parseStructura
return;
case tok::identifier:
nextToken();
- if (TokenNumber == 1 && FormatTok.Tok.is(tok::colon)) {
- parseLabel();
- return;
+ if (Line->Tokens.size() == 1) {
+ if (FormatTok.Tok.is(tok::colon)) {
+ parseLabel();
+ return;
+ }
+ // Recognize function-like macro usages without trailing semicolon in
+ // declaration context.
+ if (FormatTok.Tok.is(tok::l_paren)) {
+ parseParens();
+ if (Line->MustBeDeclaration && FormatTok.HasUnescapedNewline) {
+ addUnwrappedLine();
+ return;
+ }
+ }
}
break;
case tok::equal:
@@ -820,8 +828,7 @@ void UnwrappedLineParser::readToken() {
do {
FormatTok = Tokens->getNextToken();
while (!Line->InPPDirective && FormatTok.Tok.is(tok::hash) &&
- ((FormatTok.NewlinesBefore > 0 && FormatTok.HasUnescapedNewline) ||
- FormatTok.IsFirst)) {
+ (FormatTok.HasUnescapedNewline || FormatTok.IsFirst)) {
// If there is an unfinished unwrapped line, we flush the preprocessor
// directives only after that unwrapped line was finished later.
bool SwitchToPreprocessorLines =
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=179064&r1=179063&r2=179064&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Apr 8 17:16:06 2013
@@ -1339,6 +1339,22 @@ TEST_F(FormatTest, MacroDefinitionsWithI
"f(STR(this_is_a_string_literal{));");
}
+TEST_F(FormatTest, MacroCallsWithoutTrailingSemicolon) {
+ EXPECT_EQ("INITIALIZE_PASS_BEGIN(ScopDetection, \"polly-detect\")\n"
+ "INITIALIZE_AG_DEPENDENCY(AliasAnalysis)\n"
+ "INITIALIZE_PASS_DEPENDENCY(DominatorTree)\n"
+ "class X {\n"
+ "};\n"
+ "INITIALIZE_PASS_END(ScopDetection, \"polly-detect\")\n"
+ "int *createScopDetectionPass() { return 0; }",
+ format(" INITIALIZE_PASS_BEGIN(ScopDetection, \"polly-detect\")\n"
+ " INITIALIZE_AG_DEPENDENCY(AliasAnalysis)\n"
+ " INITIALIZE_PASS_DEPENDENCY(DominatorTree)\n"
+ " class X {};\n"
+ " INITIALIZE_PASS_END(ScopDetection, \"polly-detect\")\n"
+ " int *createScopDetectionPass() { return 0; }"));
+}
+
TEST_F(FormatTest, IndentPreprocessorDirectivesAtZero) {
EXPECT_EQ("{\n {\n#define A\n }\n}", format("{{\n#define A\n}}"));
}
More information about the cfe-commits
mailing list