1 package org.simantics.scl.compiler.compilation;
3 import gnu.trove.procedure.TObjectProcedure;
5 import java.util.function.Consumer;
7 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
8 import org.simantics.scl.compiler.elaboration.modules.TypeAlias;
9 import org.simantics.scl.compiler.elaboration.modules.TypeClass;
10 import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;
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.types.TCon;
23 public class NamespaceOfModule implements Namespace {
24 private final Namespace base;
25 private final Module module;
27 public NamespaceOfModule(Namespace base, Module module) {
33 public Namespace getNamespace(String name) {
34 return base.getNamespace(name);
38 public SCLValue getValue(String name) throws AmbiguousNameException {
39 SCLValue value = module.getValue(name);
42 return base.getValue(name);
46 public SCLRelation getRelation(String name) throws AmbiguousNameException {
47 SCLRelation relation = module.getRelation(name);
50 return base.getRelation(name);
54 public SCLEntityType getEntityType(String name)
55 throws AmbiguousNameException {
56 SCLEntityType entityType = module.getEntityType(name);
57 if(entityType != null)
59 return base.getEntityType(name);
63 public TypeConstructor getTypeConstructor(String name)
64 throws AmbiguousNameException {
65 TypeConstructor typeConstructor = module.getTypeConstructor(name);
66 if(typeConstructor != null)
67 return typeConstructor;
68 return base.getTypeConstructor(name);
72 public EffectConstructor getEffectConstructor(String name)
73 throws AmbiguousNameException {
74 EffectConstructor effectConstructor = module.getEffectConstructor(name);
75 if(effectConstructor != null)
76 return effectConstructor;
77 return base.getEffectConstructor(name);
81 public TypeClass getTypeClass(String name) throws AmbiguousNameException {
82 TypeClass typeClass = module.getTypeClass(name);
85 return base.getTypeClass(name);
89 public TypeAlias getTypeAlias(String name) throws AmbiguousNameException {
90 TypeAlias typeAlias = module.getTypeAlias(name);
93 return base.getTypeAlias(name);
97 public MappingRelation getMappingRelation(String name)
98 throws AmbiguousNameException {
99 MappingRelation mappingRelation = module.getMappingRelation(name);
100 if(mappingRelation != null)
101 return mappingRelation;
102 return base.getMappingRelation(name);
106 public TransformationRule getRule(String name) throws AmbiguousNameException {
107 TransformationRule rule = module.getRule(name);
110 return base.getRule(name);
114 public void findValuesForPrefix(String prefix, NamespaceFilter filter, TObjectProcedure<SCLValue> proc) {
115 base.findValuesForPrefix(prefix, filter, proc);
116 module.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
120 public void findTypesForPrefix(String prefix, NamespaceFilter filter, Consumer<TCon> consumer) {
121 base.findTypesForPrefix(prefix, filter, consumer);
122 module.findTypesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, consumer);