@@ -132,6 +132,13 @@ object NameKinds {
132
132
case DerivedTermName (underlying, info : this .NumberedInfo ) => Some ((underlying, info.num))
133
133
case _ => None
134
134
}
135
+ protected def skipSeparatorAndNum (name : SimpleTermName , separator : String ): Int = {
136
+ var i = name.length
137
+ while (i > 0 && name(i - 1 ).isDigit) i -= 1
138
+ if (i > separator.length && i < name.length &&
139
+ name.slice(i - separator.length, i).toString == separator) i
140
+ else - 1
141
+ }
135
142
}
136
143
137
144
case class UniqueNameKind (val separator : String )
@@ -205,6 +212,18 @@ object NameKinds {
205
212
val SkolemName = new UniqueNameKind (" ?" )
206
213
val LiftedTreeName = new UniqueNameKind (" liftedTree" )
207
214
215
+ val UniqueExtMethName = new UniqueNameKind (" $extension" ) {
216
+ override def unmangle (name : SimpleTermName ): TermName = {
217
+ val i = skipSeparatorAndNum(name, separator)
218
+ if (i > 0 ) {
219
+ val index = name.drop(i).toString.toInt
220
+ var original = name.take(i - separator.length).asTermName
221
+ apply(original, index)
222
+ }
223
+ else name
224
+ }
225
+ }
226
+
208
227
val PatMatStdBinderName = new UniqueNameKind (" x" )
209
228
val PatMatPiName = new UniqueNameKind (" pi" ) // FIXME: explain what this is
210
229
val PatMatPName = new UniqueNameKind (" p" ) // FIXME: explain what this is
@@ -218,15 +237,12 @@ object NameKinds {
218
237
val prefix = if (underlying.isConstructorName) nme.DEFAULT_GETTER_INIT else underlying
219
238
prefix.toString + str.DEFAULT_GETTER + (info.num + 1 )
220
239
}
221
-
222
- private val dgLen = str.DEFAULT_GETTER .length
223
-
240
+ // TODO: Reduce code duplication with UniqueExtMethName
224
241
override def unmangle (name : SimpleTermName ): TermName = {
225
- var i = name.length
226
- while (i > 0 && name(i - 1 ).isDigit) i -= 1
227
- if (i > dgLen && i < name.length && name.slice(i - dgLen, i) == nme.DEFAULT_GETTER ) {
242
+ val i = skipSeparatorAndNum(name, str.DEFAULT_GETTER )
243
+ if (i > 0 ) {
228
244
val index = name.drop(i).toString.toInt - 1
229
- var original = name.take(i - dgLen ).asTermName
245
+ var original = name.take(i - str. DEFAULT_GETTER .length ).asTermName
230
246
if (original == nme.DEFAULT_GETTER_INIT ) original = Names .CONSTRUCTOR
231
247
apply(original, index)
232
248
}
@@ -260,6 +276,7 @@ object NameKinds {
260
276
val AvoidClashName = new SuffixNameKind (AVOIDCLASH , " $_avoid_name_clash_$" )
261
277
val DirectName = new SuffixNameKind (DIRECT , " $direct" )
262
278
val FieldName = new SuffixNameKind (FIELD , " $$local" )
279
+ val ExtMethName = new SuffixNameKind (EXTMETH , " $extension" )
263
280
val ModuleVarName = new SuffixNameKind (OBJECTVAR , " $module" )
264
281
val ModuleClassName = new SuffixNameKind (OBJECTCLASS , " $" , optInfoString = " ModuleClass" )
265
282
@@ -283,7 +300,7 @@ object NameKinds {
283
300
}
284
301
285
302
val Scala2MethodNameKinds : List [NameKind ] =
286
- List (DefaultGetterName , ProtectedAccessorName , ProtectedSetterName )
303
+ List (DefaultGetterName , ExtMethName , UniqueExtMethName , ProtectedAccessorName , ProtectedSetterName )
287
304
288
305
def simpleNameKindOfTag : collection.Map [Int , ClassifiedNameKind ] = simpleNameKinds
289
306
def qualifiedNameKindOfTag : collection.Map [Int , QualifiedNameKind ] = qualifiedNameKinds
0 commit comments