1
1
package dotty .tools .backend .sjs
2
2
3
+ import scala .annotation .tailrec
4
+
3
5
import scala .collection .mutable
4
6
5
7
import dotty .tools .FatalError
6
8
7
9
import dotty .tools .dotc .core ._
10
+ import Decorators ._
8
11
import Periods ._
9
12
import SymDenotations ._
10
13
import Contexts ._
14
+ import Flags ._
11
15
import Types ._
12
16
import Symbols ._
13
17
import Denotations ._
@@ -103,11 +107,17 @@ object JSEncoding {
103
107
js.Ident (localNames.localSymbolName(sym), Some (sym.unexpandedName.decoded))
104
108
}
105
109
110
+ private [this ] var allRefClassesCache : Set [Symbol ] = _
106
111
private def allRefClasses (implicit ctx : Context ): Set [Symbol ] = {
107
- // TODO
108
- /* (Set(ObjectRefClass, VolatileObjectRefClass) ++
109
- refClass.values ++ volatileRefClass.values)*/
110
- Set ()
112
+ if (allRefClassesCache == null ) {
113
+ val baseNames = List (" Object" , " Boolean" , " Character" , " Byte" , " Short" ,
114
+ " Int" , " Long" , " Float" , " Double" )
115
+ val fullNames = baseNames.flatMap { base =>
116
+ List (s " scala.runtime. ${base}Ref " , s " scala.runtime.Volatile ${base}Ref " )
117
+ }
118
+ allRefClassesCache = fullNames.map(name => ctx.requiredClass(name)).toSet
119
+ }
120
+ allRefClassesCache
111
121
}
112
122
113
123
def encodeFieldSym (sym : Symbol )(
@@ -120,14 +130,19 @@ object JSEncoding {
120
130
if (name0.charAt(name0.length()- 1 ) != ' ' ) name0
121
131
else name0.substring(0 , name0.length()- 1 )
122
132
133
+ @ tailrec
134
+ def superClassCount (sym : Symbol , acc : Int ): Int =
135
+ if (sym == defn.ObjectClass ) acc
136
+ else superClassCount(sym.asClass.superClass, acc + 1 )
137
+
123
138
/* We have to special-case fields of Ref types (IntRef, ObjectRef, etc.)
124
139
* because they are emitted as private by our .scala source files, but
125
140
* they are considered public at use site since their symbols come from
126
141
* Java-emitted .class files.
127
142
*/
128
143
val idSuffix =
129
144
if (sym.is(Flags .Private ) || allRefClasses.contains(sym.owner))
130
- sym.owner.asClass.baseClasses.size .toString
145
+ superClassCount( sym.owner, 0 ) .toString
131
146
else
132
147
" f"
133
148
0 commit comments