From f8a42a0584d855a0548c20c7434ed83a59647ed9 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 18 Jun 2013 19:38:09 +0200 Subject: Added typedIdent method. Also some refactorings that were caused by adding this method. --- src/dotty/tools/dotc/core/Contexts.scala | 10 +++++----- src/dotty/tools/dotc/core/Denotations.scala | 17 +++++++++++++++++ src/dotty/tools/dotc/core/SymDenotations.scala | 4 ++++ src/dotty/tools/dotc/core/Types.scala | 6 ++++-- 4 files changed, 30 insertions(+), 7 deletions(-) (limited to 'src/dotty/tools/dotc/core') diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index 588c18c4c..874f28bce 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -138,10 +138,10 @@ object Contexts { protected def typer_=(typer: Typer) = _typer = typer def typer: Typer = _typer - /** The currently visible imports */ - private[this] var _imports: List[ImportInfo] = _ - protected def imports_=(imports: List[ImportInfo]) = _imports = imports - def imports: List[ImportInfo] = _imports + /** The currently active import info */ + private[this] var _importInfo: ImportInfo = _ + protected def importInfo_=(importInfo: ImportInfo) = _importInfo = importInfo + def importInfo: ImportInfo = _importInfo /** The current reporter */ private[this] var _reporter: Reporter = _ @@ -263,7 +263,7 @@ object Contexts { def withScope(scope: Scope): this.type = { this.scope = scope; this } def withNewScope: this.type = { this.scope = newScope; this } def withTyper(typer: Typer): this.type = { this.typer = typer; this.scope = typer.scope; this } - def withImport(importInfo: ImportInfo): this.type = { this.imports = importInfo :: imports; this } + def withImportInfo(importInfo: ImportInfo): this.type = { this.importInfo = importInfo; this } def withReporter(reporter: Reporter): this.type = { this.reporter = reporter; this } def withDiagnostics(diagnostics: Option[StringBuilder]): this.type = { this.diagnostics = diagnostics; this } def withMoreProperties(moreProperties: Map[String, Any]): this.type = { this.moreProperties = moreProperties; this } diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index b585fb0ef..b69997836 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -161,6 +161,11 @@ object Denotations { /** Does this denotation have an alternative that satisfies the predicate `p`? */ def hasAltWith(p: Symbol => Boolean): Boolean + /** The denotation made up from the alternatives of this denotation that + * are accessible from prefix `pre`, or NoDenotation if no accessible alternative exists. + */ + def accessibleFrom(pre: Type, superAccess: Boolean = false)(implicit ctx: Context): Denotation + /** Find member of this denotation with given name and * produce a denotation that contains the type of the member * as seen from given prefix `pre`. Exclude all members that have @@ -244,6 +249,8 @@ object Denotations { if (sym2.isClass || sym2.isAliasType) denot2 else { // if sym1, sym2 exist, they are abstract types or term symbols + // we prefer concrete because they allow more things when seen as types + // e.g. new C. Question: Should we take accessibility into account? val info1 = denot1.info val info2 = denot2.info val sym1Eligible = sym1.isAsConcrete(sym2) @@ -327,6 +334,13 @@ object Denotations { } def hasAltWith(p: Symbol => Boolean): Boolean = denot1.hasAltWith(p) || denot2.hasAltWith(p) + def accessibleFrom(pre: Type, superAccess: Boolean)(implicit ctx: Context): Denotation = { + val d1 = denot1 accessibleFrom (pre, superAccess) + val d2 = denot2 accessibleFrom (pre, superAccess) + if (!d1.exists) d2 + else if (!d2.exists) d1 + else derivedMultiDenotation(d1, d2) + } def derivedMultiDenotation(d1: Denotation, d2: Denotation) = if ((d1 eq denot1) && (d2 eq denot2)) this else MultiDenotation(d1, d2) override def toString = alternatives.mkString(" ") @@ -365,6 +379,9 @@ object Denotations { def hasAltWith(p: Symbol => Boolean): Boolean = p(symbol) + def accessibleFrom(pre: Type, superAccess: Boolean)(implicit ctx: Context): Denotation = + if (symbol isAccessibleFrom (pre, superAccess)) this else NoDenotation + def atSignature(sig: Signature)(implicit ctx: Context): SingleDenotation = if (sig == signature) this else NoDenotation diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 64119944c..3026562a3 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -208,6 +208,10 @@ object SymDenotations { final def markAbsent(): Unit = _info = NoType + /** Is symbol known to not exist? */ + final def isAbsent: Boolean = + _info == NoType + /** Is this symbol the root class or its companion object? */ final def isRoot: Boolean = name.toTermName == nme.ROOT diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index c4484c892..1a1789eeb 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -117,8 +117,10 @@ object Types { classSymbol is ModuleClass /** Is this type produced as a repair for an error? */ - final def isError(implicit ctx: Context): Boolean = - (typeSymbol is Erroneous) || (termSymbol is Erroneous) + final def isError(implicit ctx: Context): Boolean = this match { + case ErrorType => true + case _ => (typeSymbol is Erroneous) || (termSymbol is Erroneous) + } /** Is some part of this type produced as a repair for an error? */ final def isErroneous(implicit ctx: Context): Boolean = existsPart(_.isError) -- cgit v1.2.3