Skip to content

support local union, struct, and enum declarations inside functions#363

Open
paulboul1013 wants to merge 1 commit intozenc-lang:mainfrom
paulboul1013:feature-local-type-declarations-in-functions
Open

support local union, struct, and enum declarations inside functions#363
paulboul1013 wants to merge 1 commit intozenc-lang:mainfrom
paulboul1013:feature-local-type-declarations-in-functions

Conversation

@paulboul1013
Copy link
Copy Markdown

Description

This PR adds support for local struct, union, and enum declarations inside function and block scope, including main().

Before this change, Zen C already supported these declarations at top level, but parse_statement(...) did not recognize them in statement position. That meant code such as local type declarations inside main() or other function bodies could not be parsed correctly even though the rest of the pipeline already had supporting pieces for handling these nodes.

This change updates statement parsing so local struct, union, and enum declarations are accepted inside blocks. It also assigns source tokens to the generated struct/enum AST nodes so debug/source-mapping mode does not emit source mapping warnings for these local declarations.

A regression test was added to cover local type declarations in the source-mapping/codegen path.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Validation

  • make
  • bash tests/scripts/run_codegen_tests.sh
  • ./zc check tests/compiler/codegen/emit_source_mapping.zc -g --warn-errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant