]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
(refs #7541) Added support for module deprecation 94/1094/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 10 Oct 2017 15:40:00 +0000 (18:40 +0300)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Tue, 10 Oct 2017 15:40:00 +0000 (18:40 +0300)
Change-Id: I61eac59be8891aabc00e0142f6ef812c6ddba922

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/EnvironmentFactory.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/EnvironmentFactoryImpl.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java

index 50296a3a1c6c287fb12b7a3564bf26af44f7a568..f7f745841460bdbfc30aacbd0a35b5174620208f 100644 (file)
@@ -169,12 +169,17 @@ 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();
index f5799ba6777f13f8f7e2896d3f0140d2d476c5e4..1faa8f6459c3373382add3dde58a5d832b2dff6c 100644 (file)
@@ -1,12 +1,13 @@
 package org.simantics.scl.compiler.environment;
 
+import org.simantics.scl.compiler.compilation.CompilationContext;
 import org.simantics.scl.compiler.module.ConcreteModule;
 import org.simantics.scl.compiler.module.ImportDeclaration;
 import org.simantics.scl.compiler.module.repository.ImportFailureException;
 
 public interface EnvironmentFactory {
 
-    Environment createEnvironment(ImportDeclaration[] array) throws ImportFailureException;
+    Environment createEnvironment(CompilationContext context, ImportDeclaration[] array) throws ImportFailureException;
     void addBuiltinDependencies(ConcreteModule module);
 
 }
index 79009374813197eb8aaa7529cd7d159302a57e30..1a7fb3c6d89e5afe27186ec72aba82456058fc19 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.scl.compiler.environment;
 import java.util.ArrayList;
 import java.util.Arrays;
 
+import org.simantics.scl.compiler.compilation.CompilationContext;
 import org.simantics.scl.compiler.module.ConcreteModule;
 import org.simantics.scl.compiler.module.ImportDeclaration;
 import org.simantics.scl.compiler.module.repository.ImportFailureException;
@@ -23,7 +24,7 @@ public class EnvironmentFactoryImpl implements EnvironmentFactory {
     }
 
     @Override
-    public Environment createEnvironment(ImportDeclaration[] imports) throws ImportFailureException {
+    public Environment createEnvironment(CompilationContext context, ImportDeclaration[] imports) throws ImportFailureException {
         ArrayList<ImportDeclaration> acceptedBuiltinImports = 
                 new ArrayList<ImportDeclaration>(builtinImports.length);
         loop: for(ImportDeclaration builtinImport : builtinImports) {
@@ -37,7 +38,7 @@ public class EnvironmentFactoryImpl implements EnvironmentFactory {
                 acceptedBuiltinImports.toArray(new ImportDeclaration[acceptedBuiltinImports.size()]),
                 acceptedBuiltinImports.size() + imports.length);
         System.arraycopy(imports, 0, is, acceptedBuiltinImports.size(), imports.length);
-        return environment.createEnvironment(is, listener);
+        return environment.createEnvironment(context, is, listener);
     }
     
     @Override
index 73311e99ab9ab4a17f087d1f215b15de89286929..b92f3dff6417c04b5d23b9dfe0899e7315759ed6 100644 (file)
@@ -33,6 +33,7 @@ import gnu.trove.procedure.TObjectProcedure;
 public class ConcreteModule implements Module {
     String moduleName;
     String defaultLocalName;
+    String deprecation;
     THashMap<String, TypeDescriptor> typeDescriptors = new THashMap<String, TypeDescriptor>();
     THashMap<String, EffectConstructor> effectConstructors = new THashMap<String, EffectConstructor>();
     THashMap<String, TypeClass> typeClasses = new THashMap<String, TypeClass>();
@@ -326,4 +327,13 @@ public class ConcreteModule implements Module {
     public void addRuleset(String name, CHRRuleset ruleset) {
         rulesets.put(name, ruleset);
     }
+
+    @Override
+    public String getDeprecation() {
+        return deprecation;
+    }
+
+    public void setDeprecation(String deprecation) {
+        this.deprecation = deprecation;
+    }
 }
index 61d2c29288992f63ddb6ab2209a9336f86e918d8..6daef2b172bd27c0c8febf7dd3359b25b4dd190e 100644 (file)
@@ -152,4 +152,9 @@ public abstract class LazyModule implements Module {
     public CHRRuleset getRuleset(String name) {
         return null;
     }
+    
+    @Override
+    public String getDeprecation() {
+        return null;
+    }
 }
index ee90b5e1a3f7f263406debf52453ea531f394d25..6e6690fef173b17e11422bb7c79e0148104648ac 100644 (file)
@@ -60,4 +60,5 @@ public interface Module {
 
     CompilationError[] getWarnings();
     ClassLoader getParentClassLoader();
+    String getDeprecation();
 }
index 40c69f4348861e2d4bd58877d762f4677d90c7f1..089f2c26c95469e639176ed9f50136b91a9c46c7 100644 (file)
@@ -7,6 +7,7 @@ import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
+import org.simantics.scl.compiler.compilation.CompilationContext;
 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
 import org.simantics.scl.compiler.environment.ConcreteEnvironment;
 import org.simantics.scl.compiler.environment.Environment;
@@ -159,7 +160,7 @@ public class ModuleRepository {
                         Collection<ImportDeclaration> dependencies = module.getDependencies();
                         THashMap<String, ModuleEntry> moduleEntries;
                         try {
-                            moduleEntries = getModuleEntries(dependencies.toArray(new ImportDeclaration[dependencies.size()]), null);
+                            moduleEntries = getModuleEntries(null, dependencies.toArray(new ImportDeclaration[dependencies.size()]), null);
                         } catch (ImportFailureException e) {
                             throw new InternalCompilerError(e);
                         }
@@ -254,6 +255,7 @@ public class ModuleRepository {
     }
     
     private THashMap<String, ModuleEntry> getModuleEntries(
+            CompilationContext compilationContext,
             ImportDeclaration[] imports,
             UpdateListener listener) throws ImportFailureException {
         THashMap<String, ModuleEntry> result = new THashMap<String, ModuleEntry>();
@@ -268,11 +270,17 @@ public class ModuleRepository {
         while(!stack.isEmpty()) {
             ImportDeclaration import_ = stack.remove(stack.size()-1);
             if(!result.containsKey(import_.moduleName)) {
-                ModuleEntry entry = getModuleEntry(import_.moduleName, originalImports.contains(import_.moduleName) ? listener : null);
+                boolean originalImport = originalImports.contains(import_.moduleName);
+                ModuleEntry entry = getModuleEntry(import_.moduleName, originalImport ? listener : null);
                 Failable<Module> compilationResult = entry.compilationResult;
                 if(compilationResult.didSucceed()) {
                     result.put(import_.moduleName, entry);
                     stack.addAll(compilationResult.getResult().getDependencies());
+                    if(originalImport) {
+                        String deprecation = compilationResult.getResult().getDeprecation();
+                        if(deprecation != null && compilationContext != null)
+                            compilationContext.errorLog.logWarning(import_.location, "Deprecated module " + import_.moduleName   + (deprecation.isEmpty() ? "." : ": " + deprecation));
+                    }
                 }
                 else {
                     if(failures == null)
@@ -318,7 +326,14 @@ public class ModuleRepository {
     public Environment createEnvironment(
             ImportDeclaration[] imports,
             UpdateListener listener) throws ImportFailureException {
-        THashMap<String, ModuleEntry> entries = getModuleEntries(imports, listener);
+        return createEnvironment(null, imports, listener);
+    }
+    
+    public Environment createEnvironment(
+            CompilationContext compilationContext,
+            ImportDeclaration[] imports,
+            UpdateListener listener) throws ImportFailureException {
+        THashMap<String, ModuleEntry> entries = getModuleEntries(compilationContext, imports, listener);
         THashMap<String, Module> moduleMap = mapEntriesToModules(entries);
         return createEnvironment(moduleMap, imports);
     }
@@ -348,14 +363,15 @@ public class ModuleRepository {
             ImportDeclaration[] imports,
             ClassLoader parentClassLoader,
             UpdateListener listener) throws ImportFailureException {
-        THashMap<String, ModuleEntry> entries = getModuleEntries(imports, listener);
+        THashMap<String, ModuleEntry> entries = getModuleEntries(null, imports, listener);
         THashMap<String, Module> moduleMap = mapEntriesToModules(entries);
         Environment environment = createEnvironment(moduleMap, imports);
         THashMap<String, RuntimeModule> runtimeModuleMap = mapEntriesToRuntimeModules(entries);
         return new RuntimeEnvironmentImpl(environment, parentClassLoader, runtimeModuleMap);
     }
     
-    private static Environment createEnvironment(THashMap<String, Module> moduleMap, 
+    private static Environment createEnvironment(
+            THashMap<String, Module> moduleMap, 
             ImportDeclaration[] imports) {
         NamespaceSpec spec = new NamespaceSpec();
         for(ImportDeclaration import_ : imports)