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.elaboration.contexts.SimplificationContext;
7 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
8 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
9 import org.simantics.scl.compiler.elaboration.errors.NotPatternException;
10 import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType;
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.elaboration.utils.ExpressionDecorator;
16 import org.simantics.scl.compiler.types.Type;
17 import org.simantics.scl.compiler.types.exceptions.MatchException;
19 import gnu.trove.map.hash.TObjectIntHashMap;
20 import gnu.trove.set.hash.THashSet;
21 import gnu.trove.set.hash.TIntHashSet;
23 public abstract class DecoratingExpression extends SimplifiableExpression {
24 public Expression expression;
26 public DecoratingExpression(long loc, Expression expression) {
28 this.expression = expression;
32 public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
33 expression.collectRefs(allRefs, refs);
37 public void collectVars(TObjectIntHashMap<Variable> allVars,
39 expression.collectVars(allVars, vars);
43 protected void updateType() throws MatchException {
44 setType(expression.getType());
48 public void collectFreeVariables(THashSet<Variable> vars) {
49 expression.collectFreeVariables(vars);
53 public Expression simplify(SimplificationContext context) {
54 expression = expression.simplify(context);
59 public Expression resolve(TranslationContext context) {
60 expression = expression.resolve(context);
65 public Expression resolveAsPattern(TranslationContext context) {
66 expression = expression.resolveAsPattern(context);
71 public EVar getPatternHead() throws NotPatternException {
72 return expression.getPatternHead();
76 public LhsType getLhsType() throws NotPatternException {
77 return expression.getLhsType();
81 public void getParameters(TranslationContext translationContext,
82 ArrayList<Expression> parameters) {
83 expression.getParameters(translationContext, parameters);
87 public int getFunctionDefinitionArity() throws NotPatternException {
88 return expression.getFunctionDefinitionArity();
92 public Expression decorate(ExpressionDecorator decorator) {
93 expression = expression.decorate(decorator);
98 public void collectEffects(THashSet<Type> effects) {
99 expression.collectEffects(effects);
103 public void setLocationDeep(long loc) {
104 if(location == Locations.NO_LOCATION) {
106 expression.setLocationDeep(loc);
111 public void forVariables(VariableProcedure procedure) {
112 expression.forVariables(procedure);
116 public IVal toVal(Environment env, CodeWriter w) {
117 throw new InternalCompilerError("Cannot generate code for " + getClass().getSimpleName() + ".");
121 public Expression inferType(TypingContext context) {
122 expression = expression.inferType(context);
127 public Expression checkBasicType(TypingContext context, Type requiredType) {
128 expression = expression.checkBasicType(context, requiredType);
133 public Expression checkIgnoredType(TypingContext context) {
134 expression = expression.checkIgnoredType(context);