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

package ilog.language.design.base;

/**
 * @version     Last modified on Thu Apr 04 09:47:31 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>
 */

/**
 * This class is the mother of all instructions that refer to an
 * object's field, whose offset must be set upon backpatching.
 */

import ilog.language.design.types.DefinedEntry;
import ilog.language.design.backend.Runtime;
import ilog.language.design.backend.NullValueException;

public abstract class FieldInstruction extends Instruction
{
  private DefinedEntry _entry;

  protected final DefinedEntry entry ()
    {
      return _entry;
    }

  protected final int offset ()
    {
      return _entry.fieldOffset();
    }

  protected FieldInstruction (DefinedEntry codeEntry)
    {
      _entry = codeEntry;
    }

  public final void checkForNull (Runtime r, String mode) throws NullValueException
    {
      boolean objectIsNull = (mode == "access" ? r.objectIsNull() : r.fieldObjectIsNull());

      if (objectIsNull)
        throw new NullValueException("can't "+mode+" field '"+_entry.symbol()+
                                     "' of "+r.popObject());
    }      

  public final int hashCode ()
    {
      return name().hashCode() + _entry.hashCode();
    }

  public final boolean equals (Object object)
    {
      if (this == object)
        return true;

      if (!(object instanceof FieldInstruction))
        return false;

      FieldInstruction other = (FieldInstruction)object;

      return name() == other.name() && _entry == other.entry();
    }

  public final String toString ()
    {
      return name() + "(" + _entry + ")";
    }
}

