summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-10-29 20:56:06 +0000
committerpaltherr <paltherr@epfl.ch>2003-10-29 20:56:06 +0000
commitf6c0572ee8fe91ea6d306e4599da831517c05029 (patch)
tree7ebf70bef2d7ac311e6379de715ab6181650b77a /sources
parent480141c85a8f130cdf3260ca4f045962edb21975 (diff)
downloadscala-f6c0572ee8fe91ea6d306e4599da831517c05029.tar.gz
scala-f6c0572ee8fe91ea6d306e4599da831517c05029.tar.bz2
scala-f6c0572ee8fe91ea6d306e4599da831517c05029.zip
- Simplified import tree generation
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/Global.java2
-rw-r--r--sources/scalac/typechecker/AnalyzerPhase.java63
2 files changed, 12 insertions, 53 deletions
diff --git a/sources/scalac/Global.java b/sources/scalac/Global.java
index d0a89b9191..9bf7dc9492 100644
--- a/sources/scalac/Global.java
+++ b/sources/scalac/Global.java
@@ -392,7 +392,7 @@ public class Global {
}
for (int i = 0; i < imports.size(); i++) {
Symbol module = (Symbol)imports.get(i);
- ((scalac.typechecker.AnalyzerPhase)PHASE.ANALYZER.phase()).addConsoleImport(this, module);
+ ((scalac.typechecker.AnalyzerPhase)PHASE.ANALYZER.phase()).addConsoleImport(module);
}
}
diff --git a/sources/scalac/typechecker/AnalyzerPhase.java b/sources/scalac/typechecker/AnalyzerPhase.java
index 155b8a7a06..d2a2ec2c41 100644
--- a/sources/scalac/typechecker/AnalyzerPhase.java
+++ b/sources/scalac/typechecker/AnalyzerPhase.java
@@ -36,48 +36,12 @@ public class AnalyzerPhase extends Phase {
this.startContext.enclClass = this.startContext;
if (!global.noimports) {
- TreeFactory make = global.make;
- Tree java = make.Ident(Position.NOPOS, Names.java)
- .setSymbol(definitions.JAVA)
- .setType(Type.singleType(definitions.ROOT_TYPE, definitions.JAVA));
- Tree javalang = make.Select(Position.NOPOS, java, Names.lang)
- .setSymbol(definitions.JAVALANG)
- .setType(Type.singleType(java.type, definitions.JAVALANG));
- Tree importjavalang = make.Import(
- Position.NOPOS, javalang, new Name[]{Names.IMPORT_WILDCARD})
- .setSymbol(definitions.JAVALANG)
- .setType(definitions.UNIT_TYPE());
- startContext.imports = new ImportList(
- importjavalang, startContext.scope, startContext.imports);
-
- Tree scala = make.Ident(Position.NOPOS, Names.scala)
- .setSymbol(definitions.SCALA)
- .setType(Type.singleType(definitions.ROOT_TYPE, definitions.SCALA));
- Tree importscala = make.Import(
- Position.NOPOS, scala, new Name[]{Names.IMPORT_WILDCARD})
- .setSymbol(definitions.SCALA)
- .setType(definitions.UNIT_TYPE());
- startContext.imports = new ImportList(
- importscala, new Scope(), startContext.imports);
+ addImport(startContext, definitions.getModule(Names.java_lang));
+ addImport(startContext, definitions.getModule(Names.scala));
}
if (!global.noimports && !global.nopredefs) {
- TreeFactory make = global.make;
-
- Tree scala = make.Ident(Position.NOPOS, Names.scala)
- .setSymbol(definitions.SCALA)
- .setType(Type.singleType(definitions.ROOT_TYPE, definitions.SCALA));
- Symbol scalaPredefSym = definitions.getModule(Names.scala_Predef);
- Tree scalaPredef = make.Select(Position.NOPOS, scala, Names.Predef)
- .setSymbol(scalaPredefSym)
- .setType(Type.singleType(scala.type, scalaPredefSym));
-
- Tree importscalaPredef = make.Import(
- Position.NOPOS, scalaPredef, new Name[]{Names.IMPORT_WILDCARD})
- .setSymbol(scalaPredefSym)
- .setType(definitions.UNIT_TYPE());
- startContext.imports = new ImportList(
- importscalaPredef, new Scope(), startContext.imports);
+ addImport(startContext, definitions.getModule(Names.scala_Predef));
}
this.consoleContext = new Context(
@@ -87,20 +51,15 @@ public class AnalyzerPhase extends Phase {
startContext);
}
- public void addConsoleImport(Global global, Symbol module) {
- Definitions definitions = global.definitions;
- TreeFactory make = global.make;
-
- Tree console = make.Ident(Position.NOPOS, module.name)
- .setSymbol(module)
- .setType(Type.singleType(definitions.ROOT_TYPE, module));
+ public void addConsoleImport(Symbol module) {
+ addImport(consoleContext, module);
+ }
- Tree importConsole = make.Import(
- Position.NOPOS, console, new Name[]{Names.IMPORT_WILDCARD})
- .setSymbol(module)
- .setType(definitions.UNIT_TYPE());
- consoleContext.imports = new ImportList(
- importConsole, new Scope(), consoleContext.imports);
+ private void addImport(Context context, Symbol module) {
+ global.prevPhase();
+ Tree tree = global.treeGen.mkImportAll(Position.NOPOS, module);
+ global.nextPhase();
+ context.imports = new ImportList(tree, new Scope(), context.imports);
}
public void apply(Unit[] units) {