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.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;
21 public class EnvironmentOfModule implements Environment {
24 Namespace localNamespace;
26 public EnvironmentOfModule(Environment base, Module module) {
29 this.localNamespace = new NamespaceOfModule(base.getLocalNamespace(), module);
33 public Namespace getLocalNamespace() {
34 return localNamespace;
38 public SCLValue getValue(Name name) {
39 if(name.module.equals(module.getName()))
40 return module.getValue(name.name);
42 return base.getValue(name);
45 public SCLRelation getRelation(Name name) {
46 if(name.module.equals(module.getName()))
47 return module.getRelation(name.name);
49 return base.getRelation(name);
52 public SCLEntityType getEntityType(Name name) {
53 if(name.module.equals(module.getName()))
54 return module.getEntityType(name.name);
56 return base.getEntityType(name);
59 public TypeConstructor getTypeConstructor(TCon type) {
60 if(type.module.equals(module.getName()))
61 return module.getTypeConstructor(type.name);
63 return base.getTypeConstructor(type);
66 public EffectConstructor getEffectConstructor(TCon type) {
67 if(type.module.equals(module.getName()))
68 return module.getEffectConstructor(type.name);
70 return base.getEffectConstructor(type);
73 public TypeAlias getTypeAlias(TCon type) {
74 if(type.module.equals(module.getName()))
75 return module.getTypeAlias(type.name);
77 return base.getTypeAlias(type);
80 public TypeClass getTypeClass(TCon type) {
81 if(type.module.equals(module.getName()))
82 return module.getTypeClass(type.name);
84 return base.getTypeClass(type);
87 public Collection<TypeClassInstance> getInstances(TCon typeClass) {
88 Collection<TypeClassInstance> inst1 = module.getInstances(typeClass);
89 Collection<TypeClassInstance> inst2 = base.getInstances(typeClass);
94 ArrayList<TypeClassInstance> union = new ArrayList<TypeClassInstance>(inst1.size() + inst2.size());
101 public void collectRules(Collection<TransformationRule> rules) {
102 base.collectRules(rules);
103 rules.addAll(module.getRules());