[muscript] Enhance StringCoerce optimization
This commit is contained in:
parent
f84bdd2a02
commit
87f5751fa1
@ -4,7 +4,7 @@ import io.gitlab.jfronny.commons.data.dynamic.Dynamic;
|
||||
import io.gitlab.jfronny.muscript.compiler.expr.DynamicExpr;
|
||||
|
||||
public final class DynamicLiteral<T> extends DynamicExpr {
|
||||
private final Dynamic<T> value;
|
||||
public final Dynamic<T> value;
|
||||
|
||||
public DynamicLiteral(int character, Dynamic<T> value) {
|
||||
super(character);
|
||||
|
@ -2,8 +2,8 @@ package io.gitlab.jfronny.muscript.compiler.expr.string;
|
||||
|
||||
import io.gitlab.jfronny.commons.StringFormatter;
|
||||
import io.gitlab.jfronny.commons.data.dynamic.Dynamic;
|
||||
import io.gitlab.jfronny.muscript.compiler.expr.Expr;
|
||||
import io.gitlab.jfronny.muscript.compiler.expr.StringExpr;
|
||||
import io.gitlab.jfronny.muscript.compiler.expr.*;
|
||||
import io.gitlab.jfronny.muscript.compiler.expr.common.literal.*;
|
||||
|
||||
public class StringCoerce extends StringExpr {
|
||||
private final Expr<?> inner;
|
||||
@ -21,6 +21,10 @@ public class StringCoerce extends StringExpr {
|
||||
@Override
|
||||
public StringExpr optimize() {
|
||||
Expr<?> inner = this.inner.optimize();
|
||||
if (inner instanceof NullLiteral) return Expr.literal(character, "null");
|
||||
if (inner instanceof BoolLiteral expr) return Expr.literal(character, StringFormatter.toString(expr.value));
|
||||
if (inner instanceof DynamicLiteral<?> expr) return Expr.literal(character, StringFormatter.toString(expr.value));
|
||||
if (inner instanceof NumberLiteral expr) return Expr.literal(character, StringFormatter.toString(expr.value));
|
||||
if (inner instanceof StringExpr expr) return expr;
|
||||
return new StringCoerce(character, inner);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user