Skip to content

feat(parser): nested struct/union decl #516

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

Merged
merged 11 commits into from
Jul 18, 2025

Conversation

luoliwoshang
Copy link
Member

@luoliwoshang luoliwoshang commented Jul 17, 2025

fix #507 #517 #514

  • fetch all level nested named struct/union to flat order
    • filter empty decl(forward decl)
  • keep correct refer order so the inner struct 's order need before the outer node

Problem Statement

Before this fix, the parser had several critical issues with nested named structs/unions:

  1. Missing Definitions: Nested named structs/unions were only generated as tagExpr references without actual type
    definitions
  2. Incorrect Ordering: libclang returns AST nodes in preorder traversal, but correct reference ordering requires
    postorder traversal
  3. Forward Declarations: Empty/forward declarations were included in the AST, causing compilation issues

Example Problem Case

struct a {
    struct b {
        struct c {
            int a;
        } c_field;
        struct d {
            int b;
        } d_field;
    } b_field;
    struct e {
        struct f {
            int b;
        } f_field;
    } e_field;
};

Before Fix: Only references to struct b, struct c, struct d, struct e, struct f were generated without their actual
definitions.

After Fix: All nested structs are properly defined with correct dependency ordering.

solution

  1. Fetch All Level Nested Named Struct/Union to Flat Order
  2. Filter Empty Declarations (Forward Declarations)
  3. Maintain Correct Reference Order (Postorder Traversal)

Expected AST Node Order

For the example above, the correct postorder should be:
[c, d, b, f, e, a]

This ensures that:

  • c and d are defined before b (which contains them)
  • f is defined before e (which contains it)
  • b and e are defined before a (which contains them)

All test cases pass, including:

@luoliwoshang luoliwoshang force-pushed the parser/nested branch 2 times, most recently from 4f73aba to fb35aa6 Compare July 18, 2025 02:58
@luoliwoshang luoliwoshang changed the title parser:nested struct decl [wip] parser:nested struct decl Jul 18, 2025
@luoliwoshang luoliwoshang force-pushed the parser/nested branch 2 times, most recently from 81741ca to 6f5bdcb Compare July 18, 2025 08:45
Copy link

codecov bot commented Jul 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.20%. Comparing base (23c8a9e) to head (c269b9f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #516   +/-   ##
=======================================
  Coverage   84.20%   84.20%           
=======================================
  Files          27       27           
  Lines        2747     2747           
=======================================
  Hits         2313     2313           
  Misses        391      391           
  Partials       43       43           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@luoliwoshang luoliwoshang changed the title [wip] parser:nested struct decl [wip] parser:nested struct/union decl Jul 18, 2025
@luoliwoshang luoliwoshang force-pushed the parser/nested branch 5 times, most recently from b5360c8 to 7dfbe9a Compare July 18, 2025 10:13
@luoliwoshang luoliwoshang changed the title [wip] parser:nested struct/union decl parser:nested struct/union decl Jul 18, 2025
@luoliwoshang luoliwoshang changed the title parser:nested struct/union decl feat(parser): nested struct/union decl Jul 18, 2025
@MeteorsLiu MeteorsLiu merged commit 3f82aa9 into goplus:main Jul 18, 2025
12 checks passed
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

Successfully merging this pull request may close these issues.

panic: nil underlying (complex union)
2 participants