]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/TypeMonitorContext.java
Merge commit 'd7afa23'
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / TypeMonitorContext.java
1 package org.simantics.modeling;\r
2 \r
3 \r
4 public class TypeMonitorContext /*extends ContextModule*/ {\r
5 /*      \r
6     public static SCLValue GET_MONITOR_METHOD;\r
7         static {\r
8                 try {\r
9             GET_MONITOR_METHOD = ActualCompileRequest.ENVIRONMENT.getValueRef(ActualCompileRequest.CONTEXT_MODULE + "/getMonitorValue");\r
10                 } catch (ValueNotFound e) {\r
11                         e.printStackTrace();\r
12                 }\r
13         }       \r
14         \r
15         final private THashMap<String, Pair<String,Type>> properties;\r
16         \r
17         public TypeMonitorContext(THashMap<String, Pair<String,Type>> properties) {\r
18                 super("MonitorContext");\r
19                 this.properties = properties;\r
20         }\r
21 \r
22         private Pair<String,Type> decodeProperty(String name) {\r
23 \r
24             Pair<String,Type> entry = properties.get(name);\r
25                 if(entry != null) return entry;\r
26                 \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
30                 }\r
31                 \r
32                 return null;\r
33                 \r
34         }\r
35         \r
36         @Override\r
37         protected Expression createValueExpression(String name) {\r
38                 \r
39             Pair<String,Type> entry = decodeProperty(name);\r
40                 if(entry == null) return null;\r
41 \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
47                                 );\r
48         }\r
49 \r
50         @Override\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
55                         value.setType(\r
56                                         Types.forAll(A, \r
57                                                         Types.constrained(Types.pred(Types.REAL, A), A)\r
58                                                         ));\r
59                         value.setMacroRule(new BasicMacroRule(1) {\r
60                                 @Override\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
66                                                         parameters[0],\r
67                                                         value.getExpression().copy()\r
68                                                         );\r
69                                         return result;\r
70                                 }\r
71                         });\r
72                         value.setInlineInSimplification(false);\r
73                 }\r
74                 return value;\r
75         }\r
76 \r
77         @Override\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
87                 return null;\r
88         }\r
89 \r
90     @Override\r
91     public Collection<ImportDeclaration> getDependencies() {\r
92         return Collections.emptyList();\r
93     }\r
94 */\r
95 }