From: Daniel Jasper Date: Fri, 25 Dec 2015 08:53:31 +0000 (+0000) Subject: clang-format: [TableGen] Support ;-less include lines. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=794a77e319dc84fc3faaa1ed0086f580bbf6d1ab;p=clang clang-format: [TableGen] Support ;-less include lines. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256412 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Format/Format.h b/include/clang/Format/Format.h index 128c4f8c91..6d051e09cb 100644 --- a/include/clang/Format/Format.h +++ b/include/clang/Format/Format.h @@ -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. diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 364f4983a2..5068fca5c4 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -47,6 +47,7 @@ template <> struct ScalarEnumerationTraits { 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; } diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 1213332d27..34c0c83807 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -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(); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 55756aa247..9d7521fee1 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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