X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fcompilation%2FNamespaceOfModule.java;h=8621283b73dc5e12bb7a1c5473d36cc438518567;hp=7b2ee618f5dcf87d2becb248eb49c4e9b8ac6dda;hb=fad36d463b75c3a9944d875fc627c3533f6da74d;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NamespaceOfModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NamespaceOfModule.java index 7b2ee618f..8621283b7 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NamespaceOfModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NamespaceOfModule.java @@ -1,13 +1,12 @@ package org.simantics.scl.compiler.compilation; -import gnu.trove.procedure.TObjectProcedure; - +import java.util.Arrays; import java.util.function.Consumer; +import org.simantics.scl.compiler.elaboration.chr.CHRRuleset; import org.simantics.scl.compiler.elaboration.modules.SCLValue; -import org.simantics.scl.compiler.elaboration.modules.TypeAlias; import org.simantics.scl.compiler.elaboration.modules.TypeClass; -import org.simantics.scl.compiler.elaboration.modules.TypeConstructor; +import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor; import org.simantics.scl.compiler.elaboration.relations.SCLEntityType; import org.simantics.scl.compiler.elaboration.relations.SCLRelation; import org.simantics.scl.compiler.elaboration.rules.MappingRelation; @@ -18,8 +17,11 @@ import org.simantics.scl.compiler.environment.filter.AcceptAllNamespaceFilter; import org.simantics.scl.compiler.environment.filter.NamespaceFilter; import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor; import org.simantics.scl.compiler.module.Module; +import org.simantics.scl.compiler.top.SCLCompilerConfiguration; import org.simantics.scl.compiler.types.TCon; +import gnu.trove.procedure.TObjectProcedure; + public class NamespaceOfModule implements Namespace { private final Namespace base; private final Module module; @@ -37,11 +39,32 @@ public class NamespaceOfModule implements Namespace { @Override public SCLValue getValue(String name) throws AmbiguousNameException { SCLValue value = module.getValue(name); - if(value != null) - return value; - return base.getValue(name); + if(SCLCompilerConfiguration.ALLOW_OVERLOADING) { + SCLValue value2; + try { + value2 = base.getValue(name); + } catch(AmbiguousNameException e) { + if(value != null) { + String[] conflictingModules = Arrays.copyOf(e.conflictingModules, e.conflictingModules.length+1); + conflictingModules[e.conflictingModules.length] = module.getName(); + throw new AmbiguousNameException(Arrays.asList(conflictingModules), e.name); + } + else + throw e; + } + if(value == null) + return value2; + if(value2 == null) + return value; + throw new AmbiguousNameException(Arrays.asList(value.getName().module, value2.getName().module), value.getName().name); + } + else { + if(value != null) + return value; + return base.getValue(name); + } } - + @Override public SCLRelation getRelation(String name) throws AmbiguousNameException { SCLRelation relation = module.getRelation(name); @@ -50,6 +73,14 @@ public class NamespaceOfModule implements Namespace { return base.getRelation(name); } + @Override + public CHRRuleset getRuleset(String name) throws AmbiguousNameException { + CHRRuleset ruleset = module.getRuleset(name); + if(ruleset != null) + return ruleset; + return base.getRuleset(name); + } + @Override public SCLEntityType getEntityType(String name) throws AmbiguousNameException { @@ -60,12 +91,12 @@ public class NamespaceOfModule implements Namespace { } @Override - public TypeConstructor getTypeConstructor(String name) + public TypeDescriptor getTypeDescriptor(String name) throws AmbiguousNameException { - TypeConstructor typeConstructor = module.getTypeConstructor(name); - if(typeConstructor != null) - return typeConstructor; - return base.getTypeConstructor(name); + TypeDescriptor typeDescriptor = module.getTypeDescriptor(name); + if(typeDescriptor != null) + return typeDescriptor; + return base.getTypeDescriptor(name); } @Override @@ -84,14 +115,6 @@ public class NamespaceOfModule implements Namespace { return typeClass; return base.getTypeClass(name); } - - @Override - public TypeAlias getTypeAlias(String name) throws AmbiguousNameException { - TypeAlias typeAlias = module.getTypeAlias(name); - if(typeAlias != null) - return typeAlias; - return base.getTypeAlias(name); - } @Override public MappingRelation getMappingRelation(String name)