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.SimplificationContext;
8 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
9 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
10 import org.simantics.scl.compiler.elaboration.errors.NotPatternException;
11 import org.simantics.scl.compiler.elaboration.expressions.lhstype.LhsType;
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.types.Type;
16 import org.simantics.scl.compiler.types.exceptions.MatchException;
18 import gnu.trove.map.hash.TObjectIntHashMap;
19 import gnu.trove.set.hash.THashSet;
20 import gnu.trove.set.hash.TIntHashSet;
22 public abstract class DecoratingExpression extends SimplifiableExpression {
23 public Expression expression;
25 public DecoratingExpression(long loc, Expression expression) {
27 this.expression = expression;
31 public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
32 expression.collectRefs(allRefs, refs);
36 public void collectVars(TObjectIntHashMap<Variable> allVars,
38 expression.collectVars(allVars, vars);
42 protected void updateType() throws MatchException {
43 setType(expression.getType());
47 public void collectFreeVariables(THashSet<Variable> vars) {
48 expression.collectFreeVariables(vars);
52 public Expression simplify(SimplificationContext context) {
53 expression = expression.simplify(context);
58 public Expression resolve(TranslationContext context) {
59 expression = expression.resolve(context);
64 public Expression resolveAsPattern(TranslationContext context) {
65 expression = expression.resolveAsPattern(context);
70 public EVar getPatternHead() throws NotPatternException {
71 return expression.getPatternHead();
75 public LhsType getLhsType() throws NotPatternException {
76 return expression.getLhsType();
80 public void getParameters(TranslationContext translationContext,
81 ArrayList<Expression> parameters) {
82 expression.getParameters(translationContext, parameters);
86 public int getFunctionDefinitionPatternArity() throws NotPatternException {
87 return expression.getFunctionDefinitionPatternArity();
91 public void collectEffects(THashSet<Type> effects) {
92 expression.collectEffects(effects);
96 public void setLocationDeep(long loc) {
97 if(location == Locations.NO_LOCATION) {
99 expression.setLocationDeep(loc);
104 public IVal toVal(CompilationContext context, CodeWriter w) {
105 throw new InternalCompilerError("Cannot generate code for " + getClass().getSimpleName() + ".");
109 public Expression inferType(TypingContext context) {
110 expression = expression.inferType(context);
115 public Expression checkBasicType(TypingContext context, Type requiredType) {
116 expression = expression.checkBasicType(context, requiredType);
121 public Expression checkIgnoredType(TypingContext context) {
122 expression = expression.checkIgnoredType(context);
127 public int getSyntacticFunctionArity() {
128 return expression.getSyntacticFunctionArity();