X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FTypeMonitorContext.java;h=2a9df74228b505a281a16af54d49b010860ad6c2;hb=76061fee3ffb1b66ed4d78ce711ab44f38b7ffdf;hp=8536f753ed8e86d0ec289875971f64f61d67b53c;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/TypeMonitorContext.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/TypeMonitorContext.java index 8536f753e..2a9df7422 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/TypeMonitorContext.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/TypeMonitorContext.java @@ -1,95 +1,95 @@ -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(); - } -*/ +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(); + } +*/ } \ No newline at end of file