]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java
(refs #7541) Added support for module deprecation
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / module / ConcreteModule.java
index 8edd9f7019b3f1d01992a2471414b900d21fcd3f..b92f3dff6417c04b5d23b9dfe0899e7315759ed6 100644 (file)
@@ -9,17 +9,18 @@ import java.util.function.Consumer;
 
 import org.simantics.scl.compiler.common.names.Name;
 import org.simantics.scl.compiler.constants.Constant;
+import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
 import org.simantics.scl.compiler.elaboration.modules.Documentation;
 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
-import org.simantics.scl.compiler.elaboration.modules.TypeAlias;
 import org.simantics.scl.compiler.elaboration.modules.TypeClass;
 import org.simantics.scl.compiler.elaboration.modules.TypeClassInstance;
-import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;
+import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
 import org.simantics.scl.compiler.elaboration.relations.SCLEntityType;
 import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
 import org.simantics.scl.compiler.elaboration.rules.MappingRelation;
 import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
 import org.simantics.scl.compiler.environment.filter.NamespaceFilter;
+import org.simantics.scl.compiler.errors.CompilationError;
 import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
 import org.simantics.scl.compiler.top.ModuleInitializer;
 import org.simantics.scl.compiler.types.TCon;
@@ -31,20 +32,25 @@ import gnu.trove.procedure.TObjectProcedure;
 
 public class ConcreteModule implements Module {
     String moduleName;
-    THashMap<String, TypeConstructor> typeConstructors = new THashMap<String, TypeConstructor>();
-    THashMap<String, TypeAlias> typeAliases = new THashMap<String, TypeAlias>();
+    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>();
     THashMap<TCon, ArrayList<TypeClassInstance>> typeClassInstances = new THashMap<TCon, ArrayList<TypeClassInstance>>();
     THashMap<String, SCLValue> values = new THashMap<String, SCLValue>();
-    THashMap<String, SCLRelation> relations = new THashMap<String, SCLRelation>();
-    THashMap<String, SCLEntityType> entityTypes = new THashMap<String, SCLEntityType>();
-    THashMap<String, TransformationRule> rules = new THashMap<String, TransformationRule>();
-    THashMap<String, MappingRelation> mappingRelations = new THashMap<String, MappingRelation>();
+    THashMap<String, List<Constant>> fieldAccessors = new THashMap<String, List<Constant>>();
+    THashMap<String, SCLRelation> relations = new THashMap<String, SCLRelation>(2);
+    THashMap<String, SCLEntityType> entityTypes = new THashMap<String, SCLEntityType>(2);
+    THashMap<String, TransformationRule> rules = new THashMap<String, TransformationRule>(2);
+    THashMap<String, MappingRelation> mappingRelations = new THashMap<String, MappingRelation>(2);
+    THashMap<String, CHRRuleset> rulesets = new THashMap<String, CHRRuleset>(2);
     ArrayList<ImportDeclaration> dependencies = new ArrayList<ImportDeclaration>();
     THashMap<String, BranchPoint[]> branchPoints;
-
+    CompilationError[] warnings = CompilationError.EMPTY_ARRAY;
+    
     Map<String, byte[]> classes = Collections.emptyMap();
+    ClassLoader parentClassLoader;
     ModuleInitializer moduleInitializer;
 
     protected Documentation documentation;
@@ -53,12 +59,17 @@ public class ConcreteModule implements Module {
         this.moduleName = moduleName;
     }
 
-    public boolean addTypeConstructor(String name, TypeConstructor typeConstructor) {
-        return typeConstructors.put(name, typeConstructor) != null;
+    @Override
+    public String getDefaultLocalName() {
+       return defaultLocalName;
     }
-
-    public boolean addTypeAlias(String name, TypeAlias alias) {
-        return typeAliases.put(name, alias) != null;
+    
+    public void setDefaultLocalName(String defaultLocalName) {
+               this.defaultLocalName = defaultLocalName;
+       }
+    
+    public boolean addTypeDescriptor(String name, TypeDescriptor typeConstructor) {
+        return typeDescriptors.put(name, typeConstructor) != null;
     }
 
     public boolean addEffectConstructor(String name, EffectConstructor effectConstructor) {
@@ -99,6 +110,11 @@ public class ConcreteModule implements Module {
         addValue(value);
         return value;
     }
+    
+    @Override
+    public List<Constant> getFieldAccessors(String name) {
+        return fieldAccessors.get(name);
+    }
 
     public void addRelation(String name, SCLRelation relation) {
         relations.put(name, relation);
@@ -169,8 +185,8 @@ public class ConcreteModule implements Module {
     }
 
     @Override
-    public TypeConstructor getTypeConstructor(String name) {
-        return typeConstructors.get(name);
+    public TypeDescriptor getTypeDescriptor(String name) {
+        return typeDescriptors.get(name);
     }
 
     @Override
@@ -178,6 +194,11 @@ public class ConcreteModule implements Module {
         return effectConstructors.get(name);
     }
 
+    @Override
+    public CHRRuleset getRuleset(String name) {
+        return rulesets.get(name);
+    }
+    
     public Collection<TypeClass> getTypeClasses() {
         return typeClasses.values();
     }
@@ -199,11 +220,6 @@ public class ConcreteModule implements Module {
         return documentation;
     }
 
-    @Override
-    public TypeAlias getTypeAlias(String name) {
-        return typeAliases.get(name);
-    }
-
     public void setClasses(Map<String, byte[]> classes) {
         this.classes = classes;
     }
@@ -260,16 +276,11 @@ public class ConcreteModule implements Module {
 
     @Override
     public void findTypesForPrefix(String prefix, NamespaceFilter filter, Consumer<TCon> consumer) {
-        typeConstructors.values().forEach(type -> {
+        typeDescriptors.values().forEach(type -> {
             TCon tcon = type.name;
             if (tcon.name.toLowerCase().startsWith(prefix.toLowerCase()) && filter.isValueIncluded(tcon.name))
                 consumer.accept(tcon);
         });
-        typeAliases.values().forEach(type -> {
-            TCon tcon = type.getCon();
-            if (tcon.name.toLowerCase().startsWith(prefix.toLowerCase()) && filter.isValueIncluded(tcon.name))
-                consumer.accept(tcon);
-        });
     }
     
     public void setBranchPoints(THashMap<String, BranchPoint[]> branchPoints) {
@@ -283,6 +294,46 @@ public class ConcreteModule implements Module {
 
     @Override
     public void dispose() {
-        
+    }
+    
+    public void setWarnings(CompilationError[] warnings) {
+        this.warnings = warnings;
+    }
+    
+    public CompilationError[] getWarnings() {
+        return warnings;
+    }
+    
+    @Override
+    public ClassLoader getParentClassLoader() {
+        return parentClassLoader;
+    }
+    
+    public void setParentClassLoader(ClassLoader parentClassLoader) {
+        if(parentClassLoader == null)
+            throw new NullPointerException();
+        this.parentClassLoader = parentClassLoader;
+    }
+    
+    public void addFieldAccessor(String name, Constant accessor) {
+        List<Constant> list = fieldAccessors.get(name);
+        if(list == null) {
+            list = new ArrayList<Constant>(2);
+            fieldAccessors.put(name, list);
+        }
+        list.add(accessor);
+    }
+
+    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;
     }
 }