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 import gnu.trove.map.hash.TObjectIntHashMap;
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,
48 public Set<Variable> getFreeVariables() {
49 return Collections.emptySet();
52 public void toString(StringBuilder b, TypeUnparsingContext tuc) {
57 protected void updateType() throws MatchException {
58 setType(value.getType());
62 public IVal toVal(CompilationContext context, CodeWriter w) {
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 IExpression toIExpression(ExpressionInterpretationContext target) {
93 return new IConstant(value.realizeValue(target.localClassBuilder));
97 public Expression inferType(TypingContext context) {
102 public void setLocationDeep(long loc) {
103 if(location == Locations.NO_LOCATION)
108 public void accept(ExpressionVisitor visitor) {
113 public boolean isPattern(int arity) {
114 return value.constructorTag() >= 0 && value.getArity() == arity;
118 public Expression accept(ExpressionTransformer transformer) {
119 return transformer.transform(this);
123 public boolean equalsExpression(Expression expression) {
124 if(expression.getClass() != getClass())
126 ELiteral other = (ELiteral)expression;
127 return value.equals(other.value);