+ Expression[] parameters = translateFieldsToFunctionParameters(context, fields, fieldNames, false);
+ if(parameters == null)
+ return new EError(location);
+ if(asPattern)
+ for(int i=0;i<parameters.length;++i) {
+ Expression parameter = parameters[i];
+ if(parameter == null)
+ parameters[i] = Expressions.blank(null);
+ else
+ parameters[i] = parameter.resolveAsPattern(context);
+ }
+ else {
+ boolean error = false;
+ 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.");
+ error = true;
+ }
+ else
+ parameters[i] = frame.createBlank(location);
+ }
+ else
+ parameters[i] = parameter.resolve(context);
+ }
+ if(error)
+ return new EError(location);
+ }
+ EApply result = new EApply(new EConstant(constructorValue), parameters);
+ result.setLocationDeep(location);
+ return result;
+ }
+
+ public static Expression[] translateFieldsToFunctionParameters(TranslationContext context, FieldAssignment[] fields, String[] fieldNames, boolean chrLiteral) {
+ if(DEBUG) {
+ System.out.println("translateFieldsToFunctionParameters");
+ System.out.println(" fieldNames = " + Arrays.toString(fieldNames));
+ System.out.print(" fields = {");
+ for(int i=0;i<fields.length;++i) {
+ FieldAssignment field = fields[i];
+ if(i > 0)
+ System.out.print(", ");
+ System.out.print(field.name);
+ if(field.value != null) {
+ System.out.print(" = ");
+ System.out.print(field.value);
+ }
+ }
+ System.out.println("}");
+ }
+