2023-03-13 14:15:36 +01:00
|
|
|
package io.gitlab.jfronny.muscript.ast.dynamic.assign;
|
2023-01-20 21:05:04 +01:00
|
|
|
|
2023-03-13 14:15:36 +01:00
|
|
|
import io.gitlab.jfronny.muscript.ast.BoolExpr;
|
|
|
|
import io.gitlab.jfronny.muscript.compiler.ExprWriter;
|
|
|
|
import io.gitlab.jfronny.muscript.compiler.Order;
|
2023-01-20 21:05:04 +01:00
|
|
|
import io.gitlab.jfronny.muscript.data.Scope;
|
2023-03-11 13:39:17 +01:00
|
|
|
import io.gitlab.jfronny.muscript.error.LocationalException;
|
2023-01-20 21:05:04 +01:00
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2023-03-13 14:15:36 +01:00
|
|
|
public class BoolAssign extends BoolExpr {
|
2023-01-20 21:05:04 +01:00
|
|
|
private final String name;
|
2023-03-13 14:15:36 +01:00
|
|
|
private final BoolExpr value;
|
2023-01-20 21:05:04 +01:00
|
|
|
|
2023-03-13 14:15:36 +01:00
|
|
|
protected BoolAssign(int chStart, int chEnd, String name, BoolExpr value) {
|
2023-03-12 15:28:44 +01:00
|
|
|
super(Order.Primary, chStart, chEnd);
|
2023-03-11 13:39:17 +01:00
|
|
|
if (name.equals("this")) throw new LocationalException(chStart, chEnd, "Cannot reassign 'this'");
|
2023-01-20 21:05:04 +01:00
|
|
|
this.name = name;
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-03-13 14:15:36 +01:00
|
|
|
public Boolean get(Scope dataRoot) {
|
|
|
|
boolean data = value.get(dataRoot);
|
2023-01-20 21:05:04 +01:00
|
|
|
dataRoot.set(name, data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-03-13 14:15:36 +01:00
|
|
|
public BoolExpr optimize() {
|
|
|
|
return new BoolAssign(chStart, chEnd, name, value.optimize());
|
2023-01-20 21:05:04 +01:00
|
|
|
}
|
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
@Override
|
|
|
|
public void decompile(ExprWriter writer) throws IOException {
|
2023-03-12 16:16:27 +01:00
|
|
|
writer.appendLiteral(name).append(" = ");
|
2023-03-12 15:28:44 +01:00
|
|
|
value.decompile(writer);
|
|
|
|
}
|
|
|
|
|
2023-01-20 21:05:04 +01:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
2023-03-13 14:15:36 +01:00
|
|
|
return obj instanceof BoolAssign assign
|
2023-01-20 21:05:04 +01:00
|
|
|
&& name.equals(assign.name)
|
|
|
|
&& value.equals(assign.value);
|
|
|
|
}
|
|
|
|
}
|