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 actualName = field.name;
+ if(actualName.charAt(0) == '?')
+ actualName = actualName.substring(1);
+ String bestMatch = null;
+ int bestMatchLength = 0;
+ for(int i=0;i<fieldNames.length;++i) {
+ String fieldName = fieldNames[i];
+ if(actualName.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) {
if(location == Locations.NO_LOCATION) {
location = loc;
for(FieldAssignment field : fields)
- field.value.setLocationDeep(loc);
+ if(field.value != null)
+ field.value.setLocationDeep(loc);
}
}
public Expression accept(ExpressionTransformer transformer) {
return transformer.transform(this);
}
-
+
+ @Override
+ public void accept(ExpressionVisitor visitor) {
+ visitor.visit(this);
+ }
}