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.environment.Environment;
12 import org.simantics.scl.compiler.errors.Locations;
13 import org.simantics.scl.compiler.internal.codegen.references.IVal;
14 import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;
15 import org.simantics.scl.compiler.internal.codegen.writer.ModuleWriter;
16 import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
17 import org.simantics.scl.compiler.internal.interpreted.IConstant;
18 import org.simantics.scl.compiler.internal.interpreted.IExpression;
19 import org.simantics.scl.compiler.top.ExpressionInterpretationContext;
20 import org.simantics.scl.compiler.types.Type;
21 import org.simantics.scl.compiler.types.exceptions.MatchException;
22 import org.simantics.scl.compiler.types.util.TypeUnparsingContext;
24 import gnu.trove.map.hash.TObjectIntHashMap;
25 import gnu.trove.set.hash.THashSet;
26 import gnu.trove.set.hash.TIntHashSet;
28 public class EExternalConstant extends Expression {
31 public EExternalConstant(Object value, Type type) {
36 public Object getValue() {
40 public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
44 public void collectVars(TObjectIntHashMap<Variable> allVars,
48 public void toString(StringBuilder b, TypeUnparsingContext tuc) {
53 protected void updateType() throws MatchException {
54 throw new InternalCompilerError("EExternalConstants must have explicitly defined type.");
58 public IVal toVal(CompilationContext context, CodeWriter w) {
59 ModuleWriter mw = w.getModuleWriter();
60 return mw.getExternalConstant(value, getType());
64 public void collectFreeVariables(THashSet<Variable> vars) {
69 public Expression simplify(SimplificationContext context) {
74 public Expression resolve(TranslationContext context) {
79 public Expression resolveAsPattern(TranslationContext context) {
84 public void getParameters(TranslationContext translationContext,
85 ArrayList<Expression> parameters) {
89 public Expression replace(ReplaceContext context) {
90 return new EExternalConstant(value, getType().replace(context.tvarMap));
94 public void removeFreeVariables(THashSet<Variable> vars) {
98 public Expression inferType(TypingContext context) {
103 public Expression decorate(ExpressionDecorator decorator) {
104 return decorator.decorate(this);
108 public void collectEffects(THashSet<Type> effects) {
112 public void setLocationDeep(long loc) {
113 if(location == Locations.NO_LOCATION)
118 public void accept(ExpressionVisitor visitor) {
123 public IExpression toIExpression(ExpressionInterpretationContext context) {
124 return new IConstant(value);
128 public void forVariables(VariableProcedure procedure) {
132 public Expression accept(ExpressionTransformer transformer) {
133 return transformer.transform(this);