From 59875ac81b97de87ac6c4c7cb256ab71b75114f2 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 7 Nov 2013 17:43:07 +0000 Subject: [PATCH] clang-format: Remove old hack that mainly made incorrect tests pass. As a side-effect, constructors definitions will correctly be recognized and formatted as function declarations. Tests will be added in a follow-up patch actually using the correct recognition. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194209 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 8 +++----- unittests/Format/FormatTest.cpp | 35 ++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 13d3facb07..f18627ef58 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -32,8 +32,7 @@ public: AnnotatingParser(const FormatStyle &Style, AnnotatedLine &Line, IdentifierInfo &Ident_in) : Style(Style), Line(Line), CurrentToken(Line.First), - KeywordVirtualFound(false), NameFound(false), AutoFound(false), - Ident_in(Ident_in) { + KeywordVirtualFound(false), AutoFound(false), Ident_in(Ident_in) { Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false)); } @@ -367,7 +366,8 @@ private: case tok::l_paren: if (!parseParens()) return false; - if (Line.MustBeDeclaration && NameFound && !Contexts.back().IsExpression) + if (Line.MustBeDeclaration && Contexts.size() == 1 && + !Contexts.back().IsExpression) Line.MightBeFunctionDecl = true; break; case tok::l_square: @@ -632,7 +632,6 @@ private: if (isStartOfName(Current) && !Line.MightBeFunctionDecl) { Contexts.back().FirstStartOfName = &Current; Current.Type = TT_StartOfName; - NameFound = true; } else if (Current.is(tok::kw_auto)) { AutoFound = true; } else if (Current.is(tok::arrow) && AutoFound && @@ -853,7 +852,6 @@ private: AnnotatedLine &Line; FormatToken *CurrentToken; bool KeywordVirtualFound; - bool NameFound; bool AutoFound; IdentifierInfo &Ident_in; }; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 00c684cc40..43f5634131 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -2500,9 +2500,11 @@ TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) { TEST_F(FormatTest, PreventConfusingIndents) { verifyFormat( - "SomeLongMethodName(SomeReallyLongMethod(CallOtherReallyLongMethod(\n" - " parameter, parameter, parameter)),\n" - " SecondLongCall(parameter));"); + "void f() {\n" + " SomeLongMethodName(SomeReallyLongMethod(CallOtherReallyLongMethod(\n" + " parameter, parameter, parameter)),\n" + " SecondLongCall(parameter));\n" + "}"); verifyFormat( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" " aaaaaaaaaaaaaaaaaaaaaaaa(\n" @@ -3078,8 +3080,10 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { verifyFormat("aaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaa)\n" " .aaaaaaaaaaaaaaaaaa();", NoBinPacking); - verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" - " aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaa);", + verifyFormat("void f() {\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" + " aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaa);\n" + "}", NoBinPacking); verifyFormat( @@ -3168,7 +3172,8 @@ TEST_F(FormatTest, FormatsBuilderPattern) { " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" " ->aaaaaaaaaaaaaaaaa();"); verifyGoogleFormat( - "someobj->Add((new util::filetools::Handler(dir))\n" + "void f() {\n" + " someo->Add((new util::filetools::Handler(dir))\n" " ->OnEvent1(NewPermanentCallback(\n" " this, &HandlerHolderClass::EventHandlerCBA))\n" " ->OnEvent2(NewPermanentCallback(\n" @@ -3178,7 +3183,8 @@ TEST_F(FormatTest, FormatsBuilderPattern) { " ->OnEvent5(NewPermanentCallback(\n" " this, &HandlerHolderClass::EventHandlerCBD))\n" " ->OnEvent6(NewPermanentCallback(\n" - " this, &HandlerHolderClass::EventHandlerCBE)));"); + " this, &HandlerHolderClass::EventHandlerCBE)));\n" + "}"); verifyFormat( "aaaaaaaaaaa().aaaaaaaaaaa().aaaaaaaaaaa().aaaaaaaaaaa().aaaaaaaaaaa();"); @@ -3638,8 +3644,10 @@ TEST_F(FormatTest, WrapsAtFunctionCallsIfNecessary) { verifyFormat("aaaaa(aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa).aaaaa(aaaaa),\n" " aaaaaaaaaaaaaaaaaaaaa);"); - verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaa(\n" - " aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa)->aaaaaaaaa());"); + verifyFormat("void f() {\n" + " aaaaaaaaaaaaaaaaaaaaaaaaa(\n" + " aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa)->aaaaaaaaa());\n" + "}"); verifyFormat( "aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n" @@ -3723,8 +3731,10 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) { "aaaaaaaaaaaaaaaaaaaaaaaa(\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);"); - verifyFormat("a(\n" - " a(aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa));"); + verifyFormat("void f() {\n" + " a(\n" + " a(aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa));\n" + "}"); verifyFormat("template class C {};"); verifyFormat("template void f();"); @@ -4252,6 +4262,9 @@ TEST_F(FormatTest, BreaksLongDeclarations) { verifyFormat("typedef LoooooooooooooooooooooooooooooooooooooooongType\n" " AnotherNameForTheLongType;", getGoogleStyle()); + verifyFormat("typedef LongTemplateType\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;", + getGoogleStyle()); verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType\n" " LoooooooooooooooooooooooooooooooooooooooongVariable;", getGoogleStyle()); -- 2.40.0