Author: djasper Date: Thu Jun 25 03:38:46 2015 New Revision: 240624 URL: http://llvm.org/viewvc/llvm-project?rev=240624&view=rev Log: clang-format: [Proto] Don't treat "operator" as keyword.
Before: optional string operator= 1; After: optional string operator = 1; Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTestProto.cpp Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=240624&r1=240623&r2=240624&view=diff ============================================================================== --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Jun 25 03:38:46 2015 @@ -1876,7 +1876,12 @@ bool TokenAnnotator::spaceRequiredBetwee bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, const FormatToken &Right) { const FormatToken &Left = *Right.Previous; - if (Style.Language == FormatStyle::LK_Proto) { + if (Right.Tok.getIdentifierInfo() && Left.Tok.getIdentifierInfo()) + return true; // Never ever merge two identifiers. + if (Style.Language == FormatStyle::LK_Cpp) { + if (Left.is(tok::kw_operator)) + return Right.is(tok::coloncolon); + } else if (Style.Language == FormatStyle::LK_Proto) { if (Right.is(tok::period) && Left.isOneOf(Keywords.kw_optional, Keywords.kw_required, Keywords.kw_repeated)) @@ -1913,8 +1918,6 @@ bool TokenAnnotator::spaceRequiredBefore Right.is(TT_TemplateOpener)) return true; } - if (Right.Tok.getIdentifierInfo() && Left.Tok.getIdentifierInfo()) - return true; // Never ever merge two identifiers. if (Left.is(TT_ImplicitStringLiteral)) return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd(); if (Line.Type == LT_ObjCMethodDecl) { @@ -1937,8 +1940,6 @@ bool TokenAnnotator::spaceRequiredBefore return false; if (Right.isOneOf(TT_CtorInitializerColon, TT_ObjCBlockLParen)) return true; - if (Left.is(tok::kw_operator)) - return Right.is(tok::coloncolon); if (Right.is(TT_OverloadedOperatorLParen)) return false; if (Right.is(tok::colon)) { Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=240624&r1=240623&r2=240624&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTestProto.cpp (original) +++ cfe/trunk/unittests/Format/FormatTestProto.cpp Thu Jun 25 03:38:46 2015 @@ -63,6 +63,10 @@ TEST_F(FormatTestProto, FormatsMessages) "}"); } +TEST_F(FormatTestProto, KeywordsInOtherLanguages) { + verifyFormat("optional string operator = 1;"); +} + TEST_F(FormatTestProto, FormatsEnums) { verifyFormat("enum Type {\n" " UNKNOWN = 0;\n" _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits