@@ -82,8 +82,8 @@ fn encode_class_item_paths(ebml_w: ebml::writer,
82
82
priv { cont; }
83
83
pub {
84
84
let ( id, ident) = alt it. node . decl {
85
- instance_var ( v, _, _, vid) { ( vid, v) }
86
- class_method ( it) { ( it. id , it. ident ) }
85
+ instance_var ( v, _, _, vid) { ( vid, v) }
86
+ class_method ( it) { ( it. id , it. ident ) }
87
87
} ;
88
88
add_to_index ( ebml_w, path, index, ident) ;
89
89
encode_named_def_id ( ebml_w, ident, local_def ( id) ) ;
@@ -145,18 +145,18 @@ fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
145
145
ebml_w. end_tag ( ) ;
146
146
}
147
147
item_class ( tps, items, ctor) {
148
- add_to_index ( ebml_w, path, index, it. ident ) ;
149
- ebml_w. start_tag ( tag_paths_data_item) ;
150
- encode_name ( ebml_w, it. ident ) ;
151
- encode_def_id ( ebml_w, local_def ( it. id ) ) ;
152
- ebml_w. end_tag ( ) ;
153
- ebml_w. start_tag ( tag_paths) ;
154
- add_to_index ( ebml_w, path, index, it. ident ) ;
155
- #debug ( "ctor id: %d" , ctor. node . id ) ;
156
- encode_named_def_id ( ebml_w, it. ident , local_def ( ctor. node . id ) ) ;
157
- encode_class_item_paths ( ebml_w, items, path + [ it. ident ] ,
148
+ add_to_index ( ebml_w, path, index, it. ident ) ;
149
+ ebml_w. start_tag ( tag_paths_data_item) ;
150
+ encode_name ( ebml_w, it. ident ) ;
151
+ encode_def_id ( ebml_w, local_def ( it. id ) ) ;
152
+ ebml_w. end_tag ( ) ;
153
+ ebml_w. start_tag ( tag_paths) ;
154
+ add_to_index ( ebml_w, path, index, it. ident ) ;
155
+ #debug ( "ctor id: %d" , ctor. node . id ) ;
156
+ encode_named_def_id ( ebml_w, it. ident , local_def ( ctor. node . id ) ) ;
157
+ encode_class_item_paths ( ebml_w, items, path + [ it. ident ] ,
158
158
index) ;
159
- ebml_w. end_tag ( ) ;
159
+ ebml_w. end_tag ( ) ;
160
160
}
161
161
item_enum ( variants, tps) {
162
162
add_to_index ( ebml_w, path, index, it. ident ) ;
@@ -252,7 +252,12 @@ fn encode_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) {
252
252
253
253
fn encode_symbol ( ecx : @encode_ctxt , ebml_w : ebml:: writer , id : node_id ) {
254
254
ebml_w. start_tag ( tag_items_data_item_symbol) ;
255
- ebml_w. writer . write ( str:: bytes ( ecx. ccx . item_symbols . get ( id) ) ) ;
255
+ let sym = alt ecx. ccx . item_symbols . find ( id) {
256
+ some ( x) { x }
257
+ none { ecx. ccx . tcx . sess . bug ( #fmt ( "encode_symbol: \
258
+ id not found %d", id) ) ; }
259
+ } ;
260
+ ebml_w. writer . write ( str:: bytes ( sym) ) ;
256
261
ebml_w. end_tag ( ) ;
257
262
}
258
263
@@ -346,43 +351,53 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod,
346
351
ebml_w. end_tag ( ) ;
347
352
}
348
353
354
+ /* Returns an index of items in this class */
349
355
fn encode_info_for_class ( ecx : @encode_ctxt , ebml_w : ebml:: writer ,
350
356
id : node_id , path : ast_map:: path , name : ident ,
351
- tps : [ ty_param ] , items : [ @class_item ] ) {
357
+ tps : [ ty_param ] , items : [ @class_item ] )
358
+ -> [ entry < int > ] {
359
+ let index = @mutable [ ] ;
360
+
352
361
let tcx = ecx. ccx . tcx ;
353
362
encode_def_id ( ebml_w, local_def ( id) ) ;
354
363
encode_family ( ebml_w, 'C' ) ;
355
364
encode_type_param_bounds ( ebml_w, ecx, tps) ;
356
365
encode_type ( ecx, ebml_w, node_id_to_type ( tcx, id) ) ;
357
366
encode_name ( ebml_w, name) ;
367
+ encode_path ( ebml_w, path, ast_map:: path_name ( name) ) ;
358
368
359
369
for ci in items {
360
- /* We encode both private and public fields -- need to include
361
- private fields to get the offsets right */
362
- ebml_w. start_tag ( tag_items_class_member) ;
363
- alt ci. node . decl {
364
- instance_var ( nm, _, _, id) {
365
- #debug ( "encode_info_for_class: doing %s %d" , nm, id) ;
366
- encode_family ( ebml_w, 'g' ) ;
367
- encode_name ( ebml_w, nm) ;
368
- encode_type ( ecx, ebml_w, node_id_to_type ( tcx, id) ) ;
369
- /* TODO: mutability */
370
- encode_def_id ( ebml_w, local_def ( id) ) ;
371
- }
372
- class_method ( it) {
373
- encode_family ( ebml_w, 'h' ) ;
374
- encode_name ( ebml_w, it. ident ) ;
375
- alt it. node {
376
- item_fn ( fdecl, tps, _) {
377
- encode_info_for_fn ( ecx, ebml_w, it. id , it. ident ,
378
- path, none, tps, fdecl) ;
379
- }
380
- _ { fail; /* TODO */ }
381
- }
382
- }
383
- }
384
- ebml_w. end_tag ( ) ;
370
+ /* We encode both private and public fields -- need to include
371
+ private fields to get the offsets right */
372
+ alt ci. node . decl {
373
+ instance_var ( nm, _, _, id) {
374
+ * index += [ { val: id, pos: ebml_w. writer . tell ( ) } ] ;
375
+ ebml_w. start_tag ( tag_items_data_item) ;
376
+ #debug ( "encode_info_for_class: doing %s %d" , nm, id) ;
377
+ encode_family ( ebml_w, 'g' ) ;
378
+ encode_name ( ebml_w, nm) ;
379
+ encode_path ( ebml_w, path, ast_map:: path_name ( nm) ) ;
380
+ encode_type ( ecx, ebml_w, node_id_to_type ( tcx, id) ) ;
381
+ /* TODO: mutability */
382
+ encode_def_id ( ebml_w, local_def ( id) ) ;
383
+ }
384
+ class_method ( m) {
385
+ * index += [ { val: m. id , pos: ebml_w. writer . tell ( ) } ] ;
386
+ ebml_w. start_tag ( tag_items_data_item) ;
387
+ encode_family ( ebml_w, 'h' ) ;
388
+ encode_name ( ebml_w, m. ident ) ;
389
+ let impl_path = path + [ ast_map:: path_name ( m. ident ) ] ;
390
+ /*
391
+ Recall methods are (currently) monomorphic, and we don't
392
+ repeat the class's ty params in the method decl
393
+ */
394
+ encode_info_for_method ( ecx, ebml_w, impl_path,
395
+ should_inline ( m. attrs ) , id, m, [ ] ) ;
396
+ }
397
+ }
398
+ ebml_w. end_tag ( ) ;
385
399
}
400
+ * index
386
401
}
387
402
388
403
fn encode_info_for_fn ( ecx : @encode_ctxt , ebml_w : ebml:: writer ,
@@ -408,6 +423,28 @@ fn encode_info_for_fn(ecx: @encode_ctxt, ebml_w: ebml::writer,
408
423
ebml_w. end_tag ( ) ;
409
424
}
410
425
426
+ fn encode_info_for_method ( ecx : @encode_ctxt , ebml_w : ebml:: writer ,
427
+ impl_path : ast_map:: path , should_inline : bool ,
428
+ parent_id : node_id ,
429
+ m : @method , all_tps : [ ty_param ] ) {
430
+ #debug ( "encode_info_for_method: %d %s" , m. id , m. ident ) ;
431
+ ebml_w. start_tag ( tag_items_data_item) ;
432
+ encode_def_id ( ebml_w, local_def ( m. id ) ) ;
433
+ encode_family ( ebml_w, purity_fn_family ( m. decl . purity ) ) ;
434
+ encode_type_param_bounds ( ebml_w, ecx, all_tps) ;
435
+ encode_type ( ecx, ebml_w, node_id_to_type ( ecx. ccx . tcx , m. id ) ) ;
436
+ encode_name ( ebml_w, m. ident ) ;
437
+ encode_path ( ebml_w, impl_path, ast_map:: path_name ( m. ident ) ) ;
438
+ if all_tps. len ( ) > 0 u || should_inline {
439
+ astencode:: encode_inlined_item (
440
+ ecx, ebml_w, impl_path,
441
+ ii_method ( local_def ( parent_id) , m) ) ;
442
+ } else {
443
+ encode_symbol ( ecx, ebml_w, m. id ) ;
444
+ }
445
+ ebml_w. end_tag ( ) ;
446
+ }
447
+
411
448
fn purity_fn_family ( p : purity ) -> char {
412
449
alt p {
413
450
unsafe_fn { 'u' }
@@ -417,15 +454,17 @@ fn purity_fn_family(p: purity) -> char {
417
454
}
418
455
}
419
456
420
- fn encode_info_for_item ( ecx : @encode_ctxt , ebml_w : ebml:: writer , item: @item,
421
- index : @mutable [ entry < int > ] , path : ast_map:: path ) {
422
457
423
- fn should_inline ( attrs : [ attribute ] ) -> bool {
424
- alt attr:: find_inline_attr ( attrs) {
425
- attr:: ia_none { false }
426
- attr:: ia_hint | attr:: ia_always { true }
427
- }
458
+ fn should_inline ( attrs : [ attribute ] ) -> bool {
459
+ alt attr:: find_inline_attr ( attrs) {
460
+ attr:: ia_none { false }
461
+ attr:: ia_hint | attr:: ia_always { true }
428
462
}
463
+ }
464
+
465
+
466
+ fn encode_info_for_item ( ecx : @encode_ctxt , ebml_w : ebml:: writer , item: @item,
467
+ index : @mutable [ entry < int > ] , path : ast_map:: path ) {
429
468
430
469
let tcx = ecx. ccx . tcx ;
431
470
let must_write = alt item. node { item_enum ( _, _) { true } _ { false } } ;
@@ -494,11 +533,12 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
494
533
path, index, tps) ;
495
534
}
496
535
item_class ( tps, items, ctor) {
497
- /* We're not forgetting about the ctor here! It gets
498
- encoded elsewhere */
499
536
ebml_w. start_tag ( tag_items_data_item) ;
500
- encode_info_for_class ( ecx, ebml_w, item. id , path, item. ident ,
501
- tps, items) ;
537
+ let idx = encode_info_for_class ( ecx, ebml_w, item. id , path,
538
+ item. ident , tps, items) ;
539
+ /* each class must have its own index */
540
+ let bkts = create_index ( idx, hash_node_id) ;
541
+ encode_index ( ebml_w, bkts, write_int) ;
502
542
ebml_w. end_tag ( ) ;
503
543
}
504
544
item_res ( _, tps, _, _, ctor_id) {
@@ -553,21 +593,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
553
593
let impl_path = path + [ ast_map:: path_name ( item. ident ) ] ;
554
594
for m in methods {
555
595
* index += [ { val: m. id , pos: ebml_w. writer . tell ( ) } ] ;
556
- ebml_w. start_tag ( tag_items_data_item) ;
557
- encode_def_id ( ebml_w, local_def ( m. id ) ) ;
558
- encode_family ( ebml_w, purity_fn_family ( m. decl . purity ) ) ;
559
- encode_type_param_bounds ( ebml_w, ecx, tps + m. tps ) ;
560
- encode_type ( ecx, ebml_w, node_id_to_type ( tcx, m. id ) ) ;
561
- encode_name ( ebml_w, m. ident ) ;
562
- encode_path ( ebml_w, impl_path, ast_map:: path_name ( m. ident ) ) ;
563
- if tps. len ( ) > 0 u || m. tps . len ( ) > 0 u || should_inline ( m. attrs ) {
564
- astencode:: encode_inlined_item (
565
- ecx, ebml_w, impl_path,
566
- ii_method ( local_def ( item. id ) , m) ) ;
567
- } else {
568
- encode_symbol ( ecx, ebml_w, m. id ) ;
569
- }
570
- ebml_w. end_tag ( ) ;
596
+ encode_info_for_method ( ecx, ebml_w, impl_path,
597
+ should_inline ( m. attrs ) , item. id , m, tps + m. tps ) ;
571
598
}
572
599
}
573
600
item_iface ( tps, ms) {
0 commit comments