clang-format: Fix regression formatting QT's "signals:" from r234318.
authorDaniel Jasper <djasper@google.com>
Tue, 7 Apr 2015 15:04:40 +0000 (15:04 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 7 Apr 2015 15:04:40 +0000 (15:04 +0000)
llvm-svn: 234320

clang/lib/Format/FormatToken.h
clang/lib/Format/UnwrappedLineFormatter.h
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

index cef7a63..62c9932 100644 (file)
@@ -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
index 9b83b27..7d5b011 100644 (file)
@@ -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;
   }
index 3df7839..7afe183 100644 (file)
@@ -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))
index 16062dd..d96c8b0 100644 (file)
@@ -1897,6 +1897,8 @@ TEST_F(FormatTest, UnderstandsAccessSpecifiers) {
                "  void f() {}\n"
                "public Q_SLOTS:\n"
                "  void f() {}\n"
+               "signals:\n"
+               "  void g();\n"
                "};");
 }