Package icyllis.arc3d.compiler
Class ConstantFolder
java.lang.Object
icyllis.arc3d.compiler.ConstantFolder
Performs constant folding on AST expressions. This simplifies expressions containing
compile-time constants, such as replacing `Literal(2) + Literal(2)` with `Literal(4)`.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Expression
fold
(Context context, int pos, Operator op, Expression base) Simplifies the unary expression `OP base`.static Expression
fold
(Context context, int pos, Expression left, Operator op, Expression right, Type resultType) Simplifies the binary expression `left OP right`.static OptionalLong
getConstantInt
(Expression value) Returns the value if it is an int literal or const int variable with a known value.static Expression
If the expression is a const variable with a known compile-time constant value, returns that value.static Expression
If the expression is a const variable with a known compile-time constant value, returns that value.static Expression
makeConstantValueForVariable
(int pos, Expression value) If the expression is a const variable with a known compile-time constant value, returns a clone of that value.
-
Constructor Details
-
ConstantFolder
public ConstantFolder()
-
-
Method Details
-
getConstantInt
Returns the value if it is an int literal or const int variable with a known value. -
getConstantValueForVariable
If the expression is a const variable with a known compile-time constant value, returns that value. If not, returns the original expression as-is. -
makeConstantValueForVariable
If the expression is a const variable with a known compile-time constant value, returns a clone of that value. If not, returns the original expression as-is. -
getConstantValueOrNullForVariable
If the expression is a const variable with a known compile-time constant value, returns that value. If not, returns null. -
fold
@Nullable public static Expression fold(@Nonnull Context context, int pos, Expression left, Operator op, Expression right, Type resultType) Simplifies the binary expression `left OP right`. Returns null if it can't be simplified. -
fold
@Nullable public static Expression fold(@Nonnull Context context, int pos, @Nonnull Operator op, Expression base) Simplifies the unary expression `OP base`. Returns null if it can't be simplified.
-