]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETypeAnnotation.java
654b4ef1f47555395924b0ac3f7db94a22417cbc
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / ETypeAnnotation.java
1 package org.simantics.scl.compiler.elaboration.expressions;
2
3 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
4 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
5 import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
6 import org.simantics.scl.compiler.errors.Locations;
7 import org.simantics.scl.compiler.internal.elaboration.utils.ExpressionDecorator;
8 import org.simantics.scl.compiler.internal.parsing.types.TypeAst;
9 import org.simantics.scl.compiler.types.Type;
10 import org.simantics.scl.compiler.types.exceptions.MatchException;
11
12 import gnu.trove.map.hash.TObjectIntHashMap;
13 import gnu.trove.set.hash.THashSet;
14 import gnu.trove.set.hash.TIntHashSet;
15
16 public class ETypeAnnotation extends SimplifiableExpression {
17     Expression value;
18     Type type;
19     TypeAst typeAst;
20         
21     public ETypeAnnotation(Expression value, TypeAst typeAst) {
22         this.value = value;
23         this.typeAst = typeAst;
24     }
25
26     public ETypeAnnotation(long loc, Expression value, Type type) {
27         super(loc);
28         this.value = value;
29         this.type = type;
30     }
31
32         public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
33         value.collectRefs(allRefs, refs);
34     }
35         
36         @Override
37         public void collectVars(TObjectIntHashMap<Variable> allVars,
38                 TIntHashSet vars) {
39             value.collectVars(allVars, vars);
40         }
41
42         @Override
43         protected void updateType() throws MatchException {
44             setType(type);
45         }
46
47     @Override
48     public void collectFreeVariables(THashSet<Variable> vars) {
49         value.collectFreeVariables(vars);
50     }
51
52     @Override
53     public Expression simplify(SimplificationContext context) {
54         return value.simplify(context);
55     }
56
57     @Override
58     public Expression resolve(TranslationContext context) {
59         value = value.resolve(context);
60         type = context.toType(typeAst);
61         return this;
62     }
63     
64     @Override
65     public Expression resolveAsPattern(TranslationContext context) {
66         value = value.resolveAsPattern(context);
67         type = context.toType(typeAst);
68         return this;
69     }
70     
71     @Override
72     public Expression inferType(TypingContext context) {
73         return value.checkType(context, type);
74     }
75
76     @Override
77     public Expression decorate(ExpressionDecorator decorator) {
78         value = value.decorate(decorator);
79         return decorator.decorate(this);
80     }
81
82     @Override
83     public void collectEffects(THashSet<Type> effects) {
84         value.collectEffects(effects);
85     }
86     
87     @Override
88     public void setLocationDeep(long loc) {
89         if(location == Locations.NO_LOCATION) {
90             location = loc;
91             value.setLocationDeep(loc);
92         }
93     }
94     
95     @Override
96     public void accept(ExpressionVisitor visitor) {
97         visitor.visit(this);
98     }
99     
100     public Expression getValue() {
101         return value;
102     }
103
104     @Override
105     public void forVariables(VariableProcedure procedure) {
106         value.forVariables(procedure);
107     }
108     
109     @Override
110     public Expression accept(ExpressionTransformer transformer) {
111         return transformer.transform(this);
112     }
113
114 }