summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2008-02-06 13:55:18 +0000
committerMartin Odersky <odersky@gmail.com>2008-02-06 13:55:18 +0000
commit1021800b39ed89c2269bd3722aa4522d038c5c19 (patch)
tree6018fd0e88e7d05629b8f73c1c3298782275d92a /src
parentdf55a8175a90180194c61f91592a5e34b0bcf2e5 (diff)
downloadscala-1021800b39ed89c2269bd3722aa4522d038c5c19.tar.gz
scala-1021800b39ed89c2269bd3722aa4522d038c5c19.tar.bz2
scala-1021800b39ed89c2269bd3722aa4522d038c5c19.zip
added reverse to RichString.
fixed immediate problem in #409. we ignore now flag MONOMOPRHIC.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala2
-rw-r--r--src/compiler/scala/tools/nsc/SubComponent.scala3
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Flags.scala2
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala41
-rw-r--r--src/compiler/scala/tools/nsc/util/SourceFile.scala4
-rw-r--r--src/library/scala/runtime/RichString.scala10
6 files changed, 45 insertions, 17 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 5adc669fb3..493c39dd15 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -234,8 +234,6 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
def apply(unit: CompilationUnit): Unit
- private val isDevirtualized = prev.name == "devirtualize" || prev.devirtualized
- override def devirtualized = isDevirtualized
private val isErased = prev.name == "erasure" || prev.erasedTypes
override def erasedTypes: Boolean = isErased
private val isFlat = prev.name == "flatten" || prev.flatClasses
diff --git a/src/compiler/scala/tools/nsc/SubComponent.scala b/src/compiler/scala/tools/nsc/SubComponent.scala
index f3868e91ff..e683e7072d 100644
--- a/src/compiler/scala/tools/nsc/SubComponent.scala
+++ b/src/compiler/scala/tools/nsc/SubComponent.scala
@@ -24,6 +24,9 @@ abstract class SubComponent {
/** The phase factory */
def newPhase(prev: Phase): Phase
+ /** The phase defined by this subcomponent. Can be called only after phase is installed by newPhase. */
+// lazy val ownPhase: Phase = global.currentRun.phaseNamed(phaseName)
+
/** A standard phase template */
abstract class StdPhase(prev: Phase) extends global.GlobalPhase(prev) {
def name = phaseName
diff --git a/src/compiler/scala/tools/nsc/symtab/Flags.scala b/src/compiler/scala/tools/nsc/symtab/Flags.scala
index 7befdc9719..d747ecfef7 100644
--- a/src/compiler/scala/tools/nsc/symtab/Flags.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Flags.scala
@@ -91,6 +91,8 @@ object Flags extends Enumeration {
final val lateMODULE = (MODULE: Long) << LateShift
final val lateFINAL = (FINAL: Long) << LateShift
final val lateMETHOD = (METHOD: Long) << LateShift
+
+ final val notFINAL = (FINAL: Long) << AntiShift
final val notPRIVATE = (PRIVATE: Long) << AntiShift
final val notDEFERRED = (DEFERRED: Long) << AntiShift
final val notPROTECTED = (PROTECTED: Long) << AntiShift
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index 372deb295a..f547875bc1 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -207,7 +207,7 @@ trait Symbols {
final def isStaticModule = isModule && isStatic && !isMethod
final def isPackage = isModule && hasFlag(PACKAGE)
final def isThisSym = isTerm && owner.thisSym == this
- final def isMonomorphicType = isType && hasFlag(MONOMORPHIC)
+ //final def isMonomorphicType = isType && hasFlag(MONOMORPHIC)
final def isError = hasFlag(IS_ERROR)
final def isErroneous = isError || isInitialized && tpe.isErroneous
final def isTrait = isClass & hasFlag(TRAIT)
@@ -232,6 +232,19 @@ trait Symbols {
final def isScalaPackage = isPackage && name == nme.scala_ // not printed as a prefix
final def isScalaPackageClass = isPackageClass && name == nme.scala_.toTypeName // not printed as a prefix
+ /** Is symbol a monomophic type?
+ * assumption: if a type starts out as monomorphic, it will not acquire
+ * type parameters in later phases.
+ */
+ final def isMonomorphicType =
+ isType && {
+ var is = infos
+ (is eq null) || {
+ while (is.prev ne null) { is = is.prev }
+ is.info.isComplete && is.info.typeParams.isEmpty
+ }
+ }
+
def isDeprecated =
attributes exists (attr => attr.atp.typeSymbol == DeprecatedAttr)
@@ -609,14 +622,17 @@ trait Symbols {
def tpeHK = if (isType) typeConstructor else tpe // @M! used in memberType
- /** The type parameters of this symbol */
+ /** The type parameters of this symbol, without ensuring type completion.
+ * assumption: if a type starts out as monomorphic, it will not acquire
+ * type parameters later.
+ */
def unsafeTypeParams: List[Symbol] =
if (isMonomorphicType) List() else rawInfo.typeParams
- /*
- val limit = phaseId(validTo)
- (if (limit < phase.id) infos.info else rawInfo).typeParams
- */
+ /** The type parameters of this symbol.
+ * assumption: if a type starts out as monomorphic, it will not acquire
+ * type parameters later.
+ */
def typeParams: List[Symbol] =
if (isMonomorphicType) List() else { rawInfo.load(this); rawInfo.typeParams }
@@ -1287,10 +1303,11 @@ trait Symbols {
} else {
if (isInitialized) tpePeriod = currentPeriod
tpeCache = NoType
- val targs = if (phase.erasedTypes && this != ArrayClass) List()
- else unsafeTypeParams map (_.typeConstructor) //@M! use typeConstructor to generate dummy type arguments,
- // sym.tpe should not be called on a symbol that's supposed to be a higher-kinded type
- // memberType should be used instead, that's why it uses tpeHK and not tpe
+ val targs =
+ if (phase.erasedTypes && this != ArrayClass) List()
+ else unsafeTypeParams map (_.typeConstructor) //@M! use typeConstructor to generate dummy type arguments,
+ // sym.tpe should not be called on a symbol that's supposed to be a higher-kinded type
+ // memberType should be used instead, that's why it uses tpeHK and not tpe
tpeCache = typeRef(if (hasFlag(PARAM | EXISTENTIAL)) NoPrefix else owner.thisType,
this, targs)
}
@@ -1495,10 +1512,6 @@ trait Symbols {
def cloneSymbols(syms: List[Symbol]): List[Symbol] = {
val syms1 = syms map (_.cloneSymbol)
for (sym1 <- syms1) sym1.setInfo(sym1.info.substSym(syms, syms1))
- if (inIDE) {
- assert(true)
- assert(true)
- }
syms1
}
diff --git a/src/compiler/scala/tools/nsc/util/SourceFile.scala b/src/compiler/scala/tools/nsc/util/SourceFile.scala
index 2f07b79d1e..e32cde800e 100644
--- a/src/compiler/scala/tools/nsc/util/SourceFile.scala
+++ b/src/compiler/scala/tools/nsc/util/SourceFile.scala
@@ -175,9 +175,11 @@ extends BatchSourceFile(name, contents)
override def positionInUltimateSource(position: Position) = {
if (position.offset.isEmpty) super.positionInUltimateSource(position)
else {
+ println("!!!")
var off = position.offset.get
var compsLeft = components
- while(compsLeft.head.content.length-1 <= off) {
+ while (compsLeft.head.content.length-1 <= off && !compsLeft.tail.isEmpty) {
+ println("discarding "+compsLeft.head)
off = off - compsLeft.head.content.length + 1
compsLeft = compsLeft.tail
}
diff --git a/src/library/scala/runtime/RichString.scala b/src/library/scala/runtime/RichString.scala
index 23db1a3fa7..f562702405 100644
--- a/src/library/scala/runtime/RichString.scala
+++ b/src/library/scala/runtime/RichString.scala
@@ -64,6 +64,16 @@ final class RichString(val self: String) extends Proxy with RandomAccessSeq[Char
case that => super.containsSlice(that)
}
+ override def reverse: RichString = {
+ val buf = new StringBuffer
+ var i = self.length - 1
+ while (i >= 0) {
+ buf append (self charAt i)
+ i = i - 1
+ }
+ new RichString(buf.toString)
+ }
+
override def compare(other: String) = self compareTo other
private def isLineBreak(c: Char) = c == LF || c == FF