refactor: 重构循环语句节点的序列化逻辑
- 修改 Declaration 节点中的 initializer 字段名称为 init - 修改 If 节点中的 condition 字段名称为 cond - 修改 Loop 节点中 initializer、condition 和 update 字段名称分别为 init、cond 和 step
This commit is contained in:
parent
e2896eb37d
commit
1141abf231
@ -121,7 +121,7 @@ public class ASTJsonSerializer {
|
||||
Map<String, Object> map = newNodeMap("Declaration");
|
||||
map.put("name", d.getName());
|
||||
map.put("varType", d.getType());
|
||||
map.put("initializer", d.getInitializer().map(ASTJsonSerializer::exprToMap).orElse(null));
|
||||
map.put("init", d.getInitializer().map(ASTJsonSerializer::exprToMap).orElse(null));
|
||||
yield map;
|
||||
}
|
||||
// 赋值语句节点
|
||||
@ -132,7 +132,7 @@ public class ASTJsonSerializer {
|
||||
// 条件语句节点
|
||||
case IfNode i -> {
|
||||
Map<String, Object> map = newNodeMap("If");
|
||||
map.put("condition", exprToMap(i.condition()));
|
||||
map.put("cond", exprToMap(i.condition()));
|
||||
List<Object> thenList = new ArrayList<>(i.thenBranch().size());
|
||||
for (Node stmt : i.thenBranch()) thenList.add(nodeToMap(stmt));
|
||||
map.put("then", thenList);
|
||||
@ -146,9 +146,9 @@ public class ASTJsonSerializer {
|
||||
// 循环语句节点
|
||||
case LoopNode l -> {
|
||||
Map<String, Object> map = newNodeMap("Loop");
|
||||
map.put("initializer", l.initializer() != null ? nodeToMap(l.initializer()) : null);
|
||||
map.put("condition", l.condition() != null ? exprToMap(l.condition()) : null);
|
||||
map.put("update", l.update() != null ? nodeToMap(l.update()) : null);
|
||||
map.put("init", l.init() != null ? nodeToMap(l.init()) : null);
|
||||
map.put("cond", l.cond() != null ? exprToMap(l.cond()) : null);
|
||||
map.put("step", l.step() != null ? nodeToMap(l.step()) : null);
|
||||
List<Object> body = new ArrayList<>(l.body().size());
|
||||
for (Node stmt : l.body()) body.add(nodeToMap(stmt));
|
||||
map.put("body", body);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user