@@ -75,11 +75,11 @@ struct _DebugContext {
7575}
7676
7777/** Create new DebugContext */
78- pub fn mk_ctxt ( llmod : ModuleRef , crate : ~str , intr : @ ident_interner ) -> DebugContext {
78+ pub fn mk_ctxt ( llmod : ModuleRef , crate : ~str ) -> DebugContext {
7979 debug ! ( "mk_ctxt" ) ;
8080 let builder = unsafe { llvm:: LLVMDIBuilderCreate ( llmod) } ;
8181 let dcx = @mut _DebugContext {
82- names : new_namegen ( intr ) ,
82+ names : new_namegen ( ) ,
8383 crate_file: crate ,
8484 builder : builder,
8585 curr_loc : ( 0 , 0 ) ,
@@ -114,33 +114,9 @@ pub fn finalize(cx: @CrateContext) {
114114 } ;
115115}
116116
117- fn filename_from_span ( cx : @CrateContext , sp : codemap:: span ) -> ~str {
118- /*bad*/ copy cx. sess . codemap . lookup_char_pos ( sp. lo ) . file . name
119- }
120-
121- //fn filename_from_span<'cx>(cx: &'cx CrateContext, sp: codemap::span) -> &'cx str {
122- // let fname: &str = cx.sess.codemap.lookup_char_pos(sp.lo).file.name;
123- // return fname;
124- //}
125-
126- fn get_file_path_and_dir ( work_dir : & str , full_path : & str ) -> ( ~str , ~str ) {
127- let full_path =
128- if str:: starts_with ( full_path, work_dir) {
129- str:: slice ( full_path, str:: len ( work_dir) + 1 u,
130- str:: len ( full_path) ) . to_owned ( )
131- } else {
132- full_path. to_owned ( )
133- } ;
134-
135- return ( full_path, work_dir. to_owned ( ) ) ;
136- }
137-
138117fn create_compile_unit ( cx : @CrateContext ) {
139118 let crate_name: & str = dbg_cx ( cx) . crate_file ;
140-
141- let ( _, work_dir) = get_file_path_and_dir (
142- cx. sess . working_dir . to_str ( ) , crate_name) ;
143-
119+ let work_dir = cx. sess . working_dir . to_str ( ) ;
144120 let producer = fmt ! ( "rustc version %s" , env!( "CFG_VERSION" ) ) ;
145121
146122 do as_c_str( crate_name) |crate_name| {
@@ -158,29 +134,33 @@ fn create_compile_unit(cx: @CrateContext) {
158134fn create_file ( cx : @CrateContext , full_path : & str ) -> DIFile {
159135 let dcx = dbg_cx ( cx) ;
160136
161- match dcx. created_files . find ( & full_path. to_owned ( ) ) {
137+ match dcx. created_files . find_equiv ( & full_path) {
162138 Some ( file_md) => return * file_md,
163139 None => ( )
164140 }
165141
166142 debug ! ( "create_file: %s" , full_path) ;
167143
168- let ( file_path, work_dir) =
169- get_file_path_and_dir ( cx. sess . working_dir . to_str ( ) ,
170- full_path) ;
171-
144+ let work_dir = cx. sess . working_dir . to_str ( ) ;
145+ let file_name =
146+ if full_path. starts_with ( work_dir) {
147+ full_path. slice ( work_dir. len ( ) + 1 u, full_path. len ( ) )
148+ } else {
149+ full_path
150+ } ;
151+
172152 let file_md =
173- do as_c_str ( file_path ) |file_path | {
153+ do as_c_str ( file_name ) |file_name | {
174154 do as_c_str ( work_dir) |work_dir| { unsafe {
175- llvm:: LLVMDIBuilderCreateFile ( dcx. builder , file_path , work_dir)
155+ llvm:: LLVMDIBuilderCreateFile ( dcx. builder , file_name , work_dir)
176156 } } } ;
177157
178158 dcx. created_files . insert ( full_path. to_owned ( ) , file_md) ;
179159 return file_md;
180160}
181161
182- fn line_from_span ( cm : @codemap :: CodeMap , sp : span ) -> uint {
183- cm . lookup_char_pos ( sp . lo ) . line
162+ fn span_start ( cx : @CrateContext , span : span ) -> codemap :: Loc {
163+ return cx . sess . codemap . lookup_char_pos ( span . lo ) ;
184164}
185165
186166fn create_block ( bcx : block ) -> DILexicalBlock {
@@ -194,31 +174,29 @@ fn create_block(bcx: block) -> DILexicalBlock {
194174 None => fail ! ( )
195175 }
196176 }
197- let sp = bcx. node_info . get ( ) . span ;
177+ let span = bcx. node_info . get ( ) . span ;
198178 let id = bcx. node_info . get ( ) . id ;
199179
200180 match dcx. created_blocks . find ( & id) {
201181 Some ( block) => return * block,
202182 None => ( )
203183 }
204184
205- debug ! ( "create_block: %s" , bcx. sess( ) . codemap. span_to_str( sp) ) ;
206-
207- let start = bcx. sess ( ) . codemap . lookup_char_pos ( sp. lo ) ;
208- //let end = bcx.sess().codemap.lookup_char_pos(sp.hi);
185+ debug ! ( "create_block: %s" , bcx. sess( ) . codemap. span_to_str( span) ) ;
209186
210187 let parent = match bcx. parent {
211188 None => create_function ( bcx. fcx ) ,
212189 Some ( b) => create_block ( b)
213190 } ;
214-
215- let file_md = create_file ( bcx. ccx ( ) , start. file . name ) ;
191+ let cx = bcx. ccx ( ) ;
192+ let loc = span_start ( cx, span) ;
193+ let file_md = create_file ( cx, loc. file . name ) ;
216194
217195 let block_md = unsafe {
218196 llvm:: LLVMDIBuilderCreateLexicalBlock (
219197 dcx. builder ,
220198 parent, file_md,
221- start . line . to_int ( ) as c_uint , start . col . to_int ( ) as c_uint )
199+ loc . line as c_uint , loc . col . to_uint ( ) as c_uint )
222200 } ;
223201
224202 dcx. created_blocks . insert ( id, block_md) ;
@@ -342,18 +320,16 @@ impl StructContext {
342320}
343321
344322fn create_struct ( cx : @CrateContext , t : ty:: t , fields : ~[ ty:: field ] , span : span ) -> DICompositeType {
345- let fname = filename_from_span ( cx, span) ;
346- let file_md = create_file ( cx, fname) ;
347- let line = line_from_span ( cx. sess . codemap , span) ;
323+ let loc = span_start ( cx, span) ;
324+ let file_md = create_file ( cx, loc. file . name ) ;
348325
349- let mut scx = StructContext :: create ( cx, file_md, ty_to_str ( cx. tcx , t) , line) ;
326+ let mut scx = StructContext :: create ( cx, file_md, ty_to_str ( cx. tcx , t) , loc . line ) ;
350327 for fields. each |field| {
351328 let field_t = field. mt . ty ;
352329 let ty_md = create_ty ( cx, field_t, span) ;
353330 let ( size, align) = size_and_align_of ( cx, field_t) ;
354331 scx. add_member ( cx. sess . str_of ( field. ident ) ,
355- line_from_span ( cx. sess . codemap , span) ,
356- size, align, ty_md) ;
332+ loc. line , size, align, ty_md) ;
357333 }
358334 return scx. finalize ( ) ;
359335}
@@ -371,25 +347,24 @@ fn voidptr(cx: @CrateContext) -> (DIDerivedType, uint, uint) {
371347
372348fn create_tuple ( cx : @CrateContext , t : ty:: t , elements : & [ ty:: t ] , span : span ) -> DICompositeType {
373349 let dcx = dbg_cx ( cx) ;
374- let fname = filename_from_span ( cx, span) ;
375- let file_md = create_file ( cx, fname ) ;
350+ let loc = span_start ( cx, span) ;
351+ let file_md = create_file ( cx, loc . file . name ) ;
376352
377353 let name = ( cx. sess . str_of ( ( dcx. names ) ( "tuple" ) ) ) . to_owned ( ) ;
378354 let mut scx = StructContext :: create ( cx, file_md, name, loc. line ) ;
379355
380356 for elements. each |element| {
381357 let ty_md = create_ty ( cx, * element, span) ;
382358 let ( size, align) = size_and_align_of ( cx, * element) ;
383- scx. add_member ( "" , line_from_span ( cx. sess . codemap , span) ,
384- size, align, ty_md) ;
359+ scx. add_member ( "" , loc. line , size, align, ty_md) ;
385360 }
386361 return scx. finalize ( ) ;
387362}
388363
389364fn create_boxed_type ( cx : @CrateContext , contents : ty:: t ,
390365 span : span , boxed : DIType ) -> DICompositeType {
391- let fname = filename_from_span ( cx, span) ;
392- let file_md = create_file ( cx, fname ) ;
366+ let loc = span_start ( cx, span) ;
367+ let file_md = create_file ( cx, loc . file . name ) ;
393368 let int_t = ty:: mk_int ( ) ;
394369 let refcount_type = create_basic_type ( cx, int_t, span) ;
395370 let name = ty_to_str ( cx. tcx , contents) ;
@@ -412,8 +387,8 @@ fn create_fixed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
412387 len : uint , span : span ) -> DIType {
413388 let dcx = dbg_cx ( cx) ;
414389 let elem_ty_md = create_ty ( cx, elem_t, span) ;
415- let fname = filename_from_span ( cx, span) ;
416- let file_md = create_file ( cx, fname ) ;
390+ let loc = span_start ( cx, span) ;
391+ let file_md = create_file ( cx, loc . file . name ) ;
417392 let ( size, align) = size_and_align_of ( cx, elem_t) ;
418393
419394 let subrange = unsafe {
@@ -427,10 +402,10 @@ fn create_fixed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
427402}
428403
429404fn create_boxed_vec ( cx : @CrateContext , vec_t : ty:: t , elem_t : ty:: t ,
430- vec_ty_span : codemap :: span ) -> DICompositeType {
405+ vec_ty_span : span ) -> DICompositeType {
431406 let dcx = dbg_cx ( cx) ;
432- let fname = filename_from_span ( cx, vec_ty_span) ;
433- let file_md = create_file ( cx, fname ) ;
407+ let loc = span_start ( cx, vec_ty_span) ;
408+ let file_md = create_file ( cx, loc . file . name ) ;
434409 let elem_ty_md = create_ty ( cx, elem_t, vec_ty_span) ;
435410
436411 let mut vec_scx = StructContext :: create ( cx, file_md, ty_to_str ( cx. tcx , vec_t) , 0 ) ;
@@ -468,8 +443,8 @@ fn create_boxed_vec(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t,
468443}
469444
470445fn create_vec_slice ( cx : @CrateContext , vec_t : ty:: t , elem_t : ty:: t , span : span ) -> DICompositeType {
471- let fname = filename_from_span ( cx, span) ;
472- let file_md = create_file ( cx, fname ) ;
446+ let loc = span_start ( cx, span) ;
447+ let file_md = create_file ( cx, loc . file . name ) ;
473448 let elem_ty_md = create_ty ( cx, elem_t, span) ;
474449 let uint_type = create_basic_type ( cx, ty:: mk_uint ( ) , span) ;
475450 let elem_ptr = create_pointer_type ( cx, elem_t, span, elem_ty_md) ;
@@ -485,8 +460,8 @@ fn create_vec_slice(cx: @CrateContext, vec_t: ty::t, elem_t: ty::t, span: span)
485460fn create_fn_ty ( cx : @CrateContext , fn_ty : ty:: t , inputs : ~[ ty:: t ] , output : ty:: t ,
486461 span : span ) -> DICompositeType {
487462 let dcx = dbg_cx ( cx) ;
488- let fname = filename_from_span ( cx, span) ;
489- let file_md = create_file ( cx, fname ) ;
463+ let loc = span_start ( cx, span) ;
464+ let file_md = create_file ( cx, loc . file . name ) ;
490465 let ( vp, _, _) = voidptr ( cx) ;
491466 let output_md = create_ty ( cx, output, span) ;
492467 let output_ptr_md = create_pointer_type ( cx, output, span, output_md) ;
@@ -593,7 +568,7 @@ pub fn create_local_var(bcx: block, local: @ast::local) -> DIVariable {
593568 } ;
594569 let name: & str = cx. sess . str_of ( ident) ;
595570 debug ! ( "create_local_var: %s" , name) ;
596-
571+
597572 let loc = span_start ( cx, local. span ) ;
598573 let ty = node_id_type ( bcx, local. node . id ) ;
599574 let tymd = create_ty ( cx, ty, local. node . ty . span ) ;
@@ -629,12 +604,12 @@ pub fn create_local_var(bcx: block, local: @ast::local) -> DIVariable {
629604 return var_md;
630605}
631606
632- pub fn create_arg ( bcx : block , arg : ast:: arg , sp : span ) -> Option < DIVariable > {
607+ pub fn create_arg ( bcx : block , arg : ast:: arg , span : span ) -> Option < DIVariable > {
633608 debug ! ( "create_arg" ) ;
634609 let fcx = bcx. fcx , cx = * fcx. ccx ;
635610 let dcx = dbg_cx ( cx) ;
636611
637- let loc = cx . sess . codemap . lookup_char_pos ( sp . lo ) ;
612+ let loc = span_start ( cx , span ) ;
638613 if "<intrinsic>" == loc. file . name {
639614 return None ;
640615 }
@@ -654,7 +629,7 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span) -> Option<DIVariable> {
654629 let ident = path. idents . last ( ) ;
655630 let name: & str = cx. sess . str_of ( * ident) ;
656631 let mdnode = do as_c_str ( name) |name| { unsafe {
657- llvm:: LLVMDIBuilderCreateLocalVariable ( dcx. builder ,
632+ llvm:: LLVMDIBuilderCreateLocalVariable ( dcx. builder ,
658633 ArgVariableTag as u32 , context, name,
659634 filemd, loc. line as c_uint , tymd, false , 0 , 0 )
660635 // FIXME need to pass a real argument number
@@ -681,16 +656,15 @@ fn set_debug_location(bcx: block, line: uint, col: uint) {
681656 }
682657}
683658
684- pub fn update_source_pos ( bcx : block , sp : span ) {
685- if !bcx. sess ( ) . opts . debuginfo || ( * sp . lo == 0 && * sp . hi == 0 ) {
659+ pub fn update_source_pos ( bcx : block , span : span ) {
660+ if !bcx. sess ( ) . opts . debuginfo || ( * span . lo == 0 && * span . hi == 0 ) {
686661 return ;
687662 }
688663
689- debug ! ( "update_source_pos: %s" , bcx. sess( ) . codemap. span_to_str( sp ) ) ;
664+ debug ! ( "update_source_pos: %s" , bcx. sess( ) . codemap. span_to_str( span ) ) ;
690665
691- let cm = bcx. sess ( ) . codemap ;
692- let loc = cm. lookup_char_pos ( sp. lo ) ;
693666 let cx = bcx. ccx ( ) ;
667+ let loc = span_start ( cx, span) ;
694668 let mut dcx = dbg_cx ( cx) ;
695669
696670 let loc = ( loc. line , loc. col . to_uint ( ) ) ;
@@ -706,7 +680,7 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
706680 let cx = * fcx. ccx ;
707681 let mut dcx = dbg_cx ( cx) ;
708682 let fcx = & mut * fcx;
709- let sp = fcx. span . get ( ) ;
683+ let span = fcx. span . get ( ) ;
710684
711685 let ( ident, ret_ty, id) = match cx. tcx . items . get_copy ( & fcx. id ) {
712686 ast_map:: node_item( item, _) => {
@@ -739,7 +713,7 @@ pub fn create_function(fcx: fn_ctxt) -> DISubprogram {
739713
740714 debug ! ( "create_function: %s, %s" , cx. sess. str_of( ident) , cx. sess. codemap. span_to_str( span) ) ;
741715
742- let loc = cx . sess . codemap . lookup_char_pos ( sp . lo ) ;
716+ let loc = span_start ( cx , span ) ;
743717 let file_md = create_file ( cx, loc. file . name ) ;
744718
745719 let ret_ty_md = if cx. sess . opts . extra_debuginfo {
0 commit comments