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.TypeConstructor;
9 import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
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 TypeDescriptor getTypeDescriptor(String name)
87 throws AmbiguousNameException {
88 TypeDescriptor typeDescriptor = module.getTypeDescriptor(name);
89 if(typeDescriptor != null)
90 return typeDescriptor;
91 return base.getTypeDescriptor(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 MappingRelation getMappingRelation(String name)
113 throws AmbiguousNameException {
114 MappingRelation mappingRelation = module.getMappingRelation(name);
115 if(mappingRelation != null)
116 return mappingRelation;
117 return base.getMappingRelation(name);
121 public TransformationRule getRule(String name) throws AmbiguousNameException {
122 TransformationRule rule = module.getRule(name);
125 return base.getRule(name);
129 public void findValuesForPrefix(String prefix, NamespaceFilter filter, TObjectProcedure<SCLValue> proc) {
130 base.findValuesForPrefix(prefix, filter, proc);
131 module.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
135 public void findTypesForPrefix(String prefix, NamespaceFilter filter, Consumer<TCon> consumer) {
136 base.findTypesForPrefix(prefix, filter, consumer);
137 module.findTypesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, consumer);