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