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() {
39 public void collectVars(TObjectIntHashMap<Variable> allVars,
43 public void toString(StringBuilder b, TypeUnparsingContext tuc) {
48 protected void updateType() throws MatchException {
49 throw new InternalCompilerError("EExternalConstants must have explicitly defined type.");
53 public IVal toVal(CompilationContext context, CodeWriter w) {
54 ModuleWriter mw = w.getModuleWriter();
55 return mw.getExternalConstant(value, getType());
59 public void collectFreeVariables(THashSet<Variable> vars) {
64 public Expression simplify(SimplificationContext context) {
69 public Expression resolve(TranslationContext context) {
74 public Expression resolveAsPattern(TranslationContext context) {
79 public void getParameters(TranslationContext translationContext,
80 ArrayList<Expression> parameters) {
84 public Expression replace(ReplaceContext context) {
85 return new EExternalConstant(value, getType().replace(context.tvarMap));
89 public void removeFreeVariables(THashSet<Variable> vars) {
93 public Expression inferType(TypingContext context) {
98 public void collectEffects(THashSet<Type> effects) {
102 public void setLocationDeep(long loc) {
103 if(location == Locations.NO_LOCATION)
108 public void accept(ExpressionVisitor visitor) {
113 public IExpression toIExpression(ExpressionInterpretationContext context) {
114 return new IConstant(value);
118 public Expression accept(ExpressionTransformer transformer) {
119 return transformer.transform(this);