package de.dhbwstuttgart.strucTypes4.syntaxtree;

import de.dhbwstuttgart.strucTypes4.algo.ConstraintAbstract;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes4.typeVars.TypeVarStore;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by sebastian on 07.04.17.
 */
public class ExprVar extends  ExpressionAbstract {

    String name;


    public List<ConstraintAbstract> typeExpr(Map<String, TypeVarAbstract> ass, TypeVarStore typeVarStore)  {
        List<ConstraintAbstract> constriants = new ArrayList<>();

        TypeVarAbstract tv = ass.get(name);
        typeVarStore.addTuple(tv,getTypePlaceHolder());
        return  constriants;
    }

    public ExprVar(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return name;
    }

    @Override
    public String toCodeTPH() {
        return String.format( " %s : %s " ,   name ,  getTypePlaceHolder() );
    }


    @Override
    public String toCodeTyped(TypeVarStore typeVarStore) {
        return String.format( " %s : %s " ,   name ,  typeVarStore.getTypeVarByTPH(getTypePlaceHolder()) );
    }

}
