feat(ir): Add BreakStmt and ContinueStmt IR nodes#196
feat(ir): Add BreakStmt and ContinueStmt IR nodes#196Hzfengsy merged 1 commit intohw-native-sys:mainfrom
Conversation
…w-native-sys#167) Add break and continue statement nodes for loop control flow. Both are leaf statements with no fields (only inherited Span), used inside ForStmt/WhileStmt loop bodies. Changes across all three layers: - C++ core: ObjectKind enum, class definitions, kind traits - Visitor/mutator framework: functor dispatch, visitor, mutator - IR infrastructure: printer, hash, equality, serialization - Python bindings and type stubs - Documentation: BNF grammar and statement tables - Tests: 48 tests covering creation, printing, hash, equality, serialization, immutability, and composition in loops
Summary of ChangesHello @Hzfengsy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Intermediate Representation (IR) system by adding dedicated nodes for Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces BreakStmt and ContinueStmt IR nodes, which is a great addition for loop control flow. The changes are very thorough, touching all necessary layers of the IR framework from the C++ core and visitor patterns to serialization, Python bindings, and documentation. The new tests are comprehensive and cover many important cases.
I have one suggestion regarding the new test files to improve maintainability by reducing code duplication. Overall, this is an excellent and well-executed feature addition.
There was a problem hiding this comment.
Pull request overview
This PR adds BreakStmt and ContinueStmt IR nodes to support loop control flow statements (break and continue). These are minimal leaf statement nodes with only an inherited Span field, designed for use inside ForStmt and WhileStmt loop bodies. The implementation is comprehensive and consistent, spanning all three layers of the codebase: C++ core, Python bindings, and type stubs, along with documentation and extensive test coverage.
Changes:
- Added two new IR statement node types (
BreakStmtandContinueStmt) following the established pattern for leaf statements - Updated all visitor/mutator infrastructure, serialization/deserialization, structural comparison, and printing facilities
- Provided comprehensive test coverage with 48 new tests covering basic functionality, composition, and edge cases
- Updated documentation with BNF grammar and node hierarchy tables
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
include/pypto/ir/core.h |
Added BreakStmt and ContinueStmt to ObjectKind enum |
include/pypto/ir/stmt.h |
Added BreakStmt and ContinueStmt class definitions with proper field descriptors |
include/pypto/ir/kind_traits.h |
Added KindTrait entries and updated Stmt base class trait count from 10 to 12 |
include/pypto/ir/transforms/base/functor.h |
Added functor dispatch entries for both statement types |
include/pypto/ir/transforms/base/visitor.h |
Added visitor method declarations |
include/pypto/ir/transforms/base/mutator.h |
Added mutator method declarations |
src/ir/transforms/visitor.cpp |
Added empty visitor implementations for leaf nodes |
src/ir/transforms/mutator.cpp |
Added identity mutator implementations for leaf nodes |
src/ir/transforms/python_printer.cpp |
Added printer implementations outputting "break" and "continue" |
src/ir/transforms/structural_hash.cpp |
Added hash dispatch entries |
src/ir/transforms/structural_equal.cpp |
Added equality dispatch entries |
src/ir/serialization/serializer.cpp |
Added serialization dispatch |
src/ir/serialization/type_deserializers.cpp |
Added deserialization functions and registrars |
python/bindings/modules/ir.cpp |
Added nanobind class bindings with docstrings |
python/pypto/pypto_core/ir.pyi |
Added type stub entries with complete docstrings |
docs/dev/ir/01-hierarchy.md |
Updated BNF grammar, statement table, and node count summary |
tests/ut/ir/statements/test_break_stmt.py |
Added 24 comprehensive tests (445 lines) |
tests/ut/ir/statements/test_continue_stmt.py |
Added 24 comprehensive tests (445 lines) |
Summary
Add
BreakStmtandContinueStmtIR nodes for loop control flow (breakandcontinue). Both are minimal leaf statements with no fields (only inheritedSpan), used insideForStmt/WhileStmtloop bodies.Changes across all three layers (18 files):
ObjectKindenum entries, class definitions instmt.h,KindTraitentries"break"/"continue"), structural hash, structural equality, serialization, deserializationBindFields.pyientries with docstrings01-hierarchy.mdTesting
test_break_stmt.pyandtest_continue_stmt.pycovering:python_print, structural hash, structural equalityForStmtandWhileStmtbodiesIfStmtwithin loopsRelated Issues
Closes #166
Closes #167