X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fexpressions%2FERecord.java;h=e1f444d8220a12801d3ad430c55c11065a4edef8;hp=a41c0f042d46034e782ec06b78888bfe146cf7c9;hb=6d233d1b05176e40f634766537082d2a2ec65fd0;hpb=4e9b33f24c2da14a92e008362e1b039dc2303679 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERecord.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERecord.java index a41c0f042..e1f444d82 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERecord.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERecord.java @@ -2,20 +2,20 @@ package org.simantics.scl.compiler.elaboration.expressions; import org.simantics.scl.compiler.constants.SCLConstructor; import org.simantics.scl.compiler.elaboration.contexts.TranslationContext; +import org.simantics.scl.compiler.elaboration.contexts.TranslationContext.ExistentialFrame; import org.simantics.scl.compiler.elaboration.expressions.records.FieldAssignment; import org.simantics.scl.compiler.elaboration.modules.SCLValue; import org.simantics.scl.compiler.environment.AmbiguousNameException; import org.simantics.scl.compiler.errors.Locations; -import org.simantics.scl.compiler.internal.parsing.Token; import gnu.trove.map.hash.THashMap; public class ERecord extends ASTExpression { - Token constructor; - FieldAssignment[] fields; + public final EVar constructor; + public final FieldAssignment[] fields; - public ERecord(Token constructor, FieldAssignment[] fields) { + public ERecord(EVar constructor, FieldAssignment[] fields) { this.constructor = constructor; this.fields = fields; } @@ -33,30 +33,67 @@ public class ERecord extends ASTExpression { public Expression resolve(TranslationContext context, boolean asPattern) { SCLValue constructorValue; try { - constructorValue = context.getEnvironment().getLocalNamespace().getValue(constructor.text); + constructorValue = context.getEnvironment().getLocalNamespace().getValue(constructor.name); } catch (AmbiguousNameException e) { context.getErrorLog().log(constructor.location, e.getMessage()); return new EError(constructor.location); } if(constructorValue == null) { - context.getErrorLog().log(constructor.location, "Couldn't resolve the record constructor " + constructor.text + "."); + context.getErrorLog().log(constructor.location, "Couldn't resolve the record constructor " + constructor.name + "."); return new EError(constructor.location); } if(!(constructorValue.getValue() instanceof SCLConstructor)) { - context.getErrorLog().log(constructor.location, "Value " + constructor.text + " is not a record constructor."); + context.getErrorLog().log(constructor.location, "Value " + constructor.name + " is not a record constructor."); return new EError(constructor.location); } String[] fieldNames = ((SCLConstructor)constructorValue.getValue()).recordFieldNames; if(fieldNames == null) { - context.getErrorLog().log(constructor.location, "Value " + constructor.text + " is not a record constructor."); + context.getErrorLog().log(constructor.location, "Value " + constructor.name + " is not a record constructor."); return new EError(constructor.location); } + Expression[] parameters = translateFieldsToFunctionParameters(context, fields, fieldNames); + if(parameters == null) + return new EError(location); + if(asPattern) + for(int i=0;i recordMap = new THashMap(fields.length); + boolean error = false; for(FieldAssignment field : fields) { if(field.value == null) { - String actualName = field.name; - if(actualName.charAt(0) == '?') - actualName = actualName.substring(1); + String actualName = field.name; + if(actualName.charAt(0) == '?') + actualName = actualName.substring(1); String bestMatch = null; int bestMatchLength = 0; for(int i=0;i