1 package org.simantics.scl.compiler.source.repository;
3 import java.util.Collection;
4 import java.util.Collections;
7 import org.simantics.scl.compiler.common.names.Name;
8 import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant;
9 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
10 import org.simantics.scl.compiler.errors.Failable;
11 import org.simantics.scl.compiler.module.ConcreteModule;
12 import org.simantics.scl.compiler.module.repository.ModuleRepository;
13 import org.simantics.scl.compiler.module.repository.UpdateListener;
14 import org.simantics.scl.compiler.runtime.RuntimeModule;
15 import org.simantics.scl.compiler.source.ModuleSource;
16 import org.simantics.scl.compiler.source.PrecompiledModuleSource;
17 import org.simantics.scl.compiler.source.repository.procedural.ProceduralValueDefinition;
18 import org.simantics.scl.compiler.top.ValueNotFound;
20 public abstract class ProceduralModuleSourceRepository implements ModuleSourceRepository {
22 public static final String PREFIX = "procedural:";
24 protected abstract ModuleRepository getModuleRepository(UpdateListener listener);
27 public Collection<String> getModuleNames() {
28 return Collections.emptyList();
32 public ModuleSource getModuleSource(String moduleName, UpdateListener listener) {
33 if(!moduleName.startsWith(PREFIX))
36 String sourceModuleName = moduleName.substring(PREFIX.length());
37 Failable<RuntimeModule> sourceModuleF = getModuleRepository(listener)
38 .getRuntimeModule(sourceModuleName, listener);
39 if(!sourceModuleF.didSucceed())
42 RuntimeModule sourceModule = sourceModuleF.getResult();
45 values = sourceModule.getValue("values");
46 } catch (ValueNotFound e) {
50 if(!(values instanceof List))
53 ConcreteModule module = new ConcreteModule(moduleName);
54 for(Object item : (List)values) {
55 if(!(item instanceof ProceduralValueDefinition))
57 ProceduralValueDefinition def = (ProceduralValueDefinition)item;
59 SCLValue value = new SCLValue(Name.create(moduleName, def.name));
60 value.setType(def.type);
61 value.setExpression(new EExternalConstant(def.value, def.type));
62 value.setInlineInSimplification(true);
63 module.addValue(value);
65 module.setParentClassLoader(getClass().getClassLoader());
66 return new PrecompiledModuleSource(module);