<commit_before>/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
\*                                                                      */

// $Id$

import java.lang.Object;

import scalac.{Global => scalac_Global}
import scalac.typechecker.{Infer => scalac_Infer}
import scalac.ApplicationError;
import scalac.util._;
import scalac.ast._;
import scalac.symtab._;
import scala.collection.mutable.HashMap;
import scala.tools.util.Position;

import scala.tools.scalac.util.NewArray;

package scala.tools.scalac.typechecker {

class Infer(global: scalac_Global, gen: TreeGen, make: TreeFactory) extends scalac_Infer {

  import Modifiers._, Kinds._;

  val definitions: Definitions = global.definitions;
  val substituter: Substituter = new Substituter(global, gen);

  def this(trans: Transformer) = this(trans.global, trans.gen, trans.make);

// View generator, overridable */

  def getContextViewMeths: List[View] = List();

  private def getViews(tp: Type): List[View] = {
    memberViews(tp) ::: getContextViewMeths;
  }

  val memberViewCache = new HashMap[Symbol, List[View]];

//  private def memberViews(tp: Type): List[View] = List();

  private def memberViews(tp: Type): List[View] = {
    val tpsym = tp.widen().symbol();
    memberViewCache.get(tpsym) match {
      case Some(vs) => vs
      case None =>
	var vs = companionObjViews(tp, tpsym);
	val ps = tpsym.parents();
	var i = ps.length - 1; while (i >= 0) {
	  vs = memberViews(ps(i)) ::: vs;
	  i = i - 1
	}
      memberViewCache.update(tpsym, vs);
      vs
    }
  }

  private def companionObjViews(tp: Type, clazz: Symbol): List[View] = {
    if (clazz.kind == CLASS && !clazz.isModuleClass() && !clazz.isCaseClass()) {
      var obj = clazz.owner().info().lookupNonPrivate(clazz.name.toTermName());
      //System.out.println("comp obj view " + tp + " " + obj);//DEBUG
      obj.getType() match {
	case Type$OverloadedType(alts, alttypes) =>
	  var i = 0; while (i < alts.length) {
	    if (alts(i).isModule()) obj = alts(i);
	    i = i + 1
	  }
	case _ =>
      }
      if (obj.isModule()) {
	val qual = if (tp.prefix() == Type.NoType) Tree.Empty
		   else gen.mkRef(Position.NOPOS, tp.prefix(), obj);
	val viewsym = obj.info().lookupNonPrivate(Names.view);
	if (viewsym.kind == VAL) {
	  obj.getType().memberType(viewsym) match {
	    case Type$OverloadedType(alts, alttypes) =>
	      var i = alttypes.length - 1;
	      var vs: List[View] = List();
	      while (i >= 0) {
		vs = View(alts(i), alttypes(i), qual, Context.NONE) :: vs;
		i = i - 1
	      }
	      vs
	    case viewtype =>
	      List(View(viewsym, viewtype, qual, Context.NONE))
	  }
	} else List()
      } else List()
    } else List()
  }

// Error messages -------------------------------------------------------------

  def applyErrorMsg(msg1: String, fn: Tree, msg2: String, argtypes: Array[Type], pt: Type): String =
    msg1 + toString(fn.symbol(), fn.getType()) + msg2 +
    ArrayApply.toString(argtypes.asInstanceOf[Array[Object]], "(", ",", ")") +
    (if (pt == Type.AnyType) "" else " with expected result type " + pt);

  def typeErrorMsg(msg: String, found: Type, req: Type): String =
    msg + ";\n found   : " + found.toLongString() + "\n required: " + req;

  def overloadResolveErrorMsg(sym1: Symbol, tpe1: Type, sym2: Symbol, tpe2: Type): String =
    "ambiguous reference to overloaded definition,\n" +
    "both " + sym1 + ": " + tpe1 + "\n" +
    "and  " + sym2 + ": " + tpe2 + "\nmatch";

  /** Give a string representation of symbol `sym' with type `tp'
  *  for error diagnostics. `sym' may be null.
  */
  def toString(sym: Symbol, tp: Type): String =
    (if (tp.isInstanceOf[Type$OverloadedType]) "overloaded " else "") +<commit_msg>*** empty log message ***<commit_after>/*     ____ ____  ____ ____  ______                                     *\
**    / __// __ \/ __// __ \/ ____/    SOcos COmpiles Scala             **
**  __\_ \/ /_/ / /__/ /_/ /\_ \       (c) 2002, LAMP/EPFL              **
** /_____/\____/\___/\____/____/                                        **
\*                                                                      */

// $Id$

import java.lang.Object;

import scalac.{Global => scalac_Global}
import scalac.typechecker.{Infer => scalac_Infer}
import scalac.ApplicationError;
import scalac.util._;
import scalac.ast._;
import scalac.symtab._;
import scala.collection.mutable.HashMap;
import scala.tools.util.Position;

import scala.tools.scalac.util.NewArray;

package scala.tools.scalac.typechecker {

class Infer(global: scalac_Global, gen: TreeGen, make: TreeFactory) extends scalac_Infer {

  import Modifiers._, Kinds._;

  val definitions: Definitions = global.definitions;
  val substituter: Substituter = new Substituter(global, gen);

  def this(trans: Transformer) = this(trans.global, trans.gen, trans.make);

// View generator, overridable */

  def getContextViewMeths: List[View] = List();

  private def getViews(tp: Type): List[View] = {
    memberViews(tp) ::: getContextViewMeths;
  }

  val memberViewCache = new HashMap[Symbol, List[View]];

//  private def memberViews(tp: Type): List[View] = List();

  private def memberViews(tp: Type): List[View] = {
    val tpsym = tp.widen().symbol();
    memberViewCache.get(tpsym) match {
      case Some(vs) => vs
      case None =>
	var vs = companionObjViews(tp, tpsym);
	val ps = tpsym.parents();
	var i = ps.length - 1; while (i >= 0) {
	  vs = memberViews(ps(i)) ::: vs;
	  i = i - 1
	}
      memberViewCache.update(tpsym, vs);
      vs
    }
  }

  private def companionObjViews(tp: Type, clazz: Symbol): List[View] = {
    if (clazz.kind == CLASS && !clazz.isModuleClass() && !clazz.isCaseClass()) {
      var obj = clazz.owner().info().lookupNonPrivate(clazz.name.toTermName());
      if (obj.isExternal() == clazz.isExternal()) {
	//System.out.println("comp obj view " + tp + " " + obj);//DEBUG
	obj.getType() match {
	  case Type$OverloadedType(alts, alttypes) =>
	    var i = 0; while (i < alts.length) {
	      if (alts(i).isModule()) obj = alts(i);
	      i = i + 1
	    }
	  case _ =>
	}
	if (obj.isModule()) {
	  val qual = if (tp.prefix() == Type.NoType) Tree.Empty
		     else gen.mkRef(Position.NOPOS, tp.prefix(), obj);
	  val viewsym = obj.info().lookupNonPrivate(Names.view);
	  if (viewsym.kind == VAL) {
	    obj.getType().memberType(viewsym) match {
	      case Type$OverloadedType(alts, alttypes) =>
		var i = alttypes.length - 1;
		var vs: List[View] = List();
		while (i >= 0) {
		  vs = View(alts(i), alttypes(i), qual, Context.NONE) :: vs;
		  i = i - 1
		}
		vs
	      case viewtype =>
		List(View(viewsym, viewtype, qual, Context.NONE))
	    }
	  } else List()
	} else List()
      } else List()
    } else List()
  }

// Error messages -------------------------------------------------------------

  def applyErrorMsg(msg1: String, fn: Tree, msg2: String, argtypes: Array[Type], pt: Type): String =
    msg1 + toString(fn.symbol(), fn.getType()) + msg2 +
    ArrayApply.toString(argtypes.asInstanceOf[Array[Object]], "(", ",", ")") +
    (if (pt == Type.AnyType) "" else " with expected result type " + pt);

  def typeErrorMsg(msg: String, found: Type, req: Type): String =
    msg + ";\n found   : " + found.toLongString() + "\n required: " + req;

  def overloadResolveErrorMsg(sym1: Symbol, tpe1: Type, sym2: Symbol, tpe2: Type): String =
    "ambiguous reference to overloaded definition,\n" +
    "both " + sym1 + ": " + tpe1 + "\n" +
    "and  " + sym2 + ": " + tpe2 + "\nmatch";

  /** Give a string representation of symbol `sym' with type `tp'
  *  for error diagnostics. `sym' may be null.
  */
  def toString(sym: Symbol, tp: Type): String =
    (if (tp.isInstanceOf[Type$OverloadedType]) "overloaded " else "") +
{'fraction_non_alphanumeric': 0.17212394931627148, 'fraction_numerical': 0.0060218291305984195, 'mean_word_length': 2.493426818580193, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4037231', 'n_tokens_mistral': 2768, 'n_tokens_neox': 2663, 'n_words': 631}