1 package org.simantics.scl.compiler.compilation;
3 import java.util.Arrays;
4 import java.util.Collection;
5 import java.util.function.Consumer;
7 import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
8 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
9 import org.simantics.scl.compiler.elaboration.modules.TypeClass;
10 import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
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.top.SCLCompilerConfiguration;
22 import org.simantics.scl.compiler.types.TCon;
24 import gnu.trove.procedure.TObjectProcedure;
26 public class NamespaceOfModule implements Namespace {
27 private final Namespace base;
28 private final Module module;
30 public NamespaceOfModule(Namespace base, Module module) {
36 public Namespace getNamespace(String name) {
37 return base.getNamespace(name);
41 public Collection<String> getNamespaces() {
42 return base.getNamespaces();
46 public SCLValue getValue(String name) throws AmbiguousNameException {
47 SCLValue value = module.getValue(name);
48 if(SCLCompilerConfiguration.ALLOW_OVERLOADING) {
51 value2 = base.getValue(name);
52 } catch(AmbiguousNameException e) {
54 String[] conflictingModules = Arrays.copyOf(e.conflictingModules, e.conflictingModules.length+1);
55 conflictingModules[e.conflictingModules.length] = module.getName();
56 throw new AmbiguousNameException(Arrays.asList(conflictingModules), e.name);
65 throw new AmbiguousNameException(Arrays.asList(value.getName().module, value2.getName().module), value.getName().name);
70 return base.getValue(name);
75 public SCLRelation getRelation(String name) throws AmbiguousNameException {
76 SCLRelation relation = module.getRelation(name);
79 return base.getRelation(name);
83 public CHRRuleset getRuleset(String name) throws AmbiguousNameException {
84 CHRRuleset ruleset = module.getRuleset(name);
87 return base.getRuleset(name);
91 public SCLEntityType getEntityType(String name)
92 throws AmbiguousNameException {
93 SCLEntityType entityType = module.getEntityType(name);
94 if(entityType != null)
96 return base.getEntityType(name);
100 public TypeDescriptor getTypeDescriptor(String name)
101 throws AmbiguousNameException {
102 TypeDescriptor typeDescriptor = module.getTypeDescriptor(name);
103 if(typeDescriptor != null)
104 return typeDescriptor;
105 return base.getTypeDescriptor(name);
109 public EffectConstructor getEffectConstructor(String name)
110 throws AmbiguousNameException {
111 EffectConstructor effectConstructor = module.getEffectConstructor(name);
112 if(effectConstructor != null)
113 return effectConstructor;
114 return base.getEffectConstructor(name);
118 public TypeClass getTypeClass(String name) throws AmbiguousNameException {
119 TypeClass typeClass = module.getTypeClass(name);
120 if(typeClass != null)
122 return base.getTypeClass(name);
126 public MappingRelation getMappingRelation(String name)
127 throws AmbiguousNameException {
128 MappingRelation mappingRelation = module.getMappingRelation(name);
129 if(mappingRelation != null)
130 return mappingRelation;
131 return base.getMappingRelation(name);
135 public TransformationRule getRule(String name) throws AmbiguousNameException {
136 TransformationRule rule = module.getRule(name);
139 return base.getRule(name);
143 public void findValuesForPrefix(String prefix, NamespaceFilter filter, TObjectProcedure<SCLValue> proc) {
144 base.findValuesForPrefix(prefix, filter, proc);
145 module.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
149 public void findTypesForPrefix(String prefix, NamespaceFilter filter, Consumer<TCon> consumer) {
150 base.findTypesForPrefix(prefix, filter, consumer);
151 module.findTypesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, consumer);