1 package org.simantics.scl.compiler.compilation;
3 import java.util.ArrayList;
4 import java.util.Collection;
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;
20 public class EnvironmentOfModule implements Environment {
23 Namespace localNamespace;
25 public EnvironmentOfModule(Environment base, Module module) {
28 this.localNamespace = new NamespaceOfModule(base.getLocalNamespace(), module);
32 public Namespace getLocalNamespace() {
33 return localNamespace;
37 public SCLValue getValue(Name name) {
38 if(name.module.equals(module.getName()))
39 return module.getValue(name.name);
41 return base.getValue(name);
44 public SCLRelation getRelation(Name name) {
45 if(name.module.equals(module.getName()))
46 return module.getRelation(name.name);
48 return base.getRelation(name);
51 public SCLEntityType getEntityType(Name name) {
52 if(name.module.equals(module.getName()))
53 return module.getEntityType(name.name);
55 return base.getEntityType(name);
58 public TypeDescriptor getTypeDescriptor(TCon type) {
59 if(type.module.equals(module.getName()))
60 return module.getTypeDescriptor(type.name);
62 return base.getTypeDescriptor(type);
65 public EffectConstructor getEffectConstructor(TCon type) {
66 if(type.module.equals(module.getName()))
67 return module.getEffectConstructor(type.name);
69 return base.getEffectConstructor(type);
72 public TypeClass getTypeClass(TCon type) {
73 if(type.module.equals(module.getName()))
74 return module.getTypeClass(type.name);
76 return base.getTypeClass(type);
79 public Collection<TypeClassInstance> getInstances(TCon typeClass) {
80 Collection<TypeClassInstance> inst1 = module.getInstances(typeClass);
81 Collection<TypeClassInstance> inst2 = base.getInstances(typeClass);
86 ArrayList<TypeClassInstance> union = new ArrayList<TypeClassInstance>(inst1.size() + inst2.size());
93 public void collectRules(Collection<TransformationRule> rules) {
94 base.collectRules(rules);
95 rules.addAll(module.getRules());