diff options
Diffstat (limited to 'src')
3 files changed, 10 insertions, 66 deletions
diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/ConcreteType.java b/src/main/java/org/zwobble/couscous/interpreter/values/ConcreteType.java index 63c1bbe..cf48d3c 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/ConcreteType.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/ConcreteType.java @@ -28,7 +28,7 @@ public class ConcreteType { } public static class Builder<T> { - private final ImmutableMap.Builder<String, FieldValue> fields = ImmutableMap.builder(); + private final ImmutableMap.Builder<String, FieldDeclarationNode> fields = ImmutableMap.builder(); private MethodValue constructor = new MethodValue(list(), (environment, arguments) -> InterpreterValues.UNIT); private final ImmutableMap.Builder<MethodSignature, MethodValue> methods = ImmutableMap.builder(); private final ImmutableMap.Builder<MethodSignature, StaticMethodValue> staticMethods = ImmutableMap.builder(); @@ -41,7 +41,7 @@ public class ConcreteType { } public Builder<T> field(String name, TypeName type) { - fields.put(name, new FieldValue(false, name, type)); + fields.put(name, FieldDeclarationNode.field(name, type)); return this; } @@ -92,10 +92,10 @@ public class ConcreteType { } public static ConcreteType fromNode(ClassNode classNode) { - Map<String, FieldValue> fields = classNode.getFields().stream() + Map<String, FieldDeclarationNode> fields = classNode.getFields().stream() .collect(toMap( field -> field.getName(), - field -> new FieldValue(field.isStatic(), field.getName(), field.getType()))); + field -> field)); MethodValue constructor = new MethodValue(getArgumentTypes(classNode.getConstructor().getArguments()), (environment, arguments) -> Executor.callMethod(environment, classNode.getConstructor(), Optional.of(arguments.getReceiver()), arguments.getPositionalArguments())); Map<MethodSignature, MethodValue> methods = classNode.getMethods() .stream() @@ -130,7 +130,7 @@ public class ConcreteType { } private final TypeName name; private final Set<TypeName> superTypes; - private final Map<String, FieldValue> fields; + private final Map<String, FieldDeclarationNode> fields; private final List<StatementNode> staticConstructor; private final MethodValue constructor; private final Map<MethodSignature, MethodValue> methods; @@ -139,7 +139,7 @@ public class ConcreteType { private ConcreteType( TypeName name, Set<TypeName> superTypes, - Map<String, FieldValue> fields, + Map<String, FieldDeclarationNode> fields, List<StatementNode> staticConstructor, MethodValue constructor, Map<MethodSignature, MethodValue> methods, Map<MethodSignature, StaticMethodValue> staticMethods) @@ -161,7 +161,7 @@ public class ConcreteType { return superTypes; } - public Optional<FieldValue> getField(boolean isStatic, String fieldName) { + public Optional<FieldDeclarationNode> getField(boolean isStatic, String fieldName) { return Optional.ofNullable(fields.get(fieldName)) .filter(field -> field.isStatic() == isStatic); } diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/FieldValue.java b/src/main/java/org/zwobble/couscous/interpreter/values/FieldValue.java deleted file mode 100644 index 90a6099..0000000 --- a/src/main/java/org/zwobble/couscous/interpreter/values/FieldValue.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.zwobble.couscous.interpreter.values; - -import org.zwobble.couscous.ast.TypeName; - -public final class FieldValue { - private final boolean isStatic; - private final String name; - private final TypeName type; - - public FieldValue(final boolean isStatic, final String name, final TypeName type) { - this.isStatic = isStatic; - this.name = name; - this.type = type; - } - - public boolean isStatic() { - return isStatic; - } - - public String getName() { - return this.name; - } - - public TypeName getType() { - return this.type; - } - - @Override - public String toString() { - return "FieldValue(" + - "isStatic=" + isStatic + - ", name='" + name + '\'' + - ", type=" + type + - ')'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - FieldValue that = (FieldValue) o; - - if (isStatic != that.isStatic) return false; - if (!name.equals(that.name)) return false; - return type.equals(that.type); - - } - - @Override - public int hashCode() { - int result = (isStatic ? 1 : 0); - result = 31 * result + name.hashCode(); - result = 31 * result + type.hashCode(); - return result; - } -}
\ No newline at end of file diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java b/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java index df33d60..1661ee7 100644 --- a/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java +++ b/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java @@ -1,5 +1,6 @@ package org.zwobble.couscous.interpreter.values; +import org.zwobble.couscous.ast.FieldDeclarationNode; import org.zwobble.couscous.interpreter.InterpreterTypes; import org.zwobble.couscous.interpreter.errors.NoSuchField; import org.zwobble.couscous.interpreter.errors.UnboundField; @@ -36,12 +37,12 @@ public class InterpreterFields { } public void setField(String fieldName, InterpreterValue value) { - FieldValue field = getFieldDefinition(fieldName); + FieldDeclarationNode field = getFieldDefinition(fieldName); InterpreterTypes.checkIsInstance(field.getType(), value); fields.put(fieldName, value); } - private FieldValue getFieldDefinition(String fieldName) { + private FieldDeclarationNode getFieldDefinition(String fieldName) { return type.getField(isStatic, fieldName) .orElseThrow(() -> new NoSuchField(fieldName)); } |
