Skip to content

Fix #8114: Add bind symbol and tree constructors #8975

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

Merged
merged 1 commit into from
May 13, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend

def Tree_Bind_pattern(self: Bind)(using ctx: Context): Tree = self.body

def Tree_Bind_module_apply(sym: Symbol, body: Tree)(using ctx: Context): Bind =
tpd.Bind(sym, body)

def Tree_Bind_module_copy(original: Tree)(name: String, pattern: Tree)(using ctx: Context): Bind =
withDefaultPos(tpd.cpy.Bind(original)(name.toTermName, pattern))

Expand Down Expand Up @@ -1790,6 +1793,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
def Symbol_newVal(parent: Symbol, name: String, flags: Flags, tpe: Type, privateWithin: Symbol)(using ctx: Context): Symbol =
ctx.newSymbol(parent, name.toTermName, flags, tpe, privateWithin)

def Symbol_newBind(parent: Symbol, name: String, flags: Flags, tpe: Type)(using ctx: Context): Symbol =
ctx.newSymbol(parent, name.toTermName, flags | Case, tpe)

def Symbol_isTypeParam(self: Symbol)(using ctx: Context): Boolean =
self.isTypeParam

Expand Down
16 changes: 15 additions & 1 deletion library/src/scala/tasty/Reflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,8 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
given (using ctx: Context) as IsInstanceOf[Bind] = internal.isInstanceOfBind

object Bind {
// TODO def apply(name: String, pattern: Tree)(using ctx: Context): Bind
def apply(sym: Symbol, pattern: Tree)(using ctx: Context): Bind =
internal.Tree_Bind_module_apply(sym, pattern)
def copy(original: Tree)(name: String, pattern: Tree)(using ctx: Context): Bind =
internal.Tree_Bind_module_copy(original)(name, pattern)
def unapply(pattern: Bind)(using ctx: Context): Option[(String, Tree)] =
Expand Down Expand Up @@ -2117,6 +2118,19 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
def newVal(parent: Symbol, name: String, tpe: Type, flags: Flags, privateWithin: Symbol)(using ctx: Context): Symbol =
internal.Symbol_newVal(parent, name, flags, tpe, privateWithin)

/** Generates a pattern bind symbol with the given parent, name and type.
*
* This symbol starts without an accompanying definition.
* It is the meta-programmer's responsibility to provide exactly one corresponding definition by passing
* this symbol to the BindDef constructor.
*
* @param flags extra flags to with which the symbol should be constructed
* @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)(using ctx: Context): Symbol =
internal.Symbol_newBind(parent, name, flags, tpe)

/** Definition not available */
def noSymbol(using ctx: Context): Symbol =
internal.Symbol_noSymbol
Expand Down
4 changes: 4 additions & 0 deletions library/src/scala/tasty/reflect/CompilerInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ trait CompilerInterface {

def Tree_Bind_pattern(self: Bind)(using ctx: Context): Tree

def Tree_Bind_module_apply(sym: Symbol, body: Tree)(using ctx: Context): Bind

def Tree_Bind_module_copy(original: Tree)(name: String, pattern: Tree)(using ctx: Context): Bind

/** Tree representing an unapply pattern `Xyz(...)` */
Expand Down Expand Up @@ -1336,6 +1338,8 @@ trait CompilerInterface {

def Symbol_newVal(parent: Symbol, name: String, flags: Flags, tpe: Type, privateWithin: Symbol)(using ctx: Context): Symbol

def Symbol_newBind(parent: Symbol, name: String, flags: Flags, tpe: Type)(using ctx: Context): Symbol

def Symbol_isTypeParam(self: Symbol)(using ctx: Context): Boolean

def Symbol_isPackageDef(symbol: Symbol)(using ctx: Context): Boolean
Expand Down