/*******************************************************************************
* Copyright (c)                                                                *
*           2005   Tristan Allwood,                                            *
*           2005   Daniel Burke,                                               *
*           2005   Marc Hull,                                                  *
*           2005   Ekaterina Itskova,                                          *
*           2005   Steve Zymler                                                *
*                                                                              *
* Permission is hereby granted, free of charge, to any person obtaining a      *
* copy of this software and associated documentation files (the                *
* "Software"), to deal in the Software without restriction, including          *
* without limitation the rights to use, copy, modify, merge, publish,          *
* distribute, sublicense, and/or sell copies of the Software, and to           *
* permit persons to whom the Software is furnished to do so, subject to        *
* the following conditions:                                                    *
*                                                                              *
* The above copyright notice and this permission notice shall be included      *
* in all copies or substantial portions of the Software.                       *
*                                                                              *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS      *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF                   *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.       *
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY         *
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,         *
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE            *
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                       *
*******************************************************************************/
package uk.ac.ic.doc.kevlar.core.framework.typecheck;

import java.util.Map;
import java.util.Set;

import uk.ac.ic.doc.kevlar.api.programs.arguments.IInputNode;
import uk.ac.ic.doc.kevlar.api.programs.arguments.IOutputNode;
import uk.ac.ic.doc.kevlar.publicInterfaces.INode;

/**
 * This is a utility interface that defines some helper methods for
 * Type-Checking. Implementations of this interface will need an instance of a
 * ITypeTree to use as the backing type tree.
 * 
 * @author Steve Zymler
 */
public interface ITypeChecker {

    /**
     * @return the backing ITypeTree this implementation is working from. This
     *         method must never return null.
     */
    ITypeTree getTypeTree();

    /**
     * Set the TypeTree used by this checker.
     * 
     * @param newTree the new ITypeTree to use to back this ITypeChecker
     * @throws NullPointerException if the parameter is null.
     */
    void setTypeTree(ITypeTree newTree);
        
    /**
     * Method to compute the new bounds of a set of input and output types,
     * given the default topBound, and the new input type. This is a utility for
     * template typed pipes.
     * 
     * @param inputs
     *            The set of inputs that have already been fixed.
     * @param outputs
     *            The set of outputs that have already been fixed.
     * @param topBound
     *            The top-bound of the template type.
     * @param newInput
     *            The new input that has just been added.
     * @return IBounds of the new bounds if newInput can be done without
     *         destroying everything, null if it fails.
     */
    IBounds computeBoundsInput(Set<ITypeClass> inputs, Set<ITypeClass> outputs,
            IBasicTypeClass topBound, ITypeClass newInput);
    
    
    /**
     * Method to compute the new bounds of a set of input and outputs types,
     * given the default topBound, and the new output type. This is a utility
     * for template typed pipes.
     * 
     * @param inputs
     *            The set of inputs that have already been fixed.
     * @param outputs
     *            The set of outputs that have already been fixed.
     * @param topBound
     *            The top-bound of the template type.
     * @param newOutput
     *            The new output that has just been added.
     * @return IBounds of the new bounds if newOutput can be done without
     *         destroying everything, null if it fails.
     */
    IBounds computeBoundsOutput(Set<ITypeClass> inputs, Set<ITypeClass> outputs,
            IBasicTypeClass topBound, ITypeClass newOutput);
    
    
    /**
     * 
     * @param nodeA input node to connect from
     * @param nodeB output node to connect to
     * @return if nodeA can be connected to nodeB
     */
    boolean isPipeable( IInputNode nodeA, IOutputNode nodeB);
    
    public boolean isPipeable(
			Map<String, IInterfaceClass> deltaLUBs,
			Map<String, IInterfaceClass> baseLUBs,
			INode fromNode, 
			INode toNode );
    
    public boolean isPipeable(			
			Map<String, IInterfaceClass> baseLUBs,
			INode fromNode, 
			INode toNode );	
    
    public IInterfaceClass inferTypeOfNode(
			Map<String, IInterfaceClass> deltaLUBs,
			Map<String, IInterfaceClass> baseLUBs,
			INode fromNode );
    
    public IInterfaceClass getLeastUpperBound( Set<IInterfaceClass> typeInputs);
}
