summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2013-04-09 16:15:19 +0000
committerAlexander Kornienko <alexfh@google.com>2013-04-09 16:15:19 +0000
commita04e5e213b2a4ab2cd0fda7725efc7158a095f6c (patch)
tree3fccb7e319a5fc7bcca651eb2349f44234b38c0c /clang/lib/Format
parente4549a2391a612e380d7362c2d75b729717c2d2c (diff)
downloadbcm5719-llvm-a04e5e213b2a4ab2cd0fda7725efc7158a095f6c.tar.gz
bcm5719-llvm-a04e5e213b2a4ab2cd0fda7725efc7158a095f6c.zip
Again macros without trailing semicolons: don't care about declaration context.
Summary: Some codebases use these kinds of macros in functions, e.g. Chromium's IPC_BEGIN_MESSAGE_MAP, IPC_BEGIN_MESSAGE_HANDLER, etc. Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D645 llvm-svn: 179099
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp33
1 files changed, 30 insertions, 3 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 12b7f7866fb..22aa8195dd1 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -260,6 +260,33 @@ void UnwrappedLineParser::parsePPUnknown() {
addUnwrappedLine();
}
+// Here we blacklist certain tokens that are not usually the first token in an
+// unwrapped line. This is used in attempt to distinguish macro calls without
+// trailing semicolons from other constructs split to several lines.
+bool tokenCanStartNewLine(clang::Token Tok) {
+ // Semicolon can be a null-statement, l_square can be a start of a macro or
+ // a C++11 attribute, but this doesn't seem to be common.
+ return Tok.isNot(tok::semi) && Tok.isNot(tok::l_brace) &&
+ Tok.isNot(tok::l_square) &&
+ // Tokens that can only be used as binary operators and a part of
+ // overloaded operator names.
+ Tok.isNot(tok::period) && Tok.isNot(tok::periodstar) &&
+ Tok.isNot(tok::arrow) && Tok.isNot(tok::arrowstar) &&
+ Tok.isNot(tok::less) && Tok.isNot(tok::greater) &&
+ Tok.isNot(tok::slash) && Tok.isNot(tok::percent) &&
+ Tok.isNot(tok::lessless) && Tok.isNot(tok::greatergreater) &&
+ Tok.isNot(tok::equal) && Tok.isNot(tok::plusequal) &&
+ Tok.isNot(tok::minusequal) && Tok.isNot(tok::starequal) &&
+ Tok.isNot(tok::slashequal) && Tok.isNot(tok::percentequal) &&
+ Tok.isNot(tok::ampequal) && Tok.isNot(tok::pipeequal) &&
+ Tok.isNot(tok::caretequal) && Tok.isNot(tok::greatergreaterequal) &&
+ Tok.isNot(tok::lesslessequal) &&
+ // Colon is used in labels, base class lists, initializer lists,
+ // range-based for loops, ternary operator, but should never be the
+ // first token in an unwrapped line.
+ Tok.isNot(tok::colon);
+}
+
void UnwrappedLineParser::parseStructuralElement() {
assert(!FormatTok.Tok.is(tok::l_brace));
switch (FormatTok.Tok.getKind()) {
@@ -386,11 +413,11 @@ void UnwrappedLineParser::parseStructuralElement() {
parseLabel();
return;
}
- // Recognize function-like macro usages without trailing semicolon in
- // declaration context.
+ // Recognize function-like macro usages without trailing semicolon.
if (FormatTok.Tok.is(tok::l_paren)) {
parseParens();
- if (Line->MustBeDeclaration && FormatTok.HasUnescapedNewline) {
+ if (FormatTok.HasUnescapedNewline &&
+ tokenCanStartNewLine(FormatTok.Tok)) {
addUnwrappedLine();
return;
}
OpenPOWER on IntegriCloud