1 package org.simantics.modeling;
4 public class TypeMonitorContext /*extends ContextModule*/ {
6 public static SCLValue GET_MONITOR_METHOD;
9 GET_MONITOR_METHOD = ActualCompileRequest.ENVIRONMENT.getValueRef(ActualCompileRequest.CONTEXT_MODULE + "/getMonitorValue");
10 } catch (ValueNotFound e) {
15 final private THashMap<String, Pair<String,Type>> properties;
17 public TypeMonitorContext(THashMap<String, Pair<String,Type>> properties) {
18 super("MonitorContext");
19 this.properties = properties;
22 private Pair<String,Type> decodeProperty(String name) {
24 Pair<String,Type> entry = properties.get(name);
25 if(entry != null) return entry;
27 String[] parts = name.split("\\.");
28 if(parts.length == 2) {
29 return Pair.make("/" + parts[0] + "#" + parts[1], (Type)Types.DOUBLE);
37 protected Expression createValueExpression(String name) {
39 Pair<String,Type> entry = decodeProperty(name);
40 if(entry == null) return null;
42 return new EApply(Locations.NO_LOCATION,
43 new EConstant(GET_MONITOR_METHOD, entry.second),
44 new EGetContext(1, ActualCompileRequest.STRUCTURAL_COMPONENT),
45 new EGetContext(0, ActualCompileRequest.READ_GRAPH_INTERNAL),
46 new EExternalConstant(entry.first, Types.STRING)
51 protected SCLValue createValue(String name) {
52 final SCLValue value = super.createValue(name);
53 if(value != null && value.getType().equals(Types.DOUBLE)) {
54 TVar A = Types.var(Kinds.STAR);
57 Types.constrained(Types.pred(Types.REAL, A), A)
59 value.setMacroRule(new BasicMacroRule(1) {
61 public Expression apply(SimplificationContext context,
62 Type[] typeParameters, Expression[] parameters) {
63 Expression result = new EApply(
64 Locations.NO_LOCATION,
65 new EConstant(ActualCompileRequest.FROM_DOUBLE, typeParameters[0]),
67 value.getExpression().copy()
72 value.setInlineInSimplification(false);
78 public TypeConstructor getTypeConstructor(TCon type) {
79 if(type.name.equals("ReadGraph"))
80 return ActualCompileRequest.READ_GRAPH_TYPE_CONSTRUCTOR;
81 if(type.name.equals("Resource"))
82 return ActualCompileRequest.RESOURCE_TYPE_CONSTRUCTOR;
83 if(type.name.equals("Variable"))
84 return ActualCompileRequest.VARIABLE_TYPE_CONSTRUCTOR;
85 if(type.name.equals("Binding"))
86 return ActualCompileRequest.BINDING_TYPE_CONSTRUCTOR;
91 public Collection<ImportDeclaration> getDependencies() {
92 return Collections.emptyList();