@@ -2244,47 +2244,38 @@ pub fn trans_mod(ccx: @mut CrateContext, m: &ast::_mod) {
2244
2244
2245
2245
pub fn register_fn( ccx: @mut CrateContext ,
2246
2246
sp: span,
2247
- path: path,
2248
- node_id: ast:: node_id,
2249
- attrs: & [ ast:: Attribute ] )
2247
+ sym: ~str ,
2248
+ node_id: ast:: node_id)
2250
2249
-> ValueRef {
2251
2250
let t = ty:: node_id_to_type( ccx. tcx, node_id) ;
2252
- register_fn_full( ccx, sp, path , node_id, attrs , t)
2251
+ register_fn_full( ccx, sp, sym , node_id, t)
2253
2252
}
2254
2253
2255
2254
pub fn register_fn_full( ccx: @mut CrateContext ,
2256
2255
sp: span,
2257
- path : path ,
2256
+ sym : ~ str ,
2258
2257
node_id: ast:: node_id,
2259
- attrs: & [ ast:: Attribute ] ,
2260
2258
node_type: ty:: t)
2261
2259
-> ValueRef {
2262
2260
let llfty = type_of_fn_from_ty( ccx, node_type) ;
2263
- register_fn_fuller( ccx, sp, path , node_id, attrs , node_type,
2261
+ register_fn_fuller( ccx, sp, sym , node_id, node_type,
2264
2262
lib:: llvm:: CCallConv , llfty)
2265
2263
}
2266
2264
2267
2265
pub fn register_fn_fuller( ccx: @mut CrateContext ,
2268
2266
sp: span,
2269
- path : path ,
2267
+ sym : ~ str ,
2270
2268
node_id: ast:: node_id,
2271
- attrs: & [ ast:: Attribute ] ,
2272
2269
node_type: ty:: t,
2273
2270
cc: lib:: llvm:: CallConv ,
2274
2271
fn_ty: Type )
2275
2272
-> ValueRef {
2276
2273
debug!( "register_fn_fuller creating fn for item %d with path %s",
2277
2274
node_id,
2278
- ast_map:: path_to_str( path, token:: get_ident_interner( ) ) ) ;
2279
-
2280
- let ps = if attr:: contains_name( attrs, "no_mangle") {
2281
- path_elt_to_str( * path. last( ) , token:: get_ident_interner( ) )
2282
- } else {
2283
- mangle_exported_name( ccx, path, node_type)
2284
- } ;
2275
+ ast_map:: path_to_str( item_path( ccx, & node_id) , token:: get_ident_interner( ) ) ) ;
2285
2276
2286
- let llfn = decl_fn( ccx. llmod, ps , cc, fn_ty) ;
2287
- ccx. item_symbols. insert( node_id, ps ) ;
2277
+ let llfn = decl_fn( ccx. llmod, sym , cc, fn_ty) ;
2278
+ ccx. item_symbols. insert( node_id, sym ) ;
2288
2279
2289
2280
// FIXME #4404 android JNI hacks
2290
2281
let is_entry = is_entry_fn( & ccx. sess, node_id) && ( !* ccx. sess. building_library ||
@@ -2430,162 +2421,182 @@ pub fn fill_fn_pair(bcx: @mut Block, pair: ValueRef, llfn: ValueRef,
2430
2421
Store ( bcx, llenvblobptr, env_cell) ;
2431
2422
}
2432
2423
2433
- pub fn item_path( ccx: & CrateContext , i: & ast:: item) -> path {
2434
- let base = match ccx. tcx. items. get_copy( & i. id) {
2435
- ast_map:: node_item( _, p) => p,
2436
- // separate map for paths?
2424
+ pub fn item_path( ccx: & CrateContext , id: & ast:: node_id) -> path {
2425
+ match ccx. tcx. items. get_copy( id) {
2426
+ ast_map:: node_item( i, p) =>
2427
+ vec:: append( ( * p) . clone( ) , [ path_name( i. ident) ] ) ,
2428
+ // separate map for paths?
2437
2429
_ => fail!( "item_path")
2438
- } ;
2439
- vec:: append( ( * base) . clone( ) , [ path_name( i. ident) ] )
2430
+ }
2431
+ }
2432
+
2433
+ fn exported_name( ccx: @mut CrateContext , path: path, ty: ty:: t, attrs: & [ ast:: Attribute ] ) -> ~str {
2434
+ if attr:: contains_name( attrs, "no_mangle") {
2435
+ path_elt_to_str( * path. last( ) , token:: get_ident_interner( ) )
2436
+ } else {
2437
+ mangle_exported_name( ccx, path, ty)
2438
+ }
2440
2439
}
2441
2440
2442
2441
pub fn get_item_val( ccx: @mut CrateContext , id: ast:: node_id) -> ValueRef {
2443
2442
debug!( "get_item_val( id=`%?`) ", id) ;
2443
+
2444
2444
let val = ccx. item_vals. find_copy( & id) ;
2445
2445
match val {
2446
- Some ( v) => v,
2447
- None => {
2448
- let mut exprt = false;
2449
- let item = ccx. tcx. items. get_copy( & id) ;
2450
- let val = match item {
2451
- ast_map:: node_item( i, pth) => {
2452
- let my_path = vec:: append( ( * pth) . clone( ) , [ path_name( i. ident) ] ) ;
2453
- let v = match i. node {
2454
- ast:: item_static( _, m, expr) => {
2455
- let typ = ty:: node_id_to_type( ccx. tcx, i. id) ;
2456
- let s = mangle_exported_name( ccx, my_path, typ) ;
2457
- // We need the translated value here, because for enums the
2458
- // LLVM type is not fully determined by the Rust type.
2459
- let v = consts:: const_expr( ccx, expr) ;
2460
- ccx. const_values. insert( id, v) ;
2461
- exprt = m == ast:: m_mutbl;
2462
- unsafe {
2463
- let llty = llvm:: LLVMTypeOf ( v) ;
2464
- let g = do s. as_c_str |buf| {
2465
- llvm:: LLVMAddGlobal ( ccx. llmod, llty, buf)
2446
+ Some ( v) => v,
2447
+ None => {
2448
+ let mut exprt = false;
2449
+ let item = ccx. tcx. items. get_copy( & id) ;
2450
+ let val = match item {
2451
+ ast_map:: node_item( i, pth) => {
2452
+
2453
+ let my_path = vec:: append( ( * pth) . clone( ) , [ path_name( i. ident) ] ) ;
2454
+ let ty = ty:: node_id_to_type( ccx. tcx, i. id) ;
2455
+ let sym = exported_name( ccx, my_path, ty, i. attrs) ;
2456
+
2457
+ let v = match i. node {
2458
+ ast:: item_static( _, m, expr) => {
2459
+ // We need the translated value here, because for enums the
2460
+ // LLVM type is not fully determined by the Rust type.
2461
+ let v = consts:: const_expr( ccx, expr) ;
2462
+ ccx. const_values. insert( id, v) ;
2463
+ exprt = m == ast:: m_mutbl;
2464
+
2465
+ unsafe {
2466
+ let llty = llvm:: LLVMTypeOf ( v) ;
2467
+ let g = do sym. as_c_str |buf| {
2468
+ llvm:: LLVMAddGlobal ( ccx. llmod, llty, buf)
2469
+ } ;
2470
+
2471
+ ccx. item_symbols. insert( i. id, sym) ;
2472
+ g
2473
+ }
2474
+ }
2475
+
2476
+ ast:: item_fn( _, purity, _, _, _) => {
2477
+ let llfn = if purity != ast:: extern_fn {
2478
+ register_fn_full( ccx, i. span, sym, i. id, ty)
2479
+ } else {
2480
+ foreign:: register_foreign_fn( ccx, i. span, sym, i. id)
2481
+ } ;
2482
+ set_inline_hint_if_appr( i. attrs, llfn) ;
2483
+ llfn
2484
+ }
2485
+
2486
+ _ => fail!( "get_item_val: weird result in table")
2466
2487
} ;
2467
- ccx. item_symbols. insert( i. id, s) ;
2468
- g
2469
- }
2470
- }
2471
- ast:: item_fn( _, purity, _, _, _) => {
2472
- let llfn = if purity != ast:: extern_fn {
2473
- register_fn( ccx, i. span, my_path, i. id, i. attrs)
2474
- } else {
2475
- foreign:: register_foreign_fn( ccx,
2476
- i. span,
2477
- my_path,
2478
- i. id,
2479
- i. attrs)
2480
- } ;
2481
- set_inline_hint_if_appr( i. attrs, llfn) ;
2482
- llfn
2483
- }
2484
- _ => fail!( "get_item_val: weird result in table")
2485
- } ;
2486
- match ( attr:: first_attr_value_str_by_name ( i. attrs , "link_section" ) ) {
2487
- Some ( sect) => unsafe {
2488
- do sect. as_c_str |buf| {
2489
- llvm:: LLVMSetSection ( v, buf) ;
2488
+
2489
+ match ( attr:: first_attr_value_str_by_name ( i. attrs , "link_section" ) ) {
2490
+ Some ( sect) => unsafe {
2491
+ do sect. as_c_str |buf| {
2492
+ llvm:: LLVMSetSection ( v, buf) ;
2493
+ }
2494
+ } ,
2495
+ None => ( )
2490
2496
}
2491
- } ,
2492
- None => ( )
2493
- }
2494
- v
2495
- }
2496
- ast_map:: node_trait_method ( trait_method, _, pth) => {
2497
- debug ! ( "get_item_val(): processing a node_trait_method" ) ;
2498
- match * trait_method {
2499
- ast:: required( _) => {
2500
- ccx. sess . bug ( "unexpected variant: required trait method in \
2501
- get_item_val()") ;
2502
- }
2503
- ast:: provided( m) => {
2504
- exprt = true ;
2505
- register_method ( ccx, id, pth, m)
2506
- }
2507
- }
2508
- }
2509
- ast_map:: node_method ( m, _, pth) => {
2510
- register_method ( ccx, id, pth, m)
2511
- }
2512
- ast_map:: node_foreign_item ( ni, _, _, pth) => {
2513
- exprt = true ;
2514
- match ni. node {
2515
- ast:: foreign_item_fn( * ) => {
2516
- register_fn ( ccx, ni. span ,
2517
- vec:: append ( ( * pth) . clone ( ) ,
2518
- [ path_name ( ni. ident ) ] ) ,
2519
- ni. id ,
2520
- ni. attrs )
2497
+
2498
+ v
2521
2499
}
2522
- ast :: foreign_item_static ( * ) => {
2523
- let typ = ty :: node_id_to_type ( ccx . tcx , ni . id ) ;
2524
- let ident = token :: ident_to_str ( & ni . ident ) ;
2525
- let g = do ident . as_c_str |buf| {
2526
- unsafe {
2527
- let ty = type_of ( ccx , typ ) ;
2528
- llvm :: LLVMAddGlobal ( ccx . llmod , ty . to_ref ( ) , buf )
2500
+
2501
+ ast_map :: node_trait_method ( trait_method , _ , pth ) => {
2502
+ debug ! ( "get_item_val(): processing a node_trait_method" ) ;
2503
+ match * trait_method {
2504
+ ast :: required ( _ ) => {
2505
+ ccx . sess . bug ( "unexpected variant: required trait method in \
2506
+ get_item_val()" ) ;
2529
2507
}
2530
- } ;
2531
- g
2508
+ ast:: provided( m) => {
2509
+ exprt = true ;
2510
+ register_method ( ccx, id, pth, m)
2511
+ }
2512
+ }
2532
2513
}
2533
- }
2534
- }
2535
2514
2536
- ast_map:: node_variant ( ref v, enm, pth) => {
2537
- let llfn;
2538
- match v. node . kind {
2539
- ast:: tuple_variant_kind( ref args) => {
2540
- assert ! ( args. len( ) != 0 u) ;
2541
- let pth = vec:: append ( ( * pth) . clone ( ) ,
2542
- [ path_name ( enm. ident ) ,
2543
- path_name ( ( * v) . node . name ) ] ) ;
2544
- llfn = match enm. node {
2545
- ast:: item_enum( _, _) => {
2546
- register_fn ( ccx, ( * v) . span , pth, id, enm. attrs )
2547
- }
2548
- _ => fail ! ( "node_variant, shouldn't happen" )
2549
- } ;
2550
- }
2551
- ast:: struct_variant_kind( _) => {
2552
- fail ! ( "struct variant kind unexpected in get_item_val" )
2515
+ ast_map:: node_method ( m, _, pth) => {
2516
+ register_method ( ccx, id, pth, m)
2553
2517
}
2554
- }
2555
- set_inline_hint ( llfn) ;
2556
- llfn
2557
- }
2558
2518
2559
- ast_map:: node_struct_ctor( struct_def, struct_item, struct_path) => {
2560
- // Only register the constructor if this is a tuple-like struct.
2561
- match struct_def. ctor_id {
2562
- None => {
2563
- ccx. tcx . sess . bug ( "attempt to register a constructor of \
2564
- a non-tuple-like struct")
2519
+ ast_map:: node_foreign_item ( ni, _, _, pth) => {
2520
+ let ty = ty:: node_id_to_type ( ccx. tcx , ni. id ) ;
2521
+ exprt = true ;
2522
+
2523
+ match ni. node {
2524
+ ast:: foreign_item_fn( * ) => {
2525
+ let path = vec:: append ( ( * pth) . clone ( ) , [ path_name ( ni. ident ) ] ) ;
2526
+ let sym = exported_name ( ccx, path, ty, ni. attrs ) ;
2527
+
2528
+ register_fn_full ( ccx, ni. span , sym, ni. id , ty)
2529
+ }
2530
+ ast:: foreign_item_static( * ) => {
2531
+ let ident = token:: ident_to_str ( & ni. ident ) ;
2532
+ let g = do ident. as_c_str |buf| {
2533
+ unsafe {
2534
+ let ty = type_of ( ccx, ty) ;
2535
+ llvm:: LLVMAddGlobal ( ccx. llmod , ty. to_ref ( ) , buf)
2536
+ }
2537
+ } ;
2538
+ g
2539
+ }
2540
+ }
2565
2541
}
2566
- Some ( ctor_id) => {
2567
- let llfn = register_fn ( ccx,
2568
- struct_item. span ,
2569
- ( * struct_path) . clone ( ) ,
2570
- ctor_id,
2571
- struct_item. attrs ) ;
2542
+
2543
+ ast_map:: node_variant ( ref v, enm, pth) => {
2544
+ let llfn;
2545
+ match v. node . kind {
2546
+ ast:: tuple_variant_kind( ref args) => {
2547
+ assert ! ( args. len( ) != 0 u) ;
2548
+ let pth = vec:: append ( ( * pth) . clone ( ) ,
2549
+ [ path_name ( enm. ident ) ,
2550
+ path_name ( ( * v) . node . name ) ] ) ;
2551
+ let ty = ty:: node_id_to_type ( ccx. tcx , id) ;
2552
+ let sym = exported_name ( ccx, pth, ty, enm. attrs ) ;
2553
+
2554
+ llfn = match enm. node {
2555
+ ast:: item_enum( _, _) => {
2556
+ register_fn_full ( ccx, ( * v) . span , sym, id, ty)
2557
+ }
2558
+ _ => fail ! ( "node_variant, shouldn't happen" )
2559
+ } ;
2560
+ }
2561
+ ast:: struct_variant_kind( _) => {
2562
+ fail ! ( "struct variant kind unexpected in get_item_val" )
2563
+ }
2564
+ }
2572
2565
set_inline_hint ( llfn) ;
2573
2566
llfn
2574
2567
}
2568
+
2569
+ ast_map:: node_struct_ctor( struct_def, struct_item, struct_path) => {
2570
+ // Only register the constructor if this is a tuple-like struct.
2571
+ match struct_def. ctor_id {
2572
+ None => {
2573
+ ccx. tcx . sess . bug ( "attempt to register a constructor of \
2574
+ a non-tuple-like struct")
2575
+ }
2576
+ Some ( ctor_id) => {
2577
+ let ty = ty:: node_id_to_type ( ccx. tcx , ctor_id) ;
2578
+ let sym = exported_name ( ccx, ( * struct_path) . clone ( ) , ty,
2579
+ struct_item. attrs ) ;
2580
+ let llfn = register_fn_full ( ccx, struct_item. span , sym, ctor_id, ty) ;
2581
+ set_inline_hint ( llfn) ;
2582
+ llfn
2583
+ }
2584
+ }
2585
+ }
2586
+
2587
+ ref variant => {
2588
+ ccx. sess . bug ( fmt ! ( "get_item_val(): unexpected variant: %?" ,
2589
+ variant) )
2590
+ }
2591
+ } ;
2592
+
2593
+ if !exprt && !ccx. reachable . contains ( & id) {
2594
+ lib:: llvm:: SetLinkage ( val, lib:: llvm:: InternalLinkage ) ;
2575
2595
}
2576
- }
2577
2596
2578
- ref variant => {
2579
- ccx. sess . bug ( fmt ! ( "get_item_val(): unexpected variant: %?" ,
2580
- variant) )
2581
- }
2582
- } ;
2583
- if !exprt && !ccx. reachable . contains ( & id) {
2584
- lib:: llvm:: SetLinkage ( val, lib:: llvm:: InternalLinkage ) ;
2597
+ ccx. item_vals . insert ( id, val) ;
2598
+ val
2585
2599
}
2586
- ccx. item_vals . insert ( id, val) ;
2587
- val
2588
- }
2589
2600
}
2590
2601
}
2591
2602
@@ -2599,7 +2610,9 @@ pub fn register_method(ccx: @mut CrateContext,
2599
2610
path. push ( path_name ( gensym_name ( "meth" ) ) ) ;
2600
2611
path. push ( path_name ( m. ident ) ) ;
2601
2612
2602
- let llfn = register_fn_full ( ccx, m. span , path, id, m. attrs , mty) ;
2613
+ let sym = exported_name ( ccx, path, mty, m. attrs ) ;
2614
+
2615
+ let llfn = register_fn_full ( ccx, m. span , sym, id, mty) ;
2603
2616
set_inline_hint_if_appr ( m. attrs , llfn) ;
2604
2617
llfn
2605
2618
}
@@ -2613,7 +2626,7 @@ pub fn trans_constant(ccx: &mut CrateContext, it: @ast::item) {
2613
2626
ast:: def_id { crate : ast:: local_crate,
2614
2627
node : it. id } ) ;
2615
2628
let mut i = 0 ;
2616
- let path = item_path ( ccx, it ) ;
2629
+ let path = item_path ( ccx, & it . id ) ;
2617
2630
for ( * enum_definition) . variants. iter( ) . advance |variant| {
2618
2631
let p = vec:: append( path. clone( ) , [
2619
2632
path_name( variant. node. name) ,
0 commit comments