1 package org.simantics.scl.compiler.elaboration.expressions;
3 import java.util.ArrayList;
4 import java.util.Collections;
7 import org.simantics.scl.compiler.compilation.CompilationContext;
8 import org.simantics.scl.compiler.constants.Constant;
9 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
10 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
11 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
12 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
13 import org.simantics.scl.compiler.errors.Locations;
14 import org.simantics.scl.compiler.internal.codegen.references.IVal;
15 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
16 import org.simantics.scl.compiler.internal.interpreted.IConstant;
17 import org.simantics.scl.compiler.internal.interpreted.IExpression;
18 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
19 import org.simantics.scl.compiler.types.exceptions.MatchException;
20 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
22 public class ELiteral extends Expression {
25 public ELiteral(Constant value) {
27 setType(value.getType());
30 public ELiteral(long loc, Constant value) {
35 public Constant getValue() {
40 public Set<Variable> getFreeVariables() {
41 return Collections.emptySet();
44 public void toString(StringBuilder b, TypeUnparsingContext tuc) {
49 protected void updateType() throws MatchException {
50 setType(value.getType());
54 public IVal toVal(CompilationContext context, CodeWriter w) {
59 public Expression simplify(SimplificationContext context) {
64 public Expression resolve(TranslationContext context) {
69 public Expression resolveAsPattern(TranslationContext context) {
74 public void getParameters(TranslationContext translationContext,
75 ArrayList<Expression> parameters) {
79 public Expression replace(ReplaceContext context) {
80 return new ELiteral(value);
84 public IExpression toIExpression(ExpressionInterpretationContext target) {
85 return new IConstant(value.realizeValue(target.localClassBuilder));
89 public Expression inferType(TypingContext context) {
94 public void setLocationDeep(long loc) {
95 if(location == Locations.NO_LOCATION)
100 public void accept(ExpressionVisitor visitor) {
105 public boolean isPattern(int arity) {
106 return value.constructorTag() >= 0 && value.getArity() == arity;
110 public Expression accept(ExpressionTransformer transformer) {
111 return transformer.transform(this);
115 public boolean equalsExpression(Expression expression) {
116 if(expression.getClass() != getClass())
118 ELiteral other = (ELiteral)expression;
119 return value.equals(other.value);