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 collectVars(TObjectIntHashMap<Variable> allVars,
33 expression.collectVars(allVars, vars);
37 protected void updateType() throws MatchException {
38 setType(expression.getType());
42 public void collectFreeVariables(THashSet<Variable> vars) {
43 expression.collectFreeVariables(vars);
47 public Expression simplify(SimplificationContext context) {
48 expression = expression.simplify(context);
53 public Expression resolve(TranslationContext context) {
54 expression = expression.resolve(context);
59 public Expression resolveAsPattern(TranslationContext context) {
60 expression = expression.resolveAsPattern(context);
65 public EVar getPatternHead() throws NotPatternException {
66 return expression.getPatternHead();
70 public LhsType getLhsType() throws NotPatternException {
71 return expression.getLhsType();
75 public void getParameters(TranslationContext translationContext,
76 ArrayList<Expression> parameters) {
77 expression.getParameters(translationContext, parameters);
81 public int getFunctionDefinitionPatternArity() throws NotPatternException {
82 return expression.getFunctionDefinitionPatternArity();
86 public void setLocationDeep(long loc) {
87 if(location == Locations.NO_LOCATION) {
89 expression.setLocationDeep(loc);
94 public IVal toVal(CompilationContext context, CodeWriter w) {
95 throw new InternalCompilerError("Cannot generate code for " + getClass().getSimpleName() + ".");
99 public Expression inferType(TypingContext context) {
100 expression = expression.inferType(context);
105 public Expression checkBasicType(TypingContext context, Type requiredType) {
106 expression = expression.checkBasicType(context, requiredType);
111 public Expression checkIgnoredType(TypingContext context) {
112 expression = expression.checkIgnoredType(context);
117 public int getSyntacticFunctionArity() {
118 return expression.getSyntacticFunctionArity();