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() {
43 public void collectVars(TObjectIntHashMap<Variable> allVars,
47 public void toString(StringBuilder b, TypeUnparsingContext tuc) {
52 protected void updateType() throws MatchException {
53 setType(value.getType());
57 public IVal toVal(CompilationContext context, CodeWriter w) {
62 public void collectFreeVariables(THashSet<Variable> vars) {
67 public Expression simplify(SimplificationContext context) {
72 public Expression resolve(TranslationContext context) {
77 public Expression resolveAsPattern(TranslationContext context) {
82 public void getParameters(TranslationContext translationContext,
83 ArrayList<Expression> parameters) {
87 public Expression replace(ReplaceContext context) {
88 return new ELiteral(value);
92 public void removeFreeVariables(THashSet<Variable> vars) {
96 public IExpression toIExpression(ExpressionInterpretationContext target) {
97 return new IConstant(value.realizeValue(target.localClassBuilder));
101 public Expression inferType(TypingContext context) {
106 public void collectEffects(THashSet<Type> effects) {
110 public void setLocationDeep(long loc) {
111 if(location == Locations.NO_LOCATION)
116 public void accept(ExpressionVisitor visitor) {
121 public boolean isPattern(int arity) {
122 return value.constructorTag() >= 0 && value.getArity() == arity;
126 public Expression accept(ExpressionTransformer transformer) {
127 return transformer.transform(this);
131 public boolean equalsExpression(Expression expression) {
132 if(expression.getClass() != getClass())
134 ELiteral other = (ELiteral)expression;
135 return value.equals(other.value);