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

org.qbicc.pointer.RootPointer Maven / Gradle / Ivy

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

import org.qbicc.interpreter.Memory;
import org.qbicc.type.PointerType;

/**
 * A base (terminal) pointer which does not modify another pointer value.
 */
public abstract class RootPointer extends Pointer {
    RootPointer(PointerType type) {
        super(type);
    }

    @Override
    public RootPointer getRootPointer() {
        return this;
    }

    @Override
    public long getRootByteOffset() {
        return 0;
    }

    @Override
    public Memory getRootMemoryIfExists() {
        return null;
    }

    @Override
    public String getRootSymbolIfExists() {
        return null;
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }

    @Override
    public final boolean equals(Pointer other) {
        return other instanceof RootPointer rp && equals(rp);
    }

    public boolean equals(RootPointer other) {
        return other != null;
    }

    @Override
    public final  R accept(Pointer.Visitor visitor, T t) {
        return accept((Visitor) visitor, t);
    }

    public abstract  R accept(Visitor visitor, T t);

    public interface Visitor {
        default R visitAny(T t, RootPointer rootPointer) {
            return null;
        }

        default R visit(T t, ConstructorPointer pointer) {
            return visitAny(t, pointer);
        }

        default R visit(T t, FunctionPointer pointer) {
            return visitAny(t, pointer);
        }

        default R visit(T t, GlobalPointer pointer) {
            return visitAny(t, pointer);
        }

        default R visit(T t, InitializerPointer pointer) {
            return visitAny(t, pointer);
        }

        default R visit(T t, InstanceMethodPointer pointer) {
            return visitAny(t, pointer);
        }

        default R visit(T t, IntegerAsPointer pointer) {
            return visitAny(t, pointer);
        }

        default R visit(T t, MemoryPointer pointer) {
            return visitAny(t, pointer);
        }

        default R visit(T t, ProgramObjectPointer pointer) {
            return visitAny(t, pointer);
        }

        default R visit(T t, ReferenceAsPointer pointer) {
            return visitAny(t, pointer);
        }

        default R visit(T t, StaticFieldPointer pointer) {
            return visitAny(t, pointer);
        }

        default R visit(T t, StaticMethodPointer pointer) {
            return visitAny(t, pointer);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy