package org.simantics.modeling; public class TypeMonitorContext /*extends ContextModule*/ { /* public static SCLValue GET_MONITOR_METHOD; static { try { GET_MONITOR_METHOD = ActualCompileRequest.ENVIRONMENT.getValueRef(ActualCompileRequest.CONTEXT_MODULE + "/getMonitorValue"); } catch (ValueNotFound e) { e.printStackTrace(); } } final private THashMap> properties; public TypeMonitorContext(THashMap> properties) { super("MonitorContext"); this.properties = properties; } private Pair decodeProperty(String name) { Pair entry = properties.get(name); if(entry != null) return entry; String[] parts = name.split("\\."); if(parts.length == 2) { return Pair.make("/" + parts[0] + "#" + parts[1], (Type)Types.DOUBLE); } return null; } @Override protected Expression createValueExpression(String name) { Pair entry = decodeProperty(name); if(entry == null) return null; return new EApply(Locations.NO_LOCATION, new EConstant(GET_MONITOR_METHOD, entry.second), new EGetContext(1, ActualCompileRequest.STRUCTURAL_COMPONENT), new EGetContext(0, ActualCompileRequest.READ_GRAPH_INTERNAL), new EExternalConstant(entry.first, Types.STRING) ); } @Override protected SCLValue createValue(String name) { final SCLValue value = super.createValue(name); if(value != null && value.getType().equals(Types.DOUBLE)) { TVar A = Types.var(Kinds.STAR); value.setType( Types.forAll(A, Types.constrained(Types.pred(Types.REAL, A), A) )); value.setMacroRule(new BasicMacroRule(1) { @Override public Expression apply(SimplificationContext context, Type[] typeParameters, Expression[] parameters) { Expression result = new EApply( Locations.NO_LOCATION, new EConstant(ActualCompileRequest.FROM_DOUBLE, typeParameters[0]), parameters[0], value.getExpression().copy() ); return result; } }); value.setInlineInSimplification(false); } return value; } @Override public TypeConstructor getTypeConstructor(TCon type) { if(type.name.equals("ReadGraph")) return ActualCompileRequest.READ_GRAPH_TYPE_CONSTRUCTOR; if(type.name.equals("Resource")) return ActualCompileRequest.RESOURCE_TYPE_CONSTRUCTOR; if(type.name.equals("Variable")) return ActualCompileRequest.VARIABLE_TYPE_CONSTRUCTOR; if(type.name.equals("Binding")) return ActualCompileRequest.BINDING_TYPE_CONSTRUCTOR; return null; } @Override public Collection getDependencies() { return Collections.emptyList(); } */ }