[PATCH] D32864: clang-format: [JS] exponentiation operator
Martin Probst via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 4 08:17:21 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL302156: clang-format: [JS] exponentiation operator (authored by mprobst).
Changed prior to commit:
https://reviews.llvm.org/D32864?vs=97829&id=97830#toc
Repository:
rL LLVM
https://reviews.llvm.org/D32864
Files:
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/FormatTokenLexer.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Index: cfe/trunk/lib/Format/FormatToken.h
===================================================================
--- cfe/trunk/lib/Format/FormatToken.h
+++ cfe/trunk/lib/Format/FormatToken.h
@@ -53,6 +53,8 @@
TYPE(InlineASMColon) \
TYPE(JavaAnnotation) \
TYPE(JsComputedPropertyName) \
+ TYPE(JsExponentiation) \
+ TYPE(JsExponentiationEqual) \
TYPE(JsFatArrow) \
TYPE(JsNonNullAssertion) \
TYPE(JsTypeColon) \
Index: cfe/trunk/lib/Format/FormatTokenLexer.cpp
===================================================================
--- cfe/trunk/lib/Format/FormatTokenLexer.cpp
+++ cfe/trunk/lib/Format/FormatTokenLexer.cpp
@@ -74,6 +74,10 @@
static const tok::TokenKind JSShiftEqual[] = {tok::greater, tok::greater,
tok::greaterequal};
static const tok::TokenKind JSRightArrow[] = {tok::equal, tok::greater};
+ static const tok::TokenKind JSExponentiation[] = {tok::star, tok::star};
+ static const tok::TokenKind JSExponentiationEqual[] = {tok::star,
+ tok::starequal};
+
// FIXME: Investigate what token type gives the correct operator priority.
if (tryMergeTokens(JSIdentity, TT_BinaryOperator))
return;
@@ -83,6 +87,12 @@
return;
if (tryMergeTokens(JSRightArrow, TT_JsFatArrow))
return;
+ if (tryMergeTokens(JSExponentiation, TT_JsExponentiation))
+ return;
+ if (tryMergeTokens(JSExponentiationEqual, TT_JsExponentiationEqual)) {
+ Tokens.back()->Tok.setKind(tok::starequal);
+ return;
+ }
}
if (Style.Language == FormatStyle::LK_Java) {
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1786,5 +1786,11 @@
getGoogleJSStyleWithColumns(25));
verifyFormat("// taze: x from 'location'", getGoogleJSStyleWithColumns(10));
}
+
+TEST_F(FormatTestJS, Exponentiation) {
+ verifyFormat("squared = x ** 2;");
+ verifyFormat("squared **= 2;");
+}
+
} // end namespace tooling
} // end namespace clang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32864.97830.patch
Type: text/x-patch
Size: 2195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170504/54f2c6eb/attachment.bin>
More information about the cfe-commits
mailing list