r195251 - Support for JavaScript === and !== operators.
Alexander Kornienko
alexfh at google.com
Wed Nov 20 06:30:27 PST 2013
Author: alexfh
Date: Wed Nov 20 08:30:26 2013
New Revision: 195251
URL: http://llvm.org/viewvc/llvm-project?rev=195251&view=rev
Log:
Support for JavaScript === and !== operators.
Reviewers: klimek, djasper
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2231
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=195251&r1=195250&r2=195251&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Nov 20 08:30:26 2013
@@ -1363,6 +1363,10 @@ bool TokenAnnotator::spaceRequiredBefore
if (Tok.isOneOf(tok::arrowstar, tok::periodstar) ||
Tok.Previous->isOneOf(tok::arrowstar, tok::periodstar))
return false;
+ // JavaScript identity operators ===, !==.
+ if (Tok.Previous->isOneOf(tok::equalequal, tok::exclaimequal) &&
+ Tok.is(tok::equal))
+ return false;
if (!Style.SpaceBeforeAssignmentOperators &&
Tok.getPrecedence() == prec::Assignment)
return false;
@@ -1452,6 +1456,9 @@ bool TokenAnnotator::canBreakBefore(cons
return false;
if (Left.is(tok::equal) && Line.Type == LT_VirtualFunctionDecl)
return false;
+ // JavaScript identity operators ===, !==.
+ if (Left.isOneOf(tok::equalequal, tok::exclaimequal) && Right.is(tok::equal))
+ return false;
if (Left.Previous) {
if (Left.is(tok::l_paren) && Right.is(tok::l_paren) &&
Left.Previous->is(tok::kw___attribute))
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=195251&r1=195250&r2=195251&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Nov 20 08:30:26 2013
@@ -7309,5 +7309,13 @@ TEST_F(FormatTest, SpacesInAngles) {
verifyFormat("A<A<int>>();", Spaces);
}
+
+TEST_F(FormatTest, UnderstandsJavaScript) {
+ verifyFormat("a === b;");
+ verifyFormat("aaaaaaa === b;", getLLVMStyleWithColumns(10));
+ verifyFormat("a !== b;");
+ verifyFormat("aaaaaaa !== b;", getLLVMStyleWithColumns(10));
+}
+
} // end namespace tooling
} // end namespace clang
More information about the cfe-commits
mailing list