Commit 850df18d authored by Skylot's avatar Skylot

refactor: update duplicate methods in InsnArg classes

parent 7f4da306
......@@ -59,6 +59,11 @@ public final class FieldArg extends RegisterArg {
}
@Override
public RegisterArg duplicate() {
return copyCommonParams(new FieldArg(field, instArg));
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
......
......@@ -159,7 +159,7 @@ public abstract class InsnArg extends Typed {
return contains(AFlag.THIS);
}
protected InsnArg copyCommonParams(InsnArg copy) {
protected final <T extends InsnArg> T copyCommonParams(T copy) {
copy.copyAttributesFrom(this);
copy.setParentInsn(parentInsn);
return copy;
......
......@@ -49,6 +49,13 @@ public final class LiteralArg extends InsnArg {
}
@Override
public InsnArg duplicate() {
LiteralArg copy = new LiteralArg(literal, getType());
copy.type = type;
return copyCommonParams(copy);
}
@Override
public int hashCode() {
return (int) (literal ^ literal >>> 32) + 31 * getType().hashCode();
}
......
......@@ -27,6 +27,16 @@ public final class NamedArg extends InsnArg implements Named {
}
@Override
public InsnArg duplicate() {
return copyCommonParams(new NamedArg(name, type));
}
@Override
public int hashCode() {
return name.hashCode();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
......@@ -38,11 +48,6 @@ public final class NamedArg extends InsnArg implements Named {
}
@Override
public int hashCode() {
return name.hashCode();
}
@Override
public String toString() {
return '(' + name + ' ' + type + ')';
}
......
......@@ -115,8 +115,7 @@ public class RegisterArg extends InsnArg implements Named {
if (sVar != null) {
dup.setSVar(sVar);
}
dup.copyAttributesFrom(this);
return dup;
return copyCommonParams(dup);
}
@Nullable
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment