feat: 支持 Struct 多构造函数降级
- 修改 lowerAndRegisterStruct 方法以支持多个构造函数 - 为每个构造函数生成独立的降级版本,命名格式为 StructName.__init__N
This commit is contained in:
parent
5f6751b3d4
commit
4ac95dd5ef
@ -138,9 +138,9 @@ public final class IRProgramBuilder {
|
|||||||
// ===================== Struct 降级:方法/构造 → 普通函数 =====================
|
// ===================== Struct 降级:方法/构造 → 普通函数 =====================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将一个 Struct 的构造函数(init)和方法(methods)降级为普通 Function,并注册进 IRProgram:
|
* 将一个 Struct 的所有构造函数(inits)和方法(methods)降级为普通 Function,并注册进 IRProgram:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>构造函数:StructName.__init__(this:StructName, ...)</li>
|
* <li>构造函数:StructName.__init__N(this:StructName, ...),N为参数个数</li>
|
||||||
* <li>方法:StructName.method(this:StructName, ...)</li>
|
* <li>方法:StructName.method(this:StructName, ...)</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* <p>降级规则:</p>
|
* <p>降级规则:</p>
|
||||||
@ -155,17 +155,20 @@ public final class IRProgramBuilder {
|
|||||||
private void lowerAndRegisterStruct(StructNode structNode, IRProgram out) {
|
private void lowerAndRegisterStruct(StructNode structNode, IRProgram out) {
|
||||||
String structName = structNode.name();
|
String structName = structNode.name();
|
||||||
|
|
||||||
// 1) 降级处理构造函数(如有)
|
// 1. 多构造函数:降级为 StructName.__init__N
|
||||||
if (structNode.init() != null) {
|
if (structNode.inits() != null) {
|
||||||
FunctionNode loweredInit = lowerStructCallable(
|
for (FunctionNode initFn : structNode.inits()) {
|
||||||
structNode.init(),
|
String loweredName = structName + ".__init__" + initFn.parameters().size();
|
||||||
structName + ".__init__",
|
FunctionNode loweredInit = lowerStructCallable(
|
||||||
structName
|
initFn,
|
||||||
);
|
loweredName,
|
||||||
out.add(buildFunction(loweredInit));
|
structName
|
||||||
|
);
|
||||||
|
out.add(buildFunction(loweredInit));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) 降级处理所有普通方法
|
// 2. 降级处理所有普通方法
|
||||||
if (structNode.methods() != null) {
|
if (structNode.methods() != null) {
|
||||||
for (FunctionNode m : structNode.methods()) {
|
for (FunctionNode m : structNode.methods()) {
|
||||||
FunctionNode loweredMethod = lowerStructCallable(
|
FunctionNode loweredMethod = lowerStructCallable(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user