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.compilation.CompilationContext;
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.codegen.writer.ModuleWriter;
15 import org.simantics.scl.compiler.internal.interpreted.IConstant;
16 import org.simantics.scl.compiler.internal.interpreted.IExpression;
17 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
18 import org.simantics.scl.compiler.types.Type;
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.THashSet;
24 import gnu.trove.set.hash.TIntHashSet;
26 public class EExternalConstant extends Expression {
29 public EExternalConstant(Object value, Type type) {
34 public Object getValue() {
38 public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
42 public void collectVars(TObjectIntHashMap<Variable> allVars,
46 public void toString(StringBuilder b, TypeUnparsingContext tuc) {
51 protected void updateType() throws MatchException {
52 throw new InternalCompilerError("EExternalConstants must have explicitly defined type.");
56 public IVal toVal(CompilationContext context, CodeWriter w) {
57 ModuleWriter mw = w.getModuleWriter();
58 return mw.getExternalConstant(value, getType());
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 EExternalConstant(value, getType().replace(context.tvarMap));
92 public void removeFreeVariables(THashSet<Variable> vars) {
96 public Expression inferType(TypingContext context) {
101 public void collectEffects(THashSet<Type> effects) {
105 public void setLocationDeep(long loc) {
106 if(location == Locations.NO_LOCATION)
111 public void accept(ExpressionVisitor visitor) {
116 public IExpression toIExpression(ExpressionInterpretationContext context) {
117 return new IConstant(value);
121 public Expression accept(ExpressionTransformer transformer) {
122 return transformer.transform(this);