/**
 * 
 */
package accrue.analysis.pointer;

import polyglot.main.Report;
import polyglot.types.CodeInstance;
import polyglot.util.Position;
import accrue.analysis.AnalysisTopics;
import accrue.analysis.pointer.PointsToEngine.StmtAndContext;
import accrue.analysis.pointer.analyses.HeapAbstractionFactory;

public class StmtLocalToLocal extends PointsToStmt {

    final ReferenceVariable left;
    final ReferenceVariable right;

    public StmtLocalToLocal(ReferenceVariable left, ReferenceVariable right, Position origin,
            CodeInstance code) {
        super(origin, code, left.expectedType(), right.expectedType(), false);
        this.left = left;
        this.right = right;
    }

    @Override
    public String toString() {
        return left + " = " + right;
    }

    @Override
    public boolean process(CContext context, PointsToGraph g,
            StmtRegistrar registrar, HeapAbstractionFactory af,
            StmtAndContext sac) {
        PointsToGraphNode l =
                ReferenceVariableReplica.create(context, left, af);
        PointsToGraphNode r =
                ReferenceVariableReplica.create(context, right, af);

        if (Report.should_report(AnalysisTopics.POINTSTO, 3))
            Report.report(3, "Processing local to local " + this
                    + " in context " + context);

        return g.addEdges(sac,
                          l,
                          g.pointsToFiltered(sac, r, this.left.expectedType()),
                          origin);
    }

}
