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

package ilog.language.design.kernel;

/**
 * @version     Last modified on Fri Oct 18 17:49:06 2002 by hak
 * @version          modified on Wed Jun 12 19:41:30 2002 by pviry
 * @author      <a href="mailto:hak@ilog.fr">Hassan A&iuml;t-Kaci</a>
 * @copyrite   &copy; 2000-2002 <a href="http://www.ilog.fr/">ILOG, S.A.</a>
 */

import ilog.language.design.types.*;
import ilog.language.design.base.*;

import java.util.ArrayList;

public abstract class AndOr extends Expression
{
  Type _type = Type.BOOLEAN();

  protected Expression _leftExpression;
  protected Expression _riteExpression;

  public AndOr (Expression leftExpression, Expression riteExpression)
    {
      _leftExpression = leftExpression;
      _riteExpression = riteExpression;      
    }

  public final int numberOfSubexpressions ()
    {
      return 2;
    }

  public final Expression subexpression (int n) throws NoSuchSubexpressionException
    {
      switch (n)
        {
        case 0:
          return _leftExpression;
        case 1:
          return _riteExpression;
        }

      throw new NoSuchSubexpressionException(this,n);
    }

  public abstract void compile (Compiler compiler);

  public final Expression sanitizeNames (ParameterStack parameters, ClassTypeHandle handle)
    {
      _leftExpression = _leftExpression.sanitizeNames(parameters, handle);
      _riteExpression = _riteExpression.sanitizeNames(parameters, handle);

      return this;
    }

  public final void sanitizeSorts (Enclosure enclosure)
    {
      _leftExpression.sanitizeSorts(enclosure);
      _riteExpression.sanitizeSorts(enclosure);
    }

  public final void setType (Type type)
    {
      throw new java.lang.Error("Illegal method call in "+getClass()+": setType(Type)");
    }

  public final Type type ()
    {
      return _type.value();
    }

  public final Type typeRef ()
    {
      return _type;
    }

  public final Type checkedType ()
    {
      return _type;
    }

  public final void setCheckedType (Type type)
    {
    }

  public final void setCheckedType ()
    {
      if (isSetCheckedType()) return;
      _leftExpression.setCheckedType();
      _riteExpression.setCheckedType();
    }

  public final void typeCheck (TypeChecker typeChecker) throws TypingErrorException
    {
      if (typeCheckLocked()) return;

      _leftExpression.typeCheck(Type.BOOLEAN(),typeChecker);
      _riteExpression.typeCheck(Type.BOOLEAN(),typeChecker);
    }

  public final Expression shiftOffsets (int intShift, int realShift, int objectShift,
                                        int intDepth, int realDepth, int objectDepth)
    {
      _leftExpression = _leftExpression.shiftOffsets(intShift,realShift,objectShift,
                                                     intDepth,realDepth,objectDepth);

      _riteExpression = _riteExpression.shiftOffsets(intShift,realShift,objectShift,
                                                     intDepth,realDepth,objectDepth);

      return this;
    }

}
