summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2018-04-13 13:37:09 +0000
committerKrasimir Georgiev <krasimir@google.com>2018-04-13 13:37:09 +0000
commitf28347ea7d082d629bdb29a6511b8cc66a6716ef (patch)
tree972d63465b8627c706974d66541ad196f95c7de8 /clang/lib/Format
parent308f8b7a66dcbd629e39ed7fd9010642d433bab8 (diff)
downloadbcm5719-llvm-f28347ea7d082d629bdb29a6511b8cc66a6716ef.tar.gz
bcm5719-llvm-f28347ea7d082d629bdb29a6511b8cc66a6716ef.zip
[clang-format] Improve Incomplete detection for (text) protos
Summary: This patch improves detection of incomplete code for protos and text protos. This is especially important for text protos in raw string literals, since they might be partial strings concatenated, and we'd like to disable formatting in these cases. Reviewers: sammccall Reviewed By: sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D44203 llvm-svn: 330016
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 49e21520b70..f76ae86b4c6 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -592,7 +592,8 @@ private:
return false;
}
}
- return true;
+ // There are no top-level unbalanced braces in text protos.
+ return Style.Language != FormatStyle::LK_TextProto;
}
void updateParameterCount(FormatToken *Left, FormatToken *Current) {
@@ -712,6 +713,11 @@ private:
} else if (Contexts.back().ContextKind == tok::l_paren) {
Tok->Type = TT_InlineASMColon;
}
+ // Detects trailing pieces like key:
+ if ((Style.Language == FormatStyle::LK_Proto ||
+ Style.Language == FormatStyle::LK_TextProto) &&
+ !CurrentToken)
+ return false;
break;
case tok::pipe:
case tok::amp:
@@ -798,6 +804,10 @@ private:
if (Previous && Previous->Type != TT_DictLiteral)
Previous->Type = TT_SelectorName;
}
+ } else if (Style.Language == FormatStyle::LK_TextProto ||
+ Style.Language == FormatStyle::LK_Proto) {
+ // In TT_Proto and TT_TextProto, tok::less cannot be a binary operator.
+ return false;
} else {
Tok->Type = TT_BinaryOperator;
NonTemplateLess.insert(Tok);
@@ -809,13 +819,16 @@ private:
case tok::r_square:
return false;
case tok::r_brace:
- // Lines can start with '}'.
- if (Tok->Previous)
+ // Lines can start with '}' except in text protos.
+ if (Tok->Previous || Style.Language == FormatStyle::LK_TextProto)
return false;
break;
case tok::greater:
- if (Style.Language != FormatStyle::LK_TextProto)
- Tok->Type = TT_BinaryOperator;
+ // In protos and text protos tok::greater cannot be a binary operator.
+ if (Style.Language == FormatStyle::LK_Proto ||
+ Style.Language == FormatStyle::LK_TextProto)
+ return false;
+ Tok->Type = TT_BinaryOperator;
break;
case tok::kw_operator:
if (Style.Language == FormatStyle::LK_TextProto ||
OpenPOWER on IntegriCloud