summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-05-10 08:42:04 +0000
committerDaniel Jasper <djasper@google.com>2015-05-10 08:42:04 +0000
commitc6366077ed8dafe40fbd04315bdec0450e84e087 (patch)
tree17c617a6e8915c37199d85f4cda0eff4e999c092 /clang/lib/Format
parent4cc8d202d0f2d0c16bd748c0a0f675002957b172 (diff)
downloadbcm5719-llvm-c6366077ed8dafe40fbd04315bdec0450e84e087.tar.gz
bcm5719-llvm-c6366077ed8dafe40fbd04315bdec0450e84e087.zip
clang-format: Preserve line break before } in __asm { ... }.
Some compilers ignore everything after a semicolon in such inline asm blocks and thus, the closing brace must not be moved to the previous line. llvm-svn: 236946
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/FormatToken.h1
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp5
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp2
3 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index b6a7dcd81b0..54951abade0 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -48,6 +48,7 @@ enum TokenType {
TT_ImplicitStringLiteral,
TT_InheritanceColon,
TT_InlineASMColon,
+ TT_InlineASMBrace,
TT_JavaAnnotation,
TT_JsTypeColon,
TT_JsTypeOptionalQuestion,
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 50ef0cafbde..67a66fcbd4c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -736,7 +736,8 @@ private:
// recovered from an error (e.g. failure to find the matching >).
if (!CurrentToken->isOneOf(TT_LambdaLSquare, TT_ForEachMacro,
TT_FunctionLBrace, TT_ImplicitStringLiteral,
- TT_RegexLiteral, TT_TrailingReturnArrow))
+ TT_InlineASMBrace, TT_RegexLiteral,
+ TT_TrailingReturnArrow))
CurrentToken->Type = TT_Unknown;
CurrentToken->Role.reset();
CurrentToken->MatchingParen = nullptr;
@@ -2006,6 +2007,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
Style.Language == FormatStyle::LK_Proto)
// Don't put enums onto single lines in protocol buffers.
return true;
+ if (Right.is(TT_InlineASMBrace))
+ return Right.HasUnescapedNewline;
if (Style.Language == FormatStyle::LK_JavaScript && Right.is(tok::r_brace) &&
Left.is(tok::l_brace) && !Left.Children.empty())
// Support AllowShortFunctionsOnASingleLine for JavaScript.
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 117e83802c8..a85d9c77316 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -666,9 +666,11 @@ void UnwrappedLineParser::parseStructuralElement() {
case tok::kw_asm:
nextToken();
if (FormatTok->is(tok::l_brace)) {
+ FormatTok->Type = TT_InlineASMBrace;
nextToken();
while (FormatTok && FormatTok->isNot(tok::eof)) {
if (FormatTok->is(tok::r_brace)) {
+ FormatTok->Type = TT_InlineASMBrace;
nextToken();
break;
}
OpenPOWER on IntegriCloud