summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2006-10-08 20:58:49 +0000
committerMartin Odersky <odersky@gmail.com>2006-10-08 20:58:49 +0000
commitfbc3a71a1e0d5cea346f0832202bbca8523f5aba (patch)
tree19b104c7b6a537a2f41ada8f16fff18b4eea7915 /src
parent86c028b6fa610ca2afdab7661faf2a9c1edcde9b (diff)
downloadscala-fbc3a71a1e0d5cea346f0832202bbca8523f5aba.tar.gz
scala-fbc3a71a1e0d5cea346f0832202bbca8523f5aba.tar.bz2
scala-fbc3a71a1e0d5cea346f0832202bbca8523f5aba.zip
wildcard types are in there now.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreePrinters.scala3
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala17
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala32
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala3
5 files changed, 47 insertions, 12 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
index 52e95ea818..1acc8e8c20 100644
--- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
@@ -313,6 +313,9 @@ abstract class TreePrinters {
case AppliedTypeTree(tp, args) =>
print(tp); printRow(args, "[", ", ", "]")
+
+ case WildcardTypeTree(lo, hi) =>
+ print("_ "); printOpt(" >: ", lo); printOpt(" <: ", hi)
}
if (global.settings.printtypes.value && tree.isTerm && !tree.isEmpty) {
print("{"); print(if (tree.tpe == null) "<null>" else tree.tpe.toString()); print("}")
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index a5667ece19..817ad2d451 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -570,8 +570,10 @@ trait Trees requires Global {
extends TypTree {
override def symbol: Symbol = tpt.symbol
override def symbol_=(sym: Symbol): unit = { tpt.symbol = sym }
+ }
-}
+ case class WildcardTypeTree(lo: Tree, hi: Tree)
+ extends TypTree
/* A standard pattern match
case EmptyTree =>
@@ -615,6 +617,7 @@ trait Trees requires Global {
case SelectFromTypeTree(qualifier, selector) => (eliminated by uncurry)
case CompoundTypeTree(templ: Template) => (eliminated by uncurry)
case AppliedTypeTree(tpt, args) => (eliminated by uncurry)
+ case WildcardTypeTree(lo, hi) => (eliminated by uncurry)
*/
abstract class TreeCopier {
@@ -658,6 +661,7 @@ trait Trees requires Global {
def SelectFromTypeTree(tree: Tree, qualifier: Tree, selector: Name): SelectFromTypeTree
def CompoundTypeTree(tree: Tree, templ: Template): CompoundTypeTree
def AppliedTypeTree(tree: Tree, tpt: Tree, args: List[Tree]): AppliedTypeTree
+ def WildcardTypeTree(tree: Tree, lo: Tree, hi: Tree): WildcardTypeTree
}
class StrictTreeCopier extends TreeCopier {
@@ -741,6 +745,8 @@ trait Trees requires Global {
new CompoundTypeTree(templ).copyAttrs(tree)
def AppliedTypeTree(tree: Tree, tpt: Tree, args: List[Tree]) =
new AppliedTypeTree(tpt, args).copyAttrs(tree)
+ def WildcardTypeTree(tree: Tree, lo: Tree, hi: Tree) =
+ new WildcardTypeTree(lo, hi).copyAttrs(tree)
}
class LazyTreeCopier(copy: TreeCopier) extends TreeCopier {
@@ -945,6 +951,11 @@ trait Trees requires Global {
if (tpt0 == tpt) && (args0 == args) => t
case _ => copy.AppliedTypeTree(tree, tpt, args)
}
+ def WildcardTypeTree(tree: Tree, lo: Tree, hi: Tree) = tree match {
+ case t @ WildcardTypeTree(lo0, hi0)
+ if (lo0 == lo) && (hi0 == hi) => t
+ case _ => copy.WildcardTypeTree(tree, lo, hi)
+ }
}
abstract class Transformer {
@@ -1054,6 +1065,8 @@ trait Trees requires Global {
copy.CompoundTypeTree(tree, transformTemplate(templ))
case AppliedTypeTree(tpt, args) =>
copy.AppliedTypeTree(tree, transform(tpt), transformTrees(args))
+ case WildcardTypeTree(lo, hi) =>
+ copy.WildcardTypeTree(tree, transform(lo), transform(hi))
}
def transformTrees(trees: List[Tree]): List[Tree] =
@@ -1186,6 +1199,8 @@ trait Trees requires Global {
traverse(templ)
case AppliedTypeTree(tpt, args) =>
traverse(tpt); traverseTrees(args)
+ case WildcardTypeTree(lo, hi) =>
+ traverse(lo); traverse(hi)
}
def traverseTrees(trees: List[Tree]): unit =
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 91d66f4220..723ff86968 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -603,15 +603,29 @@ trait Parsers requires SyntaxAnalyzer {
null; //dummy
}
- /** TypeArgs ::= `[' Types `]'
+ /** TypeArgs ::= `[' TypeArg {`,' TypeArg} `]'
*/
def typeArgs(): List[Tree] = {
accept(LBRACKET)
- val ts = types()
+ val ts = new ListBuffer[Tree] + typeArg()
+ while (in.token == COMMA) {
+ in.nextToken()
+ ts += typeArg()
+ }
accept(RBRACKET)
- ts
+ ts.toList
}
+ /** TypeArg ::= Type
+ * | `_' TypeBounds
+ */
+ def typeArg(): Tree =
+ if (in.token == USCORE)
+ atPos(in.skipToken()) {
+ WildcardTypeTree(bound(SUPERTYPE, nme.Nothing), bound(SUBTYPE, nme.Any))
+ }
+ else typ()
+
//////// EXPRESSIONS ////////////////////////////////////////////////////////
// XX_LIFTED
@@ -1425,14 +1439,14 @@ trait Parsers requires SyntaxAnalyzer {
/** TypeBounds ::= [`>:' Type] [`<:' Type]
*/
- def typeBounds(mods: Modifiers, name: Name): AbsTypeDef = {
- def bound(tok: int, default: Name): Tree =
- if (in.token == tok) { in.nextToken(); typ() }
- else scalaDot(default.toTypeName)
+ def typeBounds(mods: Modifiers, name: Name): AbsTypeDef =
AbsTypeDef(mods, name.toTypeName,
- bound(SUPERTYPE, nme.All),
+ bound(SUPERTYPE, nme.Nothing),
bound(SUBTYPE, nme.Any))
- }
+
+ def bound(tok: int, default: Name): Tree =
+ if (in.token == tok) { in.nextToken(); typ() }
+ else scalaDot(default.toTypeName)
//////// DEFS ////////////////////////////////////////////////////////////////
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index a5c4fc2ac0..6005f24765 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -1548,11 +1548,11 @@ trait Types requires SymbolTable {
}
object lowerBoundMap extends TypeMap {
- def apply(tp: Type): Type = tp.lowerBound
+ def apply(tp: Type): Type = if (variance == -1) tp.upperBound else tp.lowerBound
}
object upperBoundMap extends TypeMap {
- def apply(tp: Type): Type = tp.upperBound
+ def apply(tp: Type): Type = if (variance == -1) tp.lowerBound else tp.upperBound
}
/** A base class to compute all substitutions */
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index f26970e453..a12b814cd6 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1873,6 +1873,9 @@ trait Typers requires Analyzer {
errorTree(tree, "wrong number of type arguments for "+tpt1.tpe+", should be "+tparams.length)
}
+ case WildcardTypeTree(lo, hi) =>
+ tree setType TypeBounds(typedType(lo).tpe, typedType(hi).tpe)
+
case TypeTree() =>
// we should get here only when something before failed
// and we try again (@see tryTypedApply). In that case we can assign