]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/NameExistenceChecks.java
Fixed multiple issues causing dangling references to discarded queries
[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.module.ConcreteModule;
9 import org.simantics.scl.compiler.top.SCLCompilerConfiguration;
10
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.");
18             }
19             return;
20         }
21         else {
22             try {
23                 SCLValue value = environment.getLocalNamespace().getValue(name);
24                 if(value != null)
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.");
34             }
35         }
36     }
37     
38     public static void checkIfTypeExists(ErrorLog errorLog, long location,
39             Environment environment, String name) {
40         try {
41             TypeDescriptor tdesc = environment.getLocalNamespace().getTypeDescriptor(name);
42             if(tdesc != null)
43                 errorLog.log(location,
44                         "Type " + name + " has already been defined in the module " + 
45                                 tdesc.name.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.");
52         }
53     }
54 }