@@ -4,6 +4,8 @@ import syntax::ast::*;
4
4
import syntax:: ast_util;
5
5
import syntax:: ast_util:: inlined_item_methods;
6
6
import syntax:: { visit, codemap} ;
7
+ import driver:: session:: session;
8
+ import front:: attr;
7
9
8
10
enum path_elt { path_mod( str ) , path_name( str ) }
9
11
type path = [ path_elt ] ;
@@ -24,20 +26,21 @@ fn path_to_str(p: path) -> str {
24
26
25
27
enum ast_node {
26
28
node_item( @item, @path) ,
27
- node_native_item( @native_item , @path) ,
29
+ node_native_item( @native_item , native_abi , @path) ,
28
30
node_method( @method , def_id /* impl did */ , @path /* path to the impl */ ) ,
29
- node_variant( variant , def_id , @path) ,
31
+ node_variant( variant , @item , @path) ,
30
32
node_expr( @expr) ,
31
33
node_export( @view_path , @path) ,
32
34
// Locals are numbered, because the alias analysis needs to know in which
33
35
// order they are introduced.
34
36
node_arg( arg , uint ) ,
35
37
node_local( uint ) ,
36
- node_res_ctor ( @item) ,
38
+ node_ctor ( @item) ,
37
39
}
38
40
39
41
type map = std:: map:: hashmap < node_id , ast_node > ;
40
- type ctx = { map : map , mutable path: path, mutable local_id : uint } ;
42
+ type ctx = { map : map , mutable path: path,
43
+ mutable local_id: uint , sess : session } ;
41
44
type vt = visit:: vt < ctx > ;
42
45
43
46
fn extend ( cx : ctx , elt : str ) -> @path {
@@ -47,7 +50,6 @@ fn extend(cx: ctx, elt: str) -> @path {
47
50
fn mk_ast_map_visitor ( ) -> vt {
48
51
ret visit:: mk_vt ( @{
49
52
visit_item: map_item,
50
- visit_native_item: map_native_item,
51
53
visit_expr: map_expr,
52
54
visit_fn: map_fn,
53
55
visit_local: map_local,
@@ -57,18 +59,19 @@ fn mk_ast_map_visitor() -> vt {
57
59
} ) ;
58
60
}
59
61
60
- fn map_crate ( c: crate ) -> map {
62
+ fn map_crate ( sess : session , c: crate ) -> map {
61
63
let cx = { map: std:: map:: new_int_hash ( ) ,
62
64
mutable path: [ ] ,
63
- mutable local_id: 0 u} ;
65
+ mutable local_id: 0 u,
66
+ sess: sess} ;
64
67
visit:: visit_crate ( c, cx, mk_ast_map_visitor ( ) ) ;
65
68
ret cx. map ;
66
69
}
67
70
68
71
// Used for items loaded from external crate that are being inlined into this
69
72
// crate. The `path` should be the path to the item but should not include
70
73
// the item itself.
71
- fn map_decoded_item ( map : map , path : path , ii : inlined_item ) {
74
+ fn map_decoded_item ( sess : session , map : map , path : path , ii : inlined_item ) {
72
75
// I believe it is ok for the local IDs of inlined items from other crates
73
76
// to overlap with the local ids from this crate, so just generate the ids
74
77
// starting from 0. (In particular, I think these ids are only used in
@@ -77,7 +80,8 @@ fn map_decoded_item(map: map, path: path, ii: inlined_item) {
77
80
// variables that are simultaneously in scope).
78
81
let cx = { map: map,
79
82
mutable path: path,
80
- mutable local_id: 0 u} ;
83
+ mutable local_id: 0 u,
84
+ sess: sess} ;
81
85
let v = mk_ast_map_visitor ( ) ;
82
86
83
87
// methods get added to the AST map when their impl is visited. Since we
@@ -86,7 +90,7 @@ fn map_decoded_item(map: map, path: path, ii: inlined_item) {
86
90
alt ii {
87
91
ii_item( i) { /* fallthrough */ }
88
92
ii_method ( impl_did, m) {
89
- map_method ( impl_did, @vec :: init ( path) , m, cx) ;
93
+ map_method ( impl_did, @path, m, cx) ;
90
94
}
91
95
}
92
96
@@ -137,19 +141,31 @@ fn map_item(i: @item, cx: ctx, v: vt) {
137
141
item_impl ( _, _, _, ms) {
138
142
let impl_did = ast_util:: local_def ( i. id ) ;
139
143
for m in ms {
140
- map_method ( impl_did, item_path , m, cx) ;
144
+ map_method ( impl_did, extend ( cx , i . ident ) , m, cx) ;
141
145
}
142
146
}
143
147
item_res ( _, _, _, dtor_id, ctor_id) {
144
- cx. map . insert ( ctor_id, node_res_ctor ( i) ) ;
148
+ cx. map . insert ( ctor_id, node_ctor ( i) ) ;
145
149
cx. map . insert ( dtor_id, node_item ( i, item_path) ) ;
146
150
}
147
151
item_enum ( vs, _) {
148
152
for v in vs {
149
153
cx. map . insert ( v. node . id , node_variant (
150
- v, ast_util :: local_def ( i . id ) , extend ( cx, i. ident ) ) ) ;
154
+ v, i , extend ( cx, i. ident ) ) ) ;
151
155
}
152
156
}
157
+ item_native_mod ( nm) {
158
+ let abi = alt attr:: native_abi ( i. attrs ) {
159
+ either:: left ( msg) { cx. sess . span_fatal ( i. span , msg) ; }
160
+ either:: right ( abi) { abi }
161
+ } ;
162
+ for nitem in nm. items {
163
+ cx. map . insert ( nitem. id , node_native_item ( nitem, abi, @cx. path ) ) ;
164
+ }
165
+ }
166
+ item_class ( _, _, ctor) {
167
+ cx. map . insert ( ctor. node . id , node_ctor ( i) ) ;
168
+ }
153
169
_ { }
154
170
}
155
171
alt i. node {
@@ -179,11 +195,6 @@ fn map_view_item(vi: @view_item, cx: ctx, _v: vt) {
179
195
}
180
196
}
181
197
182
- fn map_native_item ( i : @native_item , cx : ctx , v : vt ) {
183
- cx. map . insert ( i. id , node_native_item ( i, @cx. path ) ) ;
184
- visit:: visit_native_item ( i, cx, v) ;
185
- }
186
-
187
198
fn map_expr ( ex : @expr, cx : ctx , v : vt ) {
188
199
cx. map . insert ( ex. id , node_expr ( ex) ) ;
189
200
visit:: visit_expr ( ex, cx, v) ;
0 commit comments