feat(switch): 新增 switch 语句并禁止 match 内 fallthrough
- vast/Nodes.py:Match 增加 is_switch 字段(含默认值) - vast/Parser.py:新增 _ParseSwitch(case <常量|枚举变体> / default:,desugar 为 Match(is_switch=True));match / struct / fallthrough 改为硬关键字 - vast/Unparser.py:round-trip 忠实还原 switch 与 default: - HandlesMatch / HandlesBody:新增 in_switch_case 门控,fallthrough 只允许出现在 switch 的 case 体内 - HandlesFor:补齐嵌套函数的 saved_loop_break/continue_targets 定义(修 NameError),并隔离 in_switch_case - LLVMCG/BaseGen:新增 in_switch_case 状态
This commit is contained in:
1 parent
8b6c36d24f
commit
74cfaeb917
7 files changed
+187
-97
No files matched your search
@@ -350,6 +350,10 @@ class BaseGenMixin:
|
||||
self.class_member_annotations: dict[str, dict[str, Any]] = {}
|
||||
self.loop_break_targets: list[ir.Block] = []
|
||||
self.loop_continue_targets: list[ir.Block] = []
|
||||
# 当前是否正处于 switch 的 case 语句体内(True=是)。供 `fallthrough`
|
||||
# 标记语句(vast 脱糖为 c.NoBreak())判定合法性:只在 switch 的 case 体内
|
||||
# 合法;写进 match(完全禁止 fallthrough)或 switch 之外一律 fail-fast。
|
||||
self.in_switch_case: bool = False
|
||||
self.eh_jmp_buf_stack: list[ir.Value] = []
|
||||
self.eh_except_block_stack: list[ir.Block] = []
|
||||
self.eh_finally_stack: list[Any] = []
|
||||
|
||||
Reference in new issue
Block a user