From 5994368c76fc759e343c500ae283b241b196a514 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 25 Jun 2015 08:38:46 +0000 Subject: [PATCH] clang-format: [Proto] Don't treat "operator" as keyword. Before: optional string operator= 1; After: optional string operator = 1; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240624 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 11 ++++++----- unittests/Format/FormatTestProto.cpp | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 8d08c3d262..2f1aae3934 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1876,7 +1876,12 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, 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(const AnnotatedLine &Line, 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(const AnnotatedLine &Line, 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)) { diff --git a/unittests/Format/FormatTestProto.cpp b/unittests/Format/FormatTestProto.cpp index ac8fcbdda4..74f7005b21 100644 --- a/unittests/Format/FormatTestProto.cpp +++ b/unittests/Format/FormatTestProto.cpp @@ -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" -- 2.40.0