blob: 7f3e82c659b1154b1e5ac68c62991aba6de63829 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/* ____ ____ ____ ____ ______ *\
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
** /_____/\____/\___/\____/____/ **
**
** $Id$
\* */
package scalac.typechecker;
import scalac.*;
import scalac.util.*;
import scalac.symtab.*;
import scalac.ast.*;
/////////////////////////////////////////////////////////////////////////////
// Import Lists
/////////////////////////////////////////////////////////////////////////////
class ImportList {
Tree tree; // The import definition
Scope enclscope; // The scope in which the import occurs.
ImportList prev; // The previous active import list.
ImportList(Tree tree, Scope enclscope, ImportList prev) {
this.tree = tree;
this.enclscope = enclscope;
this.prev = prev;
}
public String toString() {
String str = tree.symbol().toString();
if (prev != null) str = prev + "; " + str;
return str;
}
Tree importPrefix() {
switch (tree) {
case Import(Tree expr, _): return expr;
default: throw new ApplicationError();
}
}
Type importType() {
return tree.symbol().type();
}
boolean sameImport(ImportList that) {
return this.importType().isSameAs(that.importType());
}
Symbol importedSymbol(Name name) {
Type t = this.importType();
boolean renamed = false;
switch (tree) {
case Import(Tree expr, Name[] selectors):
for (int i = 0; i < selectors.length; i = i + 2) {
if (i + 1 < selectors.length && name.toTermName() == selectors[i + 1]) {
if (name.isTypeName())
return t.lookupNonPrivate(selectors[i].toTypeName());
else if (name.isConstrName())
return t.lookupNonPrivate(selectors[i].toConstrName());
else
return t.lookupNonPrivate(selectors[i]);
} else if (name.toTermName() == selectors[i]) {
renamed = true;
} else if (selectors[i] == Names.WILDCARD && !renamed) {
return t.lookupNonPrivate(name);
}
}
return Symbol.NONE;
default:
throw new ApplicationError();
}
}
}
|