@@ -565,12 +565,8 @@ package body Instrument.C is
565565 Last : Boolean;
566566 Pragma_Aspect_Name : Name_Id := Namet.No_Name)
567567 is
568- Loc : Source_Location_T :=
569- Get_Range_Start (Get_Cursor_Extent (N));
570-
571- Line, Column, Offset : aliased unsigned;
572- File : File_T;
573- Info : PP_Info;
568+ Loc : Source_Location_T := Get_Range_Start (Get_Cursor_Extent (N));
569+ Info : PP_Info;
574570 begin
575571 Append_SCO (C1, C2, From, To, Last, Pragma_Aspect_Name);
576572
@@ -591,14 +587,10 @@ package body Instrument.C is
591587 Expansion_Stack : Expansion_Lists.List;
592588 Definition_Info : Expansion_Info;
593589
594- Macro_Expansion_Name : US.Unbounded_String;
595- Immediate_Expansion_Loc_C : Source_Location_T;
596- Immediate_Expansion_Loc : Source_Location;
597-
598- Macro_Arg_Expanded_Loc_C : aliased Source_Location_T;
599- Macro_Arg_Expanded_Loc : Source_Location;
590+ Macro_Expansion_Name : US.Unbounded_String;
591+ Immediate_Expansion_Loc : Source_Location_T;
592+ Macro_Arg_Expanded_Loc : Source_Location_T;
600593 begin
601-
602594 -- Note: macro arguments are completely macro-expanded before they
603595 -- are substituted in a macro body, unless they are stringified or
604596 -- pasted with other tokens.
@@ -662,53 +654,26 @@ package body Instrument.C is
662654 -- So we have to get the macro argument expansion location, and
663655 -- get its spelling location.
664656
665- if Is_Macro_Arg_Expansion
666- (Loc, Macro_Arg_Expanded_Loc_C'Access , UIC.TU)
657+ if Is_Macro_Arg_Expansion (Loc, Macro_Arg_Expanded_Loc, UIC.TU)
667658 then
668- Get_Spelling_Location
669- (Macro_Arg_Expanded_Loc_C,
670- File'Address,
671- Line'Access ,
672- Column'Access ,
673- Offset'Access );
674- Macro_Arg_Expanded_Loc :=
675- (Source_File =>
676- Get_Index_From_Generic_Name
677- (Name => Get_File_Name (File),
678- Kind => Source_File),
679- L => (Natural (Line), Natural (Column)));
680-
681659 Macro_Expansion_Name :=
682660 +Get_Immediate_Macro_Name_For_Diagnostics
683- (Macro_Arg_Expanded_Loc_C , UIC.TU);
661+ (Macro_Arg_Expanded_Loc , UIC.TU);
684662
685663 Definition_Info :=
686664 (Macro_Name => Macro_Expansion_Name,
687- Sloc => Macro_Arg_Expanded_Loc);
665+ Sloc => Spelling_Location ( Macro_Arg_Expanded_Loc) );
688666 else
689- Get_Spelling_Location
690- (Loc,
691- File'Address,
692- Line'Access ,
693- Column'Access ,
694- Offset'Access );
695-
696- Immediate_Expansion_Loc :=
697- (Source_File =>
698- Get_Index_From_Generic_Name
699- (Name => Get_File_Name (File),
700- Kind => Source_File),
701- L => (Natural (Line), Natural (Column)));
702667 Macro_Expansion_Name :=
703668 +Get_Immediate_Macro_Name_For_Diagnostics (Loc, UIC.TU);
704669 Definition_Info :=
705670 (Macro_Name => Macro_Expansion_Name,
706- Sloc => Immediate_Expansion_Loc );
671+ Sloc => Spelling_Location (Loc) );
707672 end if ;
708673
709674 while Is_Macro_Location (Loc) loop
710675
711- Immediate_Expansion_Loc_C := Loc;
676+ Immediate_Expansion_Loc := Loc;
712677
713678 -- Find the location of the immediately expanded macro. Getting
714679 -- the immediate expansion location yields a location in the
@@ -747,9 +712,7 @@ package body Instrument.C is
747712 -- as implemented in clang.
748713
749714 while Is_Macro_Arg_Expansion
750- (Immediate_Expansion_Loc_C,
751- Macro_Arg_Expanded_Loc_C'Access ,
752- UIC.TU)
715+ (Immediate_Expansion_Loc, Macro_Arg_Expanded_Loc, UIC.TU)
753716 loop
754717 -- TODO??? Document why it is needed to loop while we are
755718 -- in a macro argument expansion (did not manage to make an
@@ -758,31 +721,17 @@ package body Instrument.C is
758721 -- Get_Immediate_Macro_Name_For_Diagnostics implemented in
759722 -- clang.
760723
761- Immediate_Expansion_Loc_C :=
724+ Immediate_Expansion_Loc :=
762725 Get_Immediate_Expansion_Loc
763- (Immediate_Expansion_Loc_C , UIC.TU);
726+ (Immediate_Expansion_Loc , UIC.TU);
764727 end loop ;
765728
766- -- Immediate_Expansion_Loc is the location of the token in
767- -- the immediate expanded macro definition. To get to the
768- -- expansion point, go up one level.
769-
770- Immediate_Expansion_Loc_C :=
771- Get_Immediate_Expansion_Loc
772- (Immediate_Expansion_Loc_C, UIC.TU);
773- Get_Spelling_Location
774- (Immediate_Expansion_Loc_C,
775- File'Address,
776- Line'Access ,
777- Column'Access ,
778- Offset'Access );
729+ -- Immediate_Expansion_Loc is the location of the token in the
730+ -- immediate expanded macro definition. To get to the expansion
731+ -- point, go up one level.
779732
780733 Immediate_Expansion_Loc :=
781- (Source_File =>
782- Get_Index_From_Generic_Name
783- (Name => Get_File_Name (File),
784- Kind => Source_File),
785- L => (Natural (Line), Natural (Column)));
734+ Get_Immediate_Expansion_Loc (Immediate_Expansion_Loc, UIC.TU);
786735 Macro_Expansion_Name :=
787736 +Get_Immediate_Macro_Name_For_Diagnostics (Loc, UIC.TU);
788737
@@ -797,7 +746,8 @@ package body Instrument.C is
797746 if Length (Macro_Expansion_Name) /= 0 then
798747 Expansion_Stack.Append
799748 ((Macro_Name => Macro_Expansion_Name,
800- Sloc => Immediate_Expansion_Loc));
749+ Sloc => Spelling_Location
750+ (Immediate_Expansion_Loc)));
801751 end if ;
802752 end loop ;
803753
@@ -844,9 +794,6 @@ package body Instrument.C is
844794 End_Loc : constant Source_Location_T :=
845795 Get_Range_End (Cursor_Source_Range_C);
846796
847- Line, Column, Offset : aliased unsigned;
848- File : File_T;
849-
850797 Cursor_Source_Range : Slocs.Local_Source_Location_Range;
851798
852799 procedure Update (LL_SCO : Nat; Info : in out PP_Info);
@@ -864,28 +811,13 @@ package body Instrument.C is
864811 end Update ;
865812
866813 begin
867- -- Get start of the range
868-
869- Get_File_Location
870- (Start_Loc,
871- File'Address,
872- Line'Access ,
873- Column'Access ,
874- Offset'Access );
875- Cursor_Source_Range.First_Sloc :=
876- (Line => Natural (Line), Column => Natural (Column));
877-
878- -- Get end of the range. Note: end column is exclusive
879-
880- Get_File_Location
881- (End_Loc,
882- File'Address,
883- Line'Access ,
884- Column'Access ,
885- Offset'Access );
886-
887- Cursor_Source_Range.Last_Sloc :=
888- (Line => Natural (Line), Column => Natural (Column) - 1 );
814+ -- Get start and end of the range. Note: End_Loc is exclusive,
815+ -- whereas we need Cursor_Source_Range.Last_Sloc to be inclusive.
816+
817+ Cursor_Source_Range.First_Sloc := File_Location (Start_Loc);
818+ Cursor_Source_Range.Last_Sloc := File_Location (End_Loc);
819+ Cursor_Source_Range.Last_Sloc.Column :=
820+ Cursor_Source_Range.Last_Sloc.Column - 1 ;
889821
890822 UIC.LL_PP_Info_Map.Update_Element
891823 (UIC.LL_PP_Info_Map.Find (SCOs.SCO_Table.Last), Update'Access );
0 commit comments