1 package org.simantics.scl.compiler.compilation;
3 import java.util.Arrays;
4 import java.util.function.Consumer;
6 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
7 import org.simantics.scl.compiler.elaboration.modules.TypeAlias;
8 import org.simantics.scl.compiler.elaboration.modules.TypeClass;
9 import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;
10 import org.simantics.scl.compiler.elaboration.relations.SCLEntityType;
11 import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
12 import org.simantics.scl.compiler.elaboration.rules.MappingRelation;
13 import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
14 import org.simantics.scl.compiler.environment.AmbiguousNameException;
15 import org.simantics.scl.compiler.environment.Namespace;
16 import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter;
17 import org.simantics.scl.compiler.environment.filter.NamespaceFilter;
18 import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
19 import org.simantics.scl.compiler.module.Module;
20 import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
21 import org.simantics.scl.compiler.types.TCon;
23 import gnu.trove.procedure.TObjectProcedure;
25 public class NamespaceOfModule implements Namespace {
26 private final Namespace base;
27 private final Module module;
29 public NamespaceOfModule(Namespace base, Module module) {
35 public Namespace getNamespace(String name) {
36 return base.getNamespace(name);
40 public SCLValue getValue(String name) throws AmbiguousNameException {
41 SCLValue value = module.getValue(name);
42 if(SCLCompilerConfiguration.ALLOW_OVERLOADING) {
45 value2 = base.getValue(name);
46 } catch(AmbiguousNameException e) {
48 String[] conflictingModules = Arrays.copyOf(e.conflictingModules, e.conflictingModules.length+1);
49 conflictingModules[e.conflictingModules.length] = module.getName();
50 throw new AmbiguousNameException(Arrays.asList(conflictingModules), e.name);
59 throw new AmbiguousNameException(Arrays.asList(value.getName().module, value2.getName().module), value.getName().name);
64 return base.getValue(name);
69 public SCLRelation getRelation(String name) throws AmbiguousNameException {
70 SCLRelation relation = module.getRelation(name);
73 return base.getRelation(name);
77 public SCLEntityType getEntityType(String name)
78 throws AmbiguousNameException {
79 SCLEntityType entityType = module.getEntityType(name);
80 if(entityType != null)
82 return base.getEntityType(name);
86 public TypeConstructor getTypeConstructor(String name)
87 throws AmbiguousNameException {
88 TypeConstructor typeConstructor = module.getTypeConstructor(name);
89 if(typeConstructor != null)
90 return typeConstructor;
91 return base.getTypeConstructor(name);
95 public EffectConstructor getEffectConstructor(String name)
96 throws AmbiguousNameException {
97 EffectConstructor effectConstructor = module.getEffectConstructor(name);
98 if(effectConstructor != null)
99 return effectConstructor;
100 return base.getEffectConstructor(name);
104 public TypeClass getTypeClass(String name) throws AmbiguousNameException {
105 TypeClass typeClass = module.getTypeClass(name);
106 if(typeClass != null)
108 return base.getTypeClass(name);
112 public TypeAlias getTypeAlias(String name) throws AmbiguousNameException {
113 TypeAlias typeAlias = module.getTypeAlias(name);
114 if(typeAlias != null)
116 return base.getTypeAlias(name);
120 public MappingRelation getMappingRelation(String name)
121 throws AmbiguousNameException {
122 MappingRelation mappingRelation = module.getMappingRelation(name);
123 if(mappingRelation != null)
124 return mappingRelation;
125 return base.getMappingRelation(name);
129 public TransformationRule getRule(String name) throws AmbiguousNameException {
130 TransformationRule rule = module.getRule(name);
133 return base.getRule(name);
137 public void findValuesForPrefix(String prefix, NamespaceFilter filter, TObjectProcedure<SCLValue> proc) {
138 base.findValuesForPrefix(prefix, filter, proc);
139 module.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
143 public void findTypesForPrefix(String prefix, NamespaceFilter filter, Consumer<TCon> consumer) {
144 base.findTypesForPrefix(prefix, filter, consumer);
145 module.findTypesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, consumer);