63 lines
1.5 KiB
Java
63 lines
1.5 KiB
Java
package io.gitlab.jfronny.muscript.ast;
|
|
|
|
import io.gitlab.jfronny.muscript.compiler.*;
|
|
import io.gitlab.jfronny.muscript.data.Scope;
|
|
import io.gitlab.jfronny.muscript.data.dynamic.DNull;
|
|
import io.gitlab.jfronny.muscript.annotations.CanThrow;
|
|
import io.gitlab.jfronny.muscript.ast.literal.DynamicLiteral;
|
|
import io.gitlab.jfronny.muscript.error.LocationalException;
|
|
|
|
import java.io.IOException;
|
|
|
|
@CanThrow
|
|
public final class NullLiteral extends Expr<Object> {
|
|
public NullLiteral(int chStart, int chEnd) {
|
|
super(Order.Primary, chStart, chEnd);
|
|
}
|
|
|
|
@Override
|
|
public Type getResultType() {
|
|
return Type.Dynamic;
|
|
}
|
|
|
|
@Override
|
|
public Object get(Scope dataRoot) {
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public NullLiteral optimize() {
|
|
return this;
|
|
}
|
|
|
|
@Override
|
|
public void decompile(ExprWriter writer) throws IOException {
|
|
writer.append("null");
|
|
}
|
|
|
|
@Override
|
|
public DynamicExpr asDynamicExpr() {
|
|
return new DynamicLiteral<>(chStart, chEnd, new DNull());
|
|
}
|
|
|
|
@Override
|
|
public NumberExpr asNumberExpr() {
|
|
throw new LocationalException(chStart, chEnd, "Attempted to convert null to a number");
|
|
}
|
|
|
|
@Override
|
|
public StringExpr asStringExpr() {
|
|
return literal(chStart, chEnd, "null");
|
|
}
|
|
|
|
@Override
|
|
public BoolExpr asBoolExpr() {
|
|
throw new LocationalException(chStart, chEnd, "Attempted to convert null to a boolean");
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
return obj instanceof NullLiteral;
|
|
}
|
|
}
|