X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fscl%2FGraphRelation.java;h=72bfa128e9f58e5394414aa5876569c7d87598a9;hp=807d44a16612c48ff3d670b672b3ad0d6e00b0b9;hb=a8758de5bc19e5adb3f618d3038743a164f09912;hpb=12d9af17384d960b75d58c3935d2b7b46d93e87b diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java index 807d44a16..72bfa128e 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java @@ -2,6 +2,7 @@ package org.simantics.modeling.scl; import org.simantics.db.Resource; import org.simantics.scl.compiler.common.names.Name; +import org.simantics.scl.compiler.elaboration.chr.plan.PlanContext; import org.simantics.scl.compiler.elaboration.expressions.EApply; import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant; import org.simantics.scl.compiler.elaboration.expressions.EVariable; @@ -10,7 +11,9 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable; import org.simantics.scl.compiler.elaboration.query.compilation.EnforcingContext; import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilationContext; import org.simantics.scl.compiler.elaboration.relations.SCLRelation; +import org.simantics.scl.compiler.environment.Environment; import org.simantics.scl.compiler.errors.Locations; +import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter; import org.simantics.scl.compiler.types.TVar; import org.simantics.scl.compiler.types.Type; import org.simantics.scl.compiler.types.Types; @@ -69,7 +72,7 @@ public class GraphRelation implements SCLRelation { context.iterateList(parameters[1], new EApply( Locations.NO_LOCATION, Types.READ_GRAPH, - context.getTypingContext().getConstant(GET_OBJECTS), + context.getCompilationContext().getConstant(GET_OBJECTS), new EVariable(parameters[0]), new EExternalConstant(relation, Types.RESOURCE) )); @@ -80,7 +83,7 @@ public class GraphRelation implements SCLRelation { context.iterateList(parameters[0], new EApply( Locations.NO_LOCATION, Types.READ_GRAPH, - context.getTypingContext().getConstant(GET_OBJECTS), + context.getCompilationContext().getConstant(GET_OBJECTS), new EVariable(parameters[1]), new EExternalConstant(inverseRelation, Types.RESOURCE) )); @@ -91,7 +94,7 @@ public class GraphRelation implements SCLRelation { ? new EApply( Locations.NO_LOCATION, Types.READ_GRAPH, - context.getTypingContext().getConstant(HAS_STATEMENT), + context.getCompilationContext().getConstant(HAS_STATEMENT), new Expression[] { new EVariable(parameters[0]), new EExternalConstant(relation, Types.RESOURCE), @@ -101,7 +104,7 @@ public class GraphRelation implements SCLRelation { : new EApply( Locations.NO_LOCATION, Types.READ_GRAPH, - context.getTypingContext().getConstant(HAS_STATEMENT), + context.getCompilationContext().getConstant(HAS_STATEMENT), new Expression[] { new EVariable(parameters[1]), new EExternalConstant(inverseRelation, Types.RESOURCE), @@ -121,7 +124,7 @@ public class GraphRelation implements SCLRelation { return new EApply( Locations.NO_LOCATION, Types.WRITE_GRAPH, - context.getTypingContext().getConstant(CLAIM), + context.getCompilationContext().getConstant(CLAIM), new EVariable(parameters[0]), new EExternalConstant(relation, Types.RESOURCE), new EVariable(parameters[1]) @@ -133,4 +136,50 @@ public class GraphRelation implements SCLRelation { return 0; } + @Override + public void generateIterate(PlanContext context, CodeWriter w, long location, int boundMask, Variable[] variables, + Expression[] expressions) { + Environment env = context.context.environment; + switch(boundMask) { + case BF: + context.iterateList(location, w, variables[1], + w.apply(location, + env.getValue(GET_OBJECTS).getValue(), + expressions[0].toVal(env, w), + w.getModuleWriter().getExternalConstant(relation, Types.RESOURCE))); + break; + case FB: + if(inverseRelation == null) + throw new IllegalArgumentException(); + context.iterateList(location, w, variables[0], + w.apply(location, + env.getValue(GET_OBJECTS).getValue(), + expressions[1].toVal(env, w), + w.getModuleWriter().getExternalConstant(inverseRelation, Types.RESOURCE))); + break; + case BB: + context.check(location, w, + inverseRelation == null || relationSelectivity <= inverseRelationSelectivity + ? w.apply(location, env.getValue(HAS_STATEMENT).getValue(), + expressions[0].toVal(env, w), + w.getModuleWriter().getExternalConstant(relation, Types.RESOURCE), + expressions[1].toVal(env, w)) + : w.apply(location, env.getValue(HAS_STATEMENT).getValue(), + expressions[1].toVal(env, w), + w.getModuleWriter().getExternalConstant(inverseRelation, Types.RESOURCE), + expressions[0].toVal(env, w))); + break; + default: throw new IllegalArgumentException(); + } + } + + @Override + public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters) { + Environment env = context.context.environment; + w.apply(location, + env.getValue(CLAIM).getValue(), + parameters[0].toVal(env, w), + w.getModuleWriter().getExternalConstant(relation, Types.RESOURCE), + parameters[1].toVal(env, w)); + } }