8000 WIP mapOver/traverse/transform: refactor pattern match into virtual call [ci: last-only] by retronym · Pull Request #5906 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

WIP mapOver/traverse/transform: refactor pattern match into virtual call [ci: last-only] #5906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "SI-3832 Extract tracking of under-construction classes to a m…
…ixin"

This reverts commit c2dc346.
  • Loading branch information
retronym committed May 15, 2017
commit 372d1526f3d4c239f5b1573f9647dbc38ccd0981
17 changes: 15 additions & 2 deletions src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ abstract class ExplicitOuter extends InfoTransform
* values for outer parameters of constructors.
* The class provides methods for referencing via outer.
*/
abstract class OuterPathTransformer(unit: CompilationUnit) extends TypingTransformer(unit) with UnderConstructionTransformer {
abstract class OuterPathTransformer(unit: CompilationUnit) extends TypingTransformer(unit) {
/** The directly enclosing outer parameter, if we are in a constructor */
protected var outerParam: Symbol = NoSymbol

Expand Down Expand Up @@ -267,6 +267,13 @@ abstract class ExplicitOuter extends InfoTransform
else outerPath(outerSelect(base), from.outerClass, to)
}


/** The stack of class symbols in which a call to this() or to the super
* constructor, or early definition is active
*/
protected def isUnderConstruction(clazz: Symbol) = selfOrSuperCalls contains clazz
protected val selfOrSuperCalls = collection.mutable.Stack[Symbol]()

override def transform(tree: Tree): Tree = {
def sym = tree.symbol
val savedOuterParam = outerParam
Expand All @@ -279,7 +286,13 @@ abstract class ExplicitOuter extends InfoTransform
assert(outerParam.name startsWith nme.OUTER, outerParam.name)
case _ =>
}
super.transform(tree)
if ((treeInfo isSelfOrSuperConstrCall tree) || (treeInfo isEarlyDef tree)) {
selfOrSuperCalls push currentOwner.owner
val transformed = super.transform(tree)
selfOrSuperCalls.pop()
transformed
} else
super.transform(tree)
}
finally outerParam = savedOuterParam
}
Expand Down
19 changes: 0 additions & 19 deletions src/reflect/scala/reflect/internal/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1762,25 +1762,6 @@ trait Trees extends api.Trees {
}
}

/** Tracks the classes currently under construction during a transform */
trait UnderConstructionTransformer extends Transformer {
import collection.mutable

protected def isUnderConstruction(clazz: Symbol) = selfOrSuperCalls contains clazz

/** The stack of class symbols in which a call to this() or to the super
* constructor, or early definition is active */
private val selfOrSuperCalls = mutable.Stack[Symbol]()

abstract override def transform(tree: Tree) = {
if ((treeInfo isSelfOrSuperConstrCall tree) || (treeInfo isEarlyDef tree)) {
selfOrSuperCalls push currentOwner.owner
try super.transform(tree)
finally selfOrSuperCalls.pop()
} else super.transform(tree)
}
}

def duplicateAndKeepPositions(tree: Tree) = new Duplicator(focusPositions = false) transform tree

// this is necessary to avoid crashes like https://github.com/scalamacros/paradise/issues/1
Expand Down
0