]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/scl/GraphRelation.java
Merged changes from feature/scl to master.
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / scl / GraphRelation.java
index 807d44a16612c48ff3d670b672b3ad0d6e00b0b9..72bfa128e9f58e5394414aa5876569c7d87598a9 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.modeling.scl;
 \r
 import org.simantics.db.Resource;\r
 import org.simantics.scl.compiler.common.names.Name;\r
+import org.simantics.scl.compiler.elaboration.chr.plan.PlanContext;\r
 import org.simantics.scl.compiler.elaboration.expressions.EApply;\r
 import org.simantics.scl.compiler.elaboration.expressions.EExternalConstant;\r
 import org.simantics.scl.compiler.elaboration.expressions.EVariable;\r
@@ -10,7 +11,9 @@ import org.simantics.scl.compiler.elaboration.expressions.Variable;
 import org.simantics.scl.compiler.elaboration.query.compilation.EnforcingContext;\r
 import org.simantics.scl.compiler.elaboration.query.compilation.QueryCompilationContext;\r
 import org.simantics.scl.compiler.elaboration.relations.SCLRelation;\r
+import org.simantics.scl.compiler.environment.Environment;\r
 import org.simantics.scl.compiler.errors.Locations;\r
+import org.simantics.scl.compiler.internal.codegen.writer.CodeWriter;\r
 import org.simantics.scl.compiler.types.TVar;\r
 import org.simantics.scl.compiler.types.Type;\r
 import org.simantics.scl.compiler.types.Types;\r
@@ -69,7 +72,7 @@ public class GraphRelation implements SCLRelation {
             context.iterateList(parameters[1], new EApply(\r
                     Locations.NO_LOCATION,\r
                     Types.READ_GRAPH,\r
-                    context.getTypingContext().getConstant(GET_OBJECTS),\r
+                    context.getCompilationContext().getConstant(GET_OBJECTS),\r
                     new EVariable(parameters[0]),\r
                     new EExternalConstant(relation, Types.RESOURCE)\r
                     ));\r
@@ -80,7 +83,7 @@ public class GraphRelation implements SCLRelation {
             context.iterateList(parameters[0], new EApply(\r
                     Locations.NO_LOCATION,\r
                     Types.READ_GRAPH,\r
-                    context.getTypingContext().getConstant(GET_OBJECTS),\r
+                    context.getCompilationContext().getConstant(GET_OBJECTS),\r
                     new EVariable(parameters[1]),\r
                     new EExternalConstant(inverseRelation, Types.RESOURCE)\r
                     ));\r
@@ -91,7 +94,7 @@ public class GraphRelation implements SCLRelation {
                     ? new EApply(\r
                             Locations.NO_LOCATION,\r
                             Types.READ_GRAPH,\r
-                            context.getTypingContext().getConstant(HAS_STATEMENT),\r
+                            context.getCompilationContext().getConstant(HAS_STATEMENT),\r
                             new Expression[] {\r
                                 new EVariable(parameters[0]),\r
                                 new EExternalConstant(relation, Types.RESOURCE),\r
@@ -101,7 +104,7 @@ public class GraphRelation implements SCLRelation {
                     : new EApply(\r
                             Locations.NO_LOCATION,\r
                             Types.READ_GRAPH,\r
-                            context.getTypingContext().getConstant(HAS_STATEMENT),\r
+                            context.getCompilationContext().getConstant(HAS_STATEMENT),\r
                             new Expression[] {\r
                                 new EVariable(parameters[1]),\r
                                 new EExternalConstant(inverseRelation, Types.RESOURCE),\r
@@ -121,7 +124,7 @@ public class GraphRelation implements SCLRelation {
         return new EApply(\r
                 Locations.NO_LOCATION,\r
                 Types.WRITE_GRAPH,\r
-                context.getTypingContext().getConstant(CLAIM),\r
+                context.getCompilationContext().getConstant(CLAIM),\r
                 new EVariable(parameters[0]),\r
                 new EExternalConstant(relation, Types.RESOURCE),\r
                 new EVariable(parameters[1])\r
@@ -133,4 +136,50 @@ public class GraphRelation implements SCLRelation {
         return 0;\r
     }\r
 \r
+    @Override\r
+    public void generateIterate(PlanContext context, CodeWriter w, long location, int boundMask, Variable[] variables,\r
+            Expression[] expressions) {\r
+        Environment env = context.context.environment;\r
+        switch(boundMask) {\r
+        case BF:\r
+            context.iterateList(location, w, variables[1],\r
+                    w.apply(location,\r
+                            env.getValue(GET_OBJECTS).getValue(),\r
+                            expressions[0].toVal(env, w),\r
+                            w.getModuleWriter().getExternalConstant(relation, Types.RESOURCE)));\r
+            break;\r
+        case FB:\r
+            if(inverseRelation == null)\r
+                throw new IllegalArgumentException();\r
+            context.iterateList(location, w, variables[0],\r
+                    w.apply(location,\r
+                            env.getValue(GET_OBJECTS).getValue(),\r
+                            expressions[1].toVal(env, w),\r
+                            w.getModuleWriter().getExternalConstant(inverseRelation, Types.RESOURCE)));\r
+            break;\r
+        case BB:\r
+            context.check(location, w, \r
+                    inverseRelation == null || relationSelectivity <= inverseRelationSelectivity\r
+                    ? w.apply(location, env.getValue(HAS_STATEMENT).getValue(), \r
+                            expressions[0].toVal(env, w),\r
+                            w.getModuleWriter().getExternalConstant(relation, Types.RESOURCE),\r
+                            expressions[1].toVal(env, w))\r
+                    : w.apply(location, env.getValue(HAS_STATEMENT).getValue(), \r
+                            expressions[1].toVal(env, w),\r
+                            w.getModuleWriter().getExternalConstant(inverseRelation, Types.RESOURCE),\r
+                            expressions[0].toVal(env, w)));\r
+            break;\r
+        default: throw new IllegalArgumentException();\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters) {\r
+        Environment env = context.context.environment;\r
+        w.apply(location,\r
+                env.getValue(CLAIM).getValue(),\r
+                parameters[0].toVal(env, w),\r
+                w.getModuleWriter().getExternalConstant(relation, Types.RESOURCE),\r
+                parameters[1].toVal(env, w));\r
+    }\r
 }\r