Newer
Older
zweic / sources / zweic / Report.scala
/*  zweic -- a compiler for zwei
 *
 *  Stephane Micheloud & LAMP
 *
 *  $Id$
 */

package zweic;


/** This class provides functionality for printing error messages.
 */
object Report {

  /** Number of errors.
   */
  var errors: Int = 0;

  /** Prints out an error message.
   */
  def error(message: String): Unit = {
    errors = errors + 1;
    System.err.println(message);
  }

  /** Prints out an error message.
   */
  def error(position: Int, message: String): Unit = {
    errors = errors + 1;
    print(position, message);
  }

  /** Prints out an error message and stops the program execution.
   */
  def fail(message: String): Unit = {
    error(message);
    System.exit(-1);
  }

  /** Prints out an error message and stops the program execution.
   */
  def fail(position: Int, message: String): Unit = {
    error(position, message);
    System.exit(-1);
  }

  /** Imprime la position et le message passés en argument. */
  private def print(pos: Int, message: String): Unit =
    System.err.println(Position.toString(pos) + ": " + message);

}