1 package org.simantics.scl.compiler.compilation;
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.module.debug.ModuleDebugInfo;
17 import org.simantics.scl.compiler.module.repository.ModuleRepository;
18 import org.simantics.scl.compiler.types.Type;
20 import gnu.trove.map.hash.THashMap;
22 public class CompilationContext implements EnvironmentalContext {
23 public final ErrorLog errorLog = new ErrorLog();
24 public ModuleRepository moduleRepository;
25 public Environment environment;
26 public JavaTypeTranslator javaTypeTranslator;
27 public JavaNamingPolicy namingPolicy;
28 public ConcreteModule module;
29 public ModuleHeader header;
30 public ModuleDebugInfo moduleDebugInfo;
32 private THashMap<Name, SCLValue> valueCache = new THashMap<Name, SCLValue>();
34 public SCLValue getValue(Name name) {
35 if(valueCache.containsKey(name))
36 return valueCache.get(name);
37 SCLValue value = environment.getValue(name);
39 errorLog.log(Locations.NO_LOCATION, "Couldn't find " + name + ".");
40 valueCache.put(name, value);
44 public Expression getConstant(Name name, Type ... typeParameters) {
45 SCLValue value = getValue(name);
47 return new EError(Locations.NO_LOCATION);
48 return new EConstant(value, typeParameters);