\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
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
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
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
? 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
: 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
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
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