Skip to content

Tasty add flag constructors #5670

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
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@ trait CoreImpl extends scala.tasty.reflect.Core {
type BindSymbol = core.Symbols.TermSymbol
type ValSymbol = core.Symbols.TermSymbol
type NoSymbol = core.Symbols.NoSymbol.type

type Flags = core.Flags.FlagSet
}
68 changes: 0 additions & 68 deletions compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala

This file was deleted.

46 changes: 46 additions & 0 deletions compiler/src/dotty/tools/dotc/tastyreflect/FlagsOpsImpl.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package dotty.tools.dotc
package tastyreflect

import dotty.tools.dotc.core.Decorators._

import scala.tasty.reflect

trait FlagsOpsImpl extends scala.tasty.reflect.FlagsOps with CoreImpl {

def FlagsDeco(flagSet: Flags): FlagsAPI = new FlagsAPI {
def is(that: Flags): Boolean = flagSet is that
def |(that: Flags): Flags = flagSet | that
def &(that: Flags): Flags = flagSet & that
}

object Flags extends FlagsModule {
def Protected: Flags = core.Flags.Protected
def Abstract: Flags = core.Flags.Abstract
def Final: Flags = core.Flags.Final
def Sealed: Flags = core.Flags.Sealed
def Case: Flags = core.Flags.Case
def Implicit: Flags = core.Flags.Implicit
def Erased: Flags = core.Flags.Erased
def Lazy: Flags = core.Flags.Lazy
def Override: Flags = core.Flags.Override
def Inline: Flags = core.Flags.Inline
def Macro: Flags = core.Flags.Macro
def Static: Flags = core.Flags.JavaStatic
def Object: Flags = core.Flags.Module
def Trait: Flags = core.Flags.Trait
def Local: Flags = core.Flags.Local
def Synthetic: Flags = core.Flags.Synthetic
def Artifact: Flags = core.Flags.Artifact
def Mutable: Flags = core.Flags.Mutable
def FieldAccessor: Flags = core.Flags.Accessor
def CaseAcessor: Flags = core.Flags.CaseAccessor
def Covariant: Flags = core.Flags.Covariant
def Contravariant: Flags = core.Flags.Contravariant
def Scala2X: Flags = core.Flags.Scala2x
def DefaultParameterized: Flags = core.Flags.DefaultParameterized
def Stable: Flags = core.Flags.Stable
def Param: Flags = core.Flags.Param
def ParamAccessor: Flags = core.Flags.ParamAccessor
}

}
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/tastyreflect/PrintersImpl.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package dotty.tools.dotc.tastyreflect
import dotty.tools.dotc.core.Flags

trait PrintersImpl extends scala.tasty.reflect.Printers with scala.tasty.reflect.Core { reflect: ReflectionImpl =>

Expand Down Expand Up @@ -48,4 +49,9 @@ trait PrintersImpl extends scala.tasty.reflect.Printers with scala.tasty.reflect
def showCode(implicit ctx: Context): String = showSourceCode.showSymbol(symbol)
}

/** Adds `show` as an extension method of a `Flags` */
implicit def FlagsShowDeco(flags: Flags): ShowAPI = new ShowAPI {
def show(implicit ctx: Context): String = showExtractors.showFlags(flags)
def showCode(implicit ctx: Context): String = showSourceCode.showFlags(flags)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ReflectionImpl(val rootContext: Contexts.Context)
with CaseDefOpsImpl
with ConstantOpsImpl
with ContextOpsImpl
with FlagsOpsImpl
with IdOpsImpl
with ImportSelectorOpsImpl
with QuotedOpsImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl {

def SymbolDeco(symbol: Symbol): SymbolAPI = new SymbolAPI {

def flags(implicit ctx: Context): FlagSet = new FlagSet(symbol.flags)
def flags(implicit ctx: Context): Flags = symbol.flags

def privateWithin(implicit ctx: Context): Option[Type] = {
val within = symbol.privateWithin
Expand Down
1 change: 1 addition & 0 deletions library/src/scala/tasty/Reflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ abstract class Reflection
with CaseDefOps
with ConstantOps
with ContextOps
with FlagsOps
with IdOps
with ImportSelectorOps
with QuotedOps
Expand Down
4 changes: 4 additions & 0 deletions library/src/scala/tasty/reflect/Core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ package scala.tasty.reflect
* +- BindSymbol
* +- NoSymbol
*
* +- Flags
*
* Aliases:
* # TermOrTypeTree = Term | TypeTree
*
Expand Down Expand Up @@ -445,4 +447,6 @@ trait Core {
/** No symbol available. */
type NoSymbol <: Symbol

/** FlagSet of a Symbol */
type Flags
}
85 changes: 0 additions & 85 deletions library/src/scala/tasty/reflect/FlagSet.scala

This file was deleted.

99 changes: 99 additions & 0 deletions library/src/scala/tasty/reflect/FlagsOps.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package scala.tasty.reflect

trait FlagsOps extends Core {

trait FlagsAPI {
/** Is the given flag set a subset of this flag sets */
def is(flagSet: Flags): Boolean
/** Union of the two flag sets */
def |(flagSet: Flags): Flags
/** Intersection of the two flag sets */
def &(flagSet: Flags): Flags
}
implicit def FlagsDeco(flagSet: Flags): FlagsAPI

val Flags: FlagsModule
abstract class FlagsModule {
/** Is this symbol `protected` */
def Protected: Flags

/** Is this symbol `abstract` */
def Abstract: Flags

/** Is this symbol `final` */
def Final: Flags

/** Is this symbol `sealed` */
def Sealed: Flags

/** Is this symbol `case` */
def Case: Flags

/** Is this symbol `implicit` */
def Implicit: Flags

/** Is this symbol `erased` */
def Erased: Flags

/** Is this symbol `lazy` */
def Lazy: Flags

/** Is this symbol `override` */
def Override: Flags

/** Is this symbol `inline` */
def Inline: Flags

/** Is this symbol markes as a macro. An inline method containing toplevel splices */
def Macro: Flags

/** Is this symbol marked as static. Mapped to static Java member */
def Static: Flags

/** Is this symbol an object or its class (used for a ValDef or a ClassDef extends Modifier respectively) */
def Object: Flags

/** Is this symbol a trait */
def Trait: Flags

/** Is this symbol local? Used in conjunction with Private/private[Type] to mean private[this] extends Modifier proctected[this] */
def Local: Flags

/** Was this symbol generated by Scala compiler */
def Synthetic: Flags

/** Is this symbol to be tagged Java Synthetic */
def Artifact: Flags

/** Is this symbol a `var` (when used on a ValDef) */
def Mutable: Flags

/** Is this symbol a getter or a setter */
def FieldAccessor: Flags

/** Is this symbol a getter for case class parameter */
def CaseAcessor: Flags

/** Is this symbol a type parameter marked as covariant `+` */
def Covariant: Flags

/** Is this symbol a type parameter marked as contravariant `-` */
def Contravariant: Flags

/** Was this symbol imported from Scala2.x */
def Scala2X: Flags

/** Is this symbol a method with default parameters */
def DefaultParameterized: Flags

/** Is this symbol member that is assumed to be stable */
def Stable: Flags

/** Is this symbol a parameter */
def Param: Flags

/** Is this symbol a parameter accessor */
def ParamAccessor: Flags
}

}
Loading