package accrue.analysis.pointer;

import polyglot.types.ProcedureInstance;
import polyglot.util.InternalCompilerError;
import polyglot.util.Position;

/**
 * XXX TODO
 * Represents a call site, to a method or constructor.
 *
 */
public class CallSiteNode {
    private final int id;
    private final String debugString;
    private final ProcedureInstance callee;
    private final Position pos;

    public static final boolean SHOW_POSITION = true;

    private static int generator;

    public CallSiteNode(ProcedureInstance callee, String debugString,
            Position pos) {
        this.id = ++generator;
        this.callee = callee;
        this.debugString = debugString;
        this.pos = pos;
        if (debugString == null) {
            throw new InternalCompilerError("Need debug string");
        }
        if ("null".equals(debugString)) {
            throw new InternalCompilerError("Whacky debug string");
        }
    }

    public ProcedureInstance callee() {
        return this.callee;
    }

    @Override
    public String toString() {
        if (SHOW_POSITION) {
            return debugString + "{" + id + ":" + pos.file() + ":" + pos.line()
                    + "}";
        }
        return debugString + "{" + id + "}";
    }

    @Override
    final public boolean equals(Object o) {
        return this == o;
    }

    @Override
    final public int hashCode() {
        return id;
    }

    public Position getPosition() {
        return pos;
    }
}
