summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sources/scala/tools/scalai/Compiler.java20
-rw-r--r--sources/scalac/atree/ATreeFromSTree.java5
-rw-r--r--sources/scalac/backend/msil/GenMSIL.java10
-rw-r--r--sources/scalac/checkers/TreeChecker.java8
-rw-r--r--sources/scalac/transformer/AddInterfaces.java2
-rw-r--r--sources/scalac/typechecker/RefCheck.java6
6 files changed, 14 insertions, 37 deletions
diff --git a/sources/scala/tools/scalai/Compiler.java b/sources/scala/tools/scalai/Compiler.java
index 83d7bc7ad2..963af1ad53 100644
--- a/sources/scala/tools/scalai/Compiler.java
+++ b/sources/scala/tools/scalai/Compiler.java
@@ -281,6 +281,9 @@ public class Compiler {
case ClassDef(_, _, _, _, _, _):
sources.put(tree, source);
environment.insertClassDef(symbol, (Tree.ClassDef)tree);
+ if (symbol.isModuleClass() && symbol.module().isGlobalModule()) {
+ environment.insertVariable(symbol.module(), Variable.Module(new CodePromise(new ModuleBuilder(this, source, symbol.module())), null));
+ }
return;
// !!! these could be removed
@@ -290,11 +293,6 @@ public class Compiler {
declare(source, body);
return;
- case ValDef(_, _, _, Tree body):
- assert symbol.isModule() : Debug.show(symbol);
- environment.insertVariable(symbol, Variable.Module(new CodePromise(new ModuleBuilder(this, source, symbol, body)), null));
- return;
-
default:
throw Debug.abort("illegal case", tree);
}
@@ -408,17 +406,21 @@ public class Compiler {
private final Compiler compiler;
private final SourceFile source;
private final Symbol symbol;
- private final Tree body;
- public ModuleBuilder(Compiler compiler, SourceFile source, Symbol symbol, Tree body) {
+ public ModuleBuilder(Compiler compiler, SourceFile source, Symbol symbol) {
this.compiler = compiler;
this.source = source;
this.symbol = symbol;
- this.body = body;
}
public CodeContainer generate() {
- return compiler.compile(source, symbol, body, Symbol.EMPTY_ARRAY);
+ TreeGen gen = compiler.global.treeGen;
+ Symbol clasz = symbol.moduleClass();
+ Symbol initializer = clasz.lookup(Names.INITIALIZER);
+ compiler.global.prevPhase();
+ Tree code =gen.New(gen.Apply(gen.Ident(symbol.pos, initializer)));
+ compiler.global.nextPhase();
+ return compiler.compile(source, symbol, code, Symbol.EMPTY_ARRAY);
}
}
diff --git a/sources/scalac/atree/ATreeFromSTree.java b/sources/scalac/atree/ATreeFromSTree.java
index 5761a1aabb..180551ec9f 100644
--- a/sources/scalac/atree/ATreeFromSTree.java
+++ b/sources/scalac/atree/ATreeFromSTree.java
@@ -65,6 +65,7 @@ public class ATreeFromSTree {
case ClassDef(_, _, _, _, _, Template(_, Tree[] body)):
AClass clasz = new AClass(tree.symbol());
+ // !!! add static field to global modules
repository.addClass(clasz);
member(clasz, body);
return;
@@ -73,10 +74,6 @@ public class ATreeFromSTree {
template(repository, body);
return;
- case ValDef(_, _, _, Tree rhs):
- // !!!
- return;
-
default:
throw Debug.abort("illegal case", tree);
}
diff --git a/sources/scalac/backend/msil/GenMSIL.java b/sources/scalac/backend/msil/GenMSIL.java
index 2e359011a5..c12cfea8ea 100644
--- a/sources/scalac/backend/msil/GenMSIL.java
+++ b/sources/scalac/backend/msil/GenMSIL.java
@@ -191,9 +191,6 @@ public final class GenMSIL {
//currModule = getPackage(packageName);
genPackage(currAssembly, impl.body);
break;
- case ValDef(_, _, _, _):
- //log("ValDef: " + dumpSym(tree.symbol()));
- break;
default:
throw new ApplicationError
("Illegal top-level definition: " + Debug.show(tree));
@@ -218,13 +215,6 @@ public final class GenMSIL {
genClass(sym, classBody);
break;
- case ValDef(_, _, Tree tpe, Tree rhs):
- if (sym.isModule()) {
- } else
- throw new ApplicationError();
- //log("ValDef: " + dumpSym(tree.symbol()));
- break;
-
case PackageDef(Tree packaged, Template(_ , Tree[] body2)):
//log("genPackage: nested package: " + dumpSym(sym));
genPackage(currAssembly, body2);
diff --git a/sources/scalac/checkers/TreeChecker.java b/sources/scalac/checkers/TreeChecker.java
index 9cce42ca69..c6d2af5052 100644
--- a/sources/scalac/checkers/TreeChecker.java
+++ b/sources/scalac/checkers/TreeChecker.java
@@ -122,14 +122,6 @@ public class TreeChecker {
popOwner();
return true;
- case ValDef(_, _, _, Tree rhs):
- Symbol symbol = tree.symbol();
- assert symbol != null && symbol.isModule(): show(tree);
- pushOwner(symbol);
- expression(rhs, symbol.type());
- popOwner();
- return true;
-
default:
throw Debug.abort("illegal case", tree);
}
diff --git a/sources/scalac/transformer/AddInterfaces.java b/sources/scalac/transformer/AddInterfaces.java
index b242500663..cb94006d98 100644
--- a/sources/scalac/transformer/AddInterfaces.java
+++ b/sources/scalac/transformer/AddInterfaces.java
@@ -176,9 +176,7 @@ public class AddInterfaces extends GenTransformer {
this.clasz = null;
return;
case DefDef(_, _, _, _, _, _):
- return;
case ValDef(_, _, _, _):
- if (tree.symbol().owner().isPackage()) trees.append(tree);
return;
default:
throw Debug.abort("illegal tree", tree);
diff --git a/sources/scalac/typechecker/RefCheck.java b/sources/scalac/typechecker/RefCheck.java
index 8e10889800..d787c803cf 100644
--- a/sources/scalac/typechecker/RefCheck.java
+++ b/sources/scalac/typechecker/RefCheck.java
@@ -524,11 +524,9 @@ public class RefCheck extends Transformer implements Modifiers, Kinds {
private Tree[] transformModule(Tree tree, int mods, Name name, Tree tpe, Tree.Template templ) {
Symbol sym = tree.symbol();
Tree cdef = gen.ClassDef(sym.moduleClass(), templ);
+ if (sym.isGlobalModule()) return new Tree[]{cdef};
Tree alloc = gen.New(gen.mkPrimaryConstr(tree.pos, sym.moduleClass()));
- if (sym.isGlobalModule()) {
- Tree vdef = gen.ValDef(sym, alloc);
- return new Tree[]{cdef, vdef};
- } else {
+ {
// var m$: T = null;
Name varname = Name.fromString(name + "$");
Symbol mvar = new TermSymbol(