digitalmars.D - [SAOC 2024] Separate Semantic Routines from AST Nodes. - Weekly Update
- Dennis (49/49) Oct 27 ## Tasks for the week(Oct.21th-Oct.27th)
- I started this week by figuring out which of the `include` visitor methods was problematic. I used the strategy which I mentioned in last week’s report. After the debugging I figured out that the StaticIfDeclaration was problematic because there was an incorrect cast to the ConditionalDeclaration. **Initial snippet** ``` Dsymbols* d = include(cast(ConditionalDeclaration)sif, sif._scope); ``` This is what happens here, the cast is ignored when calling include because include expects an AttribDeclaration. It then uses a visitor pattern to reach the appropriate visit override, but this results in the StaticIfDeclaration override being called instead of ConditionalDeclaration. So to effect the change the original scope (sc) was saved into saved_scope temporalily, the scope was then changed to sif._scope, which represents the scope of the sif (StaticIfDeclaration). It processes the sif_scope by treating it like a `ConditionalDeclaration` stores the result in the `symbols` and restores the original scope without altering any behaviour. https://github.com/dlang/dmd/pull/16970/files/ed00ce2cfcd85eb0ff2dff45357e8c94c8013cd5#diff-862192b33df815981dcb4a8a49bc7dc572506b444a7dc034fde3643f887e2982 **Refactored snippet** ``` Scope* saved_scope = sc; sc = sif._scope; visit(cast(ConditionalDeclaration) sif); Dsymbols* d = symbols; sc = saved_scope; ``` - To make the unittest and CI pass successfully, I did the following things - Updated the `cxxfrontend.cc` with a refactored free function call. - Updated `frontend.h` using this Command `./build.d cxx-headers-test AUTO_UPDATE=1` - Updates `dsymbol.h` with the include signature `Dsymbols *include(Dsymbol *d, Scope *sc);` - Added a Wrapper for the include method in cxxfrontend.d to reflect the update in dmd namespace block in `dsymbol.h` **Merged PR** = [https://github.com/dlang/dmd/pull/16970](https://github.com/dlang/dmd/pull/16970) It was a week full of debugging and learning. Next will be, to fix the prepare, lowerNonArrayAggregate and lowerArrayAggregate methods in statementsem to pass the test suite and then move all semantics methods from `dclass.d` to their appropriate modules.
Oct 27