Skip to content

Commit f3f3d3c

Browse files
committed
Use direct extractors for tasty trees
1 parent 1e9c6bd commit f3f3d3c

File tree

121 files changed

+2719
-3216
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+2719
-3216
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,11 @@ class Definitions {
667667
def Unpickler_liftedExpr = ctx.requiredMethod("scala.runtime.quoted.Unpickler.liftedExpr")
668668
def Unpickler_unpickleType = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleType")
669669

670-
lazy val TastyContextModule = ctx.requiredModule("scala.tasty.Context")
671-
def TastyContextModuleClass(implicit ctx: Context) = TastyContextModule.symbol.asClass
670+
lazy val TastyUniverseModule = ctx.requiredModule("scala.tasty.Universe")
671+
def TastyUniverseModuleClass(implicit ctx: Context) = TastyUniverseModule.symbol.asClass
672672

673-
lazy val TastyContext_compilationContextR = TastyContextModule.requiredMethod("compilationContext")
674-
def TastyContext_compilationContext(implicit ctx: Context) = TastyContext_compilationContextR.symbol
673+
lazy val TastyUniverse_compilationUniverseR = TastyUniverseModule.requiredMethod("compilationUniverse")
674+
def TastyUniverse_compilationUniverse(implicit ctx: Context) = TastyUniverse_compilationUniverseR.symbol
675675

676676
lazy val EqType = ctx.requiredClassRef("scala.Eq")
677677
def EqClass(implicit ctx: Context) = EqType.symbol.asClass
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dotty.tools.dotc.tasty
2+
3+
import dotty.tools.dotc.core.Contexts.Context
4+
5+
class CompilationUniverse(val context: Context) extends scala.tasty.Universe {
6+
val tasty: TastyImpl.type = TastyImpl
7+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package dotty.tools.dotc.tasty
2+
3+
import dotty.tools.dotc.core.Flags
4+
import dotty.tools.dotc.core.Flags._
5+
6+
class FlagSet(flags: Flags.FlagSet) extends scala.tasty.FlagSet {
7+
8+
def isProtected: Boolean = flags.is(Protected)
9+
def isAbstract: Boolean = flags.is(Abstract)
10+
def isFinal: Boolean = flags.is(Final)
11+
def isSealed: Boolean = flags.is(Sealed)
12+
def isCase: Boolean = flags.is(Case)
13+
def isImplicit: Boolean = flags.is(Implicit)
14+
def isErased: Boolean = flags.is(Erased)
15+
def isLazy: Boolean = flags.is(Lazy)
16+
def isOverride: Boolean = flags.is(Override)
17+
def isInline: Boolean = flags.is(Inline)
18+
def isMacro: Boolean = flags.is(Macro)
19+
def isStatic: Boolean = flags.is(JavaStatic)
20+
def isObject: Boolean = flags.is(Module)
21+
def isTrait: Boolean = flags.is(Trait)
22+
def isLocal: Boolean = flags.is(Local)
23+
def isSynthetic: Boolean = flags.is(Synthetic)
24+
def isArtifact: Boolean = flags.is(Artifact)
25+
def isMutable: Boolean = flags.is(Mutable)
26+
def isLabel: Boolean = flags.is(Label)
27+
def isFieldAccessor: Boolean = flags.is(Accessor)
28+
def isCaseAcessor: Boolean = flags.is(CaseAccessor)
29+
def isCovariant: Boolean = flags.is(Covariant)
30+
def isContravariant: Boolean = flags.is(Contravariant)
31+
def isScala2X: Boolean = flags.is(Scala2x)
32+
def isDefaultParameterized: Boolean = flags.is(DefaultParameterized)
33+
def isStable: Boolean = flags.is(Stable)
34+
35+
override def toString: String = {
36+
val flags = List.newBuilder[String]
37+
if (isProtected) flags += "protected "
38+
if (isAbstract) flags += "abstract"
39+
if (isFinal) flags += "final"
40+
if (isSealed) flags += "sealed"
41+
if (isCase) flags += "case"
42+
if (isImplicit) flags += "implicit"
43+
if (isErased) flags += "erased"
44+
if (isLazy) flags += "lazy"
45+
if (isOverride) flags += "override"
46+
if (isInline) flags += "inline"
47+
if (isMacro) flags += "macro"
48+
if (isStatic) flags += "javaStatic"
49+
if (isObject) flags += "module"
50+
if (isTrait) flags += "trait"
51+
if (isLocal) flags += "local"
52+
if (isSynthetic) flags += "synthetic"
53+
if (isArtifact) flags += "artifact"
54+
if (isMutable) flags += "mutable"
55+
if (isLabel) flags += "label"
56+
if (isFieldAccessor) flags += "accessor"
57+
if (isCaseAcessor) flags += "caseAccessor"
58+
if (isCovariant) flags += "covariant"
59+
if (isContravariant) flags += "contravariant"
60+
if (isScala2X) flags += "scala2x"
61+
if (isDefaultParameterized) flags += "defaultParameterized"
62+
if (isStable) flags += "stable"
63+
flags.result().mkString("<", ",", ">")
64+
}
65+
66+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package dotty.tools.dotc.tasty
2+
3+
import dotty.tools.dotc.ast.tpd
4+
import dotty.tools.dotc.core.Contexts.Context
5+
import dotty.tools.dotc.core.Symbols._
6+
import dotty.tools.dotc.core.Flags._
7+
8+
9+
object FromSymbol {
10+
11+
def definition(sym: Symbol)(implicit ctx: Context): tpd.Tree = {
12+
if (sym.is(Package)) packageDef(sym)
13+
else if (sym == defn.AnyClass) tpd.EmptyTree // FIXME
14+
else if (sym == defn.NothingClass) tpd.EmptyTree // FIXME
15+
else if (sym.isClass) classDef(sym.asClass)
16+
else if (sym.isType) typeDef(sym.asType)
17+
else if (sym.is(Method)) defDef(sym.asTerm)
18+
else valDef(sym.asTerm)
19+
}
20+
21+
def packageDef(sym: Symbol)(implicit ctx: Context): tpd.PackageDef =
22+
tpd.PackageDef(tpd.Ident(sym.typeRef), Nil)
23+
24+
def classDef(cls: ClassSymbol)(implicit ctx: Context): tpd.Tree = {
25+
val constr = tpd.DefDef(cls.unforcedDecls.find(_.isPrimaryConstructor).asTerm)
26+
val body = cls.unforcedDecls.filter(!_.isPrimaryConstructor).map(s => definition(s))
27+
val superArgs = Nil // TODO
28+
tpd.ClassDef(cls, constr, body, superArgs)
29+
}
30+
31+
def typeDef(sym: TypeSymbol)(implicit ctx: Context): tpd.TypeDef = tpd.TypeDef(sym)
32+
33+
def defDef(sym: TermSymbol)(implicit ctx: Context): tpd.DefDef = tpd.DefDef(sym)
34+
35+
def valDef(sym: TermSymbol)(implicit ctx: Context): tpd.ValDef = tpd.ValDef(sym)
36+
37+
}

0 commit comments

Comments
 (0)