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