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