]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java
(refs #7809) Added builtin Pure type to indicate no effects
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / module / ConcreteModule.java
index 55ee202f7d78d9b56f189bee8df90d96920f03b7..31ef0dc5a0cb9863874d042858aec59d451adadd 100644 (file)
@@ -9,8 +9,10 @@ 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.TypeDescriptor;
@@ -21,8 +23,12 @@ 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.module.debug.ModuleDebugInfo;
 import org.simantics.scl.compiler.top.ModuleInitializer;
 import org.simantics.scl.compiler.types.TCon;
+import org.simantics.scl.compiler.types.TVar;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.runtime.profiling.BranchPoint;
 
 import gnu.trove.map.hash.THashMap;
@@ -32,15 +38,18 @@ 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>();
     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;
@@ -50,6 +59,8 @@ public class ConcreteModule implements Module {
     ModuleInitializer moduleInitializer;
 
     protected Documentation documentation;
+    
+    public ModuleDebugInfo moduleDebugInfo;
 
     public ConcreteModule(String moduleName) {
         this.moduleName = moduleName;
@@ -72,6 +83,10 @@ public class ConcreteModule implements Module {
         return effectConstructors.put(name, effectConstructor) != null;
     }
 
+    public void addTypeAlias(String name, TVar[] parameters, Type body) {
+        typeDescriptors.put(name, new TypeAlias(Types.con(moduleName, name), parameters, body));
+    }
+    
     public boolean addTypeClass(String name, TypeClass typeClass) {
         return typeClasses.put(name, typeClass) != null;
     }
@@ -106,6 +121,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);
@@ -185,6 +205,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();
     }
@@ -235,7 +260,7 @@ public class ConcreteModule implements Module {
         this.values.forEachEntry(new TObjectObjectProcedure<String,SCLValue>() {
             @Override
             public boolean execute(String name, SCLValue value) {
-                if(value.isPrivate())
+                if(value.isPrivateOrDerived())
                     return true;
                 String lowerPrefix = prefix.toLowerCase();
                 String lowerName = name.toLowerCase();
@@ -255,6 +280,11 @@ public class ConcreteModule implements Module {
                 consumer.accept(value);
         });
     }
+    
+    @Override
+    public List<String> getValueNames() {
+        return new ArrayList<String>(values.keySet());
+    }
 
     public Collection<SCLRelation> getRelations() {
         return relations.values();
@@ -300,4 +330,31 @@ public class ConcreteModule implements Module {
             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;
+    }
+    
+    @Override
+    public ModuleDebugInfo getModuleDebugInfo() {
+        return moduleDebugInfo;
+    }
 }