]> gerrit.simantics Code Review - simantics/platform.git/blob
1f45c5f41a9d88c8345686e70fcd8b4834dd37ff
[simantics/platform.git] /
1 package org.simantics.scl.compiler.compilation;\r
2 \r
3 import org.simantics.scl.compiler.elaboration.modules.SCLValue;\r
4 import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;\r
5 import org.simantics.scl.compiler.environment.AmbiguousNameException;\r
6 import org.simantics.scl.compiler.environment.Environment;\r
7 import org.simantics.scl.compiler.errors.ErrorLog;\r
8 import org.simantics.scl.compiler.top.SCLCompilerConfiguration;\r
9 \r
10 public class NameExistenceChecks {\r
11     public static void checkIfValueExists(ErrorLog errorLog, long location,\r
12             Environment environment, String name) {\r
13         if(SCLCompilerConfiguration.ALLOW_OVERLOADING)\r
14             return;\r
15         else {\r
16             try {\r
17                 SCLValue value = environment.getLocalNamespace().getValue(name);\r
18                 if(value != null)\r
19                     errorLog.log(location,\r
20                             "Value " + name + " is already defined in the module " + \r
21                                     value.getName().module + \r
22                             " that is imported to the default namespace.");\r
23             } catch(AmbiguousNameException e) {\r
24                 errorLog.log(location,\r
25                         "Value " + name + " is already defined in the modules " + \r
26                                 e.conflictingModules[0] + " and  " + e.conflictingModules[1] +  \r
27                         " that are imported to the default namespace.");\r
28             }\r
29         }\r
30     }\r
31     \r
32     public static void checkIfTypeExists(ErrorLog errorLog, long location,\r
33             Environment environment, String name) {\r
34         try {\r
35             TypeConstructor value = environment.getLocalNamespace().getTypeConstructor(name);\r
36             if(value != null)\r
37                 errorLog.log(location,\r
38                         "Type " + name + " is already defined in the module " + \r
39                                 value.name.module + \r
40                         " that is imported to the default namespace.");\r
41         } catch(AmbiguousNameException e) {\r
42             errorLog.log(location,\r
43                     "Type " + name + " is already defined in the modules " + \r
44                             e.conflictingModules[0] + " and  " + e.conflictingModules[1] +  \r
45                     " that are imported to the default namespace.");\r
46         }\r
47     }\r
48 }\r