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.interpreted.IConstant;
15 import org.simantics.scl.compiler.internal.interpreted.IExpression;
16 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
17 import org.simantics.scl.compiler.types.Type;
18 import org.simantics.scl.compiler.types.exceptions.MatchException;
19 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
21 import gnu.trove.map.hash.TObjectIntHashMap;
22 import gnu.trove.set.hash.THashSet;
23 import gnu.trove.set.hash.TIntHashSet;
25 public class ELiteral extends Expression {
28 public ELiteral(Constant value) {
30 setType(value.getType());
33 public ELiteral(long loc, Constant value) {
38 public Constant getValue() {
42 public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
46 public void collectVars(TObjectIntHashMap<Variable> allVars,
50 public void toString(StringBuilder b, TypeUnparsingContext tuc) {
55 protected void updateType() throws MatchException {
56 setType(value.getType());
60 public IVal toVal(CompilationContext context, CodeWriter w) {
65 public void collectFreeVariables(THashSet<Variable> vars) {
70 public Expression simplify(SimplificationContext context) {
75 public Expression resolve(TranslationContext context) {
80 public Expression resolveAsPattern(TranslationContext context) {
85 public void getParameters(TranslationContext translationContext,
86 ArrayList<Expression> parameters) {
90 public Expression replace(ReplaceContext context) {
91 return new ELiteral(value);
95 public void removeFreeVariables(THashSet<Variable> vars) {
99 public IExpression toIExpression(ExpressionInterpretationContext target) {
100 return new IConstant(value.realizeValue(target.localClassBuilder));
104 public Expression inferType(TypingContext context) {
109 public void collectEffects(THashSet<Type> effects) {
113 public void setLocationDeep(long loc) {
114 if(location == Locations.NO_LOCATION)
119 public void accept(ExpressionVisitor visitor) {
124 public void forVariables(VariableProcedure procedure) {
128 public boolean isPattern(int arity) {
129 return value.constructorTag() >= 0 && value.getArity() == arity;
133 public Expression accept(ExpressionTransformer transformer) {
134 return transformer.transform(this);
138 public boolean equalsExpression(Expression expression) {
139 if(expression.getClass() != getClass())
141 ELiteral other = (ELiteral)expression;
142 return value.equals(other.value);