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.TPred;
import org.simantics.scl.compiler.types.TVar;
import org.simantics.scl.compiler.types.Type;
import org.simantics.scl.compiler.types.Types;
Type[] parameterTypes;
private static final Type RESOURCE = Types.con("Simantics/DB", "Resource");
-
+
public GraphPropertyRelation(Resource propertyRelation, Type valueType) {
this.propertyRelation = propertyRelation;
this.valueType = valueType;
public TVar[] getTypeVariables() {
return TVar.EMPTY_ARRAY;
}
-
+
+ @Override
+ public TPred[] getTypeConstraints() {
+ return new TPred[] {Types.pred(Types.SERIALIZABLE, valueType)};
+ }
+
@Override
public Type[] getParameterTypes() {
return parameterTypes;
default: throw new IllegalArgumentException();
}
}
-
+
@Override
public int getRequiredVariablesMask() {
return BF;
}
-
+
private static final Name POSSIBLE_RELATED_VALUE = Name.create("Simantics/DB", "possibleRelatedValue");
-
+
@Override
public void generate(long location, QueryCompilationContext context,
Type[] typeParameters, Variable[] parameters, int boundVariables) {
context.condition(new EApply(
context.getCompilationContext().getConstant(Names.Builtin_equals, valueType),
new Expression[] {
- new EVariable(temp),
- new EVariable(parameters[1])
+ new EVariable(temp),
+ new EVariable(parameters[1])
}
));
context.iterateMaybe(temp, possibleValue);
}
private static final Name CLAIM_RELATED_VALUE = Name.create("Simantics/DB", "claimRelatedValue");
-
+
@Override
public Expression generateEnforce(long location, EnforcingContext context,
Type[] typeParameters, Variable[] parameters) {
public int getPhase() {
return 0;
}
-
+
@Override
- public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters) {
- throw new UnsupportedOperationException(getClass().getSimpleName() + " does not support enforce.");
+ public void generateIterate(PlanContext context, CodeWriter w, long location, int boundMask, Variable[] variables,
+ Expression[] expressions, Expression[] typeConstraintEvidenceParameters) {
+ Environment env = context.context.environment;
+ switch(boundMask) {
+ case BF:
+ context.iterateMaybe(location, w, variables[1],
+ w.apply(location,
+ env.getValue(POSSIBLE_RELATED_VALUE).getValue().createSpecialization(valueType),
+ typeConstraintEvidenceParameters[0].toVal(env, w),
+ expressions[0].toVal(env, w),
+ w.getModuleWriter().getExternalConstant(propertyRelation, Types.RESOURCE)));
+ break;
+ case BB:
+ context.checkEqualsJust(location, w, expressions[1].toVal(env, w),
+ w.apply(location,
+ env.getValue(POSSIBLE_RELATED_VALUE).getValue().createSpecialization(valueType),
+ typeConstraintEvidenceParameters[0].toVal(env, w),
+ expressions[0].toVal(env, w),
+ w.getModuleWriter().getExternalConstant(propertyRelation, Types.RESOURCE)));
+ break;
+ default: throw new IllegalArgumentException();
+ }
}
-
+
@Override
- public void generateIterate(PlanContext context, CodeWriter w, long location, int boundMask, Variable[] variables,
- Expression[] expressions) {
- throw new UnsupportedOperationException(getClass().getSimpleName() + " does not support iterate.");
+ public void generateEnforce(PlanContext context, CodeWriter w, long location, Expression[] parameters, Expression[] typeConstraintEvidenceParameters) {
+ Environment env = context.context.environment;
+ w.apply(location,
+ env.getValue(CLAIM_RELATED_VALUE).getValue().createSpecialization(valueType),
+ typeConstraintEvidenceParameters[0].toVal(env, w),
+ parameters[0].toVal(env, w),
+ w.getModuleWriter().getExternalConstant(propertyRelation, Types.RESOURCE),
+ parameters[1].toVal(env, w));
}
}