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.exceptions.MatchException;
18 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
20 import gnu.trove.map.hash.TObjectIntHashMap;
21 import gnu.trove.set.hash.THashSet;
22 import gnu.trove.set.hash.TIntHashSet;
24 public class ELiteral extends Expression {
27 public ELiteral(Constant value) {
29 setType(value.getType());
32 public ELiteral(long loc, Constant value) {
37 public Constant getValue() {
42 public void collectVars(TObjectIntHashMap<Variable> allVars,
46 public void toString(StringBuilder b, TypeUnparsingContext tuc) {
51 protected void updateType() throws MatchException {
52 setType(value.getType());
56 public IVal toVal(CompilationContext context, CodeWriter w) {
61 public void collectFreeVariables(THashSet<Variable> vars) {
66 public Expression simplify(SimplificationContext context) {
71 public Expression resolve(TranslationContext context) {
76 public Expression resolveAsPattern(TranslationContext context) {
81 public void getParameters(TranslationContext translationContext,
82 ArrayList<Expression> parameters) {
86 public Expression replace(ReplaceContext context) {
87 return new ELiteral(value);
91 public void removeFreeVariables(THashSet<Variable> vars) {
95 public IExpression toIExpression(ExpressionInterpretationContext target) {
96 return new IConstant(value.realizeValue(target.localClassBuilder));
100 public Expression inferType(TypingContext context) {
105 public void setLocationDeep(long loc) {
106 if(location == Locations.NO_LOCATION)
111 public void accept(ExpressionVisitor visitor) {
116 public boolean isPattern(int arity) {
117 return value.constructorTag() >= 0 && value.getArity() == arity;
121 public Expression accept(ExpressionTransformer transformer) {
122 return transformer.transform(this);
126 public boolean equalsExpression(Expression expression) {
127 if(expression.getClass() != getClass())
129 ELiteral other = (ELiteral)expression;
130 return value.equals(other.value);