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