diff options
author | Martin Odersky <odersky@gmail.com> | 2013-02-01 17:52:00 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-02-01 17:52:00 +0100 |
commit | abc8f5e1c382b1ead761976227878c4c38ebfbf5 (patch) | |
tree | b135a1bd0945f375e256af8e4ddfbd818c567865 /src/dotty/tools/dotc/core | |
parent | 5610fe1abbb8e4cb005d644f37669f872327828b (diff) | |
download | dotty-abc8f5e1c382b1ead761976227878c4c38ebfbf5.tar.gz dotty-abc8f5e1c382b1ead761976227878c4c38ebfbf5.tar.bz2 dotty-abc8f5e1c382b1ead761976227878c4c38ebfbf5.zip |
Added config package with settings, platform.
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r-- | src/dotty/tools/dotc/core/Contexts.scala | 14 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Flags.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/NameOps.scala | 63 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/SymbolLoaders.scala | 107 |
5 files changed, 88 insertions, 100 deletions
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index e2fe9822f..d7c8609f1 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -10,6 +10,7 @@ import Symbols._ import TypeComparers._, Printers._, NameOps._, SymDenotations._ import collection.mutable import collection.immutable.BitSet +import config.{Settings, Platform} object Contexts { @@ -53,12 +54,16 @@ object Contexts { protected def owner_=(owner: Symbol) = _owner = owner def owner: Symbol = _owner + private[this] var _settings: Settings = _ + protected def settings_=(settings: Settings) = _settings = settings + def settings: Settings = _settings + def phase: Phase = ??? // phase(period.phaseId) def enclClass: Context = ??? def erasedTypes: Boolean = ??? def debug: Boolean = ??? -// def settings: Settings = ??? def warning(msg: String) = ??? + def inform(msg: String) = ??? def fresh: FreshContext = { val newctx = super.clone.asInstanceOf[FreshContext] @@ -90,8 +95,7 @@ object Contexts { } class ContextBase extends Transformers.TransformerBase - with Printers.PrinterBase - with NameOps.NameOpsBase { + with Printers.PrinterBase { val initialCtx: Context = new InitialContext(this) @@ -99,6 +103,10 @@ object Contexts { lazy val definitions = new Definitions()(initialCtx) + lazy val loaders = new SymbolLoaders + + lazy val platform: Platform = ??? + // Symbols state /** A map from a superclass id to the class that has it */ private[core] var classOfId = new Array[ClassSymbol](InitialSuperIdsSize) diff --git a/src/dotty/tools/dotc/core/Flags.scala b/src/dotty/tools/dotc/core/Flags.scala index cafc4495d..13392a1c9 100644 --- a/src/dotty/tools/dotc/core/Flags.scala +++ b/src/dotty/tools/dotc/core/Flags.scala @@ -331,7 +331,7 @@ object Flags { /** Flags representing access rights */ final val AccessFlags = Private | Protected | Local - final val ModuleFlags: FlagSet = ??? + final val RetainedModuleFlags: FlagSet = ??? final val UninstantiatableFlags = Abstract | Final diff --git a/src/dotty/tools/dotc/core/NameOps.scala b/src/dotty/tools/dotc/core/NameOps.scala index 2bbfa1360..5aa7e2e25 100644 --- a/src/dotty/tools/dotc/core/NameOps.scala +++ b/src/dotty/tools/dotc/core/NameOps.scala @@ -10,25 +10,24 @@ import Decorators.StringDecorator object NameOps { - trait NameOpsBase { this: ContextBase => - - final object compactify extends (String => String) { - val md5 = MessageDigest.getInstance("MD5") - - /** COMPACTIFY - * - * The hashed name has the form (prefix + marker + md5 + marker + suffix), where - * - prefix/suffix.length = MaxNameLength / 4 - * - md5.length = 32 - * - * We obtain the formula: - * - * FileNameLength = 2*(MaxNameLength / 4) + 2.marker.length + 32 + 6 - * - * (+6 for ".class"). MaxNameLength can therefore be computed as follows: - */ + final object compactify { + lazy val md5 = MessageDigest.getInstance("MD5") + + /** COMPACTIFY + * + * The hashed name has the form (prefix + marker + md5 + marker + suffix), where + * - prefix/suffix.length = MaxNameLength / 4 + * - md5.length = 32 + * + * We obtain the formula: + * + * FileNameLength = 2*(MaxNameLength / 4) + 2.marker.length + 32 + 6 + * + * (+6 for ".class"). MaxNameLength can therefore be computed as follows: + */ + def apply(s: String)(implicit ctx: Context): String = { val marker = "$$$$" - val limit: Int = ??? // !!! settings.maxClassfileName.value + val limit: Int = ctx.settings.XmaxClassfileName.value val MaxNameLength = (limit - 6) min 2 * (limit - 6 - 2 * marker.length - 32) def toMD5(s: String, edge: Int): String = { @@ -42,21 +41,11 @@ object NameOps { prefix + marker + md5chars + marker + suffix } - def apply(s: String): String = - if (s.length <= MaxNameLength) s else toMD5(s, MaxNameLength / 4) + + if (s.length <= MaxNameLength) s else toMD5(s, MaxNameLength / 4) } } - private val Boxed = Map[TypeName, TypeName]( - tpnme.Boolean -> jtpnme.BoxedBoolean, - tpnme.Byte -> jtpnme.BoxedByte, - tpnme.Char -> jtpnme.BoxedCharacter, - tpnme.Short -> jtpnme.BoxedShort, - tpnme.Int -> jtpnme.BoxedInteger, - tpnme.Long -> jtpnme.BoxedLong, - tpnme.Float -> jtpnme.BoxedFloat, - tpnme.Double -> jtpnme.BoxedDouble) - implicit class NameDecorator(val name: Name) extends AnyVal { import nme._ @@ -147,9 +136,21 @@ object NameOps { } /** If name length exceeds allowable limit, replace part of it by hash */ - def compactified(implicit ctx: Context): TermName = termName(ctx.compactify(name.toString)) + def compactified(implicit ctx: Context): TermName = termName(compactify(name.toString)) } + // needed??? + private val Boxed = Map[TypeName, TypeName]( + tpnme.Boolean -> jtpnme.BoxedBoolean, + tpnme.Byte -> jtpnme.BoxedByte, + tpnme.Char -> jtpnme.BoxedCharacter, + tpnme.Short -> jtpnme.BoxedShort, + tpnme.Int -> jtpnme.BoxedInteger, + tpnme.Long -> jtpnme.BoxedLong, + tpnme.Float -> jtpnme.BoxedFloat, + tpnme.Double -> jtpnme.BoxedDouble) + + // needed??? implicit class TypeNameDecorator(val name: TypeName) extends AnyVal { def isUnboxedName = Boxed contains name def boxedName: TypeName = Boxed(name) diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 0b61906b1..e916d0e70 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -721,7 +721,7 @@ object SymDenotations { def classDenot(denot: LazySymDenotation) = denot.moduleClass.denot.asInstanceOf[LazyClassDenotation] def copyLoadedFields(denot: LazySymDenotation, from: LazyClassDenotation) = { - denot.setFlags(from.flags.toTermFlags & ModuleFlags) + denot.setFlags(from.flags.toTermFlags & RetainedModuleFlags) denot.privateWithin = from.privateWithin } def copyCompletedFields(denot: LazySymDenotation, from: LazyClassDenotation) = { diff --git a/src/dotty/tools/dotc/core/SymbolLoaders.scala b/src/dotty/tools/dotc/core/SymbolLoaders.scala index 972242fbd..41bd0fdeb 100644 --- a/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -10,108 +10,84 @@ package core import java.io.IOException import scala.compat.Platform.currentTime import dotty.tools.io.{ClassPath, AbstractFile} -import Contexts._, Symbols._, Flags._, SymDenotations._ +import Contexts._, Symbols._, Flags._, SymDenotations._, Types._ import Decorators.StringDecorator //import classfile.ClassfileParser +abstract class SymbolLoader extends ClassCompleter -abstract class SymbolLoaders(implicit ctx: Context) { - protected def enterIfNew(owner: Symbol, member: Symbol, completer: SymbolLoader): Symbol = { +class SymbolLoaders { + + protected def enterIfNew(owner: Symbol, member: Symbol, completer: SymbolLoader)(implicit ctx: Context): Symbol = { assert(owner.info.decls.lookup(member.name) == NoSymbol, owner.fullName + "." + member.name) owner.info.decls enter member member } - /** Enter class with given `name` into scope of `root` - * and give them `completer` as type. + /** Enter class with given `name` into scope of `owner`. */ - def enterClass(owner: Symbol, name: String, completer: SymbolLoader): Symbol = { + def enterClass(owner: Symbol, name: String, completer: SymbolLoader)(implicit ctx: Context): Symbol = { val cls = ctx.newLazyClassSymbol(owner, name.toTypeName, EmptyFlags, completer) enterIfNew(owner, cls, completer) } - /** Enter module with given `name` into scope of `root` - * and give them `completer` as type. + /** Enter module with given `name` into scope of `owner`. */ - def enterModule(owner: Symbol, name: String, completer: SymbolLoader): Symbol = { + def enterModule(owner: Symbol, name: String, completer: SymbolLoader)(implicit ctx: Context): Symbol = { val module = ctx.newLazyModuleSymbol(owner, name.toTermName, EmptyFlags, completer) enterIfNew(owner, module, completer) } - abstract class SymbolLoader extends ClassCompleter -} -/* - /** Enter module with given `name` into scope of `root` - * and give them `completer` as type. - */ - def enterModule(owner: Symbol, name: String, completer: SymbolLoader): Symbol = { - val module = owner.newModule(newTermName(name)) - module setInfo completer - module.moduleClass setInfo moduleClassLoader - enterIfNew(owner, module, completer) - } - - /** Enter package with given `name` into scope of `root` + /** Enter package with given `name` into scope of `owner` * and give them `completer` as type. */ - def enterPackage(root: Symbol, name: String, completer: SymbolLoader): Symbol = { - val pname = newTermName(name) - val preExisting = root.info.decls lookup pname + def enterPackage(owner: Symbol, name: String, completer: SymbolLoader)(implicit ctx: Context): Symbol = { + val pname = name.toTermName + val preExisting = owner.info.decls lookup pname if (preExisting != NoSymbol) { // Some jars (often, obfuscated ones) include a package and // object with the same name. Rather than render them unusable, // offer a setting to resolve the conflict one way or the other. // This was motivated by the desire to use YourKit probes, which // require yjp.jar at runtime. See SI-2089. - if (settings.termConflict.isDefault) + if (ctx.settings.YtermConflict == ctx.settings.default.YtermConflict) throw new TypeError( - root+" contains object and package with same name: "+ - name+"\none of them needs to be removed from classpath" - ) - else if (settings.termConflict.value == "package") { - global.warning( - "Resolving package/object name conflict in favor of package " + - preExisting.fullName + ". The object will be inaccessible." - ) - root.info.decls.unlink(preExisting) - } - else { - global.warning( - "Resolving package/object name conflict in favor of object " + - preExisting.fullName + ". The package will be inaccessible." - ) + s"""$owner contains object and package with same name: $name + |one of them needs to be removed from classpath""".stripMargin) + else if (ctx.settings.YtermConflict.value == "package") { + ctx.warning( + s"Resolving package/object name conflict in favor of package ${preExisting.fullName}. The object will be inaccessible.") + owner.info.decls.unlink(preExisting) + } else { + ctx.warning( + s"Resolving package/object name conflict in favor of object ${preExisting.fullName}. The package will be inaccessible.") return NoSymbol } } - // todo: find out initialization sequence for pkg/pkg.moduleClass is different from enterModule - val pkg = root.newPackage(pname) - pkg.moduleClass setInfo completer - pkg setInfo pkg.moduleClass.tpe - root.info.decls enter pkg - pkg + ctx.newLazyModuleSymbol(owner, pname, PackageCreationFlags, completer).entered } - /** Enter class and module with given `name` into scope of `root` + /** Enter class and module with given `name` into scope of `owner` * and give them `completer` as type. */ - def enterClassAndModule(root: Symbol, name: String, completer: SymbolLoader) { - val clazz = enterClass(root, name, completer) - val module = enterModule(root, name, completer) + def enterClassAndModule(owner: Symbol, name: String, completer: SymbolLoader)(implicit ctx: Context) { + val clazz = enterClass(owner, name, completer) + val module = enterModule(owner, name, completer) if (!clazz.isAnonymousClass) { assert(clazz.companionModule == module, module) assert(module.companionClass == clazz, clazz) } } - /** In batch mode: Enter class and module with given `name` into scope of `root` + /** In batch mode: Enter class and module with given `name` into scope of `owner` * and give them a source completer for given `src` as type. - * In IDE mode: Find all toplevel definitions in `src` and enter then into scope of `root` + * In IDE mode: Find all toplevel definitions in `src` and enter then into scope of `owner` * with source completer for given `src` as type. * (overridden in interactive.Global). */ - def enterToplevelsFromSource(root: Symbol, name: String, src: AbstractFile) { - enterClassAndModule(root, name, new SourcefileLoader(src)) + def enterToplevelsFromSource(owner: Symbol, name: String, src: AbstractFile)(implicit ctx: Context) { + ??? // !!! enterClassAndModule(owner, name, new SourcefileLoader(src)) } /** The package objects of scala and scala.reflect should always @@ -121,26 +97,29 @@ abstract class SymbolLoaders(implicit ctx: Context) { * Note: We do a name-base comparison here because the method is called before we even * have ReflectPackage defined. */ - def binaryOnly(owner: Symbol, name: String): Boolean = + def binaryOnly(owner: Symbol, name: String)(implicit ctx: Context): Boolean = name == "package" && (owner.fullName == "scala" || owner.fullName == "scala.reflect") /** Initialize toplevel class and module symbols in `owner` from class path representation `classRep` */ - def initializeFromClassPath(owner: Symbol, classRep: ClassPath[platform.BinaryRepr]#ClassRep) { + def initializeFromClassPath(owner: Symbol, classRep: ClassPath#ClassRep)(implicit ctx: Context) { ((classRep.binary, classRep.source) : @unchecked) match { case (Some(bin), Some(src)) - if platform.needCompile(bin, src) && !binaryOnly(owner, classRep.name) => - if (settings.verbose.value) inform("[symloader] picked up newer source file for " + src.path) - global.loaders.enterToplevelsFromSource(owner, classRep.name, src) + if needCompile(bin, src) && !binaryOnly(owner, classRep.name) => + if (ctx.settings.verbose.value) ctx.inform("[symloader] picked up newer source file for " + src.path) + enterToplevelsFromSource(owner, classRep.name, src) case (None, Some(src)) => - if (settings.verbose.value) inform("[symloader] no class, picked up source file for " + src.path) - global.loaders.enterToplevelsFromSource(owner, classRep.name, src) + if (ctx.settings.verbose.value) ctx.inform("[symloader] no class, picked up source file for " + src.path) + enterToplevelsFromSource(owner, classRep.name, src) case (Some(bin), _) => - global.loaders.enterClassAndModule(owner, classRep.name, platform.newClassLoader(bin)) + enterClassAndModule(owner, classRep.name, ctx.platform.newClassLoader(bin)) } } + def needCompile(bin: AbstractFile, src: AbstractFile) = + src.lastModified >= bin.lastModified +}/* /** * A lazy type that completes itself by calling parameter doComplete. * Any linked modules/classes or module classes are also initialized. |