]> granicus.if.org Git - clang/commitdiff
clang-format: [TableGen] Support ;-less include lines.
authorDaniel Jasper <djasper@google.com>
Fri, 25 Dec 2015 08:53:31 +0000 (08:53 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 25 Dec 2015 08:53:31 +0000 (08:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256412 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Format/Format.h
lib/Format/Format.cpp
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 128c4f8c91ac34b37d11c51f6e4640ffa0bb8336..6d051e09cb6437e6e3d7d033e1a2fdb74e3c8567 100644 (file)
@@ -427,7 +427,9 @@ struct FormatStyle {
     LK_JavaScript,
     /// Should be used for Protocol Buffers
     /// (https://developers.google.com/protocol-buffers/).
-    LK_Proto
+    LK_Proto,
+    /// Should be used for TableGen code.
+    LK_TableGen
   };
 
   /// \brief Language, this format style is targeted at.
index 364f4983a2ca2b0afcccdc1cf0edff64b8d0e724..5068fca5c44dd79349dbb123a083dcc29c64d826 100644 (file)
@@ -47,6 +47,7 @@ template <> struct ScalarEnumerationTraits<FormatStyle::LanguageKind> {
     IO.enumCase(Value, "Java", FormatStyle::LK_Java);
     IO.enumCase(Value, "JavaScript", FormatStyle::LK_JavaScript);
     IO.enumCase(Value, "Proto", FormatStyle::LK_Proto);
+    IO.enumCase(Value, "TableGen", FormatStyle::LK_TableGen);
   }
 };
 
@@ -1942,15 +1943,15 @@ const char *StyleOptionHelpDescription =
     "  -style=\"{BasedOnStyle: llvm, IndentWidth: 8}\"";
 
 static FormatStyle::LanguageKind getLanguageByFileName(StringRef FileName) {
-  if (FileName.endswith(".java")) {
+  if (FileName.endswith(".java"))
     return FormatStyle::LK_Java;
-  } else if (FileName.endswith_lower(".js") || FileName.endswith_lower(".ts")) {
-    // JavaScript or TypeScript.
-    return FormatStyle::LK_JavaScript;
-  } else if (FileName.endswith_lower(".proto") ||
-             FileName.endswith_lower(".protodevel")) {
+  if (FileName.endswith_lower(".js") || FileName.endswith_lower(".ts"))
+    return FormatStyle::LK_JavaScript; // JavaScript or TypeScript.
+  if (FileName.endswith_lower(".proto") ||
+      FileName.endswith_lower(".protodevel"))
     return FormatStyle::LK_Proto;
-  }
+  if (FileName.endswith_lower(".td"))
+    return FormatStyle::LK_TableGen;
   return FormatStyle::LK_Cpp;
 }
 
index 1213332d2734369657f6796fb40c54fb56672509..34c0c83807290e752485e08e8445db9c01236439 100644 (file)
@@ -650,7 +650,15 @@ static bool tokenCanStartNewLine(const clang::Token &Tok) {
 }
 
 void UnwrappedLineParser::parseStructuralElement() {
-  assert(!FormatTok->Tok.is(tok::l_brace));
+  assert(!FormatTok->is(tok::l_brace));
+  if (Style.Language == FormatStyle::LK_TableGen &&
+      FormatTok->is(tok::pp_include)) {
+    nextToken();
+    if (FormatTok->is(tok::string_literal))
+      nextToken();
+    addUnwrappedLine();
+    return;
+  }
   switch (FormatTok->Tok.getKind()) {
   case tok::at:
     nextToken();
index 55756aa247e2c6af03b414c4138edb61b9d2bfa5..9d7521fee105d77a33fc5c57d28591fca9fb291c 100644 (file)
@@ -11020,6 +11020,12 @@ TEST_F(FormatTest, DoNotCrashOnInvalidInput) {
   verifyNoCrash("#define a\\\n /**/}");
 }
 
+TEST_F(FormatTest, FormatsTableGenCode) {
+  FormatStyle Style = getLLVMStyle();
+  Style.Language = FormatStyle::LK_TableGen;
+  verifyFormat("include \"a.td\"\ninclude \"b.td\"", Style);
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang