diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-01-27 14:22:28 +0300 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-02-12 14:50:16 +0100 |
commit | 1af8dcb22b36cf256eef0615e2f3a7005ee21e68 (patch) | |
tree | b24a5df981b9917fc7801423bae92dbd513b4518 | |
parent | 98320a6d5947f26e7252b025cf56a0763b39cd07 (diff) | |
download | scala-1af8dcb22b36cf256eef0615e2f3a7005ee21e68.tar.gz scala-1af8dcb22b36cf256eef0615e2f3a7005ee21e68.tar.bz2 scala-1af8dcb22b36cf256eef0615e2f3a7005ee21e68.zip |
SI-6565 Adds missing flag values to reflection API
Among the flags requested by our users, the most popular are definitely
PARAMACCESSOR and CASEACCESSOR. Among other things that are missing in
2.10.x are SYNTHETIC and its close friend ARTIFACT. Apparently, SYNTHETIC
was was added somewhen during the 2.11.0-M* development cycle, so I only
has to introduce ARTIFACT.
There was also METHOD as requested by Paul in https://github.com/xeno-by/declosurify/blob/ce6c55b04086c755102227dd8124b0bf0dac46e1/src/main/scala/macros.scala#L102,
but the absence of that one is compensated by the fact that it’s only needed
when manually creating symbols, and for that we already have Symbol.newMethodSymbol.
This doesn't remove the necessity to see SI-6267 through (read the recently
updated issue description for more information!), but that'd be a significant
change, so let's delay it until better times.
-rw-r--r-- | src/reflect/scala/reflect/api/FlagSets.scala | 76 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/FlagSets.scala | 5 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Flags.scala | 14 |
3 files changed, 78 insertions, 17 deletions
diff --git a/src/reflect/scala/reflect/api/FlagSets.scala b/src/reflect/scala/reflect/api/FlagSets.scala index 54b65166d8..44c5f78a48 100644 --- a/src/reflect/scala/reflect/api/FlagSets.scala +++ b/src/reflect/scala/reflect/api/FlagSets.scala @@ -167,9 +167,6 @@ trait FlagSets { self: Universe => /** Flag indicating that tree represents a variable or a member initialized to the default value */ val DEFAULTINIT: FlagSet - /** Flag indicating that tree was generated by the compiler */ - val SYNTHETIC: FlagSet - /** Flag indicating that tree represents an enum. * * It can only appear at @@ -177,6 +174,79 @@ trait FlagSets { self: Universe => * - enum constants **/ val ENUM: FlagSet + + /** Flag indicating that tree represents a parameter of the primary constructor of some class + * or a synthetic member underlying thereof: + * + * 13:57 ~$ parse 'class C(val x: Int)' + * [[syntax trees at end of parser]]// Scala source: tmposDU52 + * class C extends scala.AnyRef { + * <paramaccessor> val x: Int = _; + * def <init>(x: Int) = { + * super.<init>(); + * () + * } + * } + * ClassDef( + * Modifiers(), TypeName("C"), List(), + * Template( + * List(Select(Ident(scala), TypeName("AnyRef"))), + * noSelfType, + * List( + * ValDef(Modifiers(PARAMACCESSOR), TermName("x"), Ident(TypeName("Int")), EmptyTree), + * DefDef( + * Modifiers(), nme.CONSTRUCTOR, List(), + * List(List(ValDef(Modifiers(PARAM | PARAMACCESSOR), TermName("x"), Ident(TypeName("Int")), EmptyTree))), TypeTree(), + * Block(List(pendingSuperCall), Literal(Constant(()))))))))) + */ + val PARAMACCESSOR: FlagSet + + /** Flag indicating that tree represents a parameter of the primary constructor of some case class + * or a synthetic member underlying thereof: + * + * 13:58 ~$ parse 'case class C(val x: Int)' + * [[syntax trees at end of parser]]// Scala source: tmpnHkJ3y + * case class C extends scala.Product with scala.Serializable { + * <caseaccessor> <paramaccessor> val x: Int = _; + * def <init>(x: Int) = { + * super.<init>(); + * () + * } + * } + * ClassDef( + * Modifiers(CASE), TypeName("C"), List(), + * Template( + * List(Select(Ident(scala), TypeName("Product")), Select(Ident(scala), TypeName("Serializable"))), + * noSelfType, + * List( + * ValDef(Modifiers(CASEACCESSOR | PARAMACCESSOR), TermName("x"), Ident(TypeName("Int")), EmptyTree), + * DefDef( + * Modifiers(), nme.CONSTRUCTOR, List(), + * List(List(ValDef(Modifiers(PARAM | PARAMACCESSOR), TermName("x"), Ident(TypeName("Int")), EmptyTree))), TypeTree(), + * Block(List(pendingSuperCall), Literal(Constant(()))))))))) + */ + val CASEACCESSOR: FlagSet + + /** Flag used to distinguish programmatically generated definitions from user-written ones. + * @see ARTIFACT + */ + val SYNTHETIC: FlagSet + + /** Flag used to distinguish platform-specific implementation details. + * Trees and symbols which are currently marked ARTIFACT by scalac: + * * $outer fields and accessors + * * super accessors + * * protected accessors + * * lazy local accessors + * * bridge methods + * * default argument getters + * * evaluation-order preserving locals for right-associative and out-of-order named arguments + * * catch-expression storing vals + * * anything else which feels a setFlag(ARTIFACT) + * + * @see SYNTHETIC + */ + val ARTIFACT: FlagSet } /** The empty set of flags diff --git a/src/reflect/scala/reflect/internal/FlagSets.scala b/src/reflect/scala/reflect/internal/FlagSets.scala index 799f85054a..bc6a8ec01f 100644 --- a/src/reflect/scala/reflect/internal/FlagSets.scala +++ b/src/reflect/scala/reflect/internal/FlagSets.scala @@ -42,7 +42,10 @@ trait FlagSets extends api.FlagSets { self: SymbolTable => val DEFAULTPARAM : FlagSet = Flags.DEFAULTPARAM val PRESUPER : FlagSet = Flags.PRESUPER val DEFAULTINIT : FlagSet = Flags.DEFAULTINIT - val SYNTHETIC : FlagSet = Flags.SYNTHETIC val ENUM : FlagSet = Flags.ENUM + val PARAMACCESSOR : FlagSet = Flags.PARAMACCESSOR + val CASEACCESSOR : FlagSet = Flags.CASEACCESSOR + val SYNTHETIC : FlagSet = Flags.SYNTHETIC + val ARTIFACT : FlagSet = Flags.ARTIFACT } } diff --git a/src/reflect/scala/reflect/internal/Flags.scala b/src/reflect/scala/reflect/internal/Flags.scala index e66ed9a3d4..1707061817 100644 --- a/src/reflect/scala/reflect/internal/Flags.scala +++ b/src/reflect/scala/reflect/internal/Flags.scala @@ -118,22 +118,10 @@ class ModifierFlags { final val PRESUPER = 1L << 37 // value is evaluated before super call final val DEFAULTINIT = 1L << 41 // symbol is initialized to the default value: used by -Xcheckinit final val ARTIFACT = 1L << 46 // symbol should be ignored when typechecking; will be marked ACC_SYNTHETIC in bytecode + // to see which symbols are marked as ARTIFACT, see scaladocs for FlagValues.ARTIFACT final val DEFAULTMETHOD = 1L << 47 // symbol is a java default method final val ENUM = 1L << 48 // symbol is an enum - /** Symbols which are marked ARTIFACT. (Expand this list?) - * - * - $outer fields and accessors - * - super accessors - * - protected accessors - * - lazy local accessors - * - bridge methods - * - default argument getters - * - evaluation-order preserving locals for right-associative and out-of-order named arguments - * - catch-expression storing vals - * - anything else which feels a setFlag(ARTIFACT) - */ - // Overridden. def flagToString(flag: Long): String = "" |