blob: 090f0e58fb1c2365a69e126a0ec2dd56787daa46 (
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
|
/* ____ ____ ____ ____ ______ *\
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
** /_____/\____/\___/\____/____/ **
**
** $Id$
\* */
package scalac.typechecker;
import scalac.symtab.*;
import scalac.ast.Tree;
public class Context {
Tree tree; // Tree associated with this context
Symbol owner; // The current owner
Scope scope; // The current scope
ImportList imports; // The current import list
Context outer; // The next outer context
Context enclClass = this; // The next outer context whose tree
// is a class template
int variance; // Variance relative to eclosing class.
public Context() {}
public Context(Tree tree, Context outer) {
this(tree, outer.owner, outer.scope, outer);
}
public Context(Tree tree, Symbol owner, Scope scope, Context outer) {
this.tree = tree;
this.owner = owner;
this.scope = scope;
this.imports = outer.imports;
if (tree instanceof Tree.Template ||
tree instanceof Tree.CompoundType) this.enclClass = this;
else this.enclClass = outer.enclClass;
this.variance = outer.variance;
this.outer = outer;
}
public static Context NONE = new Context();
Context outerContext(Symbol clazz) {
Context c = this;
while (c != Context.NONE && c.owner != clazz) c = c.outer;
return c;
}
boolean isTopLevel() {
switch (tree) {
case Block(_):
return false;
case Template(_, _):
return outer.tree instanceof Tree.PackageDef;
case Empty:
return true;
default:
return outer.isTopLevel();
}
}
}
|