Skip to content

Commit b058c90

Browse files
committed
*** empty log message ***
1 parent b6f8d5a commit b058c90

19 files changed

+1063
-368
lines changed

sources/scala/tools/nsc/Global.scala

Lines changed: 460 additions & 0 deletions
Large diffs are not rendered by default.

sources/scala/tools/nsc/ast/TreeGen.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ abstract class TreeGen {
9696
result
9797
}
9898

99-
10099
/** Builds an instance test with given value and type. */
101100
def mkIsInstanceOf(value: Tree, tpe: Type, erased: Boolean): Tree = {
102101
val sym =

sources/scala/tools/nsc/symtab/Flags.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ object Flags {
5656

5757
final val IS_ERROR = 0x100000000l; // symbol is an error symbol
5858
final val OVERLOADED = 0x200000000l; // symbol is overloaded
59-
final val FLATTENED = 0x400000000l; // class has been lifted out to package level
59+
final val LIFTED = 0x400000000l; // class has been lifted out to package level
60+
// local value has been lifted out to class level
6061
final val MIXEDIN = 0x800000000l; // member has been mixed in
6162

6263
final val EXPANDEDNAME = 0x1000000000l; // name has been expanded with class suffix
@@ -79,7 +80,11 @@ object Flags {
7980
final val lateFINAL = (FINAL: long) << LateShift;
8081
final val notPRIVATE = (PRIVATE: long) << AntiShift;
8182
final val notPROTECTED = (PROTECTED: long) << AntiShift;
82-
final val notFINAL = (FINAL: long) << AntiShift;
83+
final val notABSTRACT = (ABSTRACT: long) << AntiShift;
84+
final val notOVERRIDE = (OVERRIDE: long) << AntiShift;
85+
86+
final val STATICMODULE = lateMODULE;
87+
final val STATICMEMBER = notOVERRIDE;
8388

8489
// masks
8590
/** This flags can be set when class or module symbol is first created. */
@@ -115,11 +120,14 @@ object Flags {
115120
else if (flag == INTERFACE) "<interface>"
116121
else if (flag == IS_ERROR) "<is-error>"
117122
else if (flag == OVERLOADED) "<overloaded>"
123+
else if (flag == LIFTED) "<lifted>"
118124
else if (flag == TRANS_FLAG) "<trans-flag>"
119125
else if (flag == MIXEDIN) "<mixedin>"
120126
else if (flag == EXPANDEDNAME) "<expandedname>"
121127
else if (flag == INITIALIZED) "<initialized>"
122128
else if (flag == LOCKED) "<locked>"
129+
else if (flag == STATICMODULE) "<staticobject>"
130+
else if (flag == STATICMEMBER) "<staticmember>"
123131
else flag.asInstanceOf[int] match {
124132
case IMPLICIT => "implicit"
125133
case FINAL => "final"

sources/scala/tools/nsc/symtab/Names.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ class Names {
203203
*/
204204
final def lastPos(c: char): int = lastPos(c, len - 1);
205205

206+
final def lastPos(s: String): int = lastPos(s, len - s.length());
207+
206208
/** return the index of last occurrence of char c in this name from `start',
207209
* -1 if not found
208210
*/
@@ -212,6 +214,22 @@ class Names {
212214
i
213215
}
214216

217+
/** return the index of last occurrence of string s in this name from `start',
218+
* -1 if not found
219+
*/
220+
final def lastPos(s: String, start: int): int = {
221+
var i = lastPos(s.charAt(0), start);
222+
while (i >= 0) {
223+
var j = 1;
224+
while (s.charAt(j) == chrs(index + i + j)) {
225+
j = j + 1;
226+
if (j == s.length()) return i;
227+
}
228+
i = lastPos(s.charAt(0), i - 1)
229+
}
230+
-s.length()
231+
}
232+
215233
/** does this name start with prefix?
216234
*/
217235
final def startsWith(prefix: Name): boolean = startsWith(prefix, 0);

sources/scala/tools/nsc/symtab/StdNames.scala

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,56 +62,72 @@ abstract class StdNames: SymbolTable {
6262
val HASHkw = newTermName("#");
6363
val ATkw = newTermName("@");
6464

65-
private val LOCAL_PREFIX_STRING = "local$";
66-
private val MIXIN_PREFIX_STRING = "mixin$";
67-
private val SUPER_PREFIX_STRING = "super$";
68-
private val ACCESS_PREFIX_STRING = "access$";
69-
private val TUPLE_FIELD_PREFIX_STRING = "_";
70-
private val TYPE_PREFIX_STRING = "type$";
71-
72-
val LOCAL_PREFIX = newTermName(LOCAL_PREFIX_STRING);
73-
74-
def LOCAL(clazz: Symbol) = newTermName(LOCAL_PREFIX_STRING + clazz.name);
65+
val LOCALDUMMY_PREFIX_STRING = "local$";
66+
val SUPER_PREFIX_STRING = "super$";
67+
val EXPAND_SEPARATOR_STRING = "$$";
68+
val TUPLE_FIELD_PREFIX_STRING = "_";
7569

70+
def LOCAL(clazz: Symbol) = newTermName(LOCALDUMMY_PREFIX_STRING + clazz.name);
7671
def TUPLE_FIELD(index: int) = newTermName(TUPLE_FIELD_PREFIX_STRING + index);
7772

78-
def isLocalName(name: Name) = originalName(name).endsWith(LOCAL_SUFFIX);
79-
def isSetterName(name: Name) = originalName(name).endsWith(_EQ);
73+
val LOCAL_SUFFIX = newTermName(" ");
74+
val SETTER_SUFFIX = encode("_=");
75+
val IMPL_CLASS_SUFFIX = newTermName("$class");
76+
val MODULE_SUFFIX = newTermName("$module");
77+
val LOCALDUMMY_PREFIX = newTermName(LOCALDUMMY_PREFIX_STRING);
8078

81-
def originalName(name: Name) = name.subName(0, name.pos("$$"));
79+
def isLocalName(name: Name) = name.endsWith(LOCAL_SUFFIX);
80+
def isSetterName(name: Name) = name.endsWith(SETTER_SUFFIX);
81+
def isLocalDummyName(name: Name) = name.startsWith(LOCALDUMMY_PREFIX);
8282

83-
private def applyToOriginal(name: Name, f: Name => Name): Name = {
84-
val oname = originalName(name);
85-
if (oname == name) f(name)
86-
else newTermName(f(oname).toString() + name.subName(oname.length, name.length))
83+
// def originalName(name: Name): Name = {
84+
def originalName(name: Name): Name = {
85+
var i = name.length;
86+
while (i >= 2 && !(name(i - 1) == '$' && name(i - 2) == '$')) i = i - 1;
87+
if (i >= 2) {
88+
while (i >= 3 && name(i - 3) == '$') i = i - 1;
89+
name.subName(i, name.length)
90+
} else name
8791
}
92+
// val result = originalName(name);
93+
// System.out.println("oroginal " + name + " = " + result);
94+
// result
95+
// }
8896

8997
def localToGetter(name: Name): Name = {
9098
assert(isLocalName(name));//debug
91-
applyToOriginal(name, oname => oname.subName(0, oname.length - LOCAL_SUFFIX.length));
99+
name.subName(0, name.length - LOCAL_SUFFIX.length);
92100
}
93101

94102
def getterToLocal(name: Name): Name = {
95103
assert(!isLocalName(name) && !isSetterName(name));//debug
96-
applyToOriginal(name, oname => newTermName(oname.toString() + LOCAL_SUFFIX));
104+
newTermName(name.toString() + LOCAL_SUFFIX);
97105
}
98106

99107
def getterToSetter(name: Name): Name = {
100108
assert(!isLocalName(name) && !isSetterName(name));//debug
101-
applyToOriginal(name, oname => newTermName(oname.toString() + SETTER_SUFFIX));
109+
newTermName(name.toString() + SETTER_SUFFIX);
102110
}
103111

104112
def setterToGetter(name: Name): Name = {
105-
assert(isSetterName(name));//debug
106-
applyToOriginal(name, oname => oname.subName(0, oname.length - SETTER_SUFFIX.length));
113+
name.subName(0, name.length - SETTER_SUFFIX.length);
107114
}
108115

109116
def getterName(name: Name): Name =
110117
if (isLocalName(name)) localToGetter(name) else name;
111118

119+
def isImplClassName(name: Name): boolean =
120+
name endsWith IMPL_CLASS_SUFFIX;
121+
112122
def implClassName(name: Name): Name =
113123
newTypeName(name.toString() + IMPL_CLASS_SUFFIX);
114124

125+
def moduleVarName(name: Name): Name =
126+
newTermName(name.toString() + MODULE_SUFFIX);
127+
128+
def isModuleVarName(name: Name): boolean =
129+
name.endsWith(MODULE_SUFFIX); //todo handle also local modules
130+
115131
def superName(name: Name) = newTermName("super$" + name);
116132

117133
val ERROR = newTermName("<error>");
@@ -133,14 +149,13 @@ abstract class StdNames: SymbolTable {
133149
val ROOT = newTermName("<root>");
134150
val REPEATED_PARAM_CLASS_NAME = newTermName("<repeated>");
135151
val BYNAME_PARAM_CLASS_NAME = newTermName("<byname>");
136-
val SELF = newTermName("$self");
152+
val SELF = newTermName("$this");
137153

138154
val CONSTRUCTOR = newTermName("<init>");
139155
val MIXIN_CONSTRUCTOR = newTermName("$init$");
140156
val INITIALIZER = newTermName("<init>");
141157
val INLINED_INITIALIZER = newTermName("$init$");
142158

143-
val _EQ = encode("_=");
144159
val MINUS = encode("-");
145160
val PLUS = encode("+");
146161
val TILDE = encode("~");
@@ -291,10 +306,6 @@ abstract class StdNames: SymbolTable {
291306
val JacoMetaATTR = newTermName("JacoMeta");
292307
val ScalaSignatureATTR = newTermName("ScalaSignature");
293308
val JavaInterfaceATTR = newTermName("JacoInterface");
294-
295-
val LOCAL_SUFFIX = newTermName(" ");
296-
val SETTER_SUFFIX = _EQ;
297-
val IMPL_CLASS_SUFFIX = newTermName("$class");
298309
}
299310

300311
def encode(str: String): Name = newTermName(NameTransformer.encode(str));

sources/scala/tools/nsc/symtab/Symbols.scala

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ abstract class Symbols: SymbolTable {
9797
def isClass = false; //to be overridden
9898

9999
final def isValue = isTerm && !(isModule && hasFlag(PACKAGE | JAVA));
100-
final def isVariable = isTerm && hasFlag(MUTABLE);
100+
final def isVariable = isTerm && hasFlag(MUTABLE) && !isMethod;
101+
final def isSetter = isTerm && hasFlag(ACCESSOR) && nme.isSetterName(name);
102+
//todo: make independent of name, as this can be forged.
101103
final def hasGetter = isTerm && nme.isLocalName(name);
102104
final def isValueParameter = isTerm && hasFlag(PARAM);
103-
final def isLocalDummy = isTerm && (name startsWith nme.LOCAL_PREFIX);
105+
final def isLocalDummy = isTerm && nme.isLocalDummyName(name);
104106
final def isMethod = isTerm && hasFlag(METHOD);
105107
final def isSourceMethod = isTerm && (flags & (METHOD | STABLE)) == METHOD;
106108
final def isLabel = isTerm && hasFlag(LABEL);
@@ -115,7 +117,8 @@ abstract class Symbols: SymbolTable {
115117
final def isAliasType = isType && !isClass && !hasFlag(DEFERRED);
116118
final def isAbstractType = isType && !isClass && hasFlag(DEFERRED);
117119
final def isTypeParameter = isType && hasFlag(PARAM);
118-
final def isAnonymousClass = isClass && (name startsWith nme.ANON_CLASS_NAME); // startsWith necessary because name may grow when lifted and also because of anonymous function classes
120+
final def isAnonymousClass = isClass && (originalName startsWith nme.ANON_CLASS_NAME);
121+
// startsWith necessary because name may grow when lifted and also because of anonymous function classes
119122
final def isRefinementClass = isClass && name == nme.REFINE_CLASS_NAME.toTypeName; // no lifting for refinement classes
120123
final def isModuleClass = isClass && hasFlag(MODULE);
121124
final def isPackageClass = isClass && hasFlag(PACKAGE);
@@ -133,8 +136,13 @@ abstract class Symbols: SymbolTable {
133136
isConstructor && owner.primaryConstructor == this;
134137

135138
/** Is this symbol an implementation class for a trait ? */
136-
final def isImplClass: boolean =
137-
name.endsWith(nme.IMPL_CLASS_SUFFIX);
139+
final def isImplClass: boolean = isClass && nme.isImplClassName(name);
140+
141+
final def needsImplClass: boolean =
142+
isTrait && (!hasFlag(INTERFACE) || hasFlag(lateINTERFACE)) && !isImplClass;
143+
144+
/** Is this symbol a module variable ? */
145+
final def isModuleVar: boolean = isVariable && nme.isModuleVarName(name);
138146

139147
/** Is this symbol static (i.e. with no outer instance)? */
140148
final def isStatic: boolean = hasFlag(STATIC) || isRoot || owner.isStaticOwner;
@@ -203,6 +211,8 @@ abstract class Symbols: SymbolTable {
203211
def name: Name = rawname;
204212
final def name_=(name: Name): unit = { rawname = name }
205213

214+
def originalName = nme.originalName(name);
215+
206216
final def flags = {
207217
val fs = rawflags & phase.flagMask;
208218
(fs | ((fs & LateFlags) >>> LateShift)) & ~(fs >>> AntiShift)
@@ -296,7 +306,7 @@ abstract class Symbols: SymbolTable {
296306
phase = current;
297307
limit = current;
298308
}
299-
assert(infos != null/*, name.toString() + " " + limit + " " + phase*/);
309+
assert(infos != null, name);
300310
infos.info
301311
} else {
302312
var infos = this.infos;
@@ -454,11 +464,11 @@ abstract class Symbols: SymbolTable {
454464
*/
455465
final def accessed: Symbol = {
456466
assert(hasFlag(ACCESSOR));
457-
//todo: make independent of name, as this can be forged.
458-
owner.info.decl(
459-
nme.getterToLocal(if (nme.isSetterName(name)) nme.setterToGetter(name) else name))
467+
owner.info.decl(nme.getterToLocal(if (isSetter) nme.setterToGetter(name) else name))
460468
}
461469

470+
final def implClass: Symbol = owner.info.decl(nme.implClassName(name));
471+
462472
/** For a paramaccessor: a superclass paramaccessor for which this symbol is
463473
* an alias, NoSymbol for all others */
464474
def alias: Symbol = NoSymbol;
@@ -492,6 +502,13 @@ abstract class Symbols: SymbolTable {
492502
owner.info.decl(name.toTermName).suchThat(sym => sym.rawInfo != NoType)
493503
else NoSymbol;
494504

505+
final def toInterface: Symbol =
506+
if (isImplClass) {
507+
val iface = tpe.parents.last.symbol;
508+
assert(nme.implClassName(iface.name) == name, this);
509+
iface
510+
} else this;
511+
495512
/** The module corresponding to this module class (note that this
496513
* is not updated when a module is cloned).
497514
*/
@@ -525,17 +542,13 @@ abstract class Symbols: SymbolTable {
525542
sym
526543
}
527544

528-
/** The superaccessor for this symbol in the definition of `base'. */
529-
final def superAccessor(base: Symbol): Symbol =
530-
base.info.decl(nme.superName(name)) suchThat (.alias.==(this));
531-
532545
/** The getter of this value definition in class `base', or NoSymbol if none exists */
533546
final def getter(base: Symbol): Symbol =
534-
base.info.decl(nme.localToGetter(name)) filter (.hasFlag(ACCESSOR));
547+
base.info.decl(nme.getterName(name)) filter (.hasFlag(ACCESSOR));
535548

536549
/** The setter of this value definition, or NoSymbol if none exists */
537550
final def setter(base: Symbol): Symbol =
538-
base.info.decl(nme.getterToSetter(nme.localToGetter(name))) filter (.hasFlag(ACCESSOR));
551+
base.info.decl(nme.getterToSetter(nme.getterName(name))) filter (.hasFlag(ACCESSOR));
539552

540553
/** Remove private modifier from symbol `sym's definition. If `sym' is a
541554
* term symbol rename it by expanding its name to avoid name clashes
@@ -559,9 +572,12 @@ abstract class Symbols: SymbolTable {
559572
getter(owner).expandName(base);
560573
setter(owner).expandName(base);
561574
}
562-
name = newTermName(name.toString() + "$$" + base.fullNameString('$'))
575+
name = base.expandedName(name)
563576
}
564577

578+
def expandedName(name: Name): Name =
579+
newTermName(fullNameString('$') + nme.EXPAND_SEPARATOR_STRING + name);
580+
565581
/*
566582
def referenced: Symbol =
567583
throw new Error("referenced inapplicable for " + this);
@@ -709,9 +725,10 @@ abstract class Symbols: SymbolTable {
709725
}
710726

711727
override def alias: Symbol =
712-
if (hasFlag(SUPERACCESSOR | PARAMACCESSOR)) referenced else NoSymbol;
728+
if (hasFlag(SUPERACCESSOR | PARAMACCESSOR | MIXEDIN)) initialize.referenced else NoSymbol;
713729

714730
def setAlias(alias: Symbol): TermSymbol = {
731+
assert(alias != NoSymbol);
715732
assert(hasFlag(SUPERACCESSOR | PARAMACCESSOR | MIXEDIN));
716733
referenced = alias;
717734
this
@@ -738,12 +755,14 @@ abstract class Symbols: SymbolTable {
738755
override def tpe: Type = {
739756
assert(tpeCache != NoType, this);
740757
if (tpePhase != phase) {
741-
if (isValid(tpePhase)) tpePhase = phase
742-
else {
758+
if (isValid(tpePhase)) {
759+
tpePhase = phase
760+
} else {
743761
if (hasFlag(INITIALIZED)) tpePhase = phase;
744762
tpeCache = NoType;
745-
tpeCache = typeRef(if (isTypeParameter) NoPrefix else owner.thisType,
746-
this, unsafeTypeParams map (.tpe))
763+
val targs = if (phase.erasedTypes && this != ArrayClass) List()
764+
else unsafeTypeParams map (.tpe);
765+
tpeCache = typeRef(if (isTypeParameter) NoPrefix else owner.thisType, this, targs)
747766
}
748767
}
749768
assert(tpeCache != null/*, "" + this + " " + phase*/);//debug
@@ -803,12 +822,11 @@ abstract class Symbols: SymbolTable {
803822
val p = thisTypePhase;
804823
if (p != phase) {
805824
thisTypePhase = phase;
806-
if (!isValid(p)) {
825+
if (!(isValid(p) /*||
826+
thisTypePhase != null && thisTypePhase.erasedTypes && phase.erasedTypes*/)) {
807827
thisTypeCache =
808-
if (isModuleClass && !isRoot && !phase.erasedTypes) {
809-
assert(sourceModule != NoSymbol, this);
810-
singleType(owner.thisType, sourceModule);
811-
}
828+
if (isModuleClass && !isRoot && !phase.erasedTypes)
829+
singleType(owner.thisType, sourceModule);
812830
else ThisType(this);
813831
}
814832
}

0 commit comments

Comments
 (0)