]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ETypeAnnotation.java
6452812fc370f82989e662b643cb7675f85a65ac
[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         public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {
32         value.collectRefs(allRefs, refs);
33     }
34         
35         @Override
36         public void collectVars(TObjectIntHashMap<Variable> allVars,
37                 TIntHashSet vars) {
38             value.collectVars(allVars, vars);
39         }
40
41         @Override
42         protected void updateType() throws MatchException {
43             setType(type);
44         }
45
46     @Override
47     public void collectFreeVariables(THashSet<Variable> vars) {
48         value.collectFreeVariables(vars);
49     }
50
51     @Override
52     public Expression simplify(SimplificationContext context) {
53         return value.simplify(context);
54     }
55
56     @Override
57     public Expression resolve(TranslationContext context) {
58         value = value.resolve(context);
59         type = context.toType(typeAst);
60         return this;
61     }
62     
63     @Override
64     public Expression resolveAsPattern(TranslationContext context) {
65         value = value.resolveAsPattern(context);
66         type = context.toType(typeAst);
67         return this;
68     }
69     
70     @Override
71     public Expression inferType(TypingContext context) {
72         return value.checkType(context, type);
73     }
74     
75     @Override
76     public void collectEffects(THashSet<Type> effects) {
77         value.collectEffects(effects);
78     }
79     
80     @Override
81     public void setLocationDeep(long loc) {
82         if(location == Locations.NO_LOCATION) {
83             location = loc;
84             value.setLocationDeep(loc);
85         }
86     }
87     
88     @Override
89     public void accept(ExpressionVisitor visitor) {
90         visitor.visit(this);
91     }
92     
93     public Expression getValue() {
94         return value;
95     }
96     
97     @Override
98     public Expression accept(ExpressionTransformer transformer) {
99         return transformer.transform(this);
100     }
101
102 }