summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-04-07 15:04:40 +0000
committerDaniel Jasper <djasper@google.com>2015-04-07 15:04:40 +0000
commit53395406dae24921b7d5ad68be7436e23b1a659b (patch)
tree25bb96ad2ab1a0102adbf4096f5c66daf9984e91
parente4651eb0331d5d4daf1c9a4c05b449b8670b276a (diff)
downloadbcm5719-llvm-53395406dae24921b7d5ad68be7436e23b1a659b.tar.gz
bcm5719-llvm-53395406dae24921b7d5ad68be7436e23b1a659b.zip
clang-format: Fix regression formatting QT's "signals:" from r234318.
llvm-svn: 234320
-rw-r--r--clang/lib/Format/FormatToken.h9
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.h3
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp7
-rw-r--r--clang/unittests/Format/FormatTest.cpp2
4 files changed, 18 insertions, 3 deletions
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index cef7a638d53..62c99326b69 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -549,6 +549,10 @@ struct AdditionalKeywords {
kw_repeated = &IdentTable.get("repeated");
kw_required = &IdentTable.get("required");
kw_returns = &IdentTable.get("returns");
+
+ kw_signals = &IdentTable.get("signals");
+ kw_slots = &IdentTable.get("slots");
+ kw_qslots = &IdentTable.get("Q_SLOTS");
}
// Context sensitive keywords.
@@ -583,6 +587,11 @@ struct AdditionalKeywords {
IdentifierInfo *kw_repeated;
IdentifierInfo *kw_required;
IdentifierInfo *kw_returns;
+
+ // QT keywords.
+ IdentifierInfo *kw_signals;
+ IdentifierInfo *kw_slots;
+ IdentifierInfo *kw_qslots;
};
} // namespace format
diff --git a/clang/lib/Format/UnwrappedLineFormatter.h b/clang/lib/Format/UnwrappedLineFormatter.h
index 9b83b2733e1..7d5b01148b0 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.h
+++ b/clang/lib/Format/UnwrappedLineFormatter.h
@@ -80,7 +80,8 @@ private:
if (Style.Language == FormatStyle::LK_Java ||
Style.Language == FormatStyle::LK_JavaScript)
return 0;
- if (RootToken.isAccessSpecifier(false) || RootToken.isObjCAccessSpecifier())
+ if (RootToken.isAccessSpecifier(false) ||
+ RootToken.isObjCAccessSpecifier() || RootToken.is(Keywords.kw_signals))
return Style.AccessModifierOffset;
return 0;
}
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 3df7839b79b..7afe183236a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -753,6 +753,10 @@ void UnwrappedLineParser::parseStructuralElement() {
parseJavaScriptEs6ImportExport();
return;
}
+ if (FormatTok->is(Keywords.kw_signals)) {
+ parseAccessSpecifier();
+ return;
+ }
// In all other cases, parse the declaration.
break;
default:
@@ -1410,8 +1414,7 @@ void UnwrappedLineParser::parseSwitch() {
void UnwrappedLineParser::parseAccessSpecifier() {
nextToken();
// Understand Qt's slots.
- if (FormatTok->is(tok::identifier) &&
- (FormatTok->TokenText == "slots" || FormatTok->TokenText == "Q_SLOTS"))
+ if (FormatTok->isOneOf(Keywords.kw_slots, Keywords.kw_qslots))
nextToken();
// Otherwise, we don't know what it is, and we'd better keep the next token.
if (FormatTok->Tok.is(tok::colon))
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 16062dd40b7..d96c8b0303c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1897,6 +1897,8 @@ TEST_F(FormatTest, UnderstandsAccessSpecifiers) {
" void f() {}\n"
"public Q_SLOTS:\n"
" void f() {}\n"
+ "signals:\n"
+ " void g();\n"
"};");
}
OpenPOWER on IntegriCloud