Skip to content

Commit

Permalink
#132 Format BinPackParameters false
Browse files Browse the repository at this point in the history
Signed-off-by: vityaman <[email protected]>
  • Loading branch information
vityaman authored and mike-lischke committed Jul 31, 2024
1 parent 91f7aa7 commit 32a793c
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 84 deletions.
3 changes: 3 additions & 0 deletions ports/cpp/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ AllowShortLoopsOnASingleLine: false
DerivePointerAlignment: false
BreakConstructorInitializers: BeforeComma
AlignAfterOpenBracket: BlockIndent

BinPackArguments: false
BinPackParameters: false
50 changes: 37 additions & 13 deletions ports/cpp/source/antlr4-c3/CodeCompletionCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,19 @@ std::map<std::type_index, FollowSetsPerState> // NOLINT
// Matches ATNStateType enum
std::vector<std::string> 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)
Expand All @@ -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<bool>* cancel
) {
shortcutMap.clear();
Expand Down Expand Up @@ -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<FollowSetWithPath>& followSets, std::vector<antlr4::atn::ATNState*>& stateStack,
antlr4::atn::ATNState* state,
antlr4::atn::ATNState* stopState,
std::vector<FollowSetWithPath>& followSets,
std::vector<antlr4::atn::ATNState*>& stateStack,
std::vector<size_t>& ruleStack
) {
if (std::find(stateStack.begin(), stateStack.end(), state) != stateStack.end()) {
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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) {
Expand All @@ -643,8 +661,12 @@ RuleEndStatus CodeCompletionCore::processRule( // NOLINT
auto* ruleStartState = dynamic_cast<antlr4::atn::RuleStartState*>(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;
Expand Down Expand Up @@ -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, ' ');
Expand Down
22 changes: 16 additions & 6 deletions ports/cpp/source/antlr4-c3/CodeCompletionCore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>* cancel = nullptr
);

Expand Down Expand Up @@ -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<FollowSetWithPath>& followSets, std::vector<antlr4::atn::ATNState*>& stateStack,
antlr4::atn::ATNState* state,
antlr4::atn::ATNState* stopState,
std::vector<FollowSetWithPath>& followSets,
std::vector<antlr4::atn::ATNState*>& stateStack,
std::vector<size_t>& 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
);

Expand Down
157 changes: 108 additions & 49 deletions ports/cpp/test/cpp14/Cpp14Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 14 additions & 6 deletions ports/cpp/test/expr/ExprTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
}
}
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 32a793c

Please sign in to comment.