From b65b352ab0bf9520abca3a97443e990598961818 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 1 Dec 2015 12:05:04 +0000 Subject: [PATCH] clang-format: treat Q_SIGNALS as an access modifier Patch by Alexander Richardson, thank you! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254407 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/FormatToken.h | 2 ++ lib/Format/UnwrappedLineFormatter.cpp | 4 ++-- lib/Format/UnwrappedLineParser.cpp | 3 ++- unittests/Format/FormatTest.cpp | 16 +++++++++++++--- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index 4988520599..93baaf2932 100644 --- a/lib/Format/FormatToken.h +++ b/lib/Format/FormatToken.h @@ -561,6 +561,7 @@ struct AdditionalKeywords { kw_returns = &IdentTable.get("returns"); kw_signals = &IdentTable.get("signals"); + kw_qsignals = &IdentTable.get("Q_SIGNALS"); kw_slots = &IdentTable.get("slots"); kw_qslots = &IdentTable.get("Q_SLOTS"); } @@ -607,6 +608,7 @@ struct AdditionalKeywords { // QT keywords. IdentifierInfo *kw_signals; + IdentifierInfo *kw_qsignals; IdentifierInfo *kw_slots; IdentifierInfo *kw_qslots; }; diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp index 04087e8487..f650569079 100644 --- a/lib/Format/UnwrappedLineFormatter.cpp +++ b/lib/Format/UnwrappedLineFormatter.cpp @@ -90,8 +90,8 @@ private: return 0; if (RootToken.isAccessSpecifier(false) || RootToken.isObjCAccessSpecifier() || - (RootToken.is(Keywords.kw_signals) && RootToken.Next && - RootToken.Next->is(tok::colon))) + (RootToken.isOneOf(Keywords.kw_signals, Keywords.kw_qsignals) && + RootToken.Next && RootToken.Next->is(tok::colon))) return Style.AccessModifierOffset; return 0; } diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index ad548217b4..e06903c306 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -784,7 +784,8 @@ void UnwrappedLineParser::parseStructuralElement() { parseJavaScriptEs6ImportExport(); return; } - if (FormatTok->is(Keywords.kw_signals)) { + if (FormatTok->isOneOf(Keywords.kw_signals, Keywords.kw_qsignals, + Keywords.kw_slots, Keywords.kw_qslots)) { nextToken(); if (FormatTok->is(tok::colon)) { nextToken(); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 1d64405f08..084ffc9442 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1867,11 +1867,21 @@ TEST_F(FormatTest, UnderstandsAccessSpecifiers) { "};"); verifyFormat("class A {\n" "public slots:\n" - " void f() {}\n" + " void f1() {}\n" "public Q_SLOTS:\n" - " void f() {}\n" + " void f2() {}\n" + "protected slots:\n" + " void f3() {}\n" + "protected Q_SLOTS:\n" + " void f4() {}\n" + "private slots:\n" + " void f5() {}\n" + "private Q_SLOTS:\n" + " void f6() {}\n" "signals:\n" - " void g();\n" + " void g1();\n" + "Q_SIGNALS:\n" + " void g2();\n" "};"); // Don't interpret 'signals' the wrong way. -- 2.40.0