feat: 为结构体添加继承功能
- 在 StructNode 中添加 parent 参数,用于表示父类名称 - 更新 toString 方法以包含 parent 信息 - 优化类注释,移除冗余信息并增加对继承特性的说明
This commit is contained in:
parent
8bc431091c
commit
8ff103e105
@ -16,24 +16,9 @@ import java.util.StringJoiner;
|
|||||||
* 描述一个结构体类型,包括字段、可选构造函数、方法列表等。
|
* 描述一个结构体类型,包括字段、可选构造函数、方法列表等。
|
||||||
* 结构体可声明零个或多个字段,可选构造函数(init),
|
* 结构体可声明零个或多个字段,可选构造函数(init),
|
||||||
* 以及零个或多个方法。
|
* 以及零个或多个方法。
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* 字段说明:
|
|
||||||
* <ul>
|
|
||||||
* <li>{@code name} —— 结构体名称,类型定义的唯一标识。</li>
|
|
||||||
* <li>{@code fields} —— 字段声明列表,每个字段为 {@link DeclarationNode}。</li>
|
|
||||||
* <li>{@code init} —— 构造函数(FunctionNode),可为 null。</li>
|
|
||||||
* <li>{@code methods} —— 方法列表,每个为 {@link FunctionNode},可空列表。</li>
|
|
||||||
* <li>{@code context} —— 源代码位置信息(行号、文件名等)。</li>
|
|
||||||
* </ul>
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* 本类型为 Java record,不可变;构造参数即为字段名,自动生成 getter。
|
|
||||||
* </p>
|
|
||||||
*
|
*
|
||||||
* @param name 结构体名称
|
* @param name 结构体名称
|
||||||
|
* @param parent 父类名称(无继承时为 {@code null})
|
||||||
* @param fields 字段声明列表
|
* @param fields 字段声明列表
|
||||||
* @param init 构造函数(可为 null)
|
* @param init 构造函数(可为 null)
|
||||||
* @param methods 方法列表
|
* @param methods 方法列表
|
||||||
@ -41,6 +26,7 @@ import java.util.StringJoiner;
|
|||||||
*/
|
*/
|
||||||
public record StructNode(
|
public record StructNode(
|
||||||
String name,
|
String name,
|
||||||
|
String parent,
|
||||||
List<DeclarationNode> fields,
|
List<DeclarationNode> fields,
|
||||||
FunctionNode init,
|
FunctionNode init,
|
||||||
List<FunctionNode> methods,
|
List<FunctionNode> methods,
|
||||||
@ -64,6 +50,7 @@ public record StructNode(
|
|||||||
|
|
||||||
// 3) 合成最终输出
|
// 3) 合成最终输出
|
||||||
return "Struct(name=" + name +
|
return "Struct(name=" + name +
|
||||||
|
", parent=" + (parent == null ? "null" : parent) +
|
||||||
", fields=[" + fj + "], init=" +
|
", fields=[" + fj + "], init=" +
|
||||||
(init == null ? "null" : init.name()) +
|
(init == null ? "null" : init.name()) +
|
||||||
", methods=[" + mj + "])";
|
", methods=[" + mj + "])";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user