aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/FormatTokenLexer.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-10-23 17:52:09 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-10-23 17:52:09 +0000
commit519fc96c475680de2cc49e7811dbbfadb912cbcc (patch)
tree310ca684459b7e9ae13c9a3b9abf308b3a634afe /lib/Format/FormatTokenLexer.cpp
parent2298981669bf3bd63335a4be179bc0f96823a8f4 (diff)
downloadsrc-519fc96c475680de2cc49e7811dbbfadb912cbcc.tar.gz
src-519fc96c475680de2cc49e7811dbbfadb912cbcc.zip
Vendor import of stripped clang trunk r375505, the last commit beforevendor/clang/clang-trunk-r375505vendor/clang
the upstream Subversion repository was made read-only, and the LLVM project migrated to GitHub: https://llvm.org/svn/llvm-project/cfe/trunk@375505
Notes
Notes: svn path=/vendor/clang/dist/; revision=353942 svn path=/vendor/clang/clang-r375505/; revision=353943; tag=vendor/clang/clang-trunk-r375505
Diffstat (limited to 'lib/Format/FormatTokenLexer.cpp')
-rw-r--r--lib/Format/FormatTokenLexer.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/Format/FormatTokenLexer.cpp b/lib/Format/FormatTokenLexer.cpp
index 009b8849753c..5d8a77577c0b 100644
--- a/lib/Format/FormatTokenLexer.cpp
+++ b/lib/Format/FormatTokenLexer.cpp
@@ -80,6 +80,8 @@ void FormatTokenLexer::tryMergePreviousTokens() {
return;
if (tryMergeCSharpNullConditionals())
return;
+ if (tryTransformCSharpForEach())
+ return;
static const tok::TokenKind JSRightArrow[] = {tok::equal, tok::greater};
if (tryMergeTokens(JSRightArrow, TT_JsFatArrow))
return;
@@ -254,6 +256,21 @@ bool FormatTokenLexer::tryMergeCSharpNullConditionals() {
return true;
}
+// In C# transform identifier foreach into kw_foreach
+bool FormatTokenLexer::tryTransformCSharpForEach() {
+ if (Tokens.size() < 1)
+ return false;
+ auto &Identifier = *(Tokens.end() - 1);
+ if (!Identifier->is(tok::identifier))
+ return false;
+ if (Identifier->TokenText != "foreach")
+ return false;
+
+ Identifier->Type = TT_ForEachMacro;
+ Identifier->Tok.setKind(tok::kw_for);
+ return true;
+}
+
bool FormatTokenLexer::tryMergeLessLess() {
// Merge X,less,less,Y into X,lessless,Y unless X or Y is less.
if (Tokens.size() < 3)
@@ -657,7 +674,8 @@ FormatToken *FormatTokenLexer::getNextToken() {
++Column;
break;
case '\t':
- Column += Style.TabWidth - Column % Style.TabWidth;
+ Column +=
+ Style.TabWidth - (Style.TabWidth ? Column % Style.TabWidth : 0);
break;
case '\\':
if (i + 1 == e || (Text[i + 1] != '\r' && Text[i + 1] != '\n'))