From 32a793cecb39909352528d13f858219397801aac Mon Sep 17 00:00:00 2001 From: vityaman Date: Tue, 30 Jul 2024 10:46:32 +0300 Subject: [PATCH] #132 Format BinPackParameters false Signed-off-by: vityaman --- ports/cpp/.clang-format | 3 + .../source/antlr4-c3/CodeCompletionCore.cpp | 50 ++++-- .../source/antlr4-c3/CodeCompletionCore.hpp | 22 ++- ports/cpp/test/cpp14/Cpp14Test.cpp | 157 ++++++++++++------ ports/cpp/test/expr/ExprTest.cpp | 20 ++- ports/cpp/test/utility/AntlrPipeline.hpp | 8 +- ports/cpp/test/whitebox/WhiteboxTest.cpp | 24 ++- 7 files changed, 200 insertions(+), 84 deletions(-) diff --git a/ports/cpp/.clang-format b/ports/cpp/.clang-format index f22f00b..e4edb9b 100644 --- a/ports/cpp/.clang-format +++ b/ports/cpp/.clang-format @@ -12,3 +12,6 @@ AllowShortLoopsOnASingleLine: false DerivePointerAlignment: false BreakConstructorInitializers: BeforeComma AlignAfterOpenBracket: BlockIndent + +BinPackArguments: false +BinPackParameters: false diff --git a/ports/cpp/source/antlr4-c3/CodeCompletionCore.cpp b/ports/cpp/source/antlr4-c3/CodeCompletionCore.cpp index eb4d019..e381c4b 100644 --- a/ports/cpp/source/antlr4-c3/CodeCompletionCore.cpp +++ b/ports/cpp/source/antlr4-c3/CodeCompletionCore.cpp @@ -61,9 +61,19 @@ std::map // NOLINT // Matches ATNStateType enum std::vector c3::CodeCompletionCore::atnStateTypeMap // NOLINT { - "invalid", "basic", "rule start", "block start", "plus block start", - "star block start", "token start", "rule stop", "block end", "star loop back", - "star loop entry", "plus loop back", "loop end", + "invalid", + "basic", + "rule start", + "block start", + "plus block start", + "star block start", + "token start", + "rule stop", + "block end", + "star loop back", + "star loop entry", + "plus loop back", + "loop end", }; CodeCompletionCore::CodeCompletionCore(antlr4::Parser* parser) @@ -76,7 +86,9 @@ CodeCompletionCore::CodeCompletionCore(antlr4::Parser* parser) } CandidatesCollection CodeCompletionCore::collectCandidates( // NOLINT - size_t caretTokenIndex, antlr4::ParserRuleContext* context, size_t timeoutMS, + size_t caretTokenIndex, + antlr4::ParserRuleContext* context, + size_t timeoutMS, std::atomic* cancel ) { shortcutMap.clear(); @@ -356,8 +368,10 @@ FollowSetsHolder CodeCompletionCore::determineFollowSets( * rule end was reached, so no subsequent rules could add tokens */ bool CodeCompletionCore::collectFollowSets( // NOLINT - antlr4::atn::ATNState* state, antlr4::atn::ATNState* stopState, - std::vector& followSets, std::vector& stateStack, + antlr4::atn::ATNState* state, + antlr4::atn::ATNState* stopState, + std::vector& followSets, + std::vector& stateStack, std::vector& ruleStack ) { if (std::find(stateStack.begin(), stateStack.end(), state) != stateStack.end()) { @@ -453,9 +467,11 @@ bool CodeCompletionCore::collectFollowSets( // NOLINT * to be taken). */ RuleEndStatus CodeCompletionCore::processRule( // NOLINT - antlr4::atn::RuleStartState* startState, size_t tokenListIndex, - RuleWithStartTokenList& callStack, int precedence, // NOLINT - size_t indentation, // NOLINT + antlr4::atn::RuleStartState* startState, + size_t tokenListIndex, + RuleWithStartTokenList& callStack, + int precedence, // NOLINT + size_t indentation, // NOLINT bool& timedOut ) { // Cancelled by external caller? @@ -618,7 +634,9 @@ RuleEndStatus CodeCompletionCore::processRule( // NOLINT const bool atCaret = currentEntry.tokenListIndex >= tokens.size() - 1; if (showDebugOutput) { printDescription( - indentation, currentEntry.state, generateBaseDescription(currentEntry.state), + indentation, + currentEntry.state, + generateBaseDescription(currentEntry.state), currentEntry.tokenListIndex ); if (showRuleStack) { @@ -643,8 +661,12 @@ RuleEndStatus CodeCompletionCore::processRule( // NOLINT auto* ruleStartState = dynamic_cast(ruleTransition->target); bool innerCancelled = false; const RuleEndStatus endStatus = processRule( - ruleStartState, currentEntry.tokenListIndex, callStack, ruleTransition->precedence, - indentation + 1, innerCancelled + ruleStartState, + currentEntry.tokenListIndex, + callStack, + ruleTransition->precedence, + indentation + 1, + innerCancelled ); if (innerCancelled) { timedOut = true; @@ -796,7 +818,9 @@ std::string CodeCompletionCore::generateBaseDescription(antlr4::atn::ATNState* s } void CodeCompletionCore::printDescription( - size_t indentation, antlr4::atn::ATNState* state, std::string const& baseDescription, + size_t indentation, + antlr4::atn::ATNState* state, + std::string const& baseDescription, size_t tokenIndex ) { const std::string indent = std::string(indentation * 2, ' '); diff --git a/ports/cpp/source/antlr4-c3/CodeCompletionCore.hpp b/ports/cpp/source/antlr4-c3/CodeCompletionCore.hpp index fc15cf1..c7da799 100644 --- a/ports/cpp/source/antlr4-c3/CodeCompletionCore.hpp +++ b/ports/cpp/source/antlr4-c3/CodeCompletionCore.hpp @@ -182,7 +182,9 @@ class CodeCompletionCore { * and the collected candidates may be incomplete. */ CandidatesCollection collectCandidates( - size_t caretTokenIndex, antlr4::ParserRuleContext* context = nullptr, size_t timeoutMS = 0, + size_t caretTokenIndex, + antlr4::ParserRuleContext* context = nullptr, + size_t timeoutMS = 0, std::atomic* cancel = nullptr ); @@ -227,20 +229,28 @@ class CodeCompletionCore { FollowSetsHolder determineFollowSets(antlr4::atn::ATNState* start, antlr4::atn::ATNState* stop); bool collectFollowSets( - antlr4::atn::ATNState* state, antlr4::atn::ATNState* stopState, - std::vector& followSets, std::vector& stateStack, + antlr4::atn::ATNState* state, + antlr4::atn::ATNState* stopState, + std::vector& followSets, + std::vector& stateStack, std::vector& ruleStack ); RuleEndStatus processRule( - antlr4::atn::RuleStartState* startState, size_t tokenListIndex, - RuleWithStartTokenList& callStack, int precedence, size_t indentation, bool& timedOut + antlr4::atn::RuleStartState* startState, + size_t tokenListIndex, + RuleWithStartTokenList& callStack, + int precedence, + size_t indentation, + bool& timedOut ); std::string generateBaseDescription(antlr4::atn::ATNState* state); void printDescription( - size_t indentation, antlr4::atn::ATNState* state, std::string const& baseDescription, + size_t indentation, + antlr4::atn::ATNState* state, + std::string const& baseDescription, size_t tokenIndex ); diff --git a/ports/cpp/test/cpp14/Cpp14Test.cpp b/ports/cpp/test/cpp14/Cpp14Test.cpp index 8544f97..7fa4823 100644 --- a/ports/cpp/test/cpp14/Cpp14Test.cpp +++ b/ports/cpp/test/cpp14/Cpp14Test.cpp @@ -39,10 +39,17 @@ TEST(CPP14Parser, SimpleExample) { // NOLINT: complexity // Ignore operators and the generic ID token. completion.ignoredTokens = { - CPP14Lexer::Identifier, CPP14Lexer::LeftParen, CPP14Lexer::RightParen, - CPP14Lexer::Operator, CPP14Lexer::Star, CPP14Lexer::And, - CPP14Lexer::AndAnd, CPP14Lexer::LeftBracket, CPP14Lexer::Ellipsis, - CPP14Lexer::Doublecolon, CPP14Lexer::Semi, + CPP14Lexer::Identifier, + CPP14Lexer::LeftParen, + CPP14Lexer::RightParen, + CPP14Lexer::Operator, + CPP14Lexer::Star, + CPP14Lexer::And, + CPP14Lexer::AndAnd, + CPP14Lexer::LeftBracket, + CPP14Lexer::Ellipsis, + CPP14Lexer::Doublecolon, + CPP14Lexer::Semi, }; // For a C++ grammar you can of course get many candidates of all kind. For @@ -62,43 +69,83 @@ TEST(CPP14Parser, SimpleExample) { // NOLINT: complexity EXPECT_THAT( Keys(candidates.tokens), UnorderedElementsAre( - CPP14Lexer::Extern, CPP14Lexer::Mutable, CPP14Lexer::Register, CPP14Lexer::Static, - CPP14Lexer::Thread_local, CPP14Lexer::Decltype, CPP14Lexer::Char, CPP14Lexer::Char16, - CPP14Lexer::Char32, CPP14Lexer::Wchar, CPP14Lexer::Bool, CPP14Lexer::Short, - CPP14Lexer::Int, CPP14Lexer::Long, CPP14Lexer::Signed, CPP14Lexer::Unsigned, - CPP14Lexer::Float, CPP14Lexer::Double, CPP14Lexer::Void, CPP14Lexer::Auto, - CPP14Lexer::Class, CPP14Lexer::Struct, CPP14Lexer::Union, CPP14Lexer::Enum, - CPP14Lexer::Typename, CPP14Lexer::Const, CPP14Lexer::Volatile, CPP14Lexer::Explicit, - CPP14Lexer::Inline, CPP14Lexer::Virtual, CPP14Lexer::Friend, CPP14Lexer::Typedef, - CPP14Lexer::Constexpr, CPP14Lexer::Alignas, CPP14Lexer::Asm, CPP14Lexer::Namespace, - CPP14Lexer::Using, CPP14Lexer::Static_assert, CPP14Lexer::Template, CPP14Lexer::EOF + CPP14Lexer::Extern, + CPP14Lexer::Mutable, + CPP14Lexer::Register, + CPP14Lexer::Static, + CPP14Lexer::Thread_local, + CPP14Lexer::Decltype, + CPP14Lexer::Char, + CPP14Lexer::Char16, + CPP14Lexer::Char32, + CPP14Lexer::Wchar, + CPP14Lexer::Bool, + CPP14Lexer::Short, + CPP14Lexer::Int, + CPP14Lexer::Long, + CPP14Lexer::Signed, + CPP14Lexer::Unsigned, + CPP14Lexer::Float, + CPP14Lexer::Double, + CPP14Lexer::Void, + CPP14Lexer::Auto, + CPP14Lexer::Class, + CPP14Lexer::Struct, + CPP14Lexer::Union, + CPP14Lexer::Enum, + CPP14Lexer::Typename, + CPP14Lexer::Const, + CPP14Lexer::Volatile, + CPP14Lexer::Explicit, + CPP14Lexer::Inline, + CPP14Lexer::Virtual, + CPP14Lexer::Friend, + CPP14Lexer::Typedef, + CPP14Lexer::Constexpr, + CPP14Lexer::Alignas, + CPP14Lexer::Asm, + CPP14Lexer::Namespace, + CPP14Lexer::Using, + CPP14Lexer::Static_assert, + CPP14Lexer::Template, + CPP14Lexer::EOF ) ); EXPECT_THAT( - Keys(candidates.rules), UnorderedElementsAre( - CPP14Parser::RuleClassname, CPP14Parser::RuleNamespacename, - CPP14Parser::RuleIdexpression - ) + Keys(candidates.rules), + UnorderedElementsAre( + CPP14Parser::RuleClassname, + CPP14Parser::RuleNamespacename, + CPP14Parser::RuleIdexpression + ) ); EXPECT_THAT( candidates.rules[CPP14Parser::RuleNamespacename].ruleList, ElementsAre( - CPP14Parser::RuleTranslationunit, CPP14Parser::RuleDeclarationseq, - CPP14Parser::RuleDeclaration, CPP14Parser::RuleFunctiondefinition, - CPP14Parser::RuleDeclarator, CPP14Parser::RulePtrdeclarator, - CPP14Parser::RulePtroperator, CPP14Parser::RuleNestednamespecifier + CPP14Parser::RuleTranslationunit, + CPP14Parser::RuleDeclarationseq, + CPP14Parser::RuleDeclaration, + CPP14Parser::RuleFunctiondefinition, + CPP14Parser::RuleDeclarator, + CPP14Parser::RulePtrdeclarator, + CPP14Parser::RulePtroperator, + CPP14Parser::RuleNestednamespecifier ) ); EXPECT_THAT( candidates.rules[CPP14Parser::RuleClassname].ruleList, ElementsAre( - CPP14Parser::RuleTranslationunit, CPP14Parser::RuleDeclarationseq, - CPP14Parser::RuleDeclaration, CPP14Parser::RuleFunctiondefinition, - CPP14Parser::RuleDeclarator, CPP14Parser::RulePtrdeclarator, - CPP14Parser::RulePtroperator, CPP14Parser::RuleNestednamespecifier, + CPP14Parser::RuleTranslationunit, + CPP14Parser::RuleDeclarationseq, + CPP14Parser::RuleDeclaration, + CPP14Parser::RuleFunctiondefinition, + CPP14Parser::RuleDeclarator, + CPP14Parser::RulePtrdeclarator, + CPP14Parser::RulePtroperator, + CPP14Parser::RuleNestednamespecifier, CPP14Parser::RuleTypename ) ); @@ -150,10 +197,12 @@ TEST(CPP14Parser, SimpleExample) { // NOLINT: complexity }; EXPECT_THAT( - Keys(candidates.rules), UnorderedElementsAre( - CPP14Parser::RuleClassname, CPP14Parser::RuleNamespacename, - CPP14Parser::RuleIdexpression - ) + Keys(candidates.rules), + UnorderedElementsAre( + CPP14Parser::RuleClassname, + CPP14Parser::RuleNamespacename, + CPP14Parser::RuleIdexpression + ) ); EXPECT_THAT( @@ -196,17 +245,18 @@ TEST(CPP14Parser, SimpleExample) { // NOLINT: complexity EXPECT_EQ(candidates.tokens.size(), 82); EXPECT_THAT( - Keys(candidates.tokens), IsSupersetOf({ - CPP14Lexer::If, - CPP14Lexer::This, - CPP14Lexer::New, - CPP14Lexer::Case, - CPP14Lexer::While, - CPP14Lexer::Throw, - // Fixing issue #12 causes this to be included that was - // previously not returned - CPP14Lexer::Decltype, - }) + Keys(candidates.tokens), + IsSupersetOf({ + CPP14Lexer::If, + CPP14Lexer::This, + CPP14Lexer::New, + CPP14Lexer::Case, + CPP14Lexer::While, + CPP14Lexer::Throw, + // Fixing issue #12 causes this to be included that was + // previously not returned + CPP14Lexer::Decltype, + }) ); EXPECT_FALSE(candidates.tokens.contains(CPP14Lexer::Override)); @@ -311,10 +361,17 @@ TEST(CPP14Parser, RealCppFile) { // NOLINT: complexity // Ignore operators and the generic ID token. completion.ignoredTokens = { - CPP14Lexer::Identifier, CPP14Lexer::LeftParen, CPP14Lexer::RightParen, - CPP14Lexer::Operator, CPP14Lexer::Star, CPP14Lexer::And, - CPP14Lexer::AndAnd, CPP14Lexer::LeftBracket, CPP14Lexer::Ellipsis, - CPP14Lexer::Doublecolon, CPP14Lexer::Semi, + CPP14Lexer::Identifier, + CPP14Lexer::LeftParen, + CPP14Lexer::RightParen, + CPP14Lexer::Operator, + CPP14Lexer::Star, + CPP14Lexer::And, + CPP14Lexer::AndAnd, + CPP14Lexer::LeftBracket, + CPP14Lexer::Ellipsis, + CPP14Lexer::Doublecolon, + CPP14Lexer::Semi, }; completion.preferredRules = { @@ -366,10 +423,12 @@ TEST(CPP14Parser, RealCppFile) { // NOLINT: complexity auto candidates = completion.collectCandidates(3469); // NOLINT: magic EXPECT_THAT( - Keys(candidates.rules), UnorderedElementsAre( - CPP14Parser::RuleClassname, CPP14Parser::RuleNamespacename, - CPP14Parser::RuleIdexpression - ) + Keys(candidates.rules), + UnorderedElementsAre( + CPP14Parser::RuleClassname, + CPP14Parser::RuleNamespacename, + CPP14Parser::RuleIdexpression + ) ); EXPECT_THAT( diff --git a/ports/cpp/test/expr/ExprTest.cpp b/ports/cpp/test/expr/ExprTest.cpp index dd251fd..c3ff7ec 100644 --- a/ports/cpp/test/expr/ExprTest.cpp +++ b/ports/cpp/test/expr/ExprTest.cpp @@ -61,10 +61,14 @@ TEST(SimpleExpressionParser, MostSimpleSetup) { // candidates, but we have not set up the c3 engine yet to not return them. auto candidates = completion.collectCandidates(8); // NOLINT: magic EXPECT_THAT( - Keys(candidates.tokens), UnorderedElementsAre( - ExprLexer::PLUS, ExprLexer::MINUS, ExprLexer::MULTIPLY, - ExprLexer::DIVIDE, ExprLexer::OPEN_PAR - ) + Keys(candidates.tokens), + UnorderedElementsAre( + ExprLexer::PLUS, + ExprLexer::MINUS, + ExprLexer::MULTIPLY, + ExprLexer::DIVIDE, + ExprLexer::OPEN_PAR + ) ); } } @@ -76,8 +80,12 @@ TEST(SimpleExpressionParser, TypicalSetup) { c3::CodeCompletionCore completion(&pipeline.parser); completion.ignoredTokens = { - ExprLexer::ID, ExprLexer::PLUS, ExprLexer::MINUS, - ExprLexer::MULTIPLY, ExprLexer::DIVIDE, ExprLexer::EQUAL, + ExprLexer::ID, + ExprLexer::PLUS, + ExprLexer::MINUS, + ExprLexer::MULTIPLY, + ExprLexer::DIVIDE, + ExprLexer::EQUAL, }; completion.preferredRules = { ExprParser::RuleFunctionRef, diff --git a/ports/cpp/test/utility/AntlrPipeline.hpp b/ports/cpp/test/utility/AntlrPipeline.hpp index c9afda7..aa7d205 100644 --- a/ports/cpp/test/utility/AntlrPipeline.hpp +++ b/ports/cpp/test/utility/AntlrPipeline.hpp @@ -16,8 +16,12 @@ namespace c3::test { class CountingErrorListener final : public antlr4::BaseErrorListener { public: void syntaxError( - antlr4::Recognizer* /*recognizer*/, antlr4::Token* /*offendingSymbol*/, std::size_t /*line*/, - std::size_t /*charPositionInLine*/, const std::string& /*msg*/, std::exception_ptr /*e*/ + antlr4::Recognizer* /*recognizer*/, + antlr4::Token* /*offendingSymbol*/, + std::size_t /*line*/, + std::size_t /*charPositionInLine*/, + const std::string& /*msg*/, + std::exception_ptr /*e*/ ) override { errorCount += 1; } diff --git a/ports/cpp/test/whitebox/WhiteboxTest.cpp b/ports/cpp/test/whitebox/WhiteboxTest.cpp index 29e160b..42c7d42 100644 --- a/ports/cpp/test/whitebox/WhiteboxTest.cpp +++ b/ports/cpp/test/whitebox/WhiteboxTest.cpp @@ -27,10 +27,14 @@ TEST(WhiteboxGrammarTests, CaretAtTransitionToRuleWithNonExhaustiveFollowSet) { auto candidates = completion.collectCandidates(1, ctx); EXPECT_THAT( - Keys(candidates.tokens), UnorderedElementsAre( - WhiteboxLexer::IPSUM, WhiteboxLexer::DOLOR, WhiteboxLexer::SIT, - WhiteboxLexer::AMET, WhiteboxLexer::CONSECTETUR - ) + Keys(candidates.tokens), + UnorderedElementsAre( + WhiteboxLexer::IPSUM, + WhiteboxLexer::DOLOR, + WhiteboxLexer::SIT, + WhiteboxLexer::AMET, + WhiteboxLexer::CONSECTETUR + ) ); } @@ -44,10 +48,14 @@ TEST(WhiteboxGrammarTests, CaretAtTransitionToRuleWithEmptyFollowSet) { auto candidates = completion.collectCandidates(1, ctx); EXPECT_THAT( - Keys(candidates.tokens), UnorderedElementsAre( - WhiteboxLexer::IPSUM, WhiteboxLexer::DOLOR, WhiteboxLexer::SIT, - WhiteboxLexer::AMET, WhiteboxLexer::CONSECTETUR - ) + Keys(candidates.tokens), + UnorderedElementsAre( + WhiteboxLexer::IPSUM, + WhiteboxLexer::DOLOR, + WhiteboxLexer::SIT, + WhiteboxLexer::AMET, + WhiteboxLexer::CONSECTETUR + ) ); }