]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/expressions/ERecord.java
migrated to svn revision 33108
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / expressions / ERecord.java
index cbb69a34be75153b04d99a9d78ccb234676a9194..32999dcb48877a689c980d7e7c1bc73973b46345 100644 (file)
@@ -52,8 +52,29 @@ public class ERecord extends ASTExpression {
             return new EError(constructor.location);
         }
         THashMap<String,FieldAssignment> recordMap = new THashMap<String,FieldAssignment>(fields.length);
-        for(FieldAssignment field : fields)
-            recordMap.put(field.name, field);
+        for(FieldAssignment field : fields) {
+            if(field.value == null) {
+                String bestMatch = null;
+                int bestMatchLength = 0;
+                for(int i=0;i<fieldNames.length;++i) {
+                    String fieldName = fieldNames[i];
+                    if(field.name.startsWith(fieldName) && fieldName.length() > bestMatchLength) {
+                        bestMatch = fieldName;
+                        bestMatchLength = fieldName.length();
+                    }
+                }
+                if(bestMatch == null) {
+                    context.getErrorLog().log(field.location, "Invalid shorthand field " + field.name + " is defined twice.");
+                    return new EError(location);
+                }
+                field.value = new EVar(field.location, field.name);
+                field.name = bestMatch;
+            }
+            if(recordMap.put(field.name, field) != null) {
+                context.getErrorLog().log(field.location, "Field " + field.name + " is defined more than once.");
+                return new EError(location);
+            }
+        }
         Expression[] parameters = new Expression[fieldNames.length];
         boolean error = false;
         for(int i=0;i<fieldNames.length;++i) {
@@ -91,7 +112,8 @@ public class ERecord extends ASTExpression {
         if(location == Locations.NO_LOCATION) {
             location = loc;
             for(FieldAssignment field : fields)
-                field.value.setLocationDeep(loc);
+                if(field.value != null)
+                    field.value.setLocationDeep(loc);
         }
     }