feat: 增强结构体打印细节
- 添加结构体继承关系打印 - 优化字段、构造函数和方法的打印顺序 - 改进打印格式,提高可读性
This commit is contained in:
parent
808403e8e8
commit
6428ba5cbd
@ -62,16 +62,36 @@ public class ASTPrinter {
|
|||||||
for (ImportNode imp : m.imports()) {
|
for (ImportNode imp : m.imports()) {
|
||||||
System.out.println(pad + " import " + imp.moduleName());
|
System.out.println(pad + " import " + imp.moduleName());
|
||||||
}
|
}
|
||||||
|
for (StructNode s : m.structs()) {
|
||||||
|
print(s, indent + 1);
|
||||||
|
}
|
||||||
for (FunctionNode fn : m.functions()) {
|
for (FunctionNode fn : m.functions()) {
|
||||||
print(fn, indent + 1);
|
print(fn, indent + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case StructNode s -> {
|
case StructNode s -> {
|
||||||
System.out.println(pad + "struct " + s.name());
|
System.out.print(pad + "struct " + s.name());
|
||||||
s.fields().forEach(f -> print(f, indent + 1));
|
if (s.parent() != null && !s.parent().isEmpty()) {
|
||||||
if (s.init() != null) print(s.init(), indent + 1);
|
System.out.print(" extends " + s.parent());
|
||||||
s.methods().forEach(m -> print(m, indent + 1));
|
}
|
||||||
|
System.out.println();
|
||||||
|
for (DeclarationNode f : s.fields()) {
|
||||||
|
print(f, indent + 1);
|
||||||
|
}
|
||||||
|
// 打印所有构造函数 inits
|
||||||
|
if (s.inits() != null && !s.inits().isEmpty()) {
|
||||||
|
for (FunctionNode ctor : s.inits()) {
|
||||||
|
System.out.println(pad + " [init]");
|
||||||
|
print(ctor, indent + 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 打印所有方法
|
||||||
|
if (s.methods() != null && !s.methods().isEmpty()) {
|
||||||
|
for (FunctionNode m : s.methods()) {
|
||||||
|
print(m, indent + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case FunctionNode(
|
case FunctionNode(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user