]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NameExistenceChecks.java
(refs #7250) Merging master, minor CHR bugfixes
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / compilation / NameExistenceChecks.java
1 package org.simantics.scl.compiler.compilation;
2
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.top.SCLCompilerConfiguration;
9
10 public class NameExistenceChecks {
11     public static void checkIfValueExists(ErrorLog errorLog, long location,
12             Environment environment, String name) {
13         if(SCLCompilerConfiguration.ALLOW_OVERLOADING)
14             return;
15         else {
16             try {
17                 SCLValue value = environment.getLocalNamespace().getValue(name);
18                 if(value != null)
19                     errorLog.log(location,
20                             "Value " + name + " is already defined in the module " + 
21                                     value.getName().module + 
22                             " that is imported to the default namespace.");
23             } catch(AmbiguousNameException e) {
24                 errorLog.log(location,
25                         "Value " + name + " is already defined in the modules " + 
26                                 e.conflictingModules[0] + " and  " + e.conflictingModules[1] +  
27                         " that are imported to the default namespace.");
28             }
29         }
30     }
31     
32     public static void checkIfTypeExists(ErrorLog errorLog, long location,
33             Environment environment, String name) {
34         try {
35             TypeDescriptor tdesc = environment.getLocalNamespace().getTypeDescriptor(name);
36             if(tdesc != null)
37                 errorLog.log(location,
38                         "Type " + name + " is already defined in the module " + 
39                                 tdesc.name.module + 
40                         " that is imported to the default namespace.");
41         } catch(AmbiguousNameException e) {
42             errorLog.log(location,
43                     "Type " + name + " is already defined in the modules " + 
44                             e.conflictingModules[0] + " and  " + e.conflictingModules[1] +  
45                     " that are imported to the default namespace.");
46         }
47     }
48 }