69 lines
1.6 KiB
Java
69 lines
1.6 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;
|
|
import java.util.stream.Stream;
|
|
|
|
@CanThrow
|
|
public final class NullLiteral extends Expr<Object> {
|
|
public NullLiteral(CodeLocation location) {
|
|
super(Order.Primary, location);
|
|
}
|
|
|
|
@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<>(location, new DNull());
|
|
}
|
|
|
|
@Override
|
|
public Stream<Expr<?>> extractSideEffects() {
|
|
return Stream.empty();
|
|
}
|
|
|
|
@Override
|
|
public NumberExpr asNumberExpr() {
|
|
throw new LocationalException(location, "Attempted to convert null to a number");
|
|
}
|
|
|
|
@Override
|
|
public StringExpr asStringExpr() {
|
|
return literal(location, "null");
|
|
}
|
|
|
|
@Override
|
|
public BoolExpr asBoolExpr() {
|
|
throw new LocationalException(location, "Attempted to convert null to a boolean");
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
return obj instanceof NullLiteral;
|
|
}
|
|
}
|