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.chr.CHRRuleset;
7 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
8 import org.simantics.scl.compiler.elaboration.modules.TypeClass;
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 CHRRuleset getRuleset(String name) throws AmbiguousNameException {
78 CHRRuleset ruleset = module.getRuleset(name);
81 return base.getRuleset(name);
85 public SCLEntityType getEntityType(String name)
86 throws AmbiguousNameException {
87 SCLEntityType entityType = module.getEntityType(name);
88 if(entityType != null)
90 return base.getEntityType(name);
94 public TypeDescriptor getTypeDescriptor(String name)
95 throws AmbiguousNameException {
96 TypeDescriptor typeDescriptor = module.getTypeDescriptor(name);
97 if(typeDescriptor != null)
98 return typeDescriptor;
99 return base.getTypeDescriptor(name);
103 public EffectConstructor getEffectConstructor(String name)
104 throws AmbiguousNameException {
105 EffectConstructor effectConstructor = module.getEffectConstructor(name);
106 if(effectConstructor != null)
107 return effectConstructor;
108 return base.getEffectConstructor(name);
112 public TypeClass getTypeClass(String name) throws AmbiguousNameException {
113 TypeClass typeClass = module.getTypeClass(name);
114 if(typeClass != null)
116 return base.getTypeClass(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);