summaryrefslogtreecommitdiff
path: root/sources/scalac/ast
diff options
context:
space:
mode:
Diffstat (limited to 'sources/scalac/ast')
-rw-r--r--sources/scalac/ast/SubstTransformer.java4
-rw-r--r--sources/scalac/ast/TreeGen.java57
-rw-r--r--sources/scalac/ast/TreeInfo.java11
-rw-r--r--sources/scalac/ast/parser/Parser.java20
-rw-r--r--sources/scalac/ast/printer/TextTreePrinter.java34
5 files changed, 83 insertions, 43 deletions
diff --git a/sources/scalac/ast/SubstTransformer.java b/sources/scalac/ast/SubstTransformer.java
index ee8541dbb0..99c8e4f787 100644
--- a/sources/scalac/ast/SubstTransformer.java
+++ b/sources/scalac/ast/SubstTransformer.java
@@ -181,7 +181,7 @@ public class SubstTransformer extends Transformer {
switch (tree) {
case ClassDef(_, // fix Emacs :
_,
- Tree.TypeDef[] tparams,
+ Tree.AbsTypeDef[] tparams,
Tree.ValDef[][] vparams,
Tree tpe,
Tree.Template impl) :
@@ -202,7 +202,7 @@ public class SubstTransformer extends Transformer {
case DefDef(_, // fix for Emacs :
Name name,
- Tree.TypeDef[] tparams,
+ Tree.AbsTypeDef[] tparams,
Tree.ValDef[][] vparams,
Tree tpe,
Tree rhs):
diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java
index 137e76c6fa..863c652090 100644
--- a/sources/scalac/ast/TreeGen.java
+++ b/sources/scalac/ast/TreeGen.java
@@ -112,7 +112,7 @@ public class TreeGen implements Kinds, Modifiers {
case SingleType(Type pre1, Symbol sym):
return mkStable(mkRef(pos, pre1, sym));
default:
- throw new ApplicationError();
+ throw new ApplicationError(pre);
}
}
@@ -144,8 +144,10 @@ public class TreeGen implements Kinds, Modifiers {
switch (sym.kind) {
case ERROR:
return make.Bad(pos, Symbol.ERROR).setType(Type.ErrorType);
- case TYPE: case ALIAS:
- return TypeDef(pos, sym);
+ case TYPE:
+ return AbsTypeDef(pos, sym);
+ case ALIAS:
+ return AliasTypeDef(pos, sym);
case VAL:
if (sym.isMethod()) return DefDef(pos, sym, Tree.Empty);
else return ValDef(pos, sym, Tree.Empty);
@@ -265,8 +267,8 @@ public class TreeGen implements Kinds, Modifiers {
/** Build type parameter section corresponding to given array of symbols .
*/
- public TypeDef[] mkTypeParams(int pos, Symbol[] symbols) {
- TypeDef[] res = new TypeDef[symbols.length];
+ public AbsTypeDef[] mkTypeParams(int pos, Symbol[] symbols) {
+ AbsTypeDef[] res = new AbsTypeDef[symbols.length];
for (int i = 0; i < symbols.length; i++) {
res[i] = mkTypeParam(pos, symbols[i]);
}
@@ -275,28 +277,47 @@ public class TreeGen implements Kinds, Modifiers {
/** Build type parameter corresponding to given symbol .
*/
- public TypeDef mkTypeParam(int pos, Symbol sym) {
- return TypeDef(pos, sym);
+ public AbsTypeDef mkTypeParam(int pos, Symbol sym) {
+ return AbsTypeDef(pos, sym);
}
- public TypeDef mkTypeParam(Symbol sym) {
+ public AbsTypeDef mkTypeParam(Symbol sym) {
return mkTypeParam(sym.pos, sym);
}
- /** Build type definition corresponding to given symbol .
+ /** Build abstract type definition corresponding to given symbol .
*/
- public TypeDef TypeDef(int pos, Symbol sym) {
+ public AbsTypeDef AbsTypeDef(int pos, Symbol sym) {
Global.instance.nextPhase();
Type symtype = sym.info();
Global.instance.prevPhase();
- TypeDef res = make.TypeDef(
+ AbsTypeDef res = make.AbsTypeDef(
pos, sym, TypeTerm(pos, symtype), TypeTerm(pos, sym.loBound()));
res.setType(definitions.UNIT_TYPE);
return res;
}
- public TypeDef TypeDef(Symbol sym) {
- return TypeDef(sym.pos, sym);
+ public AbsTypeDef AbsTypeDef(Symbol sym) {
+ return AbsTypeDef(sym.pos, sym);
+ }
+
+ /** Build type definition corresponding to given symbol .
+ */
+ public AliasTypeDef AliasTypeDef(int pos, Symbol sym) {
+ Global.instance.nextPhase();
+ Type symtype = sym.info();
+ Global.instance.prevPhase();
+ AliasTypeDef res = make.AliasTypeDef(
+ pos,
+ sym,
+ mkTypeParams(pos, sym.typeParams()),
+ TypeTerm(pos, symtype));
+ res.setType(definitions.UNIT_TYPE);
+ return res;
+ }
+
+ public AliasTypeDef AliasTypeDef(Symbol sym) {
+ return AliasTypeDef(sym.pos, sym);
}
/** Build and attribute block with given statements, starting
@@ -633,8 +654,9 @@ public class TreeGen implements Kinds, Modifiers {
changeOwner(body, owner, applyMeth);
Tree applyDef = DefDef(applyMeth, body);
Tree classDef = ClassDef(clazz, new Tree[]{applyDef});
- Tree alloc = New(pos, Type.localThisType, clazz, Tree.EMPTY_ARRAY);
- return Block(new Tree[]{classDef, alloc}).setType(ft);
+ Tree alloc = New(pos, Type.localThisType, clazz, Tree.EMPTY_ARRAY)
+ .setType(ft);
+ return Block(new Tree[]{classDef, alloc});
}
public Tree mkPartialFunction(int pos, Tree applyVisitor, Tree isDefinedAtVisitor,
@@ -652,8 +674,9 @@ public class TreeGen implements Kinds, Modifiers {
pattype, restype, clazz, owner),
makeVisitorMethod(pos, Names.isDefinedAt, isDefinedAtVisitor,
pattype, definitions.BOOLEAN_TYPE, clazz, owner)});
- Tree alloc = New(pos, Type.localThisType, clazz, Tree.EMPTY_ARRAY);
- return Block(new Tree[]{classDef, alloc}).setType(pft);
+ Tree alloc = New(pos, Type.localThisType, clazz, Tree.EMPTY_ARRAY)
+ .setType(pft);
+ return Block(new Tree[]{classDef, alloc});
}
//where
private Tree makeVisitorMethod(int pos, Name name, Tree visitor,
diff --git a/sources/scalac/ast/TreeInfo.java b/sources/scalac/ast/TreeInfo.java
index 637928188f..bc5e03f9b8 100644
--- a/sources/scalac/ast/TreeInfo.java
+++ b/sources/scalac/ast/TreeInfo.java
@@ -47,7 +47,8 @@ public class TreeInfo {
case ModuleDef(_, _, _, _):
case DefDef(_, _, _, _, _, _):
case ValDef(_, _, _, _):
- case TypeDef(_, _, _, _):
+ case AbsTypeDef(_, _, _, _):
+ case AliasTypeDef(_, _, _, _):
case Import(_, _):
return true;
default:
@@ -61,7 +62,8 @@ public class TreeInfo {
return rhs == Tree.Empty;
case ValDef(_, _, _, Tree rhs):
return rhs == Tree.Empty;
- case TypeDef(_, _, _, _):
+ case AbsTypeDef(_, _, _, _):
+ case AliasTypeDef(_, _, _, _):
return true;
default:
return false;
@@ -76,7 +78,8 @@ public class TreeInfo {
case ClassDef(_, _, _, _, _, _):
case ModuleDef(_, _, _, _):
case DefDef(_, _, _, _, _, _):
- case TypeDef(_, _, _, _):
+ case AbsTypeDef(_, _, _, _):
+ case AliasTypeDef(_, _, _, _):
case Import(_, _):
return true;
case ValDef(int mods, _, _, Tree rhs):
@@ -154,6 +157,8 @@ public class TreeInfo {
return methSymbol(fn);
case TypeApply(Tree fn, _):
return methSymbol(fn);
+ case AppliedType(Tree fn, _):
+ return methSymbol(fn);
default:
if (tree.hasSymbol()) return tree.symbol();
else return Symbol.NONE;
diff --git a/sources/scalac/ast/parser/Parser.java b/sources/scalac/ast/parser/Parser.java
index 8c01c53b41..7212745657 100644
--- a/sources/scalac/ast/parser/Parser.java
+++ b/sources/scalac/ast/parser/Parser.java
@@ -1441,7 +1441,7 @@ public class Parser implements Tokens {
/** TypeParamClauseOpt ::= [`[' TypeParam {`,' TypeParam} `]']
* FunTypeParamClauseOpt ::= [`[' FunTypeParam {`,' FunTypeParam} `]']
*/
- TypeDef[] typeParamClauseOpt(boolean variant) {
+ AbsTypeDef[] typeParamClauseOpt(boolean variant) {
TreeList params = new TreeList();
if (s.token == LBRACKET) {
s.nextToken();
@@ -1452,7 +1452,7 @@ public class Parser implements Tokens {
}
accept(RBRACKET);
}
- return (TypeDef[])params.copyTo(new TypeDef[params.length()]);
+ return (AbsTypeDef[])params.copyTo(new AbsTypeDef[params.length()]);
}
/** TypeParam ::= [`+' | `-'] FunTypeParam
@@ -1491,7 +1491,7 @@ public class Parser implements Tokens {
} else {
hibound = scalaDot(pos, Names.Any.toTypeName());
}
- return make.TypeDef(pos, mods, name.toTypeName(), hibound, lobound);
+ return make.AbsTypeDef(pos, mods, name.toTypeName(), hibound, lobound);
}
//////// DEFS ////////////////////////////////////////////////////////////////
@@ -1726,11 +1726,11 @@ public class Parser implements Tokens {
accept(EQUALS);
return make.DefDef(
pos, mods, Names.this_.toTypeName(),
- Tree.TypeDef_EMPTY_ARRAY, vparams, Tree.Empty,
+ Tree.AbsTypeDef_EMPTY_ARRAY, vparams, Tree.Empty,
convertToSelfConstr(expr()));
} else {
Name name = ident();
- TypeDef[] tparams = typeParamClauseOpt(false);
+ AbsTypeDef[] tparams = typeParamClauseOpt(false);
ValDef[][] vparams = paramClauses();
Tree restype = typedOpt();
if (s.token == EQUALS || restype == Tree.Empty)
@@ -1749,9 +1749,13 @@ public class Parser implements Tokens {
int pos = s.pos;
Name name = ident().toTypeName();
switch (s.token) {
+ case LBRACKET:
+ AbsTypeDef[] tparams = typeParamClauseOpt(true);
+ accept(EQUALS);
+ return make.AliasTypeDef(pos, mods, name, tparams, type());
case EQUALS:
s.nextToken();
- return make.TypeDef(pos, mods, name, type(), Tree.Empty);
+ return make.AliasTypeDef(pos, mods, name, Tree.AbsTypeDef_EMPTY_ARRAY, type());
case SUPERTYPE:
case SUBTYPE:
case SEMI:
@@ -1768,7 +1772,7 @@ public class Parser implements Tokens {
Tree classDef(int mods) {
int pos = s.pos;
Name clazzname = ident().toTypeName();
- TypeDef[] tparams = typeParamClauseOpt(true);
+ AbsTypeDef[] tparams = typeParamClauseOpt(true);
ValDef[][] params = paramClauseOpt();
TreeList result = new TreeList();
return popComment(make.ClassDef(pos, mods, clazzname, tparams, params,
@@ -1830,7 +1834,7 @@ public class Parser implements Tokens {
Tree constr() {
Tree t = convertToConstr(stableId());
if (s.token == LBRACKET)
- t = make.TypeApply(s.pos, t, typeArgs());
+ t = make.AppliedType(s.pos, t, typeArgs());
if (s.token == LPAREN)
t = make.Apply(s.pos, t, argumentExprs());
return applyConstr(t);
diff --git a/sources/scalac/ast/printer/TextTreePrinter.java b/sources/scalac/ast/printer/TextTreePrinter.java
index 39b312f4a7..20013c0711 100644
--- a/sources/scalac/ast/printer/TextTreePrinter.java
+++ b/sources/scalac/ast/printer/TextTreePrinter.java
@@ -254,7 +254,7 @@ public class TextTreePrinter implements TreePrinter {
case ClassDef(int mods, // :
Name name,
- Tree.TypeDef[] tparams,
+ Tree.AbsTypeDef[] tparams,
Tree.ValDef[][] vparams,
Tree tpe,
Tree.Template impl):
@@ -316,7 +316,7 @@ public class TextTreePrinter implements TreePrinter {
case DefDef(int mods,
Name name,
- Tree.TypeDef[] tparams,
+ Tree.AbsTypeDef[] tparams,
Tree.ValDef[][] vparams,
Tree tpe,
Tree rhs):
@@ -331,19 +331,27 @@ public class TextTreePrinter implements TreePrinter {
printOpt(TXT_EQUAL, rhs, true);
break;
- case TypeDef(int mods,
- Name name,
- Tree rhs,
- Tree lobound):
+ case AbsTypeDef(int mods,
+ Name name,
+ Tree rhs,
+ Tree lobound):
printModifiers(mods);
print(KW_TYPE);
print(Text.Space);
printSymbolDefinition(tree.symbol(), name);
- if ((mods & (Modifiers.DEFERRED | Modifiers.PARAM)) != 0) {
- printBounds(lobound, rhs);
- } else {
- printOpt(TXT_EQUAL, rhs, true);
- }
+ printBounds(lobound, rhs);
+ break;
+
+ case AliasTypeDef(int mods,
+ Name name,
+ Tree.AbsTypeDef[] tparams,
+ Tree rhs):
+ printModifiers(mods);
+ print(KW_TYPE);
+ print(Text.Space);
+ printSymbolDefinition(tree.symbol(), name);
+ printParams(tparams);
+ printOpt(TXT_EQUAL, rhs, true);
break;
case Import(Tree expr, Name[] selectors):
@@ -688,7 +696,7 @@ public class TextTreePrinter implements TreePrinter {
}
}
- protected void printParams(Tree.TypeDef[] tparams) {
+ protected void printParams(Tree.AbsTypeDef[] tparams) {
if (tparams.length > 0) {
print(TXT_LEFT_BRACKET);
for (int i = 0; i < tparams.length; i++) {
@@ -715,7 +723,7 @@ public class TextTreePrinter implements TreePrinter {
protected void printParam(Tree tree) {
switch (tree) {
- case TypeDef(int mods, Name name, Tree bound, Tree lobound):
+ case AbsTypeDef(int mods, Name name, Tree bound, Tree lobound):
printModifiers(mods);
printSymbolDefinition(tree.symbol(), name);
printBounds(lobound, bound);