@@ -5,19 +5,23 @@ import std::option;
5
5
import std:: vec;
6
6
import std:: str;
7
7
import std:: io;
8
+ import std:: map:: hashmap;
8
9
import front:: ast;
9
10
import middle:: ty;
10
11
import tags:: * ;
11
12
import tydecode:: parse_def_id;
12
13
import tydecode:: parse_ty_data;
13
14
import driver:: session;
15
+ import util:: common;
16
+ import pretty:: pprust;
14
17
15
18
export get_symbol;
16
19
export get_tag_variants;
17
20
export get_type;
18
21
export lookup_defs;
19
22
export get_type;
20
23
export list_crate_metadata;
24
+ export get_exported_metadata;
21
25
22
26
fn lookup_hash( & ebml:: doc d, fn ( vec[ u8 ] ) -> bool eq_fn , uint hash) ->
23
27
vec[ ebml:: doc ] {
@@ -252,8 +256,35 @@ fn item_kind_to_str(u8 kind) -> str {
252
256
}
253
257
}
254
258
255
- fn list_crate_metadata( vec[ u8] bytes, io:: writer out) {
256
- auto md = ebml:: new_doc( bytes) ;
259
+ fn get_meta_items( & ebml:: doc md) -> vec[ ast:: meta_item] {
260
+ let vec[ ast:: meta_item] items = [ ] ;
261
+ for each ( ebml:: doc meta_item_doc in
262
+ ebml:: tagged_docs( md, tag_meta_item) ) {
263
+ auto kd = ebml:: get_doc( meta_item_doc, tag_meta_item_key) ;
264
+ auto vd = ebml:: get_doc( meta_item_doc, tag_meta_item_value) ;
265
+ auto k = str:: unsafe_from_bytes( ebml:: doc_data( kd) ) ;
266
+ auto v = str:: unsafe_from_bytes( ebml:: doc_data( vd) ) ;
267
+ items += [ rec( node=ast:: meta_key_value( k, v) ,
268
+ span=rec( lo=0 u, hi=0 u) ) ] ;
269
+ }
270
+ ret items;
271
+ }
272
+
273
+ fn list_meta_items( & ebml:: doc meta_items, io:: writer out) {
274
+ for ( ast:: meta_item mi in get_meta_items( meta_items) ) {
275
+ out. write_str( #fmt( "%s\n " , pprust:: meta_item_to_str( mi) ) ) ;
276
+ }
277
+ }
278
+
279
+ fn list_crate_attributes( & ebml:: doc md, io:: writer out) {
280
+ out. write_str( "=Crate=\n " ) ;
281
+ auto meta_items = ebml:: get_doc( md, tag_meta_export) ;
282
+ list_meta_items( meta_items, out) ;
283
+ out. write_str( "\n " ) ;
284
+ }
285
+
286
+ fn list_crate_items( vec[ u8] bytes, & ebml:: doc md, io:: writer out) {
287
+ out. write_str( "=Items=\n " ) ;
257
288
auto paths = ebml:: get_doc( md, tag_paths) ;
258
289
auto items = ebml:: get_doc( md, tag_items) ;
259
290
auto index = ebml:: get_doc( paths, tag_index) ;
@@ -270,8 +301,33 @@ fn list_crate_metadata(vec[u8] bytes, io::writer out) {
270
301
describe_def( items, did) ) ) ;
271
302
}
272
303
}
304
+ out. write_str( "\n " ) ;
305
+ }
306
+
307
+ fn list_crate_metadata( vec[ u8] bytes, io:: writer out) {
308
+ auto md = ebml:: new_doc( bytes) ;
309
+ list_crate_attributes( md, out) ;
310
+ list_crate_items( bytes, md, out) ;
273
311
}
274
312
313
+ fn get_exported_metadata( & session:: session sess, & str path, & vec[ u8] data) ->
314
+ hashmap[ str, str] {
315
+ auto meta_items =
316
+ ebml:: get_doc( ebml:: new_doc( data) , tag_meta_export) ;
317
+ auto mm = common:: new_str_hash[ str] ( ) ;
318
+ for each ( ebml:: doc m in
319
+ ebml:: tagged_docs( meta_items, tag_meta_item) ) {
320
+ auto kd = ebml:: get_doc( m, tag_meta_item_key) ;
321
+ auto vd = ebml:: get_doc( m, tag_meta_item_value) ;
322
+ auto k = str:: unsafe_from_bytes( ebml:: doc_data( kd) ) ;
323
+ auto v = str:: unsafe_from_bytes( ebml:: doc_data( vd) ) ;
324
+ log #fmt( "metadata in %s: %s = %s" , path, k, v) ;
325
+ if ( !mm. insert( k, v) ) {
326
+ sess. warn( #fmt( "Duplicate metadata item in %s: %s" , path, k) ) ;
327
+ }
328
+ }
329
+ ret mm;
330
+ }
275
331
276
332
// Local Variables:
277
333
// mode: rust
0 commit comments