Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add missing types to TASTy reflect #5483

Merged
merged 1 commit into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ trait CoreImpl extends scala.tasty.reflect.Core {
type DefDef = tpd.DefDef
type ValDef = tpd.ValDef
type Term = tpd.Tree
val Term: TermCoreModuleImpl
trait TermCoreModuleImpl extends TermCoreModule {
type Ident = tpd.Ident
type Select = tpd.Select
type Literal = tpd.Literal
type This = tpd.This
type New = tpd.New
type NamedArg = tpd.NamedArg
type Apply = tpd.Apply
type TypeApply = tpd.TypeApply
type Super = tpd.Super
type Typed = tpd.Typed
type Assign = tpd.Assign
type Block = tpd.Block
type Lambda = tpd.Closure
type If = tpd.If
type Match = tpd.Match
type Try = tpd.Try
type Return = tpd.Return
type Repeated = tpd.SeqLiteral
type Inlined = tpd.Inlined
type SelectOuter = tpd.Select
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is SelectOuter? I think maybe there is no need for constructor for Inline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Select outer is a special case of a Select where it keeps track of the inlined scoped to avoid ambiguities.

Inline is used to keep track of the source file where the tree came from to have a correct position. If the macros would just drop them, every position in the resulting tree would be incorrect.

type While = tpd.WhileDo
}


type CaseDef = tpd.CaseDef
type TypeCaseDef = tpd.CaseDef
Expand All @@ -37,6 +62,23 @@ trait CoreImpl extends scala.tasty.reflect.Core {

type TypeOrBoundsTree = tpd.Tree
type TypeTree = tpd.Tree
val TypeTree: TypeTreeCoreModuleImpl
trait TypeTreeCoreModuleImpl extends TypeTreeCoreModule {
type Synthetic = tpd.TypeTree
type Ident = tpd.Ident
type Select = tpd.Select
type Project = tpd.Select
type Singleton = tpd.SingletonTypeTree
type Refined = tpd.RefinedTypeTree
type Applied = tpd.AppliedTypeTree
type Annotated = tpd.Annotated
type And = tpd.AndTypeTree
type Or = tpd.OrTypeTree
type MatchType = tpd.MatchTypeTree
type ByName = tpd.ByNameTypeTree
type LambdaTypeTree = tpd.LambdaTypeTree
type Bind = tpd.Bind
}
type TypeBoundsTree = tpd.Tree

type TypeOrBounds = Types.Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with CoreImpl with Helpers
if (termOrTypeTree.isTerm) Some(termOrTypeTree) else None
}

object Term extends TermModule {
object Term extends TermModule with TermCoreModuleImpl {

object Ident extends IdentExtractor {
def unapply(x: Term)(implicit ctx: Context): Option[String] = x match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
if (termOrTypeTree.isType) Some(termOrTypeTree) else None
}

object TypeTree extends TypeTreeModule {
object TypeTree extends TypeTreeModule with TypeTreeCoreModuleImpl {

object Synthetic extends SyntheticExtractor {
def unapply(x: TypeTree)(implicit ctx: Context): Boolean = x match {
Expand Down
145 changes: 130 additions & 15 deletions library/src/scala/tasty/reflect/Core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ package scala.tasty.reflect
* | +- Or
* | +- MatchType
* | +- ByName
* | +- TypeLambdaTree
* | +- LambdaTypeTree
* | +- Bind
* |
* +- TypeBoundsTree
Expand Down Expand Up @@ -136,29 +136,97 @@ trait Core {
/** 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`*/
/** 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. */
/** 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. */
/** Tree representing a class definition. This includes annonymus class definitions and the class of a module object */
type ClassDef <: Definition

/** Tree representing a type (paramter or member) definition in the source code. */
/** Tree representing a type (paramter or member) definition in the source code */
type TypeDef <: Definition

/** Tree representing a method definition in the source code. */
/** 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. */
/** 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. */
/** Tree representing an expression in the source code */
type Term <: Statement

// TODO Add subtype types of Term for documentation? Or support refined bindings and add the types.
/** Trees representing an expression in the source code */
val Term: TermCoreModule

/** Trees representing an expression in the source code */
trait TermCoreModule {

/** Tree representing a reference to definition with a given name */
type Ident <: Term

/** Tree representing a selection of definition with a given name on a given prefix */
type Select <: Term

/** 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

/** Tree representing a lambda `(...) => ...` in the source code */
type Lambda <: 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 tyr 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

}

/** Branch of a pattern match or catch clause */
type CaseDef <: AnyRef
Expand Down Expand Up @@ -190,8 +258,55 @@ trait Core {
/** Type tree representing a type written in the source */
type TypeTree <: TypeOrBoundsTree

// TODO Add subtype types of TypeTree for documentation? Or support refined bindings and add the types.
/** Type trees representing a type written in the source */
val TypeTree: TypeTreeCoreModule

/** Type trees representing a type written in the source */
abstract class TypeTreeCoreModule {

/** Type tree representing an inferred type */
type Synthetic <: TypeTree
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inferred instead of Synthetic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I will propose it in another PR.


/** Type tree representing a reference to definition with a given name */
type Ident <: TypeTree

/** Type tree representing a selection of definition with a given name on a given term prefix */
type Select <: TypeTree

/** Type tree representing a selection of definition with a given name on a given type prefix */
type Project <: 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 an intersection type */
type And <: TypeTree

/** Type tree representing a union type */
type Or <: TypeTree

/** Type tree representing a type match */
type MatchType <: 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 Bind <: TypeTree

}

/** Type tree representing a type bound written in the source */
type TypeBoundsTree <: TypeOrBoundsTree
Expand Down Expand Up @@ -250,25 +365,25 @@ trait Core {
*/
type Symbol <: AnyRef

/** Symbol of a package defnition */
/** Symbol of a package definition */
type PackageSymbol <: Symbol

/** Symbol of a class defnition. This includes annonymus class definitions and the class of a module object. */
/** Symbol of a class definition. This includes anonymous class definitions and the class of a module object. */
type ClassSymbol <: Symbol

/** Symbol of a type (paramter or member) definition. */
/** Symbol of a type (parameter or member) definition. */
type TypeSymbol <: Symbol

/** Symbol representing a method definition. */
type DefSymbol <: Symbol

/** Symbol representing a value definition. This inclues `val`, `lazy val`, `var`, `object` and parameter defintions. */
/** Symbol representing a value definition. This includes `val`, `lazy val`, `var`, `object` and parameter definitions. */
type ValSymbol <: Symbol

/** Symbol representing a bind definition. */
type BindSymbol <: Symbol

/** No symbol availabe. */
/** No symbol available. */
type NoSymbol <: Symbol

}
2 changes: 1 addition & 1 deletion library/src/scala/tasty/reflect/TreeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ trait TreeOps extends Core {

/** Scala term. Any tree that can go in expression position. */
val Term: TermModule
abstract class TermModule {
abstract class TermModule extends TermCoreModule {

/** Scala term identifier */
val Ident: IdentExtractor
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait TypeOrBoundsTreeOps extends Core {
}

val TypeTree: TypeTreeModule
abstract class TypeTreeModule {
abstract class TypeTreeModule extends TypeTreeCoreModule {

/** TypeTree containing an inferred type */
val Synthetic: SyntheticExtractor
Expand Down