Skip to content

Add TASTy reflect settings #5235

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 2 commits into from
Oct 10, 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
11 changes: 11 additions & 0 deletions compiler/src/dotty/tools/dotc/tastyreflect/SettingsOpsImpl.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dotty.tools.dotc.tastyreflect

trait SettingsOpsImpl extends scala.tasty.reflect.SettingsOps with TastyCoreImpl {

def settings(implicit ctx: Context): Settings = ctx.settings

def SettingsDeco(settings: Settings): SettingsAPI = new SettingsAPI {
def color(implicit ctx: Context): Boolean = settings.color.value == "always"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ trait TastyCoreImpl extends scala.tasty.reflect.TastyCore {

type Context = core.Contexts.Context

type Settings = config.ScalaSettings

type TermOrTypeTree = tpd.Tree

type Tree = tpd.Tree
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TastyImpl(val rootContext: Contexts.Context)
with PatternOpsImpl
with PositionOpsImpl
with PrintersImpl
with SettingsOpsImpl
with SignatureOpsImpl
with StandardDefinitions
with SymbolOpsImpl
Expand Down
1 change: 1 addition & 0 deletions library/src/scala/tasty/Tasty.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ abstract class Tasty
with PatternOps
with PositionOps
with Printers
with SettingsOps
with SignatureOps
with StandardDefinitions
with SymbolOps
Expand Down
13 changes: 13 additions & 0 deletions library/src/scala/tasty/reflect/SettingsOps.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package scala.tasty.reflect

trait SettingsOps extends TastyCore {

/** Compiler settings */
def settings(implicit ctx: Context): Settings

trait SettingsAPI {
def color(implicit ctx: Context): Boolean
}
implicit def SettingsDeco(settings: Settings): SettingsAPI

}
3 changes: 3 additions & 0 deletions library/src/scala/tasty/reflect/TastyCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ trait TastyCore {
/** Compilation context */
type Context

/** Settings */
type Settings

// TODO: When bootstrapped, remove and use `Term | TypeTree` type directly in other files
/** Workaround missing `|` types in Scala 2 to represent `Term | TypeTree` */
type TermOrTypeTree /* Term | TypeTree */
Expand Down
5 changes: 5 additions & 0 deletions library/src/scala/tasty/util/ShowSourceCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import scala.annotation.switch
class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty0) {
import tasty.{rootContext => _, _}

private[this] val color: Boolean = {
import tasty.rootContext
tasty.settings.color
}

def showTree(tree: Tree)(implicit ctx: Context): String =
(new Buffer).printTree(tree).result()

Expand Down