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.TIntHashSet;
25 public class EExternalConstant extends Expression {
28 public EExternalConstant(Object value, Type type) {
33 public Object getValue() {
38 public void collectVars(TObjectIntHashMap<Variable> allVars,
42 public void toString(StringBuilder b, TypeUnparsingContext tuc) {
47 protected void updateType() throws MatchException {
48 throw new InternalCompilerError("EExternalConstants must have explicitly defined type.");
52 public IVal toVal(CompilationContext context, CodeWriter w) {
53 ModuleWriter mw = w.getModuleWriter();
54 return mw.getExternalConstant(value, getType());
58 public Expression simplify(SimplificationContext context) {
63 public Expression resolve(TranslationContext context) {
68 public Expression resolveAsPattern(TranslationContext context) {
73 public void getParameters(TranslationContext translationContext,
74 ArrayList<Expression> parameters) {
78 public Expression replace(ReplaceContext context) {
79 return new EExternalConstant(value, getType().replace(context.tvarMap));
83 public Expression inferType(TypingContext context) {
88 public void setLocationDeep(long loc) {
89 if(location == Locations.NO_LOCATION)
94 public void accept(ExpressionVisitor visitor) {
99 public IExpression toIExpression(ExpressionInterpretationContext context) {
100 return new IConstant(value);
104 public Expression accept(ExpressionTransformer transformer) {
105 return transformer.transform(this);