]> gerrit.simantics Code Review - simantics/platform.git/blob
411b93fe22eb72cb58523d62a88c4af61f6ce067
[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.internal.header.ModuleHeader;
15 import org.simantics.scl.compiler.module.ConcreteModule;
16 import org.simantics.scl.compiler.types.Type;
17
18 import gnu.trove.map.hash.THashMap;
19
20 public class CompilationContext implements EnvironmentalContext {
21     public final ErrorLog errorLog = new ErrorLog();
22     public Environment environment;
23     public JavaTypeTranslator javaTypeTranslator;
24     public JavaNamingPolicy namingPolicy;
25     public ConcreteModule module;
26     public ModuleHeader header;
27     
28     private THashMap<Name, SCLValue> valueCache = new THashMap<Name, SCLValue>();
29
30     public SCLValue getValue(Name name) {
31         if(valueCache.containsKey(name))
32             return valueCache.get(name);
33         SCLValue value = environment.getValue(name);
34         if(value == null)
35             errorLog.log(Locations.NO_LOCATION, "Couldn't find " + name + ".");
36         valueCache.put(name, value);
37         return value;
38     }
39     
40     public Expression getConstant(Name name, Type ... typeParameters) {
41         SCLValue value = getValue(name);
42         if(value == null)
43             return new EError(Locations.NO_LOCATION);
44         return new EConstant(value, typeParameters);
45     }
46 }