aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/SymDenotations.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-07-01 14:43:18 +0200
committerMartin Odersky <odersky@gmail.com>2014-07-17 11:01:59 +0200
commit3ab2784948d084557e88cd7eb5c55a29613742d0 (patch)
tree62ce5b62fc08afc070e9e705687e9fa05a6e1947 /src/dotty/tools/dotc/core/SymDenotations.scala
parent8112a39d3a00f53a68af794d0a83cf995faf31e2 (diff)
downloaddotty-3ab2784948d084557e88cd7eb5c55a29613742d0.tar.gz
dotty-3ab2784948d084557e88cd7eb5c55a29613742d0.tar.bz2
dotty-3ab2784948d084557e88cd7eb5c55a29613742d0.zip
Added phase: SuperAccessors
Rewrote SuperAccessors (more to be done; see comments), and added stuff here and there to make it work smoother.
Diffstat (limited to 'src/dotty/tools/dotc/core/SymDenotations.scala')
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala45
1 files changed, 41 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index 802762045..643237038 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -395,6 +395,14 @@ object SymDenotations {
/** Is this a user defined "def" method? Excluded are accessors. */
final def isSourceMethod(implicit ctx: Context) = this is (Method, butNot = Accessor)
+ /** This this a method in a value class that is implemented as an extension method? */
+ final def isMethodWithExtension(implicit ctx: Context) =
+ isSourceMethod &&
+ owner.isDerivedValueClass &&
+ !isConstructor &&
+ !is(SuperAccessor) &&
+ !is(Macro)
+
/** Is this a setter? */
final def isGetter(implicit ctx: Context) = (this is Accessor) && !originalName.isSetterName
@@ -447,7 +455,7 @@ object SymDenotations {
def accessWithin(boundary: Symbol) =
ctx.owner.isContainedIn(boundary) &&
(!(this is JavaDefined) || // disregard package nesting for Java
- ctx.owner.enclosingPackage == boundary.enclosingPackage)
+ ctx.owner.enclosingPackageClass == boundary.enclosingPackageClass)
/** Are we within definition of linked class of `boundary`? */
def accessWithinLinked(boundary: Symbol) = {
@@ -572,6 +580,12 @@ object SymDenotations {
NoSymbol
}
+ /** The field accessed by this getter or setter */
+ def accessedField(implicit ctx: Context): Symbol = {
+ val fieldName = if (isSetter) name.asTermName.setterToGetter else name
+ owner.info.decl(fieldName).suchThat(d => !(d is Method)).symbol
+ }
+
/** The chain of owners of this denotation, starting with the denoting symbol itself */
final def ownersIterator(implicit ctx: Context) = new Iterator[Symbol] {
private[this] var current = symbol
@@ -624,8 +638,8 @@ object SymDenotations {
}
/** The package class containing this denotation */
- final def enclosingPackage(implicit ctx: Context): Symbol =
- if (this is PackageClass) symbol else owner.enclosingPackage
+ final def enclosingPackageClass(implicit ctx: Context): Symbol =
+ if (this is PackageClass) symbol else owner.enclosingPackageClass
/** The module object with the same (term-) name as this class or module class,
* and which is also defined in the same scope and compilation unit.
@@ -747,7 +761,6 @@ object SymDenotations {
loop(base.info.baseClasses.dropWhile(owner != _).tail)
}
-
/** A a member of class `base` is incomplete if
* (1) it is declared deferred or
* (2) it is abstract override and its super symbol in `base` is
@@ -895,6 +908,15 @@ object SymDenotations {
case _ => Nil
}
+ /** The symbol of the superclass, NoSymbol if no superclass exists */
+ def superClass(implicit ctx: Context): Symbol = classParents match {
+ case parent :: _ =>
+ val cls = parent.classSymbol
+ if (cls is Trait) NoSymbol else cls
+ case _ =>
+ NoSymbol
+ }
+
/** The denotation is fully completed: all attributes are fully defined.
* ClassDenotations compiled from source are first completed, then fully completed.
* @see Namer#ClassCompleter
@@ -1292,6 +1314,21 @@ object SymDenotations {
def underlyingOfValueClass: Type = ???
def valueClassUnbox: Symbol = ???
+
+ /** If this class has the same `decls` scope reference in `phase` and
+ * `phase.next`, install a new denotation with a cloned scope in `phase.next`.
+ * @pre Can only be called in `phase.next`.
+ */
+ def ensureFreshScopeAfter(phase: DenotTransformer)(implicit ctx: Context): Unit = {
+ assert(ctx.phaseId == phase.next.id)
+ val prevCtx = ctx.withPhase(phase)
+ val ClassInfo(pre, _, ps, decls, selfInfo) = classInfo
+ if (classInfo(prevCtx).decls eq decls) {
+ copySymDenotation(
+ info = ClassInfo(pre, classSymbol, ps, decls.cloneScope, selfInfo),
+ initFlags = this.flags &~ Frozen).installAfter(phase)
+ }
+ }
}
/** The denotation of a package class.