2023-01-20 18:52:57 +01:00
|
|
|
package io.gitlab.jfronny.muscript.ast.literal;
|
2022-06-07 13:36:48 +02:00
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
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-01-20 18:52:57 +01:00
|
|
|
import io.gitlab.jfronny.muscript.ast.BoolExpr;
|
2022-06-07 13:36:48 +02:00
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2022-06-07 13:36:48 +02:00
|
|
|
public final class BoolLiteral extends BoolExpr {
|
2022-06-29 17:38:05 +02:00
|
|
|
public final boolean value;
|
2022-06-07 13:36:48 +02:00
|
|
|
|
2023-01-20 17:47:41 +01:00
|
|
|
public BoolLiteral(int chStart, int chEnd, boolean value) {
|
2023-03-12 15:28:44 +01:00
|
|
|
super(Order.Primary, chStart, chEnd);
|
2022-06-07 13:36:48 +02:00
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-20 21:05:04 +01:00
|
|
|
public Boolean get(Scope dataRoot) {
|
2022-06-07 13:36:48 +02:00
|
|
|
return value;
|
|
|
|
}
|
2022-06-29 17:38:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public BoolExpr optimize() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
@Override
|
|
|
|
public void decompile(ExprWriter writer) throws IOException {
|
|
|
|
writer.append(value ? "true" : "false");
|
|
|
|
}
|
|
|
|
|
2022-06-29 17:38:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
return obj instanceof BoolLiteral literal && value == literal.value;
|
|
|
|
}
|
2022-06-07 13:36:48 +02:00
|
|
|
}
|