2023-01-20 18:52:57 +01:00
|
|
|
package io.gitlab.jfronny.muscript.ast;
|
2022-06-07 13:36:48 +02:00
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
import io.gitlab.jfronny.muscript.compiler.*;
|
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.data.dynamic.DNull;
|
|
|
|
import io.gitlab.jfronny.muscript.annotations.CanThrow;
|
|
|
|
import io.gitlab.jfronny.muscript.ast.literal.DynamicLiteral;
|
2022-06-29 15:41:44 +02:00
|
|
|
import io.gitlab.jfronny.muscript.error.LocationalException;
|
2022-06-07 13:36:48 +02:00
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2022-06-13 13:31:54 +02:00
|
|
|
@CanThrow
|
2022-06-07 13:36:48 +02:00
|
|
|
public final class NullLiteral extends Expr<Object> {
|
2023-01-20 17:47:41 +01:00
|
|
|
public NullLiteral(int chStart, int chEnd) {
|
2023-03-12 15:28:44 +01:00
|
|
|
super(Order.Primary, chStart, chEnd);
|
2022-06-13 13:31:54 +02:00
|
|
|
}
|
|
|
|
|
2022-06-07 13:36:48 +02:00
|
|
|
@Override
|
|
|
|
public Type getResultType() {
|
|
|
|
return Type.Dynamic;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-01-20 21:05:04 +01:00
|
|
|
public Object get(Scope dataRoot) {
|
2022-06-07 13:36:48 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-06-29 17:38:05 +02:00
|
|
|
@Override
|
|
|
|
public NullLiteral optimize() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2023-03-12 15:28:44 +01:00
|
|
|
@Override
|
|
|
|
public void decompile(ExprWriter writer) throws IOException {
|
|
|
|
writer.append("null");
|
|
|
|
}
|
|
|
|
|
2022-06-07 13:36:48 +02:00
|
|
|
@Override
|
|
|
|
public DynamicExpr asDynamicExpr() {
|
2023-01-20 17:47:41 +01:00
|
|
|
return new DynamicLiteral<>(chStart, chEnd, new DNull());
|
2022-06-13 13:31:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public NumberExpr asNumberExpr() {
|
2023-01-20 17:47:41 +01:00
|
|
|
throw new LocationalException(chStart, chEnd, "Attempted to convert null to a number");
|
2022-06-13 13:31:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StringExpr asStringExpr() {
|
2023-01-20 18:52:57 +01:00
|
|
|
return literal(chStart, chEnd, "null");
|
2022-06-13 13:31:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BoolExpr asBoolExpr() {
|
2023-01-20 17:47:41 +01:00
|
|
|
throw new LocationalException(chStart, chEnd, "Attempted to convert null to a boolean");
|
2022-06-07 13:36:48 +02:00
|
|
|
}
|
2022-06-29 17:38:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
return obj instanceof NullLiteral;
|
|
|
|
}
|
2022-06-07 13:36:48 +02:00
|
|
|
}
|