From 9b9c9f8bf9394f54576153240931bf2e5a85e3eb Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 17 Sep 2020 17:53:20 +0200 Subject: [PATCH 1/2] Implement Reflection API directly Revert to the original design with abstract modules that are implemented directly. We had to move the implementations to the compiler interface with one of the iterations of extension methods. The current extension methods are again compatible with this design. CompilerInterface is kept for the internal methods that are only available in the stdlib. * Now Reflection contains the full user-facing API * CompilerInterface only contains internal methods used in the stdlib * tasty.refelct.Types was merged into Reflection * QuoteContextImpl implements every member directly * All members of tasty are lazily initialized using object * Fix defn.NullClass * Fix typo in Flags.Accessor * Rename Scala2X to Scala2x to follow dotty conventions --- .../tools/dotc/quoted/QuoteContextImpl.scala | 2613 +++++++++++++- .../reflect/ReflectionCompilerInterface.scala | 2115 ----------- .../dotty/tools/dotc/transform/TailRec.scala | 1 + .../scala/quoted/Liftable.scala | 6 +- .../internal/tasty/CompilerInterface.scala | 1143 +----- library/src/scala/tasty/Reflection.scala | 3199 ++++++++++------- .../tasty/reflect/ExtractorsPrinter.scala | 4 +- library/src/scala/tasty/reflect/Printer.scala | 1 + .../tasty/reflect/SourceCodePrinter.scala | 6 +- library/src/scala/tasty/reflect/Types.scala | 409 --- tests/run-macros/tasty-definitions-1.check | 2 +- 11 files changed, 4512 insertions(+), 4987 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/quoted/reflect/ReflectionCompilerInterface.scala delete mode 100644 library/src/scala/tasty/reflect/Types.scala diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala index f9133d65739c..f0d85cc20d8f 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala @@ -1,12 +1,25 @@ package dotty.tools.dotc.quoted +import dotty.tools.dotc import dotty.tools.dotc.ast.tpd +import dotty.tools.dotc.ast.untpd +import dotty.tools.dotc.core.Annotations import dotty.tools.dotc.core.Contexts._ +import dotty.tools.dotc.core.Types +import dotty.tools.dotc.core.Flags._ +import dotty.tools.dotc.core.NameKinds +import dotty.tools.dotc.core.StdNames._ import dotty.tools.dotc.quoted.reflect._ +import dotty.tools.dotc.core.Decorators._ +import dotty.tools.dotc.quoted.reflect.FromSymbol.{definitionFromSym, packageDefFromSym} +import dotty.tools.dotc.typer.Implicits import scala.quoted.QuoteContext import scala.quoted.show.SyntaxHighlight +import scala.internal.quoted.Unpickler +import scala.tasty.reflect._ + object QuoteContextImpl { type ScopeId = Int @@ -36,8 +49,2602 @@ object QuoteContextImpl { } -class QuoteContextImpl private (ctx: Context) extends QuoteContext { +class QuoteContextImpl private (ctx: Context) extends QuoteContext: // NOTE: The tasty class should only mixin the compiler interface and the reflection interface. // We should not implement methods here, all should be implemented by `ReflectionCompilerInterface` - val tasty = new ReflectionCompilerInterface(ctx) with scala.tasty.Reflection -} + object tasty extends scala.tasty.Reflection, scala.internal.tasty.CompilerInterface: + + def rootContext: Context = ctx + + def rootPosition: dotc.util.SourcePosition = + MacroExpansion.position.getOrElse(dotc.util.SourcePosition(rootContext.source, dotc.util.Spans.NoSpan)) + + type Context = dotc.core.Contexts.Context + + type Tree = tpd.Tree + + object Tree extends TreeModule + + object TreeMethodsImpl extends TreeMethods: + extension (self: Tree): + def pos: Position = self.sourcePos + def symbol: Symbol = self.symbol + def showExtractors: String = + new ExtractorsPrinter[tasty.type](tasty).showTree(self) + def show: String = + self.showWith(SyntaxHighlight.plain) + def showWith(syntaxHighlight: SyntaxHighlight): String = + new SourceCodePrinter[tasty.type](tasty)(syntaxHighlight).showTree(self) + def isExpr: Boolean = + self match + case TermTypeTest(self) => + self.tpe.widen match + case _: MethodType | _: PolyType => false + case _ => true + case _ => false + end extension + + extension [T](tree: Tree) + def asExprOf(using scala.quoted.Type[T])(using QuoteContext): scala.quoted.Expr[T] = + if tree.isExpr then + new scala.internal.quoted.Expr(tree, compilerId).asExprOf[T] + else tree match + case TermTypeTest(tree) => throw new Exception("Expected an expression. This is a partially applied Term. Try eta-expanding the term first.") + case _ => throw new Exception("Expected a Term but was: " + tree) + + end TreeMethodsImpl + + type PackageClause = tpd.PackageDef + + object PackageClauseTypeTest extends TypeTest[Tree, PackageClause]: + def runtimeClass: Class[?] = classOf[PackageClause] + override def unapply(x: Any): Option[PackageClause] = x match + case x: tpd.PackageDef @unchecked => Some(x) + case _ => None + end PackageClauseTypeTest + + object PackageClause extends PackageClauseModule: + def apply(pid: Ref, stats: List[Tree]): PackageClause = + withDefaultPos(tpd.PackageDef(pid.asInstanceOf[tpd.RefTree], stats)) + def copy(original: Tree)(pid: Ref, stats: List[Tree]): PackageClause = + tpd.cpy.PackageDef(original)(pid, stats) + def unapply(tree: PackageClause): Some[(Ref, List[Tree])] = + Some((tree.pid, tree.stats)) + end PackageClause + + object PackageClauseMethodsImpl extends PackageClauseMethods: + extension (self: PackageClause): + def pid: Ref = self.pid + def stats: List[Tree] = self.stats + end extension + end PackageClauseMethodsImpl + + type Import = tpd.Import + + object ImportTypeTest extends TypeTest[Tree, Import]: + def runtimeClass: Class[?] = classOf[Import] + override def unapply(x: Any): Option[Import] = x match + case tree: tpd.Import @unchecked => Some(tree) + case _ => None + end ImportTypeTest + + object Import extends ImportModule: + def apply(expr: Term, selectors: List[ImportSelector]): Import = + withDefaultPos(tpd.Import(expr, selectors)) + def copy(original: Tree)(expr: Term, selectors: List[ImportSelector]): Import = + tpd.cpy.Import(original)(expr, selectors) + def unapply(tree: Import): Option[(Term, List[ImportSelector])] = + Some((tree.expr, tree.selectors)) + end Import + + object ImportMethodsImpl extends ImportMethods: + extension (self: Import): + def expr: Term = self.expr + def selectors: List[ImportSelector] = self.selectors + end extension + end ImportMethodsImpl + + type Statement = tpd.Tree + + object StatementTypeTest extends TypeTest[Tree, Statement]: + def runtimeClass: Class[?] = classOf[Statement] + override def unapply(x: Any): Option[Statement] = x match + case _: tpd.PatternTree @unchecked => None + case tree: Tree @unchecked if tree.isTerm => TermTypeTest.unapply(tree) + case tree: Tree @unchecked => DefinitionTypeTest.unapply(tree) + case _ => None + end StatementTypeTest + + type Definition = tpd.Tree + + object DefinitionTypeTest extends TypeTest[Tree, Definition]: + def runtimeClass: Class[?] = classOf[Definition] + override def unapply(x: Any): Option[Definition] = x match + case x: tpd.MemberDef @unchecked => Some(x) + case x: PackageDefinition @unchecked => Some(x) + case _ => None + end DefinitionTypeTest + + object Definition extends DefinitionModule + + object DefinitionMethodsImpl extends DefinitionMethods: + extension (self: Definition): + def name: String = self match + case self: tpd.MemberDef => self.name.toString + case self: PackageDefinition => self.symbol.name.toString // TODO make PackageDefinition a MemberDef or NameTree + end extension + end DefinitionMethodsImpl + + type ClassDef = tpd.TypeDef + + object ClassDefTypeTest extends TypeTest[Tree, ClassDef]: + def runtimeClass: Class[?] = classOf[ClassDef] + override def unapply(x: Any): Option[ClassDef] = x match + case x: tpd.TypeDef @unchecked if x.isClassDef => Some(x) + case _ => None + end ClassDefTypeTest + + object ClassDef extends ClassDefModule: + def copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement]): ClassDef = { + val dotc.ast.Trees.TypeDef(_, originalImpl: tpd.Template) = original + tpd.cpy.TypeDef(original)(name.toTypeName, tpd.cpy.Template(originalImpl)(constr, parents, derived, selfOpt.getOrElse(tpd.EmptyValDef), body)) + } + def unapply(cdef: ClassDef): Option[(String, DefDef, List[Tree /* Term | TypeTree */], List[TypeTree], Option[ValDef], List[Statement])] = + val rhs = cdef.rhs.asInstanceOf[tpd.Template] + Some((cdef.name.toString, cdef.constructor, cdef.parents, rhs.derived.asInstanceOf[List[TypeTree]], cdef.self, rhs.body)) + end ClassDef + + object ClassDefMethodsImpl extends ClassDefMethods: + extension (self: ClassDef): + def constructor: DefDef = + self.rhs.asInstanceOf[tpd.Template].constr + def parents: List[Tree] = + self.rhs.asInstanceOf[tpd.Template].parents + def derived: List[TypeTree] = + self.rhs.asInstanceOf[tpd.Template].derived.asInstanceOf[List[TypeTree]] + def self: Option[ValDef] = + optional(self.rhs.asInstanceOf[tpd.Template].self) + def body: List[Statement] = + self.rhs.asInstanceOf[tpd.Template].body + end extension + end ClassDefMethodsImpl + + type DefDef = tpd.DefDef + + object DefDefTypeTest extends TypeTest[Tree, DefDef]: + def runtimeClass: Class[?] = classOf[DefDef] + override def unapply(x: Any): Option[DefDef] = x match + case x: tpd.DefDef @unchecked => Some(x) + case _ => None + end DefDefTypeTest + + object DefDef extends DefDefModule: + def apply(symbol: Symbol, rhsFn: List[Type] => List[List[Term]] => Option[Term]): DefDef = + withDefaultPos(tpd.polyDefDef(symbol.asTerm, tparams => vparamss => rhsFn(tparams)(vparamss).getOrElse(tpd.EmptyTree))) + def copy(original: Tree)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term]): DefDef = + tpd.cpy.DefDef(original)(name.toTermName, typeParams, paramss, tpt, rhs.getOrElse(tpd.EmptyTree)) + def unapply(ddef: DefDef): Option[(String, List[TypeDef], List[List[ValDef]], TypeTree, Option[Term])] = + Some((ddef.name.toString, ddef.typeParams, ddef.paramss, ddef.tpt, optional(ddef.rhs))) + end DefDef + + object DefDefMethodsImpl extends DefDefMethods: + extension (self: DefDef): + def typeParams: List[TypeDef] = self.tparams + def paramss: List[List[ValDef]] = self.vparamss + def returnTpt: TypeTree = self.tpt + def rhs: Option[Term] = optional(self.rhs) + end extension + end DefDefMethodsImpl + + type ValDef = tpd.ValDef + + object ValDefTypeTest extends TypeTest[Tree, ValDef]: + def runtimeClass: Class[?] = classOf[ValDef] + override def unapply(x: Any): Option[ValDef] = x match + case x: tpd.ValDef @unchecked => Some(x) + case _ => None + end ValDefTypeTest + + object ValDef extends ValDefModule: + def apply(symbol: Symbol, rhs: Option[Term]): ValDef = + tpd.ValDef(symbol.asTerm, rhs.getOrElse(tpd.EmptyTree)) + def copy(original: Tree)(name: String, tpt: TypeTree, rhs: Option[Term]): ValDef = + tpd.cpy.ValDef(original)(name.toTermName, tpt, rhs.getOrElse(tpd.EmptyTree)) + def unapply(vdef: ValDef): Option[(String, TypeTree, Option[Term])] = + Some((vdef.name.toString, vdef.tpt, optional(vdef.rhs))) + end ValDef + + object ValDefMethodsImpl extends ValDefMethods: + extension (self: ValDef): + def tpt: TypeTree = self.tpt + def rhs: Option[Term] = optional(self.rhs) + end extension + end ValDefMethodsImpl + + type TypeDef = tpd.TypeDef + + object TypeDefTypeTest extends TypeTest[Tree, TypeDef]: + def runtimeClass: Class[?] = classOf[TypeDef] + override def unapply(x: Any): Option[TypeDef] = x match + case x: tpd.TypeDef @unchecked if !x.isClassDef => Some(x) + case _ => None + end TypeDefTypeTest + + object TypeDef extends TypeDefModule: + def apply(symbol: Symbol): TypeDef = + withDefaultPos(tpd.TypeDef(symbol.asType)) + def copy(original: Tree)(name: String, rhs: Tree): TypeDef = + tpd.cpy.TypeDef(original)(name.toTypeName, rhs) + def unapply(tdef: TypeDef): Option[(String, Tree /*TypeTree | TypeBoundsTree*/ /* TypeTree | TypeBoundsTree */)] = + Some((tdef.name.toString, tdef.rhs)) + end TypeDef + + object TypeDefMethodsImpl extends TypeDefMethods: + extension (self: TypeDef): + def rhs: Tree = self.rhs + end extension + end TypeDefMethodsImpl + + type PackageDef = PackageDefinition + + object PackageDefTypeTest extends TypeTest[Tree, PackageDef]: + def runtimeClass: Class[?] = classOf[PackageDef] + override def unapply(x: Any): Option[PackageDef] = x match + case x: PackageDefinition @unchecked => Some(x) + case _ => None + end PackageDefTypeTest + + object PackageDef extends PackageDefModule: + def unapply(tree: PackageDef): Option[(String, PackageDef)] = + Some((tree.name, tree.owner)) + end PackageDef + + object PackageDefMethodsImpl extends PackageDefMethods: + extension (self: PackageDef): + def owner: PackageDef = packageDefFromSym(self.symbol.owner) + def members: List[Statement] = + if (self.symbol.is(JavaDefined)) Nil // FIXME should also support java packages + else self.symbol.info.decls.iterator.map(definitionFromSym).toList + end extension + end PackageDefMethodsImpl + + type Term = tpd.Tree + + object TermTypeTest extends TypeTest[Tree, Term]: + def runtimeClass: Class[?] = classOf[Term] + override def unapply(x: Any): Option[Term] = x match + case _ if UnapplyTypeTest.unapply(x).isDefined => None + case _: tpd.PatternTree @unchecked => None + case x: tpd.Tree @unchecked if x.isTerm => Some(x) + case x: tpd.SeqLiteral @unchecked => Some(x) + case x: tpd.Inlined @unchecked => Some(x) + case x: tpd.NamedArg @unchecked => Some(x) + case _ => None + end TermTypeTest + + object Term extends TermModule + + object TermMethodsImpl extends TermMethods: + extension (self: Term): + def seal: scala.quoted.Expr[Any] = + if self.isExpr then new scala.internal.quoted.Expr(self, compilerId) + else throw new Exception("Cannot seal a partially applied Term. Try eta-expanding the term first.") + + def sealOpt: Option[scala.quoted.Expr[Any]] = + if self.isExpr then Some(new scala.internal.quoted.Expr(self, compilerId)) + else None + + def tpe: Type = self.tpe + def underlyingArgument: Term = new tpd.TreeOps(self).underlyingArgument + def underlying: Term = new tpd.TreeOps(self).underlying + def etaExpand: Term = self.tpe.widen match { + case mtpe: Types.MethodType if !mtpe.isParamDependent => + val closureResType = mtpe.resType match { + case t: Types.MethodType @unchecked => t.toFunctionType() + case t => t + } + val closureTpe = Types.MethodType(mtpe.paramNames, mtpe.paramInfos, closureResType) + val closureMethod = dotc.core.Symbols.newSymbol(ctx.owner, nme.ANON_FUN, Synthetic | Method, closureTpe) + tpd.Closure(closureMethod, tss => new tpd.TreeOps(self).appliedToArgs(tss.head).etaExpand) + case _ => self + } + + def appliedTo(arg: Term): Term = + self.appliedToArgs(arg :: Nil) + def appliedTo(arg: Term, args: Term*): Term = + self.appliedToArgs(arg :: args.toList) + def appliedToArgs(args: List[Term]): Apply = + Apply(self, args) + def appliedToArgss(argss: List[List[Term]]): Term = + argss.foldLeft(self: Term)(Apply(_, _)) + def appliedToNone: Apply = + self.appliedToArgs(Nil) + def appliedToType(targ: Type): Term = + self.appliedToTypes(targ :: Nil) + def appliedToTypes(targs: List[Type]): Term = + self.appliedToTypeTrees(targs map (Inferred(_))) + def appliedToTypeTrees(targs: List[TypeTree]): Term = + if (targs.isEmpty) self else TypeApply(self, targs) + def select(sym: Symbol): Select = Select(self, sym) + + end extension + end TermMethodsImpl + + type Ref = tpd.RefTree + + object RefTypeTest extends TypeTest[Tree, Ref]: + def runtimeClass: Class[?] = classOf[Ref] + override def unapply(x: Any): Option[Ref] = x match + case x: tpd.RefTree @unchecked if x.isTerm => Some(x) + case _ => None + end RefTypeTest + + object Ref extends RefModule: + def term(tp: TermRef): Ref = + withDefaultPos(tpd.ref(tp).asInstanceOf[tpd.RefTree]) + def apply(sym: Symbol): Ref = + assert(sym.isTerm) + withDefaultPos(tpd.ref(sym).asInstanceOf[tpd.RefTree]) + end Ref + + type Ident = tpd.Ident + + object IdentTypeTest extends TypeTest[Tree, Ident]: + def runtimeClass: Class[?] = classOf[Ident] + override def unapply(x: Any): Option[Ident] = x match + case x: tpd.Ident @unchecked if x.isTerm => Some(x) + case _ => None + end IdentTypeTest + + object Ident extends IdentModule: + def apply(tmref: TermRef): Term = + withDefaultPos(tpd.ref(tmref).asInstanceOf[Term]) + def copy(original: Tree)(name: String): Ident = + tpd.cpy.Ident(original)(name.toTermName) + def unapply(tree: Ident): Option[String] = + Some(tree.name.toString) + end Ident + + object IdentMethodsImpl extends IdentMethods: + extension (self: Ident): + def name: String = self.name.toString + end extension + end IdentMethodsImpl + + type Select = tpd.Select + + object SelectTypeTest extends TypeTest[Tree, Select]: + def runtimeClass: Class[?] = classOf[Select] + override def unapply(x: Any): Option[Select] = x match + case x: tpd.Select @unchecked if x.isTerm => Some(x) + case _ => None + end SelectTypeTest + + object Select extends SelectModule: + def apply(qualifier: Term, symbol: Symbol): Select = + withDefaultPos(tpd.Select(qualifier, Types.TermRef(qualifier.tpe, symbol))) + def unique(qualifier: Term, name: String): Select = + val denot = qualifier.tpe.member(name.toTermName) + assert(!denot.isOverloaded, s"The symbol `$name` is overloaded. The method Select.unique can only be used for non-overloaded symbols.") + withDefaultPos(tpd.Select(qualifier, name.toTermName)) + def overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term]): Apply = + withDefaultPos(tpd.applyOverloaded(qualifier, name.toTermName, args, targs, Types.WildcardType).asInstanceOf[Apply]) + def copy(original: Tree)(qualifier: Term, name: String): Select = + tpd.cpy.Select(original)(qualifier, name.toTermName) + def unapply(x: Select): Option[(Term, String)] = + Some((x.qualifier, x.name.toString)) + end Select + + object SelectMethodsImpl extends SelectMethods: + extension (self: Select): + def qualifier: Term = self.qualifier + def name: String = self.name.toString + def signature: Option[Signature] = + if self.symbol.signature == dotc.core.Signature.NotAMethod then None + else Some(self.symbol.signature) + end extension + end SelectMethodsImpl + + type Literal = tpd.Literal + + object LiteralTypeTest extends TypeTest[Tree, Literal]: + def runtimeClass: Class[?] = classOf[Literal] + override def unapply(x: Any): Option[Literal] = x match + case x: tpd.Literal @unchecked => Some(x) + case _ => None + end LiteralTypeTest + + object Literal extends LiteralModule: + def apply(constant: Constant): Literal = + withDefaultPos(tpd.Literal(constant)) + def copy(original: Tree)(constant: Constant): Literal = + tpd.cpy.Literal(original)(constant) + def unapply(x: Literal): Option[Constant] = + Some(x.constant) + end Literal + + object LiteralMethodsImpl extends LiteralMethods: + extension (self: Literal): + def constant: Constant = self.const + end extension + end LiteralMethodsImpl + + type This = tpd.This + + object ThisTypeTest extends TypeTest[Tree, This]: + def runtimeClass: Class[?] = classOf[This] + override def unapply(x: Any): Option[This] = x match + case x: tpd.This @unchecked => Some(x) + case _ => None + end ThisTypeTest + + object This extends ThisModule: + def apply(cls: Symbol): This = + withDefaultPos(tpd.This(cls.asClass)) + def copy(original: Tree)(qual: Option[Id]): This = + tpd.cpy.This(original)(qual.getOrElse(untpd.EmptyTypeIdent)) + def unapply(x: This): Option[Option[Id]] = + Some(x.id) + end This + + object ThisMethodsImpl extends ThisMethods: + extension (self: This): + def id: Option[Id] = optional(self.qual) + end extension + end ThisMethodsImpl + + type New = tpd.New + + object NewTypeTest extends TypeTest[Tree, New]: + def runtimeClass: Class[?] = classOf[New] + override def unapply(x: Any): Option[New] = x match + case x: tpd.New @unchecked => Some(x) + case _ => None + end NewTypeTest + + object New extends NewModule: + def apply(tpt: TypeTree): New = + withDefaultPos(tpd.New(tpt)) + def copy(original: Tree)(tpt: TypeTree): New = + tpd.cpy.New(original)(tpt) + def unapply(x: New): Option[TypeTree] = Some(x.tpt) + end New + + object NewMethodsImpl extends NewMethods: + extension (self: New): + def tpt: TypeTree = self.tpt + end extension + end NewMethodsImpl + + type NamedArg = tpd.NamedArg + + object NamedArgTypeTest extends TypeTest[Tree, NamedArg]: + def runtimeClass: Class[?] = classOf[NamedArg] + override def unapply(x: Any): Option[NamedArg] = x match + case x: tpd.NamedArg @unchecked if x.name.isInstanceOf[dotc.core.Names.TermName] => Some(x) // TODO: Now, the name should alwas be a term name + case _ => None + end NamedArgTypeTest + + object NamedArg extends NamedArgModule: + def apply(name: String, arg: Term): NamedArg = + withDefaultPos(tpd.NamedArg(name.toTermName, arg)) + def copy(original: Tree)(name: String, arg: Term): NamedArg = + tpd.cpy.NamedArg(original)(name.toTermName, arg) + def unapply(x: NamedArg): Option[(String, Term)] = + Some((x.name.toString, x.value)) + end NamedArg + + object NamedArgMethodsImpl extends NamedArgMethods: + extension (self: NamedArg): + def name: String = self.name.toString + def value: Term = self.arg + end extension + end NamedArgMethodsImpl + + type Apply = tpd.Apply + + object ApplyTypeTest extends TypeTest[Tree, Apply]: + def runtimeClass: Class[?] = classOf[Apply] + override def unapply(x: Any): Option[Apply] = x match + case x: tpd.Apply @unchecked => Some(x) + case _ => None + end ApplyTypeTest + + object Apply extends ApplyModule: + def apply(fun: Term, args: List[Term]): Apply = + withDefaultPos(tpd.Apply(fun, args)) + def copy(original: Tree)(fun: Term, args: List[Term]): Apply = + tpd.cpy.Apply(original)(fun, args) + def unapply(x: Apply): Option[(Term, List[Term])] = + Some((x.fun, x.args)) + end Apply + + object ApplyMethodsImpl extends ApplyMethods: + extension (self: Apply): + def fun: Term = self.fun + def args: List[Term] = self.args + end extension + end ApplyMethodsImpl + + type TypeApply = tpd.TypeApply + + object TypeApplyTypeTest extends TypeTest[Tree, TypeApply]: + def runtimeClass: Class[?] = classOf[TypeApply] + override def unapply(x: Any): Option[TypeApply] = x match + case x: tpd.TypeApply @unchecked => Some(x) + case _ => None + end TypeApplyTypeTest + + object TypeApply extends TypeApplyModule: + def apply(fun: Term, args: List[TypeTree]): TypeApply = + withDefaultPos(tpd.TypeApply(fun, args)) + def copy(original: Tree)(fun: Term, args: List[TypeTree]): TypeApply = + tpd.cpy.TypeApply(original)(fun, args) + def unapply(x: TypeApply): Option[(Term, List[TypeTree])] = + Some((x.fun, x.args)) + end TypeApply + + object TypeApplyMethodsImpl extends TypeApplyMethods: + extension (self: TypeApply): + def fun: Term = self.fun + def args: List[TypeTree] = self.args + end extension + end TypeApplyMethodsImpl + + type Super = tpd.Super + + object SuperTypeTest extends TypeTest[Tree, Super]: + def runtimeClass: Class[?] = classOf[Super] + override def unapply(x: Any): Option[Super] = x match + case x: tpd.Super @unchecked => Some(x) + case _ => None + end SuperTypeTest + + object Super extends SuperModule: + def apply(qual: Term, mix: Option[Id]): Super = + withDefaultPos(tpd.Super(qual, mix.getOrElse(untpd.EmptyTypeIdent), dotc.core.Symbols.NoSymbol)) + def copy(original: Tree)(qual: Term, mix: Option[Id]): Super = + tpd.cpy.Super(original)(qual, mix.getOrElse(untpd.EmptyTypeIdent)) + def unapply(x: Super): Option[(Term, Option[Id])] = + Some((x.qualifier, x.id)) + end Super + + object SuperMethodsImpl extends SuperMethods: + extension (self: Super): + def qualifier: Term = self.qual + def id: Option[Id] = optional(self.mix) + end extension + end SuperMethodsImpl + + type Typed = tpd.Typed + + object TypedTypeTest extends TypeTest[Tree, Typed]: + def runtimeClass: Class[?] = classOf[Typed] + override def unapply(x: Any): Option[Typed] = x match + case x: tpd.Typed @unchecked => Some(x) + case _ => None + end TypedTypeTest + + object Typed extends TypedModule: + def apply(expr: Term, tpt: TypeTree): Typed = + withDefaultPos(tpd.Typed(expr, tpt)) + def copy(original: Tree)(expr: Term, tpt: TypeTree): Typed = + tpd.cpy.Typed(original)(expr, tpt) + def unapply(x: Typed): Option[(Term, TypeTree)] = + Some((x.expr, x.tpt)) + end Typed + + object TypedMethodsImpl extends TypedMethods: + extension (self: Typed): + def expr: Term = self.expr + def tpt: TypeTree = self.tpt + end extension + end TypedMethodsImpl + + type Assign = tpd.Assign + + object AssignTypeTest extends TypeTest[Tree, Assign]: + def runtimeClass: Class[?] = classOf[Assign] + override def unapply(x: Any): Option[Assign] = x match + case x: tpd.Assign @unchecked => Some(x) + case _ => None + end AssignTypeTest + + object Assign extends AssignModule: + def apply(lhs: Term, rhs: Term): Assign = + withDefaultPos(tpd.Assign(lhs, rhs)) + def copy(original: Tree)(lhs: Term, rhs: Term): Assign = + tpd.cpy.Assign(original)(lhs, rhs) + def unapply(x: Assign): Option[(Term, Term)] = + Some((x.lhs, x.rhs)) + end Assign + + object AssignMethodsImpl extends AssignMethods: + extension (self: Assign): + def lhs: Term = self.lhs + def rhs: Term = self.rhs + end extension + end AssignMethodsImpl + + type Block = tpd.Block + + val BlockTypeTest: TypeTest[Tree, Block] = new { + def runtimeClass: Class[?] = classOf[Block] + override def unapply(x: Any): Option[Block] = + x match + case x: tpd.Tree @unchecked => + normalizedLoops(x) match + case y: tpd.Block => Some(y) + case _ => None + case _ => None + + /** Normalizes non Blocks. + * i) Put `while` loops in their own blocks: `{ def while$() = ...; while$() }` + * ii) Put closures in their own blocks: `{ def anon$() = ...; closure(anon$, ...) }` + */ + private def normalizedLoops(tree: tpd.Tree): tpd.Tree = tree match { + case block: tpd.Block if block.stats.size > 1 => + def normalizeInnerLoops(stats: List[tpd.Tree]): List[tpd.Tree] = stats match { + case (x: tpd.DefDef) :: y :: xs if needsNormalization(y) => + tpd.Block(x :: Nil, y) :: normalizeInnerLoops(xs) + case x :: xs => x :: normalizeInnerLoops(xs) + case Nil => Nil + } + if (needsNormalization(block.expr)) { + val stats1 = normalizeInnerLoops(block.stats.init) + val normalLoop = tpd.Block(block.stats.last :: Nil, block.expr) + tpd.Block(stats1, normalLoop) + } + else { + val stats1 = normalizeInnerLoops(block.stats) + tpd.cpy.Block(block)(stats1, block.expr) + } + case _ => tree + } + + /** If it is the second statement of a closure. See: `normalizedLoops` */ + private def needsNormalization(tree: tpd.Tree): Boolean = tree match { + case _: tpd.Closure => true + case _ => false + } + } + + object Block extends BlockModule: + def apply(stats: List[Statement], expr: Term): Block = + withDefaultPos(tpd.Block(stats, expr)) + def copy(original: Tree)(stats: List[Statement], expr: Term): Block = + tpd.cpy.Block(original)(stats, expr) + def unapply(x: Block): Option[(List[Statement], Term)] = + Some((x.statements, x.expr)) + end Block + + object BlockMethodsImpl extends BlockMethods: + extension (self: Block): + def statements: List[Statement] = self.stats + def expr: Term = self.expr + end extension + end BlockMethodsImpl + + type Closure = tpd.Closure + + object ClosureTypeTest extends TypeTest[Tree, Closure]: + def runtimeClass: Class[?] = classOf[Closure] + override def unapply(x: Any): Option[Closure] = x match + case x: tpd.Closure @unchecked => Some(x) + case _ => None + end ClosureTypeTest + + object Closure extends ClosureModule: + def apply(meth: Term, tpe: Option[Type]): Closure = + withDefaultPos(tpd.Closure(Nil, meth, tpe.map(tpd.TypeTree(_)).getOrElse(tpd.EmptyTree))) + def copy(original: Tree)(meth: Tree, tpe: Option[Type]): Closure = + tpd.cpy.Closure(original)(Nil, meth, tpe.map(tpd.TypeTree(_)).getOrElse(tpd.EmptyTree)) + def unapply(x: Closure): Option[(Term, Option[Type])] = + Some((x.meth, x.tpeOpt)) + end Closure + + object ClosureMethodsImpl extends ClosureMethods: + extension (self: Closure): + def meth: Term = self.meth + def tpeOpt: Option[Type] = optional(self.tpt).map(_.tpe) + end extension + end ClosureMethodsImpl + + object Lambda extends LambdaModule: + def apply(tpe: MethodType, rhsFn: List[Tree] => Tree): Block = + tpd.Lambda(tpe, rhsFn) + def unapply(tree: Block): Option[(List[ValDef], Term)] = tree match { + case Block((ddef @ DefDef(_, _, params :: Nil, _, Some(body))) :: Nil, Closure(meth, _)) + if ddef.symbol == meth.symbol => + Some((params, body)) + case _ => None + } + end Lambda + + type If = tpd.If + + object IfTypeTest extends TypeTest[Tree, If]: + def runtimeClass: Class[?] = classOf[If] + override def unapply(x: Any): Option[If] = x match + case x: tpd.If @unchecked => Some(x) + case _ => None + end IfTypeTest + + object If extends IfModule: + def apply(cond: Term, thenp: Term, elsep: Term): If = + withDefaultPos(tpd.If(cond, thenp, elsep)) + def copy(original: Tree)(cond: Term, thenp: Term, elsep: Term): If = + tpd.cpy.If(original)(cond, thenp, elsep) + def unapply(tree: If): Option[(Term, Term, Term)] = + Some((tree.cond, tree.thenp, tree.elsep)) + end If + + object IfMethodsImpl extends IfMethods: + extension (self: If): + def cond: Term = self.cond + def thenp: Term = self.thenp + def elsep: Term = self.elsep + end extension + end IfMethodsImpl + + type Match = tpd.Match + + object MatchTypeTest extends TypeTest[Tree, Match]: + def runtimeClass: Class[?] = classOf[Match] + override def unapply(x: Any): Option[Match] = x match + case x: tpd.Match @unchecked if !x.selector.isEmpty => Some(x) + case _ => None + end MatchTypeTest + + object Match extends MatchModule: + def apply(selector: Term, cases: List[CaseDef]): Match = + withDefaultPos(tpd.Match(selector, cases)) + + def copy(original: Tree)(selector: Term, cases: List[CaseDef]): Match = + tpd.cpy.Match(original)(selector, cases) + + def unapply(x: Match): Option[(Term, List[CaseDef])] = + Some((x.scrutinee, x.cases)) + end Match + + object MatchMethodsImpl extends MatchMethods: + extension (self: Match): + def scrutinee: Term = self.selector + def cases: List[CaseDef] = self.cases + end extension + end MatchMethodsImpl + + type GivenMatch = tpd.Match + + object GivenMatchTypeTest extends TypeTest[Tree, GivenMatch]: + def runtimeClass: Class[?] = classOf[GivenMatch] + override def unapply(x: Any): Option[GivenMatch] = x match + case x: tpd.Match @unchecked if x.selector.isEmpty => Some(x) + case _ => None + end GivenMatchTypeTest + + object GivenMatch extends GivenMatchModule: + def apply(cases: List[CaseDef]): GivenMatch = + withDefaultPos(tpd.Match(tpd.EmptyTree, cases)) + def copy(original: Tree)(cases: List[CaseDef]): GivenMatch = + tpd.cpy.Match(original)(tpd.EmptyTree, cases) + def unapply(x: GivenMatch): Option[List[CaseDef]] = + Some(x.cases) + end GivenMatch + + object GivenMatchMethodsImpl extends GivenMatchMethods: + extension (self: GivenMatch): + def cases: List[CaseDef] = self.cases + end extension + end GivenMatchMethodsImpl + + type Try = tpd.Try + + object TryTypeTest extends TypeTest[Tree, Try]: + def runtimeClass: Class[?] = classOf[Try] + override def unapply(x: Any): Option[Try] = x match + case x: tpd.Try @unchecked => Some(x) + case _ => None + end TryTypeTest + + object Try extends TryModule: + def apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term]): Try = + withDefaultPos(tpd.Try(expr, cases, finalizer.getOrElse(tpd.EmptyTree))) + def copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term]): Try = + tpd.cpy.Try(original)(expr, cases, finalizer.getOrElse(tpd.EmptyTree)) + def unapply(x: Try): Option[(Term, List[CaseDef], Option[Term])] = + Some((x.body, x.cases, optional(x.finalizer))) + end Try + + object TryMethodsImpl extends TryMethods: + extension (self: Try): + def body: Term = self.expr + def cases: List[CaseDef] = self.cases + def finalizer: Option[Term] = optional(self.finalizer) + end extension + end TryMethodsImpl + + type Return = tpd.Return + + object ReturnTypeTest extends TypeTest[Tree, Return]: + def runtimeClass: Class[?] = classOf[Return] + override def unapply(x: Any): Option[Return] = x match + case x: tpd.Return @unchecked => Some(x) + case _ => None + end ReturnTypeTest + + object Return extends ReturnModule: + def apply(expr: Term): Return = + withDefaultPos(tpd.Return(expr, ctx.owner)) + def copy(original: Tree)(expr: Term): Return = + tpd.cpy.Return(original)(expr, tpd.ref(ctx.owner)) + def unapply(x: Return): Option[Term] = Some(x.expr) + end Return + + object ReturnMethodsImpl extends ReturnMethods: + extension (self: Return): + def expr: Term = self.expr + end extension + end ReturnMethodsImpl + + type Repeated = tpd.SeqLiteral + + object RepeatedTypeTest extends TypeTest[Tree, Repeated]: + def runtimeClass: Class[?] = classOf[Repeated] + override def unapply(x: Any): Option[Repeated] = x match + case x: tpd.SeqLiteral @unchecked => Some(x) + case _ => None + end RepeatedTypeTest + + object Repeated extends RepeatedModule: + def apply(elems: List[Term], elemtpt: TypeTree): Repeated = + withDefaultPos(tpd.SeqLiteral(elems, elemtpt)) + def copy(original: Tree)(elems: List[Term], elemtpt: TypeTree): Repeated = + tpd.cpy.SeqLiteral(original)(elems, elemtpt) + def unapply(x: Repeated): Option[(List[Term], TypeTree)] = + Some((x.elems, x.elemtpt)) + end Repeated + + object RepeatedMethodsImpl extends RepeatedMethods: + extension (self: Repeated): + def elems: List[Term] = self.elems + def elemtpt: TypeTree = self.elemtpt + end extension + end RepeatedMethodsImpl + + type Inlined = tpd.Inlined + + object InlinedTypeTest extends TypeTest[Tree, Inlined]: + def runtimeClass: Class[?] = classOf[Inlined] + override def unapply(x: Any): Option[Inlined] = x match + case x: tpd.Inlined @unchecked => Some(x) + case _ => None + end InlinedTypeTest + + object Inlined extends InlinedModule: + def apply(call: Option[Tree], bindings: List[Definition], expansion: Term): Inlined = + withDefaultPos(tpd.Inlined(call.getOrElse(tpd.EmptyTree), bindings.map { case b: tpd.MemberDef => b }, expansion)) + def copy(original: Tree)(call: Option[Tree], bindings: List[Definition], expansion: Term): Inlined = + tpd.cpy.Inlined(original)(call.getOrElse(tpd.EmptyTree), bindings.asInstanceOf[List[tpd.MemberDef]], expansion) + def unapply(x: Inlined): Option[(Option[Tree /* Term | TypeTree */], List[Definition], Term)] = + Some((optional(x.call), x.bindings, x.body)) + end Inlined + + object InlinedMethodsImpl extends InlinedMethods: + extension (self: Inlined): + def call: Option[Tree] = optional(self.call) + def bindings: List[Definition] = self.bindings + def body: Term = self.expansion + end extension + end InlinedMethodsImpl + + type SelectOuter = tpd.Select + + object SelectOuterTypeTest extends TypeTest[Tree, SelectOuter]: + def runtimeClass: Class[?] = classOf[SelectOuter] + override def unapply(x: Any): Option[SelectOuter] = x match + case x: tpd.Select @unchecked => + x.name match + case NameKinds.OuterSelectName(_, _) => Some(x) + case _ => None + case _ => None + end SelectOuterTypeTest + + object SelectOuter extends SelectOuterModule: + def apply(qualifier: Term, name: String, levels: Int): SelectOuter = + withDefaultPos(tpd.Select(qualifier, NameKinds.OuterSelectName(name.toTermName, levels))) + def copy(original: Tree)(qualifier: Term, name: String, levels: Int): SelectOuter = + tpd.cpy.Select(original)(qualifier, NameKinds.OuterSelectName(name.toTermName, levels)) + def unapply(x: SelectOuter): Option[(Term, Int, Type)] = // TODO homogenize order of parameters + Some((x.qualifier, x.level, x.tpe)) + end SelectOuter + + object SelectOuterMethodsImpl extends SelectOuterMethods: + extension (self: SelectOuter): + def qualifier: Term = self.qualifier + def level: Int = + val NameKinds.OuterSelectName(_, levels) = self.name + levels + end extension + end SelectOuterMethodsImpl + + type While = tpd.WhileDo + + object WhileTypeTest extends TypeTest[Tree, While]: + def runtimeClass: Class[?] = classOf[While] + override def unapply(x: Any): Option[While] = x match + case x: tpd.WhileDo @unchecked => Some(x) + case _ => None + end WhileTypeTest + + object While extends WhileModule: + def apply(cond: Term, body: Term): While = + withDefaultPos(tpd.WhileDo(cond, body)) + def copy(original: Tree)(cond: Term, body: Term): While = + tpd.cpy.WhileDo(original)(cond, body) + def unapply(x: While): Option[(Term, Term)] = + Some((x.cond, x.body)) + end While + + object WhileMethodsImpl extends WhileMethods: + extension (self: While): + def cond: Term = self.cond + def body: Term = self.body + end extension + end WhileMethodsImpl + + type TypeTree = tpd.Tree + + object TypeTreeTypeTest extends TypeTest[Tree, TypeTree]: + def runtimeClass: Class[?] = classOf[TypeTree] + override def unapply(x: Any): Option[TypeTree] = x match + case x: tpd.TypeBoundsTree @unchecked => None + case x: tpd.Tree @unchecked if x.isType => Some(x) + case _ => None + end TypeTreeTypeTest + + object TypeTree extends TypeTreeModule + + object TypeTreeMethodsImpl extends TypeTreeMethods: + extension (self: TypeTree): + def tpe: Type = self.tpe.stripTypeVar + end extension + end TypeTreeMethodsImpl + + type Inferred = tpd.TypeTree + + object InferredTypeTest extends TypeTest[Tree, Inferred]: + def runtimeClass: Class[?] = classOf[Inferred] + override def unapply(x: Any): Option[Inferred] = x match + case tpt: tpd.TypeTree @unchecked if !tpt.tpe.isInstanceOf[Types.TypeBounds] => Some(tpt) + case _ => None + end InferredTypeTest + + object Inferred extends InferredModule: + def apply(tpe: Type): Inferred = + withDefaultPos(tpd.TypeTree(tpe)) + def unapply(x: Inferred): Boolean = true + end Inferred + + type TypeIdent = tpd.Ident + + object TypeIdentTypeTest extends TypeTest[Tree, TypeIdent]: + def runtimeClass: Class[?] = classOf[TypeIdent] + override def unapply(x: Any): Option[TypeIdent] = x match + case tpt: tpd.Ident @unchecked if tpt.isType => Some(tpt) + case _ => None + end TypeIdentTypeTest + + object TypeIdent extends TypeIdentModule: + def apply(sym: Symbol): TypeTree = + assert(sym.isType) + withDefaultPos(tpd.ref(sym).asInstanceOf[tpd.TypeTree]) + def copy(original: Tree)(name: String): TypeIdent = + tpd.cpy.Ident(original)(name.toTypeName) + def unapply(x: TypeIdent): Option[String] = + Some(x.name.toString) + end TypeIdent + + object TypeIdentMethodsImpl extends TypeIdentMethods: + extension (self: TypeIdent): + def name: String = self.name.toString + end extension + end TypeIdentMethodsImpl + + type TypeSelect = tpd.Select + + object TypeSelectTypeTest extends TypeTest[Tree, TypeSelect]: + def runtimeClass: Class[?] = classOf[TypeSelect] + override def unapply(x: Any): Option[TypeSelect] = x match + case tpt: tpd.Select @unchecked if tpt.isType && tpt.qualifier.isTerm => Some(tpt) + case _ => None + end TypeSelectTypeTest + + object TypeSelect extends TypeSelectModule: + def apply(qualifier: Term, name: String): TypeSelect = + withDefaultPos(tpd.Select(qualifier, name.toTypeName)) + def copy(original: Tree)(qualifier: Term, name: String): TypeSelect = + tpd.cpy.Select(original)(qualifier, name.toTypeName) + def unapply(x: TypeSelect): Option[(Term, String)] = + Some((x.qualifier, x.name.toString)) + end TypeSelect + + object TypeSelectMethodsImpl extends TypeSelectMethods: + extension (self: TypeSelect): + def qualifier: Term = self.qualifier + def name: String = self.name.toString + end extension + end TypeSelectMethodsImpl + + type Projection = tpd.Select + + object ProjectionTypeTest extends TypeTest[Tree, Projection]: + def runtimeClass: Class[?] = classOf[Projection] + override def unapply(x: Any): Option[Projection] = x match + case tpt: tpd.Select @unchecked if tpt.isType && tpt.qualifier.isType => Some(tpt) + case _ => None + end ProjectionTypeTest + + object Projection extends ProjectionModule: + def copy(original: Tree)(qualifier: TypeTree, name: String): Projection = + tpd.cpy.Select(original)(qualifier, name.toTypeName) + def unapply(x: Projection): Option[(TypeTree, String)] = + Some((x.qualifier, x.name.toString)) + end Projection + + object ProjectionMethodsImpl extends ProjectionMethods: + extension (self: Projection): + def qualifier: TypeTree = self.qualifier + def name: String = self.name.toString + end extension + end ProjectionMethodsImpl + + type Singleton = tpd.SingletonTypeTree + + object SingletonTypeTest extends TypeTest[Tree, Singleton]: + def runtimeClass: Class[?] = classOf[Singleton] + override def unapply(x: Any): Option[Singleton] = x match + case tpt: tpd.SingletonTypeTree @unchecked => Some(tpt) + case _ => None + end SingletonTypeTest + + object Singleton extends SingletonModule: + def apply(ref: Term): Singleton = + withDefaultPos(tpd.SingletonTypeTree(ref)) + def copy(original: Tree)(ref: Term): Singleton = + tpd.cpy.SingletonTypeTree(original)(ref) + def unapply(x: Singleton): Option[Term] = + Some(x.ref) + end Singleton + + object SingletonMethodsImpl extends SingletonMethods: + extension (self: Singleton): + def ref: Term = self.ref + end extension + end SingletonMethodsImpl + + type Refined = tpd.RefinedTypeTree + + object RefinedTypeTest extends TypeTest[Tree, Refined]: + def runtimeClass: Class[?] = classOf[Refined] + override def unapply(x: Any): Option[Refined] = x match + case tpt: tpd.RefinedTypeTree @unchecked => Some(tpt) + case _ => None + end RefinedTypeTest + + object Refined extends RefinedModule: + def copy(original: Tree)(tpt: TypeTree, refinements: List[Definition]): Refined = + tpd.cpy.RefinedTypeTree(original)(tpt, refinements) + def unapply(x: Refined): Option[(TypeTree, List[Definition])] = + Some((x.tpt, x.refinements)) + end Refined + + object RefinedMethodsImpl extends RefinedMethods: + extension (self: Refined): + def tpt: TypeTree = self.tpt + def refinements: List[Definition] = self.refinements + end extension + end RefinedMethodsImpl + + type Applied = tpd.AppliedTypeTree + + object AppliedTypeTest extends TypeTest[Tree, Applied]: + def runtimeClass: Class[?] = classOf[Applied] + override def unapply(x: Any): Option[Applied] = x match + case tpt: tpd.AppliedTypeTree @unchecked => Some(tpt) + case _ => None + end AppliedTypeTest + + object Applied extends AppliedModule: + def apply(tpt: TypeTree, args: List[Tree]): Applied = + withDefaultPos(tpd.AppliedTypeTree(tpt, args)) + def copy(original: Tree)(tpt: TypeTree, args: List[Tree]): Applied = + tpd.cpy.AppliedTypeTree(original)(tpt, args) + def unapply(x: Applied): Option[(TypeTree, List[Tree /*TypeTree | TypeBoundsTree*/])] = + Some((x.tpt, x.args)) + end Applied + + object AppliedMethodsImpl extends AppliedMethods: + extension (self: Applied): + def tpt: TypeTree = self.tpt + def args: List[Tree] = self.args + end extension + end AppliedMethodsImpl + + type Annotated = tpd.Annotated + + object AnnotatedTypeTest extends TypeTest[Tree, Annotated]: + def runtimeClass: Class[?] = classOf[Annotated] + override def unapply(x: Any): Option[Annotated] = x match + case tpt: tpd.Annotated @unchecked => Some(tpt) + case _ => None + end AnnotatedTypeTest + + object Annotated extends AnnotatedModule: + def apply(arg: TypeTree, annotation: Term): Annotated = + withDefaultPos(tpd.Annotated(arg, annotation)) + def copy(original: Tree)(arg: TypeTree, annotation: Term): Annotated = + tpd.cpy.Annotated(original)(arg, annotation) + def unapply(x: Annotated): Option[(TypeTree, Term)] = + Some((x.arg, x.annotation)) + end Annotated + + object AnnotatedMethodsImpl extends AnnotatedMethods: + extension (self: Annotated): + def arg: TypeTree = self.arg + def annotation: Term = self.annot + end extension + end AnnotatedMethodsImpl + + type MatchTypeTree = tpd.MatchTypeTree + + object MatchTypeTreeTypeTest extends TypeTest[Tree, MatchTypeTree]: + def runtimeClass: Class[?] = classOf[MatchTypeTree] + override def unapply(x: Any): Option[MatchTypeTree] = x match + case tpt: tpd.MatchTypeTree @unchecked => Some(tpt) + case _ => None + end MatchTypeTreeTypeTest + + object MatchTypeTree extends MatchTypeTreeModule: + def apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef]): MatchTypeTree = + withDefaultPos(tpd.MatchTypeTree(bound.getOrElse(tpd.EmptyTree), selector, cases)) + def copy(original: Tree)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef]): MatchTypeTree = + tpd.cpy.MatchTypeTree(original)(bound.getOrElse(tpd.EmptyTree), selector, cases) + def unapply(x: MatchTypeTree): Option[(Option[TypeTree], TypeTree, List[TypeCaseDef])] = + Some((optional(x.bound), x.selector, x.cases)) + end MatchTypeTree + + object MatchTypeTreeMethodsImpl extends MatchTypeTreeMethods: + extension (self: MatchTypeTree): + def bound: Option[TypeTree] = optional(self.bound) + def selector: TypeTree = self.selector + def cases: List[TypeCaseDef] = self.cases + end extension + end MatchTypeTreeMethodsImpl + + type ByName = tpd.ByNameTypeTree + + object ByNameTypeTest extends TypeTest[Tree, ByName]: + def runtimeClass: Class[?] = classOf[ByName] + override def unapply(x: Any): Option[ByName] = x match + case tpt: tpd.ByNameTypeTree @unchecked => Some(tpt) + case _ => None + end ByNameTypeTest + + object ByName extends ByNameModule: + def apply(result: TypeTree): ByName = + withDefaultPos(tpd.ByNameTypeTree(result)) + def copy(original: Tree)(result: TypeTree): ByName = + tpd.cpy.ByNameTypeTree(original)(result) + def unapply(x: ByName): Option[TypeTree] = + Some(x.result) + end ByName + + object ByNameMethodsImpl extends ByNameMethods: + extension (self: ByName): + def result: TypeTree = self.result + end extension + end ByNameMethodsImpl + + type LambdaTypeTree = tpd.LambdaTypeTree + + object LambdaTypeTreeTypeTest extends TypeTest[Tree, LambdaTypeTree]: + def runtimeClass: Class[?] = classOf[LambdaTypeTree] + override def unapply(x: Any): Option[LambdaTypeTree] = x match + case tpt: tpd.LambdaTypeTree @unchecked => Some(tpt) + case _ => None + end LambdaTypeTreeTypeTest + + object LambdaTypeTree extends LambdaTypeTreeModule: + def apply(tparams: List[TypeDef], body: Tree): LambdaTypeTree = + withDefaultPos(tpd.LambdaTypeTree(tparams, body)) + def copy(original: Tree)(tparams: List[TypeDef], body: Tree): LambdaTypeTree = + tpd.cpy.LambdaTypeTree(original)(tparams, body) + def unapply(tree: LambdaTypeTree): Option[(List[TypeDef], Tree /*TypeTree | TypeBoundsTree*/)] = + Some((tree.tparams, tree.body)) + end LambdaTypeTree + + object LambdaTypeTreeMethodsImpl extends LambdaTypeTreeMethods: + extension (self: LambdaTypeTree): + def tparams: List[TypeDef] = self.tparams + def body: Tree = self.body + end extension + end LambdaTypeTreeMethodsImpl + + type TypeBind = tpd.Bind + + object TypeBindTypeTest extends TypeTest[Tree, TypeBind]: + def runtimeClass: Class[?] = classOf[TypeBind] + override def unapply(x: Any): Option[TypeBind] = x match + case tpt: tpd.Bind @unchecked if tpt.name.isTypeName => Some(tpt) + case _ => None + end TypeBindTypeTest + + object TypeBind extends TypeBindModule: + def copy(original: Tree)(name: String, tpt: Tree): TypeBind = + tpd.cpy.Bind(original)(name.toTypeName, tpt) + def unapply(x: TypeBind): Option[(String, Tree /*TypeTree | TypeBoundsTree*/)] = + Some((x.name.toString, x.body)) + end TypeBind + + object TypeBindMethodsImpl extends TypeBindMethods: + extension (self: TypeBind): + def name: String = self.name.toString + def body: Tree = self.body + end extension + end TypeBindMethodsImpl + + type TypeBlock = tpd.Block + + object TypeBlockTypeTest extends TypeTest[Tree, TypeBlock]: + def runtimeClass: Class[?] = classOf[TypeBlock] + override def unapply(x: Any): Option[TypeBlock] = x match + case tpt: tpd.Block @unchecked => Some(tpt) + case _ => None + end TypeBlockTypeTest + + object TypeBlock extends TypeBlockModule: + def apply(aliases: List[TypeDef], tpt: TypeTree): TypeBlock = + withDefaultPos(tpd.Block(aliases, tpt)) + def copy(original: Tree)(aliases: List[TypeDef], tpt: TypeTree): TypeBlock = + tpd.cpy.Block(original)(aliases, tpt) + def unapply(x: TypeBlock): Option[(List[TypeDef], TypeTree)] = + Some((x.aliases, x.tpt)) + end TypeBlock + + object TypeBlockMethodsImpl extends TypeBlockMethods: + extension (self: TypeBlock): + def aliases: List[TypeDef] = self.stats.map { case alias: TypeDef => alias } + def tpt: TypeTree = self.expr + end extension + end TypeBlockMethodsImpl + + type TypeBoundsTree = tpd.TypeBoundsTree + + object TypeBoundsTreeTypeTest extends TypeTest[Tree, TypeBoundsTree]: + def runtimeClass: Class[?] = classOf[TypeBoundsTree] + override def unapply(x: Any): Option[TypeBoundsTree] = x match + case x: tpd.TypeBoundsTree @unchecked => Some(x) + case x @ tpd.TypeTree() => + // TODO only enums generate this kind of type bounds. Is this possible without enums? If not generate tpd.TypeBoundsTree for enums instead + (x.tpe: Any) match { + case tpe: Types.TypeBounds => + Some(tpd.TypeBoundsTree(tpd.TypeTree(tpe.lo).withSpan(x.span), tpd.TypeTree(tpe.hi).withSpan(x.span))) + case _ => None + } + case _ => None + end TypeBoundsTreeTypeTest + + object TypeBoundsTree extends TypeBoundsTreeModule: + def unapply(x: TypeBoundsTree): Option[(TypeTree, TypeTree)] = + Some((x.low, x.hi)) + end TypeBoundsTree + + object TypeBoundsTreeMethodsImpl extends TypeBoundsTreeMethods: + extension (self: TypeBoundsTree): + def tpe: TypeBounds = self.tpe.asInstanceOf[Types.TypeBounds] + def low: TypeTree = self.lo + def hi: TypeTree = self.hi + end extension + end TypeBoundsTreeMethodsImpl + + type WildcardTypeTree = tpd.Ident + + object WildcardTypeTreeTypeTest extends TypeTest[Tree, WildcardTypeTree]: + def runtimeClass: Class[?] = classOf[WildcardTypeTree] + override def unapply(x: Any): Option[WildcardTypeTree] = x match + case x: tpd.Ident @unchecked if x.name == nme.WILDCARD => Some(x) + case _ => None + end WildcardTypeTreeTypeTest + + object WildcardTypeTree extends WildcardTypeTreeModule: + def unapply(x: WildcardTypeTree): Boolean = true + end WildcardTypeTree + + object WildcardTypeTreeMethodsImpl extends WildcardTypeTreeMethods: + extension (self: WildcardTypeTree): + def tpe: Type = self.tpe.stripTypeVar + end extension + end WildcardTypeTreeMethodsImpl + + type CaseDef = tpd.CaseDef + + object CaseDefTypeTest extends TypeTest[Tree, CaseDef]: + def runtimeClass: Class[?] = classOf[CaseDef] + override def unapply(x: Any): Option[CaseDef] = x match + case tree: tpd.CaseDef @unchecked if tree.body.isTerm => Some(tree) + case _ => None + end CaseDefTypeTest + + object CaseDef extends CaseDefModule: + def apply(pattern: Tree, guard: Option[Term], rhs: Term): CaseDef = + tpd.CaseDef(pattern, guard.getOrElse(tpd.EmptyTree), rhs) + def copy(original: Tree)(pattern: Tree, guard: Option[Term], rhs: Term): CaseDef = + tpd.cpy.CaseDef(original)(pattern, guard.getOrElse(tpd.EmptyTree), rhs) + def unapply(x: CaseDef): Option[(Tree, Option[Term], Term)] = + Some((x.pat, optional(x.guard), x.body)) + end CaseDef + + object CaseDefMethodsImpl extends CaseDefMethods: + extension (self: CaseDef): + def pattern: Tree = self.pat + def guard: Option[Term] = optional(self.guard) + def rhs: Term = self.body + end extension + end CaseDefMethodsImpl + + type TypeCaseDef = tpd.CaseDef + + object TypeCaseDefTypeTest extends TypeTest[Tree, TypeCaseDef]: + def runtimeClass: Class[?] = classOf[TypeCaseDef] + override def unapply(x: Any): Option[TypeCaseDef] = x match + case tree: tpd.CaseDef @unchecked if tree.body.isType => Some(tree) + case _ => None + end TypeCaseDefTypeTest + + object TypeCaseDef extends TypeCaseDefModule: + def apply(pattern: TypeTree, rhs: TypeTree): TypeCaseDef = + tpd.CaseDef(pattern, tpd.EmptyTree, rhs) + def copy(original: Tree)(pattern: TypeTree, rhs: TypeTree): TypeCaseDef = + tpd.cpy.CaseDef(original)(pattern, tpd.EmptyTree, rhs) + def unapply(tree: TypeCaseDef): Option[(TypeTree, TypeTree)] = + Some((tree.pat, tree.body)) + end TypeCaseDef + + object TypeCaseDefMethodsImpl extends TypeCaseDefMethods: + extension (self: TypeCaseDef): + def pattern: TypeTree = self.pat + def rhs: TypeTree = self.body + end extension + end TypeCaseDefMethodsImpl + + type Bind = tpd.Bind + + object BindTypeTest extends TypeTest[Tree, Bind]: + def runtimeClass: Class[?] = classOf[Bind] + override def unapply(x: Any): Option[Bind] = x match + case x: tpd.Bind @unchecked if x.name.isTermName => Some(x) + case _ => None + end BindTypeTest + + object Bind extends BindModule: + def apply(sym: Symbol, pattern: Tree): Bind = + tpd.Bind(sym, pattern) + def copy(original: Tree)(name: String, pattern: Tree): Bind = + withDefaultPos(tpd.cpy.Bind(original)(name.toTermName, pattern)) + def unapply(pattern: Bind): Option[(String, Tree)] = + Some((pattern.name.toString, pattern.pattern)) + end Bind + + object BindMethodsImpl extends BindMethods: + extension (self: Bind): + def name: String = self.name.toString + def pattern: Tree = self.body + end extension + end BindMethodsImpl + + type Unapply = tpd.UnApply + + object UnapplyTypeTest extends TypeTest[Tree, Unapply]: + def runtimeClass: Class[?] = classOf[Unapply] + override def unapply(x: Any): Option[Unapply] = x match + case pattern: tpd.UnApply @unchecked => Some(pattern) + case dotc.ast.Trees.Typed(pattern: tpd.UnApply @unchecked, _) => Some(pattern) + case _ => None + end UnapplyTypeTest + + object Unapply extends UnapplyModule: + def copy(original: Tree)(fun: Term, implicits: List[Term], patterns: List[Tree]): Unapply = + withDefaultPos(tpd.cpy.UnApply(original)(fun, implicits, patterns)) + def unapply(x: Unapply): Option[(Term, List[Term], List[Tree])] = + Some((x.fun, x.implicits, x.patterns)) + end Unapply + + object UnapplyMethodsImpl extends UnapplyMethods: + extension (self: Unapply): + def fun: Term = self.fun + def implicits: List[Term] = self.implicits + def patterns: List[Tree] = effectivePatterns(self.patterns) + end extension + private def effectivePatterns(patterns: List[Tree]): List[Tree] = + patterns match + case patterns0 :+ dotc.ast.Trees.SeqLiteral(elems, _) => patterns0 ::: elems + case _ => patterns + end UnapplyMethodsImpl + + type Alternatives = tpd.Alternative + + object AlternativesTypeTest extends TypeTest[Tree, Alternatives]: + def runtimeClass: Class[?] = classOf[Alternatives] + override def unapply(x: Any): Option[Alternatives] = x match + case x: tpd.Alternative @unchecked => Some(x) + case _ => None + end AlternativesTypeTest + + object Alternatives extends AlternativesModule: + def apply(patterns: List[Tree]): Alternatives = + withDefaultPos(tpd.Alternative(patterns)) + def copy(original: Tree)(patterns: List[Tree]): Alternatives = + tpd.cpy.Alternative(original)(patterns) + def unapply(x: Alternatives): Option[List[Tree]] = + Some(x.patterns) + end Alternatives + + object AlternativesMethodsImpl extends AlternativesMethods: + extension (self: Alternatives): + def patterns: List[Tree] = self.trees + end extension + end AlternativesMethodsImpl + + type ImportSelector = untpd.ImportSelector + + object ImportSelector extends ImportSelectorModule + + type SimpleSelector = untpd.ImportSelector + + object SimpleSelectorTypeTest extends TypeTest[ImportSelector, SimpleSelector]: + def runtimeClass: Class[?] = classOf[SimpleSelector] + override def unapply(x: Any): Option[SimpleSelector] = x match + case x: untpd.ImportSelector if x.renamed.isEmpty => Some(x) + case _ => None // TODO: handle import bounds + end SimpleSelectorTypeTest + + object SimpleSelector extends SimpleSelectorModule: + def unapply(x: SimpleSelector): Option[Id] = Some(x.selection) + end SimpleSelector + + + object SimpleSelectorMethodsImpl extends SimpleSelectorMethods: + extension (self: SimpleSelector): + def selection: Id = self.imported + end extension + end SimpleSelectorMethodsImpl + + type RenameSelector = untpd.ImportSelector + + object RenameSelectorTypeTest extends TypeTest[ImportSelector, RenameSelector]: + def runtimeClass: Class[?] = classOf[RenameSelector] + override def unapply(x: Any): Option[RenameSelector] = x match + case x: untpd.ImportSelector if !x.renamed.isEmpty => Some(x) + case _ => None + end RenameSelectorTypeTest + + object RenameSelector extends RenameSelectorModule: + def unapply(x: RenameSelector): Option[(Id, Id)] = Some((x.from, x.to)) + end RenameSelector + + object RenameSelectorMethodsImpl extends RenameSelectorMethods: + extension (self: RenameSelector): + def from: Id = self.imported + def to: Id = self.renamed.asInstanceOf[untpd.Ident] + end extension + end RenameSelectorMethodsImpl + + type OmitSelector = untpd.ImportSelector + + object OmitSelectorTypeTest extends TypeTest[ImportSelector, OmitSelector]: + def runtimeClass: Class[?] = classOf[OmitSelector] + override def unapply(x: Any): Option[OmitSelector] = x match { + case self: untpd.ImportSelector => + self.renamed match + case dotc.ast.Trees.Ident(nme.WILDCARD) => Some(self) + case _ => None + case _ => None + } + end OmitSelectorTypeTest + + object OmitSelector extends OmitSelectorModule: + def unapply(x: OmitSelector): Option[Id] = Some(x.omitted) + end OmitSelector + + object OmitSelectorMethodsImpl extends OmitSelectorMethods: + extension (self: OmitSelector): + def omitted: Id = self.imported + end extension + end OmitSelectorMethodsImpl + + type Type = dotc.core.Types.Type + + object Type extends TypeModule: + def of[T <: AnyKind](using qtype: scala.quoted.Type[T]): Type = + qtype.asInstanceOf[scala.internal.quoted.Type[TypeTree]].typeTree.tpe + def typeConstructorOf(clazz: Class[?]): Type = + if (clazz.isPrimitive) + if (clazz == classOf[Boolean]) dotc.core.Symbols.defn.BooleanType + else if (clazz == classOf[Byte]) dotc.core.Symbols.defn.ByteType + else if (clazz == classOf[Char]) dotc.core.Symbols.defn.CharType + else if (clazz == classOf[Short]) dotc.core.Symbols.defn.ShortType + else if (clazz == classOf[Int]) dotc.core.Symbols.defn.IntType + else if (clazz == classOf[Long]) dotc.core.Symbols.defn.LongType + else if (clazz == classOf[Float]) dotc.core.Symbols.defn.FloatType + else if (clazz == classOf[Double]) dotc.core.Symbols.defn.DoubleType + else dotc.core.Symbols.defn.UnitType + else if (clazz.isArray) + dotc.core.Symbols.defn.ArrayType.appliedTo(typeConstructorOf(clazz.getComponentType)) + else if clazz.isMemberClass then + val name = clazz.getSimpleName.toTypeName + val enclosing = typeConstructorOf(clazz.getEnclosingClass) + if (enclosing.member(name).exists) enclosing.select(name) + else enclosing.classSymbol.companionModule.termRef.select(name) + else + dotc.core.Symbols.getClassIfDefined(clazz.getCanonicalName).typeRef + end Type + + object TypeMethodsImpl extends TypeMethods: + extension (self: Type): + def showExtractors: String = + new ExtractorsPrinter[tasty.type](tasty).showType(self) + + def show: String = + self.showWith(SyntaxHighlight.plain) + + def showWith(syntaxHighlight: SyntaxHighlight): String = + new SourceCodePrinter[tasty.type](tasty)(syntaxHighlight).showType(self) + + def seal: scala.quoted.Type[_] = + new scala.internal.quoted.Type(Inferred(self), compilerId) + + def =:=(that: Type): Boolean = self =:= that + def <:<(that: Type): Boolean = self <:< that + def widen: Type = self.widen + def widenTermRefExpr: Type = self.widenTermRefExpr + def dealias: Type = self.dealias + def simplified: Type = self.simplified + def classSymbol: Option[Symbol] = + if self.classSymbol.exists then Some(self.classSymbol.asClass) + else None + def typeSymbol: Symbol = self.typeSymbol + def termSymbol: Symbol = self.termSymbol + def isSingleton: Boolean = self.isSingleton + def memberType(member: Symbol): Type = + member.info.asSeenFrom(self, member.owner) + def baseClasses: List[Symbol] = self.baseClasses + def baseType(cls: Symbol): Type = self.baseType(cls) + def derivesFrom(cls: Symbol): Boolean = self.derivesFrom(cls) + def isFunctionType: Boolean = + dotc.core.Symbols.defn.isFunctionType(self) + def isContextFunctionType: Boolean = + dotc.core.Symbols.defn.isContextFunctionType(self) + def isErasedFunctionType: Boolean = + dotc.core.Symbols.defn.isErasedFunctionType(self) + def isDependentFunctionType: Boolean = + val tpNoRefinement = self.dropDependentRefinement + tpNoRefinement != self + && dotc.core.Symbols.defn.isNonRefinedFunction(tpNoRefinement) + def select(sym: Symbol): Type = self.select(sym) + def appliedTo(targ: Type): Type = + dotc.core.Types.decorateTypeApplications(self).appliedTo(targ) + def appliedTo(targs: List[Type]): Type = + dotc.core.Types.decorateTypeApplications(self).appliedTo(targs) + end extension + end TypeMethodsImpl + + type ConstantType = dotc.core.Types.ConstantType + + object ConstantTypeTypeTest extends TypeTest[Type, ConstantType]: + def runtimeClass: Class[?] = classOf[ConstantType] + override def unapply(x: Any): Option[ConstantType] = x match + case tpe: Types.ConstantType => Some(tpe) + case _ => None + end ConstantTypeTypeTest + + object ConstantType extends ConstantTypeModule: + def apply(const: Constant): ConstantType = Types.ConstantType(const) + def unapply(x: ConstantType): Option[Constant] = Some(x.constant) + end ConstantType + + object ConstantTypeMethodsImpl extends ConstantTypeMethods: + extension (self: ConstantType) def constant: Constant = self.value + end ConstantTypeMethodsImpl + + type TermRef = dotc.core.Types.NamedType + + object TermRefTypeTest extends TypeTest[Type, TermRef]: + def runtimeClass: Class[?] = classOf[TermRef] + override def unapply(x: Any): Option[TermRef] = x match + case tp: Types.TermRef => Some(tp) + case _ => None + end TermRefTypeTest + + object TermRef extends TermRefModule: + def apply(qual: Type, name: String): TermRef = + Types.TermRef(qual, name.toTermName) + def unapply(x: TermRef): Option[(Type, String)] = + Some((x.prefix, x.name.toString)) + end TermRef + + object TermRefMethodsImpl extends TermRefMethods: + extension (self: TermRef): + def qualifier: Type = self.prefix + def name: String = self.name.toString + end extension + end TermRefMethodsImpl + + type TypeRef = dotc.core.Types.NamedType + + object TypeRefTypeTest extends TypeTest[Type, TypeRef]: + def runtimeClass: Class[?] = classOf[TypeRef] + override def unapply(x: Any): Option[TypeRef] = x match + case tp: Types.TypeRef => Some(tp) + case _ => None + end TypeRefTypeTest + + object TypeRef extends TypeRefModule: + def unapply(x: TypeRef): Option[(Type, String)] = + Some((x.prefix, x.name.toString)) + end TypeRef + + object TypeRefMethodsImpl extends TypeRefMethods: + extension (self: TypeRef): + def qualifier: Type = self.prefix + def name: String = self.name.toString + def isOpaqueAlias: Boolean = self.symbol.isOpaqueAlias + def translucentSuperType: Type = self.translucentSuperType + end extension + end TypeRefMethodsImpl + + type SuperType = dotc.core.Types.SuperType + + object SuperTypeTypeTest extends TypeTest[Type, SuperType]: + def runtimeClass: Class[?] = classOf[SuperType] + override def unapply(x: Any): Option[SuperType] = x match + case tpe: Types.SuperType => Some(tpe) + case _ => None + end SuperTypeTypeTest + + object SuperType extends SuperTypeModule: + def apply(thistpe: Type, supertpe: Type): SuperType = + Types.SuperType(thistpe, supertpe) + def unapply(x: SuperType): Option[(Type, Type)] = + Some((x.thistpe, x.supertpe)) + end SuperType + + object SuperTypeMethodsImpl extends SuperTypeMethods: + extension (self: SuperType): + def thistpe: Type = self.thistpe + def supertpe: Type = self.thistpe + end extension + end SuperTypeMethodsImpl + + type Refinement = dotc.core.Types.RefinedType + + object RefinementTypeTest extends TypeTest[Type, Refinement]: + def runtimeClass: Class[?] = classOf[Refinement] + override def unapply(x: Any): Option[Refinement] = x match + case tpe: Types.RefinedType => Some(tpe) + case _ => None + end RefinementTypeTest + + object Refinement extends RefinementModule: + def apply(parent: Type, name: String, info: Type): Refinement = + val name1 = + info match + case _: TypeBounds => name.toTypeName + case _ => name.toTermName + Types.RefinedType(parent, name1, info) + def unapply(x: Refinement): Option[(Type, String, Type)] = + Some((x.parent, x.name, x.info)) + end Refinement + + object RefinementMethodsImpl extends RefinementMethods: + extension (self: Refinement): + def parent: Type = self.parent + def name: String = self.refinedName.toString + def info: Type = self.refinedInfo + end extension + end RefinementMethodsImpl + + type AppliedType = dotc.core.Types.AppliedType + + object AppliedTypeTypeTest extends TypeTest[Type, AppliedType]: + def runtimeClass: Class[?] = classOf[AppliedType] + override def unapply(x: Any): Option[AppliedType] = x match + case tpe: Types.AppliedType => Some(tpe) + case _ => None + end AppliedTypeTypeTest + + object AppliedType extends AppliedTypeModule: + def unapply(x: AppliedType): Option[(Type, List[Type])] = + Some((x.tycon, x.args)) + end AppliedType + + object AppliedTypeMethodsImpl extends AppliedTypeMethods: + extension (self: AppliedType): + def tycon: Type = self.tycon + def args: List[Type] = self.args + end extension + end AppliedTypeMethodsImpl + + type AnnotatedType = dotc.core.Types.AnnotatedType + + object AnnotatedTypeTypeTest extends TypeTest[Type, AnnotatedType]: + def runtimeClass: Class[?] = classOf[AnnotatedType] + override def unapply(x: Any): Option[AnnotatedType] = x match + case tpe: Types.AnnotatedType => Some(tpe) + case _ => None + end AnnotatedTypeTypeTest + + object AnnotatedType extends AnnotatedTypeModule: + def apply(underlying: Type, annot: Term): AnnotatedType = + Types.AnnotatedType(underlying, Annotations.Annotation(annot)) + def unapply(x: AnnotatedType): Option[(Type, Term)] = + Some((x.underlying.stripTypeVar, x.annot.tree)) + end AnnotatedType + + object AnnotatedTypeMethodsImpl extends AnnotatedTypeMethods: + extension (self: AnnotatedType): + def underlying: Type = self.underlying.stripTypeVar + def annot: Term = self.annot.tree + end extension + end AnnotatedTypeMethodsImpl + + type AndType = dotc.core.Types.AndType + + object AndTypeTypeTest extends TypeTest[Type, AndType]: + def runtimeClass: Class[?] = classOf[AndType] + override def unapply(x: Any): Option[AndType] = x match + case tpe: Types.AndType => Some(tpe) + case _ => None + end AndTypeTypeTest + + object AndType extends AndTypeModule: + def apply(lhs: Type, rhs: Type): AndType = Types.AndType(lhs, rhs) + def unapply(x: AndType): Option[(Type, Type)] = Some((x.left, x.right)) + end AndType + + object AndTypeMethodsImpl extends AndTypeMethods: + extension (self: AndType): + def left: Type = self.tp1.stripTypeVar + def right: Type = self.tp2.stripTypeVar + end extension + end AndTypeMethodsImpl + + type OrType = dotc.core.Types.OrType + + object OrTypeTypeTest extends TypeTest[Type, OrType]: + def runtimeClass: Class[?] = classOf[OrType] + override def unapply(x: Any): Option[OrType] = x match + case tpe: Types.OrType => Some(tpe) + case _ => None + end OrTypeTypeTest + + object OrType extends OrTypeModule: + def apply(lhs: Type, rhs: Type): OrType = Types.OrType(lhs, rhs) + def unapply(x: OrType): Option[(Type, Type)] = Some((x.left, x.right)) + end OrType + + object OrTypeMethodsImpl extends OrTypeMethods: + extension (self: OrType): + def left: Type = self.tp1.stripTypeVar + def right: Type = self.tp2.stripTypeVar + end extension + end OrTypeMethodsImpl + + type MatchType = dotc.core.Types.MatchType + + object MatchTypeTypeTest extends TypeTest[Type, MatchType]: + def runtimeClass: Class[?] = classOf[MatchType] + override def unapply(x: Any): Option[MatchType] = x match + case tpe: Types.MatchType => Some(tpe) + case _ => None + end MatchTypeTypeTest + + object MatchType extends MatchTypeModule: + def apply(bound: Type, scrutinee: Type, cases: List[Type]): MatchType = + Types.MatchType(bound, scrutinee, cases) + def unapply(x: MatchType): Option[(Type, Type, List[Type])] = + Some((x.bound, x.scrutinee, x.cases)) + end MatchType + + object MatchTypeMethodsImpl extends MatchTypeMethods: + extension (self: MatchType): + def bound: Type = self.bound + def scrutinee: Type = self.scrutinee + def cases: List[Type] = self.cases + end extension + end MatchTypeMethodsImpl + + type ByNameType = dotc.core.Types.ExprType + + object ByNameTypeTypeTest extends TypeTest[Type, ByNameType]: + def runtimeClass: Class[?] = classOf[ByNameType] + override def unapply(x: Any): Option[ByNameType] = x match + case tpe: Types.ExprType => Some(tpe) + case _ => None + end ByNameTypeTypeTest + + object ByNameType extends ByNameTypeModule: + def apply(underlying: Type): Type = Types.ExprType(underlying) + def unapply(x: ByNameType): Option[Type] = Some(x.underlying) + end ByNameType + + object ByNameTypeMethodsImpl extends ByNameTypeMethods: + extension (self: ByNameType): + def underlying: Type = self.resType.stripTypeVar + end extension + end ByNameTypeMethodsImpl + + type ParamRef = dotc.core.Types.ParamRef + + object ParamRefTypeTest extends TypeTest[Type, ParamRef]: + def runtimeClass: Class[?] = classOf[ParamRef] + override def unapply(x: Any): Option[ParamRef] = x match + case tpe: Types.TypeParamRef => Some(tpe) + case tpe: Types.TermParamRef => Some(tpe) + case _ => None + end ParamRefTypeTest + + object ParamRef extends ParamRefModule: + def unapply(x: ParamRef): Option[(LambdaType, Int)] = + Some((x.binder, x.paramNum)) + end ParamRef + + object ParamRefMethodsImpl extends ParamRefMethods: + extension (self: ParamRef): + def binder: LambdaType = self.binder.asInstanceOf[LambdaType] // Cast to tpd + def paramNum: Int = self.paramNum + end extension + end ParamRefMethodsImpl + + type ThisType = dotc.core.Types.ThisType + + object ThisTypeTypeTest extends TypeTest[Type, ThisType]: + def runtimeClass: Class[?] = classOf[ThisType] + override def unapply(x: Any): Option[ThisType] = x match + case tpe: Types.ThisType => Some(tpe) + case _ => None + end ThisTypeTypeTest + + object ThisType extends ThisTypeModule: + def unapply(x: ThisType): Option[Type] = Some(x.tref) + end ThisType + + object ThisTypeMethodsImpl extends ThisTypeMethods: + extension (self: ThisType): + def tref: Type = self.tref + end extension + end ThisTypeMethodsImpl + + type RecursiveThis = dotc.core.Types.RecThis + + object RecursiveThisTypeTest extends TypeTest[Type, RecursiveThis]: + def runtimeClass: Class[?] = classOf[RecursiveThis] + override def unapply(x: Any): Option[RecursiveThis] = x match + case tpe: Types.RecThis => Some(tpe) + case _ => None + end RecursiveThisTypeTest + + object RecursiveThis extends RecursiveThisModule: + def unapply(x: RecursiveThis): Option[RecursiveType] = Some(x.binder) + end RecursiveThis + + + object RecursiveThisMethodsImpl extends RecursiveThisMethods: + extension (self: RecursiveThis): + def binder: RecursiveType = self.binder + end extension + end RecursiveThisMethodsImpl + + type RecursiveType = dotc.core.Types.RecType + + object RecursiveTypeTypeTest extends TypeTest[Type, RecursiveType]: + def runtimeClass: Class[?] = classOf[RecursiveType] + override def unapply(x: Any): Option[RecursiveType] = x match + case tpe: Types.RecType => Some(tpe) + case _ => None + end RecursiveTypeTypeTest + + object RecursiveType extends RecursiveTypeModule: + def apply(parentExp: RecursiveType => Type): RecursiveType = + Types.RecType(parentExp) + def unapply(x: RecursiveType): Option[Type] = Some(x.underlying) + end RecursiveType + + object RecursiveTypeMethodsImpl extends RecursiveTypeMethods: + extension (self: RecursiveType): + def underlying: Type = self.underlying.stripTypeVar + def recThis: RecursiveThis = self.recThis + end extension + end RecursiveTypeMethodsImpl + + type LambdaType = dotc.core.Types.LambdaType + + type MethodType = dotc.core.Types.MethodType + + object MethodTypeTypeTest extends TypeTest[Type, MethodType]: + def runtimeClass: Class[?] = classOf[MethodType] + override def unapply(x: Any): Option[MethodType] = x match + case tpe: Types.MethodType => Some(tpe) + case _ => None + end MethodTypeTypeTest + + object MethodType extends MethodTypeModule: + def apply(paramNames: List[String])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type): MethodType = + Types.MethodType(paramNames.map(_.toTermName))(paramInfosExp, resultTypeExp) + def unapply(x: MethodType): Option[(List[String], List[Type], Type)] = + Some((x.paramNames.map(_.toString), x.paramTypes, x.resType)) + end MethodType + + object MethodTypeMethodsImpl extends MethodTypeMethods: + extension (self: MethodType): + def isErased: Boolean = self.isErasedMethod + def isImplicit: Boolean = self.isImplicitMethod + def param(idx: Int): Type = self.newParamRef(idx) + def paramNames: List[String] = self.paramNames.map(_.toString) + def paramTypes: List[Type] = self.paramInfos + def resType: Type = self.resType + end extension + end MethodTypeMethodsImpl + + type PolyType = dotc.core.Types.PolyType + + object PolyTypeTypeTest extends TypeTest[Type, PolyType]: + def runtimeClass: Class[?] = classOf[PolyType] + override def unapply(x: Any): Option[PolyType] = x match + case tpe: Types.PolyType => Some(tpe) + case _ => None + end PolyTypeTypeTest + + object PolyType extends PolyTypeModule: + def apply(paramNames: List[String])(paramBoundsExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type): PolyType = + Types.PolyType(paramNames.map(_.toTypeName))(paramBoundsExp, resultTypeExp) + def unapply(x: PolyType): Option[(List[String], List[TypeBounds], Type)] = + Some((x.paramNames.map(_.toString), x.paramBounds, x.resType)) + end PolyType + + object PolyTypeMethodsImpl extends PolyTypeMethods: + extension (self: PolyType): + def param(idx: Int): Type = self.newParamRef(idx) + def paramNames: List[String] = self.paramNames.map(_.toString) + def paramBounds: List[TypeBounds] = self.paramInfos + def resType: Type = self.resType + end extension + end PolyTypeMethodsImpl + + type TypeLambda = dotc.core.Types.TypeLambda + + object TypeLambdaTypeTest extends TypeTest[Type, TypeLambda]: + def runtimeClass: Class[?] = classOf[TypeLambda] + override def unapply(x: Any): Option[TypeLambda] = x match + case tpe: Types.TypeLambda => Some(tpe) + case _ => None + end TypeLambdaTypeTest + + object TypeLambda extends TypeLambdaModule: + def apply(paramNames: List[String], boundsFn: TypeLambda => List[TypeBounds], bodyFn: TypeLambda => Type): TypeLambda = + Types.HKTypeLambda(paramNames.map(_.toTypeName))(boundsFn, bodyFn) + def unapply(x: TypeLambda): Option[(List[String], List[TypeBounds], Type)] = + Some((x.paramNames.map(_.toString), x.paramBounds, x.resType)) + end TypeLambda + + object TypeLambdaMethodsImpl extends TypeLambdaMethods: + extension (self: TypeLambda): + def paramNames: List[String] = self.paramNames.map(_.toString) + def paramBounds: List[TypeBounds] = self.paramInfos + def param(idx: Int): Type = self.newParamRef(idx) + def resType: Type = self.resType + end extension + end TypeLambdaMethodsImpl + + type TypeBounds = dotc.core.Types.TypeBounds + + object TypeBoundsTypeTest extends TypeTest[Type, TypeBounds]: + def runtimeClass: Class[?] = classOf[TypeBounds] + override def unapply(x: Any): Option[TypeBounds] = x match + case x: Types.TypeBounds => Some(x) + case _ => None + end TypeBoundsTypeTest + + object TypeBounds extends TypeBoundsModule: + def apply(low: Type, hi: Type): TypeBounds = Types.TypeBounds(low, hi) + def unapply(x: TypeBounds): Option[(Type, Type)] = Some((x.low, x.hi)) + end TypeBounds + + object TypeBoundsMethodsImpl extends TypeBoundsMethods: + extension (self: TypeBounds): + def low: Type = self.lo + def hi: Type = self.hi + end extension + end TypeBoundsMethodsImpl + + type NoPrefix = dotc.core.Types.NoPrefix.type + + object NoPrefixTypeTest extends TypeTest[Type, NoPrefix]: + def runtimeClass: Class[?] = classOf[Types.NoPrefix.type] + override def unapply(x: Any): Option[NoPrefix] = + if (x == Types.NoPrefix) Some(Types.NoPrefix) else None + end NoPrefixTypeTest + + object NoPrefix extends NoPrefixModule: + def unapply(x: NoPrefix): Boolean = true + end NoPrefix + + type Constant = dotc.core.Constants.Constant + + object Constant extends ConstantModule: + def apply(x: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type): Constant = + dotc.core.Constants.Constant(x) + def unapply(constant: Constant): Option[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type] = + Some(constant.value.asInstanceOf[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type]) + object ClassTag extends ClassTagModule: + def apply[T](using x: Type): Constant = dotc.core.Constants.Constant(x) + def unapply(constant: Constant): Option[Type] = + if constant.tag == dotc.core.Constants.ClazzTag then Some(constant.typeValue) + else None + end ClassTag + end Constant + + object ConstantMethodsImpl extends ConstantMethods: + extension (self: Constant): + def value: Any = self.value + def showExtractors: String = + new ExtractorsPrinter[tasty.type](tasty).showConstant(self) + def show: String = + self.showWith(SyntaxHighlight.plain) + def showWith(syntaxHighlight: SyntaxHighlight): String = + new SourceCodePrinter[tasty.type](tasty)(syntaxHighlight).showConstant(self) + end extension + end ConstantMethodsImpl + + type Id = untpd.Ident + + object Id extends IdModule: + def unapply(id: Id): Option[String] = Some(id.name.toString) + end Id + + object IdMethodsImpl extends IdMethods: + extension (self: Id): + def pos: Position = self.sourcePos + def name: String = self.name.toString + end extension + end IdMethodsImpl + + type ImplicitSearchResult = Tree + + def searchImplicit(tpe: Type): ImplicitSearchResult = + ctx.typer.inferImplicitArg(tpe, rootPosition.span) + + type ImplicitSearchSuccess = Tree + + object ImplicitSearchSuccessTypeTest extends TypeTest[ImplicitSearchResult, ImplicitSearchSuccess]: + def runtimeClass: Class[?] = classOf[ImplicitSearchSuccess] + override def unapply(x: Any): Option[ImplicitSearchSuccess] = x match + case x: Tree @unchecked => + x.tpe match + case _: Implicits.SearchFailureType => None + case _ => Some(x) + case _ => None + end ImplicitSearchSuccessTypeTest + + object ImplicitSearchSuccessMethodsImpl extends ImplicitSearchSuccessMethods: + extension (self: ImplicitSearchSuccess): + def tree: Term = self + end extension + end ImplicitSearchSuccessMethodsImpl + + type ImplicitSearchFailure = Tree + + object ImplicitSearchFailureTypeTest extends TypeTest[ImplicitSearchResult, ImplicitSearchFailure]: + def runtimeClass: Class[?] = classOf[ImplicitSearchFailure] + override def unapply(x: Any): Option[ImplicitSearchFailure] = x match + case x: Tree @unchecked => + x.tpe match + case _: Implicits.SearchFailureType => Some(x) + case _ => None + case _ => None + end ImplicitSearchFailureTypeTest + + object ImplicitSearchFailureMethodsImpl extends ImplicitSearchFailureMethods: + extension (self: ImplicitSearchFailure): + def explanation: String = + self.tpe.asInstanceOf[Implicits.SearchFailureType].explanation + end extension + end ImplicitSearchFailureMethodsImpl + + type DivergingImplicit = Tree + + object DivergingImplicitTypeTest extends TypeTest[ImplicitSearchResult, DivergingImplicit]: + def runtimeClass: Class[?] = classOf[DivergingImplicit] + override def unapply(x: Any): Option[DivergingImplicit] = x match + case x: Tree @unchecked => + x.tpe match + case _: Implicits.DivergingImplicit => Some(x) + case _ => None + case _ => None + end DivergingImplicitTypeTest + + type NoMatchingImplicits = Tree + + object NoMatchingImplicitsTypeTest extends TypeTest[ImplicitSearchResult, NoMatchingImplicits]: + def runtimeClass: Class[?] = classOf[NoMatchingImplicits] + override def unapply(x: Any): Option[NoMatchingImplicits] = x match + case x: Tree @unchecked => + x.tpe match + case _: Implicits.NoMatchingImplicits => Some(x) + case _ => None + case _ => None + end NoMatchingImplicitsTypeTest + + type AmbiguousImplicits = Tree + + object AmbiguousImplicitsTypeTest extends TypeTest[ImplicitSearchResult, AmbiguousImplicits]: + def runtimeClass: Class[?] = classOf[AmbiguousImplicits] + override def unapply(x: Any): Option[AmbiguousImplicits] = x match + case x: Tree @unchecked => + x.tpe match + case _: Implicits.AmbiguousImplicits => Some(x) + case _ => None + case _ => None + end AmbiguousImplicitsTypeTest + + type Symbol = dotc.core.Symbols.Symbol + + object Symbol extends SymbolModule: + def currentOwner(using ctx: Context): Symbol = ctx.owner + def requiredPackage(path: String): Symbol = dotc.core.Symbols.requiredPackage(path) + def requiredClass(path: String): Symbol = dotc.core.Symbols.requiredClass(path) + def requiredModule(path: String): Symbol = dotc.core.Symbols.requiredModule(path) + def requiredMethod(path: String): Symbol = dotc.core.Symbols.requiredMethod(path) + def classSymbol(fullName: String): Symbol = dotc.core.Symbols.requiredClass(fullName) + def newMethod(parent: Symbol, name: String, tpe: Type): Symbol = + newMethod(parent, name, tpe, Flags.EmptyFlags, noSymbol) + def newMethod(parent: Symbol, name: String, tpe: Type, flags: Flags, privateWithin: Symbol): Symbol = + dotc.core.Symbols.newSymbol(parent, name.toTermName, flags | dotc.core.Flags.Method, tpe, privateWithin) + def newVal(parent: Symbol, name: String, tpe: Type, flags: Flags, privateWithin: Symbol): Symbol = + dotc.core.Symbols.newSymbol(parent, name.toTermName, flags, tpe, privateWithin) + def newBind(parent: Symbol, name: String, flags: Flags, tpe: Type): Symbol = + dotc.core.Symbols.newSymbol(parent, name.toTermName, flags | Case, tpe) + def noSymbol: Symbol = dotc.core.Symbols.NoSymbol + end Symbol + + object SymbolMethodsImpl extends SymbolMethods: + extension (self: Symbol): + def owner: Symbol = self.denot.owner + def maybeOwner: Symbol = self.denot.maybeOwner + def flags: Flags = self.denot.flags + + def privateWithin: Option[Type] = + val within: Symbol = + self.denot.privateWithin + if (within.exists && !self.is(dotc.core.Flags.Protected)) Some(within.typeRef) + else None + + def protectedWithin: Option[Type] = + val within: Symbol = + self.denot.privateWithin + if (within.exists && self.is(dotc.core.Flags.Protected)) Some(within.typeRef) + else None + + def name: String = self.denot.name.toString + def fullName: String = self.denot.fullName.toString + def pos: Position = self.sourcePos + + def localContext: Context = + if self.exists then ctx.withOwner(self) else ctx + def comment: Option[Comment] = + import dotc.core.Comments.CommentsContext + val docCtx = ctx.docCtx.getOrElse { + throw new RuntimeException( + "DocCtx could not be found and comments are unavailable. This is a compiler-internal error." + ) + } + docCtx.docstring(self) + + def tree: Tree = FromSymbol.definitionFromSym(self) + + def annots: List[Term] = + self.annotations.flatMap { + case _: dotc.core.Annotations.BodyAnnotation => Nil + case annot => annot.tree :: Nil + } + + def isDefinedInCurrentRun: Boolean = + self.topLevelClass.asClass.isDefinedInCurrentRun + def isLocalDummy: Boolean = self.denot.isLocalDummy + def isRefinementClass: Boolean = self.denot.isRefinementClass + def isAliasType: Boolean = self.denot.isAliasType + def isAnonymousClass: Boolean = self.denot.isAnonymousClass + def isAnonymousFunction: Boolean = self.denot.isAnonymousFunction + def isAbstractType: Boolean = self.denot.isAbstractType + def isClassConstructor: Boolean = self.denot.isClassConstructor + def isType: Boolean = self.isType + def isTerm: Boolean = self.isTerm + def isPackageDef: Boolean = self.is(dotc.core.Flags.Package) + def isClassDef: Boolean = self.isClass + def isTypeDef: Boolean = + self.isType && !self.isClass && !self.is(dotc.core.Flags.Case) + def isValDef: Boolean = + self.isTerm && !self.is(dotc.core.Flags.Method) && !self.is(dotc.core.Flags.Case/*, FIXME add this check and fix sourcecode butNot = Enum | Module*/) + def isDefDef: Boolean = self.is(dotc.core.Flags.Method) + def isBind: Boolean = + self.is(dotc.core.Flags.Case, butNot = Enum | Module) && !self.isClass + def isNoSymbol: Boolean = self == Symbol.noSymbol + def exists: Boolean = self != Symbol.noSymbol + def fields: List[Symbol] = self.unforcedDecls.filter(isField) + + def field(name: String): Symbol = + val sym = self.unforcedDecls.find(sym => sym.name == name.toTermName) + if (isField(sym)) sym else dotc.core.Symbols.NoSymbol + + def classMethod(name: String): List[Symbol] = + self.typeRef.decls.iterator.collect { + case sym if isMethod(sym) && sym.name.toString == name => sym.asTerm + }.toList + + def classMethods: List[Symbol] = + self.typeRef.decls.iterator.collect { + case sym if isMethod(sym) => sym.asTerm + }.toList + + def typeMembers: List[Symbol] = + self.unforcedDecls.filter(_.isType) + + def typeMember(name: String): Symbol = + self.unforcedDecls.find(sym => sym.name == name.toTypeName) + + def method(name: String): List[Symbol] = + appliedTypeRef(self).allMembers.iterator.map(_.symbol).collect { + case sym if isMethod(sym) && sym.name.toString == name => sym.asTerm + }.toList + + def methods: List[Symbol] = + appliedTypeRef(self).allMembers.iterator.map(_.symbol).collect { + case sym if isMethod(sym) => sym.asTerm + }.toList + + def paramSymss: List[List[Symbol]] = self.denot.paramSymss + def primaryConstructor: Symbol = self.denot.primaryConstructor + + def caseFields: List[Symbol] = + if !self.isClass then Nil + else self.asClass.paramAccessors.collect { + case sym if sym.is(dotc.core.Flags.CaseAccessor) => sym.asTerm + } + + def isTypeParam: Boolean = self.isTypeParam + def signature: Signature = self.signature + def moduleClass: Symbol = self.denot.moduleClass + def companionClass: Symbol = self.denot.companionClass + def companionModule: Symbol = self.denot.companionModule + def children: List[Symbol] = self.denot.children + + def showExtractors: String = + new ExtractorsPrinter[tasty.type](tasty).showSymbol(self) + def show: String = + self.showWith(SyntaxHighlight.plain) + def showWith(syntaxHighlight: SyntaxHighlight): String = + new SourceCodePrinter[tasty.type](tasty)(syntaxHighlight).showSymbol(self) + + end extension + + private def appliedTypeRef(sym: Symbol): Type = + sym.typeRef.appliedTo(sym.typeParams.map(_.typeRef)) + + private def isMethod(sym: Symbol): Boolean = + sym.isTerm && sym.is(dotc.core.Flags.Method) && !sym.isConstructor + + private def isField(sym: Symbol): Boolean = + sym.isTerm && !sym.is(dotc.core.Flags.Method) + end SymbolMethodsImpl + + type Signature = dotc.core.Signature + + object Signature extends SignatureModule: + def unapply(sig: Signature): Option[(List[String | Int], String)] = + Some((sig.paramSigs, sig.resultSig)) + end Signature + + object SignatureMethodsImpl extends SignatureMethods: + extension (self: Signature): + def paramSigs: List[String | Int] = + self.paramsSig.map { + case paramSig: dotc.core.Names.TypeName => + paramSig.toString + case paramSig: Int => + paramSig + } + def resultSig: String = + self.resSig.toString + end extension + end SignatureMethodsImpl + + object defn extends DefnModule: + def RootPackage: Symbol = dotc.core.Symbols.defn.RootPackage + def RootClass: Symbol = dotc.core.Symbols.defn.RootClass + def EmptyPackageClass: Symbol = dotc.core.Symbols.defn.EmptyPackageClass + def ScalaPackage: Symbol = dotc.core.Symbols.defn.ScalaPackageVal + def ScalaPackageClass: Symbol = dotc.core.Symbols.defn.ScalaPackageClass + def AnyClass: Symbol = dotc.core.Symbols.defn.AnyClass + def AnyValClass: Symbol = dotc.core.Symbols.defn.AnyValClass + def ObjectClass: Symbol = dotc.core.Symbols.defn.ObjectClass + def AnyRefClass: Symbol = dotc.core.Symbols.defn.AnyRefAlias + def NullClass: Symbol = dotc.core.Symbols.defn.NullClass + def NothingClass: Symbol = dotc.core.Symbols.defn.NothingClass + def UnitClass: Symbol = dotc.core.Symbols.defn.UnitClass + def ByteClass: Symbol = dotc.core.Symbols.defn.ByteClass + def ShortClass: Symbol = dotc.core.Symbols.defn.ShortClass + def CharClass: Symbol = dotc.core.Symbols.defn.CharClass + def IntClass: Symbol = dotc.core.Symbols.defn.IntClass + def LongClass: Symbol = dotc.core.Symbols.defn.LongClass + def FloatClass: Symbol = dotc.core.Symbols.defn.FloatClass + def DoubleClass: Symbol = dotc.core.Symbols.defn.DoubleClass + def BooleanClass: Symbol = dotc.core.Symbols.defn.BooleanClass + def StringClass: Symbol = dotc.core.Symbols.defn.StringClass + def ClassClass: Symbol = dotc.core.Symbols.defn.ClassClass + def ArrayClass: Symbol = dotc.core.Symbols.defn.ArrayClass + def PredefModule: Symbol = dotc.core.Symbols.defn.ScalaPredefModule + def Predef_classOf: Symbol = dotc.core.Symbols.defn.Predef_classOf + def JavaLangPackage: Symbol = dotc.core.Symbols.defn.JavaLangPackageVal + def ArrayModule: Symbol = dotc.core.Symbols.defn.ArrayModule + def Array_apply: Symbol = dotc.core.Symbols.defn.Array_apply + def Array_clone: Symbol = dotc.core.Symbols.defn.Array_clone + def Array_length: Symbol = dotc.core.Symbols.defn.Array_length + def Array_update: Symbol = dotc.core.Symbols.defn.Array_update + def RepeatedParamClass: Symbol = dotc.core.Symbols.defn.RepeatedParamClass + def RepeatedAnnot: Symbol = dotc.core.Symbols.defn.RepeatedAnnot + def OptionClass: Symbol = dotc.core.Symbols.defn.OptionClass + def NoneModule: Symbol = dotc.core.Symbols.defn.NoneModule + def SomeModule: Symbol = dotc.core.Symbols.defn.SomeClass.companionModule + def ProductClass: Symbol = dotc.core.Symbols.defn.ProductClass + def FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol = + dotc.core.Symbols.defn.FunctionClass(arity, isImplicit, isErased) + def TupleClass(arity: Int): Symbol = + dotc.core.Symbols.defn.TupleType(arity).classSymbol.asClass + def isTupleClass(sym: Symbol): Boolean = + dotc.core.Symbols.defn.isTupleClass(sym) + def ScalaPrimitiveValueClasses: List[Symbol] = + UnitClass :: BooleanClass :: ScalaNumericValueClasses + def ScalaNumericValueClasses: List[Symbol] = + ByteClass :: ShortClass :: IntClass :: LongClass :: FloatClass :: DoubleClass :: CharClass :: Nil + end defn + + type Flags = dotc.core.Flags.FlagSet + + object Flags extends FlagsModule: + def Abstract: Flags = dotc.core.Flags.Abstract + def Artifact: Flags = dotc.core.Flags.Artifact + def Case: Flags = dotc.core.Flags.Case + def CaseAccessor: Flags = dotc.core.Flags.CaseAccessor + def Contravariant: Flags = dotc.core.Flags.Contravariant + def Covariant: Flags = dotc.core.Flags.Covariant + def EmptyFlags = dotc.core.Flags.EmptyFlags + def Enum: Flags = dotc.core.Flags.Enum + def Erased: Flags = dotc.core.Flags.Erased + def ExtensionMethod: Flags = dotc.core.Flags.ExtensionMethod + def FieldAccessor: Flags = dotc.core.Flags.Accessor + def Final: Flags = dotc.core.Flags.Final + def Given: Flags = dotc.core.Flags.Given + def HasDefault: Flags = dotc.core.Flags.HasDefault + def Implicit: Flags = dotc.core.Flags.Implicit + def Inline: Flags = dotc.core.Flags.Inline + def JavaDefined: Flags = dotc.core.Flags.JavaDefined + def Lazy: Flags = dotc.core.Flags.Lazy + def Local: Flags = dotc.core.Flags.Local + def Macro: Flags = dotc.core.Flags.Macro + def ModuleClass: Flags = dotc.core.Flags.ModuleClass + def Mutable: Flags = dotc.core.Flags.Mutable + def Object: Flags = dotc.core.Flags.Module + def Override: Flags = dotc.core.Flags.Override + def Package: Flags = dotc.core.Flags.Package + def Param: Flags = dotc.core.Flags.Param + def ParamAccessor: Flags = dotc.core.Flags.ParamAccessor + def Private: Flags = dotc.core.Flags.Private + def PrivateLocal: Flags = dotc.core.Flags.PrivateLocal + def Protected: Flags = dotc.core.Flags.Protected + def Scala2x: Flags = dotc.core.Flags.Scala2x + def Sealed: Flags = dotc.core.Flags.Sealed + def StableRealizable: Flags = dotc.core.Flags.StableRealizable + def Static: Flags = dotc.core.Flags.JavaStatic + def Synthetic: Flags = dotc.core.Flags.Synthetic + def Trait: Flags = dotc.core.Flags.Trait + end Flags + + object FlagsMethodsImpl extends FlagsMethods: + extension (self: Flags): + def is(that: Flags): Boolean = self.isAllOf(that) + def |(that: Flags): Flags = dotc.core.Flags.extension_|(self)(that) + def &(that: Flags): Flags = dotc.core.Flags.extension_&(self)(that) + def showExtractors: String = + new ExtractorsPrinter[tasty.type](tasty).showFlags(self) + def show: String = + self.showWith(SyntaxHighlight.plain) + def showWith(syntaxHighlight: SyntaxHighlight): String = + new SourceCodePrinter[tasty.type](tasty)(syntaxHighlight).showFlags(self) + end extension + end FlagsMethodsImpl + + type Position = dotc.util.SourcePosition + + object Position extends PositionModule + + object PositionMethodsImpl extends PositionMethods: + extension (self: Position): + def start: Int = self.start + def end: Int = self.end + def exists: Boolean = self.exists + def sourceFile: SourceFile = self.source + def startLine: Int = self.startLine + def endLine: Int = self.endLine + def startColumn: Int = self.startColumn + def endColumn: Int = self.endColumn + def sourceCode: String = + new String(self.source.content(), self.start, self.end - self.start) + end extension + end PositionMethodsImpl + + type SourceFile = dotc.util.SourceFile + + object SourceFile extends SourceFileModule + + object SourceFileMethodsImpl extends SourceFileMethods: + extension (self: SourceFile): + def jpath: java.nio.file.Path = self.file.jpath + def content: String = new String(self.content()) + end extension + end SourceFileMethodsImpl + + object Source extends SourceModule: + def path: java.nio.file.Path = ctx.compilationUnit.source.file.jpath + def isJavaCompilationUnit: Boolean = ctx.compilationUnit.isInstanceOf[dotc.fromtasty.JavaCompilationUnit] + def isScala2CompilationUnit: Boolean = ctx.compilationUnit.isInstanceOf[dotc.fromtasty.Scala2CompilationUnit] + def isAlreadyLoadedCompilationUnit: Boolean = ctx.compilationUnit.isInstanceOf[dotc.fromtasty.AlreadyLoadedCompilationUnit] + def compilationUnitClassname: String = + ctx.compilationUnit match + case cu: dotc.fromtasty.JavaCompilationUnit => cu.className + case cu: dotc.fromtasty.Scala2CompilationUnit => cu.className + case cu: dotc.fromtasty.AlreadyLoadedCompilationUnit => cu.className + case cu => "" + end Source + + def error(msg: => String, pos: Position): Unit = + dotc.report.error(msg, pos) + + def error(msg: => String, sourceFile: SourceFile, start: Int, end: Int): Unit = + dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end))) + + def warning(msg: => String, pos: Position): Unit = + dotc.report.warning(msg, pos) + + def warning(msg: => String, sourceFile: SourceFile, start: Int, end: Int): Unit = + dotc.report.error(msg, dotc.util.SourcePosition(sourceFile, dotc.util.Spans.Span(start, end))) + + type Comment = dotc.core.Comments.Comment + + object Comment extends CommentModule + + object CommentMethodsImpl extends CommentMethods: + extension (self: Comment): + def raw: String = self.raw + def expanded: Option[String] = self.expanded + def usecases: List[(String, Option[DefDef])] = + self.usecases.map { uc => (uc.code, uc.tpdCode) } + end extension + end CommentMethodsImpl + + private def optional[T <: dotc.ast.Trees.Tree[?]](tree: T): Option[tree.type] = + if tree.isEmpty then None else Some(tree) + + private def withDefaultPos[T <: Tree](fn: Context ?=> T): T = + fn(using ctx.withSource(rootPosition.source)).withSpan(rootPosition.span) + + + def unpickleExpr(repr: Unpickler.PickledQuote, args: Unpickler.PickledArgs): Term = + PickledQuotes.unpickleExpr(repr, args) + + def unpickleType(repr: Unpickler.PickledQuote, args: Unpickler.PickledArgs): TypeTree = + PickledQuotes.unpickleType(repr, args) + + def Constraints_context[T]: scala.quoted.QuoteContext = + val ctx1 = ctx.fresh.setFreshGADTBounds.addMode(dotc.core.Mode.GadtConstraintInference) + dotty.tools.dotc.quoted.QuoteContextImpl()(using ctx1) + + def Constraints_add(syms: List[Symbol]): Boolean = + ctx.gadt.addToConstraint(syms) + + def Constraints_approximation(sym: Symbol, fromBelow: Boolean): Type = + ctx.gadt.approximation(sym, fromBelow) + + def Definitions_InternalQuotedMatcher_patternHole: Symbol = dotc.core.Symbols.defn.InternalQuotedMatcher_patternHole + def Definitions_InternalQuotedMatcher_higherOrderHole: Symbol = dotc.core.Symbols.defn.InternalQuotedMatcher_higherOrderHole + def Definitions_InternalQuotedMatcher_patternTypeAnnot: Symbol = dotc.core.Symbols.defn.InternalQuotedMatcher_patternTypeAnnot + def Definitions_InternalQuotedMatcher_fromAboveAnnot: Symbol = dotc.core.Symbols.defn.InternalQuotedMatcher_fromAboveAnnot + + def Definitions_UnitType: Type = dotc.core.Symbols.defn.UnitType + def Definitions_ByteType: Type = dotc.core.Symbols.defn.ByteType + def Definitions_ShortType: Type = dotc.core.Symbols.defn.ShortType + def Definitions_CharType: Type = dotc.core.Symbols.defn.CharType + def Definitions_IntType: Type = dotc.core.Symbols.defn.IntType + def Definitions_LongType: Type = dotc.core.Symbols.defn.LongType + def Definitions_FloatType: Type = dotc.core.Symbols.defn.FloatType + def Definitions_DoubleType: Type = dotc.core.Symbols.defn.DoubleType + def Definitions_BooleanType: Type = dotc.core.Symbols.defn.BooleanType + def Definitions_AnyType: Type = dotc.core.Symbols.defn.AnyType + def Definitions_AnyValType: Type = dotc.core.Symbols.defn.AnyValType + def Definitions_AnyRefType: Type = dotc.core.Symbols.defn.AnyRefType + def Definitions_ObjectType: Type = dotc.core.Symbols.defn.ObjectType + def Definitions_NothingType: Type = dotc.core.Symbols.defn.NothingType + def Definitions_NullType: Type = dotc.core.Symbols.defn.NullType + def Definitions_StringType: Type = dotc.core.Symbols.defn.StringType + def Definitions_TupleType: Type = dotc.core.Symbols.defn.TupleTypeRef + def Definitions_EmptyTupleType: Type = dotc.core.Symbols.defn.EmptyTupleModule.termRef + def Definitions_NonEmptyTupleType: Type = dotc.core.Symbols.defn.NonEmptyTupleClass.typeRef + def Definitions_TupleConsType: Type = dotc.core.Symbols.defn.PairClass.typeRef + + def betaReduce(tree: Term): Option[Term] = + tree match + case app @ tpd.Apply(tpd.Select(fn, nme.apply), args) if dotc.core.Symbols.defn.isFunctionType(fn.tpe) => + val app1 = dotc.transform.BetaReduce(app, fn, args) + if app1 eq app then None + else Some(app1.withSpan(tree.span)) + case tpd.Block(Nil, expr) => + for e <- betaReduce(expr) yield tpd.cpy.Block(tree)(Nil, e) + case tpd.Inlined(_, Nil, expr) => + betaReduce(expr) + case _ => + None + + def lambdaExtractor(fn: Term, paramTypes: List[Type]): Option[List[Term] => Term] = { + def rec(fn: Term, transformBody: Term => Term): Option[List[Term] => Term] = { + fn match { + case tpd.Inlined(call, bindings, expansion) => + // this case must go before closureDef to avoid dropping the inline node + rec(expansion, tpd.cpy.Inlined(fn)(call, bindings, _)) + case tpd.Typed(expr, tpt) => + val tpe = tpt.tpe.dropDependentRefinement + // we checked that this is a plain Function closure, so there will be an apply method with a MethodType + // and the expected signature based on param types + val expectedSig = Signature(Nil, tpnme.WILDCARD).prependTermParams(paramTypes, false) + val method = tpt.tpe.member(nme.apply).atSignature(expectedSig) + if method.symbol.is(Deferred) then + val methodType = method.info.asInstanceOf[MethodType] + // result might contain paramrefs, so we substitute them with arg termrefs + val resultTypeWithSubst = methodType.resultType.substParams(methodType, paramTypes) + rec(expr, tpd.Typed(_, tpd.TypeTree(resultTypeWithSubst).withSpan(tpt.span))) + else + None + case cl @ tpd.closureDef(ddef) => + def replace(body: Term, argRefs: List[Term]): Term = { + val paramSyms = ddef.vparamss.head.map(param => param.symbol) + val paramToVals = paramSyms.zip(argRefs).toMap + new dotc.ast.TreeTypeMap( + oldOwners = ddef.symbol :: Nil, + newOwners = ctx.owner :: Nil, + treeMap = tree => paramToVals.get(tree.symbol).map(_.withSpan(tree.span)).getOrElse(tree) + ).transform(body) + } + Some(argRefs => replace(transformBody(ddef.rhs), argRefs)) + case tpd.Block(stats, expr) => + // this case must go after closureDef to avoid matching the closure + rec(expr, tpd.cpy.Block(fn)(stats, _)) + case _ => + None + } + } + rec(fn, identity) + } + + def compilerId: Int = rootContext.outersIterator.toList.last.hashCode() + + end tasty + +end QuoteContextImpl diff --git a/compiler/src/dotty/tools/dotc/quoted/reflect/ReflectionCompilerInterface.scala b/compiler/src/dotty/tools/dotc/quoted/reflect/ReflectionCompilerInterface.scala deleted file mode 100644 index a4f37ac4bccf..000000000000 --- a/compiler/src/dotty/tools/dotc/quoted/reflect/ReflectionCompilerInterface.scala +++ /dev/null @@ -1,2115 +0,0 @@ -package dotty.tools.dotc -package quoted -package reflect - -import dotty.tools.dotc.ast.Trees._ -import dotty.tools.dotc.ast.{TreeTypeMap, Trees, tpd, untpd} -import dotty.tools.dotc.typer.{Implicits, Typer} -import dotty.tools.dotc.core._ -import dotty.tools.dotc.core.Flags._ -import dotty.tools.dotc.core.Contexts._ -import dotty.tools.dotc.core.StdNames._ -import dotty.tools.dotc.core.Symbols._ -import dotty.tools.dotc.core.Decorators._ -import dotty.tools.dotc.core.Types.SingletonType -import dotty.tools.dotc.quoted._ -import dotty.tools.dotc.quoted.reflect.FromSymbol.{definitionFromSym, packageDefFromSym} -import dotty.tools.dotc.typer.Implicits.{AmbiguousImplicits, DivergingImplicit, NoMatchingImplicits, SearchFailure, SearchFailureType} -import dotty.tools.dotc.util.{SourceFile, SourcePosition, Spans} - -import scala.internal.quoted.Unpickler -import scala.internal.tasty.CompilerInterface - -import scala.tasty.reflect.TypeTest - -// NOTE: `ReflectionCompilerInterface` should be a class to make sure that all functionality of -// `CompilerInterface` is implemented here. - -class ReflectionCompilerInterface(val rootContext: Context) extends CompilerInterface { - import tpd._ - - private given core.Contexts.Context = rootContext - - def rootPosition: util.SourcePosition = - MacroExpansion.position.getOrElse(SourcePosition(rootContext.source, Spans.NoSpan)) - - - ////////////////////// - // QUOTE UNPICKLING // - ////////////////////// - - def unpickleExpr(repr: Unpickler.PickledQuote, args: Unpickler.PickledArgs): Term = - PickledQuotes.unpickleExpr(repr, args) - - def unpickleType(repr: Unpickler.PickledQuote, args: Unpickler.PickledArgs): TypeTree = - PickledQuotes.unpickleType(repr, args) - - - ///////////// - // CONTEXT // - ///////////// - - type Context = core.Contexts.Context - - ///////////////// - // Constraints // - ///////////////// - - def Constraints_context[T]: scala.quoted.QuoteContext = - val ctx1 = ctx.fresh.setFreshGADTBounds.addMode(Mode.GadtConstraintInference) - dotty.tools.dotc.quoted.QuoteContextImpl()(using ctx1) - - def Constraints_add(syms: List[Symbol]): Boolean = - ctx.gadt.addToConstraint(syms) - - def Constraints_approximation(sym: Symbol, fromBelow: Boolean): Type = - ctx.gadt.approximation(sym, fromBelow) - - //////////// - // Source // - //////////// - - def Source_path: java.nio.file.Path = ctx.compilationUnit.source.file.jpath - def Source_isJavaCompilationUnit: Boolean = ctx.compilationUnit.isInstanceOf[fromtasty.JavaCompilationUnit] - def Source_isScala2CompilationUnit: Boolean = ctx.compilationUnit.isInstanceOf[fromtasty.Scala2CompilationUnit] - def Source_isAlreadyLoadedCompilationUnit: Boolean = ctx.compilationUnit.isInstanceOf[fromtasty.AlreadyLoadedCompilationUnit] - def Source_compilationUnitClassname: String = - ctx.compilationUnit match { - case cu: fromtasty.JavaCompilationUnit => cu.className - case cu: fromtasty.Scala2CompilationUnit => cu.className - case cu: fromtasty.AlreadyLoadedCompilationUnit => cu.className - case cu => "" - } - - - /////////////// - // REPORTING // - /////////////// - - def error(msg: => String, pos: Position): Unit = - report.error(msg, pos) - - def error(msg: => String, sourceFile: SourceFile, start: Int, end: Int): Unit = - report.error(msg, util.SourcePosition(sourceFile, util.Spans.Span(start, end))) - - def warning(msg: => String, pos: Position): Unit = - report.warning(msg, pos) - - def warning(msg: => String, sourceFile: SourceFile, start: Int, end: Int): Unit = - report.error(msg, util.SourcePosition(sourceFile, util.Spans.Span(start, end))) - - - /////////// - // TREES // - /////////// - - type Tree = tpd.Tree - - def Tree_pos(self: Tree): Position = self.sourcePos - def Tree_symbol(self: Tree): Symbol = self.symbol - - type PackageClause = tpd.PackageDef - - def PackageClause_TypeTest: TypeTest[Tree, PackageClause] = new { - def runtimeClass: Class[?] = classOf[PackageClause] - override def unapply(x: Any): Option[PackageClause] = x match - case x: tpd.PackageDef @unchecked => Some(x) - case _ => None - } - - def PackageClause_pid(self: PackageClause): Ref = self.pid - def PackageClause_stats(self: PackageClause): List[Tree] = self.stats - - def PackageClause_apply(pid: Ref, stats: List[Tree]): PackageClause = - withDefaultPos(tpd.PackageDef(pid.asInstanceOf[tpd.RefTree], stats)) - - def PackageClause_copy(original: Tree)(pid: Ref, stats: List[Tree]): PackageClause = - tpd.cpy.PackageDef(original)(pid, stats) - - type Statement = tpd.Tree - - def Statement_TypeTest: TypeTest[Tree, Statement] = new { - def runtimeClass: Class[?] = classOf[Statement] - override def unapply(x: Any): Option[Statement] = x match - case _: PatternTree @unchecked => None - case tree: Tree @unchecked if tree.isTerm => Term_TypeTest.unapply(tree) - case tree: Tree @unchecked => Definition_TypeTest.unapply(tree) - case _ => None - } - - type Import = tpd.Import - - def Import_TypeTest: TypeTest[Tree, Import] = new { - def runtimeClass: Class[?] = classOf[Import] - override def unapply(x: Any): Option[Import] = x match - case tree: tpd.Import @unchecked => Some(tree) - case _ => None - } - - def Import_implied(self: Import): Boolean = false // TODO: adapt to new import scheme - def Import_expr(self: Import): Tree = self.expr - def Import_selectors(self: Import): List[ImportSelector] = self.selectors - - def Import_apply(expr: Term, selectors: List[ImportSelector]): Import = - withDefaultPos(tpd.Import(expr, selectors)) - - def Import_copy(original: Tree)(expr: Term, selectors: List[ImportSelector]): Import = - tpd.cpy.Import(original)(expr, selectors) - - type Definition = tpd.Tree - - def Definition_TypeTest: TypeTest[Tree, Definition] = new { - def runtimeClass: Class[?] = classOf[Definition] - override def unapply(x: Any): Option[Definition] = x match - case x: tpd.MemberDef @unchecked => Some(x) - case x: PackageDefinition @unchecked => Some(x) - case _ => None - } - - def Definition_name(self: Definition): String = self match { - case self: tpd.MemberDef => self.name.toString - case self: PackageDefinition => self.symbol.name.toString // TODO make PackageDefinition a MemberDef or NameTree - } - - type PackageDef = PackageDefinition - - def PackageDef_TypeTest: TypeTest[Tree, PackageDef] = new { - def runtimeClass: Class[?] = classOf[PackageDef] - override def unapply(x: Any): Option[PackageDef] = x match - case x: PackageDefinition @unchecked => Some(x) - case _ => None - } - - def PackageDef_owner(self: PackageDef): PackageDef = packageDefFromSym(self.symbol.owner) - - def PackageDef_members(self: PackageDef): List[Statement] = - if (self.symbol.is(core.Flags.JavaDefined)) Nil // FIXME should also support java packages - else self.symbol.info.decls.iterator.map(definitionFromSym).toList - - type ClassDef = tpd.TypeDef - - def ClassDef_TypeTest: TypeTest[Tree, ClassDef] = new { - def runtimeClass: Class[?] = classOf[ClassDef] - override def unapply(x: Any): Option[ClassDef] = x match - case x: tpd.TypeDef @unchecked if x.isClassDef => Some(x) - case _ => None - } - - def ClassDef_constructor(self: ClassDef): DefDef = ClassDef_rhs(self).constr - def ClassDef_parents(self: ClassDef): List[Term | TypeTree] = ClassDef_rhs(self).parents - def ClassDef_derived(self: ClassDef): List[TypeTree] = ClassDef_rhs(self).derived.asInstanceOf[List[TypeTree]] - def ClassDef_self(self: ClassDef): Option[ValDef] = optional(ClassDef_rhs(self).self) - def ClassDef_body(self: ClassDef): List[Statement] = ClassDef_rhs(self).body - private def ClassDef_rhs(self: ClassDef) = self.rhs.asInstanceOf[tpd.Template] - - def ClassDef_copy(original: Tree)(name: String, constr: DefDef, parents: List[Term | TypeTree], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement]): ClassDef = { - val Trees.TypeDef(_, originalImpl: tpd.Template) = original - tpd.cpy.TypeDef(original)(name.toTypeName, tpd.cpy.Template(originalImpl)(constr, parents, derived, selfOpt.getOrElse(tpd.EmptyValDef), body)) - } - - type TypeDef = tpd.TypeDef - - def TypeDef_TypeTest: TypeTest[Tree, TypeDef] = new { - def runtimeClass: Class[?] = classOf[TypeDef] - override def unapply(x: Any): Option[TypeDef] = x match - case x: tpd.TypeDef @unchecked if !x.isClassDef => Some(x) - case _ => None - } - - def TypeDef_rhs(self: TypeDef): TypeTree | TypeBoundsTree = self.rhs - - def TypeDef_apply(symbol: Symbol): TypeDef = withDefaultPos(tpd.TypeDef(symbol.asType)) - def TypeDef_copy(original: Tree)(name: String, rhs: TypeTree | TypeBoundsTree): TypeDef = - tpd.cpy.TypeDef(original)(name.toTypeName, rhs) - - type DefDef = tpd.DefDef - - def DefDef_TypeTest: TypeTest[Tree, DefDef] = new { - def runtimeClass: Class[?] = classOf[DefDef] - override def unapply(x: Any): Option[DefDef] = x match - case x: tpd.DefDef @unchecked => Some(x) - case _ => None - } - - def DefDef_typeParams(self: DefDef): List[TypeDef] = self.tparams - def DefDef_paramss(self: DefDef): List[List[ValDef]] = self.vparamss - def DefDef_returnTpt(self: DefDef): TypeTree = self.tpt - def DefDef_rhs(self: DefDef): Option[Tree] = optional(self.rhs) - - def DefDef_apply(symbol: Symbol, rhsFn: List[Type] => List[List[Term]] => Option[Term]): DefDef = - withDefaultPos(tpd.polyDefDef(symbol.asTerm, tparams => vparamss => rhsFn(tparams)(vparamss).getOrElse(tpd.EmptyTree))) - - def DefDef_copy(original: Tree)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term]): DefDef = - tpd.cpy.DefDef(original)(name.toTermName, typeParams, paramss, tpt, rhs.getOrElse(tpd.EmptyTree)) - - type ValDef = tpd.ValDef - - def ValDef_TypeTest: TypeTest[Tree, ValDef] = new { - def runtimeClass: Class[?] = classOf[ValDef] - override def unapply(x: Any): Option[ValDef] = x match - case x: tpd.ValDef @unchecked => Some(x) - case _ => None - } - - def ValDef_tpt(self: ValDef): TypeTree = self.tpt - def ValDef_rhs(self: ValDef): Option[Tree] = optional(self.rhs) - - def ValDef_apply(symbol: Symbol, rhs: Option[Term]): ValDef = - tpd.ValDef(symbol.asTerm, rhs.getOrElse(tpd.EmptyTree)) - - def ValDef_copy(original: Tree)(name: String, tpt: TypeTree, rhs: Option[Term]): ValDef = - tpd.cpy.ValDef(original)(name.toTermName, tpt, rhs.getOrElse(tpd.EmptyTree)) - - type Term = tpd.Tree - - def Term_TypeTest: TypeTest[Tree, Term] = new { - def runtimeClass: Class[?] = classOf[Term] - override def unapply(x: Any): Option[Term] = x match - case _ if Unapply_TypeTest.unapply(x).isDefined => None - case _: tpd.PatternTree @unchecked => None - case x: tpd.Tree @unchecked if x.isTerm => Some(x) - case x: tpd.SeqLiteral @unchecked => Some(x) - case x: tpd.Inlined @unchecked => Some(x) - case x: tpd.NamedArg @unchecked => Some(x) - case _ => None - } - - def Term_tpe(self: Term): Type = self.tpe - def Term_underlyingArgument(self: Term): Term = self.underlyingArgument - def Term_underlying(self: Term): Term = self.underlying - - def Term_etaExpand(term: Term): Term = term.tpe.widen match { - case mtpe: Types.MethodType if !mtpe.isParamDependent => - val closureResType = mtpe.resType match { - case t: Types.MethodType @unchecked => t.toFunctionType() - case t => t - } - val closureTpe = Types.MethodType(mtpe.paramNames, mtpe.paramInfos, closureResType) - val closureMethod = newSymbol(ctx.owner, nme.ANON_FUN, Synthetic | Method, closureTpe) - tpd.Closure(closureMethod, tss => Term_etaExpand(new tpd.TreeOps(term).appliedToArgs(tss.head))) - case _ => term - } - - def TypeRef_apply(sym: Symbol): TypeTree = { - assert(sym.isType) - withDefaultPos(tpd.ref(sym).asInstanceOf[tpd.TypeTree]) - } - - type Ref = tpd.RefTree - - def Ref_TypeTest: TypeTest[Tree, Ref] = new { - def runtimeClass: Class[?] = classOf[Ref] - override def unapply(x: Any): Option[Ref] = x match - case x: tpd.RefTree @unchecked if x.isTerm => Some(x) - case _ => None - } - - def Ref_term(tp: TermRef): Ref = - withDefaultPos(tpd.ref(tp).asInstanceOf[tpd.RefTree]) - - def Ref_apply(sym: Symbol): Ref = { - assert(sym.isTerm) - withDefaultPos(tpd.ref(sym).asInstanceOf[tpd.RefTree]) - } - - type Ident = tpd.Ident - - def Ident_TypeTest: TypeTest[Tree, Ident] = new { - def runtimeClass: Class[?] = classOf[Ident] - override def unapply(x: Any): Option[Ident] = x match - case x: tpd.Ident @unchecked if x.isTerm => Some(x) - case _ => None - } - - def Ident_name(self: Ident): String = self.name.show - - def Ident_apply(tmref: TermRef): Term = - withDefaultPos(tpd.ref(tmref).asInstanceOf[Term]) - - def Ident_copy(original: Tree)(name: String): Ident = - tpd.cpy.Ident(original)(name.toTermName) - - type Select = tpd.Select - - def Select_TypeTest: TypeTest[Tree, Select] = new { - def runtimeClass: Class[?] = classOf[Select] - override def unapply(x: Any): Option[Select] = x match - case x: tpd.Select @unchecked if x.isTerm => Some(x) - case _ => None - } - - def Select_qualifier(self: Select): Term = self.qualifier - def Select_name(self: Select): String = self.name.toString - def Select_signature(self: Select): Option[Signature] = - if (self.symbol.signature == core.Signature.NotAMethod) None - else Some(self.symbol.signature) - - def Select_apply(qualifier: Term, symbol: Symbol): Select = - withDefaultPos(tpd.Select(qualifier, Types.TermRef(qualifier.tpe, symbol))) - - def Select_unique(qualifier: Term, name: String): Select = { - val denot = qualifier.tpe.member(name.toTermName) - assert(!denot.isOverloaded, s"The symbol `$name` is overloaded. The method Select.unique can only be used for non-overloaded symbols.") - withDefaultPos(tpd.Select(qualifier, name.toTermName)) - } - - // TODO rename, this returns an Apply and not a Select - def Select_overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term]): Apply = - withDefaultPos(tpd.applyOverloaded(qualifier, name.toTermName, args, targs, Types.WildcardType).asInstanceOf[Apply]) - - def Select_copy(original: Tree)(qualifier: Term, name: String): Select = - tpd.cpy.Select(original)(qualifier, name.toTermName) - - type Literal = tpd.Literal - - def Literal_TypeTest: TypeTest[Tree, Literal] = new { - def runtimeClass: Class[?] = classOf[Literal] - override def unapply(x: Any): Option[Literal] = x match - case x: tpd.Literal @unchecked => Some(x) - case _ => None - } - - def Literal_constant(self: Literal): Constant = self.const - - def Literal_apply(constant: Constant): Literal = - withDefaultPos(tpd.Literal(constant)) - - def Literal_copy(original: Tree)(constant: Constant): Literal = - tpd.cpy.Literal(original)(constant) - - type This = tpd.This - - def This_TypeTest: TypeTest[Tree, This] = new { - def runtimeClass: Class[?] = classOf[This] - override def unapply(x: Any): Option[This] = x match - case x: tpd.This @unchecked => Some(x) - case _ => None - } - - def This_id(self: This): Option[Id] = optional(self.qual) - - def This_apply(cls: Symbol): This = - withDefaultPos(tpd.This(cls.asClass)) - - def This_copy(original: Tree)(qual: Option[Id]): This = - tpd.cpy.This(original)(qual.getOrElse(untpd.EmptyTypeIdent)) - - type New = tpd.New - - def New_TypeTest: TypeTest[Tree, New] = new { - def runtimeClass: Class[?] = classOf[New] - override def unapply(x: Any): Option[New] = x match - case x: tpd.New @unchecked => Some(x) - case _ => None - } - - def New_tpt(self: New): TypeTree = self.tpt - - def New_apply(tpt: TypeTree): New = withDefaultPos(tpd.New(tpt)) - - def New_copy(original: Tree)(tpt: TypeTree): New = - tpd.cpy.New(original)(tpt) - - type NamedArg = tpd.NamedArg - - def NamedArg_TypeTest: TypeTest[Tree, NamedArg] = new { - def runtimeClass: Class[?] = classOf[NamedArg] - override def unapply(x: Any): Option[NamedArg] = x match - case x: tpd.NamedArg @unchecked if x.name.isInstanceOf[core.Names.TermName] => Some(x) // TODO: Now, the name should alwas be a term name - case _ => None - } - - def NamedArg_name(self: NamedArg): String = self.name.toString - def NamedArg_value(self: NamedArg): Term = self.arg - - def NamedArg_apply(name: String, arg: Term): NamedArg = - withDefaultPos(tpd.NamedArg(name.toTermName, arg)) - - def NamedArg_copy(original: Tree)(name: String, arg: Term): NamedArg = - tpd.cpy.NamedArg(original)(name.toTermName, arg) - - type Apply = tpd.Apply - - def Apply_TypeTest: TypeTest[Tree, Apply] = new { - def runtimeClass: Class[?] = classOf[Apply] - override def unapply(x: Any): Option[Apply] = x match - case x: tpd.Apply @unchecked => Some(x) - case _ => None - } - - def Apply_fun(self: Apply): Term = self.fun - def Apply_args(self: Apply): List[Term] = self.args - - - def Apply_apply(fn: Term, args: List[Term]): Apply = - withDefaultPos(tpd.Apply(fn, args)) - - def Apply_copy(original: Tree)(fun: Term, args: List[Term]): Apply = - tpd.cpy.Apply(original)(fun, args) - - type TypeApply = tpd.TypeApply - - def TypeApply_TypeTest: TypeTest[Tree, TypeApply] = new { - def runtimeClass: Class[?] = classOf[TypeApply] - override def unapply(x: Any): Option[TypeApply] = x match - case x: tpd.TypeApply @unchecked => Some(x) - case _ => None - } - - def TypeApply_fun(self: TypeApply): Term = self.fun - def TypeApply_args(self: TypeApply): List[TypeTree] = self.args - - def TypeApply_apply(fn: Term, args: List[TypeTree]): TypeApply = - withDefaultPos(tpd.TypeApply(fn, args)) - - def TypeApply_copy(original: Tree)(fun: Term, args: List[TypeTree]): TypeApply = - tpd.cpy.TypeApply(original)(fun, args) - - type Super = tpd.Super - - def Super_TypeTest: TypeTest[Tree, Super] = new { - def runtimeClass: Class[?] = classOf[Super] - override def unapply(x: Any): Option[Super] = x match - case x: tpd.Super @unchecked => Some(x) - case _ => None - } - - def Super_qualifier(self: Super): Term = self.qual - def Super_id(self: Super): Option[Id] = optional(self.mix) - - def Super_apply(qual: Term, mix: Option[Id]): Super = - withDefaultPos(tpd.Super(qual, mix.getOrElse(untpd.EmptyTypeIdent), NoSymbol)) - - def Super_copy(original: Tree)(qual: Term, mix: Option[Id]): Super = - tpd.cpy.Super(original)(qual, mix.getOrElse(untpd.EmptyTypeIdent)) - - type Typed = tpd.Typed - - def Typed_TypeTest: TypeTest[Tree, Typed] = new { - def runtimeClass: Class[?] = classOf[Typed] - override def unapply(x: Any): Option[Typed] = x match - case x: tpd.Typed @unchecked => Some(x) - case _ => None - } - - def Typed_expr(self: Typed): Term = self.expr - def Typed_tpt(self: Typed): TypeTree = self.tpt - - def Typed_apply(expr: Term, tpt: TypeTree): Typed = - withDefaultPos(tpd.Typed(expr, tpt)) - - def Typed_copy(original: Tree)(expr: Term, tpt: TypeTree): Typed = - tpd.cpy.Typed(original)(expr, tpt) - - type Assign = tpd.Assign - - def Assign_TypeTest: TypeTest[Tree, Assign] = new { - def runtimeClass: Class[?] = classOf[Assign] - override def unapply(x: Any): Option[Assign] = x match - case x: tpd.Assign @unchecked => Some(x) - case _ => None - } - - def Assign_lhs(self: Assign): Term = self.lhs - def Assign_rhs(self: Assign): Term = self.rhs - - def Assign_apply(lhs: Term, rhs: Term): Assign = - withDefaultPos(tpd.Assign(lhs, rhs)) - - def Assign_copy(original: Tree)(lhs: Term, rhs: Term): Assign = - tpd.cpy.Assign(original)(lhs, rhs) - - type Block = tpd.Block - - def Block_TypeTest: TypeTest[Tree, Block] = new { - def runtimeClass: Class[?] = classOf[Block] - override def unapply(x: Any): Option[Block] = - x match - case x: tpd.Tree @unchecked => - normalizedLoops(x) match - case y: tpd.Block => Some(y) - case _ => None - case _ => None - } - - /** Normalizes non Blocks. - * i) Put `while` loops in their own blocks: `{ def while$() = ...; while$() }` - * ii) Put closures in their own blocks: `{ def anon$() = ...; closure(anon$, ...) }` - */ - private def normalizedLoops(tree: tpd.Tree): tpd.Tree = tree match { - case block: tpd.Block if block.stats.size > 1 => - def normalizeInnerLoops(stats: List[tpd.Tree]): List[tpd.Tree] = stats match { - case (x: tpd.DefDef) :: y :: xs if needsNormalization(y) => - tpd.Block(x :: Nil, y) :: normalizeInnerLoops(xs) - case x :: xs => x :: normalizeInnerLoops(xs) - case Nil => Nil - } - if (needsNormalization(block.expr)) { - val stats1 = normalizeInnerLoops(block.stats.init) - val normalLoop = tpd.Block(block.stats.last :: Nil, block.expr) - tpd.Block(stats1, normalLoop) - } - else { - val stats1 = normalizeInnerLoops(block.stats) - tpd.cpy.Block(block)(stats1, block.expr) - } - case _ => tree - } - - /** If it is the second statement of a closure. See: `normalizedLoops` */ - private def needsNormalization(tree: tpd.Tree): Boolean = tree match { - case _: tpd.Closure => true - case _ => false - } - - def Block_statements(self: Block): List[Statement] = self.stats - def Block_expr(self: Block): Term = self.expr - - def Block_apply(stats: List[Statement], expr: Term): Block = - withDefaultPos(tpd.Block(stats, expr)) - - def Block_copy(original: Tree)(stats: List[Statement], expr: Term): Block = - tpd.cpy.Block(original)(stats, expr) - - type Inlined = tpd.Inlined - - def Inlined_TypeTest: TypeTest[Tree, Inlined] = new { - def runtimeClass: Class[?] = classOf[Inlined] - override def unapply(x: Any): Option[Inlined] = x match - case x: tpd.Inlined @unchecked => Some(x) - case _ => None - } - - def Inlined_call(self: Inlined): Option[Term | TypeTree] = optional(self.call) - def Inlined_bindings(self: Inlined): List[Definition] = self.bindings - def Inlined_body(self: Inlined): Term = self.expansion - - def Inlined_apply(call: Option[Term | TypeTree], bindings: List[Definition], expansion: Term): Inlined = - withDefaultPos(tpd.Inlined(call.getOrElse(tpd.EmptyTree), bindings.map { case b: tpd.MemberDef => b }, expansion)) - - def Inlined_copy(original: Tree)(call: Option[Term | TypeTree], bindings: List[Definition], expansion: Term): Inlined = - tpd.cpy.Inlined(original)(call.getOrElse(tpd.EmptyTree), bindings.asInstanceOf[List[tpd.MemberDef]], expansion) - - type Closure = tpd.Closure - - def Closure_TypeTest: TypeTest[Tree, Closure] = new { - def runtimeClass: Class[?] = classOf[Closure] - override def unapply(x: Any): Option[Closure] = x match - case x: tpd.Closure @unchecked => Some(x) - case _ => None - } - - def Closure_meth(self: Closure): Term = self.meth - def Closure_tpeOpt(self: Closure): Option[Type] = optional(self.tpt).map(_.tpe) - - def Closure_apply(meth: Term, tpe: Option[Type]): Closure = - withDefaultPos(tpd.Closure(Nil, meth, tpe.map(tpd.TypeTree(_)).getOrElse(tpd.EmptyTree))) - - def Closure_copy(original: Tree)(meth: Tree, tpe: Option[Type]): Closure = - tpd.cpy.Closure(original)(Nil, meth, tpe.map(tpd.TypeTree(_)).getOrElse(tpd.EmptyTree)) - - def Lambda_apply(tpe: MethodType, rhsFn: List[Tree] => Tree): Block = - tpd.Lambda(tpe, rhsFn) - - type If = tpd.If - - def If_TypeTest: TypeTest[Tree, If] = new { - def runtimeClass: Class[?] = classOf[If] - override def unapply(x: Any): Option[If] = x match - case x: tpd.If @unchecked => Some(x) - case _ => None - } - - def If_cond(self: If): Term = self.cond - def If_thenp(self: If): Term = self.thenp - def If_elsep(self: If): Term = self.elsep - - def If_apply(cond: Term, thenp: Term, elsep: Term): If = - withDefaultPos(tpd.If(cond, thenp, elsep)) - - def If_copy(original: Tree)(cond: Term, thenp: Term, elsep: Term): If = - tpd.cpy.If(original)(cond, thenp, elsep) - - type Match = tpd.Match - - def Match_TypeTest: TypeTest[Tree, Match] = new { - def runtimeClass: Class[?] = classOf[Match] - override def unapply(x: Any): Option[Match] = x match - case x: tpd.Match @unchecked if !x.selector.isEmpty => Some(x) - case _ => None - } - - def Match_scrutinee(self: Match): Term = self.selector - def Match_cases(self: Match): List[CaseDef] = self.cases - - def Match_apply(selector: Term, cases: List[CaseDef]): Match = - withDefaultPos(tpd.Match(selector, cases)) - - def Match_copy(original: Tree)(selector: Term, cases: List[CaseDef]): Match = - tpd.cpy.Match(original)(selector, cases) - - type GivenMatch = tpd.Match - - def GivenMatch_TypeTest: TypeTest[Tree, GivenMatch] = new { - def runtimeClass: Class[?] = classOf[GivenMatch] - override def unapply(x: Any): Option[GivenMatch] = x match - case x: tpd.Match @unchecked if x.selector.isEmpty => Some(x) - case _ => None - } - - def GivenMatch_cases(self: Match): List[CaseDef] = self.cases - - def GivenMatch_apply(cases: List[CaseDef]): GivenMatch = - withDefaultPos(tpd.Match(tpd.EmptyTree, cases)) - - def GivenMatch_copy(original: Tree)(cases: List[CaseDef]): GivenMatch = - tpd.cpy.Match(original)(tpd.EmptyTree, cases) - - type Try = tpd.Try - - def Try_TypeTest: TypeTest[Tree, Try] = new { - def runtimeClass: Class[?] = classOf[Try] - override def unapply(x: Any): Option[Try] = x match - case x: tpd.Try @unchecked => Some(x) - case _ => None - } - - def Try_body(self: Try): Term = self.expr - def Try_cases(self: Try): List[CaseDef] = self.cases - def Try_finalizer(self: Try): Option[Term] = optional(self.finalizer) - - def Try_apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term]): Try = - withDefaultPos(tpd.Try(expr, cases, finalizer.getOrElse(tpd.EmptyTree))) - - def Try_copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term]): Try = - tpd.cpy.Try(original)(expr, cases, finalizer.getOrElse(tpd.EmptyTree)) - - type Return = tpd.Return - - def Return_TypeTest: TypeTest[Tree, Return] = new { - def runtimeClass: Class[?] = classOf[Return] - override def unapply(x: Any): Option[Return] = x match - case x: tpd.Return @unchecked => Some(x) - case _ => None - } - - def Return_expr(self: Return): Term = self.expr - - def Return_apply(expr: Term): Return = - withDefaultPos(tpd.Return(expr, ctx.owner)) - - def Return_copy(original: Tree)(expr: Term): Return = - tpd.cpy.Return(original)(expr, tpd.ref(ctx.owner)) - - type Repeated = tpd.SeqLiteral - - def Repeated_TypeTest: TypeTest[Tree, Repeated] = new { - def runtimeClass: Class[?] = classOf[Repeated] - override def unapply(x: Any): Option[Repeated] = x match - case x: tpd.SeqLiteral @unchecked => Some(x) - case _ => None - } - - def Repeated_elems(self: Repeated): List[Term] = self.elems - def Repeated_elemtpt(self: Repeated): TypeTree = self.elemtpt - - def Repeated_apply(elems: List[Term], elemtpt: TypeTree): Repeated = - withDefaultPos(tpd.SeqLiteral(elems, elemtpt)) - - def Repeated_copy(original: Tree)(elems: List[Term], elemtpt: TypeTree): Repeated = - tpd.cpy.SeqLiteral(original)(elems, elemtpt) - - type SelectOuter = tpd.Select - - def SelectOuter_TypeTest: TypeTest[Tree, SelectOuter] = new { - def runtimeClass: Class[?] = classOf[SelectOuter] - override def unapply(x: Any): Option[SelectOuter] = x match - case x: tpd.Select @unchecked => - x.name match - case NameKinds.OuterSelectName(_, _) => Some(x) - case _ => None - case _ => None - } - - def SelectOuter_qualifier(self: SelectOuter): Term = self.qualifier - def SelectOuter_level(self: SelectOuter): Int = { - val NameKinds.OuterSelectName(_, levels) = self.name - levels - } - - def SelectOuter_apply(qualifier: Term, name: String, levels: Int): SelectOuter = - withDefaultPos(tpd.Select(qualifier, NameKinds.OuterSelectName(name.toTermName, levels))) - - def SelectOuter_copy(original: Tree)(qualifier: Term, name: String, levels: Int): SelectOuter = - tpd.cpy.Select(original)(qualifier, NameKinds.OuterSelectName(name.toTermName, levels)) - - type While = tpd.WhileDo - - def While_TypeTest: TypeTest[Tree, While] = new { - def runtimeClass: Class[?] = classOf[While] - override def unapply(x: Any): Option[While] = x match - case x: tpd.WhileDo @unchecked => Some(x) - case _ => None - } - - def While_cond(self: While): Term = self.cond - def While_body(self: While): Term = self.body - - def While_apply(cond: Term, body: Term): While = - withDefaultPos(tpd.WhileDo(cond, body)) - - def While_copy(original: Tree)(cond: Term, body: Term): While = - tpd.cpy.WhileDo(original)(cond, body) - - type TypeTree = tpd.Tree - - def TypeTree_TypeTest: TypeTest[Tree, TypeTree] = new { - def runtimeClass: Class[?] = classOf[TypeTree] - override def unapply(x: Any): Option[TypeTree] = x match - case x: tpd.TypeBoundsTree @unchecked => None - case x: tpd.Tree @unchecked if x.isType => Some(x) - case _ => None - } - - def TypeTree_tpe(self: TypeTree): Type = self.tpe.stripTypeVar - - type Inferred = tpd.TypeTree - - def Inferred_TypeTest: TypeTest[Tree, Inferred] = new { - def runtimeClass: Class[?] = classOf[Inferred] - override def unapply(x: Any): Option[Inferred] = x match - case tpt: tpd.TypeTree @unchecked if !tpt.tpe.isInstanceOf[Types.TypeBounds] => Some(tpt) - case _ => None - } - - def Inferred_apply(tpe: Type): Inferred = withDefaultPos(tpd.TypeTree(tpe)) - - type TypeIdent = tpd.Ident - - def TypeIdent_TypeTest: TypeTest[Tree, TypeIdent] = new { - def runtimeClass: Class[?] = classOf[TypeIdent] - override def unapply(x: Any): Option[TypeIdent] = x match - case tpt: tpd.Ident @unchecked if tpt.isType => Some(tpt) - case _ => None - } - - def TypeIdent_name(self: TypeIdent): String = self.name.toString - - def TypeIdent_copy(original: Tree)(name: String): TypeIdent = - tpd.cpy.Ident(original)(name.toTypeName) - - type TypeSelect = tpd.Select - - def TypeSelect_TypeTest: TypeTest[Tree, TypeSelect] = new { - def runtimeClass: Class[?] = classOf[TypeSelect] - override def unapply(x: Any): Option[TypeSelect] = x match - case tpt: tpd.Select @unchecked if tpt.isType && tpt.qualifier.isTerm => Some(tpt) - case _ => None - } - - def TypeSelect_qualifier(self: TypeSelect): Term = self.qualifier - def TypeSelect_name(self: TypeSelect): String = self.name.toString - - def TypeSelect_apply(qualifier: Term, name: String): TypeSelect = - withDefaultPos(tpd.Select(qualifier, name.toTypeName)) - - def TypeSelect_copy(original: Tree)(qualifier: Term, name: String): TypeSelect = - tpd.cpy.Select(original)(qualifier, name.toTypeName) - - - type Projection = tpd.Select - - def Projection_TypeTest: TypeTest[Tree, Projection] = new { - def runtimeClass: Class[?] = classOf[Projection] - override def unapply(x: Any): Option[Projection] = x match - case tpt: tpd.Select @unchecked if tpt.isType && tpt.qualifier.isType => Some(tpt) - case _ => None - } - - def Projection_qualifier(self: Projection): TypeTree = self.qualifier - def Projection_name(self: Projection): String = self.name.toString - - def Projection_copy(original: Tree)(qualifier: TypeTree, name: String): Projection = - tpd.cpy.Select(original)(qualifier, name.toTypeName) - - type Singleton = tpd.SingletonTypeTree - - def Singleton_TypeTest: TypeTest[Tree, Singleton] = new { - def runtimeClass: Class[?] = classOf[Singleton] - override def unapply(x: Any): Option[Singleton] = x match - case tpt: tpd.SingletonTypeTree @unchecked => Some(tpt) - case _ => None - } - - def Singleton_ref(self: Singleton): Term = self.ref - - def Singleton_apply(ref: Term): Singleton = - withDefaultPos(tpd.SingletonTypeTree(ref)) - - def Singleton_copy(original: Tree)(ref: Term): Singleton = - tpd.cpy.SingletonTypeTree(original)(ref) - - type Refined = tpd.RefinedTypeTree - - def Refined_TypeTest: TypeTest[Tree, Refined] = new { - def runtimeClass: Class[?] = classOf[Refined] - override def unapply(x: Any): Option[Refined] = x match - case tpt: tpd.RefinedTypeTree @unchecked => Some(tpt) - case _ => None - } - - def Refined_tpt(self: Refined): TypeTree = self.tpt - def Refined_refinements(self: Refined): List[Definition] = self.refinements - - def Refined_copy(original: Tree)(tpt: TypeTree, refinements: List[Definition]): Refined = - tpd.cpy.RefinedTypeTree(original)(tpt, refinements) - - type Applied = tpd.AppliedTypeTree - - def Applied_TypeTest: TypeTest[Tree, Applied] = new { - def runtimeClass: Class[?] = classOf[Applied] - override def unapply(x: Any): Option[Applied] = x match - case tpt: tpd.AppliedTypeTree @unchecked => Some(tpt) - case _ => None - } - - def Applied_tpt(self: Applied): TypeTree = self.tpt - def Applied_args(self: Applied): List[TypeTree | TypeBoundsTree] = self.args - - def Applied_apply(tpt: TypeTree, args: List[TypeTree | TypeBoundsTree]): Applied = - withDefaultPos(tpd.AppliedTypeTree(tpt, args)) - - def Applied_copy(original: Tree)(tpt: TypeTree, args: List[TypeTree | TypeBoundsTree]): Applied = - tpd.cpy.AppliedTypeTree(original)(tpt, args) - - type Annotated = tpd.Annotated - - def Annotated_TypeTest: TypeTest[Tree, Annotated] = new { - def runtimeClass: Class[?] = classOf[Annotated] - override def unapply(x: Any): Option[Annotated] = x match - case tpt: tpd.Annotated @unchecked => Some(tpt) - case _ => None - } - - def Annotated_arg(self: Annotated): TypeTree = self.arg - def Annotated_annotation(self: Annotated): Term = self.annot - - def Annotated_apply(arg: TypeTree, annotation: Term): Annotated = - withDefaultPos(tpd.Annotated(arg, annotation)) - - def Annotated_copy(original: Tree)(arg: TypeTree, annotation: Term): Annotated = - tpd.cpy.Annotated(original)(arg, annotation) - - type MatchTypeTree = tpd.MatchTypeTree - - def MatchTypeTree_TypeTest: TypeTest[Tree, MatchTypeTree] = new { - def runtimeClass: Class[?] = classOf[MatchTypeTree] - override def unapply(x: Any): Option[MatchTypeTree] = x match - case tpt: tpd.MatchTypeTree @unchecked => Some(tpt) - case _ => None - } - - def MatchTypeTree_bound(self: MatchTypeTree): Option[TypeTree] = if (self.bound == tpd.EmptyTree) None else Some(self.bound) - def MatchTypeTree_selector(self: MatchTypeTree): TypeTree = self.selector - def MatchTypeTree_cases(self: MatchTypeTree): List[CaseDef] = self.cases - - def MatchTypeTree_apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef]): MatchTypeTree = - withDefaultPos(tpd.MatchTypeTree(bound.getOrElse(tpd.EmptyTree), selector, cases)) - - def MatchTypeTree_copy(original: Tree)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef]): MatchTypeTree = - tpd.cpy.MatchTypeTree(original)(bound.getOrElse(tpd.EmptyTree), selector, cases) - - type ByName = tpd.ByNameTypeTree - - def ByName_TypeTest: TypeTest[Tree, ByName] = new { - def runtimeClass: Class[?] = classOf[ByName] - override def unapply(x: Any): Option[ByName] = x match - case tpt: tpd.ByNameTypeTree @unchecked => Some(tpt) - case _ => None - } - - def ByName_result(self: ByName): TypeTree = self.result - - def ByName_apply(result: TypeTree): ByName = - withDefaultPos(tpd.ByNameTypeTree(result)) - - def ByName_copy(original: Tree)(result: TypeTree): ByName = - tpd.cpy.ByNameTypeTree(original)(result) - - type LambdaTypeTree = tpd.LambdaTypeTree - - def LambdaTypeTree_TypeTest: TypeTest[Tree, LambdaTypeTree] = new { - def runtimeClass: Class[?] = classOf[LambdaTypeTree] - override def unapply(x: Any): Option[LambdaTypeTree] = x match - case tpt: tpd.LambdaTypeTree @unchecked => Some(tpt) - case _ => None - } - - def Lambdatparams(self: LambdaTypeTree): List[TypeDef] = self.tparams - def Lambdabody(self: LambdaTypeTree): TypeTree | TypeBoundsTree = self.body - - def Lambdaapply(tparams: List[TypeDef], body: TypeTree | TypeBoundsTree): LambdaTypeTree = - withDefaultPos(tpd.LambdaTypeTree(tparams, body)) - - def Lambdacopy(original: Tree)(tparams: List[TypeDef], body: TypeTree | TypeBoundsTree): LambdaTypeTree = - tpd.cpy.LambdaTypeTree(original)(tparams, body) - - type TypeBind = tpd.Bind - - def TypeBind_TypeTest: TypeTest[Tree, TypeBind] = new { - def runtimeClass: Class[?] = classOf[TypeBind] - override def unapply(x: Any): Option[TypeBind] = x match - case tpt: tpd.Bind @unchecked if tpt.name.isTypeName => Some(tpt) - case _ => None - } - - def TypeBind_name(self: TypeBind): String = self.name.toString - def TypeBind_body(self: TypeBind): TypeTree | TypeBoundsTree = self.body - - def TypeBind_copy(original: Tree)(name: String, tpt: TypeTree | TypeBoundsTree): TypeBind = - tpd.cpy.Bind(original)(name.toTypeName, tpt) - - type TypeBlock = tpd.Block - - def TypeBlock_TypeTest: TypeTest[Tree, TypeBlock] = new { - def runtimeClass: Class[?] = classOf[TypeBlock] - override def unapply(x: Any): Option[TypeBlock] = x match - case tpt: tpd.Block @unchecked => Some(tpt) - case _ => None - } - - def TypeBlock_aliases(self: TypeBlock): List[TypeDef] = self.stats.map { case alias: TypeDef => alias } - def TypeBlock_tpt(self: TypeBlock): TypeTree = self.expr - - def TypeBlock_apply(aliases: List[TypeDef], tpt: TypeTree): TypeBlock = - withDefaultPos(tpd.Block(aliases, tpt)) - - def TypeBlock_copy(original: Tree)(aliases: List[TypeDef], tpt: TypeTree): TypeBlock = - tpd.cpy.Block(original)(aliases, tpt) - - type TypeBoundsTree = tpd.TypeBoundsTree - - def TypeBoundsTree_TypeTest: TypeTest[Tree, TypeBoundsTree] = new { - def runtimeClass: Class[?] = classOf[TypeBoundsTree] - override def unapply(x: Any): Option[TypeBoundsTree] = x match - case x: tpd.TypeBoundsTree @unchecked => Some(x) - case x @ tpd.TypeTree() => - // TODO only enums generate this kind of type bounds. Is this possible without enums? If not generate tpd.TypeBoundsTree for enums instead - (x.tpe: Any) match { - case tpe: Types.TypeBounds => - Some(tpd.TypeBoundsTree(tpd.TypeTree(tpe.lo).withSpan(x.span), tpd.TypeTree(tpe.hi).withSpan(x.span))) - case _ => None - } - case _ => None - } - - def TypeBoundsTree_tpe(self: TypeBoundsTree): TypeBounds = self.tpe.asInstanceOf[Types.TypeBounds] - def TypeBoundsTree_low(self: TypeBoundsTree): TypeTree = self.lo - def TypeBoundsTree_hi(self: TypeBoundsTree): TypeTree = self.hi - - type WildcardTypeTree = tpd.Ident - - def WildcardTypeTree_TypeTest: TypeTest[Tree, WildcardTypeTree] = new { - def runtimeClass: Class[?] = classOf[WildcardTypeTree] - override def unapply(x: Any): Option[WildcardTypeTree] = x match - case x: tpd.Ident @unchecked if x.name == nme.WILDCARD => Some(x) - case _ => None - } - - def WildcardTypeTree_tpe(self: WildcardTypeTree): Type = self.tpe.stripTypeVar - - type CaseDef = tpd.CaseDef - - def CaseDef_TypeTest: TypeTest[Tree, CaseDef] = new { - def runtimeClass: Class[?] = classOf[CaseDef] - override def unapply(x: Any): Option[CaseDef] = x match - case tree: tpd.CaseDef @unchecked if tree.body.isTerm => Some(tree) - case _ => None - } - - def CaseDef_pattern(self: CaseDef): Tree = self.pat - def CaseDef_guard(self: CaseDef): Option[Term] = optional(self.guard) - def CaseDef_rhs(self: CaseDef): Term = self.body - - def CaseDef_module_apply(pattern: Tree, guard: Option[Term], body: Term): CaseDef = - tpd.CaseDef(pattern, guard.getOrElse(tpd.EmptyTree), body) - - def CaseDef_module_copy(original: Tree)(pattern: Tree, guard: Option[Term], body: Term): CaseDef = - tpd.cpy.CaseDef(original)(pattern, guard.getOrElse(tpd.EmptyTree), body) - - type TypeCaseDef = tpd.CaseDef - - def TypeCaseDef_TypeTest: TypeTest[Tree, TypeCaseDef] = new { - def runtimeClass: Class[?] = classOf[TypeCaseDef] - override def unapply(x: Any): Option[TypeCaseDef] = x match - case tree: tpd.CaseDef @unchecked if tree.body.isType => Some(tree) - case _ => None - } - - def TypeCaseDef_pattern(self: TypeCaseDef): TypeTree = self.pat - def TypeCaseDef_rhs(self: TypeCaseDef): TypeTree = self.body - - def TypeCaseDef_module_apply(pattern: TypeTree, body: TypeTree): TypeCaseDef = - tpd.CaseDef(pattern, tpd.EmptyTree, body) - - def TypeCaseDef_module_copy(original: Tree)(pattern: TypeTree, body: TypeTree): TypeCaseDef = - tpd.cpy.CaseDef(original)(pattern, tpd.EmptyTree, body) - - type Bind = tpd.Bind - - def Bind_TypeTest: TypeTest[Tree, Bind] = new { - def runtimeClass: Class[?] = classOf[Bind] - override def unapply(x: Any): Option[Bind] = x match - case x: tpd.Bind @unchecked if x.name.isTermName => Some(x) - case _ => None - } - - def Tree_Bind_name(self: Bind): String = self.name.toString - - def Tree_Bind_pattern(self: Bind): Tree = self.body - - def Tree_Bind_module_apply(sym: Symbol, body: Tree): Bind = - tpd.Bind(sym, body) - - def Tree_Bind_module_copy(original: Tree)(name: String, pattern: Tree): Bind = - withDefaultPos(tpd.cpy.Bind(original)(name.toTermName, pattern)) - - type Unapply = tpd.UnApply - - def Unapply_TypeTest: TypeTest[Tree, Unapply] = new { - def runtimeClass: Class[?] = classOf[Unapply] - override def unapply(x: Any): Option[Unapply] = x match - case pattern: tpd.UnApply @unchecked => Some(pattern) - case Trees.Typed(pattern: tpd.UnApply @unchecked, _) => Some(pattern) - case _ => None - } - - def Tree_Unapply_fun(self: Unapply): Term = self.fun - def Tree_Unapply_implicits(self: Unapply): List[Term] = self.implicits - def Tree_Unapply_patterns(self: Unapply): List[Tree] = effectivePatterns(self.patterns) - - def Tree_Unapply_module_copy(original: Tree)(fun: Term, implicits: List[Term], patterns: List[Tree]): Unapply = - withDefaultPos(tpd.cpy.UnApply(original)(fun, implicits, patterns)) - - private def effectivePatterns(patterns: List[Tree]): List[Tree] = patterns match { - case patterns0 :+ Trees.SeqLiteral(elems, _) => patterns0 ::: elems - case _ => patterns - } - - type Alternatives = tpd.Alternative - - def Alternatives_TypeTest: TypeTest[Tree, Alternatives] = new { - def runtimeClass: Class[?] = classOf[Alternatives] - override def unapply(x: Any): Option[Alternatives] = x match - case x: tpd.Alternative @unchecked => Some(x) - case _ => None - } - - def Tree_Alternatives_patterns(self: Alternatives): List[Tree] = self.trees - - def Tree_Alternatives_module_apply(patterns: List[Tree]): Alternatives = - withDefaultPos(tpd.Alternative(patterns)) - - def Tree_Alternatives_module_copy(original: Tree)(patterns: List[Tree]): Alternatives = - tpd.cpy.Alternative(original)(patterns) - - - ///////////// - // TYPES // - ///////////// - - type Type = Types.Type - - def Type_TypeTest: TypeTest[Type, Type] = new { - def runtimeClass: Class[?] = classOf[Type] - override def unapply(x: Any): Option[Type] = x match - case x: TypeBounds => None - case x: Types.Type if x != Types.NoPrefix => Some(x) - case _ => None - } - - def Type_ofErasedClass(clazz: Class[?]): Type = - if (clazz.isPrimitive) - if (clazz == classOf[Boolean]) defn.BooleanType - else if (clazz == classOf[Byte]) defn.ByteType - else if (clazz == classOf[Char]) defn.CharType - else if (clazz == classOf[Short]) defn.ShortType - else if (clazz == classOf[Int]) defn.IntType - else if (clazz == classOf[Long]) defn.LongType - else if (clazz == classOf[Float]) defn.FloatType - else if (clazz == classOf[Double]) defn.DoubleType - else defn.UnitType - else if (clazz.isArray) - defn.ArrayType.appliedTo(Type_ofErasedClass(clazz.getComponentType)) - else if (clazz.isMemberClass) { - val name = clazz.getSimpleName.toTypeName - val enclosing = Type_ofErasedClass(clazz.getEnclosingClass) - if (enclosing.member(name).exists) enclosing.select(name) - else - enclosing.classSymbol.companionModule.termRef.select(name) - } - else getClassIfDefined(clazz.getCanonicalName).typeRef - - def Type_isTypeEq(self: Type)(that: Type): Boolean = self =:= that - - def Type_isSubType(self: Type)(that: Type): Boolean = self <:< that - - def Type_widen(self: Type): Type = self.widen - - def Type_widenTermRefExpr(self: Type): Type = self.widenTermRefExpr - - def Type_dealias(self: Type): Type = self.dealias - - def Type_simplified(self: Type): Type = self.simplified - - def Type_classSymbol(self: Type): Option[Symbol] = - if (self.classSymbol.exists) Some(self.classSymbol.asClass) else None - - def Type_typeSymbol(self: Type): Symbol = self.typeSymbol - - def Type_termSymbol(self: Type): Symbol = self.termSymbol - - def Type_isSingleton(self: Type): Boolean = self.isSingleton - - def Type_memberType(self: Type)(member: Symbol): Type = - member.info.asSeenFrom(self, member.owner) - - def Type_baseClasses(self: Type): List[Symbol] = - self.baseClasses - - def Type_baseType(self: Type)(cls: Symbol): Type = - self.baseType(cls) - - def Type_derivesFrom(self: Type)(cls: Symbol): Boolean = - self.derivesFrom(cls) - - def Type_isFunctionType(self: Type): Boolean = - defn.isFunctionType(self) - - def Type_isContextFunctionType(self: Type): Boolean = - defn.isContextFunctionType(self) - - def Type_isErasedFunctionType(self: Type): Boolean = - defn.isErasedFunctionType(self) - - def Type_isDependentFunctionType(self: Type): Boolean = { - val tpNoRefinement = self.dropDependentRefinement - tpNoRefinement != self && defn.isNonRefinedFunction(tpNoRefinement) - } - - def Type_select(self: Type)(sym: Symbol): Type = - self.select(sym) - - def Type_appliedTo(self: Type)(targs: List[Type]): Type = - self.appliedTo(targs) - - type ConstantType = Types.ConstantType - - def ConstantType_TypeTest: TypeTest[Type, ConstantType] = new { - def runtimeClass: Class[?] = classOf[ConstantType] - override def unapply(x: Any): Option[ConstantType] = x match - case tpe: Types.ConstantType => Some(tpe) - case _ => None - } - - def ConstantType_apply(const: Constant): ConstantType = - Types.ConstantType(const) - - def ConstantType_constant(self: ConstantType): Constant = self.value - - type TermRef = Types.NamedType - - def TermRef_TypeTest: TypeTest[Type, TermRef] = new { - def runtimeClass: Class[?] = classOf[TermRef] - override def unapply(x: Any): Option[TermRef] = x match - case tp: Types.TermRef => Some(tp) - case _ => None - } - - def TermRef_apply(qual: Type, name: String): TermRef = - Types.TermRef(qual, name.toTermName) - - def TermRef_qualifier(self: TermRef): Type = self.prefix - - def TermRef_name(self: TermRef): String = self.name.toString - - type TypeRef = Types.NamedType - - def TypeRef_TypeTest: TypeTest[Type, TypeRef] = new { - def runtimeClass: Class[?] = classOf[TypeRef] - override def unapply(x: Any): Option[TypeRef] = x match - case tp: Types.TypeRef => Some(tp) - case _ => None - } - - def TypeRef_qualifier(self: TypeRef): Type = self.prefix - - def TypeRef_name(self: TypeRef): String = self.name.toString - - def TypeRef_isOpaqueAlias(self: TypeRef): Boolean = self.symbol.isOpaqueAlias - - def TypeRef_translucentSuperType(self: TypeRef): Type = self.translucentSuperType - - type NamedTermRef = Types.NamedType - - def NamedTermRef_TypeTest: TypeTest[Type, NamedTermRef] = new { - def runtimeClass: Class[?] = classOf[NamedTermRef] - override def unapply(x: Any): Option[NamedTermRef] = x match - case tpe: Types.NamedType => - tpe.designator match { - case name: Names.TermName => Some(tpe) - case _ => None - } - case _ => None - } - - def NamedTermRef_name(self: NamedTermRef): String = self.name.toString - def NamedTermRef_qualifier(self: NamedTermRef): Type = self.prefix - - type SuperType = Types.SuperType - - def SuperType_TypeTest: TypeTest[Type, SuperType] = new { - def runtimeClass: Class[?] = classOf[SuperType] - override def unapply(x: Any): Option[SuperType] = x match - case tpe: Types.SuperType => Some(tpe) - case _ => None - } - - def SuperType_apply(thistpe: Type, supertpe: Type): SuperType = - Types.SuperType(thistpe, supertpe) - - def SuperType_thistpe(self: SuperType): Type = self.thistpe - def SuperType_supertpe(self: SuperType): Type = self.supertpe - - type Refinement = Types.RefinedType - - def Refinement_TypeTest: TypeTest[Type, Refinement] = new { - def runtimeClass: Class[?] = classOf[Refinement] - override def unapply(x: Any): Option[Refinement] = x match - case tpe: Types.RefinedType => Some(tpe) - case _ => None - } - - def Refinement_apply(parent: Type, name: String, info: Type): Refinement = { - val name1 = - info match - case _: TypeBounds => name.toTypeName - case _ => name.toTermName - Types.RefinedType(parent, name1, info) - } - - def Refinement_parent(self: Refinement): Type = self.parent - def Refinement_name(self: Refinement): String = self.refinedName.toString - def Refinement_info(self: Refinement): Type = self.refinedInfo - - type AppliedType = Types.AppliedType - - def AppliedType_TypeTest: TypeTest[Type, AppliedType] = new { - def runtimeClass: Class[?] = classOf[AppliedType] - override def unapply(x: Any): Option[AppliedType] = x match - case tpe: Types.AppliedType => Some(tpe) - case _ => None - } - - def AppliedType_tycon(self: AppliedType): Type = self.tycon - def AppliedType_args(self: AppliedType): List[Type] = self.args - - type AnnotatedType = Types.AnnotatedType - - def AnnotatedType_TypeTest: TypeTest[Type, AnnotatedType] = new { - def runtimeClass: Class[?] = classOf[AnnotatedType] - override def unapply(x: Any): Option[AnnotatedType] = x match - case tpe: Types.AnnotatedType => Some(tpe) - case _ => None - } - - def AnnotatedType_apply(underlying: Type, annot: Term): AnnotatedType = - Types.AnnotatedType(underlying, Annotations.Annotation(annot)) - - def AnnotatedType_underlying(self: AnnotatedType): Type = self.underlying.stripTypeVar - def AnnotatedType_annot(self: AnnotatedType): Term = self.annot.tree - - type AndType = Types.AndType - - def AndType_TypeTest: TypeTest[Type, AndType] = new { - def runtimeClass: Class[?] = classOf[AndType] - override def unapply(x: Any): Option[AndType] = x match - case tpe: Types.AndType => Some(tpe) - case _ => None - } - - def AndType_apply(lhs: Type, rhs: Type): AndType = - Types.AndType(lhs, rhs) - - def AndType_left(self: AndType): Type = self.tp1.stripTypeVar - def AndType_right(self: AndType): Type = self.tp2.stripTypeVar - - type OrType = Types.OrType - - def OrType_TypeTest: TypeTest[Type, OrType] = new { - def runtimeClass: Class[?] = classOf[OrType] - override def unapply(x: Any): Option[OrType] = x match - case tpe: Types.OrType => Some(tpe) - case _ => None - } - - def OrType_apply(lhs: Type, rhs: Type): OrType = - Types.OrType(lhs, rhs) - - def OrType_left(self: OrType): Type = self.tp1.stripTypeVar - def OrType_right(self: OrType): Type = self.tp2.stripTypeVar - - type MatchType = Types.MatchType - - def MatchType_TypeTest: TypeTest[Type, MatchType] = new { - def runtimeClass: Class[?] = classOf[MatchType] - override def unapply(x: Any): Option[MatchType] = x match - case tpe: Types.MatchType => Some(tpe) - case _ => None - } - - def MatchType_apply(bound: Type, scrutinee: Type, cases: List[Type]): MatchType = - Types.MatchType(bound, scrutinee, cases) - - def MatchType_bound(self: MatchType): Type = self.bound - def MatchType_scrutinee(self: MatchType): Type = self.scrutinee - def MatchType_cases(self: MatchType): List[Type] = self.cases - - type ByNameType = Types.ExprType - - def ByNameType_TypeTest: TypeTest[Type, ByNameType] = new { - def runtimeClass: Class[?] = classOf[ByNameType] - override def unapply(x: Any): Option[ByNameType] = x match - case tpe: Types.ExprType => Some(tpe) - case _ => None - } - - def ByNameType_apply(underlying: Type): Type = Types.ExprType(underlying) - - def ByNameType_underlying(self: ByNameType): Type = self.resType.stripTypeVar - - type ParamRef = Types.ParamRef - - def ParamRef_TypeTest: TypeTest[Type, ParamRef] = new { - def runtimeClass: Class[?] = classOf[ParamRef] - override def unapply(x: Any): Option[ParamRef] = x match - case tpe: Types.TypeParamRef => Some(tpe) - case tpe: Types.TermParamRef => Some(tpe) - case _ => None - } - - def ParamRef_binder(self: ParamRef): LambdaType = - self.binder.asInstanceOf[LambdaType] // Cast to tpd - def ParamRef_paramNum(self: ParamRef): Int = self.paramNum - - type ThisType = Types.ThisType - - def ThisType_TypeTest: TypeTest[Type, ThisType] = new { - def runtimeClass: Class[?] = classOf[ThisType] - override def unapply(x: Any): Option[ThisType] = x match - case tpe: Types.ThisType => Some(tpe) - case _ => None - } - - def ThisType_tref(self: ThisType): Type = self.tref - - type RecursiveThis = Types.RecThis - - def RecursiveThis_TypeTest: TypeTest[Type, RecursiveThis] = new { - def runtimeClass: Class[?] = classOf[RecursiveThis] - override def unapply(x: Any): Option[RecursiveThis] = x match - case tpe: Types.RecThis => Some(tpe) - case _ => None - } - - def RecursiveThis_binder(self: RecursiveThis): RecursiveType = self.binder - - type RecursiveType = Types.RecType - - def RecursiveType_TypeTest: TypeTest[Type, RecursiveType] = new { - def runtimeClass: Class[?] = classOf[RecursiveType] - override def unapply(x: Any): Option[RecursiveType] = x match - case tpe: Types.RecType => Some(tpe) - case _ => None - } - - def RecursiveType_apply(parentExp: RecursiveType => Type): RecursiveType = - Types.RecType(parentExp) - - def RecursiveType_underlying(self: RecursiveType): Type = self.underlying.stripTypeVar - - def RecursiveThis_recThis(self: RecursiveType): RecursiveThis = self.recThis - - type LambdaType = Types.LambdaType - - type MethodType = Types.MethodType - - def MethodType_TypeTest: TypeTest[Type, MethodType] = new { - def runtimeClass: Class[?] = classOf[MethodType] - override def unapply(x: Any): Option[MethodType] = x match - case tpe: Types.MethodType => Some(tpe) - case _ => None - } - - def MethodType_apply(paramNames: List[String])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type): MethodType = - Types.MethodType(paramNames.map(_.toTermName))(paramInfosExp, resultTypeExp) - - def MethodType_isErased(self: MethodType): Boolean = self.isErasedMethod - def MethodType_isImplicit(self: MethodType): Boolean = self.isImplicitMethod - def MethodType_param(self: MethodType, idx: Int): Type = self.newParamRef(idx) - def MethodType_paramNames(self: MethodType): List[String] = self.paramNames.map(_.toString) - def MethodType_paramTypes(self: MethodType): List[Type] = self.paramInfos - def MethodType_resType(self: MethodType): Type = self.resType - - type PolyType = Types.PolyType - - def PolyType_TypeTest: TypeTest[Type, PolyType] = new { - def runtimeClass: Class[?] = classOf[PolyType] - override def unapply(x: Any): Option[PolyType] = x match - case tpe: Types.PolyType => Some(tpe) - case _ => None - } - - def PolyType_apply(paramNames: List[String])(paramBoundsExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type): PolyType = - Types.PolyType(paramNames.map(_.toTypeName))(paramBoundsExp, resultTypeExp) - - def PolyType_param(self: PolyType, idx: Int): Type = self.newParamRef(idx) - def PolyType_paramNames(self: PolyType): List[String] = self.paramNames.map(_.toString) - def PolyType_paramBounds(self: PolyType): List[TypeBounds] = self.paramInfos - def PolyType_resType(self: PolyType): Type = self.resType - - type TypeLambda = Types.TypeLambda - - def TypeLambda_TypeTest: TypeTest[Type, TypeLambda] = new { - def runtimeClass: Class[?] = classOf[TypeLambda] - override def unapply(x: Any): Option[TypeLambda] = x match - case tpe: Types.TypeLambda => Some(tpe) - case _ => None - } - - def TypeLambda_apply(paramNames: List[String], boundsFn: TypeLambda => List[TypeBounds], bodyFn: TypeLambda => Type): TypeLambda = - Types.HKTypeLambda(paramNames.map(_.toTypeName))(boundsFn, bodyFn) - - def TypeLambda_paramNames(self: TypeLambda): List[String] = self.paramNames.map(_.toString) - def TypeLambda_paramBounds(self: TypeLambda): List[TypeBounds] = self.paramInfos - def TypeLambda_param(self: TypeLambda, idx: Int): Type = - self.newParamRef(idx) - def TypeLambda_resType(self: TypeLambda): Type = self.resType - - type NoPrefix = Types.NoPrefix.type - - def NoPrefix_TypeTest: TypeTest[Type, NoPrefix] = new { - def runtimeClass: Class[?] = classOf[Types.NoPrefix.type] - override def unapply(x: Any): Option[NoPrefix] = - if (x == Types.NoPrefix) Some(Types.NoPrefix) else None - } - - type TypeBounds = Types.TypeBounds - - def TypeBounds_TypeTest: TypeTest[Type, TypeBounds] = new { - def runtimeClass: Class[?] = classOf[TypeBounds] - override def unapply(x: Any): Option[TypeBounds] = x match - case x: Types.TypeBounds => Some(x) - case _ => None - } - - def TypeBounds_apply(low: Type, hi: Type): TypeBounds = - Types.TypeBounds(low, hi) - - def TypeBounds_low(self: TypeBounds): Type = self.lo - def TypeBounds_hi(self: TypeBounds): Type = self.hi - - ////////////////////// - // IMPORT SELECTORS // - ////////////////////// - - type ImportSelector = untpd.ImportSelector - - type SimpleSelector = untpd.ImportSelector - - def SimpleSelector_TypeTest: TypeTest[ImportSelector, SimpleSelector] = new { - def runtimeClass: Class[?] = classOf[SimpleSelector] - override def unapply(x: Any): Option[SimpleSelector] = x match - case x: untpd.ImportSelector if x.renamed.isEmpty => Some(x) - case _ => None // TODO: handle import bounds - } - - def SimpleSelector_selection(self: SimpleSelector): Id = self.imported - - type RenameSelector = untpd.ImportSelector - - def RenameSelector_TypeTest: TypeTest[ImportSelector, RenameSelector] = new { - def runtimeClass: Class[?] = classOf[RenameSelector] - override def unapply(x: Any): Option[RenameSelector] = x match - case x: untpd.ImportSelector if !x.renamed.isEmpty => Some(x) - case _ => None - } - - def RenameSelector_from(self: RenameSelector): Id = - self.imported - def RenameSelector_to(self: RenameSelector): Id = - self.renamed.asInstanceOf[untpd.Ident] - - type OmitSelector = untpd.ImportSelector - - def OmitSelector_TypeTest: TypeTest[ImportSelector, OmitSelector] = new { - def runtimeClass: Class[?] = classOf[OmitSelector] - override def unapply(x: Any): Option[OmitSelector] = x match { - case self: untpd.ImportSelector => - self.renamed match - case Trees.Ident(nme.WILDCARD) => Some(self) - case _ => None - case _ => None - } - - } - - def SimpleSelector_omitted(self: OmitSelector): Id = - self.imported - - - ///////////////// - // IDENTIFIERS // - ///////////////// - - type Id = untpd.Ident - - def Id_pos(self: Id): Position = self.sourcePos - - def Id_name(self: Id): String = self.name.toString - - - //////////////// - // SIGNATURES // - //////////////// - - type Signature = core.Signature - - def Signature_paramSigs(self: Signature): List[String | Int] = - self.paramsSig.map { - case paramSig: core.Names.TypeName => - paramSig.toString - case paramSig: Int => - paramSig - } - - def Signature_resultSig(self: Signature): String = - self.resSig.toString - - - /////////////// - // POSITIONS // - /////////////// - - type Position = util.SourcePosition - - def Position_start(self: Position): Int = self.start - - def Position_end(self: Position): Int = self.end - - def Position_exists(self: Position): Boolean = self.exists - - def Position_sourceFile(self: Position): SourceFile = self.source - - def Position_startLine(self: Position): Int = self.startLine - - def Position_endLine(self: Position): Int = self.endLine - - def Position_startColumn(self: Position): Int = self.startColumn - - def Position_endColumn(self: Position): Int = self.endColumn - - def Position_sourceCode(self: Position): String = - new String(self.source.content(), self.start, self.end - self.start) - - - ////////////////// - // SOURCE FILES // - ////////////////// - - type SourceFile = util.SourceFile - - def SourceFile_jpath(self: SourceFile): java.nio.file.Path = self.file.jpath - - def SourceFile_content(self: SourceFile): String = new String(self.content()) - - - ////////////// - // COMMENTS // - ////////////// - - type Comment = core.Comments.Comment - - def Comment_raw(self: Comment): String = self.raw - def Comment_expanded(self: Comment): Option[String] = self.expanded - def Comment_usecases(self: Comment): List[(String, Option[DefDef])] = self.usecases.map { uc => (uc.code, uc.tpdCode) } - - - /////////////// - // CONSTANTS // - /////////////// - - type Constant = Constants.Constant - - def Constant_value(const: Constant): Any = const.value - - def matchConstant(constant: Constant): Option[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type] = - Some(constant.value.asInstanceOf[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type]) - - def matchConstant_ClassTag(x: Constant): Option[Type] = - if (x.tag == Constants.ClazzTag) Some(x.typeValue) else None - - def Constant_apply(x: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type): Constant = - Constants.Constant(x) - - def Constant_ClassTag_apply(x: Type): Constant = Constants.Constant(x) - - - ///////////// - // SYMBOLS // - ///////////// - - type Symbol = core.Symbols.Symbol - - def Symbol_currentOwner(using ctx: Context): Symbol = ctx.owner - - def Symbol_owner(self: Symbol): Symbol = self.owner - def Symbol_maybeOwner(self: Symbol): Symbol = self.maybeOwner - - def Symbol_flags(self: Symbol): Flags = self.flags - - def Symbol_tree(self: Symbol): Tree = - FromSymbol.definitionFromSym(self) - - def Symbol_privateWithin(self: Symbol): Option[Type] = { - val within = self.privateWithin - if (within.exists && !self.is(core.Flags.Protected)) Some(within.typeRef) - else None - } - - def Symbol_protectedWithin(self: Symbol): Option[Type] = { - val within = self.privateWithin - if (within.exists && self.is(core.Flags.Protected)) Some(within.typeRef) - else None - } - - def Symbol_name(self: Symbol): String = self.name.toString - - def Symbol_fullName(self: Symbol): String = self.fullName.toString - - def Symbol_pos(self: Symbol): Position = self.sourcePos - - def Symbol_localContext(self: Symbol): Context = - if (self.exists) ctx.withOwner(self) - else ctx - - def Symbol_comment(self: Symbol): Option[Comment] = { - import dotty.tools.dotc.core.Comments.CommentsContext - val docCtx = ctx.docCtx.getOrElse { - throw new RuntimeException( - "DocCtx could not be found and comments are unavailable. This is a compiler-internal error." - ) - } - docCtx.docstring(self) - } - def Symbol_annots(self: Symbol): List[Term] = - self.annotations.flatMap { - case _: core.Annotations.BodyAnnotation => Nil - case annot => annot.tree :: Nil - } - - def Symbol_isDefinedInCurrentRun(self: Symbol): Boolean = - self.topLevelClass.asClass.isDefinedInCurrentRun - - def Symbol_isLocalDummy(self: Symbol): Boolean = self.isLocalDummy - def Symbol_isRefinementClass(self: Symbol): Boolean = self.isRefinementClass - def Symbol_isAliasType(self: Symbol): Boolean = self.isAliasType - def Symbol_isAnonymousClass(self: Symbol): Boolean = self.isAnonymousClass - def Symbol_isAnonymousFunction(self: Symbol): Boolean = self.isAnonymousFunction - def Symbol_isAbstractType(self: Symbol): Boolean = self.isAbstractType - def Symbol_isClassConstructor(self: Symbol): Boolean = self.isClassConstructor - - def Symbol_fields(self: Symbol): List[Symbol] = - self.unforcedDecls.filter(isField) - - def Symbol_field(self: Symbol)(name: String): Symbol = { - val sym = self.unforcedDecls.find(sym => sym.name == name.toTermName) - if (isField(sym)) sym else core.Symbols.NoSymbol - } - - def Symbol_classMethod(self: Symbol)(name: String): List[Symbol] = - self.typeRef.decls.iterator.collect { - case sym if isMethod(sym) && sym.name.toString == name => sym.asTerm - }.toList - - def Symbol_typeMembers(self: Symbol): List[Symbol] = - self.unforcedDecls.filter(_.isType) - - def Symbol_typeMember(self: Symbol)(name: String): Symbol = - self.unforcedDecls.find(sym => sym.name == name.toTypeName) - - def Symbol_classMethods(self: Symbol): List[Symbol] = - self.typeRef.decls.iterator.collect { - case sym if isMethod(sym) => sym.asTerm - }.toList - - private def appliedTypeRef(sym: Symbol): Type = sym.typeRef.appliedTo(sym.typeParams.map(_.typeRef)) - - def Symbol_method(self: Symbol)(name: String): List[Symbol] = - appliedTypeRef(self).allMembers.iterator.map(_.symbol).collect { - case sym if isMethod(sym) && sym.name.toString == name => sym.asTerm - }.toList - - def Symbol_methods(self: Symbol): List[Symbol] = - appliedTypeRef(self).allMembers.iterator.map(_.symbol).collect { - case sym if isMethod(sym) => sym.asTerm - }.toList - - private def isMethod(sym: Symbol): Boolean = - sym.isTerm && sym.is(Flags.Method) && !sym.isConstructor - - def Symbol_paramSymss(self: Symbol): List[List[Symbol]] = - self.paramSymss - - def Symbol_primaryConstructor(self: Symbol): Symbol = - self.primaryConstructor - - def Symbol_caseFields(self: Symbol): List[Symbol] = - if (!self.isClass) Nil - else self.asClass.paramAccessors.collect { - case sym if sym.is(Flags.CaseAccessor) => sym.asTerm - } - - def Symbol_children(self: Symbol): List[Symbol] = - self.children - - private def isField(sym: Symbol): Boolean = sym.isTerm && !sym.is(Flags.Method) - - def Symbol_requiredPackage(path: String): Symbol = requiredPackage(path) - def Symbol_requiredClass(path: String): Symbol = requiredClass(path) - def Symbol_requiredModule(path: String): Symbol = requiredModule(path) - def Symbol_requiredMethod(path: String): Symbol = requiredMethod(path) - - def Symbol_of(fullName: String): Symbol = - requiredClass(fullName) - - def Symbol_newMethod(parent: Symbol, name: String, flags: Flags, tpe: Type, privateWithin: Symbol): Symbol = - newSymbol(parent, name.toTermName, flags | Flags.Method, tpe, privateWithin) - - def Symbol_newVal(parent: Symbol, name: String, flags: Flags, tpe: Type, privateWithin: Symbol): Symbol = - newSymbol(parent, name.toTermName, flags, tpe, privateWithin) - - def Symbol_newBind(parent: Symbol, name: String, flags: Flags, tpe: Type): Symbol = - newSymbol(parent, name.toTermName, flags | Case, tpe) - - def Symbol_isTypeParam(self: Symbol): Boolean = - self.isTypeParam - - def Symbol_isType(symbol: Symbol): Boolean = - symbol.isType - - def Symbol_isTerm(symbol: Symbol): Boolean = - symbol.isTerm - - def Symbol_isPackageDef(symbol: Symbol): Boolean = - symbol.is(Flags.Package) - - def Symbol_isClassDef(symbol: Symbol): Boolean = - symbol.isClass - - def Symbol_isTypeDef(symbol: Symbol): Boolean = - symbol.isType && !symbol.isClass && !symbol.is(Flags.Case) - - def Symbol_isValDef(symbol: Symbol): Boolean = - symbol.isTerm && !symbol.is(core.Flags.Method) && !symbol.is(core.Flags.Case/*, FIXME add this check and fix sourcecode butNot = Enum | Module*/) - - def Symbol_isDefDef(symbol: Symbol): Boolean = - symbol.is(core.Flags.Method) - - def Symbol_isBind(symbol: Symbol): Boolean = - symbol.is(core.Flags.Case, butNot = Enum | Module) && !symbol.isClass - - def Symbol_signature(self: Symbol): Signature = - self.signature - - - def Symbol_moduleClass(self: Symbol): Symbol = self.moduleClass - - def Symbol_companionClass(self: Symbol): Symbol = self.companionClass - - def Symbol_companionModule(self: Symbol): Symbol = self.companionModule - - def Symbol_noSymbol: Symbol = core.Symbols.NoSymbol - - - /////////// - // FLAGS // - /////////// - - type Flags = core.Flags.FlagSet - - /** Is the given flag set a subset of this flag sets */ - def Flags_is(self: Flags)(that: Flags): Boolean = self.isAllOf(that) - - /** Union of the two flag sets */ - def Flags_or(self: Flags)(that: Flags): Flags = self | that - - /** Intersection of the two flag sets */ - def Flags_and(self: Flags)(that: Flags): Flags = self & that - - def Flags_Abstract: Flags = core.Flags.Abstract - def Flags_Artifact: Flags = core.Flags.Artifact - def Flags_Case: Flags = core.Flags.Case - def Flags_CaseAcessor: Flags = core.Flags.CaseAccessor - def Flags_Contravariant: Flags = core.Flags.Contravariant - def Flags_Covariant: Flags = core.Flags.Covariant - def Flags_EmptyFlags: Flags = core.Flags.EmptyFlags - def Flags_Enum: Flags = core.Flags.Enum - def Flags_Erased: Flags = core.Flags.Erased - def Flags_ExtensionMethod: Flags = core.Flags.ExtensionMethod - def Flags_FieldAccessor: Flags = core.Flags.Accessor - def Flags_Final: Flags = core.Flags.Final - def Flags_Given: Flags = core.Flags.Given - def Flags_HasDefault: Flags = core.Flags.HasDefault - def Flags_Implicit: Flags = core.Flags.Implicit - def Flags_Inline: Flags = core.Flags.Inline - def Flags_JavaDefined: Flags = core.Flags.JavaDefined - def Flags_Lazy: Flags = core.Flags.Lazy - def Flags_Local: Flags = core.Flags.Local - def Flags_Macro: Flags = core.Flags.Macro - def Flags_ModuleClass: Flags = core.Flags.ModuleClass - def Flags_Mutable: Flags = core.Flags.Mutable - def Flags_Object: Flags = core.Flags.Module - def Flags_Open: Flags = core.Flags.Open - def Flags_Override: Flags = core.Flags.Override - def Flags_Package: Flags = core.Flags.Package - def Flags_Param: Flags = core.Flags.Param - def Flags_ParamAccessor: Flags = core.Flags.ParamAccessor - def Flags_Private: Flags = core.Flags.Private - def Flags_PrivateLocal: Flags = core.Flags.PrivateLocal - def Flags_Protected: Flags = core.Flags.Protected - def Flags_Scala2X: Flags = core.Flags.Scala2x - def Flags_Sealed: Flags = core.Flags.Sealed - def Flags_StableRealizable: Flags = core.Flags.StableRealizable - def Flags_Static: Flags = core.Flags.JavaStatic - def Flags_Synthetic: Flags = core.Flags.Synthetic - def Flags_Trait: Flags = core.Flags.Trait - - - ///////////////// - // DEFINITIONS // - ///////////////// - - // Symbols - - def Definitions_RootPackage: Symbol = defn.RootPackage - def Definitions_RootClass: Symbol = defn.RootClass - - def Definitions_EmptyPackageClass: Symbol = defn.EmptyPackageClass - - def Definitions_ScalaPackage: Symbol = defn.ScalaPackageVal - def Definitions_ScalaPackageClass: Symbol = defn.ScalaPackageClass - - def Definitions_AnyClass: Symbol = defn.AnyClass - def Definitions_AnyValClass: Symbol = defn.AnyValClass - def Definitions_ObjectClass: Symbol = defn.ObjectClass - def Definitions_AnyRefClass: Symbol = defn.AnyRefAlias - def Definitions_NullClass: Symbol = defn.AnyClass - def Definitions_NothingClass: Symbol = defn.NothingClass - def Definitions_UnitClass: Symbol = defn.UnitClass - def Definitions_ByteClass: Symbol = defn.ByteClass - def Definitions_ShortClass: Symbol = defn.ShortClass - def Definitions_CharClass: Symbol = defn.CharClass - def Definitions_IntClass: Symbol = defn.IntClass - def Definitions_LongClass: Symbol = defn.LongClass - def Definitions_FloatClass: Symbol = defn.FloatClass - def Definitions_DoubleClass: Symbol = defn.DoubleClass - def Definitions_BooleanClass: Symbol = defn.BooleanClass - def Definitions_StringClass: Symbol = defn.StringClass - def Definitions_ClassClass: Symbol = defn.ClassClass - def Definitions_ArrayClass: Symbol = defn.ArrayClass - def Definitions_PredefModule: Symbol = defn.ScalaPredefModule.asTerm - def Definitions_Predef_classOf: Symbol = defn.Predef_classOf.asTerm - - def Definitions_JavaLangPackage: Symbol = defn.JavaLangPackageVal - - def Definitions_ArrayModule: Symbol = defn.ArrayClass.companionModule.asTerm - - def Definitions_Array_apply: Symbol = defn.Array_apply.asTerm - def Definitions_Array_clone: Symbol = defn.Array_clone.asTerm - def Definitions_Array_length: Symbol = defn.Array_length.asTerm - def Definitions_Array_update: Symbol = defn.Array_update.asTerm - - def Definitions_RepeatedParamClass: Symbol = defn.RepeatedParamClass - def Definitions_RepeatedAnnot: Symbol = defn.RepeatedAnnot - - def Definitions_OptionClass: Symbol = defn.OptionClass - def Definitions_NoneModule: Symbol = defn.NoneModule - def Definitions_SomeModule: Symbol = defn.SomeClass.companionModule.asTerm - - def Definitions_ProductClass: Symbol = defn.ProductClass - def Definitions_FunctionClass(arity: Int, isImplicit: Boolean, isErased: Boolean): Symbol = - defn.FunctionClass(arity, isImplicit, isErased).asClass - def Definitions_TupleClass(arity: Int): Symbol = defn.TupleType(arity).classSymbol.asClass - def Definitions_isTupleClass(sym: Symbol): Boolean = defn.isTupleClass(sym) - - def Definitions_InternalQuotedMatcher_patternHole: Symbol = defn.InternalQuotedMatcher_patternHole - def Definitions_InternalQuotedMatcher_higherOrderHole: Symbol = defn.InternalQuotedMatcher_higherOrderHole - def Definitions_InternalQuotedMatcher_patternTypeAnnot: Symbol = defn.InternalQuotedMatcher_patternTypeAnnot - def Definitions_InternalQuotedMatcher_fromAboveAnnot: Symbol = defn.InternalQuotedMatcher_fromAboveAnnot - - // Types - - def Definitions_UnitType: Type = defn.UnitType - def Definitions_ByteType: Type = defn.ByteType - def Definitions_ShortType: Type = defn.ShortType - def Definitions_CharType: Type = defn.CharType - def Definitions_IntType: Type = defn.IntType - def Definitions_LongType: Type = defn.LongType - def Definitions_FloatType: Type = defn.FloatType - def Definitions_DoubleType: Type = defn.DoubleType - def Definitions_BooleanType: Type = defn.BooleanType - def Definitions_AnyType: Type = defn.AnyType - def Definitions_AnyValType: Type = defn.AnyValType - def Definitions_AnyRefType: Type = defn.AnyRefType - def Definitions_ObjectType: Type = defn.ObjectType - def Definitions_NothingType: Type = defn.NothingType - def Definitions_NullType: Type = defn.NullType - def Definitions_StringType: Type = defn.StringType - def Definitions_TupleType: Type = defn.TupleTypeRef - def Definitions_EmptyTupleType: Type = defn.EmptyTupleModule.termRef - def Definitions_NonEmptyTupleType: Type = defn.NonEmptyTupleClass.typeRef - def Definitions_TupleConsType: Type = defn.PairClass.typeRef - - /////////////// - // IMPLICITS // - /////////////// - - type ImplicitSearchResult = Tree - - def searchImplicit(tpe: Type): ImplicitSearchResult = - ctx.typer.inferImplicitArg(tpe, rootPosition.span) - - type ImplicitSearchSuccess = Tree - def ImplicitSearchSuccess_TypeTest: TypeTest[ImplicitSearchResult, ImplicitSearchSuccess] = new { - def runtimeClass: Class[?] = classOf[ImplicitSearchSuccess] - override def unapply(x: Any): Option[ImplicitSearchSuccess] = x match - case x: Tree @unchecked => - x.tpe match - case _: SearchFailureType => None - case _ => Some(x) - case _ => None - } - def ImplicitSearchSuccess_tree(self: ImplicitSearchSuccess): Term = self - - type ImplicitSearchFailure = Tree - def ImplicitSearchFailure_TypeTest: TypeTest[ImplicitSearchResult, ImplicitSearchFailure] = new { - def runtimeClass: Class[?] = classOf[ImplicitSearchFailure] - override def unapply(x: Any): Option[ImplicitSearchFailure] = x match - case x: Tree @unchecked => - x.tpe match - case _: SearchFailureType => Some(x) - case _ => None - case _ => None - } - def ImplicitSearchFailure_explanation(self: ImplicitSearchFailure): String = - self.tpe.asInstanceOf[SearchFailureType].explanation - - type DivergingImplicit = Tree - def DivergingImplicit_TypeTest: TypeTest[ImplicitSearchResult, DivergingImplicit] = new { - def runtimeClass: Class[?] = classOf[DivergingImplicit] - override def unapply(x: Any): Option[DivergingImplicit] = x match - case x: Tree @unchecked => - x.tpe match - case _: Implicits.DivergingImplicit => Some(x) - case _ => None - case _ => None - } - - type NoMatchingImplicits = Tree - def NoMatchingImplicits_TypeTest: TypeTest[ImplicitSearchResult, NoMatchingImplicits] = new { - def runtimeClass: Class[?] = classOf[NoMatchingImplicits] - override def unapply(x: Any): Option[NoMatchingImplicits] = x match - case x: Tree @unchecked => - x.tpe match - case _: Implicits.NoMatchingImplicits => Some(x) - case _ => None - case _ => None - } - - type AmbiguousImplicits = Tree - def AmbiguousImplicits_TypeTest: TypeTest[ImplicitSearchResult, AmbiguousImplicits] = new { - def runtimeClass: Class[?] = classOf[AmbiguousImplicits] - override def unapply(x: Any): Option[AmbiguousImplicits] = x match - case x: Tree @unchecked => - x.tpe match - case _: Implicits.AmbiguousImplicits => Some(x) - case _ => None - case _ => None - } - - def betaReduce(tree: Term): Option[Term] = - tree match - case app @ Apply(Select(fn, nme.apply), args) if defn.isFunctionType(fn.tpe) => - val app1 = transform.BetaReduce(app, fn, args) - if app1 eq app then None - else Some(app1.withSpan(tree.span)) - case Block(Nil, expr) => - for e <- betaReduce(expr) yield cpy.Block(tree)(Nil, e) - case Inlined(_, Nil, expr) => - betaReduce(expr) - case _ => - None - - def lambdaExtractor(fn: Term, paramTypes: List[Type]): Option[List[Term] => Term] = { - def rec(fn: Term, transformBody: Term => Term): Option[List[Term] => Term] = { - fn match { - case Inlined(call, bindings, expansion) => - // this case must go before closureDef to avoid dropping the inline node - rec(expansion, cpy.Inlined(fn)(call, bindings, _)) - case Typed(expr, tpt) => - val tpe = tpt.tpe.dropDependentRefinement - // we checked that this is a plain Function closure, so there will be an apply method with a MethodType - // and the expected signature based on param types - val expectedSig = Signature(Nil, tpnme.WILDCARD).prependTermParams(paramTypes, false) - val method = tpt.tpe.member(nme.apply).atSignature(expectedSig) - if method.symbol.is(Deferred) then - val methodType = method.info.asInstanceOf[MethodType] - // result might contain paramrefs, so we substitute them with arg termrefs - val resultTypeWithSubst = methodType.resultType.substParams(methodType, paramTypes) - rec(expr, Typed(_, TypeTree(resultTypeWithSubst).withSpan(tpt.span))) - else - None - case cl @ closureDef(ddef) => - def replace(body: Term, argRefs: List[Term]): Term = { - val paramSyms = ddef.vparamss.head.map(param => param.symbol) - val paramToVals = paramSyms.zip(argRefs).toMap - new TreeTypeMap( - oldOwners = ddef.symbol :: Nil, - newOwners = ctx.owner :: Nil, - treeMap = tree => paramToVals.get(tree.symbol).map(_.withSpan(tree.span)).getOrElse(tree) - ).transform(body) - } - Some(argRefs => replace(transformBody(ddef.rhs), argRefs)) - case Block(stats, expr) => - // this case must go after closureDef to avoid matching the closure - rec(expr, cpy.Block(fn)(stats, _)) - case _ => - None - } - } - rec(fn, identity) - } - - ///////////// - // HELPERS // - ///////////// - - private def optional[T <: Trees.Tree[?]](tree: T): Option[tree.type] = - if (tree.isEmpty) None else Some(tree) - - private def withDefaultPos[T <: Tree](fn: Context ?=> T): T = - fn(using ctx.withSource(rootPosition.source)).withSpan(rootPosition.span) - - def compilerId: Int = rootContext.outersIterator.toList.last.hashCode() -} diff --git a/compiler/src/dotty/tools/dotc/transform/TailRec.scala b/compiler/src/dotty/tools/dotc/transform/TailRec.scala index d6b17f3c82e1..0fe23dfd42c1 100644 --- a/compiler/src/dotty/tools/dotc/transform/TailRec.scala +++ b/compiler/src/dotty/tools/dotc/transform/TailRec.scala @@ -186,6 +186,7 @@ class TailRec extends MiniPhase { def tailArgOrPureExpr(stat: Tree): Boolean = stat match { case stat: ValDef if stat.name.is(TailTempName) || !stat.symbol.is(Mutable) => tailArgOrPureExpr(stat.rhs) case Assign(lhs: Ident, rhs) if lhs.symbol.name.is(TailLocalName) => tailArgOrPureExpr(rhs) + case Assign(lhs: Ident, rhs: Ident) if lhs.symbol == rhs.symbol => true case stat: Ident if stat.symbol.name.is(TailLocalName) => true case _ => tpd.isPureExpr(stat) } diff --git a/library/src-bootstrapped/scala/quoted/Liftable.scala b/library/src-bootstrapped/scala/quoted/Liftable.scala index e99f43a00077..e1ee9a06892e 100644 --- a/library/src-bootstrapped/scala/quoted/Liftable.scala +++ b/library/src-bootstrapped/scala/quoted/Liftable.scala @@ -59,10 +59,8 @@ object Liftable { /** Default liftable for Class[T] */ given ClassLiftable[T] as Liftable[Class[T]] = new Liftable[Class[T]] { def toExpr(x: Class[T]) = { - val qctx1 = scala.internal.tasty.CompilerInterface.quoteContextWithCompilerInterface(qctx) - import qctx1.tasty._ - val tpe = qctx1.tasty.Type_ofErasedClass(x) - Ref(defn.Predef_classOf).appliedToType(tpe).seal.asInstanceOf[Expr[Class[T]]] + import qctx.tasty._ + Ref(defn.Predef_classOf).appliedToType(Type.typeConstructorOf(x)).seal.asInstanceOf[Expr[Class[T]]] } } diff --git a/library/src/scala/internal/tasty/CompilerInterface.scala b/library/src/scala/internal/tasty/CompilerInterface.scala index 401774c1c2a6..1c01bef097c9 100644 --- a/library/src/scala/internal/tasty/CompilerInterface.scala +++ b/library/src/scala/internal/tasty/CompilerInterface.scala @@ -5,14 +5,7 @@ import scala.tasty.reflect._ import scala.internal.quoted.Unpickler /** Part of the reflection interface that needs to be implemented by the compiler */ -trait CompilerInterface extends scala.tasty.reflect.Types { - - /** Context of the macro expansion */ - def rootContext: Context - - /** Root position of this tasty context. For macros it corresponds to the expansion site. */ - def rootPosition: Position - +trait CompilerInterface { self: scala.tasty.Reflection => ////////////////////// // QUOTE UNPICKLING // @@ -29,1091 +22,14 @@ trait CompilerInterface extends scala.tasty.reflect.Types { def unpickleType(repr: Unpickler.PickledQuote, args: Unpickler.PickledArgs): TypeTree - ///////////////// - // Constraints // - ///////////////// - def Constraints_context[T]: scala.quoted.QuoteContext def Constraints_add(syms: List[Symbol]): Boolean def Constraints_approximation(sym: Symbol, fromBelow: Boolean): Type - //////////// - // Source // - //////////// - - /** Returns the source file being compiled. The path is relative to the current working directory. */ - def Source_path: java.nio.file.Path - - /** Returns true if we've tried to reflect on a Java class. */ - def Source_isJavaCompilationUnit: Boolean - - /** Returns true if we've tried to reflect on a Scala2 (non-Tasty) class. */ - def Source_isScala2CompilationUnit: Boolean - - /** Returns true if we've tried to reflect on a class that's already loaded (e.g. Option). */ - def Source_isAlreadyLoadedCompilationUnit: Boolean - - /** Class name of the current CompilationUnit */ - def Source_compilationUnitClassname: String - - /////////////// - // REPORTING // - /////////////// - - /** Report a compilation error with the given message at the given position */ - def error(msg: => String, pos: Position): Unit - - /** Report a compilation error with the given message at the given position range */ - def error(msg: => String, source: SourceFile, start: Int, end: Int): Unit - - /** Report a compilation warning with the given message at the given position */ - def warning(msg: => String, pos: Position): Unit - - /** Report a compilation warning with the given message at the given position range */ - def warning(msg: => String, source: SourceFile, start: Int, end: Int): Unit - - - ///////////// - // TREES // - ///////////// - - def Tree_pos(self: Tree): Position - def Tree_symbol(self: Tree): Symbol - - def PackageClause_TypeTest: TypeTest[Tree, PackageClause] - - def PackageClause_pid(self: PackageClause): Ref - def PackageClause_stats(self: PackageClause): List[Tree] - - def PackageClause_apply(pid: Ref, stats: List[Tree]): PackageClause - - def PackageClause_copy(original: Tree)(pid: Ref, stats: List[Tree]): PackageClause - - def Statement_TypeTest: TypeTest[Tree, Statement] - - def Import_TypeTest: TypeTest[Tree, Import] - - def Import_implied(self: Import): Boolean - def Import_expr(self: Import): Term - def Import_selectors(self: Import): List[ImportSelector] - - def Import_apply(iexpr: Term, selectors: List[ImportSelector]): Import - - def Import_copy(original: Tree)(expr: Term, selectors: List[ImportSelector]): Import - - def Definition_TypeTest: TypeTest[Tree, Definition] - - def Definition_name(self: Definition): String - - def PackageDef_TypeTest: TypeTest[Tree, PackageDef] - - def PackageDef_owner(self: PackageDef): PackageDef - def PackageDef_members(self: PackageDef): List[Statement] - - def ClassDef_TypeTest: TypeTest[Tree, ClassDef] - - def ClassDef_constructor(self: ClassDef): DefDef - def ClassDef_parents(self: ClassDef): List[Tree/* Term | TypeTree */] - def ClassDef_derived(self: ClassDef): List[TypeTree] - def ClassDef_self(self: ClassDef): Option[ValDef] - def ClassDef_body(self: ClassDef): List[Statement] - - def ClassDef_copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree/* Term | TypeTree */], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement]): ClassDef - - def TypeDef_TypeTest: TypeTest[Tree, TypeDef] - - def TypeDef_rhs(self: TypeDef): Tree /*TypeTree | TypeBoundsTree*/ - - def TypeDef_apply(symbol: Symbol): TypeDef - def TypeDef_copy(original: Tree)(name: String, rhs: Tree /*TypeTree | TypeBoundsTree*/): TypeDef - - def DefDef_TypeTest: TypeTest[Tree, DefDef] - - def DefDef_typeParams(self: DefDef): List[TypeDef] - def DefDef_paramss(self: DefDef): List[List[ValDef]] - def DefDef_returnTpt(self: DefDef): TypeTree - def DefDef_rhs(self: DefDef): Option[Term] - - def DefDef_apply(symbol: Symbol, rhsFn: List[Type] => List[List[Term]] => Option[Term]): DefDef - def DefDef_copy(original: Tree)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term]): DefDef - - def ValDef_TypeTest: TypeTest[Tree, ValDef] - - def ValDef_tpt(self: ValDef): TypeTree - def ValDef_rhs(self: ValDef): Option[Term] - - def ValDef_apply(symbol: Symbol, rhs: Option[Term]): ValDef - def ValDef_copy(original: Tree)(name: String, tpt: TypeTree, rhs: Option[Term]): ValDef - - def Term_TypeTest: TypeTest[Tree, Term] - - def Term_tpe(self: Term): Type - def Term_underlyingArgument(self: Term): Term - def Term_underlying(self: Term): Term - def Term_etaExpand(term: Term): Term - - def Ref_TypeTest: TypeTest[Tree, Ref] - - /** A tree representing the same reference as the given type */ - def Ref_term(tp: TermRef): Ref - - def Ref_apply(sym: Symbol): Ref - - def Ident_TypeTest: TypeTest[Tree, Ident] - - def Ident_name(self: Ident): String - - def Ident_apply(tmref: TermRef): Term - def Ident_copy(original: Tree)(name: String): Ident - - def Select_TypeTest: TypeTest[Tree, Select] - - def Select_qualifier(self: Select): Term - def Select_name(self: Select): String - def Select_signature(self: Select): Option[Signature] - - def Select_apply(qualifier: Term, symbol: Symbol): Select - def Select_unique(qualifier: Term, name: String): Select - // TODO rename, this returns an Apply and not a Select - def Select_overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term]): Apply - def Select_copy(original: Tree)(qualifier: Term, name: String): Select - - def Literal_TypeTest: TypeTest[Tree, Literal] - - def Literal_constant(self: Literal): Constant - - def Literal_apply(constant: Constant): Literal - def Literal_copy(original: Tree)(constant: Constant): Literal - - def This_TypeTest: TypeTest[Tree, This] - - def This_id(self: This): Option[Id] - - def This_apply(cls: Symbol): This - def This_copy(original: Tree)(qual: Option[Id]): This - - def New_TypeTest: TypeTest[Tree, New] - - def New_tpt(self: New): TypeTree - - def New_apply(tpt: TypeTree): New - def New_copy(original: Tree)(tpt: TypeTree): New - - def NamedArg_TypeTest: TypeTest[Tree, NamedArg] - - def NamedArg_name(self: NamedArg): String - def NamedArg_value(self: NamedArg): Term - - def NamedArg_apply(name: String, arg: Term): NamedArg - def NamedArg_copy(original: Tree)(name: String, arg: Term): NamedArg - - def Apply_TypeTest: TypeTest[Tree, Apply] - - def Apply_fun(self: Apply): Term - def Apply_args(self: Apply): List[Term] - - def Apply_apply(fn: Term, args: List[Term]): Apply - def Apply_copy(original: Tree)(fun: Term, args: List[Term]): Apply - - def TypeApply_TypeTest: TypeTest[Tree, TypeApply] - - def TypeApply_fun(self: TypeApply): Term - def TypeApply_args(self: TypeApply): List[TypeTree] - - def TypeApply_apply(fn: Term, args: List[TypeTree]): TypeApply - def TypeApply_copy(original: Tree)(fun: Term, args: List[TypeTree]): TypeApply - - def Super_TypeTest: TypeTest[Tree, Super] - - def Super_qualifier(self: Super): Term - def Super_id(self: Super): Option[Id] - - def Super_apply(qual: Term, mix: Option[Id]): Super - def Super_copy(original: Tree)(qual: Term, mix: Option[Id]): Super - - def Typed_TypeTest: TypeTest[Tree, Typed] - - def Typed_expr(self: Typed): Term - def Typed_tpt(self: Typed): TypeTree - - def Typed_apply(expr: Term, tpt: TypeTree): Typed - def Typed_copy(original: Tree)(expr: Term, tpt: TypeTree): Typed - - def Assign_TypeTest: TypeTest[Tree, Assign] - - def Assign_lhs(self: Assign): Term - def Assign_rhs(self: Assign): Term - - def Assign_apply(lhs: Term, rhs: Term): Assign - def Assign_copy(original: Tree)(lhs: Term, rhs: Term): Assign - - def Block_TypeTest: TypeTest[Tree, Block] - - def Block_statements(self: Block): List[Statement] - def Block_expr(self: Block): Term - - def Block_apply(stats: List[Statement], expr: Term): Block - def Block_copy(original: Tree)(stats: List[Statement], expr: Term): Block - - def Closure_TypeTest: TypeTest[Tree, Closure] - - def Closure_meth(self: Closure): Term - def Closure_tpeOpt(self: Closure): Option[Type] - - def Closure_apply(meth: Term, tpe: Option[Type]): Closure - def Closure_copy(original: Tree)(meth: Tree, tpe: Option[Type]): Closure - - def Lambda_apply(tpe: MethodType, rhsFn: List[Tree] => Tree): Block - - def If_TypeTest: TypeTest[Tree, If] - - def If_cond(self: If): Term - def If_thenp(self: If): Term - def If_elsep(self: If): Term - - def If_apply(cond: Term, thenp: Term, elsep: Term): If - def If_copy(original: Tree)(cond: Term, thenp: Term, elsep: Term): If - - def Match_TypeTest: TypeTest[Tree, Match] - - def Match_scrutinee(self: Match): Term - def Match_cases(self: Match): List[CaseDef] - - def Match_apply(selector: Term, cases: List[CaseDef]): Match - def Match_copy(original: Tree)(selector: Term, cases: List[CaseDef]): Match - - def GivenMatch_TypeTest: TypeTest[Tree, GivenMatch] - - def GivenMatch_cases(self: GivenMatch): List[CaseDef] - - def GivenMatch_apply(cases: List[CaseDef]): GivenMatch - def GivenMatch_copy(original: Tree)(cases: List[CaseDef]): GivenMatch - - def Try_TypeTest: TypeTest[Tree, Try] - - def Try_body(self: Try): Term - def Try_cases(self: Try): List[CaseDef] - def Try_finalizer(self: Try): Option[Term] - - def Try_apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term]): Try - def Try_copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term]): Try - - def Return_TypeTest: TypeTest[Tree, Return] - - def Return_expr(self: Return): Term - - def Return_apply(expr: Term): Return - def Return_copy(original: Tree)(expr: Term): Return - - def Repeated_TypeTest: TypeTest[Tree, Repeated] - - def Repeated_elems(self: Repeated): List[Term] - def Repeated_elemtpt(self: Repeated): TypeTree - - def Repeated_apply(elems: List[Term], elemtpt: TypeTree): Repeated - def Repeated_copy(original: Tree)(elems: List[Term], elemtpt: TypeTree): Repeated - - def Inlined_TypeTest: TypeTest[Tree, Inlined] - - def Inlined_call(self: Inlined): Option[Tree/* Term | TypeTree */] - def Inlined_bindings(self: Inlined): List[Definition] - def Inlined_body(self: Inlined): Term - - def Inlined_apply(call: Option[Tree/* Term | TypeTree */], bindings: List[Definition], expansion: Term): Inlined - def Inlined_copy(original: Tree)(call: Option[Tree/* Term | TypeTree */], bindings: List[Definition], expansion: Term): Inlined - - def SelectOuter_TypeTest: TypeTest[Tree, SelectOuter] - - def SelectOuter_qualifier(self: SelectOuter): Term - def SelectOuter_level(self: SelectOuter): Int - - def SelectOuter_apply(qualifier: Term, name: String, levels: Int): SelectOuter - def SelectOuter_copy(original: Tree)(qualifier: Term, name: String, levels: Int): SelectOuter - - def While_TypeTest: TypeTest[Tree, While] - - def While_cond(self: While): Term - def While_body(self: While): Term - - def While_apply(cond: Term, body: Term): While - def While_copy(original: Tree)(cond: Term, body: Term): While - - def TypeTree_TypeTest: TypeTest[Tree, TypeTree] - - def TypeTree_tpe(self: TypeTree): Type - - def Inferred_TypeTest: TypeTest[Tree, Inferred] - - def Inferred_apply(tpe: Type): Inferred - - def TypeRef_apply(sym: Symbol): TypeTree - - def TypeIdent_TypeTest: TypeTest[Tree, TypeIdent] - - def TypeIdent_name(self: TypeIdent): String - - def TypeIdent_copy(original: Tree)(name: String): TypeIdent - - def TypeSelect_TypeTest: TypeTest[Tree, TypeSelect] - - def TypeSelect_qualifier(self: TypeSelect): Term - def TypeSelect_name(self: TypeSelect): String - - def TypeSelect_apply(qualifier: Term, name: String): TypeSelect - def TypeSelect_copy(original: Tree)(qualifier: Term, name: String): TypeSelect - - def Projection_TypeTest: TypeTest[Tree, Projection] - - def Projection_qualifier(self: Projection): TypeTree - def Projection_name(self: Projection): String - - def Projection_copy(original: Tree)(qualifier: TypeTree, name: String): Projection - - def Singleton_TypeTest: TypeTest[Tree, Singleton] - - def Singleton_ref(self: Singleton): Term - - def Singleton_apply(ref: Term): Singleton - def Singleton_copy(original: Tree)(ref: Term): Singleton - - def Refined_TypeTest: TypeTest[Tree, Refined] - - def Refined_tpt(self: Refined): TypeTree - def Refined_refinements(self: Refined): List[Definition] - - def Refined_copy(original: Tree)(tpt: TypeTree, refinements: List[Definition]): Refined - - def Applied_TypeTest: TypeTest[Tree, Applied] - - def Applied_tpt(self: Applied): TypeTree - def Applied_args(self: Applied): List[Tree /*TypeTree | TypeBoundsTree*/] - - def Applied_apply(tpt: TypeTree, args: List[Tree /*TypeTree | TypeBoundsTree*/]): Applied - def Applied_copy(original: Tree)(tpt: TypeTree, args: List[Tree /*TypeTree | TypeBoundsTree*/]): Applied - - def Annotated_TypeTest: TypeTest[Tree, Annotated] - - def Annotated_arg(self: Annotated): TypeTree - def Annotated_annotation(self: Annotated): Term - - def Annotated_apply(arg: TypeTree, annotation: Term): Annotated - def Annotated_copy(original: Tree)(arg: TypeTree, annotation: Term): Annotated - - def MatchTypeTree_TypeTest: TypeTest[Tree, MatchTypeTree] - - def MatchTypeTree_bound(self: MatchTypeTree): Option[TypeTree] - def MatchTypeTree_selector(self: MatchTypeTree): TypeTree - def MatchTypeTree_cases(self: MatchTypeTree): List[TypeCaseDef] - - def MatchTypeTree_apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef]): MatchTypeTree - def MatchTypeTree_copy(original: Tree)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef]): MatchTypeTree - - def ByName_result(self: ByName): TypeTree - - def ByName_TypeTest: TypeTest[Tree, ByName] - - def ByName_apply(result: TypeTree): ByName - def ByName_copy(original: Tree)(result: TypeTree): ByName - - def LambdaTypeTree_TypeTest: TypeTest[Tree, LambdaTypeTree] - - def Lambdatparams(self: LambdaTypeTree): List[TypeDef] - def Lambdabody(self: LambdaTypeTree): Tree /*TypeTree | TypeBoundsTree*/ - - def Lambdaapply(tparams: List[TypeDef], body: Tree /*TypeTree | TypeBoundsTree*/): LambdaTypeTree - def Lambdacopy(original: Tree)(tparams: List[TypeDef], body: Tree /*TypeTree | TypeBoundsTree*/): LambdaTypeTree - - def TypeBind_TypeTest: TypeTest[Tree, TypeBind] - - def TypeBind_name(self: TypeBind): String - def TypeBind_body(self: TypeBind): Tree /*TypeTree | TypeBoundsTree*/ - - def TypeBind_copy(original: Tree)(name: String, tpt: Tree /*TypeTree | TypeBoundsTree*/): TypeBind - - def TypeBlock_TypeTest: TypeTest[Tree, TypeBlock] - - def TypeBlock_aliases(self: TypeBlock): List[TypeDef] - def TypeBlock_tpt(self: TypeBlock): TypeTree - - def TypeBlock_apply(aliases: List[TypeDef], tpt: TypeTree): TypeBlock - def TypeBlock_copy(original: Tree)(aliases: List[TypeDef], tpt: TypeTree): TypeBlock - - def TypeBoundsTree_TypeTest: TypeTest[Tree, TypeBoundsTree] - - def TypeBoundsTree_tpe(self: TypeBoundsTree): TypeBounds - def TypeBoundsTree_low(self: TypeBoundsTree): TypeTree - def TypeBoundsTree_hi(self: TypeBoundsTree): TypeTree - - def WildcardTypeTree_TypeTest: TypeTest[Tree, WildcardTypeTree] - - def WildcardTypeTree_tpe(self: WildcardTypeTree): Type - - def CaseDef_TypeTest: TypeTest[Tree, CaseDef] - - def CaseDef_pattern(self: CaseDef): Tree - def CaseDef_guard(self: CaseDef): Option[Term] - def CaseDef_rhs(self: CaseDef): Term - - def CaseDef_module_apply(pattern: Tree, guard: Option[Term], body: Term): CaseDef - def CaseDef_module_copy(original: Tree)(pattern: Tree, guard: Option[Term], body: Term): CaseDef - - def TypeCaseDef_TypeTest: TypeTest[Tree, TypeCaseDef] - - def TypeCaseDef_pattern(self: TypeCaseDef): TypeTree - def TypeCaseDef_rhs(self: TypeCaseDef): TypeTree - - def TypeCaseDef_module_apply(pattern: TypeTree, body: TypeTree): TypeCaseDef - def TypeCaseDef_module_copy(original: Tree)(pattern: TypeTree, body: TypeTree): TypeCaseDef - - // - // PATTERNS - // - - def Bind_TypeTest: TypeTest[Tree, Bind] - - def Tree_Bind_name(self: Bind): String - - def Tree_Bind_pattern(self: Bind): Tree - - def Tree_Bind_module_apply(sym: Symbol, body: Tree): Bind - - def Tree_Bind_module_copy(original: Tree)(name: String, pattern: Tree): Bind - - def Unapply_TypeTest: TypeTest[Tree, Unapply] - - def Tree_Unapply_fun(self: Unapply): Term - - def Tree_Unapply_implicits(self: Unapply): List[Term] - - def Tree_Unapply_patterns(self: Unapply): List[Tree] - - def Tree_Unapply_module_copy(original: Tree)(fun: Term, implicits: List[Term], patterns: List[Tree]): Unapply - - def Alternatives_TypeTest: TypeTest[Tree, Alternatives] - - def Tree_Alternatives_patterns(self: Alternatives): List[Tree] - - def Tree_Alternatives_module_apply(patterns: List[Tree]): Alternatives - def Tree_Alternatives_module_copy(original: Tree)(patterns: List[Tree]): Alternatives - - // // TYPES // - def NoPrefix_TypeTest: TypeTest[Tree, NoPrefix] - - def TypeBounds_TypeTest: TypeTest[Type, TypeBounds] - - def TypeBounds_apply(low: Type, hi: Type): TypeBounds - - def TypeBounds_low(self: TypeBounds): Type - def TypeBounds_hi(self: TypeBounds): Type - - def Type_TypeTest: TypeTest[Type, Type] - - /** Returns the type of the runtime class. This type is the erased representation - * that of the type that is used by arrays. - * - */ - def Type_ofErasedClass(clazz: Class[_]): Type - - /** Is `self` type the same as `that` type? - * This is the case iff `Type_isSubType(self, that)` and `Type_isSubType(that, self)`. - */ - def Type_isTypeEq(self: Type)(that: Type): Boolean - - /** Is this type a subtype of that type? */ - def Type_isSubType(self: Type)(that: Type): Boolean - - /** Widen from singleton type to its underlying non-singleton - * base type by applying one or more `underlying` dereferences, - * Also go from => T to T. - * Identity for all other types. Example: - * - * class Outer { class C ; val x: C } - * def o: Outer - * .widen = o.C - */ - def Type_widen(self: Type): Type - - /** Widen from TermRef to its underlying non-termref - * base type, while also skipping Expr types. - */ - def Type_widenTermRefExpr(self: Type): Type - - /** Follow aliases and dereferences LazyRefs, annotated types and instantiated - * TypeVars until type is no longer alias type, annotated type, LazyRef, - * or instantiated type variable. - */ - def Type_dealias(self: Type): Type - - def Type_simplified(self: Type): Type - - def Type_classSymbol(self: Type): Option[Symbol] // TODO remove Option and use NoSymbol - - def Type_typeSymbol(self: Type): Symbol - - def Type_termSymbol(self: Type): Symbol - - def Type_isSingleton(self: Type): Boolean - - def Type_memberType(self: Type)(member: Symbol): Type - - /** The base classes of this type with the class itself as first element. */ - def Type_baseClasses(self: Type): List[Symbol] - - /** The least type instance of given class which is a super-type - * of this type. Example: - * {{{ - * class D[T] - * class C extends p.D[Int] - * ThisType(C).baseType(D) = p.D[Int] - * }}} - */ - def Type_baseType(self: Type)(cls: Symbol): Type - - /** Is this type an instance of a non-bottom subclass of the given class `cls`? */ - def Type_derivesFrom(self: Type)(cls: Symbol): Boolean - - /** Is this type a function type? - * - * @return true if the dealised type of `self` without refinement is `FunctionN[T1, T2, ..., Tn]` - * - * @note The function - * - * - returns true for `given Int => Int` and `erased Int => Int` - * - returns false for `List[Int]`, despite that `List[Int] <:< Int => Int`. - */ - def Type_isFunctionType(self: Type): Boolean - - /** Is this type an context function type? - * - * @see `Type_isFunctionType` - */ - def Type_isContextFunctionType(self: Type): Boolean - - /** Is this type an erased function type? - * - * @see `Type_isFunctionType` - */ - def Type_isErasedFunctionType(self: Type): Boolean - - /** Is this type a dependent function type? - * - * @see `Type_isFunctionType` - */ - def Type_isDependentFunctionType(self: Type): Boolean - - /** The type , reduced if possible */ - def Type_select(self: Type)(sym: Symbol): Type - - /** The current type applied to given type arguments: `this[targ0, ..., targN]` */ - def Type_appliedTo(self: Type)(targs: List[Type]): Type - - def ConstantType_TypeTest: TypeTest[Type, ConstantType] - - def ConstantType_apply(const : Constant): ConstantType - - def ConstantType_constant(self: ConstantType): Constant - - def TermRef_TypeTest: TypeTest[Type, TermRef] - - def TermRef_apply(qual: Type, name: String): TermRef - - def TermRef_qualifier(self: TermRef): Type - def TermRef_name(self: TermRef): String - - def TypeRef_TypeTest: TypeTest[Type, TypeRef] - - def TypeRef_qualifier(self: TypeRef): Type - def TypeRef_name(self: TypeRef): String - def TypeRef_isOpaqueAlias(self: TypeRef): Boolean - def TypeRef_translucentSuperType(self: TypeRef): Type - - def SuperType_TypeTest: TypeTest[Type, SuperType] - - def SuperType_apply(thistpe: Type, supertpe: Type): SuperType - - def SuperType_thistpe(self: SuperType): Type - def SuperType_supertpe(self: SuperType): Type - - def Refinement_TypeTest: TypeTest[Type, Refinement] - - def Refinement_apply(parent: Type, name: String, info: Type): Refinement - - def Refinement_parent(self: Refinement): Type - def Refinement_name(self: Refinement): String - def Refinement_info(self: Refinement): Type - - def AppliedType_TypeTest: TypeTest[Type, AppliedType] - - def AppliedType_tycon(self: AppliedType): Type - def AppliedType_args(self: AppliedType): List[Type] - - def AnnotatedType_TypeTest: TypeTest[Type, AnnotatedType] - - def AnnotatedType_apply(underlying: Type, annot: Term): AnnotatedType - - def AnnotatedType_underlying(self: AnnotatedType): Type - def AnnotatedType_annot(self: AnnotatedType): Term - - def AndType_TypeTest: TypeTest[Type, AndType] - - def AndType_apply(lhs: Type, rhs: Type): AndType - - def AndType_left(self: AndType): Type - def AndType_right(self: AndType): Type - - def OrType_TypeTest: TypeTest[Type, OrType] - - def OrType_apply(lhs : Type, rhs : Type): OrType - - def OrType_left(self: OrType): Type - def OrType_right(self: OrType): Type - - def MatchType_TypeTest: TypeTest[Type, MatchType] - - def MatchType_apply(bound: Type, scrutinee: Type, cases: List[Type]): MatchType - - def MatchType_bound(self: MatchType): Type - def MatchType_scrutinee(self: MatchType): Type - def MatchType_cases(self: MatchType): List[Type] - - def ByNameType_TypeTest: TypeTest[Type, ByNameType] - - def ByNameType_apply(underlying: Type): Type - - def ByNameType_underlying(self: ByNameType): Type - - def ParamRef_TypeTest: TypeTest[Type, ParamRef] - - def ParamRef_binder(self: ParamRef): LambdaType - def ParamRef_paramNum(self: ParamRef): Int - - def ThisType_TypeTest: TypeTest[Type, ThisType] - - def ThisType_tref(self: ThisType): Type - - def RecursiveThis_TypeTest: TypeTest[Type, RecursiveThis] - - def RecursiveThis_binder(self: RecursiveThis): RecursiveType - - def RecursiveType_TypeTest: TypeTest[Type, RecursiveType] - - /** Create a RecType, normalizing its contents. This means: - * - * 1. Nested Rec types on the type's spine are merged with the outer one. - * 2. Any refinement of the form `type T = z.T` on the spine of the type - * where `z` refers to the created rec-type is replaced by - * `type T`. This avoids infinite recursions later when we - * try to follow these references. - */ - def RecursiveType_apply(parentExp: RecursiveType => Type): RecursiveType - - def RecursiveType_underlying(self: RecursiveType): Type - - def RecursiveThis_recThis(self: RecursiveType): RecursiveThis - - def MethodType_TypeTest: TypeTest[Type, MethodType] - - def MethodType_apply(paramNames: List[String])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type): MethodType - - def MethodType_isErased(self: MethodType): Boolean - def MethodType_isImplicit(self: MethodType): Boolean - def MethodType_param(self: MethodType, ids: Int): Type - def MethodType_paramNames(self: MethodType): List[String] - def MethodType_paramTypes(self: MethodType): List[Type] - def MethodType_resType(self: MethodType): Type - - def PolyType_TypeTest: TypeTest[Type, PolyType] - - def PolyType_apply(paramNames: List[String])(paramBoundsExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type): PolyType - - def PolyType_param(self: PolyType, idx: Int): Type - def PolyType_paramNames(self: PolyType): List[String] - def PolyType_paramBounds(self: PolyType): List[TypeBounds] - def PolyType_resType(self: PolyType): Type - - def TypeLambda_TypeTest: TypeTest[Type, TypeLambda] - - def TypeLambda_apply(paramNames: List[String], boundsFn: TypeLambda => List[TypeBounds], bodyFn: TypeLambda => Type): TypeLambda - - def TypeLambda_paramNames(self: TypeLambda): List[String] - def TypeLambda_paramBounds(self: TypeLambda): List[TypeBounds] - def TypeLambda_param(self: TypeLambda, idx: Int): Type - def TypeLambda_resType(self: TypeLambda): Type - - - ////////////////////// - // IMPORT SELECTORS // - ////////////////////// - - def SimpleSelector_TypeTest: TypeTest[ImportSelector, SimpleSelector] - - def SimpleSelector_selection(self: SimpleSelector): Id - - def RenameSelector_TypeTest: TypeTest[ImportSelector, RenameSelector] - - def RenameSelector_from(self: RenameSelector): Id - def RenameSelector_to(self: RenameSelector): Id - - def OmitSelector_TypeTest: TypeTest[ImportSelector, OmitSelector] - - def SimpleSelector_omitted(self: OmitSelector): Id - - - ///////////////// - // IDENTIFIERS // - ///////////////// - - /** Position in the source code */ - def Id_pos(self: Id): Position - - /** Name of the identifier */ - def Id_name(self: Id): String - - - //////////////// - // SIGNATURES // - //////////////// - - def Signature_paramSigs(self: Signature): List[String | Int] - - def Signature_resultSig(self: Signature): String - - - /////////////// - // POSITIONS // - /////////////// - - /** The start offset in the source file */ - def Position_start(self: Position): Int - - /** The end offset in the source file */ - def Position_end(self: Position): Int - - /** Does this position exist */ - def Position_exists(self: Position): Boolean - - /** Source file in which this position is located */ - def Position_sourceFile(self: Position): SourceFile - - /** The start line in the source file */ - def Position_startLine(self: Position): Int - - /** The end line in the source file */ - def Position_endLine(self: Position): Int - - /** The start column in the source file */ - def Position_startColumn(self: Position): Int - - /** The end column in the source file */ - def Position_endColumn(self: Position): Int - - /** Source code within the position */ - def Position_sourceCode(self: Position): String - - ///////////////// - // SOURCE FILE // - ///////////////// - - /** Path to a source file */ - def SourceFile_jpath(self: SourceFile): java.nio.file.Path - - /** Content of a source file */ - def SourceFile_content(self: SourceFile): String - - - ////////////// - // COMMENTS // - ////////////// - - def Comment_raw(self: Comment): String - def Comment_expanded(self: Comment): Option[String] - def Comment_usecases(self: Comment): List[(String, Option[DefDef])] - - - /////////////// - // CONSTANTS // - /////////////// - - def Constant_value(const: Constant): Any - - def matchConstant(constant: Constant): Option[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type] - def matchConstant_ClassTag(constant: Constant): Option[Type] - - def Constant_apply(x: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type): Constant - def Constant_ClassTag_apply(x: Type): Constant - - - ///////////// - // SYMBOLS // - ///////////// - - /** Returns the symbol of the enclosing definition of the given context */ - def Symbol_currentOwner(using ctx: Context): Symbol - - /** Owner of this symbol. The owner is the symbol in which this symbol is defined. Throws if this symbol does not have an owner. */ - def Symbol_owner(self: Symbol): Symbol - - /** Owner of this symbol. The owner is the symbol in which this symbol is defined. Returns `NoSymbol` if this symbol does not have an owner. */ - def Symbol_maybeOwner(self: Symbol): Symbol - - /** Flags of this symbol */ - def Symbol_flags(self: Symbol): Flags - - def Symbol_tree(self: Symbol): Tree - - def Symbol_isLocalDummy(self: Symbol): Boolean - - def Symbol_isRefinementClass(self: Symbol): Boolean - - def Symbol_isAliasType(self: Symbol): Boolean - - def Symbol_isAnonymousClass(self: Symbol): Boolean - - def Symbol_isAnonymousFunction(self: Symbol): Boolean - - def Symbol_isAbstractType(self: Symbol): Boolean - - def Symbol_isClassConstructor(self: Symbol): Boolean - - /** This symbol is private within the resulting type. */ - def Symbol_privateWithin(self: Symbol): Option[Type] - - /** This symbol is protected within the resulting type. */ - def Symbol_protectedWithin(self: Symbol): Option[Type] - - /** The name of this symbol. */ - def Symbol_name(self: Symbol): String - - /** The full name of this symbol up to the root package. */ - def Symbol_fullName(self: Symbol): String - - /** The position of this symbol */ - def Symbol_pos(self: Symbol): Position - - def Symbol_localContext(self: Symbol): Context - - /** The comment of the symbol */ - def Symbol_comment(self: Symbol): Option[Comment] - - /** Annotations attached to this symbol */ - def Symbol_annots(self: Symbol): List[Term] - - def Symbol_isDefinedInCurrentRun(self: Symbol): Boolean - - /** Fields directly declared in the class */ - def Symbol_fields(self: Symbol): List[Symbol] - - /** Field with the given name directly declared in the class */ - def Symbol_field(self: Symbol)(name: String): Symbol - - /** Get non-private named methods defined directly inside the class */ - def Symbol_classMethod(self: Symbol)(name: String): List[Symbol] - - /** Get all non-private methods defined directly inside the class, excluding constructors */ - def Symbol_classMethods(self: Symbol): List[Symbol] - - /** Get named non-private methods declared or inherited */ - def Symbol_method(self: Symbol)(name: String): List[Symbol] - - /** Get all non-private methods declared or inherited */ - def Symbol_methods(self: Symbol): List[Symbol] - - /** Type member directly declared in the class */ - def Symbol_typeMembers(self: Symbol): List[Symbol] - - /** Type member with the given name directly declared in the class */ - def Symbol_typeMember(self: Symbol)(name: String): Symbol - - /** The symbols of each type parameter list and value parameter list of this - * method, or Nil if this isn't a method. - */ - def Symbol_paramSymss(self: Symbol): List[List[Symbol]] - - /** The primary constructor of a class or trait, `noSymbol` if not applicable. */ - def Symbol_primaryConstructor(self: Symbol): Symbol - - /** Fields of a case class type -- only the ones declared in primary constructor */ - def Symbol_caseFields(self: Symbol): List[Symbol] - - /** Get package symbol if package is either defined in current compilation run or present on classpath. */ - def Symbol_requiredPackage(path: String): Symbol - - /** Get class symbol if class is either defined in current compilation run or present on classpath. */ - def Symbol_requiredClass(path: String): Symbol - - /** Get module symbol if module is either defined in current compilation run or present on classpath. */ - def Symbol_requiredModule(path: String): Symbol - - /** Get method symbol if method is either defined in current compilation run or present on classpath. Throws if the method has an overload. */ - def Symbol_requiredMethod(path: String): Symbol - - def Symbol_of(fullName: String): Symbol - - def Symbol_newMethod(parent: Symbol, name: String, flags: Flags, tpe: Type, privateWithin: Symbol): Symbol - - def Symbol_newVal(parent: Symbol, name: String, flags: Flags, tpe: Type, privateWithin: Symbol): Symbol - - def Symbol_newBind(parent: Symbol, name: String, flags: Flags, tpe: Type): Symbol - - def Symbol_isTypeParam(self: Symbol): Boolean - - def Symbol_isPackageDef(symbol: Symbol): Boolean - - /** Is this the definition of a type? */ - def Symbol_isType(symbol: Symbol): Boolean - - /** Is this the definition of a term? */ - def Symbol_isTerm(symbol: Symbol): Boolean - - /** Is this the definition of a ClassDef tree? */ - def Symbol_isClassDef(symbol: Symbol): Boolean - - /** Is this the definition of a TypeDef tree? */ - def Symbol_isTypeDef(symbol: Symbol): Boolean - - /** Is this the definition of a DefDef tree? */ - def Symbol_isDefDef(symbol: Symbol): Boolean - - /** Is this the definition of a ValDef tree? */ - def Symbol_isValDef(symbol: Symbol): Boolean - - /** Is this the definition of a Bind pattern? */ - def Symbol_isBind(symbol: Symbol): Boolean - - /** Signature of this definition */ - def Symbol_signature(self: Symbol): Signature - - /** The class symbol of the companion module class */ - def Symbol_moduleClass(self: Symbol): Symbol - - /** The symbol of the companion class */ - def Symbol_companionClass(self: Symbol): Symbol - - /** The symbol of the companion module */ - def Symbol_companionModule(self: Symbol): Symbol - - def Symbol_noSymbol: Symbol - - /** Case class or case object children of a sealed trait */ - def Symbol_children(self: Symbol): List[Symbol] - - - /////////// - // FLAGS // - /////////// - - /** Is the given flag set a subset of this flag sets */ - def Flags_is(self: Flags)(that: Flags): Boolean - - /** Union of the two flag sets */ - def Flags_or(self: Flags)(that: Flags): Flags - - /** Intersection of the two flag sets */ - def Flags_and(self: Flags)(that: Flags): Flags - - def Flags_Abstract: Flags - def Flags_Artifact: Flags - def Flags_Case: Flags - def Flags_CaseAcessor: Flags - def Flags_Contravariant: Flags - def Flags_Covariant: Flags - def Flags_EmptyFlags: Flags - def Flags_Enum: Flags - def Flags_Erased: Flags - def Flags_ExtensionMethod: Flags - def Flags_FieldAccessor: Flags - def Flags_Final: Flags - def Flags_Given: Flags - def Flags_HasDefault: Flags - def Flags_Implicit: Flags - def Flags_Inline: Flags - def Flags_JavaDefined: Flags - def Flags_Lazy: Flags - def Flags_Local: Flags - def Flags_Macro: Flags - def Flags_ModuleClass: Flags - def Flags_Mutable: Flags - def Flags_Object: Flags - def Flags_Override: Flags - def Flags_Package: Flags - def Flags_Param: Flags - def Flags_ParamAccessor: Flags - def Flags_Private: Flags - def Flags_PrivateLocal: Flags - def Flags_Protected: Flags - def Flags_Scala2X: Flags - def Flags_Sealed: Flags - def Flags_StableRealizable: Flags - def Flags_Static: Flags - def Flags_Synthetic: Flags - def Flags_Trait: Flags - - - ///////////////// - // DEFINITIONS // - ///////////////// - - def Definitions_RootPackage: Symbol - def Definitions_RootClass: Symbol - - def Definitions_EmptyPackageClass: Symbol - - def Definitions_ScalaPackage: Symbol - def Definitions_ScalaPackageClass: Symbol - - def Definitions_AnyClass: Symbol - def Definitions_AnyValClass: Symbol - def Definitions_ObjectClass: Symbol - def Definitions_AnyRefClass: Symbol - def Definitions_NullClass: Symbol - def Definitions_NothingClass: Symbol - def Definitions_UnitClass: Symbol - def Definitions_ByteClass: Symbol - def Definitions_ShortClass: Symbol - def Definitions_CharClass: Symbol - def Definitions_IntClass: Symbol - def Definitions_LongClass: Symbol - def Definitions_FloatClass: Symbol - def Definitions_DoubleClass: Symbol - def Definitions_BooleanClass: Symbol - def Definitions_StringClass: Symbol - def Definitions_ClassClass: Symbol - def Definitions_ArrayClass: Symbol - def Definitions_PredefModule: Symbol - def Definitions_Predef_classOf: Symbol - - def Definitions_JavaLangPackage: Symbol - - def Definitions_ArrayModule: Symbol - - def Definitions_Array_apply: Symbol - def Definitions_Array_clone: Symbol - def Definitions_Array_length: Symbol - def Definitions_Array_update: Symbol - - /** A dummy class symbol that is used to indicate repeated parameters - * compiled by the Scala compiler. - */ - def Definitions_RepeatedParamClass: Symbol - - /** The class symbol of class `scala.annotation.internal.Repeated` */ - def Definitions_RepeatedAnnot: Symbol - - def Definitions_OptionClass: Symbol - def Definitions_NoneModule: Symbol - def Definitions_SomeModule: Symbol - - def Definitions_ProductClass: Symbol - // TODO avoid default parameters - def Definitions_FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol - - def Definitions_TupleClass(arity: Int): Symbol - def Definitions_isTupleClass(sym: Symbol): Boolean - /** Symbol of scala.internal.CompileTime.patternHole */ def Definitions_InternalQuotedMatcher_patternHole: Symbol @@ -1153,63 +69,6 @@ trait CompilerInterface extends scala.tasty.reflect.Types { /** The type of primitive type `Boolean`. */ def Definitions_BooleanType: Type - /** The type of core type `Any`. */ - def Definitions_AnyType: Type - - /** The type of core type `AnyVal`. */ - def Definitions_AnyValType: Type - - /** The type of core type `AnyRef`. */ - def Definitions_AnyRefType: Type - - /** The type of core type `Object`. */ - def Definitions_ObjectType: Type - - /** The type of core type `Nothing`. */ - def Definitions_NothingType: Type - - /** The type of core type `Null`. */ - def Definitions_NullType: Type - - /** The type for `scala.String`. */ - def Definitions_StringType: Type - - /** The type for `scala.Tuple`. */ - def Definitions_TupleType: Type - - /** The type for `scala.EmptyTuple`. */ - def Definitions_EmptyTupleType: Type - - /** The type for `scala.NonEmptyTuple`. */ - def Definitions_NonEmptyTupleType: Type - - /** The type for `scala.*:`. */ - def Definitions_TupleConsType: Type - - /////////////// - // IMPLICITS // - /////////////// - - def ImplicitSearchSuccess_TypeTest: TypeTest[ImplicitSearchResult, ImplicitSearchSuccess] - def ImplicitSearchSuccess_tree(self: ImplicitSearchSuccess): Term - - def ImplicitSearchFailure_TypeTest: TypeTest[ImplicitSearchResult, ImplicitSearchFailure] - def ImplicitSearchFailure_explanation(self: ImplicitSearchFailure): String - - def DivergingImplicit_TypeTest: TypeTest[ImplicitSearchResult, DivergingImplicit] - - def NoMatchingImplicits_TypeTest: TypeTest[ImplicitSearchResult, NoMatchingImplicits] - - def AmbiguousImplicits_TypeTest: TypeTest[ImplicitSearchResult, AmbiguousImplicits] - - /** Find an implicit of type `T` in the current scope given by `ctx`. - * Return an `ImplicitSearchResult`. - * - * @param tpe type of the implicit parameter - * @param ctx current context - */ - def searchImplicit(tpe: Type): ImplicitSearchResult - /** Returns Some with a beta-reduced application or None */ def betaReduce(tree: Term): Option[Term] diff --git a/library/src/scala/tasty/Reflection.scala b/library/src/scala/tasty/Reflection.scala index 9d7097a85c1d..bf151f735d8b 100644 --- a/library/src/scala/tasty/Reflection.scala +++ b/library/src/scala/tasty/Reflection.scala @@ -6,329 +6,459 @@ import scala.quoted.QuoteContext import scala.quoted.show.SyntaxHighlight import scala.tasty.reflect._ +/** TASTy Reflect Interface. + * + * + */ + /** TASTy Reflect Interface. * * Provides all functionality related with AST based metaprogramming. + * + * Type hierarchy + * ```none + * + * +- Tree -+- PackageClause + * +- Import + * +- Statement -+- Definition --+- PackageDef + * | | +- ClassDef + * | | +- TypeDef + * | | +- DefDef + * | | +- ValDef + * | | + * | +- Term --------+- Ref -+- Ident + * | | +- Select + * | | + * | +- Literal + * | +- This + * | +- New + * | +- NamedArg + * | +- Apply + * | +- TypeApply + * | +- Super + * | +- Typed + * | +- Assign + * | +- Block + * | +- Closure + * | +- If + * | +- Match + * | +- GivenMatch + * | +- Try + * | +- Return + * | +- Repeated + * | +- Inlined + * | +- SelectOuter + * | +- While + * | + * | + * +- TypeTree ----+- Inferred + * | +- TypeIdent + * | +- TypeSelect + * | +- Projection + * | +- Singleton + * | +- Refined + * | +- Applied + * | +- Annotated + * | +- MatchTypeTree + * | +- ByName + * | +- LambdaTypeTree + * | +- TypeBind + * | +- TypeBlock + * | + * +- TypeBoundsTree + * +- WildcardTypeTree + * | + * +- CaseDef + * | + * +- TypeCaseDef + * +- Bind + * +- Unapply + * +- Alternatives + * + * + * +- Type -+- ConstantType + * +- TermRef + * +- TypeRef + * +- SuperType + * +- Refinement + * +- AppliedType + * +- AnnotatedType + * +- AndType + * +- OrType + * +- MatchType + * +- ByNameType + * +- ParamRef + * +- ThisType + * +- RecursiveThis + * +- RecursiveType + * +- LambdaType -+- MethodType + * | +- PolyType + * | +- TypeLambda + * +- TypeBounds + * +- NoPrefix + * + * +- ImportSelector -+- SimpleSelector + * +- RenameSelector + * +- OmitSelector + * + * +- Id + * + * +- Signature + * + * +- Position + * + * +- Comment + * + * +- Constant + * + * +- Symbol + * + * +- Flags + * + * ``` */ -trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => +trait Reflection { reflection => ////////////// // CONTEXTS // ////////////// + /** Compilation context */ + type Context <: AnyRef + /** Context of the macro expansion */ def rootContext: Context // TODO: Should this be moved to QuoteContext? given Context = rootContext // TODO: Should be an implicit converion from QuoteContext to Context - /////////////// - // Source // + // TREES // /////////////// - object Source: - - /** Returns the source file being compiled. The path is relative to the current working directory. */ - def path: java.nio.file.Path = reflectSelf.Source_path - - /** Returns true if we've tried to reflect on a Java class. */ - def isJavaCompilationUnit: Boolean = reflectSelf.Source_isJavaCompilationUnit - /** Returns true if we've tried to reflect on a Scala2 (non-Tasty) class. */ - def isScala2CompilationUnit: Boolean = reflectSelf.Source_isScala2CompilationUnit + /** Tree representing code written in the source */ + type Tree <: AnyRef - /** Returns true if we've tried to reflect on a class that's already loaded (e.g. Option). */ - def isAlreadyLoadedCompilationUnit: Boolean = reflectSelf.Source_isAlreadyLoadedCompilationUnit + val Tree: TreeModule - /** Class name of the current CompilationUnit */ - def compilationUnitClassname: String = reflectSelf.Source_compilationUnitClassname + trait TreeModule { this: Tree.type => } - end Source + given TreeMethods as TreeMethods = TreeMethodsImpl + protected val TreeMethodsImpl: TreeMethods - - /////////////// - // TREES // - /////////////// - - // ----- Tree ----------------------------------------------------- - - object Tree - - given TreeOps as AnyRef: - extension (tree: Tree): + trait TreeMethods { + extension (self: Tree): /** Position in the source code */ - def pos: Position = reflectSelf.Tree_pos(tree) + def pos: Position /** Symbol of defined or referred by this tree */ - def symbol: Symbol = reflectSelf.Tree_symbol(tree) + def symbol: Symbol /** Shows the tree as extractors */ - def showExtractors: String = - new ExtractorsPrinter[reflectSelf.type](reflectSelf).showTree(tree) + def showExtractors: String /** Shows the tree as fully typed source code */ - def show: String = - tree.showWith(SyntaxHighlight.plain) + def show: String /** Shows the tree as fully typed source code */ - def showWith(syntaxHighlight: SyntaxHighlight): String = - new SourceCodePrinter[reflectSelf.type](reflectSelf)(syntaxHighlight).showTree(tree) + def showWith(syntaxHighlight: SyntaxHighlight): String /** Does this tree represent a valid expression? */ - def isExpr: Boolean = - tree match - case tree: Term => - tree.tpe.widen match - case _: MethodType | _: PolyType => false - case _ => true - case _ => false - + def isExpr: Boolean end extension /** Convert this tree to an `quoted.Expr[T]` if the tree is a valid expression or throws */ - extension [T](tree: Tree) - def asExprOf(using scala.quoted.Type[T])(using QuoteContext): scala.quoted.Expr[T] = - if tree.isExpr then - new scala.internal.quoted.Expr(tree, reflectSelf.compilerId).asExprOf[T] - else tree match - case tree: Term => throw new Exception("Expected an expression. This is a partially applied Term. Try eta-expanding the term first.") - case _ => throw new Exception("Expected a Term but was: " + tree) - - end TreeOps - - given TypeTest[Tree, PackageClause] = reflectSelf.PackageClause_TypeTest - - object PackageClause: - def apply(pid: Ref, stats: List[Tree]): PackageClause = - reflectSelf.PackageClause_apply(pid, stats) - def copy(original: Tree)(pid: Ref, stats: List[Tree]): PackageClause = - reflectSelf.PackageClause_copy(original)(pid, stats) - def unapply(tree: PackageClause): Some[(Ref, List[Tree])] = - Some((tree.pid, tree.stats)) - end PackageClause - - given PackageClauseOps as AnyRef: + extension [T](self: Tree) + def asExprOf(using scala.quoted.Type[T])(using QuoteContext): scala.quoted.Expr[T] + } + + /** Tree representing a pacakage clause in the source code */ + type PackageClause <: Tree + + given TypeTest[Tree, PackageClause] = PackageClauseTypeTest + protected val PackageClauseTypeTest: TypeTest[Tree, PackageClause] + + val PackageClause: PackageClauseModule + + trait PackageClauseModule { this: PackageClause.type => + def apply(pid: Ref, stats: List[Tree]): PackageClause + def copy(original: Tree)(pid: Ref, stats: List[Tree]): PackageClause + def unapply(tree: PackageClause): Some[(Ref, List[Tree])] + } + + given PackageClauseMethods as PackageClauseMethods = PackageClauseMethodsImpl + protected val PackageClauseMethodsImpl: PackageClauseMethods + + trait PackageClauseMethods: extension (self: PackageClause): - def pid: Ref = reflectSelf.PackageClause_pid(self) - def stats: List[Tree] = reflectSelf.PackageClause_stats(self) + def pid: Ref + def stats: List[Tree] end extension - end PackageClauseOps + end PackageClauseMethods + + /** Tree representing an import in the source code */ + type Import <: Statement + + given TypeTest[Tree, Import] = ImportTypeTest + protected val ImportTypeTest: TypeTest[Tree, Import] - given TypeTest[Tree, Import] = reflectSelf.Import_TypeTest + val Import: ImportModule - object Import: - def apply(expr: Term, selectors: List[ImportSelector]): Import = - reflectSelf.Import_apply(expr, selectors) - def copy(original: Tree)(expr: Term, selectors: List[ImportSelector]): Import = - reflectSelf.Import_copy(original)(expr, selectors) - def unapply(tree: Import): Option[(Term, List[ImportSelector])] = - Some((tree.expr, tree.selectors)) - end Import + trait ImportModule { this: Import.type => + def apply(expr: Term, selectors: List[ImportSelector]): Import + def copy(original: Tree)(expr: Term, selectors: List[ImportSelector]): Import + def unapply(tree: Import): Option[(Term, List[ImportSelector])] + } + + given ImportMethods as ImportMethods = ImportMethodsImpl + protected val ImportMethodsImpl: ImportMethods - given ImportOps as AnyRef: + trait ImportMethods: extension (self: Import): - def expr: Term = reflectSelf.Import_expr(self) - def selectors: List[ImportSelector] = - reflectSelf.Import_selectors(self) + def expr: Term + def selectors: List[ImportSelector] end extension - end ImportOps + end ImportMethods + /** Tree representing a statement in the source code */ + type Statement <: Tree - given TypeTest[Tree, Statement] = reflectSelf.Statement_TypeTest + given TypeTest[Tree, Statement] = StatementTypeTest + protected val StatementTypeTest: TypeTest[Tree, Statement] // ----- Definitions ---------------------------------------------- - given TypeTest[Tree, Definition] = reflectSelf.Definition_TypeTest + /** Tree representing a definition in the source code. It can be `PackageDef`, `ClassDef`, `TypeDef`, `DefDef` or `ValDef` */ + type Definition <: Statement + + given TypeTest[Tree, Definition] = DefinitionTypeTest + protected val DefinitionTypeTest: TypeTest[Tree, Definition] - object Definition + val Definition: DefinitionModule - given DefinitionOps as AnyRef: + trait DefinitionModule { this: Definition.type => } + + given DefinitionMethods as DefinitionMethods = DefinitionMethodsImpl + protected val DefinitionMethodsImpl: DefinitionMethods + + trait DefinitionMethods: extension (self: Definition): - def name: String = reflectSelf.Definition_name(self) + def name: String end extension - end DefinitionOps + end DefinitionMethods // ClassDef - given TypeTest[Tree, ClassDef] = reflectSelf.ClassDef_TypeTest + /** Tree representing a class definition. This includes annonymus class definitions and the class of a module object */ + type ClassDef <: Definition + + given TypeTest[Tree, ClassDef] = ClassDefTypeTest + protected val ClassDefTypeTest: TypeTest[Tree, ClassDef] + + val ClassDef: ClassDefModule - object ClassDef: + trait ClassDefModule { this: ClassDef.type => // TODO def apply(name: String, constr: DefDef, parents: List[TermOrTypeTree], selfOpt: Option[ValDef], body: List[Statement]): ClassDef - def copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree /* Term | TypeTree */], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement]): ClassDef = - reflectSelf.ClassDef_copy(original)(name, constr, parents, derived, selfOpt, body) - def unapply(cdef: ClassDef): Option[(String, DefDef, List[Tree /* Term | TypeTree */], List[TypeTree], Option[ValDef], List[Statement])] = - Some((cdef.name, cdef.constructor, cdef.parents, cdef.derived, cdef.self, cdef.body)) - end ClassDef + def copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree /* Term | TypeTree */], derived: List[TypeTree], selfOpt: Option[ValDef], body: List[Statement]): ClassDef + def unapply(cdef: ClassDef): Option[(String, DefDef, List[Tree /* Term | TypeTree */], List[TypeTree], Option[ValDef], List[Statement])] + } + + given ClassDefMethods as ClassDefMethods = ClassDefMethodsImpl + protected val ClassDefMethodsImpl: ClassDefMethods - given ClassDefOps as AnyRef: + trait ClassDefMethods: extension (self: ClassDef): - def constructor: DefDef = reflectSelf.ClassDef_constructor(self) - def parents: List[Tree /* Term | TypeTree */] = reflectSelf.ClassDef_parents(self) - def derived: List[TypeTree] = reflectSelf.ClassDef_derived(self) - def self: Option[ValDef] = reflectSelf.ClassDef_self(self) - def body: List[Statement] = reflectSelf.ClassDef_body(self) + def constructor: DefDef + def parents: List[Tree /* Term | TypeTree */] + def derived: List[TypeTree] + def self: Option[ValDef] + def body: List[Statement] end extension - end ClassDefOps - + end ClassDefMethods // DefDef - given TypeTest[Tree, DefDef] = reflectSelf.DefDef_TypeTest + /** Tree representing a method definition in the source code */ + type DefDef <: Definition - object DefDef: - def apply(symbol: Symbol, rhsFn: List[Type] => List[List[Term]] => Option[Term]): DefDef = - reflectSelf.DefDef_apply(symbol, rhsFn) - def copy(original: Tree)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term]): DefDef = - reflectSelf.DefDef_copy(original)(name, typeParams, paramss, tpt, rhs) - def unapply(ddef: DefDef): Option[(String, List[TypeDef], List[List[ValDef]], TypeTree, Option[Term])] = - Some((ddef.name, ddef.typeParams, ddef.paramss, ddef.returnTpt, ddef.rhs)) - end DefDef + given TypeTest[Tree, DefDef] = DefDefTypeTest + protected val DefDefTypeTest: TypeTest[Tree, DefDef] - given DefDefOps as AnyRef: + val DefDef: DefDefModule + + trait DefDefModule { this: DefDef.type => + def apply(symbol: Symbol, rhsFn: List[Type] => List[List[Term]] => Option[Term]): DefDef + def copy(original: Tree)(name: String, typeParams: List[TypeDef], paramss: List[List[ValDef]], tpt: TypeTree, rhs: Option[Term]): DefDef + def unapply(ddef: DefDef): Option[(String, List[TypeDef], List[List[ValDef]], TypeTree, Option[Term])] + } + + given DefDefMethods as DefDefMethods = DefDefMethodsImpl + protected val DefDefMethodsImpl: DefDefMethods + + trait DefDefMethods: extension (self: DefDef): - def typeParams: List[TypeDef] = reflectSelf.DefDef_typeParams(self) - def paramss: List[List[ValDef]] = reflectSelf.DefDef_paramss(self) - def returnTpt: TypeTree = reflectSelf.DefDef_returnTpt(self) // TODO rename to tpt - def rhs: Option[Term] = reflectSelf.DefDef_rhs(self) + def typeParams: List[TypeDef] + def paramss: List[List[ValDef]] + def returnTpt: TypeTree + def rhs: Option[Term] end extension - end DefDefOps - + end DefDefMethods // ValDef - given TypeTest[Tree, ValDef] = reflectSelf.ValDef_TypeTest + /** Tree representing a value definition in the source code This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */ + type ValDef <: Definition + + given TypeTest[Tree, ValDef] = ValDefTypeTest + protected val ValDefTypeTest: TypeTest[Tree, ValDef] - object ValDef: - def apply(symbol: Symbol, rhs: Option[Term]): ValDef = - reflectSelf.ValDef_apply(symbol, rhs) - def copy(original: Tree)(name: String, tpt: TypeTree, rhs: Option[Term]): ValDef = - reflectSelf.ValDef_copy(original)(name, tpt, rhs) - def unapply(vdef: ValDef): Option[(String, TypeTree, Option[Term])] = - Some((vdef.name, vdef.tpt, vdef.rhs)) - end ValDef + val ValDef: ValDefModule - given ValDefOps as AnyRef: + trait ValDefModule { this: ValDef.type => + def apply(symbol: Symbol, rhs: Option[Term]): ValDef + def copy(original: Tree)(name: String, tpt: TypeTree, rhs: Option[Term]): ValDef + def unapply(vdef: ValDef): Option[(String, TypeTree, Option[Term])] + } + + given ValDefMethods as ValDefMethods = ValDefMethodsImpl + protected val ValDefMethodsImpl: ValDefMethods + + trait ValDefMethods: extension (self: ValDef): - def tpt: TypeTree = reflectSelf.ValDef_tpt(self) - def rhs: Option[Term] = reflectSelf.ValDef_rhs(self) + def tpt: TypeTree + def rhs: Option[Term] end extension - end ValDefOps - + end ValDefMethods // TypeDef - given TypeTest[Tree, TypeDef] = reflectSelf.TypeDef_TypeTest + /** Tree representing a type (parameter or member) definition in the source code */ + type TypeDef <: Definition + + given TypeTest[Tree, TypeDef] = TypeDefTypeTest + protected val TypeDefTypeTest: TypeTest[Tree, TypeDef] + + val TypeDef: TypeDefModule - object TypeDef: - def apply(symbol: Symbol): TypeDef = - reflectSelf.TypeDef_apply(symbol) - def copy(original: Tree)(name: String, rhs: Tree /*TypeTree | TypeBoundsTree*/): TypeDef = - reflectSelf.TypeDef_copy(original)(name, rhs) - def unapply(tdef: TypeDef): Option[(String, Tree /*TypeTree | TypeBoundsTree*/ /* TypeTree | TypeBoundsTree */)] = - Some((tdef.name, tdef.rhs)) - end TypeDef + trait TypeDefModule { this: TypeDef.type => + def apply(symbol: Symbol): TypeDef + def copy(original: Tree)(name: String, rhs: Tree /*TypeTree | TypeBoundsTree*/): TypeDef + def unapply(tdef: TypeDef): Option[(String, Tree /*TypeTree | TypeBoundsTree*/ /* TypeTree | TypeBoundsTree */)] + } + + given TypeDefMethods as TypeDefMethods = TypeDefMethodsImpl + protected val TypeDefMethodsImpl: TypeDefMethods - given TypeDefOps as AnyRef: + trait TypeDefMethods: extension (self: TypeDef): - def rhs: Tree /*TypeTree | TypeBoundsTree*/ = reflectSelf.TypeDef_rhs(self) + def rhs: Tree /*TypeTree | TypeBoundsTree*/ end extension - end TypeDefOps + end TypeDefMethods // PackageDef - given TypeTest[Tree, PackageDef] = reflectSelf.PackageDef_TypeTest + /** Tree representing a package definition. This includes definitions in all source files */ + type PackageDef <: Definition + + given TypeTest[Tree, PackageDef] = PackageDefTypeTest + protected val PackageDefTypeTest: TypeTest[Tree, PackageDef] + + val PackageDef: PackageDefModule + + trait PackageDefModule { this: PackageDef.type => + def unapply(tree: PackageDef): Option[(String, PackageDef)] + } - object PackageDef: - def unapply(tree: PackageDef): Option[(String, PackageDef)] = - Some((tree.name, tree.owner)) - end PackageDef + given PackageDefMethods as PackageDefMethods = PackageDefMethodsImpl + protected val PackageDefMethodsImpl: PackageDefMethods - given PackageDefOps as AnyRef: + trait PackageDefMethods: extension (self: PackageDef): - def owner: PackageDef = reflectSelf.PackageDef_owner(self) - def members: List[Statement] = reflectSelf.PackageDef_members(self) + def owner: PackageDef + def members: List[Statement] end extension - end PackageDefOps + end PackageDefMethods // ----- Terms ---------------------------------------------------- - object Term + /** Tree representing an expression in the source code */ + type Term <: Statement - given TermOps as AnyRef: + given TypeTest[Tree, Term] = TermTypeTest + protected val TermTypeTest: TypeTest[Tree, Term] + + val Term: TermModule + + trait TermModule { this: Term.type => } + + given TermMethods as TermMethods = TermMethodsImpl + protected val TermMethodsImpl: TermMethods + + trait TermMethods { extension (self: Term): /** Convert `Term` to an `quoted.Expr[Any]` if the term is a valid expression or throws */ - def seal: scala.quoted.Expr[Any] = - if self.isExpr then new scala.internal.quoted.Expr(self, reflectSelf.compilerId) - else throw new Exception("Cannot seal a partially applied Term. Try eta-expanding the term first.") + def seal: scala.quoted.Expr[Any] /** Convert `Term` to an `quoted.Expr[Any]` if the term is a valid expression */ - def sealOpt: Option[scala.quoted.Expr[Any]] = - if self.isExpr then Some(new scala.internal.quoted.Expr(self, reflectSelf.compilerId)) - else None + def sealOpt: Option[scala.quoted.Expr[Any]] /** Type of this term */ - def tpe: Type = reflectSelf.Term_tpe(self) + def tpe: Type /** Replace Inlined nodes and InlineProxy references to underlying arguments */ - def underlyingArgument: Term = reflectSelf.Term_underlyingArgument(self) + def underlyingArgument: Term /** Replace Ident nodes references to the underlying tree that defined them */ - def underlying: Term = reflectSelf.Term_underlying(self) + def underlying: Term /** Converts a partally applied term into a lambda expression */ - def etaExpand: Term = reflectSelf.Term_etaExpand(self) + def etaExpand: Term /** A unary apply node with given argument: `tree(arg)` */ - def appliedTo(arg: Term): Term = - self.appliedToArgs(arg :: Nil) + def appliedTo(arg: Term): Term /** An apply node with given arguments: `tree(arg, args0, ..., argsN)` */ - def appliedTo(arg: Term, args: Term*): Term = - self.appliedToArgs(arg :: args.toList) + def appliedTo(arg: Term, args: Term*): Term /** An apply node with given argument list `tree(args(0), ..., args(args.length - 1))` */ - def appliedToArgs(args: List[Term]): Apply = - Apply(self, args) + def appliedToArgs(args: List[Term]): Apply /** The current tree applied to given argument lists: * `tree (argss(0)) ... (argss(argss.length -1))` */ - def appliedToArgss(argss: List[List[Term]]): Term = - argss.foldLeft(self: Term)(Apply(_, _)) + def appliedToArgss(argss: List[List[Term]]): Term /** The current tree applied to (): `tree()` */ - def appliedToNone: Apply = - self.appliedToArgs(Nil) + def appliedToNone: Apply /** The current tree applied to given type argument: `tree[targ]` */ - def appliedToType(targ: Type): Term = - self.appliedToTypes(targ :: Nil) + def appliedToType(targ: Type): Term /** The current tree applied to given type arguments: `tree[targ0, ..., targN]` */ - def appliedToTypes(targs: List[Type]): Term = - self.appliedToTypeTrees(targs map (Inferred(_))) + def appliedToTypes(targs: List[Type]): Term /** The current tree applied to given type argument list: `tree[targs(0), ..., targs(targs.length - 1)]` */ - def appliedToTypeTrees(targs: List[TypeTree]): Term = - if (targs.isEmpty) self else TypeApply(self, targs) + def appliedToTypeTrees(targs: List[TypeTree]): Term - /** A select node that selects the given symbol. - */ - def select(sym: Symbol): Select = Select(self, sym) + /** A select node that selects the given symbol. */ + def select(sym: Symbol): Select end extension - end TermOps + } + + /** Tree representing a reference to definition */ + type Ref <: Term - given TypeTest[Tree, Term] = reflectSelf.Term_TypeTest + given TypeTest[Tree, Ref] = RefTypeTest + protected val RefTypeTest: TypeTest[Tree, Ref] - given TypeTest[Tree, Ref] = reflectSelf.Ref_TypeTest + val Ref: RefModule - object Ref: + trait RefModule { this: Ref.type => /** A tree representing the same reference as the given type */ - def term(tp: TermRef): Ref = - reflectSelf.Ref_term(tp) + def term(tp: TermRef): Ref /** Create a reference tree from a symbol * @@ -344,38 +474,48 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * the class body of `C`, or have `foo` outside the lexical * scope for the definition of `foo`. */ - def apply(sym: Symbol): Ref = - reflectSelf.Ref_apply(sym) - end Ref + def apply(sym: Symbol): Ref + } + + /** Tree representing a reference to definition with a given name */ + type Ident <: Ref - given TypeTest[Tree, Ident] = reflectSelf.Ident_TypeTest + given TypeTest[Tree, Ident] = IdentTypeTest + protected val IdentTypeTest: TypeTest[Tree, Ident] /** Scala term identifier */ - object Ident: - def apply(tmref: TermRef): Term = - reflectSelf.Ident_apply(tmref) + val Ident: IdentModule + + trait IdentModule { this: Ident.type => + def apply(tmref: TermRef): Term - def copy(original: Tree)(name: String): Ident = - reflectSelf.Ident_copy(original)(name) + def copy(original: Tree)(name: String): Ident /** Matches a term identifier and returns its name */ - def unapply(tree: Ident): Option[String] = - Some(tree.name) - end Ident + def unapply(tree: Ident): Option[String] + } + + given IdentMethods as IdentMethods = IdentMethodsImpl + protected val IdentMethodsImpl: IdentMethods - given IdentOps as AnyRef: + trait IdentMethods: extension (self: Ident): - def name: String = reflectSelf.Ident_name(self) + def name: String end extension - end IdentOps + end IdentMethods + + /** Tree representing a selection of definition with a given name on a given prefix */ + type Select <: Ref - given TypeTest[Tree, Select] = reflectSelf.Select_TypeTest + given TypeTest[Tree, Select] = SelectTypeTest + protected val SelectTypeTest: TypeTest[Tree, Select] /** Scala term selection */ - object Select: + val Select: SelectModule + + trait SelectModule { this: Select.type => /** Select a term member by symbol */ - def apply(qualifier: Term, symbol: Symbol): Select = - reflectSelf.Select_apply(qualifier, symbol) + def apply(qualifier: Term, symbol: Symbol): Select /** Select a field or a non-overloaded method by name * @@ -383,291 +523,360 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * method is overloaded. The method `overloaded` should be used * in that case. */ - def unique(qualifier: Term, name: String): Select = - reflectSelf.Select_unique(qualifier, name) + def unique(qualifier: Term, name: String): Select // TODO rename, this returns an Apply and not a Select /** Call an overloaded method with the given type and term parameters */ - def overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term]): Apply = - reflectSelf.Select_overloaded(qualifier, name, targs, args) + def overloaded(qualifier: Term, name: String, targs: List[Type], args: List[Term]): Apply - def copy(original: Tree)(qualifier: Term, name: String): Select = - reflectSelf.Select_copy(original)(qualifier, name) + def copy(original: Tree)(qualifier: Term, name: String): Select /** Matches `.` */ - def unapply(x: Select): Option[(Term, String)] = - Some((x.qualifier, x.name)) - end Select + def unapply(x: Select): Option[(Term, String)] + } + + given SelectMethods as SelectMethods = SelectMethodsImpl + protected val SelectMethodsImpl: SelectMethods - given SelectOps as AnyRef: + trait SelectMethods: extension (self: Select): - def qualifier: Term = reflectSelf.Select_qualifier(self) - def name: String = reflectSelf.Select_name(self) - def signature: Option[Signature] = reflectSelf.Select_signature(self) + def qualifier: Term + def name: String + def signature: Option[Signature] end extension - end SelectOps + end SelectMethods - given TypeTest[Tree, Literal] = - reflectSelf.Literal_TypeTest + given TypeTest[Tree, Literal] = LiteralTypeTest + protected val LiteralTypeTest: TypeTest[Tree, Literal] + + /** Tree representing a literal value in the source code */ + type Literal <: Term /** Scala literal constant */ - object Literal: + val Literal: LiteralModule + + trait LiteralModule { this: Literal.type => /** Create a literal constant */ - def apply(constant: Constant): Literal = - reflectSelf.Literal_apply(constant) + def apply(constant: Constant): Literal - def copy(original: Tree)(constant: Constant): Literal = - reflectSelf.Literal_copy(original)(constant) + def copy(original: Tree)(constant: Constant): Literal /** Matches a literal constant */ - def unapply(x: Literal): Option[Constant] = - Some(x.constant) - end Literal + def unapply(x: Literal): Option[Constant] + } - given LiteralOps as AnyRef: + given LiteralMethods as LiteralMethods = LiteralMethodsImpl + protected val LiteralMethodsImpl: LiteralMethods + + trait LiteralMethods: extension (self: Literal): - def constant: Constant = reflectSelf.Literal_constant(self) + def constant: Constant end extension - end LiteralOps + end LiteralMethods + + /** Tree representing `this` in the source code */ + type This <: Term - given TypeTest[Tree, This] = reflectSelf.This_TypeTest + given TypeTest[Tree, This] = ThisTypeTest + protected val ThisTypeTest: TypeTest[Tree, This] /** Scala `this` or `this[id]` */ - object This: + val This: ThisModule + + trait ThisModule { this: This.type => /** Create a `this[` */ - def apply(cls: Symbol): This = - reflectSelf.This_apply(cls) + def apply(cls: Symbol): This - def copy(original: Tree)(qual: Option[Id]): This = - reflectSelf.This_copy(original)(qual) + def copy(original: Tree)(qual: Option[Id]): This /** Matches `this[` */ - def unapply(x: This): Option[Option[Id]] = Some(x.id) - end This + def unapply(x: This): Option[Option[Id]] + } + + given ThisMethods as ThisMethods = ThisMethodsImpl + protected val ThisMethodsImpl: ThisMethods - given ThisOps as AnyRef: + trait ThisMethods: extension (self: This): - def id: Option[Id] = reflectSelf.This_id(self) + def id: Option[Id] end extension - end ThisOps + end ThisMethods + + /** Tree representing `new` in the source code */ + type New <: Term - given TypeTest[Tree, New] = reflectSelf.New_TypeTest + given TypeTest[Tree, New] = NewTypeTest + protected val NewTypeTest: TypeTest[Tree, New] /** Scala `new` */ - object New: + val New: NewModule + + trait NewModule { this: New.type => /** Create a `new ` */ - def apply(tpt: TypeTree): New = - reflectSelf.New_apply(tpt) + def apply(tpt: TypeTree): New - def copy(original: Tree)(tpt: TypeTree): New = - reflectSelf.New_copy(original)(tpt) + def copy(original: Tree)(tpt: TypeTree): New /** Matches a `new ` */ - def unapply(x: New): Option[TypeTree] = Some(x.tpt) - end New + def unapply(x: New): Option[TypeTree] + } - given NewOps as AnyRef: + given NewMethods as NewMethods = NewMethodsImpl + protected val NewMethodsImpl: NewMethods + + trait NewMethods: extension (self: New): - def tpt: TypeTree = reflectSelf.New_tpt(self) + def tpt: TypeTree end extension - end NewOps + end NewMethods + + /** Tree representing an argument passed with an explicit name. Such as `arg1 = x` in `foo(arg1 = x)` */ + type NamedArg <: Term - given as TypeTest[Tree, NamedArg] = reflectSelf.NamedArg_TypeTest + given TypeTest[Tree, NamedArg] = NamedArgTypeTest + protected val NamedArgTypeTest: TypeTest[Tree, NamedArg] /** Scala named argument `x = y` in argument position */ - object NamedArg: + val NamedArg: NamedArgModule + + trait NamedArgModule { this: NamedArg.type => /** Create a named argument ` = ` */ - def apply(name: String, arg: Term): NamedArg = - reflectSelf.NamedArg_apply(name, arg) + def apply(name: String, arg: Term): NamedArg - def copy(original: Tree)(name: String, arg: Term): NamedArg = - reflectSelf.NamedArg_copy(original)(name, arg) + def copy(original: Tree)(name: String, arg: Term): NamedArg /** Matches a named argument ` = ` */ - def unapply(x: NamedArg): Option[(String, Term)] = - Some((x.name, x.value)) - end NamedArg + def unapply(x: NamedArg): Option[(String, Term)] + } + + given NamedArgMethods as NamedArgMethods = NamedArgMethodsImpl + protected val NamedArgMethodsImpl: NamedArgMethods - given NamedArgOps as AnyRef: + trait NamedArgMethods: extension (self: NamedArg): - def name: String = reflectSelf.NamedArg_name(self) - def value: Term = reflectSelf.NamedArg_value(self) + def name: String + def value: Term end extension - end NamedArgOps + end NamedArgMethods - given TypeTest[Tree, Apply] = reflectSelf.Apply_TypeTest + /** Tree an application of arguments. It represents a single list of arguments, multiple argument lists will have nested `Apply`s */ + type Apply <: Term + + given TypeTest[Tree, Apply] = ApplyTypeTest + protected val ApplyTypeTest: TypeTest[Tree, Apply] /** Scala parameter application */ - object Apply: + val Apply: ApplyModule + + trait ApplyModule { this: Apply.type => /** Create a function application `()` */ - def apply(fun: Term, args: List[Term]): Apply = - reflectSelf.Apply_apply(fun, args) + def apply(fun: Term, args: List[Term]): Apply - def copy(original: Tree)(fun: Term, args: List[Term]): Apply = - reflectSelf.Apply_copy(original)(fun, args) + def copy(original: Tree)(fun: Term, args: List[Term]): Apply /** Matches a function application `()` */ - def unapply(x: Apply): Option[(Term, List[Term])] = - Some((x.fun, x.args)) - end Apply + def unapply(x: Apply): Option[(Term, List[Term])] + } - given ApplyOps as AnyRef: + given ApplyMethods as ApplyMethods = ApplyMethodsImpl + protected val ApplyMethodsImpl: ApplyMethods + + trait ApplyMethods: extension (self: Apply): - def fun: Term = reflectSelf.Apply_fun(self) - def args: List[Term] = reflectSelf.Apply_args(self) + def fun: Term + def args: List[Term] end extension - end ApplyOps + end ApplyMethods + + /** Tree an application of type arguments */ + type TypeApply <: Term - given TypeTest[Tree, TypeApply] = reflectSelf.TypeApply_TypeTest + given TypeTest[Tree, TypeApply] = TypeApplyTypeTest + protected val TypeApplyTypeTest: TypeTest[Tree, TypeApply] /** Scala type parameter application */ - object TypeApply: + val TypeApply: TypeApplyModule + + trait TypeApplyModule { this: TypeApply.type => /** Create a function type application `[]` */ - def apply(fun: Term, args: List[TypeTree]): TypeApply = - reflectSelf.TypeApply_apply(fun, args) + def apply(fun: Term, args: List[TypeTree]): TypeApply - def copy(original: Tree)(fun: Term, args: List[TypeTree]): TypeApply = - reflectSelf.TypeApply_copy(original)(fun, args) + def copy(original: Tree)(fun: Term, args: List[TypeTree]): TypeApply /** Matches a function type application `[]` */ - def unapply(x: TypeApply): Option[(Term, List[TypeTree])] = - Some((x.fun, x.args)) - end TypeApply + def unapply(x: TypeApply): Option[(Term, List[TypeTree])] + } + + given TypeApplyMethods as TypeApplyMethods = TypeApplyMethodsImpl + protected val TypeApplyMethodsImpl: TypeApplyMethods - given TypeApplyOps as AnyRef: + trait TypeApplyMethods: extension (self: TypeApply): - def fun: Term = reflectSelf.TypeApply_fun(self) - def args: List[TypeTree] = reflectSelf.TypeApply_args(self) + def fun: Term + def args: List[TypeTree] end extension - end TypeApplyOps + end TypeApplyMethods + + given TypeTest[Tree, Super] = SuperTypeTest + protected val SuperTypeTest: TypeTest[Tree, Super] - given TypeTest[Tree, Super] = reflectSelf.Super_TypeTest + /** Tree representing `super` in the source code */ + type Super <: Term /** Scala `x.super` or `x.super[id]` */ - object Super: + val Super: SuperModule + + trait SuperModule { this: Super.type => /** Creates a `.super[` */ - def apply(qual: Term, mix: Option[Id]): Super = - reflectSelf.Super_apply(qual, mix) + def apply(qual: Term, mix: Option[Id]): Super - def copy(original: Tree)(qual: Term, mix: Option[Id]): Super = - reflectSelf.Super_copy(original)(qual, mix) + def copy(original: Tree)(qual: Term, mix: Option[Id]): Super /** Matches a `.super[` */ - def unapply(x: Super): Option[(Term, Option[Id])] = - Some((x.qualifier, x.id)) - end Super + def unapply(x: Super): Option[(Term, Option[Id])] + } + + given SuperMethods as SuperMethods = SuperMethodsImpl + protected val SuperMethodsImpl: SuperMethods - given SuperOps as AnyRef: + trait SuperMethods: extension (self: Super): - def qualifier: Term = reflectSelf.Super_qualifier(self) - def id: Option[Id] = reflectSelf.Super_id(self) + def qualifier: Term + def id: Option[Id] end extension - end SuperOps + end SuperMethods + given TypeTest[Tree, Typed] = TypedTypeTest + protected val TypedTypeTest: TypeTest[Tree, Typed] - given TypeTest[Tree, Typed] = reflectSelf.Typed_TypeTest + /** Tree representing a type ascription `x: T` in the source code */ + type Typed <: Term /** Scala ascription `x: T` */ - object Typed: + val Typed: TypedModule + + trait TypedModule { this: Typed.type => /** Create a type ascription `: ` */ - def apply(expr: Term, tpt: TypeTree): Typed = - reflectSelf.Typed_apply(expr, tpt) + def apply(expr: Term, tpt: TypeTree): Typed - def copy(original: Tree)(expr: Term, tpt: TypeTree): Typed = - reflectSelf.Typed_copy(original)(expr, tpt) + def copy(original: Tree)(expr: Term, tpt: TypeTree): Typed /** Matches `: ` */ - def unapply(x: Typed): Option[(Term, TypeTree)] = - Some((x.expr, x.tpt)) - end Typed + def unapply(x: Typed): Option[(Term, TypeTree)] + } + + given TypedMethods as TypedMethods = TypedMethodsImpl + protected val TypedMethodsImpl: TypedMethods - given TypedOps as AnyRef: + trait TypedMethods: extension (self: Typed): - def expr: Term = reflectSelf.Typed_expr(self) - def tpt: TypeTree = reflectSelf.Typed_tpt(self) + def expr: Term + def tpt: TypeTree end extension - end TypedOps + end TypedMethods + /** Tree representing an assignment `x = y` in the source code */ + type Assign <: Term - given TypeTest[Tree, Assign] = reflectSelf.Assign_TypeTest + given TypeTest[Tree, Assign] = AssignTypeTest + protected val AssignTypeTest: TypeTest[Tree, Assign] /** Scala assign `x = y` */ - object Assign: + val Assign: AssignModule + + trait AssignModule { this: Assign.type => /** Create an assignment ` = ` */ - def apply(lhs: Term, rhs: Term): Assign = - reflectSelf.Assign_apply(lhs, rhs) + def apply(lhs: Term, rhs: Term): Assign - def copy(original: Tree)(lhs: Term, rhs: Term): Assign = - reflectSelf.Assign_copy(original)(lhs, rhs) + def copy(original: Tree)(lhs: Term, rhs: Term): Assign /** Matches an assignment ` = ` */ - def unapply(x: Assign): Option[(Term, Term)] = - Some((x.lhs, x.rhs)) - end Assign + def unapply(x: Assign): Option[(Term, Term)] + } + + given AssignMethods as AssignMethods = AssignMethodsImpl + protected val AssignMethodsImpl: AssignMethods - given AssignOps as AnyRef: + trait AssignMethods: extension (self: Assign): - def lhs: Term = reflectSelf.Assign_lhs(self) - def rhs: Term = reflectSelf.Assign_rhs(self) + def lhs: Term + def rhs: Term end extension - end AssignOps + end AssignMethods + /** Tree representing a block `{ ... }` in the source code */ + type Block <: Term - given TypeTest[Tree, Block] = reflectSelf.Block_TypeTest + given TypeTest[Tree, Block] = BlockTypeTest + protected val BlockTypeTest: TypeTest[Tree, Block] /** Scala code block `{ stat0; ...; statN; expr }` term */ - object Block: + val Block: BlockModule + + trait BlockModule { this: Block.type => /** Creates a block `{ ; }` */ - def apply(stats: List[Statement], expr: Term): Block = - reflectSelf.Block_apply(stats, expr) + def apply(stats: List[Statement], expr: Term): Block - def copy(original: Tree)(stats: List[Statement], expr: Term): Block = - reflectSelf.Block_copy(original)(stats, expr) + def copy(original: Tree)(stats: List[Statement], expr: Term): Block /** Matches a block `{ ; }` */ - def unapply(x: Block): Option[(List[Statement], Term)] = - Some((x.statements, x.expr)) - end Block + def unapply(x: Block): Option[(List[Statement], Term)] + } - given BlockOps as AnyRef: + given BlockMethods as BlockMethods = BlockMethodsImpl + protected val BlockMethodsImpl: BlockMethods + + trait BlockMethods: extension (self: Block): - def statements: List[Statement] = reflectSelf.Block_statements(self) - def expr: Term = reflectSelf.Block_expr(self) + def statements: List[Statement] + def expr: Term end extension - end BlockOps + end BlockMethods + given TypeTest[Tree, Closure] = ClosureTypeTest + protected val ClosureTypeTest: TypeTest[Tree, Closure] - given TypeTest[Tree, Closure] = reflectSelf.Closure_TypeTest + /** A lambda `(...) => ...` in the source code is represented as + * a local method and a closure: + * + * { + * def m(...) = ... + * closure(m) + * } + * + */ + type Closure <: Term - object Closure: + val Closure: ClosureModule - def apply(meth: Term, tpt: Option[Type]): Closure = - reflectSelf.Closure_apply(meth, tpt) + trait ClosureModule { this: Closure.type => - def copy(original: Tree)(meth: Tree, tpt: Option[Type]): Closure = - reflectSelf.Closure_copy(original)(meth, tpt) + def apply(meth: Term, tpe: Option[Type]): Closure - def unapply(x: Closure): Option[(Term, Option[Type])] = - Some((x.meth, x.tpeOpt)) - end Closure + def copy(original: Tree)(meth: Tree, tpe: Option[Type]): Closure - given ClosureOps as AnyRef: + def unapply(x: Closure): Option[(Term, Option[Type])] + } + + given ClosureMethods as ClosureMethods = ClosureMethodsImpl + protected val ClosureMethodsImpl: ClosureMethods + + trait ClosureMethods: extension (self: Closure): - def meth: Term = reflectSelf.Closure_meth(self) - def tpeOpt: Option[Type] = reflectSelf.Closure_tpeOpt(self) + def meth: Term + def tpeOpt: Option[Type] end extension - end ClosureOps - + end ClosureMethods /** A lambda `(...) => ...` in the source code is represented as * a local method and a closure: @@ -681,663 +890,840 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * should come before the case for `Block` to avoid mishandling * of `Lambda`. */ - object Lambda: - def unapply(tree: Block): Option[(List[ValDef], Term)] = tree match { - case Block((ddef @ DefDef(_, _, params :: Nil, _, Some(body))) :: Nil, Closure(meth, _)) - if ddef.symbol == meth.symbol => - Some(params, body) + val Lambda: LambdaModule - case _ => None - } - - def apply(tpe: MethodType, rhsFn: List[Tree] => Tree): Block = - reflectSelf.Lambda_apply(tpe, rhsFn) + trait LambdaModule { this: Lambda.type => + def unapply(tree: Block): Option[(List[ValDef], Term)] + def apply(tpe: MethodType, rhsFn: List[Tree] => Tree): Block + } - end Lambda + given TypeTest[Tree, If] = IfTypeTest + protected val IfTypeTest: TypeTest[Tree, If] - given TypeTest[Tree, If] = reflectSelf.If_TypeTest + /** Tree representing an if/then/else `if (...) ... else ...` in the source code */ + type If <: Term /** Scala `if`/`else` term */ - object If: + val If: IfModule + + trait IfModule { this: If.type => /** Create an if/then/else `if () else ` */ - def apply(cond: Term, thenp: Term, elsep: Term): If = - reflectSelf.If_apply(cond, thenp, elsep) + def apply(cond: Term, thenp: Term, elsep: Term): If - def copy(original: Tree)(cond: Term, thenp: Term, elsep: Term): If = - reflectSelf.If_copy(original)(cond, thenp, elsep) + def copy(original: Tree)(cond: Term, thenp: Term, elsep: Term): If /** Matches an if/then/else `if () else ` */ - def unapply(tree: If): Option[(Term, Term, Term)] = - Some((tree.cond, tree.thenp, tree.elsep)) - end If + def unapply(tree: If): Option[(Term, Term, Term)] + } + + given IfMethods as IfMethods = IfMethodsImpl + protected val IfMethodsImpl: IfMethods - given IfOps as AnyRef: + trait IfMethods: extension (self: If): - def cond: Term = reflectSelf.If_cond(self) - def thenp: Term = reflectSelf.If_thenp(self) - def elsep: Term = reflectSelf.If_elsep(self) + def cond: Term + def thenp: Term + def elsep: Term end extension - end IfOps + end IfMethods - given TypeTest[Tree, Match] = reflectSelf.Match_TypeTest + /** Tree representing a pattern match `x match { ... }` in the source code */ + type Match <: Term + + given TypeTest[Tree, Match] = MatchTypeTest + protected val MatchTypeTest: TypeTest[Tree, Match] /** Scala `match` term */ - object Match: + val Match: MatchModule + + trait MatchModule { this: Match.type => /** Creates a pattern match ` match { }` */ - def apply(selector: Term, cases: List[CaseDef]): Match = - reflectSelf.Match_apply(selector, cases) + def apply(selector: Term, cases: List[CaseDef]): Match - def copy(original: Tree)(selector: Term, cases: List[CaseDef]): Match = - reflectSelf.Match_copy(original)(selector, cases) + def copy(original: Tree)(selector: Term, cases: List[CaseDef]): Match /** Matches a pattern match ` match { }` */ - def unapply(x: Match): Option[(Term, List[CaseDef])] = - Some((x.scrutinee, x.cases)) - end Match + def unapply(x: Match): Option[(Term, List[CaseDef])] + } - given MatchOps as AnyRef: + given MatchMethods as MatchMethods = MatchMethodsImpl + protected val MatchMethodsImpl: MatchMethods + + trait MatchMethods: extension (self: Match): - def scrutinee: Term = reflectSelf.Match_scrutinee(self) - def cases: List[CaseDef] = reflectSelf.Match_cases(self) + def scrutinee: Term + def cases: List[CaseDef] end extension - end MatchOps + end MatchMethods + /** Tree representing a pattern match `given match { ... }` in the source code */ // TODO: drop + type GivenMatch <: Term - given TypeTest[Tree, GivenMatch] = reflectSelf.GivenMatch_TypeTest + given TypeTest[Tree, GivenMatch] = GivenMatchTypeTest + protected val GivenMatchTypeTest: TypeTest[Tree, GivenMatch] /** Scala implicit `match` term */ - object GivenMatch: + val GivenMatch: GivenMatchModule + + trait GivenMatchModule { this: GivenMatch.type => /** Creates a pattern match `given match { }` */ - def apply(cases: List[CaseDef]): GivenMatch = - reflectSelf.GivenMatch_apply(cases) + def apply(cases: List[CaseDef]): GivenMatch - def copy(original: Tree)(cases: List[CaseDef]): GivenMatch = - reflectSelf.GivenMatch_copy(original)(cases) + def copy(original: Tree)(cases: List[CaseDef]): GivenMatch /** Matches a pattern match `given match { }` */ - def unapply(x: GivenMatch): Option[List[CaseDef]] = Some(x.cases) - end GivenMatch + def unapply(x: GivenMatch): Option[List[CaseDef]] + } + + given GivenMatchMethods as GivenMatchMethods = GivenMatchMethodsImpl + protected val GivenMatchMethodsImpl: GivenMatchMethods - given GivenMatchOps as AnyRef: + trait GivenMatchMethods: extension (self: GivenMatch): - def cases: List[CaseDef] = reflectSelf.GivenMatch_cases(self) + def cases: List[CaseDef] end extension - end GivenMatchOps + end GivenMatchMethods + /** Tree representing a try catch `try x catch { ... } finally { ... }` in the source code */ + type Try <: Term - given TypeTest[Tree, Try] = reflectSelf.Try_TypeTest + given TypeTest[Tree, Try] = TryTypeTest + protected val TryTypeTest: TypeTest[Tree, Try] /** Scala `try`/`catch`/`finally` term */ - object Try: + val Try: TryModule + + trait TryModule { this: Try.type => /** Create a try/catch `try catch { } finally ` */ - def apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term]): Try = - reflectSelf.Try_apply(expr, cases, finalizer) + def apply(expr: Term, cases: List[CaseDef], finalizer: Option[Term]): Try - def copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term]): Try = - reflectSelf.Try_copy(original)(expr, cases, finalizer) + def copy(original: Tree)(expr: Term, cases: List[CaseDef], finalizer: Option[Term]): Try /** Matches a try/catch `try catch { } finally ` */ - def unapply(x: Try): Option[(Term, List[CaseDef], Option[Term])] = - Some((x.body, x.cases, x.finalizer)) - end Try + def unapply(x: Try): Option[(Term, List[CaseDef], Option[Term])] + } + + given TryMethods as TryMethods = TryMethodsImpl + protected val TryMethodsImpl: TryMethods - given TryOps as AnyRef: + trait TryMethods: extension (self: Try): - def body: Term = reflectSelf.Try_body(self) - def cases: List[CaseDef] = reflectSelf.Try_cases(self) - def finalizer: Option[Term] = reflectSelf.Try_finalizer(self) + def body: Term + def cases: List[CaseDef] + def finalizer: Option[Term] end extension - end TryOps + end TryMethods + given TypeTest[Tree, Return] = ReturnTypeTest + protected val ReturnTypeTest: TypeTest[Tree, Return] - given TypeTest[Tree, Return] = reflectSelf.Return_TypeTest + /** Tree representing a `return` in the source code */ + type Return <: Term /** Scala local `return` */ - object Return: + val Return: ReturnModule + + trait ReturnModule { this: Return.type => /** Creates `return ` */ - def apply(expr: Term): Return = - reflectSelf.Return_apply(expr) + def apply(expr: Term): Return - def copy(original: Tree)(expr: Term): Return = - reflectSelf.Return_copy(original)(expr) + def copy(original: Tree)(expr: Term): Return /** Matches `return ` */ - def unapply(x: Return): Option[Term] = Some(x.expr) - end Return + def unapply(x: Return): Option[Term] + } + + given ReturnMethods as ReturnMethods = ReturnMethodsImpl + protected val ReturnMethodsImpl: ReturnMethods - given ReturnOps as AnyRef: + trait ReturnMethods: extension (self: Return): - def expr: Term = reflectSelf.Return_expr(self) + def expr: Term end extension - end ReturnOps + end ReturnMethods + /** Tree representing a variable argument list in the source code */ + type Repeated <: Term - given TypeTest[Tree, Repeated] = reflectSelf.Repeated_TypeTest + given TypeTest[Tree, Repeated] = RepeatedTypeTest + protected val RepeatedTypeTest: TypeTest[Tree, Repeated] - object Repeated: + val Repeated: RepeatedModule - def apply(elems: List[Term], tpt: TypeTree): Repeated = - reflectSelf.Repeated_apply(elems, tpt) - - def copy(original: Tree)(elems: List[Term], tpt: TypeTree): Repeated = - reflectSelf.Repeated_copy(original)(elems, tpt) + trait RepeatedModule { this: Repeated.type => + def apply(elems: List[Term], tpt: TypeTree): Repeated + def copy(original: Tree)(elems: List[Term], tpt: TypeTree): Repeated + def unapply(x: Repeated): Option[(List[Term], TypeTree)] + } - def unapply(x: Repeated): Option[(List[Term], TypeTree)] = - Some((x.elems, x.elemtpt)) - end Repeated + given RepeatedMethods as RepeatedMethods = RepeatedMethodsImpl + protected val RepeatedMethodsImpl: RepeatedMethods - given RepeatedOps as AnyRef: + trait RepeatedMethods: extension (self: Repeated): - def elems: List[Term] = reflectSelf.Repeated_elems(self) - def elemtpt: TypeTree = reflectSelf.Repeated_elemtpt(self) + def elems: List[Term] + def elemtpt: TypeTree end extension - end RepeatedOps - + end RepeatedMethods - given TypeTest[Tree, Inlined] = reflectSelf.Inlined_TypeTest + /** Tree representing the scope of an inlined tree */ + type Inlined <: Term - object Inlined: + given TypeTest[Tree, Inlined] = InlinedTypeTest + protected val InlinedTypeTest: TypeTest[Tree, Inlined] - def apply(call: Option[Tree /* Term | TypeTree */], bindings: List[Definition], expansion: Term): Inlined = - reflectSelf.Inlined_apply(call, bindings, expansion) + val Inlined: InlinedModule - def copy(original: Tree)(call: Option[Tree /* Term | TypeTree */], bindings: List[Definition], expansion: Term): Inlined = - reflectSelf.Inlined_copy(original)(call, bindings, expansion) + trait InlinedModule { this: Inlined.type => + def apply(call: Option[Tree /* Term | TypeTree */], bindings: List[Definition], expansion: Term): Inlined + def copy(original: Tree)(call: Option[Tree /* Term | TypeTree */], bindings: List[Definition], expansion: Term): Inlined + def unapply(x: Inlined): Option[(Option[Tree /* Term | TypeTree */], List[Definition], Term)] + } - def unapply(x: Inlined): Option[(Option[Tree /* Term | TypeTree */], List[Definition], Term)] = - Some((x.call, x.bindings, x.body)) - end Inlined + given InlinedMethods as InlinedMethods = InlinedMethodsImpl + protected val InlinedMethodsImpl: InlinedMethods - given InlinedOps as AnyRef: + trait InlinedMethods: extension (self: Inlined): - def call: Option[Tree /* Term | TypeTree */] = reflectSelf.Inlined_call(self) - def bindings: List[Definition] = reflectSelf.Inlined_bindings(self) - def body: Term = reflectSelf.Inlined_body(self) + def call: Option[Tree /* Term | TypeTree */] + def bindings: List[Definition] + def body: Term end extension - end InlinedOps - + end InlinedMethods - given TypeTest[Tree, SelectOuter] = reflectSelf.SelectOuter_TypeTest + /** Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees */ + type SelectOuter <: Term - object SelectOuter: + given TypeTest[Tree, SelectOuter] = SelectOuterTypeTest + protected val SelectOuterTypeTest: TypeTest[Tree, SelectOuter] - def apply(qualifier: Term, name: String, levels: Int): SelectOuter = - reflectSelf.SelectOuter_apply(qualifier, name, levels) + val SelectOuter: SelectOuterModule - def copy(original: Tree)(qualifier: Term, name: String, levels: Int): SelectOuter = - reflectSelf.SelectOuter_copy(original)(qualifier, name, levels) + trait SelectOuterModule { this: SelectOuter.type => + def apply(qualifier: Term, name: String, levels: Int): SelectOuter + def copy(original: Tree)(qualifier: Term, name: String, levels: Int): SelectOuter + def unapply(x: SelectOuter): Option[(Term, Int, Type)] // TODO homogenize order of parameters + } - def unapply(x: SelectOuter): Option[(Term, Int, Type)] = // TODO homogenize order of parameters - Some((x.qualifier, x.level, x.tpe)) - end SelectOuter + given SelectOuterMethods as SelectOuterMethods = SelectOuterMethodsImpl + protected val SelectOuterMethodsImpl: SelectOuterMethods - given SelectOuterOps as AnyRef: + trait SelectOuterMethods: extension (self: SelectOuter): - def qualifier: Term = reflectSelf.SelectOuter_qualifier(self) - def level: Int = reflectSelf.SelectOuter_level(self) + def qualifier: Term + def level: Int end extension - end SelectOuterOps + end SelectOuterMethods + /** Tree representing a while loop */ + type While <: Term - given TypeTest[Tree, While] = reflectSelf.While_TypeTest + given TypeTest[Tree, While] = WhileTypeTest + protected val WhileTypeTest: TypeTest[Tree, While] - object While: + val While: WhileModule + + trait WhileModule { this: While.type => /** Creates a while loop `while () ` and returns (, ) */ - def apply(cond: Term, body: Term): While = - reflectSelf.While_apply(cond, body) + def apply(cond: Term, body: Term): While - def copy(original: Tree)(cond: Term, body: Term): While = - reflectSelf.While_copy(original)(cond, body) + def copy(original: Tree)(cond: Term, body: Term): While /** Extractor for while loops. Matches `while () ` and returns (, ) */ - def unapply(x: While): Option[(Term, Term)] = - Some((x.cond, x.body)) - end While + def unapply(x: While): Option[(Term, Term)] + } + + given WhileMethods as WhileMethods = WhileMethodsImpl + protected val WhileMethodsImpl: WhileMethods - given WhileOps as AnyRef: + trait WhileMethods: extension (self: While): - def cond: Term = reflectSelf.While_cond(self) - def body: Term = reflectSelf.While_body(self) + def cond: Term + def body: Term end extension - end WhileOps - + end WhileMethods // ----- TypeTrees ------------------------------------------------ - given TypeTest[Tree, TypeTree] = reflectSelf.TypeTree_TypeTest + /** Type tree representing a type written in the source */ + type TypeTree <: Tree + + given TypeTest[Tree, TypeTree] = TypeTreeTypeTest + protected val TypeTreeTypeTest: TypeTest[Tree, TypeTree] + + val TypeTree: TypeTreeModule - object TypeTree + trait TypeTreeModule { this: TypeTree.type => } - given TypeTreeOps as AnyRef: + given TypeTreeMethods as TypeTreeMethods = TypeTreeMethodsImpl + protected val TypeTreeMethodsImpl: TypeTreeMethods + + trait TypeTreeMethods: extension (self: TypeTree): /** Type of this type tree */ - def tpe: Type = reflectSelf.TypeTree_tpe(self) + def tpe: Type end extension - end TypeTreeOps + end TypeTreeMethods + + /** Type tree representing an inferred type */ + type Inferred <: TypeTree - given TypeTest[Tree, Inferred] = reflectSelf.Inferred_TypeTest + given TypeTest[Tree, Inferred] = InferredTypeTest + protected val InferredTypeTest: TypeTest[Tree, Inferred] /** TypeTree containing an inferred type */ - object Inferred: - def apply(tpe: Type): Inferred = - reflectSelf.Inferred_apply(tpe) + val Inferred: InferredModule + + trait InferredModule { this: Inferred.type => + def apply(tpe: Type): Inferred /** Matches a TypeTree containing an inferred type */ - def unapply(x: Inferred): Boolean = true - end Inferred + def unapply(x: Inferred): Boolean + } + + /** Type tree representing a reference to definition with a given name */ + type TypeIdent <: TypeTree - given TypeTest[Tree, TypeIdent] = reflectSelf.TypeIdent_TypeTest + given TypeTest[Tree, TypeIdent] = TypeIdentTypeTest + protected val TypeIdentTypeTest: TypeTest[Tree, TypeIdent] - object TypeIdent: - def apply(sym: Symbol): TypeTree = - reflectSelf.TypeRef_apply(sym) - def copy(original: Tree)(name: String): TypeIdent = - reflectSelf.TypeIdent_copy(original)(name) - def unapply(x: TypeIdent): Option[String] = Some(x.name) - end TypeIdent + val TypeIdent: TypeIdentModule + + trait TypeIdentModule { this: TypeIdent.type => + def apply(sym: Symbol): TypeTree + def copy(original: Tree)(name: String): TypeIdent + def unapply(x: TypeIdent): Option[String] + } - given TypeIdentOps as AnyRef: + given TypeIdentMethods as TypeIdentMethods = TypeIdentMethodsImpl + protected val TypeIdentMethodsImpl: TypeIdentMethods + + trait TypeIdentMethods: extension (self: TypeIdent): - def name: String = reflectSelf.TypeIdent_name(self) + def name: String end extension - end TypeIdentOps + end TypeIdentMethods + + /** Type tree representing a selection of definition with a given name on a given term prefix */ + type TypeSelect <: TypeTree - given TypeTest[Tree, TypeSelect] = reflectSelf.TypeSelect_TypeTest + given TypeTest[Tree, TypeSelect] = TypeSelectTypeTest + protected val TypeSelectTypeTest: TypeTest[Tree, TypeSelect] - object TypeSelect: - def apply(qualifier: Term, name: String): TypeSelect = - reflectSelf.TypeSelect_apply(qualifier, name) - def copy(original: Tree)(qualifier: Term, name: String): TypeSelect = - reflectSelf.TypeSelect_copy(original)(qualifier, name) - def unapply(x: TypeSelect): Option[(Term, String)] = - Some((x.qualifier, x.name)) - end TypeSelect + val TypeSelect: TypeSelectModule - given TypeSelectOps as AnyRef: + trait TypeSelectModule { this: TypeSelect.type => + def apply(qualifier: Term, name: String): TypeSelect + def copy(original: Tree)(qualifier: Term, name: String): TypeSelect + def unapply(x: TypeSelect): Option[(Term, String)] + } + + given TypeSelectMethods as TypeSelectMethods = TypeSelectMethodsImpl + protected val TypeSelectMethodsImpl: TypeSelectMethods + + trait TypeSelectMethods: extension (self: TypeSelect): - def qualifier: Term = reflectSelf.TypeSelect_qualifier(self) - def name: String = reflectSelf.TypeSelect_name(self) + def qualifier: Term + def name: String end extension - end TypeSelectOps + end TypeSelectMethods + + /** Type tree representing a selection of definition with a given name on a given type prefix */ + type Projection <: TypeTree + given TypeTest[Tree, Projection] = ProjectionTypeTest + protected val ProjectionTypeTest: TypeTest[Tree, Projection] - given TypeTest[Tree, Projection] = reflectSelf.Projection_TypeTest + val Projection: ProjectionModule - object Projection: + trait ProjectionModule { this: Projection.type => // TODO def apply(qualifier: TypeTree, name: String): Project - def copy(original: Tree)(qualifier: TypeTree, name: String): Projection = - reflectSelf.Projection_copy(original)(qualifier, name) - def unapply(x: Projection): Option[(TypeTree, String)] = - Some((x.qualifier, x.name)) - end Projection + def copy(original: Tree)(qualifier: TypeTree, name: String): Projection + def unapply(x: Projection): Option[(TypeTree, String)] + } + + given ProjectionMethods as ProjectionMethods = ProjectionMethodsImpl + protected val ProjectionMethodsImpl: ProjectionMethods - given ProjectionOps as AnyRef: + trait ProjectionMethods: extension (self: Projection): - def qualifier: TypeTree = reflectSelf.Projection_qualifier(self) - def name: String = reflectSelf.Projection_name(self) + def qualifier: TypeTree + def name: String end extension - end ProjectionOps + end ProjectionMethods + /** Type tree representing a singleton type */ + type Singleton <: TypeTree - given TypeTest[Tree, Singleton] = reflectSelf.Singleton_TypeTest + given TypeTest[Tree, Singleton] = SingletonTypeTest + protected val SingletonTypeTest: TypeTest[Tree, Singleton] - object Singleton: - def apply(ref: Term): Singleton = - reflectSelf.Singleton_apply(ref) - def copy(original: Tree)(ref: Term): Singleton = - reflectSelf.Singleton_copy(original)(ref) - def unapply(x: Singleton): Option[Term] = - Some(x.ref) - end Singleton + val Singleton: SingletonModule - given SingletonOps as AnyRef: + trait SingletonModule { this: Singleton.type => + def apply(ref: Term): Singleton + def copy(original: Tree)(ref: Term): Singleton + def unapply(x: Singleton): Option[Term] + } + + given SingletonMethods as SingletonMethods = SingletonMethodsImpl + protected val SingletonMethodsImpl: SingletonMethods + + trait SingletonMethods: extension (self: Singleton): - def ref: Term = reflectSelf.Singleton_ref(self) + def ref: Term end extension - end SingletonOps + end SingletonMethods + + /** Type tree representing a type refinement */ + type Refined <: TypeTree + given TypeTest[Tree, Refined] = RefinedTypeTest + protected val RefinedTypeTest: TypeTest[Tree, Refined] - given TypeTest[Tree, Refined] = reflectSelf.Refined_TypeTest + val Refined: RefinedModule - object Refined: + trait RefinedModule { this: Refined.type => // TODO def apply(tpt: TypeTree, refinements: List[Definition]): Refined - def copy(original: Tree)(tpt: TypeTree, refinements: List[Definition]): Refined = - reflectSelf.Refined_copy(original)(tpt, refinements) - def unapply(x: Refined): Option[(TypeTree, List[Definition])] = - Some((x.tpt, x.refinements)) - end Refined + def copy(original: Tree)(tpt: TypeTree, refinements: List[Definition]): Refined + def unapply(x: Refined): Option[(TypeTree, List[Definition])] + } + + given RefinedMethods as RefinedMethods = RefinedMethodsImpl + protected val RefinedMethodsImpl: RefinedMethods - given RefinedOps as AnyRef: + trait RefinedMethods: extension (self: Refined): - def tpt: TypeTree = reflectSelf.Refined_tpt(self) - def refinements: List[Definition] = reflectSelf.Refined_refinements(self) + def tpt: TypeTree + def refinements: List[Definition] end extension - end RefinedOps + end RefinedMethods + + /** Type tree representing a type application */ + type Applied <: TypeTree + given TypeTest[Tree, Applied] = AppliedTypeTest + protected val AppliedTypeTest: TypeTest[Tree, Applied] - given TypeTest[Tree, Applied] = reflectSelf.Applied_TypeTest + val Applied: AppliedModule - object Applied: - def apply(tpt: TypeTree, args: List[Tree /*TypeTree | TypeBoundsTree*/]): Applied = - reflectSelf.Applied_apply(tpt, args) - def copy(original: Tree)(tpt: TypeTree, args: List[Tree /*TypeTree | TypeBoundsTree*/]): Applied = - reflectSelf.Applied_copy(original)(tpt, args) - def unapply(x: Applied): Option[(TypeTree, List[Tree /*TypeTree | TypeBoundsTree*/])] = - Some((x.tpt, x.args)) - end Applied + trait AppliedModule { this: Applied.type => + def apply(tpt: TypeTree, args: List[Tree /*TypeTree | TypeBoundsTree*/]): Applied + def copy(original: Tree)(tpt: TypeTree, args: List[Tree /*TypeTree | TypeBoundsTree*/]): Applied + def unapply(x: Applied): Option[(TypeTree, List[Tree /*TypeTree | TypeBoundsTree*/])] + } + + given AppliedMethods as AppliedMethods = AppliedMethodsImpl + protected val AppliedMethodsImpl: AppliedMethods - given AppliedOps as AnyRef: + trait AppliedMethods: extension (self: Applied): - def tpt: TypeTree = reflectSelf.Applied_tpt(self) - def args: List[Tree /*TypeTree | TypeBoundsTree*/] = reflectSelf.Applied_args(self) + def tpt: TypeTree + def args: List[Tree /*TypeTree | TypeBoundsTree*/] end extension - end AppliedOps + end AppliedMethods + + /** Type tree representing an annotated type */ + type Annotated <: TypeTree + given TypeTest[Tree, Annotated] = AnnotatedTypeTest + protected val AnnotatedTypeTest: TypeTest[Tree, Annotated] - given TypeTest[Tree, Annotated] = - reflectSelf.Annotated_TypeTest + val Annotated: AnnotatedModule - object Annotated: - def apply(arg: TypeTree, annotation: Term): Annotated = - reflectSelf.Annotated_apply(arg, annotation) - def copy(original: Tree)(arg: TypeTree, annotation: Term): Annotated = - reflectSelf.Annotated_copy(original)(arg, annotation) - def unapply(x: Annotated): Option[(TypeTree, Term)] = - Some((x.arg, x.annotation)) - end Annotated + trait AnnotatedModule { this: Annotated.type => + def apply(arg: TypeTree, annotation: Term): Annotated + def copy(original: Tree)(arg: TypeTree, annotation: Term): Annotated + def unapply(x: Annotated): Option[(TypeTree, Term)] + } + + given AnnotatedMethods as AnnotatedMethods = AnnotatedMethodsImpl + protected val AnnotatedMethodsImpl: AnnotatedMethods - given AnnotatedOps as AnyRef: + trait AnnotatedMethods: extension (self: Annotated): - def arg: TypeTree = reflectSelf.Annotated_arg(self) - def annotation: Term = reflectSelf.Annotated_annotation(self) + def arg: TypeTree + def annotation: Term end extension - end AnnotatedOps + end AnnotatedMethods + /** Type tree representing a type match */ + type MatchTypeTree <: TypeTree - given as TypeTest[Tree, MatchTypeTree] = - reflectSelf.MatchTypeTree_TypeTest + given TypeTest[Tree, MatchTypeTree] = MatchTypeTreeTypeTest + protected val MatchTypeTreeTypeTest: TypeTest[Tree, MatchTypeTree] - object MatchTypeTree: - def apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef]): MatchTypeTree = - reflectSelf.MatchTypeTree_apply(bound, selector, cases) - def copy(original: Tree)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef]): MatchTypeTree = - reflectSelf.MatchTypeTree_copy(original)(bound, selector, cases) - def unapply(x: MatchTypeTree): Option[(Option[TypeTree], TypeTree, List[TypeCaseDef])] = - Some((x.bound, x.selector, x.cases)) - end MatchTypeTree + val MatchTypeTree: MatchTypeTreeModule - given MatchTypeTreeOps as AnyRef: + trait MatchTypeTreeModule { this: MatchTypeTree.type => + def apply(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef]): MatchTypeTree + def copy(original: Tree)(bound: Option[TypeTree], selector: TypeTree, cases: List[TypeCaseDef]): MatchTypeTree + def unapply(x: MatchTypeTree): Option[(Option[TypeTree], TypeTree, List[TypeCaseDef])] + } + + given MatchTypeTreeMethods as MatchTypeTreeMethods = MatchTypeTreeMethodsImpl + protected val MatchTypeTreeMethodsImpl: MatchTypeTreeMethods + + trait MatchTypeTreeMethods: extension (self: MatchTypeTree): - def bound: Option[TypeTree] = reflectSelf.MatchTypeTree_bound(self) - def selector: TypeTree = reflectSelf.MatchTypeTree_selector(self) - def cases: List[TypeCaseDef] = reflectSelf.MatchTypeTree_cases(self) + def bound: Option[TypeTree] + def selector: TypeTree + def cases: List[TypeCaseDef] end extension - end MatchTypeTreeOps + end MatchTypeTreeMethods + /** Type tree representing a by name parameter */ + type ByName <: TypeTree - given TypeTest[Tree, ByName] = - reflectSelf.ByName_TypeTest + given TypeTest[Tree, ByName] = ByNameTypeTest + protected val ByNameTypeTest: TypeTest[Tree, ByName] - object ByName: - def apply(result: TypeTree): ByName = - reflectSelf.ByName_apply(result) - def copy(original: Tree)(result: TypeTree): ByName = - reflectSelf.ByName_copy(original)(result) - def unapply(x: ByName): Option[TypeTree] = - Some(x.result) - end ByName + val ByName: ByNameModule + + trait ByNameModule { this: ByName.type => + def apply(result: TypeTree): ByName + def copy(original: Tree)(result: TypeTree): ByName + def unapply(x: ByName): Option[TypeTree] + } - given ByNameOps as AnyRef: + given ByNameMethods as ByNameMethods = ByNameMethodsImpl + protected val ByNameMethodsImpl: ByNameMethods + + trait ByNameMethods: extension (self: ByName): - def result: TypeTree = reflectSelf.ByName_result(self) + def result: TypeTree end extension - end ByNameOps + end ByNameMethods + + /** Type tree representing a lambda abstraction type */ + type LambdaTypeTree <: TypeTree + given TypeTest[Tree, LambdaTypeTree] = LambdaTypeTreeTypeTest + protected val LambdaTypeTreeTypeTest: TypeTest[Tree, LambdaTypeTree] - given TypeTest[Tree, LambdaTypeTree] = reflectSelf.LambdaTypeTree_TypeTest + val LambdaTypeTree: LambdaTypeTreeModule - object LambdaTypeTree: - def apply(tparams: List[TypeDef], body: Tree /*TypeTree | TypeBoundsTree*/): LambdaTypeTree = - reflectSelf.Lambdaapply(tparams, body) - def copy(original: Tree)(tparams: List[TypeDef], body: Tree /*TypeTree | TypeBoundsTree*/): LambdaTypeTree = - reflectSelf.Lambdacopy(original)(tparams, body) - def unapply(tree: LambdaTypeTree): Option[(List[TypeDef], Tree /*TypeTree | TypeBoundsTree*/)] = - Some((tree.tparams, tree.body)) - end LambdaTypeTree + trait LambdaTypeTreeModule { this: LambdaTypeTree.type => + def apply(tparams: List[TypeDef], body: Tree /*TypeTree | TypeBoundsTree*/): LambdaTypeTree + def copy(original: Tree)(tparams: List[TypeDef], body: Tree /*TypeTree | TypeBoundsTree*/): LambdaTypeTree + def unapply(tree: LambdaTypeTree): Option[(List[TypeDef], Tree /*TypeTree | TypeBoundsTree*/)] + } - given LambdaTypeTreeOps as AnyRef: + given LambdaTypeTreeMethods as LambdaTypeTreeMethods = LambdaTypeTreeMethodsImpl + protected val LambdaTypeTreeMethodsImpl: LambdaTypeTreeMethods + + trait LambdaTypeTreeMethods: extension (self: LambdaTypeTree): - def tparams: List[TypeDef] = reflectSelf.Lambdatparams(self) - def body: Tree /*TypeTree | TypeBoundsTree*/ = reflectSelf.Lambdabody(self) + def tparams: List[TypeDef] + def body: Tree /*TypeTree | TypeBoundsTree*/ end extension - end LambdaTypeTreeOps + end LambdaTypeTreeMethods + + /** Type tree representing a type binding */ + type TypeBind <: TypeTree + given TypeTest[Tree, TypeBind] = TypeBindTypeTest + protected val TypeBindTypeTest: TypeTest[Tree, TypeBind] - given TypeTest[Tree, TypeBind] = reflectSelf.TypeBind_TypeTest + val TypeBind: TypeBindModule - object TypeBind: + trait TypeBindModule { this: TypeBind.type => // TODO def apply(name: String, tree: Tree): TypeBind - def copy(original: Tree)(name: String, tpt: Tree /*TypeTree | TypeBoundsTree*/): TypeBind = - reflectSelf.TypeBind_copy(original)(name, tpt) - def unapply(x: TypeBind): Option[(String, Tree /*TypeTree | TypeBoundsTree*/)] = - Some((x.name, x.body)) - end TypeBind + def copy(original: Tree)(name: String, tpt: Tree /*TypeTree | TypeBoundsTree*/): TypeBind + def unapply(x: TypeBind): Option[(String, Tree /*TypeTree | TypeBoundsTree*/)] + } - given TypeBindOps as AnyRef: + given TypeBindMethods as TypeBindMethods = TypeBindMethodsImpl + protected val TypeBindMethodsImpl: TypeBindMethods + + trait TypeBindMethods: extension (self: TypeBind): - def name: String = reflectSelf.TypeBind_name(self) - def body: Tree /*TypeTree | TypeBoundsTree*/ = reflectSelf.TypeBind_body(self) + def name: String + def body: Tree /*TypeTree | TypeBoundsTree*/ end extension - end TypeBindOps + end TypeBindMethods + + /** Type tree within a block with aliases `{ type U1 = ... ; T[U1, U2] }` */ + type TypeBlock <: TypeTree + given TypeTest[Tree, TypeBlock] = TypeBlockTypeTest + protected val TypeBlockTypeTest: TypeTest[Tree, TypeBlock] - given TypeTest[Tree, TypeBlock] = reflectSelf.TypeBlock_TypeTest + val TypeBlock: TypeBlockModule - object TypeBlock: - def apply(aliases: List[TypeDef], tpt: TypeTree): TypeBlock = - reflectSelf.TypeBlock_apply(aliases, tpt) - def copy(original: Tree)(aliases: List[TypeDef], tpt: TypeTree): TypeBlock = - reflectSelf.TypeBlock_copy(original)(aliases, tpt) - def unapply(x: TypeBlock): Option[(List[TypeDef], TypeTree)] = - Some((x.aliases, x.tpt)) - end TypeBlock + trait TypeBlockModule { this: TypeBlock.type => + def apply(aliases: List[TypeDef], tpt: TypeTree): TypeBlock + def copy(original: Tree)(aliases: List[TypeDef], tpt: TypeTree): TypeBlock + def unapply(x: TypeBlock): Option[(List[TypeDef], TypeTree)] + } - given TypeBlockOps as AnyRef: + given TypeBlockMethods as TypeBlockMethods = TypeBlockMethodsImpl + protected val TypeBlockMethodsImpl: TypeBlockMethods + + trait TypeBlockMethods: extension (self: TypeBlock): - def aliases: List[TypeDef] = reflectSelf.TypeBlock_aliases(self) - def tpt: TypeTree = reflectSelf.TypeBlock_tpt(self) + def aliases: List[TypeDef] + def tpt: TypeTree end extension - end TypeBlockOps - + end TypeBlockMethods // ----- TypeBoundsTrees ------------------------------------------------ - given TypeTest[Tree, TypeBoundsTree] = reflectSelf.TypeBoundsTree_TypeTest + /** Type tree representing a type bound written in the source */ + type TypeBoundsTree <: Tree /*TypeTree | TypeBoundsTree*/ + + given TypeTest[Tree, TypeBoundsTree] = TypeBoundsTreeTypeTest + protected val TypeBoundsTreeTypeTest: TypeTest[Tree, TypeBoundsTree] + + val TypeBoundsTree: TypeBoundsTreeModule + + trait TypeBoundsTreeModule { this: TypeBoundsTree.type => + def unapply(x: TypeBoundsTree): Option[(TypeTree, TypeTree)] + } - object TypeBoundsTree: - def unapply(x: TypeBoundsTree): Option[(TypeTree, TypeTree)] = - Some((x.low, x.hi)) - end TypeBoundsTree + given TypeBoundsTreeMethods as TypeBoundsTreeMethods = TypeBoundsTreeMethodsImpl + protected val TypeBoundsTreeMethodsImpl: TypeBoundsTreeMethods - given TypeBoundsTreeOps as AnyRef: + trait TypeBoundsTreeMethods: extension (self: TypeBoundsTree): - def tpe: TypeBounds = reflectSelf.TypeBoundsTree_tpe(self) - def low: TypeTree = reflectSelf.TypeBoundsTree_low(self) - def hi: TypeTree = reflectSelf.TypeBoundsTree_hi(self) + def tpe: TypeBounds + def low: TypeTree + def hi: TypeTree end extension - end TypeBoundsTreeOps + end TypeBoundsTreeMethods + /** Type tree representing wildcard type bounds written in the source. + * The wildcard type `_` (for example in in `List[_]`) will be a type tree that + * represents a type but has `TypeBound`a inside. + */ + type WildcardTypeTree <: Tree + + given TypeTest[Tree, WildcardTypeTree] = WildcardTypeTreeTypeTest + protected val WildcardTypeTreeTypeTest: TypeTest[Tree, WildcardTypeTree] - given TypeTest[Tree, WildcardTypeTree] = reflectSelf.WildcardTypeTree_TypeTest + val WildcardTypeTree: WildcardTypeTreeModule - object WildcardTypeTree: + trait WildcardTypeTreeModule { this: WildcardTypeTree.type => /** Matches a TypeBoundsTree containing wildcard type bounds */ - def unapply(x: WildcardTypeTree): Boolean = true - end WildcardTypeTree + def unapply(x: WildcardTypeTree): Boolean + } - given WildcardTypeTreeOps as AnyRef: + given WildcardTypeTreeMethods as WildcardTypeTreeMethods = WildcardTypeTreeMethodsImpl + protected val WildcardTypeTreeMethodsImpl: WildcardTypeTreeMethods + + trait WildcardTypeTreeMethods: extension (self: WildcardTypeTree): - def tpe: Type = reflectSelf.WildcardTypeTree_tpe(self) + def tpe: Type end extension - end WildcardTypeTreeOps + end WildcardTypeTreeMethods // ----- CaseDefs ------------------------------------------------ - given TypeTest[Tree, CaseDef] = reflectSelf.CaseDef_TypeTest + /** Branch of a pattern match or catch clause */ + type CaseDef <: Tree - object CaseDef: - def apply(pattern: Tree, guard: Option[Term], rhs: Term): CaseDef = - reflectSelf.CaseDef_module_apply(pattern, guard, rhs) + given TypeTest[Tree, CaseDef] = CaseDefTypeTest + protected val CaseDefTypeTest: TypeTest[Tree, CaseDef] - def copy(original: Tree)(pattern: Tree, guard: Option[Term], rhs: Term): CaseDef = - reflectSelf.CaseDef_module_copy(original)(pattern, guard, rhs) + val CaseDef: CaseDefModule - def unapply(x: CaseDef): Option[(Tree, Option[Term], Term)] = - Some((x.pattern, x.guard, x.rhs)) - end CaseDef + trait CaseDefModule { this: CaseDef.type => + def apply(pattern: Tree, guard: Option[Term], rhs: Term): CaseDef + def copy(original: Tree)(pattern: Tree, guard: Option[Term], rhs: Term): CaseDef + def unapply(x: CaseDef): Option[(Tree, Option[Term], Term)] + } - given CaseDefOps as AnyRef: - extension (caseDef: CaseDef): - def pattern: Tree = reflectSelf.CaseDef_pattern(caseDef) - def guard: Option[Term] = reflectSelf.CaseDef_guard(caseDef) - def rhs: Term = reflectSelf.CaseDef_rhs(caseDef) - end extension - end CaseDefOps + given CaseDefMethods as CaseDefMethods = CaseDefMethodsImpl + protected val CaseDefMethodsImpl: CaseDefMethods + trait CaseDefMethods: + extension (self: CaseDef): + def pattern: Tree + def guard: Option[Term] + def rhs: Term + end extension + end CaseDefMethods - given TypeTest[Tree, TypeCaseDef] = - reflectSelf.TypeCaseDef_TypeTest + /** Branch of a type pattern match */ + type TypeCaseDef <: Tree + given TypeTest[Tree, TypeCaseDef] = TypeCaseDefTypeTest + protected val TypeCaseDefTypeTest: TypeTest[Tree, TypeCaseDef] - object TypeCaseDef: - def apply(pattern: TypeTree, rhs: TypeTree): TypeCaseDef = - reflectSelf.TypeCaseDef_module_apply(pattern, rhs) + val TypeCaseDef: TypeCaseDefModule - def copy(original: Tree)(pattern: TypeTree, rhs: TypeTree): TypeCaseDef = - reflectSelf.TypeCaseDef_module_copy(original)(pattern, rhs) + trait TypeCaseDefModule { this: TypeCaseDef.type => + def apply(pattern: TypeTree, rhs: TypeTree): TypeCaseDef + def copy(original: Tree)(pattern: TypeTree, rhs: TypeTree): TypeCaseDef + def unapply(tree: TypeCaseDef): Option[(TypeTree, TypeTree)] + } - def unapply(tree: TypeCaseDef): Option[(TypeTree, TypeTree)] = - Some((tree.pattern, tree.rhs)) - end TypeCaseDef + given TypeCaseDefMethods as TypeCaseDefMethods = TypeCaseDefMethodsImpl + protected val TypeCaseDefMethodsImpl: TypeCaseDefMethods - given TypeCaseDefOps as AnyRef: - extension (caseDef: TypeCaseDef): - def pattern: TypeTree = reflectSelf.TypeCaseDef_pattern(caseDef) - def rhs: TypeTree = reflectSelf.TypeCaseDef_rhs(caseDef) + trait TypeCaseDefMethods: + extension (self: TypeCaseDef): + def pattern: TypeTree + def rhs: TypeTree end extension - end TypeCaseDefOps + end TypeCaseDefMethods // ----- Patterns ------------------------------------------------ - given TypeTest[Tree, Bind] = reflectSelf.Bind_TypeTest + /** Pattern representing a `_ @ _` binding. */ + type Bind <: Tree - object Bind: - def apply(sym: Symbol, pattern: Tree): Bind = - reflectSelf.Tree_Bind_module_apply(sym, pattern) - def copy(original: Tree)(name: String, pattern: Tree): Bind = - reflectSelf.Tree_Bind_module_copy(original)(name, pattern) - def unapply(pattern: Bind): Option[(String, Tree)] = - Some((pattern.name, pattern.pattern)) - end Bind + given TypeTest[Tree, Bind] = BindTypeTest + protected val BindTypeTest: TypeTest[Tree, Bind] - given BindOps as AnyRef: - extension (bind: Bind): - def name: String = reflectSelf.Tree_Bind_name(bind) - def pattern: Tree = reflectSelf.Tree_Bind_pattern(bind) + val Bind: BindModule + + trait BindModule { this: Bind.type => + def apply(sym: Symbol, pattern: Tree): Bind + def copy(original: Tree)(name: String, pattern: Tree): Bind + def unapply(pattern: Bind): Option[(String, Tree)] + } + + given BindMethods as BindMethods = BindMethodsImpl + protected val BindMethodsImpl: BindMethods + + trait BindMethods: + extension (self: Bind): + def name: String + def pattern: Tree end extension - end BindOps + end BindMethods + + /** Pattern representing a `Xyz(...)` unapply. */ + type Unapply <: Tree + given TypeTest[Tree, Unapply] = UnapplyTypeTest + protected val UnapplyTypeTest: TypeTest[Tree, Unapply] - given TypeTest[Tree, Unapply] = reflectSelf.Unapply_TypeTest + val Unapply: UnapplyModule - object Unapply: + trait UnapplyModule { this: Unapply.type => // TODO def apply(fun: Term, implicits: List[Term], patterns: List[Tree]): Unapply - def copy(original: Tree)(fun: Term, implicits: List[Term], patterns: List[Tree]): Unapply = - reflectSelf.Tree_Unapply_module_copy(original)(fun, implicits, patterns) - def unapply(x: Unapply): Option[(Term, List[Term], List[Tree])] = - Some((x.fun, x.implicits, x.patterns)) - end Unapply + def copy(original: Tree)(fun: Term, implicits: List[Term], patterns: List[Tree]): Unapply + def unapply(x: Unapply): Option[(Term, List[Term], List[Tree])] + } + + given UnapplyMethods as UnapplyMethods = UnapplyMethodsImpl + protected val UnapplyMethodsImpl: UnapplyMethods - given UnapplyOps as AnyRef: - extension (unapply: Unapply): - def fun: Term = reflectSelf.Tree_Unapply_fun(unapply) - def implicits: List[Term] = reflectSelf.Tree_Unapply_implicits(unapply) - def patterns: List[Tree] = reflectSelf.Tree_Unapply_patterns(unapply) + trait UnapplyMethods: + extension (self: Unapply): + def fun: Term + def implicits: List[Term] + def patterns: List[Tree] end extension - end UnapplyOps + end UnapplyMethods + /** Pattern representing `X | Y | ...` alternatives. */ + type Alternatives <: Tree - given TypeTest[Tree, Alternatives] = reflectSelf.Alternatives_TypeTest + given TypeTest[Tree, Alternatives] = AlternativesTypeTest + protected val AlternativesTypeTest: TypeTest[Tree, Alternatives] - object Alternatives: - def apply(patterns: List[Tree]): Alternatives = - reflectSelf.Tree_Alternatives_module_apply(patterns) - def copy(original: Tree)(patterns: List[Tree]): Alternatives = - reflectSelf.Tree_Alternatives_module_copy(original)(patterns) - def unapply(x: Alternatives): Option[List[Tree]] = - Some(x.patterns) - end Alternatives + val Alternatives: AlternativesModule - given AlternativesOps as AnyRef: - extension (alternatives: Alternatives): - def patterns: List[Tree] = reflectSelf.Tree_Alternatives_patterns(alternatives) - end extension - end AlternativesOps + trait AlternativesModule { this: Alternatives.type => + def apply(patterns: List[Tree]): Alternatives + def copy(original: Tree)(patterns: List[Tree]): Alternatives + def unapply(x: Alternatives): Option[List[Tree]] + } + given AlternativesMethods as AlternativesMethods = AlternativesMethodsImpl + protected val AlternativesMethodsImpl: AlternativesMethods + trait AlternativesMethods: + extension (self: Alternatives): + def patterns: List[Tree] + end extension + end AlternativesMethods ////////////////////// // IMPORT SELECTORS // ///////////////////// - given TypeTest[ImportSelector, SimpleSelector] = reflectSelf.SimpleSelector_TypeTest + /** Import selectors: + * * SimpleSelector: `.bar` in `import foo.bar` + * * RenameSelector: `.{bar => baz}` in `import foo.{bar => baz}` + * * OmitSelector: `.{bar => _}` in `import foo.{bar => _}` + */ + type ImportSelector <: AnyRef - object SimpleSelector: - def unapply(x: SimpleSelector): Option[Id] = Some(x.selection) - end SimpleSelector + val ImportSelector: ImportSelectorModule - given SimpleSelectorOps as AnyRef: + trait ImportSelectorModule { this: ImportSelector.type => } + + given TypeTest[ImportSelector, SimpleSelector] = SimpleSelectorTypeTest + protected val SimpleSelectorTypeTest: TypeTest[ImportSelector, SimpleSelector] + + val SimpleSelector: SimpleSelectorModule + + trait SimpleSelectorModule { this: SimpleSelector.type => + def unapply(x: SimpleSelector): Option[Id] + } + + /** Simple import selector: `.bar` in `import foo.bar` */ + type SimpleSelector <: ImportSelector + + given SimpleSelectorMethods as SimpleSelectorMethods = SimpleSelectorMethodsImpl + protected val SimpleSelectorMethodsImpl: SimpleSelectorMethods + + trait SimpleSelectorMethods: extension (self: SimpleSelector): - def selection: Id = - reflectSelf.SimpleSelector_selection(self) + def selection: Id end extension - end SimpleSelectorOps + end SimpleSelectorMethods + /** Rename import selector: `.{bar => baz}` in `import foo.{bar => baz}` */ + type RenameSelector <: ImportSelector - given TypeTest[ImportSelector, RenameSelector] = reflectSelf.RenameSelector_TypeTest + given TypeTest[ImportSelector, RenameSelector] = RenameSelectorTypeTest + protected val RenameSelectorTypeTest: TypeTest[ImportSelector, RenameSelector] - object RenameSelector: - def unapply(x: RenameSelector): Option[(Id, Id)] = Some((x.from, x.to)) - end RenameSelector + val RenameSelector: RenameSelectorModule - given RenameSelectorOps as AnyRef: - extension (self: RenameSelector): - def from: Id = - reflectSelf.RenameSelector_from(self) + trait RenameSelectorModule { this: RenameSelector.type => + def unapply(x: RenameSelector): Option[(Id, Id)] + } - def to: Id = - reflectSelf.RenameSelector_to(self) + /** Omit import selector: `.{bar => _}` in `import foo.{bar => _}` */ + type OmitSelector <: ImportSelector + + given RenameSelectorMethods as RenameSelectorMethods = RenameSelectorMethodsImpl + protected val RenameSelectorMethodsImpl: RenameSelectorMethods + + trait RenameSelectorMethods: + extension (self: RenameSelector): + def from: Id + def to: Id end extension - end RenameSelectorOps + end RenameSelectorMethods + given TypeTest[ImportSelector, OmitSelector] = OmitSelectorTypeTest + protected val OmitSelectorTypeTest: TypeTest[ImportSelector, OmitSelector] - given TypeTest[ImportSelector, OmitSelector] = reflectSelf.OmitSelector_TypeTest + val OmitSelector: OmitSelectorModule - object OmitSelector: - def unapply(x: OmitSelector): Option[Id] = Some(x.omitted) - end OmitSelector + trait OmitSelectorModule { this: OmitSelector.type => + def unapply(x: OmitSelector): Option[Id] + } - given OmitSelectorOps as AnyRef: - extension (self: OmitSelector): - def omitted: Id = - reflectSelf.SimpleSelector_omitted(self) - end OmitSelectorOps + given OmitSelectorMethods as OmitSelectorMethods = OmitSelectorMethodsImpl + protected val OmitSelectorMethodsImpl: OmitSelectorMethods + trait OmitSelectorMethods: + extension (self: OmitSelector): + def omitted: Id + end OmitSelectorMethods /////////////// // TYPES // @@ -1345,44 +1731,44 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => // ----- Types ---------------------------------------------------- - given TypeTest[Type, Type] = reflectSelf.Type_TypeTest + /** A type, type constructors, type bounds or NoPrefix */ + type Type - object Type: + val Type: TypeModule + trait TypeModule { this: Type.type => /** Returns the type or kind (Type) of T */ - def of[T <: AnyKind](using qtype: scala.quoted.Type[T]): Type = - qtype.asInstanceOf[scala.internal.quoted.Type[TypeTree]].typeTree.tpe + def of[T <: AnyKind](using qtype: scala.quoted.Type[T]): Type - def typeConstructorOf(clazz: Class[_]): Type = - reflectSelf.Type_ofErasedClass(clazz) - end Type + /** Returns the type constructor of the runtime (erased) class */ + def typeConstructorOf(clazz: Class[?]): Type + } - given TypeOps as AnyRef: + given TypeMethods as TypeMethods = TypeMethodsImpl + protected val TypeMethodsImpl: TypeMethods + + trait TypeMethods { extension (self: Type): /** Shows the tree as extractors */ - def showExtractors: String = - new ExtractorsPrinter[reflectSelf.type](reflectSelf).showType(self) + def showExtractors: String /** Shows the tree as fully typed source code */ - def show: String = - self.showWith(SyntaxHighlight.plain) + def show: String /** Shows the tree as fully typed source code */ - def showWith(syntaxHighlight: SyntaxHighlight): String = - new SourceCodePrinter[reflectSelf.type](reflectSelf)(syntaxHighlight).showType(self) + def showWith(syntaxHighlight: SyntaxHighlight): String /** Convert `Type` to an `quoted.Type[_]` */ - def seal: scala.quoted.Type[_] = - new scala.internal.quoted.Type(Inferred(self), reflectSelf.compilerId) + def seal: scala.quoted.Type[_] /** Is `self` type the same as `that` type? * This is the case iff `self <:< that` and `that <:< self`. */ - def =:=(that: Type): Boolean = reflectSelf.Type_isTypeEq(self)(that) + def =:=(that: Type): Boolean /** Is this type a subtype of that type? */ - def <:<(that: Type): Boolean = reflectSelf.Type_isSubType(self)(that) + def <:<(that: Type): Boolean /** Widen from singleton type to its underlying non-singleton * base type by applying one or more `underlying` dereferences, @@ -1393,32 +1779,32 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * def o: Outer * .widen = o.C */ - def widen: Type = reflectSelf.Type_widen(self) + def widen: Type /** Widen from TermRef to its underlying non-termref * base type, while also skipping `=>T` types. */ - def widenTermRefExpr: Type = reflectSelf.Type_widenTermRefExpr(self) + def widenTermRefExpr: Type /** Follow aliases and dereferences LazyRefs, annotated types and instantiated * TypeVars until type is no longer alias type, annotated type, LazyRef, * or instantiated type variable. */ - def dealias: Type = reflectSelf.Type_dealias(self) + def dealias: Type /** A simplified version of this type which is equivalent wrt =:= to this type. * Reduces typerefs, applied match types, and and or types. */ - def simplified: Type = reflectSelf.Type_simplified(self) + def simplified: Type - def classSymbol: Option[Symbol] = reflectSelf.Type_classSymbol(self) - def typeSymbol: Symbol = reflectSelf.Type_typeSymbol(self) - def termSymbol: Symbol = reflectSelf.Type_termSymbol(self) - def isSingleton: Boolean = reflectSelf.Type_isSingleton(self) - def memberType(member: Symbol): Type = reflectSelf.Type_memberType(self)(member) + def classSymbol: Option[Symbol] + def typeSymbol: Symbol + def termSymbol: Symbol + def isSingleton: Boolean + def memberType(member: Symbol): Type /** The base classes of this type with the class itself as first element. */ - def baseClasses: List[Symbol] = reflectSelf.Type_baseClasses(self) + def baseClasses: List[Symbol] /** The least type instance of given class which is a super-type * of this type. Example: @@ -1428,11 +1814,10 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * ThisType(C).baseType(D) = p.D[Int] * }}} */ - def baseType(cls: Symbol): Type = reflectSelf.Type_baseType(self)(cls) + def baseType(cls: Symbol): Type /** Is this type an instance of a non-bottom subclass of the given class `cls`? */ - def derivesFrom(cls: Symbol): Boolean = - reflectSelf.Type_derivesFrom(self)(cls) + def derivesFrom(cls: Symbol): Boolean /** Is this type a function type? * @@ -1443,263 +1828,364 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * - returns true for `given Int => Int` and `erased Int => Int` * - returns false for `List[Int]`, despite that `List[Int] <:< Int => Int`. */ - def isFunctionType: Boolean = reflectSelf.Type_isFunctionType(self) + def isFunctionType: Boolean /** Is this type an context function type? * * @see `isFunctionType` */ - def isContextFunctionType: Boolean = reflectSelf.Type_isContextFunctionType(self) + def isContextFunctionType: Boolean /** Is this type an erased function type? * * @see `isFunctionType` */ - def isErasedFunctionType: Boolean = reflectSelf.Type_isErasedFunctionType(self) + def isErasedFunctionType: Boolean /** Is this type a dependent function type? * * @see `isFunctionType` */ - def isDependentFunctionType: Boolean = reflectSelf.Type_isDependentFunctionType(self) + def isDependentFunctionType: Boolean /** The type , reduced if possible */ - def select(sym: Symbol): Type = reflectSelf.Type_select(self)(sym) + def select(sym: Symbol): Type /** The current type applied to given type arguments: `this[targ]` */ - def appliedTo(targ: Type): Type = reflectSelf.Type_appliedTo(self)(List(targ)) + def appliedTo(targ: Type): Type /** The current type applied to given type arguments: `this[targ0, ..., targN]` */ - def appliedTo(targs: List[Type]): Type = reflectSelf.Type_appliedTo(self)(targs) + def appliedTo(targs: List[Type]): Type end extension - end TypeOps + } + + /** A singleton type representing a known constant value */ + type ConstantType <: Type - given TypeTest[Type, ConstantType] = reflectSelf.ConstantType_TypeTest + given TypeTest[Type, ConstantType] = ConstantTypeTypeTest + protected val ConstantTypeTypeTest: TypeTest[Type, ConstantType] - object ConstantType: - def apply(x : Constant): ConstantType = reflectSelf.ConstantType_apply(x) - def unapply(x: ConstantType): Option[Constant] = Some(x.constant) - end ConstantType + val ConstantType: ConstantTypeModule - given ConstantTypeOps as AnyRef: + trait ConstantTypeModule { this: ConstantType.type => + def apply(x : Constant): ConstantType + def unapply(x: ConstantType): Option[Constant] + } + + given ConstantTypeMethods as ConstantTypeMethods = ConstantTypeMethodsImpl + protected val ConstantTypeMethodsImpl: ConstantTypeMethods + + trait ConstantTypeMethods: extension (self: ConstantType): - def constant: Constant = reflectSelf.ConstantType_constant(self) + def constant: Constant end extension - end ConstantTypeOps + end ConstantTypeMethods + /** Type of a reference to a term symbol */ + type TermRef <: Type - given TypeTest[Type, TermRef] = reflectSelf.TermRef_TypeTest + given TypeTest[Type, TermRef] = TermRefTypeTest + protected val TermRefTypeTest: TypeTest[Type, TermRef] + + val TermRef: TermRefModule + + trait TermRefModule { this: TermRef.type => + def apply(qual: Type, name: String): TermRef + def unapply(x: TermRef): Option[(Type, String)] + } - object TermRef: - def apply(qual: Type, name: String): TermRef = - reflectSelf.TermRef_apply(qual, name) - def unapply(x: TermRef): Option[(Type, String)] = - Some((x.qualifier, x.name)) - end TermRef + given TermRefMethods as TermRefMethods = TermRefMethodsImpl + protected val TermRefMethodsImpl: TermRefMethods - given TermRefOps as AnyRef: + trait TermRefMethods: extension (self: TermRef): - def qualifier: Type = reflectSelf.TermRef_qualifier(self) - def name: String = reflectSelf.TermRef_name(self) + def qualifier: Type + def name: String end extension - end TermRefOps + end TermRefMethods + /** Type of a reference to a type symbol */ + type TypeRef <: Type - given TypeTest[Type, TypeRef] = reflectSelf.TypeRef_TypeTest + given TypeTest[Type, TypeRef] = TypeRefTypeTest + protected val TypeRefTypeTest: TypeTest[Type, TypeRef] - object TypeRef: - def unapply(x: TypeRef): Option[(Type, String)] = - Some((x.qualifier, x.name)) - end TypeRef + val TypeRef: TypeRefModule - given TypeRefOps as AnyRef: + trait TypeRefModule { this: TypeRef.type => + def unapply(x: TypeRef): Option[(Type, String)] + } + + given TypeRefMethods as TypeRefMethods = TypeRefMethodsImpl + protected val TypeRefMethodsImpl: TypeRefMethods + + trait TypeRefMethods: extension (self: TypeRef): - def qualifier: Type = reflectSelf.TypeRef_qualifier(self) - def name: String = reflectSelf.TypeRef_name(self) - def isOpaqueAlias: Boolean = reflectSelf.TypeRef_isOpaqueAlias(self) - def translucentSuperType: Type = reflectSelf.TypeRef_translucentSuperType(self) + def qualifier: Type + def name: String + def isOpaqueAlias: Boolean + def translucentSuperType: Type end extension - end TypeRefOps + end TypeRefMethods + /** Type of a `super` reference */ + type SuperType <: Type - given TypeTest[Type, SuperType] = reflectSelf.SuperType_TypeTest + given TypeTest[Type, SuperType] = SuperTypeTypeTest + protected val SuperTypeTypeTest: TypeTest[Type, SuperType] - object SuperType: - def apply(thistpe: Type, supertpe: Type): SuperType = - reflectSelf.SuperType_apply(thistpe, supertpe) + val SuperType: SuperTypeModule - def unapply(x: SuperType): Option[(Type, Type)] = - Some((x.thistpe, x.supertpe)) - end SuperType + trait SuperTypeModule { this: SuperType.type => + def apply(thistpe: Type, supertpe: Type): SuperType + def unapply(x: SuperType): Option[(Type, Type)] + } + + given SuperTypeMethods as SuperTypeMethods = SuperTypeMethodsImpl + protected val SuperTypeMethodsImpl: SuperTypeMethods - given SuperTypeOps as AnyRef: + trait SuperTypeMethods { this: SuperTypeMethods => extension (self: SuperType): - def thistpe: Type = reflectSelf.SuperType_thistpe(self) - def supertpe: Type = reflectSelf.SuperType_supertpe(self) + def thistpe: Type + def supertpe: Type end extension - end SuperTypeOps + } + /** A type with a type refinement `T { type U }` */ + type Refinement <: Type - given TypeTest[Type, Refinement] = reflectSelf.Refinement_TypeTest + given TypeTest[Type, Refinement] = RefinementTypeTest + protected val RefinementTypeTest: TypeTest[Type, Refinement] - object Refinement: - def apply(parent: Type, name: String, info: Type): Refinement = - reflectSelf.Refinement_apply(parent, name, info) + val Refinement: RefinementModule - def unapply(x: Refinement): Option[(Type, String, Type)] = - Some((x.parent, x.name, x.info)) - end Refinement + trait RefinementModule { this: Refinement.type => + def apply(parent: Type, name: String, info: Type): Refinement + def unapply(x: Refinement): Option[(Type, String, Type)] + } + + given RefinementMethods as RefinementMethods = RefinementMethodsImpl + protected val RefinementMethodsImpl: RefinementMethods - given RefinementOps as AnyRef: + trait RefinementMethods: extension (self: Refinement): - def parent: Type = reflectSelf.Refinement_parent(self) - def name: String = reflectSelf.Refinement_name(self) - def info: Type = reflectSelf.Refinement_info(self) + def parent: Type + def name: String + def info: Type end extension - end RefinementOps + end RefinementMethods + + /** A higher kinded type applied to some types `T[U]` */ + type AppliedType <: Type + given TypeTest[Type, AppliedType] = AppliedTypeTypeTest + protected val AppliedTypeTypeTest: TypeTest[Type, AppliedType] - given TypeTest[Type, AppliedType] = reflectSelf.AppliedType_TypeTest + val AppliedType: AppliedTypeModule - object AppliedType: - def unapply(x: AppliedType): Option[(Type, List[Type])] = - Some((x.tycon, x.args)) - end AppliedType + trait AppliedTypeModule { this: AppliedType.type => + def unapply(x: AppliedType): Option[(Type, List[Type])] + } + + given AppliedTypeMethods as AppliedTypeMethods = AppliedTypeMethodsImpl + protected val AppliedTypeMethodsImpl: AppliedTypeMethods - given AppliedTypeOps as AnyRef: + trait AppliedTypeMethods: extension (self: AppliedType): - def tycon: Type = reflectSelf.AppliedType_tycon(self) - def args: List[Type] = reflectSelf.AppliedType_args(self) + def tycon: Type + def args: List[Type] end extension - end AppliedTypeOps + end AppliedTypeMethods + + /** A type with an anottation `T @foo` */ + type AnnotatedType <: Type + given TypeTest[Type, AnnotatedType] = AnnotatedTypeTypeTest + protected val AnnotatedTypeTypeTest: TypeTest[Type, AnnotatedType] - given TypeTest[Type, AnnotatedType] = reflectSelf.AnnotatedType_TypeTest + val AnnotatedType: AnnotatedTypeModule - object AnnotatedType: - def apply(underlying: Type, annot: Term): AnnotatedType = - reflectSelf.AnnotatedType_apply(underlying, annot) - def unapply(x: AnnotatedType): Option[(Type, Term)] = - Some((x.underlying, x.annot)) - end AnnotatedType + trait AnnotatedTypeModule { this: AnnotatedType.type => + def apply(underlying: Type, annot: Term): AnnotatedType + def unapply(x: AnnotatedType): Option[(Type, Term)] + } + + given AnnotatedTypeMethods as AnnotatedTypeMethods = AnnotatedTypeMethodsImpl + protected val AnnotatedTypeMethodsImpl: AnnotatedTypeMethods - given AnnotatedTypeOps as AnyRef: + trait AnnotatedTypeMethods: extension (self: AnnotatedType): - def underlying: Type = reflectSelf.AnnotatedType_underlying(self) - def annot: Term = reflectSelf.AnnotatedType_annot(self) + def underlying: Type + def annot: Term end extension - end AnnotatedTypeOps + end AnnotatedTypeMethods + /** Intersection type `T & U` */ + type AndType <: Type - given TypeTest[Type, AndType] = reflectSelf.AndType_TypeTest + given TypeTest[Type, AndType] = AndTypeTypeTest + protected val AndTypeTypeTest: TypeTest[Type, AndType] - object AndType: - def apply(lhs: Type, rhs: Type): AndType = - reflectSelf.AndType_apply(lhs, rhs) - def unapply(x: AndType): Option[(Type, Type)] = - Some((x.left, x.right)) - end AndType + val AndType: AndTypeModule + + trait AndTypeModule { this: AndType.type => + def apply(lhs: Type, rhs: Type): AndType + def unapply(x: AndType): Option[(Type, Type)] + } - given AndTypeOps as AnyRef: + given AndTypeMethods as AndTypeMethods = AndTypeMethodsImpl + protected val AndTypeMethodsImpl: AndTypeMethods + + trait AndTypeMethods: extension (self: AndType): - def left: Type = reflectSelf.AndType_left(self) - def right: Type = reflectSelf.AndType_right(self) + def left: Type + def right: Type end extension - end AndTypeOps + end AndTypeMethods + + /** Union type `T | U` */ + type OrType <: Type + given TypeTest[Type, OrType] = OrTypeTypeTest + protected val OrTypeTypeTest: TypeTest[Type, OrType] - given TypeTest[Type, OrType] = reflectSelf.OrType_TypeTest + val OrType: OrTypeModule - object OrType: - def apply(lhs: Type, rhs: Type): OrType = reflectSelf.OrType_apply(lhs, rhs) - def unapply(x: OrType): Option[(Type, Type)] = - Some((x.left, x.right)) - end OrType + trait OrTypeModule { this: OrType.type => + def apply(lhs: Type, rhs: Type): OrType + def unapply(x: OrType): Option[(Type, Type)] + } - given OrTypeOps as AnyRef: + given OrTypeMethods as OrTypeMethods = OrTypeMethodsImpl + protected val OrTypeMethodsImpl: OrTypeMethods + + trait OrTypeMethods: extension (self: OrType): - def left: Type = reflectSelf.OrType_left(self) - def right: Type = reflectSelf.OrType_right(self) + def left: Type + def right: Type end extension - end OrTypeOps + end OrTypeMethods + + /** Type match `T match { case U => ... }` */ + type MatchType <: Type + + given TypeTest[Type, MatchType] = MatchTypeTypeTest + protected val MatchTypeTypeTest: TypeTest[Type, MatchType] + val MatchType: MatchTypeModule - given TypeTest[Type, MatchType] = reflectSelf.MatchType_TypeTest + trait MatchTypeModule { this: MatchType.type => + def apply(bound: Type, scrutinee: Type, cases: List[Type]): MatchType + def unapply(x: MatchType): Option[(Type, Type, List[Type])] + } - object MatchType: - def apply(bound: Type, scrutinee: Type, cases: List[Type]): MatchType = - reflectSelf.MatchType_apply(bound, scrutinee, cases) - def unapply(x: MatchType): Option[(Type, Type, List[Type])] = - Some((x.bound, x.scrutinee, x.cases)) - end MatchType + given MatchTypeMethods as MatchTypeMethods = MatchTypeMethodsImpl + protected val MatchTypeMethodsImpl: MatchTypeMethods - given MatchTypeOps as AnyRef: + trait MatchTypeMethods: extension (self: MatchType): - def bound: Type = reflectSelf.MatchType_bound(self) - def scrutinee: Type = reflectSelf.MatchType_scrutinee(self) - def cases: List[Type] = reflectSelf.MatchType_cases(self) + def bound: Type + def scrutinee: Type + def cases: List[Type] end extension - end MatchTypeOps + end MatchTypeMethods + + /** Type of a by by name parameter */ + type ByNameType <: Type - given TypeTest[Type, ByNameType] = reflectSelf.ByNameType_TypeTest + given TypeTest[Type, ByNameType] = ByNameTypeTypeTest + protected val ByNameTypeTypeTest: TypeTest[Type, ByNameType] - object ByNameType: - def apply(underlying: Type): Type = reflectSelf.ByNameType_apply(underlying) - def unapply(x: ByNameType): Option[Type] = Some(x.underlying) - end ByNameType + val ByNameType: ByNameTypeModule - given ByNameTypeOps as AnyRef: + trait ByNameTypeModule { this: ByNameType.type => + def apply(underlying: Type): Type + def unapply(x: ByNameType): Option[Type] + } + + given ByNameTypeMethods as ByNameTypeMethods = ByNameTypeMethodsImpl + protected val ByNameTypeMethodsImpl: ByNameTypeMethods + + trait ByNameTypeMethods: extension (self: ByNameType): - def underlying: Type = reflectSelf.ByNameType_underlying(self) + def underlying: Type end extension - end ByNameTypeOps + end ByNameTypeMethods + + /** Type of a parameter reference */ + type ParamRef <: Type + given TypeTest[Type, ParamRef] = ParamRefTypeTest + protected val ParamRefTypeTest: TypeTest[Type, ParamRef] - given TypeTest[Type, ParamRef] = reflectSelf.ParamRef_TypeTest + val ParamRef: ParamRefModule - object ParamRef: - def unapply(x: ParamRef): Option[(LambdaType, Int)] = - Some((x.binder, x.paramNum)) - end ParamRef + trait ParamRefModule { this: ParamRef.type => + def unapply(x: ParamRef): Option[(LambdaType, Int)] + } + + given ParamRefMethods as ParamRefMethods = ParamRefMethodsImpl + protected val ParamRefMethodsImpl: ParamRefMethods - given ParamRefOps as AnyRef: + trait ParamRefMethods: extension (self: ParamRef): - def binder: LambdaType = reflectSelf.ParamRef_binder(self) - def paramNum: Int = reflectSelf.ParamRef_paramNum(self) + def binder: LambdaType + def paramNum: Int end extension - end ParamRefOps + end ParamRefMethods + + /** Type of `this` */ + type ThisType <: Type + given TypeTest[Type, ThisType] = ThisTypeTypeTest + protected val ThisTypeTypeTest: TypeTest[Type, ThisType] - given TypeTest[Type, ThisType] = reflectSelf.ThisType_TypeTest + val ThisType: ThisTypeModule - object ThisType: - def unapply(x: ThisType): Option[Type] = Some(x.tref) - end ThisType + trait ThisTypeModule { this: ThisType.type => + def unapply(x: ThisType): Option[Type] + } + + given ThisTypeMethods as ThisTypeMethods = ThisTypeMethodsImpl + protected val ThisTypeMethodsImpl: ThisTypeMethods - given ThisTypeOps as AnyRef: + trait ThisTypeMethods: extension (self: ThisType): - def tref: Type = reflectSelf.ThisType_tref(self) + def tref: Type end extension - end ThisTypeOps + end ThisTypeMethods + + /** A type that is recursively defined `this` */ + type RecursiveThis <: Type + given TypeTest[Type, RecursiveThis] = RecursiveThisTypeTest + protected val RecursiveThisTypeTest: TypeTest[Type, RecursiveThis] - given TypeTest[Type, RecursiveThis] = reflectSelf.RecursiveThis_TypeTest + val RecursiveThis: RecursiveThisModule - object RecursiveThis: - def unapply(x: RecursiveThis): Option[RecursiveType] = Some(x.binder) - end RecursiveThis + trait RecursiveThisModule { this: RecursiveThis.type => + def unapply(x: RecursiveThis): Option[RecursiveType] + } + + given RecursiveThisMethods as RecursiveThisMethods = RecursiveThisMethodsImpl + protected val RecursiveThisMethodsImpl: RecursiveThisMethods - given RecursiveThisOps as AnyRef: + trait RecursiveThisMethods: extension (self: RecursiveThis): - def binder: RecursiveType = reflectSelf.RecursiveThis_binder(self) + def binder: RecursiveType end extension - end RecursiveThisOps + end RecursiveThisMethods + + /** A type that is recursively defined */ + type RecursiveType <: Type + given TypeTest[Type, RecursiveType] = RecursiveTypeTypeTest + protected val RecursiveTypeTypeTest: TypeTest[Type, RecursiveType] - given TypeTest[Type, RecursiveType] = reflectSelf.RecursiveType_TypeTest + val RecursiveType: RecursiveTypeModule - object RecursiveType: + trait RecursiveTypeModule { this: RecursiveType.type => /** Create a RecType, normalizing its contents. This means: * @@ -1709,226 +2195,304 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * `type T`. This avoids infinite recursions later when we * try to follow these references. */ - def apply(parentExp: RecursiveType => Type): RecursiveType = - reflectSelf.RecursiveType_apply(parentExp) + def apply(parentExp: RecursiveType => Type): RecursiveType - def unapply(x: RecursiveType): Option[Type] = Some(x.underlying) - end RecursiveType + def unapply(x: RecursiveType): Option[Type] + } + + given RecursiveTypeMethods as RecursiveTypeMethods = RecursiveTypeMethodsImpl + protected val RecursiveTypeMethodsImpl: RecursiveTypeMethods - given RecursiveTypeOps as AnyRef: + trait RecursiveTypeMethods: extension (self: RecursiveType): - def underlying: Type = reflectSelf.RecursiveType_underlying(self) - def recThis: RecursiveThis = reflectSelf.RecursiveThis_recThis(self) + def underlying: Type + def recThis: RecursiveThis end extension - end RecursiveTypeOps + end RecursiveTypeMethods + // TODO: remove LambdaType and use union types (MethodType | PolyType | TypeLambda) + /** Common abstraction for lambda types (MethodType, PolyType and TypeLambda). */ + type LambdaType <: Type - given TypeTest[Type, MethodType] = reflectSelf.MethodType_TypeTest + /** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */ + type MethodType <: LambdaType - object MethodType: - def apply(paramNames: List[String])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type): MethodType = - reflectSelf.MethodType_apply(paramNames)(paramInfosExp, resultTypeExp) + given TypeTest[Type, MethodType] = MethodTypeTypeTest + protected val MethodTypeTypeTest: TypeTest[Type, MethodType] - def unapply(x: MethodType): Option[(List[String], List[Type], Type)] = - Some((x.paramNames, x.paramTypes, x.resType)) - end MethodType + val MethodType: MethodTypeModule + + trait MethodTypeModule { this: MethodType.type => + def apply(paramNames: List[String])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type): MethodType + def unapply(x: MethodType): Option[(List[String], List[Type], Type)] + } - given MethodTypeOps as AnyRef: + given MethodTypeMethods as MethodTypeMethods = MethodTypeMethodsImpl + protected val MethodTypeMethodsImpl: MethodTypeMethods + + trait MethodTypeMethods: extension (self: MethodType): - def isImplicit: Boolean = reflectSelf.MethodType_isImplicit(self) - def isErased: Boolean = reflectSelf.MethodType_isErased(self) - def param(idx: Int): Type = reflectSelf.MethodType_param(self, idx) - def paramNames: List[String] = reflectSelf.MethodType_paramNames(self) - def paramTypes: List[Type] = reflectSelf.MethodType_paramTypes(self) - def resType: Type = reflectSelf.MethodType_resType(self) + def isImplicit: Boolean + def isErased: Boolean + def param(idx: Int): Type + def paramNames: List[String] + def paramTypes: List[Type] + def resType: Type end extension - end MethodTypeOps + end MethodTypeMethods + + /** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */ + type PolyType <: LambdaType + given TypeTest[Type, PolyType] = PolyTypeTypeTest + protected val PolyTypeTypeTest: TypeTest[Type, PolyType] - given TypeTest[Type, PolyType] = reflectSelf.PolyType_TypeTest + val PolyType: PolyTypeModule - object PolyType: - def apply(paramNames: List[String])(paramBoundsExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type): PolyType = - reflectSelf.PolyType_apply(paramNames)(paramBoundsExp, resultTypeExp) - def unapply(x: PolyType): Option[(List[String], List[TypeBounds], Type)] = - Some((x.paramNames, x.paramBounds, x.resType)) - end PolyType + trait PolyTypeModule { this: PolyType.type => + def apply(paramNames: List[String])(paramBoundsExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type): PolyType + def unapply(x: PolyType): Option[(List[String], List[TypeBounds], Type)] + } - given PolyTypeOps as AnyRef: + given PolyTypeMethods as PolyTypeMethods = PolyTypeMethodsImpl + protected val PolyTypeMethodsImpl: PolyTypeMethods + + trait PolyTypeMethods: extension (self: PolyType): - def param(idx: Int): Type = reflectSelf.PolyType_param(self, idx) - def paramNames: List[String] = reflectSelf.PolyType_paramNames(self) - def paramBounds: List[TypeBounds] = reflectSelf.PolyType_paramBounds(self) - def resType: Type = reflectSelf.PolyType_resType(self) + def param(idx: Int): Type + def paramNames: List[String] + def paramBounds: List[TypeBounds] + def resType: Type end extension - end PolyTypeOps + end PolyTypeMethods + + /** Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda. */ + type TypeLambda <: LambdaType + + given TypeTest[Type, TypeLambda] = TypeLambdaTypeTest + protected val TypeLambdaTypeTest: TypeTest[Type, TypeLambda] + val TypeLambda: TypeLambdaModule - given TypeTest[Type, TypeLambda] = reflectSelf.TypeLambda_TypeTest + trait TypeLambdaModule { this: TypeLambda.type => + def apply(paramNames: List[String], boundsFn: TypeLambda => List[TypeBounds], bodyFn: TypeLambda => Type): TypeLambda + def unapply(x: TypeLambda): Option[(List[String], List[TypeBounds], Type)] + } - object TypeLambda: - def apply(paramNames: List[String], boundsFn: TypeLambda => List[TypeBounds], bodyFn: TypeLambda => Type): TypeLambda = - reflectSelf.TypeLambda_apply(paramNames, boundsFn, bodyFn) - def unapply(x: TypeLambda): Option[(List[String], List[TypeBounds], Type)] = - Some((x.paramNames, x.paramBounds, x.resType)) - end TypeLambda + given TypeLambdaMethods as TypeLambdaMethods = TypeLambdaMethodsImpl + protected val TypeLambdaMethodsImpl: TypeLambdaMethods - given TypeLambdaOps as AnyRef: + trait TypeLambdaMethods: extension (self: TypeLambda): - def paramNames: List[String] = reflectSelf.TypeLambda_paramNames(self) - def paramBounds: List[TypeBounds] = reflectSelf.TypeLambda_paramBounds(self) - def param(idx: Int) : Type = reflectSelf.TypeLambda_param(self, idx) - def resType: Type = reflectSelf.TypeLambda_resType(self) + def paramNames: List[String] + def paramBounds: List[TypeBounds] + def param(idx: Int) : Type + def resType: Type end extension - end TypeLambdaOps - + end TypeLambdaMethods // ----- TypeBounds ----------------------------------------------- - given TypeTest[Type, TypeBounds] = reflectSelf.TypeBounds_TypeTest + /** Type bounds */ + type TypeBounds <: Type + + given TypeTest[Type, TypeBounds] = TypeBoundsTypeTest + protected val TypeBoundsTypeTest: TypeTest[Type, TypeBounds] - object TypeBounds: - def apply(low: Type, hi: Type): TypeBounds = - reflectSelf.TypeBounds_apply(low, hi) - def unapply(x: TypeBounds): Option[(Type, Type)] = Some((x.low, x.hi)) - end TypeBounds + val TypeBounds: TypeBoundsModule - given TypeBoundsOps as AnyRef: + trait TypeBoundsModule { this: TypeBounds.type => + def apply(low: Type, hi: Type): TypeBounds + def unapply(x: TypeBounds): Option[(Type, Type)] + } + + given TypeBoundsMethods as TypeBoundsMethods = TypeBoundsMethodsImpl + protected val TypeBoundsMethodsImpl: TypeBoundsMethods + + trait TypeBoundsMethods: extension (self: TypeBounds): - def low: Type = reflectSelf.TypeBounds_low(self) - def hi: Type = reflectSelf.TypeBounds_hi(self) + def low: Type + def hi: Type end extension - end TypeBoundsOps - + end TypeBoundsMethods // ----- NoPrefix ------------------------------------------------- - given TypeTest[Type, NoPrefix] = reflectSelf.NoPrefix_TypeTest + /** NoPrefix for a type selection */ + type NoPrefix <: Type + + given TypeTest[Type, NoPrefix] = NoPrefixTypeTest + protected val NoPrefixTypeTest: TypeTest[Type, NoPrefix] - object NoPrefix: - def unapply(x: NoPrefix): Boolean = true + val NoPrefix: NoPrefixModule + trait NoPrefixModule { this: NoPrefix.type => + def unapply(x: NoPrefix): Boolean + } /////////////// // CONSTANTS // /////////////// + /** Constant value represented as the constant itself */ + type Constant <: AnyRef /** Module of Constant literals */ - object Constant: + val Constant: ConstantModule - def apply(x: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type): Constant = - reflectSelf.Constant_apply(x) + trait ConstantModule { this: Constant.type => - def unapply(constant: Constant): Option[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type] = - reflectSelf.matchConstant(constant) + def apply(x: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type): Constant + + def unapply(constant: Constant): Option[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type] /** Module of ClassTag literals */ - object ClassTag: - /** scala.reflect.ClassTag literal */ - def apply[T](using x: Type): Constant = - reflectSelf.Constant_ClassTag_apply(x) + val ClassTag: ClassTagModule + /** Module of ClassTag literals */ + trait ClassTagModule { this: ClassTag.type => + /** scala.reflect.ClassTag literal */ + def apply[T](using x: Type): Constant /** Extractor for ClassTag literals */ - def unapply(constant: Constant): Option[Type] = - reflectSelf.matchConstant_ClassTag(constant) - end ClassTag - end Constant + def unapply(constant: Constant): Option[Type] + } + } - given ConstantOps as AnyRef: - extension (const: Constant): + given ConstantMethods as ConstantMethods = ConstantMethodsImpl + protected val ConstantMethodsImpl: ConstantMethods + + trait ConstantMethods { + extension (self: Constant): /** Returns the value of the constant */ - def value: Any = reflectSelf.Constant_value(const) + def value: Any /** Shows the tree as extractors */ - def showExtractors: String = - new ExtractorsPrinter[reflectSelf.type](reflectSelf).showConstant(const) + def showExtractors: String /** Shows the tree as fully typed source code */ - def show: String = - const.showWith(SyntaxHighlight.plain) + def show: String /** Shows the tree as fully typed source code */ - def showWith(syntaxHighlight: SyntaxHighlight): String = - new SourceCodePrinter[reflectSelf.type](reflectSelf)(syntaxHighlight).showConstant(const) + def showWith(syntaxHighlight: SyntaxHighlight): String end extension - end ConstantOps - + } ///////// // IDs // ///////// + // TODO: remove Id. Add use name and pos directly on APIs that use it. + + /** Untyped identifier */ + type Id <: AnyRef + + val Id: IdModule + + trait IdModule { this: Id.type => + def unapply(id: Id): Option[String] + } - object Id: - def unapply(id: Id): Option[String] = Some(id.name) - end Id + given IdMethods as IdMethods = IdMethodsImpl + protected val IdMethodsImpl: IdMethods - given IdOps as AnyRef: - extension (id: Id): + trait IdMethods { + extension (self: Id): /** Position in the source code */ - def pos: Position = reflectSelf.Id_pos(id) + def pos: Position /** Name of the identifier */ - def name: String = reflectSelf.Id_name(id) + def name: String end extension - end IdOps - + } ///////////////////// // IMPLICIT SEARCH // ///////////////////// + // TODO: this should not be top level + /** Find an implicit of type `T` in the current scope given by `ctx`. + * Return an `ImplicitSearchResult`. + * + * @param tpe type of the implicit parameter + * @param ctx current context + */ def searchImplicit(tpe: Type): ImplicitSearchResult - given TypeTest[ImplicitSearchResult, ImplicitSearchSuccess] = reflectSelf.ImplicitSearchSuccess_TypeTest + type ImplicitSearchResult <: AnyRef + + given TypeTest[ImplicitSearchResult, ImplicitSearchSuccess] = ImplicitSearchSuccessTypeTest + protected val ImplicitSearchSuccessTypeTest: TypeTest[ImplicitSearchResult, ImplicitSearchSuccess] + + type ImplicitSearchSuccess <: ImplicitSearchResult - given ImplicitSearchSuccessOps as AnyRef: + given ImplicitSearchSuccessMethods as ImplicitSearchSuccessMethods = ImplicitSearchSuccessMethodsImpl + protected val ImplicitSearchSuccessMethodsImpl: ImplicitSearchSuccessMethods + + trait ImplicitSearchSuccessMethods: extension (self: ImplicitSearchSuccess): - def tree: Term = reflectSelf.ImplicitSearchSuccess_tree(self) + def tree: Term end extension - end ImplicitSearchSuccessOps + end ImplicitSearchSuccessMethods + + type ImplicitSearchFailure <: ImplicitSearchResult + + given TypeTest[ImplicitSearchResult, ImplicitSearchFailure] = ImplicitSearchFailureTypeTest + protected val ImplicitSearchFailureTypeTest: TypeTest[ImplicitSearchResult, ImplicitSearchFailure] - given TypeTest[ImplicitSearchResult, ImplicitSearchFailure] = reflectSelf.ImplicitSearchFailure_TypeTest + given ImplicitSearchFailureMethods as ImplicitSearchFailureMethods = ImplicitSearchFailureMethodsImpl + protected val ImplicitSearchFailureMethodsImpl: ImplicitSearchFailureMethods - given ImplicitSearchFailureOps as AnyRef: + trait ImplicitSearchFailureMethods: extension (self: ImplicitSearchFailure): - def explanation: String = reflectSelf.ImplicitSearchFailure_explanation(self) + def explanation: String end extension - end ImplicitSearchFailureOps + end ImplicitSearchFailureMethods - given TypeTest[ImplicitSearchResult, DivergingImplicit] = reflectSelf.DivergingImplicit_TypeTest + type DivergingImplicit <: ImplicitSearchFailure - given TypeTest[ImplicitSearchResult, NoMatchingImplicits] = reflectSelf.NoMatchingImplicits_TypeTest + given TypeTest[ImplicitSearchResult, DivergingImplicit] = DivergingImplicitTypeTest + protected val DivergingImplicitTypeTest: TypeTest[ImplicitSearchResult, DivergingImplicit] - given TypeTest[ImplicitSearchResult, AmbiguousImplicits] = reflectSelf.AmbiguousImplicits_TypeTest + type NoMatchingImplicits <: ImplicitSearchFailure + given TypeTest[ImplicitSearchResult, NoMatchingImplicits] = NoMatchingImplicitsTypeTest + protected val NoMatchingImplicitsTypeTest: TypeTest[ImplicitSearchResult, NoMatchingImplicits] + + type AmbiguousImplicits <: ImplicitSearchFailure + + given TypeTest[ImplicitSearchResult, AmbiguousImplicits] = AmbiguousImplicitsTypeTest + protected val AmbiguousImplicitsTypeTest: TypeTest[ImplicitSearchResult, AmbiguousImplicits] ///////////// // SYMBOLS // ///////////// + /** Symbol of a definition. + * Then can be compared with == to know if the definition is the same. + */ + type Symbol <: AnyRef + + val Symbol: SymbolModule - object Symbol: + trait SymbolModule { this: Symbol.type => /** Returns the symbol of the current enclosing definition */ - def currentOwner(using ctx: Context): Symbol = reflectSelf.Symbol_currentOwner + def currentOwner(using ctx: Context): Symbol /** Get package symbol if package is either defined in current compilation run or present on classpath. */ - def requiredPackage(path: String): Symbol = reflectSelf.Symbol_requiredPackage(path) + def requiredPackage(path: String): Symbol /** Get class symbol if class is either defined in current compilation run or present on classpath. */ - def requiredClass(path: String): Symbol = reflectSelf.Symbol_requiredClass(path) + def requiredClass(path: String): Symbol /** Get module symbol if module is either defined in current compilation run or present on classpath. */ - def requiredModule(path: String): Symbol = reflectSelf.Symbol_requiredModule(path) + def requiredModule(path: String): Symbol /** Get method symbol if method is either defined in current compilation run or present on classpath. Throws if the method has an overload. */ - def requiredMethod(path: String): Symbol = reflectSelf.Symbol_requiredMethod(path) + def requiredMethod(path: String): Symbol /** The class Symbol of a global class definition */ - def classSymbol(fullName: String): Symbol = - reflectSelf.Symbol_of(fullName) + def classSymbol(fullName: String): Symbol /** Generates a new method symbol with the given parent, name and type. * @@ -1939,16 +2503,14 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * @note As a macro can only splice code into the point at which it is expanded, all generated symbols must be * direct or indirect children of the reflection context's owner. */ - def newMethod(parent: Symbol, name: String, tpe: Type): Symbol = - newMethod(parent, name, tpe, Flags.EmptyFlags, noSymbol) + def newMethod(parent: Symbol, name: String, tpe: Type): Symbol /** Works as the other newMethod, but with additional parameters. * * @param flags extra flags to with which the symbol should be constructed * @param privateWithin the symbol within which this new method symbol should be private. May be noSymbol. */ - def newMethod(parent: Symbol, name: String, tpe: Type, flags: Flags, privateWithin: Symbol): Symbol = - reflectSelf.Symbol_newMethod(parent, name, flags, tpe, privateWithin) + def newMethod(parent: Symbol, name: String, tpe: Type, flags: Flags, privateWithin: Symbol): Symbol /** Generates a new val/var/lazy val symbol with the given parent, name and type. * @@ -1963,8 +2525,7 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * @note As a macro can only splice code into the point at which it is expanded, all generated symbols must be * direct or indirect children of the reflection context's owner. */ - def newVal(parent: Symbol, name: String, tpe: Type, flags: Flags, privateWithin: Symbol): Symbol = - reflectSelf.Symbol_newVal(parent, name, flags, tpe, privateWithin) + def newVal(parent: Symbol, name: String, tpe: Type, flags: Flags, privateWithin: Symbol): Symbol /** Generates a pattern bind symbol with the given parent, name and type. * @@ -1976,45 +2537,46 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * @note As a macro can only splice code into the point at which it is expanded, all generated symbols must be * direct or indirect children of the reflection context's owner. */ - def newBind(parent: Symbol, name: String, flags: Flags, tpe: Type): Symbol = - reflectSelf.Symbol_newBind(parent, name, flags, tpe) + def newBind(parent: Symbol, name: String, flags: Flags, tpe: Type): Symbol /** Definition not available */ - def noSymbol: Symbol = - reflectSelf.Symbol_noSymbol - end Symbol + def noSymbol: Symbol + } + + given SymbolMethods as SymbolMethods = SymbolMethodsImpl + protected val SymbolMethodsImpl: SymbolMethods - given SymbolOps as AnyRef: - extension (sym: Symbol): + trait SymbolMethods { + extension (self: Symbol): /** Owner of this symbol. The owner is the symbol in which this symbol is defined. Throws if this symbol does not have an owner. */ - def owner: Symbol = reflectSelf.Symbol_owner(sym) + def owner: Symbol /** Owner of this symbol. The owner is the symbol in which this symbol is defined. Returns `NoSymbol` if this symbol does not have an owner. */ - def maybeOwner: Symbol = reflectSelf.Symbol_maybeOwner(sym) + def maybeOwner: Symbol /** Flags of this symbol */ - def flags: Flags = reflectSelf.Symbol_flags(sym) + def flags: Flags /** This symbol is private within the resulting type */ - def privateWithin: Option[Type] = reflectSelf.Symbol_privateWithin(sym) + def privateWithin: Option[Type] /** This symbol is protected within the resulting type */ - def protectedWithin: Option[Type] = reflectSelf.Symbol_protectedWithin(sym) + def protectedWithin: Option[Type] /** The name of this symbol */ - def name: String = reflectSelf.Symbol_name(sym) + def name: String /** The full name of this symbol up to the root package */ - def fullName: String = reflectSelf.Symbol_fullName(sym) + def fullName: String /** The position of this symbol */ - def pos: Position = reflectSelf.Symbol_pos(sym) + def pos: Position - def localContext: Context = reflectSelf.Symbol_localContext(sym) + def localContext: Context /** The comment for this symbol, if any */ - def comment: Option[Comment] = reflectSelf.Symbol_comment(sym) + def comment: Option[Comment] /** Tree of this definition * @@ -2025,152 +2587,134 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * if this symbol `isDefDef` it will return a `DefDef` * if this symbol `isBind` it will return a `Bind` */ - def tree: Tree = - reflectSelf.Symbol_tree(sym) + def tree: Tree /** Annotations attached to this symbol */ - def annots: List[Term] = reflectSelf.Symbol_annots(sym) + def annots: List[Term] - def isDefinedInCurrentRun: Boolean = reflectSelf.Symbol_isDefinedInCurrentRun(sym) + def isDefinedInCurrentRun: Boolean - def isLocalDummy: Boolean = reflectSelf.Symbol_isLocalDummy(sym) - def isRefinementClass: Boolean = reflectSelf.Symbol_isRefinementClass(sym) - def isAliasType: Boolean = reflectSelf.Symbol_isAliasType(sym) - def isAnonymousClass: Boolean = reflectSelf.Symbol_isAnonymousClass(sym) - def isAnonymousFunction: Boolean = reflectSelf.Symbol_isAnonymousFunction(sym) - def isAbstractType: Boolean = reflectSelf.Symbol_isAbstractType(sym) - def isClassConstructor: Boolean = reflectSelf.Symbol_isClassConstructor(sym) + def isLocalDummy: Boolean + def isRefinementClass: Boolean + def isAliasType: Boolean + def isAnonymousClass: Boolean + def isAnonymousFunction: Boolean + def isAbstractType: Boolean + def isClassConstructor: Boolean /** Is this the definition of a type? */ - def isType: Boolean = reflectSelf.Symbol_isType(sym) + def isType: Boolean /** Is this the definition of a term? */ - def isTerm: Boolean = reflectSelf.Symbol_isTerm(sym) + def isTerm: Boolean /** Is this the definition of a PackageDef tree? */ - def isPackageDef: Boolean = reflectSelf.Symbol_isPackageDef(sym) + def isPackageDef: Boolean /** Is this the definition of a ClassDef tree? */ - def isClassDef: Boolean = reflectSelf.Symbol_isClassDef(sym) + def isClassDef: Boolean /** Is this the definition of a TypeDef tree */ - def isTypeDef: Boolean = reflectSelf.Symbol_isTypeDef(sym) + def isTypeDef: Boolean /** Is this the definition of a ValDef tree? */ - def isValDef: Boolean = reflectSelf.Symbol_isValDef(sym) + def isValDef: Boolean /** Is this the definition of a DefDef tree? */ - def isDefDef: Boolean = reflectSelf.Symbol_isDefDef(sym) + def isDefDef: Boolean /** Is this the definition of a Bind pattern? */ - def isBind: Boolean = reflectSelf.Symbol_isBind(sym) + def isBind: Boolean /** Does this symbol represent a no definition? */ - def isNoSymbol: Boolean = sym == Symbol.noSymbol + def isNoSymbol: Boolean /** Does this symbol represent a definition? */ - def exists: Boolean = sym != Symbol.noSymbol + def exists: Boolean /** Fields directly declared in the class */ - def fields: List[Symbol] = - reflectSelf.Symbol_fields(sym) + def fields: List[Symbol] /** Field with the given name directly declared in the class */ - def field(name: String): Symbol = - reflectSelf.Symbol_field(sym)(name) + def field(name: String): Symbol /** Get non-private named methods defined directly inside the class */ - def classMethod(name: String): List[Symbol] = - reflectSelf.Symbol_classMethod(sym)(name) + def classMethod(name: String): List[Symbol] /** Get all non-private methods defined directly inside the class, exluding constructors */ - def classMethods: List[Symbol] = - reflectSelf.Symbol_classMethods(sym) + def classMethods: List[Symbol] /** Type member directly declared in the class */ - def typeMembers: List[Symbol] = - reflectSelf.Symbol_typeMembers(sym) + def typeMembers: List[Symbol] /** Type member with the given name directly declared in the class */ - def typeMember(name: String): Symbol = - reflectSelf.Symbol_typeMember(sym)(name) + def typeMember(name: String): Symbol /** Get named non-private methods declared or inherited */ - def method(name: String): List[Symbol] = - reflectSelf.Symbol_method(sym)(name) + def method(name: String): List[Symbol] /** Get all non-private methods declared or inherited */ - def methods: List[Symbol] = - reflectSelf.Symbol_methods(sym) + def methods: List[Symbol] /** The symbols of each type parameter list and value parameter list of this * method, or Nil if this isn't a method. */ - def paramSymss: List[List[Symbol]] = - reflectSelf.Symbol_paramSymss(sym) + def paramSymss: List[List[Symbol]] /** The primary constructor of a class or trait, `noSymbol` if not applicable. */ - def primaryConstructor: Symbol = - reflectSelf.Symbol_primaryConstructor(sym) + def primaryConstructor: Symbol /** Fields of a case class type -- only the ones declared in primary constructor */ - def caseFields: List[Symbol] = - reflectSelf.Symbol_caseFields(sym) + def caseFields: List[Symbol] - def isTypeParam: Boolean = - reflectSelf.Symbol_isTypeParam(sym) + def isTypeParam: Boolean /** Signature of this definition */ - def signature: Signature = - reflectSelf.Symbol_signature(sym) + def signature: Signature /** The class symbol of the companion module class */ - def moduleClass: Symbol = - reflectSelf.Symbol_moduleClass(sym) + def moduleClass: Symbol /** The symbol of the companion class */ - def companionClass: Symbol = - reflectSelf.Symbol_companionClass(sym) + def companionClass: Symbol /** The symbol of the companion module */ - def companionModule: Symbol = - reflectSelf.Symbol_companionModule(sym) + def companionModule: Symbol /** Shows the tree as extractors */ - def showExtractors: String = - new ExtractorsPrinter[reflectSelf.type](reflectSelf).showSymbol(sym) + def showExtractors: String /** Shows the tree as fully typed source code */ - def show: String = - sym.showWith(SyntaxHighlight.plain) + def show: String /** Shows the tree as fully typed source code */ - def showWith(syntaxHighlight: SyntaxHighlight): String = - new SourceCodePrinter[reflectSelf.type](reflectSelf)(syntaxHighlight).showSymbol(sym) + def showWith(syntaxHighlight: SyntaxHighlight): String /** Case class or case object children of a sealed trait */ - def children: List[Symbol] = - reflectSelf.Symbol_children(sym) + def children: List[Symbol] end extension - end SymbolOps - - - + } //////////////// // SIGNATURES // //////////////// + /** The signature of a method */ + type Signature <: AnyRef /** The signature of a method */ - object Signature: + val Signature: SignatureModule + + trait SignatureModule { this: Signature.type => /** Matches the method signature and returns its parameters and result type. */ - def unapply(sig: Signature): Option[(List[String | Int], String)] = - Some((sig.paramSigs, sig.resultSig)) - end Signature + def unapply(sig: Signature): Option[(List[String | Int], String)] + } - given SignatureOps as AnyRef: - extension (sig: Signature): + given SignatureMethods as SignatureMethods = SignatureMethodsImpl + protected val SignatureMethodsImpl: SignatureMethods + + trait SignatureMethods { + extension (self: Signature): /** The signatures of the method parameters. * @@ -2179,141 +2723,136 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * Each *term parameter* is represented by a String corresponding to the fully qualified * name of the parameter type. */ - def paramSigs: List[String | Int] = reflectSelf.Signature_paramSigs(sig) + def paramSigs: List[String | Int] /** The signature of the result type */ - def resultSig: String = reflectSelf.Signature_resultSig(sig) + def resultSig: String end extension - end SignatureOps - + } ////////////////////////// // STANDARD DEFINITIONS // ////////////////////////// - /** A value containing all standard definitions in [[DefinitionsAPI]] - * @group Definitions - */ - object defn extends StandardSymbols + /** A value containing all standard definitions */ + val defn: DefnModule - /** Defines standard symbols (and types via its base trait). - * @group API - */ - trait StandardSymbols { + /** Defines standard symbols (and types via its base trait). */ + trait DefnModule { self: defn.type => /** The module symbol of root package `_root_`. */ - def RootPackage: Symbol = reflectSelf.Definitions_RootPackage + def RootPackage: Symbol /** The class symbol of root package `_root_`. */ - def RootClass: Symbol = reflectSelf.Definitions_RootClass + def RootClass: Symbol /** The class symbol of empty package `_root_._empty_`. */ - def EmptyPackageClass: Symbol = reflectSelf.Definitions_EmptyPackageClass + def EmptyPackageClass: Symbol /** The module symbol of package `scala`. */ - def ScalaPackage: Symbol = reflectSelf.Definitions_ScalaPackage + def ScalaPackage: Symbol /** The class symbol of package `scala`. */ - def ScalaPackageClass: Symbol = reflectSelf.Definitions_ScalaPackageClass + def ScalaPackageClass: Symbol /** The class symbol of core class `scala.Any`. */ - def AnyClass: Symbol = reflectSelf.Definitions_AnyClass + def AnyClass: Symbol /** The class symbol of core class `scala.AnyVal`. */ - def AnyValClass: Symbol = reflectSelf.Definitions_AnyValClass + def AnyValClass: Symbol /** The class symbol of core class `java.lang.Object`. */ - def ObjectClass: Symbol = reflectSelf.Definitions_ObjectClass + def ObjectClass: Symbol /** The type symbol of core class `scala.AnyRef`. */ - def AnyRefClass: Symbol = reflectSelf.Definitions_AnyRefClass + def AnyRefClass: Symbol /** The class symbol of core class `scala.Null`. */ - def NullClass: Symbol = reflectSelf.Definitions_NullClass + def NullClass: Symbol /** The class symbol of core class `scala.Nothing`. */ - def NothingClass: Symbol = reflectSelf.Definitions_NothingClass + def NothingClass: Symbol /** The class symbol of primitive class `scala.Unit`. */ - def UnitClass: Symbol = reflectSelf.Definitions_UnitClass + def UnitClass: Symbol /** The class symbol of primitive class `scala.Byte`. */ - def ByteClass: Symbol = reflectSelf.Definitions_ByteClass + def ByteClass: Symbol /** The class symbol of primitive class `scala.Short`. */ - def ShortClass: Symbol = reflectSelf.Definitions_ShortClass + def ShortClass: Symbol /** The class symbol of primitive class `scala.Char`. */ - def CharClass: Symbol = reflectSelf.Definitions_CharClass + def CharClass: Symbol /** The class symbol of primitive class `scala.Int`. */ - def IntClass: Symbol = reflectSelf.Definitions_IntClass + def IntClass: Symbol /** The class symbol of primitive class `scala.Long`. */ - def LongClass: Symbol = reflectSelf.Definitions_LongClass + def LongClass: Symbol /** The class symbol of primitive class `scala.Float`. */ - def FloatClass: Symbol = reflectSelf.Definitions_FloatClass + def FloatClass: Symbol /** The class symbol of primitive class `scala.Double`. */ - def DoubleClass: Symbol = reflectSelf.Definitions_DoubleClass + def DoubleClass: Symbol /** The class symbol of primitive class `scala.Boolean`. */ - def BooleanClass: Symbol = reflectSelf.Definitions_BooleanClass + def BooleanClass: Symbol /** The class symbol of class `scala.String`. */ - def StringClass: Symbol = reflectSelf.Definitions_StringClass + def StringClass: Symbol /** The class symbol of class `java.lang.Class`. */ - def ClassClass: Symbol = reflectSelf.Definitions_ClassClass + def ClassClass: Symbol /** The class symbol of class `scala.Array`. */ - def ArrayClass: Symbol = reflectSelf.Definitions_ArrayClass + def ArrayClass: Symbol /** The module symbol of module `scala.Predef`. */ - def PredefModule: Symbol = reflectSelf.Definitions_PredefModule + def PredefModule: Symbol /** The method symbol of method `scala.Predef.classOf`. */ - def Predef_classOf: Symbol = reflectSelf.Definitions_Predef_classOf + def Predef_classOf: Symbol /** The module symbol of package `java.lang`. */ - def JavaLangPackage: Symbol = reflectSelf.Definitions_JavaLangPackage + def JavaLangPackage: Symbol /** The module symbol of module `scala.Array`. */ - def ArrayModule: Symbol = reflectSelf.Definitions_ArrayModule + def ArrayModule: Symbol /** The method symbol of method `apply` in class `scala.Array`. */ - def Array_apply: Symbol = reflectSelf.Definitions_Array_apply + def Array_apply: Symbol /** The method symbol of method `clone` in class `scala.Array`. */ - def Array_clone: Symbol = reflectSelf.Definitions_Array_clone + def Array_clone: Symbol /** The method symbol of method `length` in class `scala.Array`. */ - def Array_length: Symbol = reflectSelf.Definitions_Array_length + def Array_length: Symbol /** The method symbol of method `update` in class `scala.Array`. */ - def Array_update: Symbol = reflectSelf.Definitions_Array_update + def Array_update: Symbol /** A dummy class symbol that is used to indicate repeated parameters * compiled by the Scala compiler. */ - def RepeatedParamClass: Symbol = reflectSelf.Definitions_RepeatedParamClass + def RepeatedParamClass: Symbol - /** The class symbol of class `scala.annotation.reflectSelf.Repeated` */ - def RepeatedAnnot: Symbol = reflectSelf.Definitions_RepeatedAnnot + /** The class symbol of class `scala.annotation.reflection.Repeated` */ + def RepeatedAnnot: Symbol /** The class symbol of class `scala.Option`. */ - def OptionClass: Symbol = reflectSelf.Definitions_OptionClass + def OptionClass: Symbol /** The module symbol of module `scala.None`. */ - def NoneModule: Symbol = reflectSelf.Definitions_NoneModule + def NoneModule: Symbol /** The module symbol of module `scala.Some`. */ - def SomeModule: Symbol = reflectSelf.Definitions_SomeModule + def SomeModule: Symbol /** Function-like object that maps arity to symbols for classes `scala.Product` */ - def ProductClass: Symbol = reflectSelf.Definitions_ProductClass + def ProductClass: Symbol /** Function-like object that maps arity to symbols for classes `scala.FunctionX`. * - 0th element is `Function0` @@ -2321,8 +2860,7 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * - ... * - Nth element is `FunctionN` */ - def FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol = - reflectSelf.Definitions_FunctionClass(arity, isImplicit, isErased) + def FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol /** Function-like object that maps arity to symbols for classes `scala.TupleX`. * - 0th element is `NoSymbol` @@ -2333,12 +2871,10 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * - 23nd element is `NoSymbol` // TODO update when we will have more tuples * - ... */ - def TupleClass(arity: Int): Symbol = - reflectSelf.Definitions_TupleClass(arity) + def TupleClass(arity: Int): Symbol /** Returns `true` if `sym` is a `Tuple1`, `Tuple2`, ... `Tuple22` */ - def isTupleClass(sym: Symbol): Boolean = - reflectSelf.Definitions_isTupleClass(sym) + def isTupleClass(sym: Symbol): Boolean /** Contains Scala primitive value classes: * - Byte @@ -2351,8 +2887,7 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * - Boolean * - Unit */ - def ScalaPrimitiveValueClasses: List[Symbol] = - UnitClass :: BooleanClass :: ScalaNumericValueClasses + def ScalaPrimitiveValueClasses: List[Symbol] /** Contains Scala numeric value classes: * - Byte @@ -2363,154 +2898,155 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => * - Double * - Char */ - def ScalaNumericValueClasses: List[Symbol] = - ByteClass :: ShortClass :: IntClass :: LongClass :: FloatClass :: DoubleClass :: CharClass :: Nil + def ScalaNumericValueClasses: List[Symbol] } - /////////////// // FLAGS // /////////////// + /** FlagSet of a Symbol */ + type Flags - object Flags: + val Flags: FlagsModule + + trait FlagsModule { this: Flags.type => /** Is this symbol `abstract` */ - def Abstract: Flags = reflectSelf.Flags_Abstract + def Abstract: Flags /** Was this symbol generated by Scala compiler */ - def Artifact: Flags = reflectSelf.Flags_Artifact + def Artifact: Flags /** Is this symbol `case` */ - def Case: Flags = reflectSelf.Flags_Case + def Case: Flags /** Is this symbol a getter for case class parameter */ - def CaseAcessor: Flags = reflectSelf.Flags_CaseAcessor + def CaseAccessor: Flags /** Is this symbol a type parameter marked as contravariant `-` */ - def Contravariant: Flags = reflectSelf.Flags_Contravariant + def Contravariant: Flags /** Is this symbol a type parameter marked as covariant `+` */ - def Covariant: Flags = reflectSelf.Flags_Covariant + def Covariant: Flags /** The empty set of flags */ - def EmptyFlags = reflectSelf.Flags_EmptyFlags + def EmptyFlags: Flags /** Is this symbol an enum */ - def Enum: Flags = reflectSelf.Flags_Enum + def Enum: Flags /** Is this symbol `erased` */ - def Erased: Flags = reflectSelf.Flags_Erased + def Erased: Flags /** Is this symbol a `def` defined in an `extension` */ - def ExtensionMethod: Flags = reflectSelf.Flags_ExtensionMethod + def ExtensionMethod: Flags /** Is this symbol a getter or a setter */ - def FieldAccessor: Flags = reflectSelf.Flags_FieldAccessor + def FieldAccessor: Flags /** Is this symbol `final` */ - def Final: Flags = reflectSelf.Flags_Final + def Final: Flags /** Is this symbol an inferable ("given") parameter */ - def Given: Flags = reflectSelf.Flags_Given + def Given: Flags /** Is this symbol a parameter with a default value? */ - def HasDefault: Flags = reflectSelf.Flags_HasDefault + def HasDefault: Flags /** Is this symbol `implicit` */ - def Implicit: Flags = reflectSelf.Flags_Implicit + def Implicit: Flags /** Is this symbol `inline` */ - def Inline: Flags = reflectSelf.Flags_Inline + def Inline: Flags /** Is this symbol defined in a Java class */ - def JavaDefined: Flags = reflectSelf.Flags_JavaDefined + def JavaDefined: Flags /** Is this symbol `lazy` */ - def Lazy: Flags = reflectSelf.Flags_Lazy + def Lazy: Flags /** Is this symbol local? Used in conjunction with private/private[Type] to mean private[this] extends Modifier proctected[this] */ - def Local: Flags = reflectSelf.Flags_Local + def Local: Flags /** Is this symbol marked as a macro. An inline method containing toplevel splices */ - def Macro: Flags = reflectSelf.Flags_Macro + def Macro: Flags /** Is this symbol a module class */ - def ModuleClass: Flags = reflectSelf.Flags_ModuleClass + def ModuleClass: Flags /** Is this symbol a `var` (when used on a ValDef) */ - def Mutable: Flags = reflectSelf.Flags_Mutable + def Mutable: Flags /** Is this symbol an object or its class (used for a ValDef or a ClassDef extends Modifier respectively) */ - def Object: Flags = reflectSelf.Flags_Object + def Object: Flags /** Is this symbol `override` */ - def Override: Flags = reflectSelf.Flags_Override + def Override: Flags /** Is this symbol a package */ - def Package: Flags = reflectSelf.Flags_Package + def Package: Flags /** Is this symbol a parameter */ - def Param: Flags = reflectSelf.Flags_Param + def Param: Flags /** Is this symbol a parameter accessor */ - def ParamAccessor: Flags = reflectSelf.Flags_ParamAccessor + def ParamAccessor: Flags /** Is this symbol `private` */ - def Private: Flags = reflectSelf.Flags_Private + def Private: Flags /** Is this symbol labeled private[this] */ - def PrivateLocal: Flags = reflectSelf.Flags_PrivateLocal + def PrivateLocal: Flags /** Is this symbol `protected` */ - def Protected: Flags = reflectSelf.Flags_Protected + def Protected: Flags /** Was this symbol imported from Scala2.x */ - def Scala2X: Flags = reflectSelf.Flags_Scala2X + def Scala2x: Flags /** Is this symbol `sealed` */ - def Sealed: Flags = reflectSelf.Flags_Sealed + def Sealed: Flags /** Is this symbol member that is assumed to be stable and realizable */ - def StableRealizable: Flags = reflectSelf.Flags_StableRealizable + def StableRealizable: Flags /** Is this symbol marked as static. Mapped to static Java member */ - def Static: Flags = reflectSelf.Flags_Static + def Static: Flags /** Is this symbol to be tagged Java Synthetic */ - def Synthetic: Flags = reflectSelf.Flags_Synthetic + def Synthetic: Flags /** Is this symbol a trait */ - def Trait: Flags = reflectSelf.Flags_Trait - end Flags + def Trait: Flags + } + + given FlagsMethods as FlagsMethods = FlagsMethodsImpl + protected val FlagsMethodsImpl: FlagsMethods - given FlagsOps as AnyRef: - extension (flags: Flags): + trait FlagsMethods { + extension (self: Flags): /** Is the given flag set a subset of this flag sets */ - def is(that: Flags): Boolean = reflectSelf.Flags_is(flags)(that) + def is(that: Flags): Boolean /** Union of the two flag sets */ - def |(that: Flags): Flags = reflectSelf.Flags_or(flags)(that) + def |(that: Flags): Flags /** Intersection of the two flag sets */ - def &(that: Flags): Flags = reflectSelf.Flags_and(flags)(that) + def &(that: Flags): Flags /** Shows the tree as extractors */ - def showExtractors: String = - new ExtractorsPrinter[reflectSelf.type](reflectSelf).showFlags(flags) + def showExtractors: String /** Shows the tree as fully typed source code */ - def show: String = - flags.showWith(SyntaxHighlight.plain) + def show: String /** Shows the tree as fully typed source code */ - def showWith(syntaxHighlight: SyntaxHighlight): String = - new SourceCodePrinter[reflectSelf.type](reflectSelf)(syntaxHighlight).showFlags(flags) + def showWith(syntaxHighlight: SyntaxHighlight): String end extension - end FlagsOps - + } /////////////// // POSITIONS // @@ -2521,60 +3057,99 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => /** Root position of this tasty context. For macros it corresponds to the expansion site. */ def rootPosition: Position + /** Position in a source file */ + type Position <: AnyRef + + val Position: PositionModule - object Position + trait PositionModule { this: Position.type => } - given PositionOps as AnyRef: - extension (pos: Position): + given PositionMethods as PositionMethods = PositionMethodsImpl + protected val PositionMethodsImpl: PositionMethods + + trait PositionMethods { + extension (self: Position): /** The start offset in the source file */ - def start: Int = reflectSelf.Position_start(pos) + def start: Int /** The end offset in the source file */ - def end: Int = reflectSelf.Position_end(pos) + def end: Int /** Does this position exist */ - def exists: Boolean = reflectSelf.Position_exists(pos) + def exists: Boolean /** Source file in which this position is located */ - def sourceFile: SourceFile = reflectSelf.Position_sourceFile(pos) + def sourceFile: SourceFile /** The start line in the source file */ - def startLine: Int = reflectSelf.Position_startLine(pos) + def startLine: Int /** The end line in the source file */ - def endLine: Int = reflectSelf.Position_endLine(pos) + def endLine: Int /** The start column in the source file */ - def startColumn: Int = reflectSelf.Position_startColumn(pos) + def startColumn: Int /** The end column in the source file */ - def endColumn: Int = reflectSelf.Position_endColumn(pos) + def endColumn: Int /** Source code within the position */ - def sourceCode: String = reflectSelf.Position_sourceCode(pos) + def sourceCode: String end extension - end PositionOps + } + + /** Scala source file */ + type SourceFile <: AnyRef - object SourceFile + val SourceFile: SourceFileModule - given SourceFileOps as AnyRef: - extension (sourceFile: SourceFile): + trait SourceFileModule { this: SourceFile.type => } + given SourceFileMethods as SourceFileMethods = SourceFileMethodsImpl + protected val SourceFileMethodsImpl: SourceFileMethods + + trait SourceFileMethods { + extension (self: SourceFile): /** Path to this source file */ - def jpath: java.nio.file.Path = reflectSelf.SourceFile_jpath(sourceFile) + def jpath: java.nio.file.Path /** Content of this source file */ - def content: String = reflectSelf.SourceFile_content(sourceFile) - + def content: String end extension - end SourceFileOps + } + + /////////////// + // Source // + /////////////// + + val Source: SourceModule + + trait SourceModule { this: Source.type => + + /** Returns the source file being compiled. The path is relative to the current working directory. */ + def path: java.nio.file.Path + + /** Returns true if we've tried to reflect on a Java class. */ + def isJavaCompilationUnit: Boolean + + /** Returns true if we've tried to reflect on a Scala2 (non-Tasty) class. */ + def isScala2CompilationUnit: Boolean + + /** Returns true if we've tried to reflect on a class that's already loaded (e.g. Option). */ + def isAlreadyLoadedCompilationUnit: Boolean + + /** Class name of the current CompilationUnit */ + def compilationUnitClassname: String + } /////////////// // REPORTING // /////////////// + // TODO: these should not be top level + /** Emits an error message */ def error(msg: => String, pos: Position): Unit @@ -2587,28 +3162,35 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => /** Emits a warning at a specific range of a file */ def warning(msg: => String, source: SourceFile, start: Int, end: Int): Unit - ////////////// // COMMENTS // ////////////// - object Comment + // TODO: misnomer. Rename to `Documentation` - given CommentOps as AnyRef: - extension (self: Comment): + /** Attachment representing the documentation of a definition */ + type Comment <: AnyRef + + val Comment: CommentModule + trait CommentModule { this: Comment.type => } + + given CommentMethods as CommentMethods = CommentMethodsImpl + protected val CommentMethodsImpl: CommentMethods + + trait CommentMethods { + extension (self: Comment): /** Raw comment string */ - def raw: String = reflectSelf.Comment_raw(self) + def raw: String /** Expanded comment string, if any */ - def expanded: Option[String] = reflectSelf.Comment_expanded(self) + def expanded: Option[String] /** List of usecases and their corresponding trees, if any */ - def usecases: List[(String, Option[DefDef])] = reflectSelf.Comment_usecases(self) + def usecases: List[(String, Option[DefDef])] end extension - end CommentOps - + } /////////////// // UTILS // @@ -2616,20 +3198,20 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => /** TASTy Reflect tree accumulator */ trait TreeAccumulator[X] extends reflect.TreeAccumulator[X] { - val reflect: reflectSelf.type = reflectSelf + val reflect: reflection.type = reflection } /** TASTy Reflect tree traverser */ trait TreeTraverser extends reflect.TreeTraverser { - val reflect: reflectSelf.type = reflectSelf + val reflect: reflection.type = reflection } /** TASTy Reflect tree map */ trait TreeMap extends reflect.TreeMap { - val reflect: reflectSelf.type = reflectSelf + val reflect: reflection.type = reflection } - // TODO extract from Reflection + // TODO: extract from Reflection /** Bind the `rhs` to a `val` and use it in `body` */ def let(rhs: Term)(body: Ident => Term): Term = { @@ -2646,4 +3228,5 @@ trait Reflection extends reflect.Types { reflectSelf: CompilerInterface => rec(terms, Nil) } + } diff --git a/library/src/scala/tasty/reflect/ExtractorsPrinter.scala b/library/src/scala/tasty/reflect/ExtractorsPrinter.scala index 9c3be02490d0..81e2fac2f914 100644 --- a/library/src/scala/tasty/reflect/ExtractorsPrinter.scala +++ b/library/src/scala/tasty/reflect/ExtractorsPrinter.scala @@ -21,7 +21,7 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val tasty: R) extends Print if (flags.is(Flags.Abstract)) flagList += "Flags.Abstract" if (flags.is(Flags.Artifact)) flagList += "Flags.Artifact" if (flags.is(Flags.Case)) flagList += "Flags.Case" - if (flags.is(Flags.CaseAcessor)) flagList += "Flags.CaseAcessor" + if (flags.is(Flags.CaseAccessor)) flagList += "Flags.CaseAccessor" if (flags.is(Flags.Contravariant)) flagList += "Flags.Contravariant" if (flags.is(Flags.Covariant)) flagList += "Flags.Covariant" if (flags.is(Flags.Enum)) flagList += "Flags.Enum" @@ -46,7 +46,7 @@ class ExtractorsPrinter[R <: Reflection & Singleton](val tasty: R) extends Print if (flags.is(Flags.Private)) flagList += "Flags.Private" if (flags.is(Flags.PrivateLocal)) flagList += "Flags.PrivateLocal" if (flags.is(Flags.Protected)) flagList += "Flags.Protected" - if (flags.is(Flags.Scala2X)) flagList += "Flags.Scala2X" + if (flags.is(Flags.Scala2x)) flagList += "Flags.Scala2x" if (flags.is(Flags.Sealed)) flagList += "Flags.Sealed" if (flags.is(Flags.StableRealizable)) flagList += "Flags.StableRealizable" if (flags.is(Flags.Static)) flagList += "Flags.javaStatic" diff --git a/library/src/scala/tasty/reflect/Printer.scala b/library/src/scala/tasty/reflect/Printer.scala index ce727cc6abeb..b8137000693d 100644 --- a/library/src/scala/tasty/reflect/Printer.scala +++ b/library/src/scala/tasty/reflect/Printer.scala @@ -1,6 +1,7 @@ package scala.tasty package reflect +// TODO use QuoteContext instead of Reflection trait Printer[R <: Reflection & Singleton] { /** Instance of reflection interface */ diff --git a/library/src/scala/tasty/reflect/SourceCodePrinter.scala b/library/src/scala/tasty/reflect/SourceCodePrinter.scala index 565e735dccf7..da0775577bf9 100644 --- a/library/src/scala/tasty/reflect/SourceCodePrinter.scala +++ b/library/src/scala/tasty/reflect/SourceCodePrinter.scala @@ -26,7 +26,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig if (flags.is(Flags.Abstract)) flagList += "abstract" if (flags.is(Flags.Artifact)) flagList += "artifact" if (flags.is(Flags.Case)) flagList += "case" - if (flags.is(Flags.CaseAcessor)) flagList += "caseAccessor" + if (flags.is(Flags.CaseAccessor)) flagList += "caseAccessor" if (flags.is(Flags.Contravariant)) flagList += "contravariant" if (flags.is(Flags.Covariant)) flagList += "covariant" if (flags.is(Flags.Enum)) flagList += "enum" @@ -51,7 +51,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig if (flags.is(Flags.Private)) flagList += "private" if (flags.is(Flags.PrivateLocal)) flagList += "private[this]" if (flags.is(Flags.Protected)) flagList += "protected" - if (flags.is(Flags.Scala2X)) flagList += "scala2x" + if (flags.is(Flags.Scala2x)) flagList += "scala2x" if (flags.is(Flags.Sealed)) flagList += "sealed" if (flags.is(Flags.StableRealizable)) flagList += "stableRealizable" if (flags.is(Flags.Static)) flagList += "javaStatic" @@ -849,7 +849,7 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig } printedPrefix |= printProtectedOrPrivate(vdef) if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightValDef("var ") - else if (printedPrefix || !vdef.symbol.flags.is(Flags.CaseAcessor)) this += highlightValDef("val ") + else if (printedPrefix || !vdef.symbol.flags.is(Flags.CaseAccessor)) this += highlightValDef("val ") } } end if diff --git a/library/src/scala/tasty/reflect/Types.scala b/library/src/scala/tasty/reflect/Types.scala deleted file mode 100644 index d3b3037047b2..000000000000 --- a/library/src/scala/tasty/reflect/Types.scala +++ /dev/null @@ -1,409 +0,0 @@ -package scala.tasty.reflect - -import scala.internal.tasty.CompilerInterface - -import scala.quoted.QuoteContext -import scala.quoted.show.SyntaxHighlight -import scala.tasty.reflect._ - -/** TASTy Reflect - * - * - * Type hierarchy - * ```none - * - * +- Tree -+- PackageClause - * +- Import - * +- Statement -+- Definition --+- PackageDef - * | | +- ClassDef - * | | +- TypeDef - * | | +- DefDef - * | | +- ValDef - * | | - * | +- Term --------+- Ref -+- Ident - * | | +- Select - * | | - * | +- Literal - * | +- This - * | +- New - * | +- NamedArg - * | +- Apply - * | +- TypeApply - * | +- Super - * | +- Typed - * | +- Assign - * | +- Block - * | +- Closure - * | +- If - * | +- Match - * | +- GivenMatch - * | +- Try - * | +- Return - * | +- Repeated - * | +- Inlined - * | +- SelectOuter - * | +- While - * | - * | - * +- TypeTree ----+- Inferred - * | +- TypeIdent - * | +- TypeSelect - * | +- Projection - * | +- Singleton - * | +- Refined - * | +- Applied - * | +- Annotated - * | +- MatchTypeTree - * | +- ByName - * | +- LambdaTypeTree - * | +- TypeBind - * | +- TypeBlock - * | - * +- TypeBoundsTree - * +- WildcardTypeTree - * | - * +- CaseDef - * | - * +- TypeCaseDef - * +- Bind - * +- Unapply - * +- Alternatives - * - * - * +- Type -+- ConstantType - * +- TermRef - * +- TypeRef - * +- SuperType - * +- Refinement - * +- AppliedType - * +- AnnotatedType - * +- AndType - * +- OrType - * +- MatchType - * +- ByNameType - * +- ParamRef - * +- ThisType - * +- RecursiveThis - * +- RecursiveType - * +- LambdaType -+- MethodType - * | +- PolyType - * | +- TypeLambda - * +- TypeBounds - * +- NoPrefix - * - * +- ImportSelector -+- SimpleSelector - * +- RenameSelector - * +- OmitSelector - * - * +- Id - * - * +- Signature - * - * +- Position - * - * +- Comment - * - * +- Constant - * - * +- Symbol - * - * +- Flags - * - * ``` - */ -trait Types { - - /** Compilation context */ - type Context <: AnyRef - - /** Tree representing code written in the source */ - type Tree <: AnyRef - - /** Tree representing a pacakage clause in the source code */ - type PackageClause <: Tree - - /** Tree representing a statement in the source code */ - type Statement <: Tree - - /** Tree representing an import in the source code */ - type Import <: Statement - - /** Tree representing a definition in the source code. It can be `PackageDef`, `ClassDef`, `TypeDef`, `DefDef` or `ValDef` */ - type Definition <: Statement - - /** Tree representing a package definition. This includes definitions in all source files */ - type PackageDef <: Definition - - /** Tree representing a class definition. This includes annonymus class definitions and the class of a module object */ - type ClassDef <: Definition - - /** Tree representing a type (parameter or member) definition in the source code */ - type TypeDef <: Definition - - /** Tree representing a method definition in the source code */ - type DefDef <: Definition - - /** Tree representing a value definition in the source code This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */ - type ValDef <: Definition - - /** Tree representing an expression in the source code */ - type Term <: Statement - - /** Tree representing a reference to definition */ - type Ref <: Term - - /** Tree representing a reference to definition with a given name */ - type Ident <: Ref - - /** Tree representing a selection of definition with a given name on a given prefix */ - type Select <: Ref - - /** Tree representing a literal value in the source code */ - type Literal <: Term - - /** Tree representing `this` in the source code */ - type This <: Term - - /** Tree representing `new` in the source code */ - type New <: Term - - /** Tree representing an argument passed with an explicit name. Such as `arg1 = x` in `foo(arg1 = x)` */ - type NamedArg <: Term - - /** Tree an application of arguments. It represents a single list of arguments, multiple argument lists will have nested `Apply`s */ - type Apply <: Term - - /** Tree an application of type arguments */ - type TypeApply <: Term - - /** Tree representing `super` in the source code */ - type Super <: Term - - /** Tree representing a type ascription `x: T` in the source code */ - type Typed <: Term - - /** Tree representing an assignment `x = y` in the source code */ - type Assign <: Term - - /** Tree representing a block `{ ... }` in the source code */ - type Block <: Term - - /** A lambda `(...) => ...` in the source code is represented as - * a local method and a closure: - * - * { - * def m(...) = ... - * closure(m) - * } - * - */ - type Closure <: Term - - /** Tree representing an if/then/else `if (...) ... else ...` in the source code */ - type If <: Term - - /** Tree representing a pattern match `x match { ... }` in the source code */ - type Match <: Term - - /** Tree representing a pattern match `given match { ... }` in the source code */ // TODO: drop - type GivenMatch <: Term - - /** Tree representing a try catch `try x catch { ... } finally { ... }` in the source code */ - type Try <: Term - - /** Tree representing a `return` in the source code */ - type Return <: Term - - /** Tree representing a variable argument list in the source code */ - type Repeated <: Term - - /** Tree representing the scope of an inlined tree */ - type Inlined <: Term - - /** Tree representing a selection of definition with a given name on a given prefix and number of nested scopes of inlined trees */ - type SelectOuter <: Term - - /** Tree representing a while loop */ - type While <: Term - - /** Type tree representing a type written in the source */ - type TypeTree <: Tree - - /** Type tree representing an inferred type */ - type Inferred <: TypeTree - - /** Type tree representing a reference to definition with a given name */ - type TypeIdent <: TypeTree - - /** Type tree representing a selection of definition with a given name on a given term prefix */ - type TypeSelect <: TypeTree - - /** Type tree representing a selection of definition with a given name on a given type prefix */ - type Projection <: TypeTree - - /** Type tree representing a singleton type */ - type Singleton <: TypeTree - - /** Type tree representing a type refinement */ - type Refined <: TypeTree - - /** Type tree representing a type application */ - type Applied <: TypeTree - - /** Type tree representing an annotated type */ - type Annotated <: TypeTree - - /** Type tree representing a type match */ - type MatchTypeTree <: TypeTree - - /** Type tree representing a by name parameter */ - type ByName <: TypeTree - - /** Type tree representing a lambda abstraction type */ - type LambdaTypeTree <: TypeTree - - /** Type tree representing a type binding */ - type TypeBind <: TypeTree - - /** Type tree within a block with aliases `{ type U1 = ... ; T[U1, U2] }` */ - type TypeBlock <: TypeTree - - /** Type tree representing a type bound written in the source */ - type TypeBoundsTree <: Tree /*TypeTree | TypeBoundsTree*/ - - /** Type tree representing wildcard type bounds written in the source. - * The wildcard type `_` (for example in in `List[_]`) will be a type tree that - * represents a type but has `TypeBound`a inside. - */ - type WildcardTypeTree <: Tree - - /** Branch of a pattern match or catch clause */ - type CaseDef <: Tree - - /** Branch of a type pattern match */ - type TypeCaseDef <: Tree - - /** Pattern representing a `_ @ _` binding. */ - type Bind <: Tree - - /** Pattern representing a `Xyz(...)` unapply. */ - type Unapply <: Tree - - /** Pattern representing `X | Y | ...` alternatives. */ - type Alternatives <: Tree - - /** A type, type constructors, type bounds or NoPrefix */ - type Type - - /** A singleton type representing a known constant value */ - type ConstantType <: Type - - /** Type of a reference to a term symbol */ - type TermRef <: Type - - /** Type of a reference to a type symbol */ - type TypeRef <: Type - - /** Type of a `super` reference */ - type SuperType <: Type - - /** A type with a type refinement `T { type U }` */ - type Refinement <: Type - - /** A higher kinded type applied to some types `T[U]` */ - type AppliedType <: Type - - /** A type with an anottation `T @foo` */ - type AnnotatedType <: Type - - /** Intersection type `T & U` */ - type AndType <: Type - - /** Union type `T | U` */ - type OrType <: Type - - /** Type match `T match { case U => ... }` */ - type MatchType <: Type - - /** Type of a by by name parameter */ - type ByNameType <: Type - - /** Type of a parameter reference */ - type ParamRef <: Type - - /** Type of `this` */ - type ThisType <: Type - - /** A type that is recursively defined `this` */ - type RecursiveThis <: Type - - /** A type that is recursively defined */ - type RecursiveType <: Type - - /** Common abstraction for lambda types (MethodType, PolyType and TypeLambda). */ - type LambdaType <: Type - - /** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */ - type MethodType <: LambdaType - - /** Type of the definition of a method taking a list of type parameters. It's return type may be a MethodType. */ - type PolyType <: LambdaType - - /** Type of the definition of a type lambda taking a list of type parameters. It's return type may be a TypeLambda. */ - type TypeLambda <: LambdaType - - /** NoPrefix for a type selection */ - type NoPrefix <: Type - - /** Type bounds */ - type TypeBounds <: Type - - /** Import selectors: - * * SimpleSelector: `.bar` in `import foo.bar` - * * RenameSelector: `.{bar => baz}` in `import foo.{bar => baz}` - * * OmitSelector: `.{bar => _}` in `import foo.{bar => _}` - */ - type ImportSelector <: AnyRef - type SimpleSelector <: ImportSelector - type RenameSelector <: ImportSelector - type OmitSelector <: ImportSelector - - /** Untyped identifier */ - type Id <: AnyRef - - /** Signature of a method */ - type Signature <: AnyRef - - /** Position in a source file */ - type Position <: AnyRef - - /** Scala source file */ - type SourceFile <: AnyRef - - /** Comment */ - type Comment <: AnyRef - - /** Constant value represented as the constant itself */ - type Constant <: AnyRef - - /** Symbol of a definition. - * Then can be compared with == to know if the definition is the same. - */ - type Symbol <: AnyRef - - /** FlagSet of a Symbol */ - type Flags - - type ImplicitSearchResult <: AnyRef - - type ImplicitSearchSuccess <: ImplicitSearchResult - - type ImplicitSearchFailure <: ImplicitSearchResult - - type DivergingImplicit <: ImplicitSearchFailure - - type NoMatchingImplicits <: ImplicitSearchFailure - - type AmbiguousImplicits <: ImplicitSearchFailure - -} diff --git a/tests/run-macros/tasty-definitions-1.check b/tests/run-macros/tasty-definitions-1.check index 723d10321f1c..7ee9da3e64e8 100644 --- a/tests/run-macros/tasty-definitions-1.check +++ b/tests/run-macros/tasty-definitions-1.check @@ -4,7 +4,7 @@ Any AnyVal Object AnyRef -Any +Null Nothing Unit Byte From 5cd1cce6e8903363d2f4f04718014b5e5df76310 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 24 Sep 2020 14:23:37 +0200 Subject: [PATCH 2/2] Review --- compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala | 3 +-- compiler/src/dotty/tools/dotc/transform/TailRec.scala | 2 +- library/src/scala/tasty/Reflection.scala | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala index f0d85cc20d8f..2afd706e318f 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala @@ -50,8 +50,7 @@ object QuoteContextImpl { } class QuoteContextImpl private (ctx: Context) extends QuoteContext: - // NOTE: The tasty class should only mixin the compiler interface and the reflection interface. - // We should not implement methods here, all should be implemented by `ReflectionCompilerInterface` + object tasty extends scala.tasty.Reflection, scala.internal.tasty.CompilerInterface: def rootContext: Context = ctx diff --git a/compiler/src/dotty/tools/dotc/transform/TailRec.scala b/compiler/src/dotty/tools/dotc/transform/TailRec.scala index 0fe23dfd42c1..10841bf552c9 100644 --- a/compiler/src/dotty/tools/dotc/transform/TailRec.scala +++ b/compiler/src/dotty/tools/dotc/transform/TailRec.scala @@ -186,7 +186,7 @@ class TailRec extends MiniPhase { def tailArgOrPureExpr(stat: Tree): Boolean = stat match { case stat: ValDef if stat.name.is(TailTempName) || !stat.symbol.is(Mutable) => tailArgOrPureExpr(stat.rhs) case Assign(lhs: Ident, rhs) if lhs.symbol.name.is(TailLocalName) => tailArgOrPureExpr(rhs) - case Assign(lhs: Ident, rhs: Ident) if lhs.symbol == rhs.symbol => true + case Assign(lhs: Ident, rhs: Ident) => lhs.symbol == rhs.symbol case stat: Ident if stat.symbol.name.is(TailLocalName) => true case _ => tpd.isPureExpr(stat) } diff --git a/library/src/scala/tasty/Reflection.scala b/library/src/scala/tasty/Reflection.scala index bf151f735d8b..4cab6e126bc4 100644 --- a/library/src/scala/tasty/Reflection.scala +++ b/library/src/scala/tasty/Reflection.scala @@ -248,7 +248,7 @@ trait Reflection { reflection => // ClassDef - /** Tree representing a class definition. This includes annonymus class definitions and the class of a module object */ + /** Tree representing a class definition. This includes anonymous class definitions and the class of a module object */ type ClassDef <: Definition given TypeTest[Tree, ClassDef] = ClassDefTypeTest