package de.dhbwstuttgart.strucTypes5.assumptions;

import de.dhbwstuttgart.strucTypes5.typeVars.TypeVar;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarAbstract;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarFactory;
import de.dhbwstuttgart.strucTypes5.typeVars.TypeVarStore;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.Method;

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

/**
 * Created by sebastian on 20.04.17.
 *
 * The main Task of AssumptionFactory is to create a new Assumption and save The new TypVar in the Typevarstore with the
 * relatet TypePlaceHolder of the Syntaxtree.
 */
public class AssumptionFactory {




    public static AssumptionField makeFieldAssumption(Field feld, TypeVarStore typeVarStore) {
        TypeVar typeVar = TypeVarFactory.makeTypeVar();
        typeVarStore.addTuple(typeVar, feld.getType());
        return new AssumptionField(feld.getName(), typeVar);
    }



    public static AssumptionMethod makeMethodAssumption(Method method, TypeVarStore typeVarStore) {

        // TypeVar for Returntype
        TypeVar rType = TypeVarFactory.makeTypeVar();
        typeVarStore.addTuple(rType,method.getType());





        // TypeVar for ArgumentTypes
        List<TypeVar> typeVars = new ArrayList<>();
        for (FormalParameter fp :  method.getParameterList().getFormalparalist()) {
            TypeVar typeVarFp = TypeVarFactory.makeTypeVar();
            typeVarStore.addTuple(typeVarFp,fp.getType());
            typeVars.add(typeVarFp);
        }

        AssumptionMethod assumptionMethod = new AssumptionMethod(method.getName(), typeVars, rType);

        return assumptionMethod;
    }



    public static AssumptionArgument makeArgumentAssumption(FormalParameter formalParameter , TypeVarStore typeVarStore) {
        TypeVarAbstract typeVar = typeVarStore.storeTPH(formalParameter.getType());
        return new AssumptionArgument(formalParameter.getName(), typeVar);
    }






}
