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