Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp_parse_function only works for functions with one argument #118

Closed
aolo2 opened this issue Dec 25, 2019 · 2 comments
Closed

cpp_parse_function only works for functions with one argument #118

aolo2 opened this issue Dec 25, 2019 · 2 comments

Comments

@aolo2
Copy link

aolo2 commented Dec 25, 2019

In cpp_parse_function comma and semicolon are both accepted as the end of the function declaration/definiton, because of this check:

if (peek->kind == TokenBaseKind_ParentheticalOpen ||
                     peek->kind == TokenBaseKind_ScopeOpen ||
                     peek->kind == TokenBaseKind_ScopeClose ||
                     peek->kind == TokenBaseKind_StatementClose) {
    break;
}

This causes the the code index to ignore functions with > 1 arguments, partially breaking jump_to_definition.

The fix is a simple

... && peek->sub_kind == TokenCppKind_Semicolon
@aolo2
Copy link
Author

aolo2 commented Dec 29, 2019

In the same vein, cpp_parse_function currently thinks that function definition is over when it sees any of:

TokenBaseKind_ScopeOpen,
TokenBaseKind_ScopeClose,
TokenBaseKind_ParentheticalOpen,
TokenBaseKind_ParentheticalClose,
TokenBaseKind_StatementClose

However, this doesn't support function pointer arguments, as well as some other stuff, like C++ default values for struct arguments, e.g.:

void foo(Bar bar = { 1, 2, 3 })

An easier and more correct way of handling function declarations/definitions would be to track the parenthesis balance: the declaration/definition is over when the first opening parenthesis is closed:

scope_balance = 1;
for (peek in tokens) {
    if (peek->kind == TokenBaseKind_ParentheticalOpen) { ++scope_balance; }
    if (peek->kind == TokenBaseKind_ParentheticalClose) { --scope_balance; }
    if (scope_balance == 0) { at_paren_close = true; break; }
}

@4coder-editor
Copy link
Owner

4coder-editor commented Jan 12, 2020

Thanks for the report, I used your suggestion for paren balancing and it looks like it's working. The fix is in the patch 4.1.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants