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.TIntHashSet;
21 public abstract class DecoratingExpression extends SimplifiableExpression {
22 public Expression expression;
24 public DecoratingExpression(long loc, Expression expression) {
26 this.expression = expression;
30 public void collectVars(TObjectIntHashMap<Variable> allVars,
32 expression.collectVars(allVars, vars);
36 protected void updateType() throws MatchException {
37 setType(expression.getType());
41 public Expression simplify(SimplificationContext context) {
42 expression = expression.simplify(context);
47 public Expression resolve(TranslationContext context) {
48 expression = expression.resolve(context);
53 public Expression resolveAsPattern(TranslationContext context) {
54 expression = expression.resolveAsPattern(context);
59 public EVar getPatternHead() throws NotPatternException {
60 return expression.getPatternHead();
64 public LhsType getLhsType() throws NotPatternException {
65 return expression.getLhsType();
69 public void getParameters(TranslationContext translationContext,
70 ArrayList<Expression> parameters) {
71 expression.getParameters(translationContext, parameters);
75 public int getFunctionDefinitionPatternArity() throws NotPatternException {
76 return expression.getFunctionDefinitionPatternArity();
80 public void setLocationDeep(long loc) {
81 if(location == Locations.NO_LOCATION) {
83 expression.setLocationDeep(loc);
88 public IVal toVal(CompilationContext context, CodeWriter w) {
89 throw new InternalCompilerError("Cannot generate code for " + getClass().getSimpleName() + ".");
93 public Expression inferType(TypingContext context) {
94 expression = expression.inferType(context);
99 public Expression checkBasicType(TypingContext context, Type requiredType) {
100 expression = expression.checkBasicType(context, requiredType);
105 public Expression checkIgnoredType(TypingContext context) {
106 expression = expression.checkIgnoredType(context);
111 public int getSyntacticFunctionArity() {
112 return expression.getSyntacticFunctionArity();