
package de.dhbwstuttgart.syntaxtree.statement;

import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.ConstraintsFactory;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import org.antlr.v4.runtime.Token;


public class Assign extends Statement
{
    private final Expression rightSide;
    private final LocalVar lefSide;

    public Assign(LocalVar leftHandSide, Expression value, Token offset) {
		super(leftHandSide.getType(), offset);
        this.rightSide = value;
        this.lefSide = leftHandSide;
	}

    @Override
    public ConstraintSet getConstraints(TypeInferenceBlockInformation info) {
        ConstraintSet ret = lefSide.getConstraints(info);
        ret.addAll(rightSide.getConstraints(info));
        ret.addUndConstraint(ConstraintsFactory.createPair(
                rightSide.getType(), lefSide.getType(), PairOperator.SMALLERDOT, info));
        return ret;
    }
}
