-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add back symbols to TASTy reflect #4976
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dotty.tools.dotc.tastyreflect | ||
|
||
import dotty.tools.dotc.ast.tpd | ||
import dotty.tools.dotc.core.Symbols._ | ||
|
||
trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with TastyCoreImpl { | ||
|
||
def SymbolasDeco(symbol: Symbol): SymbolasAPI = new SymbolasAPI { | ||
def isEmpty: Boolean = symbol eq NoSymbol | ||
def localContext(implicit ctx: Context): Context = ctx.withOwner(symbol) | ||
def tree(implicit ctx: Context): Option[Definition] = | ||
if (isEmpty) None else Some(FromSymbol.definitionFromSym(symbol)) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ package scala.tasty | |
|
||
import scala.tasty.reflect._ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reformat the following line to be shorter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
abstract class Tasty extends TastyCore with CaseDefOps with ConstantOps with ContextOps with IdOps with ImportSelectorOps with QuotedOps with PatternOps with PositionOps with Printers with SignatureOps with StandardDefinitions with TreeOps with TypeOrBoundsTreeOps with TypeOrBoundsOps | ||
abstract class Tasty extends TastyCore with CaseDefOps with ConstantOps with ContextOps with IdOps with ImportSelectorOps with QuotedOps with PatternOps with PositionOps with Printers with SignatureOps with StandardDefinitions with SymbolOps with TreeOps with TypeOrBoundsTreeOps with TypeOrBoundsOps |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package scala.tasty | ||
package reflect | ||
|
||
/** Tasty reflect symbol */ | ||
trait SymbolOps extends TastyCore { | ||
|
||
trait SymbolasAPI { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
def isEmpty: Boolean | ||
def localContext(implicit ctx: Context): Context | ||
def tree(implicit ctx: Context): Option[Definition] | ||
} | ||
implicit def SymbolasDeco(symbol: Symbol): SymbolasAPI | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DefDef("foo", Nil, Nil, TypeTree.Synthetic(), None) | ||
ValDef("bar", TypeTree.Synthetic(), None) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import scala.quoted._ | ||
import scala.tasty._ | ||
|
||
object Foo { | ||
|
||
transparent def inspectBody(i: => Int): String = | ||
~inspectBodyImpl('(i))(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~ | ||
|
||
def inspectBodyImpl(x: Expr[Int])(implicit tasty: Tasty): Expr[String] = { | ||
import tasty._ | ||
def definitionString(tree: Tree): Expr[String] = tree.symbol.tree match { | ||
case Some(definition) => definition.show.toExpr | ||
case None => '("NO DEFINTION") | ||
} | ||
x.toTasty match { | ||
case Term.Inlined(None, Nil, arg) => definitionString(arg) | ||
case arg => definitionString(arg) // TODO should all by name parameters be in an inline node? | ||
} | ||
} | ||
|
||
def foo: Int = 1 + 2 | ||
val bar: Int = 2 + 3 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
println(Foo.inspectBody(Foo.foo)) | ||
println(Foo.inspectBody(Foo.bar)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DefDef("foo", Nil, Nil, TypeTree.Synthetic(), None) | ||
ValDef("bar", TypeTree.Synthetic(), None) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import scala.quoted._ | ||
import scala.tasty._ | ||
|
||
object Foo { | ||
|
||
transparent def inspectBody(i: => Int): String = | ||
~inspectBodyImpl('(i))(TopLevelSplice.tastyContext) // FIXME infer TopLevelSplice.tastyContext within top level ~ | ||
|
||
def inspectBodyImpl(x: Expr[Int])(implicit tasty: Tasty): Expr[String] = { | ||
import tasty._ | ||
def definitionString(tree: Tree): Expr[String] = tree.symbol.tree match { | ||
case Some(definition) => definition.show.toExpr | ||
case None => '("NO DEFINTION") | ||
} | ||
x.toTasty match { | ||
case Term.Inlined(None, Nil, arg) => definitionString(arg) | ||
case arg => definitionString(arg) // TODO should all by name parameters be in an inline node? | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
object Test { | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(Foo.inspectBody(foo)) | ||
println(Foo.inspectBody(bar)) | ||
} | ||
|
||
def foo: Int = 1 + 2 | ||
val bar: Int = 2 + 3 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format the following line into several lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done