1 package org.simantics.scl.compiler.compilation;
3 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
4 import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
5 import org.simantics.scl.compiler.environment.AmbiguousNameException;
6 import org.simantics.scl.compiler.environment.Environment;
7 import org.simantics.scl.compiler.errors.ErrorLog;
8 import org.simantics.scl.compiler.module.ConcreteModule;
9 import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
11 public class NameExistenceChecks {
12 public static void checkIfValueExists(ErrorLog errorLog, long location,
13 Environment environment, ConcreteModule currentModule, String name) {
14 if(SCLCompilerConfiguration.ALLOW_OVERLOADING) {
15 if(currentModule.getValue(name) != null) {
16 errorLog.log(location,
17 "Value " + name + " has already been defined in this module.");
23 SCLValue value = environment.getLocalNamespace().getValue(name);
25 errorLog.log(location,
26 "Value " + name + " has already been defined in the module " +
27 value.getName().module +
28 " that is imported to the default namespace.");
29 } catch(AmbiguousNameException e) {
30 errorLog.log(location,
31 "Value " + name + " has already been defined in the modules " +
32 e.conflictingModules[0] + " and " + e.conflictingModules[1] +
33 " that are imported to the default namespace.");
38 public static void checkIfTypeExists(ErrorLog errorLog, long location,
39 Environment environment, String name) {
41 TypeDescriptor tdesc = environment.getLocalNamespace().getTypeDescriptor(name);
43 errorLog.log(location,
44 "Type " + name + " has already been defined in the module " +
46 " that is imported to the default namespace.");
47 } catch(AmbiguousNameException e) {
48 errorLog.log(location,
49 "Type " + name + " has already been defined in the modules " +
50 e.conflictingModules[0] + " and " + e.conflictingModules[1] +
51 " that are imported to the default namespace.");