From 53b2cbb794ae91ac83990294871e424565691780 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 7 Apr 2015 15:04:40 +0000 Subject: [PATCH] clang-format: Fix regression formatting QT's "signals:" from r234318. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234320 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/FormatToken.h | 9 +++++++++ lib/Format/UnwrappedLineFormatter.h | 3 ++- lib/Format/UnwrappedLineParser.cpp | 7 +++++-- unittests/Format/FormatTest.cpp | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index cef7a638d5..62c99326b6 100644 --- a/lib/Format/FormatToken.h +++ b/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/lib/Format/UnwrappedLineFormatter.h b/lib/Format/UnwrappedLineFormatter.h index 9b83b2733e..7d5b01148b 100644 --- a/lib/Format/UnwrappedLineFormatter.h +++ b/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/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 3df7839b79..7afe183236 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 16062dd40b..d96c8b0303 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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" "};"); } -- 2.40.0