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
|
/* ____ ____ ____ ____ ______ *\
** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala **
** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL **
** /_____/\____/\___/\____/____/ **
\* */
// $Id$
package scalac.checkers;
import scalac.ast.Tree;
import scalac.symtab.Symbol;
import scalac.Global;
import scalac.util.Debug;
/**
* Verify that all tree nodes for which hasSymbol() is true have a
* non-null symbol.
*
* @author Michel Schinz
* @version 1.0
*/
public class CheckSymbols extends Checker {
public CheckSymbols(Global global) { super(global); }
public void check(Tree tree) {
verify(tree,
implies(tree.hasSymbol(), tree.symbol() != null),
"symbol not null",
"hasSymbol => symbol not null");
verify(tree,
implies(tree.hasSymbol(), tree.symbol() != Symbol.NONE),
"symbol not NONE",
"hasSymbol => symbol not NONE");
switch (tree) {
case ValDef(_, _, _, _):
case DefDef(_, _, _, _, _, _):
Symbol s1 = tree.symbol();
Symbol owner = s1.owner();
if (!owner.isClass())
break;
Symbol[] ss = owner.nextInfo()
.members().lookup(s1.name).alternativeSymbols();
int i;
for (i = 0; i < ss.length; i++) {
if (s1 == ss[i]) break;
}
verify(tree, i < ss.length, "symbol " + Debug.show(s1)
+ " should be in its owner scope",
Debug.show(owner.members()));
break;
}
}
}
|