]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java
(refs #7250) CHR rules modularization (first working version)
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / module / LazyModule.java
1 package org.simantics.scl.compiler.module;
2
3 import java.util.Collection;
4 import java.util.Collections;
5 import java.util.List;
6
7 import org.simantics.scl.compiler.constants.Constant;
8 import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
9 import org.simantics.scl.compiler.elaboration.modules.Documentation;
10 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
11 import org.simantics.scl.compiler.elaboration.modules.TypeClass;
12 import org.simantics.scl.compiler.elaboration.modules.TypeClassInstance;
13 import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
14 import org.simantics.scl.compiler.elaboration.relations.SCLEntityType;
15 import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
16 import org.simantics.scl.compiler.elaboration.rules.MappingRelation;
17 import org.simantics.scl.compiler.elaboration.rules.TransformationRule;
18 import org.simantics.scl.compiler.errors.CompilationError;
19 import org.simantics.scl.compiler.internal.codegen.effects.EffectConstructor;
20 import org.simantics.scl.compiler.top.ModuleInitializer;
21 import org.simantics.scl.compiler.types.TCon;
22 import org.simantics.scl.runtime.profiling.BranchPoint;
23
24 import gnu.trove.map.hash.THashMap;
25
26 public abstract class LazyModule implements Module {
27
28     String moduleName;
29     private THashMap<String, SCLValue> values = new THashMap<String, SCLValue>();
30     private THashMap<String, SCLRelation> relations = new THashMap<String, SCLRelation>();
31     private THashMap<String, SCLEntityType> entityTypes = new THashMap<String, SCLEntityType>();
32     
33     protected abstract SCLValue createValue(String name);
34     
35     protected SCLRelation createRelation(String name) {
36         return null;
37     }
38     
39     protected SCLEntityType createEntityType(String name) {
40         return null;
41     }
42     
43     @Override
44     public MappingRelation getMappingRelation(String name) {
45         return null;
46     }
47     
48     @Override
49     public TransformationRule getRule(String name) {
50         return null;
51     }
52     
53     public LazyModule(String moduleName) {
54         this.moduleName = moduleName;
55     }
56         
57     @Override
58     public String getName() {
59         return moduleName;
60     }
61     
62     public void findValuesForPrefix(final Collection<SCLValue> values, final String prefix) {           
63     }
64
65     @Override
66     public SCLValue getValue(String name) {
67         if(values.containsKey(name))
68             return values.get(name);
69         else {
70             SCLValue value = createValue(name);
71             values.put(name, value);
72             return value;
73         }
74     }
75     
76     @Override
77     public List<Constant> getFieldAccessors(String name) {
78         return null;
79     }
80     
81     public SCLRelation getRelation(String name) {
82         if(relations.containsKey(name))
83             return relations.get(name);
84         else {
85             SCLRelation relation = createRelation(name);
86             relations.put(name, relation);
87             return relation;
88         }
89     }
90     
91     public SCLEntityType getEntityType(String name) {
92         if(entityTypes.containsKey(name))
93             return entityTypes.get(name);
94         else {
95             SCLEntityType entityType = createEntityType(name);
96             entityTypes.put(name, entityType);
97             return entityType;
98         }
99     } 
100
101     @Override
102     public TypeClass getTypeClass(String name) {
103         return null;
104     }
105    
106     @Override
107     public Collection<TypeClassInstance> getInstances(TCon typeClass) {
108         return Collections.emptyList();
109     }
110
111     @Override
112     public TypeDescriptor getTypeDescriptor(String name) {
113         return null;
114     }
115
116     @Override
117     public Documentation getDocumentation() {
118         return null;
119     }
120     
121     @Override
122     public byte[] getClass(String name) {
123         return null;
124     }
125     
126     @Override
127     public ModuleInitializer getModuleInitializer() {
128         return null;
129     }
130     
131     @Override
132     public EffectConstructor getEffectConstructor(String name) {
133         return null;
134     }
135     
136     @Override
137     public Collection<TransformationRule> getRules() {
138         return Collections.emptyList();
139     }
140     
141     @Override
142     public THashMap<String, BranchPoint[]> getBranchPoints() {
143         return null;
144     }
145     
146     @Override
147     public CompilationError[] getWarnings() {
148         return CompilationError.EMPTY_ARRAY;
149     }
150     
151     @Override
152     public CHRRuleset getRuleset(String name) {
153         return null;
154     }
155 }