import org.simantics.scl.compiler.elaboration.chr.relations.UnresolvedCHRRelation;
import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
+import org.simantics.scl.compiler.elaboration.contexts.TranslationContext.ExistentialFrame;
import org.simantics.scl.compiler.elaboration.contexts.TypingContext;
+import org.simantics.scl.compiler.elaboration.expressions.ERecord;
import org.simantics.scl.compiler.elaboration.expressions.Expression;
import org.simantics.scl.compiler.elaboration.expressions.Variable;
import org.simantics.scl.compiler.elaboration.expressions.VariableProcedure;
import org.simantics.scl.compiler.elaboration.expressions.printing.ExpressionToStringVisitor;
+import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment;
import org.simantics.scl.compiler.elaboration.relations.SCLRelation;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.internal.parsing.Symbol;
public CHRRelation relation;
public Type[] typeParameters;
public Expression[] parameters;
+ public FieldAssignment[] fields; // optional
public Expression[] typeConstraintEvidenceParameters;
public boolean killAfterMatch;
public boolean negated;
if(sclRelation != null)
relation = new ExternalCHRRelation(sclRelation);
else {
+ if(parameters == null) {
+ context.getErrorLog().log(location, "Relation must be declared if record syntax is used.");
+ return;
+ }
Type[] parameterTypes = new Type[parameters.length];
for(int i=0;i<parameterTypes.length;++i)
parameterTypes[i] = Types.metaVar(Kinds.STAR);
}
}
}
- for(int i=0;i<parameters.length;++i)
- parameters[i] = parameters[i].resolve(context);
+ if(parameters == null && fields != null) {
+ String[] fieldNames = relation.getFieldNames();
+ if(fieldNames == null) {
+ context.getErrorLog().log(location, "Relation " + relation + " does not define field names.");
+ return;
+ }
+ parameters = ERecord.translateFieldsToFunctionParameters(context, fields, fieldNames);
+ if(parameters == null)
+ return;
+ for(int i=0;i<parameters.length;++i) {
+ Expression parameter = parameters[i];
+ if(parameter == null) {
+ ExistentialFrame frame = context.getCurrentExistentialFrame();
+ if(frame == null || frame.disallowNewExistentials)
+ context.getErrorLog().log(location, "Field " + fieldNames[i] + " not defined.");
+ else
+ parameters[i] = frame.createBlank(location);
+ }
+ else
+ parameters[i] = parameters[i].resolve(context);
+ }
+ fields = null;
+ }
+ else {
+ for(int i=0;i<parameters.length;++i)
+ parameters[i] = parameters[i].resolve(context);
+ }
}
public void collectRefs(TObjectIntHashMap<Object> allRefs, TIntHashSet refs) {