]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NamespaceOfModule.java
7b2ee618f5dcf87d2becb248eb49c4e9b8ac6dda
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / compilation / NamespaceOfModule.java
1 package org.simantics.scl.compiler.compilation;
2
3 import gnu.trove.procedure.TObjectProcedure;
4
5 import java.util.function.Consumer;
6
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.TypeConstructor;
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.MappingRelation;
14 import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
15 import org.simantics.scl.compiler.environment.AmbiguousNameException;
16 import org.simantics.scl.compiler.environment.Namespace;
17 import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter;
18 import org.simantics.scl.compiler.environment.filter.NamespaceFilter;
19 import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
20 import org.simantics.scl.compiler.module.Module;
21 import org.simantics.scl.compiler.types.TCon;
22
23 public class NamespaceOfModule implements Namespace {
24     private final Namespace base;
25     private final Module module;
26     
27     public NamespaceOfModule(Namespace base, Module module) {
28         this.base = base;
29         this.module = module;
30     }
31
32     @Override
33     public Namespace getNamespace(String name) {
34         return base.getNamespace(name);
35     }
36
37     @Override
38     public SCLValue getValue(String name) throws AmbiguousNameException {
39         SCLValue value = module.getValue(name);
40         if(value != null)
41             return value;
42         return base.getValue(name);
43     }
44
45     @Override
46     public SCLRelation getRelation(String name) throws AmbiguousNameException {
47         SCLRelation relation = module.getRelation(name);
48         if(relation != null)
49             return relation;
50         return base.getRelation(name);
51     }
52
53     @Override
54     public SCLEntityType getEntityType(String name)
55             throws AmbiguousNameException {
56         SCLEntityType entityType = module.getEntityType(name);
57         if(entityType != null)
58             return entityType;
59         return base.getEntityType(name);
60     }
61
62     @Override
63     public TypeConstructor getTypeConstructor(String name)
64             throws AmbiguousNameException {
65         TypeConstructor typeConstructor = module.getTypeConstructor(name);
66         if(typeConstructor != null)
67             return typeConstructor;
68         return base.getTypeConstructor(name);
69     }
70
71     @Override
72     public EffectConstructor getEffectConstructor(String name)
73             throws AmbiguousNameException {
74         EffectConstructor effectConstructor = module.getEffectConstructor(name);
75         if(effectConstructor != null)
76             return effectConstructor;
77         return base.getEffectConstructor(name);
78     }
79
80     @Override
81     public TypeClass getTypeClass(String name) throws AmbiguousNameException {
82         TypeClass typeClass = module.getTypeClass(name);
83         if(typeClass != null)
84             return typeClass;
85         return base.getTypeClass(name);
86     }
87
88     @Override
89     public TypeAlias getTypeAlias(String name) throws AmbiguousNameException {
90         TypeAlias typeAlias = module.getTypeAlias(name);
91         if(typeAlias != null)
92             return typeAlias;
93         return base.getTypeAlias(name);
94     }
95     
96     @Override
97     public MappingRelation getMappingRelation(String name)
98             throws AmbiguousNameException {
99         MappingRelation mappingRelation = module.getMappingRelation(name);
100         if(mappingRelation != null)
101             return mappingRelation;
102         return base.getMappingRelation(name);
103     }
104     
105     @Override
106     public TransformationRule getRule(String name) throws AmbiguousNameException {
107         TransformationRule rule = module.getRule(name);
108         if(rule != null)
109             return rule;
110         return base.getRule(name);
111     }
112
113     @Override
114     public void findValuesForPrefix(String prefix, NamespaceFilter filter, TObjectProcedure<SCLValue> proc) {
115         base.findValuesForPrefix(prefix, filter, proc);
116         module.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
117     }
118
119     @Override
120     public void findTypesForPrefix(String prefix, NamespaceFilter filter, Consumer<TCon> consumer) {
121         base.findTypesForPrefix(prefix, filter, consumer);
122         module.findTypesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, consumer);
123     }
124     
125 }