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.TypeClass;
8 import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
9 import org.simantics.scl.compiler.elaboration.relations.SCLEntityType;
10 import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
11 import org.simantics.scl.compiler.elaboration.rules.MappingRelation;
12 import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
13 import org.simantics.scl.compiler.environment.AmbiguousNameException;
14 import org.simantics.scl.compiler.environment.Namespace;
15 import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter;
16 import org.simantics.scl.compiler.environment.filter.NamespaceFilter;
17 import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
18 import org.simantics.scl.compiler.module.Module;
19 import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
20 import org.simantics.scl.compiler.types.TCon;
22 import gnu.trove.procedure.TObjectProcedure;
24 public class NamespaceOfModule implements Namespace {
25 private final Namespace base;
26 private final Module module;
28 public NamespaceOfModule(Namespace base, Module module) {
34 public Namespace getNamespace(String name) {
35 return base.getNamespace(name);
39 public SCLValue getValue(String name) throws AmbiguousNameException {
40 SCLValue value = module.getValue(name);
41 if(SCLCompilerConfiguration.ALLOW_OVERLOADING) {
44 value2 = base.getValue(name);
45 } catch(AmbiguousNameException e) {
47 String[] conflictingModules = Arrays.copyOf(e.conflictingModules, e.conflictingModules.length+1);
48 conflictingModules[e.conflictingModules.length] = module.getName();
49 throw new AmbiguousNameException(Arrays.asList(conflictingModules), e.name);
58 throw new AmbiguousNameException(Arrays.asList(value.getName().module, value2.getName().module), value.getName().name);
63 return base.getValue(name);
68 public SCLRelation getRelation(String name) throws AmbiguousNameException {
69 SCLRelation relation = module.getRelation(name);
72 return base.getRelation(name);
76 public SCLEntityType getEntityType(String name)
77 throws AmbiguousNameException {
78 SCLEntityType entityType = module.getEntityType(name);
79 if(entityType != null)
81 return base.getEntityType(name);
85 public TypeDescriptor getTypeDescriptor(String name)
86 throws AmbiguousNameException {
87 TypeDescriptor typeDescriptor = module.getTypeDescriptor(name);
88 if(typeDescriptor != null)
89 return typeDescriptor;
90 return base.getTypeDescriptor(name);
94 public EffectConstructor getEffectConstructor(String name)
95 throws AmbiguousNameException {
96 EffectConstructor effectConstructor = module.getEffectConstructor(name);
97 if(effectConstructor != null)
98 return effectConstructor;
99 return base.getEffectConstructor(name);
103 public TypeClass getTypeClass(String name) throws AmbiguousNameException {
104 TypeClass typeClass = module.getTypeClass(name);
105 if(typeClass != null)
107 return base.getTypeClass(name);
111 public MappingRelation getMappingRelation(String name)
112 throws AmbiguousNameException {
113 MappingRelation mappingRelation = module.getMappingRelation(name);
114 if(mappingRelation != null)
115 return mappingRelation;
116 return base.getMappingRelation(name);
120 public TransformationRule getRule(String name) throws AmbiguousNameException {
121 TransformationRule rule = module.getRule(name);
124 return base.getRule(name);
128 public void findValuesForPrefix(String prefix, NamespaceFilter filter, TObjectProcedure<SCLValue> proc) {
129 base.findValuesForPrefix(prefix, filter, proc);
130 module.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
134 public void findTypesForPrefix(String prefix, NamespaceFilter filter, Consumer<TCon> consumer) {
135 base.findTypesForPrefix(prefix, filter, consumer);
136 module.findTypesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, consumer);