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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use middle::subst::ParamSpace;
use syntax::ast;
use syntax::ast_util::local_def;
use std::gc::Gc;
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
pub enum Def {
DefFn(ast::DefId, ast::FnStyle),
DefStaticMethod(ast::DefId, MethodProvenance, ast::FnStyle),
DefSelfTy(ast::NodeId),
DefMod(ast::DefId),
DefForeignMod(ast::DefId),
DefStatic(ast::DefId, bool),
DefArg(ast::NodeId, ast::BindingMode),
DefLocal(ast::NodeId, ast::BindingMode),
DefVariant(ast::DefId, ast::DefId, bool),
DefTy(ast::DefId),
DefTrait(ast::DefId),
DefPrimTy(ast::PrimTy),
DefTyParam(ParamSpace, ast::DefId, uint),
DefBinding(ast::NodeId, ast::BindingMode),
DefUse(ast::DefId),
DefUpvar(ast::NodeId,Gc<Def>,ast::NodeId,ast::NodeId),
DefStruct(ast::DefId),
DefTyParamBinder(ast::NodeId),DefRegion(ast::NodeId),
DefLabel(ast::NodeId),
DefMethod(ast::DefId, Option<ast::DefId>),
}
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
pub enum MethodProvenance {
FromTrait(ast::DefId),
FromImpl(ast::DefId),
}
impl Def {
pub fn def_id(&self) -> ast::DefId {
match *self {
DefFn(id, _) | DefStaticMethod(id, _, _) | DefMod(id) |
DefForeignMod(id) | DefStatic(id, _) |
DefVariant(_, id, _) | DefTy(id) | DefTyParam(_, id, _) |
DefUse(id) | DefStruct(id) | DefTrait(id) | DefMethod(id, _) => {
id
}
DefArg(id, _) |
DefLocal(id, _) |
DefSelfTy(id) |
DefUpvar(id, _, _, _) |
DefBinding(id, _) |
DefRegion(id) |
DefTyParamBinder(id) |
DefLabel(id) => {
local_def(id)
}
DefPrimTy(_) => fail!()
}
}
pub fn variant_def_ids(&self) -> Option<(ast::DefId, ast::DefId)> {
match *self {
DefVariant(enum_id, var_id, _) => {
Some((enum_id, var_id))
}
_ => None
}
}
}