aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Symbols.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-02-18 17:07:13 +0100
committerMartin Odersky <odersky@gmail.com>2013-02-18 17:07:13 +0100
commitc0ed9aec10ba8ea3e3c0ecc22f2e9f92e550ad10 (patch)
tree3ee96faabc89ddc3c60657b2c27590e3ee512449 /src/dotty/tools/dotc/core/Symbols.scala
parent3a779e24f4b93addc07170778294dcf6225ac505 (diff)
downloaddotty-c0ed9aec10ba8ea3e3c0ecc22f2e9f92e550ad10.tar.gz
dotty-c0ed9aec10ba8ea3e3c0ecc22f2e9f92e550ad10.tar.bz2
dotty-c0ed9aec10ba8ea3e3c0ecc22f2e9f92e550ad10.zip
Addec convenience methods for symbol creation.
Diffstat (limited to 'src/dotty/tools/dotc/core/Symbols.scala')
-rw-r--r--src/dotty/tools/dotc/core/Symbols.scala55
1 files changed, 45 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala
index cd644df4e..68579f15f 100644
--- a/src/dotty/tools/dotc/core/Symbols.scala
+++ b/src/dotty/tools/dotc/core/Symbols.scala
@@ -19,6 +19,8 @@ import io.AbstractFile
/** Creation methods for symbols */
trait Symbols { this: Context =>
+// ---- Fundamental symbol creation methods ----------------------------------
+
def newLazySymbol[N <: Name](owner: Symbol, name: N, initFlags: FlagSet, completer: SymCompleter, coord: Coord = NoCoord) =
new Symbol(coord, new LazySymDenotation(_, owner, name, initFlags, completer)) {
type ThisName = N
@@ -45,9 +47,6 @@ trait Symbols { this: Context =>
(module, modcls)
}
- def newLazyPackageSymbols(owner: Symbol, name: TermName, completer: ClassCompleter) =
- newLazyModuleSymbols(owner, name, PackageCreationFlags, completer)
-
def newSymbol[N <: Name](owner: Symbol, name: N, flags: FlagSet, info: Type, privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord) =
new Symbol(coord, CompleteSymDenotation(_, owner, name, flags, info, privateWithin)) {
type ThisName = N
@@ -90,13 +89,6 @@ trait Symbols { this: Context =>
(module, modcls)
}
- def newPackageSymbols(
- owner: Symbol,
- name: TermName,
- decls: Scope = newScope) =
- newModuleSymbols(
- owner, name, PackageCreationFlags, PackageCreationFlags, Nil, NoSymbol, decls)
-
def newStubSymbol(owner: Symbol, name: Name, file: AbstractFile = null): Symbol = {
def stub = new StubCompleter(ctx.condensed)
name match {
@@ -105,12 +97,55 @@ trait Symbols { this: Context =>
}
}
+// ---- Derived symbol creation methods -------------------------------------
+
+ def newLazyPackageSymbols(owner: Symbol, name: TermName, completer: ClassCompleter) =
+ newLazyModuleSymbols(owner, name, PackageCreationFlags, completer)
+
+ def newPackageSymbols(
+ owner: Symbol,
+ name: TermName,
+ decls: Scope = newScope) =
+ newModuleSymbols(
+ owner, name, PackageCreationFlags, PackageCreationFlags, Nil, NoSymbol, decls)
+
def newLocalDummy(cls: Symbol, coord: Coord = NoCoord) =
newSymbol(cls, nme.localDummyName(cls), EmptyFlags, NoType)
def newImportSymbol(expr: TypedTree, coord: Coord = NoCoord) =
newSymbol(NoSymbol, nme.IMPORT, EmptyFlags, ImportType(expr), coord = coord)
+ def newConstructor(cls: ClassSymbol, flags: FlagSet, paramNames: List[TermName], paramTypes: List[Type], privateWithin: Symbol = NoSymbol, coord: Coord = NoCoord) =
+ newSymbol(cls, nme.CONSTRUCTOR, flags, MethodType(paramNames, paramTypes)(_ => cls.typeConstructor), privateWithin, coord)
+
+ def newDefaultConstructor(cls: ClassSymbol) =
+ newConstructor(cls, EmptyFlags, Nil, Nil)
+
+ def newSelfSym(cls: ClassSymbol) =
+ ctx.newSymbol(cls, nme.THIS, SyntheticArtifact, cls.selfType)
+
+ /** Create new type parameters with given owner, names, and flags.
+ * @param boundsFn A function that, given type refs to the newly created
+ * parameters returns a list of their bounds.
+ */
+ def newTypeParams(
+ owner: Symbol,
+ names: List[TypeName],
+ flags: FlagSet,
+ boundsFn: List[TypeRef] => List[Type]) = {
+ lazy val tparams: List[TypeSymbol] = names map { name =>
+ newLazySymbol(owner, name, flags | TypeParam, { denot =>
+ denot.info = bounds(denot.symbol.asType)
+ })
+ }
+ lazy val bounds = (tparams zip boundsFn(tparams map (_.typeConstructor))).toMap
+ tparams
+ }
+
+ private val reverseApply = (x: TypeSymbol, f: TypeSymbol => TypeBounds) => f(x)
+
+// ----- Locating predefined symbols ----------------------------------------
+
def requiredPackage(path: PreName): TermSymbol =
base.staticRef(path.toTermName).requiredSymbol(_.isPackage).asTerm