1 package org.simantics.scl.compiler.elaboration.expressions;
3 import java.util.ArrayList;
5 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
6 import org.simantics.scl.compiler.elaboration.contexts.ReplaceContext;
7 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
8 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
9 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
10 import org.simantics.scl.compiler.environment.Environment;
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.codegen.writer.ModuleWriter;
15 import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
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.Type;
20 import org.simantics.scl.compiler.types.exceptions.MatchException;
21 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
23 import gnu.trove.map.hash.TObjectIntHashMap;
24 import gnu.trove.set.hash.THashSet;
25 import gnu.trove.set.hash.TIntHashSet;
27 public class EExternalConstant extends Expression {
30 public EExternalConstant(Object value, Type type) {
35 public Object getValue() {
39 public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
43 public void collectVars(TObjectIntHashMap<Variable> allVars,
47 public void toString(StringBuilder b, TypeUnparsingContext tuc) {
52 protected void updateType() throws MatchException {
53 throw new InternalCompilerError("EExternalConstants must have explicitly defined type.");
57 public IVal toVal(Environment env, CodeWriter w) {
58 ModuleWriter mw = w.getModuleWriter();
59 return mw.getExternalConstant(value, getType());
63 public void collectFreeVariables(THashSet<Variable> vars) {
68 public Expression simplify(SimplificationContext context) {
73 public Expression resolve(TranslationContext context) {
78 public Expression resolveAsPattern(TranslationContext context) {
83 public void getParameters(TranslationContext translationContext,
84 ArrayList<Expression> parameters) {
88 public Expression replace(ReplaceContext context) {
89 return new EExternalConstant(value, getType().replace(context.tvarMap));
93 public void removeFreeVariables(THashSet<Variable> vars) {
97 public Expression inferType(TypingContext context) {
102 public Expression decorate(ExpressionDecorator decorator) {
103 return decorator.decorate(this);
107 public void collectEffects(THashSet<Type> effects) {
111 public void setLocationDeep(long loc) {
112 if(location == Locations.NO_LOCATION)
117 public void accept(ExpressionVisitor visitor) {
122 public IExpression toIExpression(ExpressionInterpretationContext context) {
123 return new IConstant(value);
127 public void forVariables(VariableProcedure procedure) {
131 public Expression accept(ExpressionTransformer transformer) {
132 return transformer.transform(this);