Skip to content

Commit

Permalink
final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdomseeker2001 committed Dec 13, 2022
1 parent 47ce580 commit 5166239
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ class Definitions {
cls.entered
cls
}

def AnyKindType: TypeRef = AnyKindClass.typeRef

@tu lazy val andType: TypeSymbol = enterBinaryAlias(tpnme.AND, AndType(_, _))
Expand Down Expand Up @@ -543,6 +544,10 @@ class Definitions {
List(AnyType), EmptyScope)
@tu lazy val SingletonType: TypeRef = SingletonClass.typeRef

@tu lazy val IterableType: TypeRef = requiredClassRef("scala.collection.Iterable")
def IterableClass(using Context): ClassSymbol = IterableType.symbol.asClass
@tu lazy val Iterable_++ : Symbol = IterableClass.requiredMethod(nme.PLUSPLUS)

@tu lazy val CollectionSeqType: TypeRef = requiredClassRef("scala.collection.Seq")
@tu lazy val SeqType: TypeRef = requiredClassRef("scala.collection.immutable.Seq")
def SeqClass(using Context): ClassSymbol = SeqType.symbol.asClass
Expand All @@ -551,7 +556,6 @@ class Definitions {
@tu lazy val Seq_drop : Symbol = SeqClass.requiredMethod(nme.drop)
@tu lazy val Seq_lengthCompare: Symbol = SeqClass.requiredMethod(nme.lengthCompare, List(IntType))
@tu lazy val Seq_length : Symbol = SeqClass.requiredMethod(nme.length)
@tu lazy val Seq_++ : Symbol = SeqClass.requiredMethod(nme.PLUSPLUS)
@tu lazy val Seq_toSeq : Symbol = SeqClass.requiredMethod(nme.toSeq)
@tu lazy val SeqModule: Symbol = requiredModule("scala.collection.immutable.Seq")

Expand Down
40 changes: 13 additions & 27 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,6 @@ trait Applications extends Compatibility {
*/
protected def isVarArg(arg: Arg): Boolean

/** If constructing trees, turn last `n` processed arguments into a
* `SeqLiteral` tree with element type `elemFormal`.
*/
protected def makeVarArg(n: Int, elemFormal: Type): Unit

/** If constructing trees, turn last `n` processed arguments into a
* `SeqLiteral` tree with element type `elemFormal' without *
*/
Expand Down Expand Up @@ -598,11 +593,12 @@ trait Applications extends Compatibility {
}
}
typedArgs.foreach(addArg(_, elemFormal))


/** Iterates through all arguments and concatenates them with a single varArg SeqLiteral
* @param la: List of Arg that accumulates the Args arguments that are not varArgs up until the first varArg
* is encountered among arguments and the process is then repeated.
* @param counter: this counts how many Vararg arguments were added to the buffer which we pass as argumnent
* @param la: List of Arg that accumulates the arguments that are not varArgs up until the first varArg
is encountered among arguments, then the process is then repeated.
* @param counter: this counts how many Vararg arguments were added to the buffer which we pass as argument
* to method argCombineVarArg.
*/
def concatVararg(listOfArgs: List[Arg], la: List[Arg], counter: Int): Unit =
Expand All @@ -621,10 +617,7 @@ trait Applications extends Compatibility {
addArg(typedArg(x1, seqElemFormal), seqElemFormal)
concatVararg(xs, Nil, counter + 1)
case Nil =>
if (counter == 0) then
harmonizeSeq(listOfArgs, elemFormal)
makeVarArg(args.length, elemFormal)
else argCombineVarArg(counter, elemFormal)
argCombineVarArg(counter, elemFormal)

def missingArg(n: Int): Unit =
fail(MissingArgument(methodType.paramNames(n), methString))
Expand Down Expand Up @@ -753,7 +746,6 @@ trait Applications extends Compatibility {
protected def argType(arg: Arg, formal: Type): Type
def typedArg(arg: Arg, formal: Type): Arg = arg
final def addArg(arg: TypedArg, formal: Type): Unit = ok = ok & argOK(arg, formal)
def makeVarArg(n: Int, elemFormal: Type): Unit = {}
def makeSeqLiteral(n: Int, elemFormal: Type): Unit = {}
def harmonizeSeq(arg: Arg, elemFormal: Type): Unit = {}
def argCombineVarArg(n: Int, elemFormal: Type): Unit = {}
Expand Down Expand Up @@ -807,14 +799,6 @@ trait Applications extends Compatibility {
def addArg(arg: Tree, formal: Type): Unit =
typedArgBuf += adapt(arg, formal.widenExpr)


def makeVarArg(n: Int, elemFormal: Type): Unit =
val args = typedArgBuf.takeRight(n).toList
typedArgBuf.dropRightInPlace(n)
val elemtpt = TypeTree(elemFormal)
typedArgBuf += seqToRepeated(SeqLiteral(args, elemtpt))


def makeSeqLiteral(n: Int, elemFormal: Type): Unit =
val args = typedArgBuf.takeRight(n).toList
typedArgBuf.dropRightInPlace(n)
Expand All @@ -827,13 +811,15 @@ trait Applications extends Compatibility {
t.asInstanceOf[Typed].expr
else t

val varArgTrees = typedArgBuf.takeRight(n)
typedArgBuf.dropRightInPlace(n)
val repeatedarg =
seqToRepeated(varArgTrees.reduce{
(lh, rh) => removeRepeated(lh).select(defn.Seq_++).
appliedToType(elemFormal).appliedTo(removeRepeated(rh))})
typedArgBuf += repeatedarg
if (n == 0) then
SeqLiteral(List.empty, TypeTree(elemFormal))
else
val varArgTrees = typedArgBuf.takeRight(n)
typedArgBuf.dropRightInPlace(n)
varArgTrees.map(x => removeRepeated(x)).reduce{
(lh, rh) => lh.select(defn.Iterable_++).appliedToType(elemFormal).appliedTo(rh)}
typedArgBuf += seqToRepeated(repeatedarg)


def harmonizeArgs(args: List[TypedArg]): List[Tree] =
Expand Down

0 comments on commit 5166239

Please sign in to comment.