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