]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java
(refs #7541) Added support for module deprecation
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / compilation / Elaboration.java
index fccf2681507466ef7f4c9b6f44dc6aab04f76b04..f7f745841460bdbfc30aacbd0a35b5174620208f 100644 (file)
@@ -61,7 +61,9 @@ import org.simantics.scl.compiler.environment.AmbiguousNameException;
 import org.simantics.scl.compiler.environment.Environment;
 import org.simantics.scl.compiler.environment.EnvironmentFactory;
 import org.simantics.scl.compiler.environment.Environments;
+import org.simantics.scl.compiler.errors.CompilationError;
 import org.simantics.scl.compiler.errors.ErrorLog;
+import org.simantics.scl.compiler.errors.ErrorSeverity;
 import org.simantics.scl.compiler.errors.Locations;
 import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
 import org.simantics.scl.compiler.internal.codegen.effects.ThreadLocalVariable;
@@ -167,19 +169,24 @@ public class Elaboration {
 
         module = new ConcreteModule(moduleName);
         compilationContext.module = module;
-        if(moduleHeader != null && moduleHeader.defaultLocalName != null)
-               module.setDefaultLocalName(moduleHeader.defaultLocalName);
+        if(moduleHeader != null) {
+            if(moduleHeader.defaultLocalName != null)
+                module.setDefaultLocalName(moduleHeader.defaultLocalName);
+            if(moduleHeader.deprecated != null)
+                module.setDeprecation(moduleHeader.deprecated);
+        }
         try {
             if(timer != null)
                 timer.suspendTimer();
             importedEnvironment = localEnvironmentFactory.createEnvironment(
+                    compilationContext,
                     importsAst.toArray(new ImportDeclaration[importsAst.size()]));
             if(timer != null)
                 timer.continueTimer();
             compilationContext.environment = new EnvironmentOfModule(importedEnvironment, module);
         } catch (ImportFailureException e) {
             for(ImportFailure failure : e.failures)
-                errorLog.log(failure.location, failure.toString());
+                errorLog.log(new CompilationError(failure.location, failure.toString(), ErrorSeverity.IMPORT_ERROR));
             return;
         }
         for(ImportDeclaration importAst : importsAst)
@@ -710,7 +717,7 @@ public class Elaboration {
                     type);
             if(callJava != null) {
                 NameExistenceChecks.checkIfValueExists(errorLog, javaMethod.location,
-                        importedEnvironment, name);
+                        importedEnvironment, module, name);
                 SCLValue value = module.addValue(name, callJava);
                 value.definitionLocation = javaMethod.methodName.location;
                 if(isPrivate)
@@ -1113,6 +1120,7 @@ public class Elaboration {
             int constructorTag = 0;
             for(Constructor constructor : dataType.constructors) {
                 SCLValue value = new SCLValue(constructor.name);
+                value.definitionLocation = constructor.loc;
                 SCLConstructor sclConstructor = 
                         new SCLConstructor(
                                 constructor.name.name,
@@ -1134,7 +1142,7 @@ public class Elaboration {
                 value.setType(constructor.getType());
                 
                 NameExistenceChecks.checkIfValueExists(errorLog, constructor.loc,
-                        importedEnvironment, constructor.name.name);
+                        importedEnvironment, module, constructor.name.name);
                 if(module.addValue(value)) {
                     errorLog.log(constructor.loc,
                             "Value " + constructor.name.name + " is already defined.");
@@ -1149,7 +1157,7 @@ public class Elaboration {
                 SCLValue value = method.createValue();
                 value.definitionLocation = method.location;
                 NameExistenceChecks.checkIfValueExists(errorLog, Locations.NO_LOCATION,
-                        importedEnvironment, value.getName().name);
+                        importedEnvironment, module, value.getName().name);
 
                 if(module.addValue(value)) {
                     String name = method.getName();
@@ -1169,7 +1177,7 @@ public class Elaboration {
             
             long location = valueDefinitionsAst.getLocation(name);
             NameExistenceChecks.checkIfValueExists(errorLog, location,
-                    importedEnvironment, value.getName().name);
+                    importedEnvironment, module, value.getName().name);
             value.definitionLocation = location;
             if(module.addValue(value))
                 errorLog.log(location, "Value " + name + " is already defined.");
@@ -1212,6 +1220,25 @@ public class Elaboration {
         
         for(String name : valueDefinitionsAst.getValueNames()) {
             ArrayList<DValueAst> defs = valueDefinitionsAst.getDefinition(name);
+            if(defs.size() != 1 || !(defs.get(0).value instanceof EPreCHRRulesetConstructor))
+                continue;
+            try {
+                SCLValue value = module.getValue(name);
+                TranslationContext context = createTranslationContext();
+                Expression expression = context.translateCases2(defs);
+                value.setExpression(expression);
+                
+                if(exportMap != null && exportMap.remove(name) == null)
+                    value.addProperty(PrivateProperty.INSTANCE);
+            } catch(RuntimeException e) {
+                errorLog.setExceptionPosition(defs.get(0).location);
+                throw e;
+            }
+        }
+        for(String name : valueDefinitionsAst.getValueNames()) {
+            ArrayList<DValueAst> defs = valueDefinitionsAst.getDefinition(name);
+            if(defs.size() == 1 && defs.get(0).value instanceof EPreCHRRulesetConstructor)
+                continue;
             try {
                 SCLValue value = module.getValue(name);
                 TranslationContext context = createTranslationContext();