X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fcompilation%2FNameExistenceChecks.java;h=b9f2f8597a03f8a0cd74b2a74082ca363adb663b;hb=ae20feb8fa4c5c2534979df4b1496dfd57e37413;hp=1f45c5f41a9d88c8345686e70fcd8b4834dd37ff;hpb=9a175feb652b2b7bba7afa540831b9076be3c10e;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NameExistenceChecks.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NameExistenceChecks.java index 1f45c5f41..b9f2f8597 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NameExistenceChecks.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NameExistenceChecks.java @@ -1,48 +1,54 @@ -package org.simantics.scl.compiler.compilation; - -import org.simantics.scl.compiler.elaboration.modules.SCLValue; -import org.simantics.scl.compiler.elaboration.modules.TypeConstructor; -import org.simantics.scl.compiler.environment.AmbiguousNameException; -import org.simantics.scl.compiler.environment.Environment; -import org.simantics.scl.compiler.errors.ErrorLog; -import org.simantics.scl.compiler.top.SCLCompilerConfiguration; - -public class NameExistenceChecks { - public static void checkIfValueExists(ErrorLog errorLog, long location, - Environment environment, String name) { - if(SCLCompilerConfiguration.ALLOW_OVERLOADING) - return; - else { - try { - SCLValue value = environment.getLocalNamespace().getValue(name); - if(value != null) - errorLog.log(location, - "Value " + name + " is already defined in the module " + - value.getName().module + - " that is imported to the default namespace."); - } catch(AmbiguousNameException e) { - errorLog.log(location, - "Value " + name + " is already defined in the modules " + - e.conflictingModules[0] + " and " + e.conflictingModules[1] + - " that are imported to the default namespace."); - } - } - } - - public static void checkIfTypeExists(ErrorLog errorLog, long location, - Environment environment, String name) { - try { - TypeConstructor value = environment.getLocalNamespace().getTypeConstructor(name); - if(value != null) - errorLog.log(location, - "Type " + name + " is already defined in the module " + - value.name.module + - " that is imported to the default namespace."); - } catch(AmbiguousNameException e) { - errorLog.log(location, - "Type " + name + " is already defined in the modules " + - e.conflictingModules[0] + " and " + e.conflictingModules[1] + - " that are imported to the default namespace."); - } - } -} +package org.simantics.scl.compiler.compilation; + +import org.simantics.scl.compiler.elaboration.modules.SCLValue; +import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor; +import org.simantics.scl.compiler.environment.AmbiguousNameException; +import org.simantics.scl.compiler.environment.Environment; +import org.simantics.scl.compiler.errors.ErrorLog; +import org.simantics.scl.compiler.module.ConcreteModule; +import org.simantics.scl.compiler.top.SCLCompilerConfiguration; + +public class NameExistenceChecks { + public static void checkIfValueExists(ErrorLog errorLog, long location, + Environment environment, ConcreteModule currentModule, String name) { + if(SCLCompilerConfiguration.ALLOW_OVERLOADING) { + if(currentModule.getValue(name) != null) { + errorLog.log(location, + "Value " + name + " has already been defined in this module."); + } + return; + } + else { + try { + SCLValue value = environment.getLocalNamespace().getValue(name); + if(value != null) + errorLog.log(location, + "Value " + name + " has already been defined in the module " + + value.getName().module + + " that is imported to the default namespace."); + } catch(AmbiguousNameException e) { + errorLog.log(location, + "Value " + name + " has already been defined in the modules " + + e.conflictingModules[0] + " and " + e.conflictingModules[1] + + " that are imported to the default namespace."); + } + } + } + + public static void checkIfTypeExists(ErrorLog errorLog, long location, + Environment environment, String name) { + try { + TypeDescriptor tdesc = environment.getLocalNamespace().getTypeDescriptor(name); + if(tdesc != null) + errorLog.log(location, + "Type " + name + " has already been defined in the module " + + tdesc.name.module + + " that is imported to the default namespace."); + } catch(AmbiguousNameException e) { + errorLog.log(location, + "Type " + name + " has already been defined in the modules " + + e.conflictingModules[0] + " and " + e.conflictingModules[1] + + " that are imported to the default namespace."); + } + } +}