clang-format: [TableGen] Support ;-less include lines.

llvm-svn: 256412
This commit is contained in:
Daniel Jasper 2015-12-25 08:53:31 +00:00
parent 2df0fd86c2
commit 498f558fcf
4 changed files with 26 additions and 9 deletions

View 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.

View 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;
}

View 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();

View 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