feat: 支持结构体多个构造函数
- 修改 SignatureRegistrar 类以支持结构体的多个构造函数 - 通过参数个数区分重载的构造函数 - 为每个构造函数解析参数类型并设置返回类型为 void
This commit is contained in:
parent
5367fc39f6
commit
6dc651d305
@ -54,10 +54,11 @@ public record SignatureRegistrar(Context ctx) {
|
|||||||
StructType st = new StructType(mod.name(), stn.name());
|
StructType st = new StructType(mod.name(), stn.name());
|
||||||
mi.getStructs().put(stn.name(), st);
|
mi.getStructs().put(stn.name(), st);
|
||||||
|
|
||||||
// --- 2.1 构造函数 init ---
|
// --- 2.1 多个构造函数 init(重载,按参数个数区分) ---
|
||||||
if (stn.init() != null) {
|
if (stn.inits() != null) {
|
||||||
|
for (FunctionNode initFn : stn.inits()) {
|
||||||
List<Type> ptypes = new ArrayList<>();
|
List<Type> ptypes = new ArrayList<>();
|
||||||
for (ParameterNode p : stn.init().parameters()) {
|
for (ParameterNode p : initFn.parameters()) {
|
||||||
// 解析参数类型,不存在则报错降级为 int
|
// 解析参数类型,不存在则报错降级为 int
|
||||||
Type t = ctx.parseType(p.type());
|
Type t = ctx.parseType(p.type());
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
@ -67,7 +68,8 @@ public record SignatureRegistrar(Context ctx) {
|
|||||||
ptypes.add(t);
|
ptypes.add(t);
|
||||||
}
|
}
|
||||||
// 构造函数返回类型固定为 void
|
// 构造函数返回类型固定为 void
|
||||||
st.setConstructor(new FunctionType(ptypes, BuiltinType.VOID));
|
st.addConstructor(new FunctionType(ptypes, BuiltinType.VOID));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- 2.2 结构体方法签名 ---
|
// --- 2.2 结构体方法签名 ---
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user