]> gerrit.simantics Code Review - simantics/platform.git/blob
397e1ce4fcd306d8dbcbcd3adcbab049fe3eb997
[simantics/platform.git] /
1 package org.simantics.scl.compiler.compilation;
2
3 import org.simantics.scl.compiler.common.names.Name;
4 import org.simantics.scl.compiler.elaboration.contexts.EnvironmentalContext;
5 import org.simantics.scl.compiler.elaboration.expressions.EConstant;
6 import org.simantics.scl.compiler.elaboration.expressions.EError;
7 import org.simantics.scl.compiler.elaboration.expressions.Expression;
8 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
9 import org.simantics.scl.compiler.environment.Environment;
10 import org.simantics.scl.compiler.errors.ErrorLog;
11 import org.simantics.scl.compiler.errors.Locations;
12 import org.simantics.scl.compiler.internal.codegen.types.JavaTypeTranslator;
13 import org.simantics.scl.compiler.internal.codegen.utils.JavaNamingPolicy;
14 import org.simantics.scl.compiler.module.ConcreteModule;
15 import org.simantics.scl.compiler.types.Type;
16
17 import gnu.trove.map.hash.THashMap;
18
19 public class CompilationContext implements EnvironmentalContext {
20     public final ErrorLog errorLog = new ErrorLog();
21     public Environment environment;
22     public JavaTypeTranslator javaTypeTranslator;
23     public JavaNamingPolicy namingPolicy;
24     public ConcreteModule module;
25     
26     private THashMap<Name, SCLValue> valueCache = new THashMap<Name, SCLValue>();
27
28     public SCLValue getValue(Name name) {
29         if(valueCache.containsKey(name))
30             return valueCache.get(name);
31         SCLValue value = environment.getValue(name);
32         if(value == null)
33             errorLog.log(Locations.NO_LOCATION, "Couldn't find " + name + ".");
34         valueCache.put(name, value);
35         return value;
36     }
37     
38     public Expression getConstant(Name name, Type ... typeParameters) {
39         SCLValue value = getValue(name);
40         if(value == null)
41             return new EError(Locations.NO_LOCATION);
42         return new EConstant(value, typeParameters);
43     }
44 }