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