//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// PLEASE DO NOT EDIT WITHOUT THE EXPLICIT CONSENT OF THE AUTHOR! \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

package ilog.language.design.types;

/**
 * @version     Last modified on Tue Dec 10 20:38:39 2002 by hak
 * @author      <a href="mailto:hak@ilog.fr">Hassan A&iuml;t-Kaci</a>
 * @copyright   &copy; 2000-2002 <a href="http://www.ilog.fr/">ILOG, S.A.</a>
 */

import ilog.language.tools.Misc;
import ilog.language.util.Locatable;

/**
 * A <tt>Goal</tt> is anything that may be established and undone by a <tt>TypeChecker</tt>.
 * Here are the different types of goals:
 * <ul>
 * <li> <a href="BaseTypeGoal.html"><tt>BaseTypeGoal</tt>,
 * <li> <a href="ArrayIndexTypeGoa.html"><tt>ArrayIndexTypeGoa</tt>,
 * <li> <a href="CheckExitableGoal.html"><tt>CheckExitableGoal</tt>,
 * <li> <a href="EmptyGoal.html"><tt>EmptyGoal</tt>,
 * <li> <a href="GlobalTypingGoal.html"><tt>GlobalTypingGoal</tt>,
 * <li> <a href="PopExitableGoal.html"><tt>PopExitableGoal</tt>,
 * <li> <a href="PruningGoal.html"><tt>PruningGoal</tt>,
 * <li> <a href="PushExitableGoal.html"><tt>PushExitableGoal</tt>,
 * <li> <a href="ResiduatedGoal.html"><tt>ResiduatedGoal</tt>,
 * <li> <a href="ShadowUnifyGoal.html"><tt>ShadowUnifyGoal</tt>,
 * <li> <a href="TypingGoal.html"><tt>TypingGoal</tt>,
 * <li> <a href="UnifyBaseTypeGoal.html"><tt>UnifyBaseTypeGoal</tt>,
 * <li> <a href="UnifyGoal.html"><tt>UnifyGoal</tt>,
 * <li> <a href="NoVoidTypeGoal.html"><tt>NoVoidTypeGoal</tt>.
 * </ul>
 */

abstract public class Goal extends TimeStamp
{
  private boolean _isTrailable = true;

  final void setIsTrailable (boolean isTrailable)
    {
      _isTrailable = isTrailable;
    }

  final void trail (TypeChecker typeChecker)
    {
      if (_isTrailable)
        typeChecker.trail(this);
    }

  /**
   * This method is called by the type checker to try and establish this goal.
   */       
  abstract void prove (TypeChecker typeChecker) throws StaticSemanticsErrorException;

  /**
   * This method is called by the type checker upon popping it from the goal trail.
   */       
  void undo (TypeChecker typeChecker)
    {
      typeChecker.pushGoal(this);
    }

  /**
   * Returns this goal's location's extent as a <a href="../../util/Locatable.html">
   * <tt>Locatable</tt></a>.
   */
  abstract Locatable extent ();

  public String toString ()
    {
      return /* Misc.locationString(extent()) + */ "Goal " + timeStamp();
    }
}
