Skip to content

Commit bbf98ac

Browse files
Merge pull request #5670 from dotty-staging/tasty-add-flag-constryctors
Tasty add flag constructors
2 parents 3a457fa + ce80f0f commit bbf98ac

File tree

14 files changed

+272
-188
lines changed

14 files changed

+272
-188
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/CoreImpl.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,6 @@ trait CoreImpl extends scala.tasty.reflect.Core {
127127
type BindSymbol = core.Symbols.TermSymbol
128128
type ValSymbol = core.Symbols.TermSymbol
129129
type NoSymbol = core.Symbols.NoSymbol.type
130+
131+
type Flags = core.Flags.FlagSet
130132
}

compiler/src/dotty/tools/dotc/tastyreflect/FlagSet.scala

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package dotty.tools.dotc
2+
package tastyreflect
3+
4+
import dotty.tools.dotc.core.Decorators._
5+
6+
import scala.tasty.reflect
7+
8+
trait FlagsOpsImpl extends scala.tasty.reflect.FlagsOps with CoreImpl {
9+
10+
def FlagsDeco(flagSet: Flags): FlagsAPI = new FlagsAPI {
11+
def is(that: Flags): Boolean = flagSet is that
12+
def |(that: Flags): Flags = flagSet | that
13+
def &(that: Flags): Flags = flagSet & that
14+
}
15+
16+
object Flags extends FlagsModule {
17+
def Private: Flags = core.Flags.Private
18+
def Protected: Flags = core.Flags.Protected
19+
def Abstract: Flags = core.Flags.Abstract
20+
def Final: Flags = core.Flags.Final
21+
def Sealed: Flags = core.Flags.Sealed
22+
def Case: Flags = core.Flags.Case
23+
def Implicit: Flags = core.Flags.Implicit
24+
def Erased: Flags = core.Flags.Erased
25+
def Lazy: Flags = core.Flags.Lazy
26+
def Override: Flags = core.Flags.Override
27+
def Inline: Flags = core.Flags.Inline
28+
def Macro: Flags = core.Flags.Macro
29+
def Static: Flags = core.Flags.JavaStatic
30+
def Object: Flags = core.Flags.Module
31+
def Trait: Flags = core.Flags.Trait
32+
def Local: Flags = core.Flags.Local
33+
def Synthetic: Flags = core.Flags.Synthetic
34+
def Artifact: Flags = core.Flags.Artifact
35+
def Mutable: Flags = core.Flags.Mutable
36+
def FieldAccessor: Flags = core.Flags.Accessor
37+
def CaseAcessor: Flags = core.Flags.CaseAccessor
38+
def Covariant: Flags = core.Flags.Covariant
39+
def Contravariant: Flags = core.Flags.Contravariant
40+
def Scala2X: Flags = core.Flags.Scala2x
41+
def DefaultParameterized: Flags = core.Flags.DefaultParameterized
42+
def Stable: Flags = core.Flags.Stable
43+
def Param: Flags = core.Flags.Param
44+
def ParamAccessor: Flags = core.Flags.ParamAccessor
45+
}
46+
47+
}

compiler/src/dotty/tools/dotc/tastyreflect/PrintersImpl.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package dotty.tools.dotc.tastyreflect
2+
import dotty.tools.dotc.core.Flags
23

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

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

52+
/** Adds `show` as an extension method of a `Flags` */
53+
implicit def FlagsShowDeco(flags: Flags): ShowAPI = new ShowAPI {
54+
def show(implicit ctx: Context): String = showExtractors.showFlags(flags)
55+
def showCode(implicit ctx: Context): String = showSourceCode.showFlags(flags)
56+
}
5157
}

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ReflectionImpl(val rootContext: Contexts.Context)
88
with CaseDefOpsImpl
99
with ConstantOpsImpl
1010
with ContextOpsImpl
11+
with FlagsOpsImpl
1112
with IdOpsImpl
1213
with ImportSelectorOpsImpl
1314
with QuotedOpsImpl

compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl {
99

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

12-
def flags(implicit ctx: Context): FlagSet = new FlagSet(symbol.flags)
12+
def flags(implicit ctx: Context): Flags = symbol.flags
1313

1414
def privateWithin(implicit ctx: Context): Option[Type] = {
1515
val within = symbol.privateWithin

library/src/scala/tasty/Reflection.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ abstract class Reflection
77
with CaseDefOps
88
with ConstantOps
99
with ContextOps
10+
with FlagsOps
1011
with IdOps
1112
with ImportSelectorOps
1213
with QuotedOps

library/src/scala/tasty/reflect/Core.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ package scala.tasty.reflect
109109
* +- BindSymbol
110110
* +- NoSymbol
111111
*
112+
* +- Flags
113+
*
112114
* Aliases:
113115
* # TermOrTypeTree = Term | TypeTree
114116
*
@@ -445,4 +447,6 @@ trait Core {
445447
/** No symbol available. */
446448
type NoSymbol <: Symbol
447449

450+
/** FlagSet of a Symbol */
451+
type Flags
448452
}

library/src/scala/tasty/reflect/FlagSet.scala

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package scala.tasty.reflect
2+
3+
trait FlagsOps extends Core {
4+
5+
trait FlagsAPI {
6+
/** Is the given flag set a subset of this flag sets */
7+
def is(flagSet: Flags): Boolean
8+
/** Union of the two flag sets */
9+
def |(flagSet: Flags): Flags
10+
/** Intersection of the two flag sets */
11+
def &(flagSet: Flags): Flags
12+
}
13+
implicit def FlagsDeco(flagSet: Flags): FlagsAPI
14+
15+
val Flags: FlagsModule
16+
abstract class FlagsModule {
17+
18+
/** Is this symbol `private` */
19+
def Private: Flags
20+
21+
/** Is this symbol `protected` */
22+
def Protected: Flags
23+
24+
/** Is this symbol `abstract` */
25+
def Abstract: Flags
26+
27+
/** Is this symbol `final` */
28+
def Final: Flags
29+
30+
/** Is this symbol `sealed` */
31+
def Sealed: Flags
32+
33+
/** Is this symbol `case` */
34+
def Case: Flags
35+
36+
/** Is this symbol `implicit` */
37+
def Implicit: Flags
38+
39+
/** Is this symbol `erased` */
40+
def Erased: Flags
41+
42+
/** Is this symbol `lazy` */
43+
def Lazy: Flags
44+
45+
/** Is this symbol `override` */
46+
def Override: Flags
47+
48+
/** Is this symbol `inline` */
49+
def Inline: Flags
50+
51+
/** Is this symbol markes as a macro. An inline method containing toplevel splices */
52+
def Macro: Flags
53+
54+
/** Is this symbol marked as static. Mapped to static Java member */
55+
def Static: Flags
56+
57+
/** Is this symbol an object or its class (used for a ValDef or a ClassDef extends Modifier respectively) */
58+
def Object: Flags
59+
60+
/** Is this symbol a trait */
61+
def Trait: Flags
62+
63+
/** Is this symbol local? Used in conjunction with private/private[Type] to mean private[this] extends Modifier proctected[this] */
64+
def Local: Flags
65+
66+
/** Was this symbol generated by Scala compiler */
67+
def Synthetic: Flags
68+
69+
/** Is this symbol to be tagged Java Synthetic */
70+
def Artifact: Flags
71+
72+
/** Is this symbol a `var` (when used on a ValDef) */
73+
def Mutable: Flags
74+
75+
/** Is this symbol a getter or a setter */
76+
def FieldAccessor: Flags
77+
78+
/** Is this symbol a getter for case class parameter */
79+
def CaseAcessor: Flags
80+
81+
/** Is this symbol a type parameter marked as covariant `+` */
82+
def Covariant: Flags
83+
84+
/** Is this symbol a type parameter marked as contravariant `-` */
85+
def Contravariant: Flags
86+
87+
/** Was this symbol imported from Scala2.x */
88+
def Scala2X: Flags
89+
90+
/** Is this symbol a method with default parameters */
91+
def DefaultParameterized: Flags
92+
93+
/** Is this symbol member that is assumed to be stable */
94+
def Stable: Flags
95+
96+
/** Is this symbol a parameter */
97+
def Param: Flags
98+
99+
/** Is this symbol a parameter accessor */
100+
def ParamAccessor: Flags
101+
}
102+
103+
}

0 commit comments

Comments
 (0)