On Wed, Nov 20, 2013 at 6:30 AM, Alexander Kornienko <[email protected]>wrote:
> 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)); > How is this the correct format? Wouldn't we expect a break before "b"? > + verifyFormat("a !== b;"); > + verifyFormat("aaaaaaa !== b;", getLLVMStyleWithColumns(10)); > +} > + > Also, I think these tests are not sufficient. What if the LHS of one of these operators needs to be broken over multiple lines (there is a whole lot of logic of what happens to the RHS then)? I think we actually might need to merge the tokens. } // end namespace tooling > } // end namespace clang > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
