-
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
Merged
nicolasstucki
merged 3 commits into
scala:master
from
dotty-staging:add-symbols-to-tasty-reflect
Aug 22, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dotty.tools.dotc.tastyreflect | ||
|
||
import dotty.tools.dotc.core.Symbols._ | ||
|
||
trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with TastyCoreImpl { | ||
|
||
def SymbolDeco(symbol: Symbol): SymbolAPI = new SymbolAPI { | ||
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)) | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,20 @@ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 SymbolAPI { | ||
def isEmpty: Boolean | ||
def localContext(implicit ctx: Context): Context | ||
def tree(implicit ctx: Context): Option[Definition] | ||
} | ||
implicit def SymbolDeco(symbol: Symbol): SymbolAPI | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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