]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/EnvironmentOfModule.java
Re-enabled Acorn transaction cancellation support for testing
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / compilation / EnvironmentOfModule.java
1 package org.simantics.scl.compiler.compilation;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5
6 import org.simantics.scl.compiler.common.names.Name;
7 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
8 import org.simantics.scl.compiler.elaboration.modules.TypeAlias;
9 import org.simantics.scl.compiler.elaboration.modules.TypeClass;
10 import org.simantics.scl.compiler.elaboration.modules.TypeClassInstance;
11 import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;
12 import org.simantics.scl.compiler.elaboration.relations.SCLEntityType;
13 import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
14 import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
15 import org.simantics.scl.compiler.environment.Environment;
16 import org.simantics.scl.compiler.environment.Namespace;
17 import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
18 import org.simantics.scl.compiler.module.Module;
19 import org.simantics.scl.compiler.types.TCon;
20
21 public class EnvironmentOfModule implements Environment {
22     Environment base;
23     Module module;
24     Namespace localNamespace;
25     
26     public EnvironmentOfModule(Environment base, Module module) {
27         this.base = base;
28         this.module = module;
29         this.localNamespace = new NamespaceOfModule(base.getLocalNamespace(), module);
30     }
31
32     @Override
33     public Namespace getLocalNamespace() {
34         return localNamespace;
35     }
36     
37     @Override
38     public SCLValue getValue(Name name) {
39         if(name.module.equals(module.getName()))
40             return module.getValue(name.name);
41         else
42             return base.getValue(name);
43     }
44     @Override
45     public SCLRelation getRelation(Name name) {
46         if(name.module.equals(module.getName()))
47             return module.getRelation(name.name);
48         else
49             return base.getRelation(name);
50     }
51     @Override
52     public SCLEntityType getEntityType(Name name) {
53         if(name.module.equals(module.getName()))
54             return module.getEntityType(name.name);
55         else
56             return base.getEntityType(name);
57     }
58     @Override
59     public TypeConstructor getTypeConstructor(TCon type) {
60         if(type.module.equals(module.getName()))
61             return module.getTypeConstructor(type.name);
62         else
63             return base.getTypeConstructor(type);
64     }
65     @Override
66     public EffectConstructor getEffectConstructor(TCon type) {
67         if(type.module.equals(module.getName()))
68             return module.getEffectConstructor(type.name);
69         else
70             return base.getEffectConstructor(type);
71     }
72     @Override
73     public TypeAlias getTypeAlias(TCon type) {
74         if(type.module.equals(module.getName()))
75             return module.getTypeAlias(type.name);
76         else
77             return base.getTypeAlias(type);
78     }
79     @Override
80     public TypeClass getTypeClass(TCon type) {
81         if(type.module.equals(module.getName()))
82             return module.getTypeClass(type.name);
83         else
84             return base.getTypeClass(type);
85     }
86     @Override
87     public Collection<TypeClassInstance> getInstances(TCon typeClass) {
88         Collection<TypeClassInstance> inst1 = module.getInstances(typeClass);
89         Collection<TypeClassInstance> inst2 = base.getInstances(typeClass);
90         if(inst1.isEmpty())
91             return inst2;
92         if(inst2.isEmpty())
93             return inst1;
94         ArrayList<TypeClassInstance> union = new ArrayList<TypeClassInstance>(inst1.size() + inst2.size());
95         union.addAll(inst1);
96         union.addAll(inst2);
97         return union;
98     }
99     
100     @Override
101     public void collectRules(Collection<TransformationRule> rules) {
102         base.collectRules(rules);
103         rules.addAll(module.getRules());
104     }
105 }