1 package org.simantics.scl.compiler.elaboration.expressions;
3 import java.util.ArrayList;
5 import org.simantics.scl.compiler.compilation.CompilationContext;
6 import org.simantics.scl.compiler.constants.Constant;
7 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
8 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
9 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
10 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
11 import org.simantics.scl.compiler.errors.Locations;
12 import org.simantics.scl.compiler.internal.codegen.references.IVal;
13 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
14 import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
15 import org.simantics.scl.compiler.internal.interpreted.IConstant;
16 import org.simantics.scl.compiler.internal.interpreted.IExpression;
17 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
18 import org.simantics.scl.compiler.types.Type;
19 import org.simantics.scl.compiler.types.exceptions.MatchException;
20 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
22 import gnu.trove.map.hash.TObjectIntHashMap;
23 import gnu.trove.set.hash.THashSet;
24 import gnu.trove.set.hash.TIntHashSet;
26 public class ELiteral extends Expression {
29 public ELiteral(Constant value) {
31 setType(value.getType());
34 public ELiteral(long loc, Constant value) {
39 public Constant getValue() {
43 public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
47 public void collectVars(TObjectIntHashMap<Variable> allVars,
51 public void toString(StringBuilder b, TypeUnparsingContext tuc) {
56 protected void updateType() throws MatchException {
57 setType(value.getType());
61 public IVal toVal(CompilationContext context, CodeWriter w) {
66 public void collectFreeVariables(THashSet<Variable> vars) {
71 public Expression simplify(SimplificationContext context) {
76 public Expression resolve(TranslationContext context) {
81 public Expression resolveAsPattern(TranslationContext context) {
86 public void getParameters(TranslationContext translationContext,
87 ArrayList<Expression> parameters) {
91 public Expression replace(ReplaceContext context) {
92 return new ELiteral(value);
96 public void removeFreeVariables(THashSet<Variable> vars) {
100 public IExpression toIExpression(ExpressionInterpretationContext target) {
101 return new IConstant(value.realizeValue(target.localClassBuilder));
105 public Expression inferType(TypingContext context) {
110 public Expression decorate(ExpressionDecorator decorator) {
111 return decorator.decorate(this);
115 public void collectEffects(THashSet<Type> effects) {
119 public void setLocationDeep(long loc) {
120 if(location == Locations.NO_LOCATION)
125 public void accept(ExpressionVisitor visitor) {
130 public void forVariables(VariableProcedure procedure) {
134 public boolean isPattern(int arity) {
135 return value.constructorTag() >= 0 && value.getArity() == arity;
139 public Expression accept(ExpressionTransformer transformer) {
140 return transformer.transform(this);
144 public boolean equalsExpression(Expression expression) {
145 if(expression.getClass() != getClass())
147 ELiteral other = (ELiteral)expression;
148 return value.equals(other.value);