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

package ilog.language.design.kernel;

/**
 * @version     Last modified on Tue Dec 10 21:31:59 2002 by hak
 * @version          modified on Wed Jul 24 12:19:07 2002 by pviry
 * @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.design.types.*;
import ilog.language.design.base.*;

/**
 * This is the class of 'new' object expressions.
 */
public class NewObject extends Constant
{
  public NewObject (Type type)
    {
      setType(type);
    }

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

      if (!(_type instanceof ClassType))
        typeChecker.error(locate(new TypingErrorException("bad class type: "+_type)));

      ClassType type = (ClassType)_type;

      for (int i=type.arity(); i-->0;)
        typeChecker.disallowVoid(type.argument(i),this,"class type instantiation");
    }

  public final void compile (Compiler compiler)
    {
      compiler.generate(new PushNewObject((ClassType)_type));
    }

  public final String toString ()
    {
      return "new "+_type;
    }

  // Added by PV
  public final String toTypedString ()
    {
        return typed("new "+_type);
    }
}
