1 package org.simantics.scl.compiler.compilation;
3 import java.util.ArrayList;
4 import java.util.Collection;
7 import org.simantics.scl.compiler.common.names.Name;
8 import org.simantics.scl.compiler.constants.Constant;
9 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
10 import org.simantics.scl.compiler.elaboration.modules.TypeClass;
11 import org.simantics.scl.compiler.elaboration.modules.TypeClassInstance;
12 import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
13 import org.simantics.scl.compiler.elaboration.relations.SCLEntityType;
14 import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
15 import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
16 import org.simantics.scl.compiler.environment.Environment;
17 import org.simantics.scl.compiler.environment.Namespace;
18 import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
19 import org.simantics.scl.compiler.module.Module;
20 import org.simantics.scl.compiler.types.TCon;
22 public class EnvironmentOfModule implements Environment {
25 Namespace localNamespace;
27 public EnvironmentOfModule(Environment base, Module module) {
30 this.localNamespace = new NamespaceOfModule(base.getLocalNamespace(), module);
34 public Namespace getLocalNamespace() {
35 return localNamespace;
39 public SCLValue getValue(Name name) {
40 if(name.module.equals(module.getName()))
41 return module.getValue(name.name);
43 return base.getValue(name);
47 public List<Constant> getFieldAccessors(String name) {
48 List<Constant> r1 = base.getFieldAccessors(name);
49 List<Constant> r2 = module.getFieldAccessors(name);
54 ArrayList<Constant> result = new ArrayList<Constant>(r1.size() + r2.size());
61 public SCLRelation getRelation(Name name) {
62 if(name.module.equals(module.getName()))
63 return module.getRelation(name.name);
65 return base.getRelation(name);
68 public SCLEntityType getEntityType(Name name) {
69 if(name.module.equals(module.getName()))
70 return module.getEntityType(name.name);
72 return base.getEntityType(name);
75 public TypeDescriptor getTypeDescriptor(TCon type) {
76 if(type.module.equals(module.getName()))
77 return module.getTypeDescriptor(type.name);
79 return base.getTypeDescriptor(type);
82 public EffectConstructor getEffectConstructor(TCon type) {
83 if(type.module.equals(module.getName()))
84 return module.getEffectConstructor(type.name);
86 return base.getEffectConstructor(type);
89 public TypeClass getTypeClass(TCon type) {
90 if(type.module.equals(module.getName()))
91 return module.getTypeClass(type.name);
93 return base.getTypeClass(type);
96 public Collection<TypeClassInstance> getInstances(TCon typeClass) {
97 Collection<TypeClassInstance> inst1 = module.getInstances(typeClass);
98 Collection<TypeClassInstance> inst2 = base.getInstances(typeClass);
103 ArrayList<TypeClassInstance> union = new ArrayList<TypeClassInstance>(inst1.size() + inst2.size());
110 public void collectRules(Collection<TransformationRule> rules) {
111 base.collectRules(rules);
112 rules.addAll(module.getRules());