All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.qbicc.graph.InstanceFieldOf Maven / Gradle / Ivy

There is a newer version: 0.77.0
Show newest version
package org.qbicc.graph;

import java.util.Objects;

import org.qbicc.type.PointerType;
import org.qbicc.type.definition.element.ExecutableElement;
import org.qbicc.type.definition.element.InstanceFieldElement;

/**
 * A pointer to an instance field.
 */
public final class InstanceFieldOf extends AbstractValue {
    private final Value instancePointer;
    private final InstanceFieldElement field;
    private final PointerType type;

    InstanceFieldOf(Node callSite, ExecutableElement element, int line, int bci, Value instancePointer, InstanceFieldElement field) {
        super(callSite, element, line, bci);
        this.instancePointer = instancePointer;
        instancePointer.getType(PointerType.class);
        this.field = field;
        type = field.getType().getPointer();
    }

    public Value getInstance() {
        return instancePointer;
    }

    @Override
    public int getValueDependencyCount() {
        return 1;
    }

    @Override
    public Value getValueDependency(int index) throws IndexOutOfBoundsException {
        return switch (index) {
            case 0 -> instancePointer;
            default -> throw new IndexOutOfBoundsException(index);
        };
    }

    @Override
    public PointerType getType() {
        return type;
    }

    public InstanceFieldElement getVariableElement() {
        return field;
    }

    int calcHashCode() {
        return Objects.hash(instancePointer, field);
    }

    @Override
    String getNodeName() {
        return "InstanceFieldOf";
    }

    @Override
    StringBuilder toRValueString(StringBuilder b) {
        b.append("field pointer ");
        instancePointer.toReferenceString(b);
        b.append('.');
        b.append(field.getName());
        return b;
    }

    public boolean equals(final Object other) {
        return other instanceof InstanceFieldOf ifo && equals(ifo);
    }

    public boolean equals(final InstanceFieldOf other) {
        return this == other || other != null && getVariableElement().equals(other.getVariableElement()) && instancePointer.equals(other.instancePointer);
    }

    @Override
    public  R accept(ValueVisitor visitor, T param) {
        return visitor.visit(param, this);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy