Skip to content

Commit 5bca564

Browse files
Jugst3rpmderodat
authored andcommitted
Use our local sloc type instead of Langkit_Support's sloc type
In both common instrumenter code and the C instrumenter, consistently use gnatcov's own sloc type rather than the Langkit_Support's. This makes more sense, as Langkit_Support is the native data type for Libadalang (which only the Ada instrumenter uses) whereas the rest of gnatcov uses gnatcov's own type. Change-Id: I1122084df2cc7cd362ff7c8603339b98e12c80ee TN: V728-002
1 parent 78615bd commit 5bca564

File tree

7 files changed

+62
-80
lines changed

7 files changed

+62
-80
lines changed

tools/gnatcov/instrument-ada_unit.adb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ package body Instrument.Ada_Unit is
269269
function Sloc (N : Ada_Node'Class) return Source_Location is
270270
(Start_Sloc (N.Sloc_Range));
271271

272+
function "+" (Sloc : Source_Location) return Slocs.Local_Source_Location
273+
is ((Natural (Sloc.Line), Natural (Sloc.Column)));
274+
272275
function Expr_Needs_Parens (Kind : Ada_Node_Kind_Type) return Boolean
273276
is (Kind in Ada_Quantified_Expr | Ada_If_Expr | Ada_Case_Expr);
274277
-- Whether nodes of type Kind must be wrapped with parens
@@ -3200,8 +3203,8 @@ package body Instrument.Ada_Unit is
32003203
Append_SCO
32013204
(C1 => '>',
32023205
C2 => Current_Dominant.K,
3203-
From => From,
3204-
To => To,
3206+
From => +From,
3207+
To => +To,
32053208
Last => False);
32063209
end;
32073210
end if;
@@ -3222,8 +3225,8 @@ package body Instrument.Ada_Unit is
32223225
Append_SCO
32233226
(C1 => 'S',
32243227
C2 => SCE.Typ,
3225-
From => SCE.From,
3226-
To => SCE.To,
3228+
From => +SCE.From,
3229+
To => +SCE.To,
32273230
Last => (J = SC_Last),
32283231
Pragma_Aspect_Name => Pragma_Aspect_Name);
32293232

@@ -4586,7 +4589,7 @@ package body Instrument.Ada_Unit is
45864589
end if;
45874590

45884591
UIC.Annotations.Append
4589-
(Annotation_Couple'(Sloc (N), Ann));
4592+
(Annotation_Couple'(+Sloc (N), Ann));
45904593

45914594
exception
45924595
when Constraint_Error =>
@@ -5346,8 +5349,8 @@ package body Instrument.Ada_Unit is
53465349
Append_SCO
53475350
(C1 => C1,
53485351
C2 => C2,
5349-
From => Sloc (Op_N),
5350-
To => No_Source_Location,
5352+
From => +Sloc (Op_N),
5353+
To => Slocs.No_Local_Location,
53515354
Last => False);
53525355

53535356
Hash_Entries.Append ((Sloc (N), SCOs.SCO_Table.Last));
@@ -5402,8 +5405,8 @@ package body Instrument.Ada_Unit is
54025405
Append_SCO
54035406
(C1 => ' ',
54045407
C2 => C2,
5405-
From => Start_Sloc (N_SR),
5406-
To => Inclusive_End_Sloc (N_SR),
5408+
From => +Start_Sloc (N_SR),
5409+
To => +Inclusive_End_Sloc (N_SR),
54075410
Last => False);
54085411
Hash_Entries.Append ((Start_Sloc (N_SR), SCOs.SCO_Table.Last));
54095412
end Output_Element;
@@ -5481,8 +5484,8 @@ package body Instrument.Ada_Unit is
54815484
Append_SCO
54825485
(C1 => T,
54835486
C2 => ' ',
5484-
From => Loc,
5485-
To => No_Source_Location,
5487+
From => +Loc,
5488+
To => Slocs.No_Local_Location,
54865489
Last => False,
54875490
Pragma_Aspect_Name => Nam);
54885491

tools/gnatcov/instrument-c.adb

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ with Instrument.C_Utils; use Instrument.C_Utils;
4646
with Outputs; use Outputs;
4747
with Paths; use Paths;
4848
with SCOs;
49-
with Slocs;
5049
with Subprocesses; use Subprocesses;
5150
with Switches; use Switches;
5251
with System; use System;
@@ -145,7 +144,7 @@ package body Instrument.C is
145144
UIC : in out C_Unit_Inst_Context'Class;
146145
N : Cursor_T;
147146
C1, C2 : Character;
148-
From, To : Source_Location;
147+
From, To : Local_Source_Location;
149148
Last : Boolean;
150149
Pragma_Aspect_Name : Name_Id := Namet.No_Name);
151150
-- Append a SCO to SCOs.SCO_Table. Also partially fill the preprocessing
@@ -159,7 +158,7 @@ package body Instrument.C is
159158
UIC : in out C_Unit_Inst_Context'Class;
160159
N : Cursor_T;
161160
C1, C2 : Character;
162-
From, To : Source_Location;
161+
From, To : Local_Source_Location;
163162
Last : Boolean;
164163
Pragma_Aspect_Name : Name_Id := Namet.No_Name);
165164
-- Append a SCO to SCOs.SCO_Table, and complete the preprocessing info with
@@ -446,7 +445,7 @@ package body Instrument.C is
446445
begin
447446
while Has_Element (Cur) loop
448447
declare
449-
Sloc : constant Slocs.Source_Location := Key (Cur);
448+
Sloc : constant Source_Location := Key (Cur);
450449
LI : constant Line_Info_Access := Get_Line (Sloc);
451450
Deleted : Boolean := False;
452451
begin
@@ -485,7 +484,7 @@ package body Instrument.C is
485484
UIC : in out C_Unit_Inst_Context'Class;
486485
N : Cursor_T;
487486
C1, C2 : Character;
488-
From, To : Source_Location;
487+
From, To : Local_Source_Location;
489488
Last : Boolean;
490489
Pragma_Aspect_Name : Name_Id := Namet.No_Name)
491490
is
@@ -508,13 +507,7 @@ package body Instrument.C is
508507
Get_Expansion_Location
509508
(Loc, File'Address, Line'Access, Column'Access, Offset'Access);
510509

511-
Info.Actual_Source_Range :=
512-
(First_Sloc =>
513-
(Line => Integer (From.Line),
514-
Column => Integer (From.Column)),
515-
Last_Sloc =>
516-
(Line => Integer (To.Line),
517-
Column => Integer (To.Column)));
510+
Info.Actual_Source_Range := (From, To);
518511

519512
-- Check if this is comes from a macro expansion, in which case we need
520513
-- to record some information, for reporting purposes.
@@ -526,10 +519,10 @@ package body Instrument.C is
526519

527520
Macro_Expansion_Name : US.Unbounded_String;
528521
Immediate_Expansion_Loc_C : Source_Location_T;
529-
Immediate_Expansion_Loc : Slocs.Source_Location;
522+
Immediate_Expansion_Loc : Source_Location;
530523

531524
Macro_Arg_Expanded_Loc_C : aliased Source_Location_T;
532-
Macro_Arg_Expanded_Loc : Slocs.Source_Location;
525+
Macro_Arg_Expanded_Loc : Source_Location;
533526
begin
534527

535528
-- Note: macro arguments are completely macro-expanded before they
@@ -609,9 +602,7 @@ package body Instrument.C is
609602
Get_Index_From_Generic_Name
610603
(Name => Get_File_Name (File),
611604
Kind => Source_File),
612-
L =>
613-
(Line => Integer (Line),
614-
Column => Integer (Column)));
605+
L => (Natural (Line), Natural (Column)));
615606

616607
Macro_Expansion_Name :=
617608
+Get_Immediate_Macro_Name_For_Diagnostics
@@ -633,9 +624,7 @@ package body Instrument.C is
633624
Get_Index_From_Generic_Name
634625
(Name => Get_File_Name (File),
635626
Kind => Source_File),
636-
L =>
637-
(Line => Integer (Line),
638-
Column => Integer (Column)));
627+
L => (Natural (Line), Natural (Column)));
639628
Macro_Expansion_Name :=
640629
+Get_Immediate_Macro_Name_For_Diagnostics (Loc, UIC.TU);
641630
Definition_Info :=
@@ -719,9 +708,7 @@ package body Instrument.C is
719708
Get_Index_From_Generic_Name
720709
(Name => Get_File_Name (File),
721710
Kind => Source_File),
722-
L =>
723-
(Line => Integer (Line),
724-
Column => Integer (Column)));
711+
L => (Natural (Line), Natural (Column)));
725712
Macro_Expansion_Name :=
726713
+Get_Immediate_Macro_Name_For_Diagnostics (Loc, UIC.TU);
727714

@@ -761,7 +748,7 @@ package body Instrument.C is
761748
UIC : in out C_Unit_Inst_Context'Class;
762749
N : Cursor_T;
763750
C1, C2 : Character;
764-
From, To : Source_Location;
751+
From, To : Local_Source_Location;
765752
Last : Boolean;
766753
Pragma_Aspect_Name : Name_Id := Namet.No_Name)
767754
is
@@ -1117,8 +1104,8 @@ package body Instrument.C is
11171104
-- If not null, node where the witness call should be inserted.
11181105
-- Otherwise, the insertion node will be N.
11191106

1120-
From : Source_Location;
1121-
To : Source_Location;
1107+
From : Local_Source_Location;
1108+
To : Local_Source_Location;
11221109
Typ : Character;
11231110

11241111
Instr_Scheme : Instr_Scheme_Type := Instr_Stmt;
@@ -1261,7 +1248,7 @@ package body Instrument.C is
12611248
-- Likewise for the putative SCO_Raw_Hash_Table entries: see below
12621249

12631250
type Hash_Entry is record
1264-
Sloc : Source_Location;
1251+
Sloc : Local_Source_Location;
12651252
SCO_Index : Nat;
12661253
end record;
12671254
-- We must register all conditions/pragmas in SCO_Raw_Hash_Table.
@@ -1388,7 +1375,7 @@ package body Instrument.C is
13881375
C1 => C1,
13891376
C2 => C2,
13901377
From => Sloc (Get_Operator_Loc (N)),
1391-
To => No_Source_Location,
1378+
To => No_Local_Location,
13921379
Last => False);
13931380

13941381
Hash_Entries.Append ((Sloc => Start_Sloc (N),
@@ -1973,8 +1960,8 @@ package body Instrument.C is
19731960
is
19741961
Insert_Cursor : aliased Cursor_T := N;
19751962

1976-
F : constant Source_Location := Start_Sloc (N);
1977-
T : Source_Location := End_Sloc (N);
1963+
F : constant Local_Source_Location := Start_Sloc (N);
1964+
T : Local_Source_Location := End_Sloc (N);
19781965
-- Source location bounds used to produce a SCO statement. By
19791966
-- default, this should cover the same source location range as N,
19801967
-- however for nodes that can contain other statements, we select an
@@ -2037,9 +2024,9 @@ package body Instrument.C is
20372024

20382025
if J = SC_First and then Current_Dominant /= No_Dominant then
20392026
declare
2040-
From : constant Source_Location :=
2027+
From : constant Local_Source_Location :=
20412028
Start_Sloc (Current_Dominant.N);
2042-
To : constant Source_Location :=
2029+
To : constant Local_Source_Location :=
20432030
End_Sloc (Current_Dominant.N);
20442031

20452032
begin

tools/gnatcov/instrument-c.ads

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
2525

2626
with GNATCOLL.Projects;
2727

28-
with Langkit_Support.Slocs; use Langkit_Support.Slocs;
29-
3028
with Namet; use Namet;
3129
with Types; use Types;
3230

@@ -36,6 +34,7 @@ with Clang.Rewrite; use Clang.Rewrite;
3634
with Instrument.Base_Types; use Instrument.Base_Types;
3735
with Instrument.Common; use Instrument.Common;
3836
with SC_Obligations; use SC_Obligations;
37+
with Slocs; use Slocs;
3938
with Strings; use Strings;
4039

4140
private package Instrument.C is
@@ -302,7 +301,7 @@ private
302301
UIC : in out C_Unit_Inst_Context'Class;
303302
N : Cursor_T;
304303
C1, C2 : Character;
305-
From, To : Source_Location;
304+
From, To : Local_Source_Location;
306305
Last : Boolean;
307306
Pragma_Aspect_Name : Name_Id := Namet.No_Name) is null;
308307

tools/gnatcov/instrument-c_utils.adb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,21 @@ package body Instrument.C_Utils is
3333
-- Sloc --
3434
----------
3535

36-
function Sloc (Loc : Source_Location_T) return Source_Location is
36+
function Sloc (Loc : Source_Location_T) return Local_Source_Location is
3737
Line, Column : aliased Interfaces.C.unsigned;
3838
begin
3939
Get_Presumed_Location (Location => Loc,
4040
Filename => null,
4141
Line => Line'Access,
4242
Column => Column'Access);
43-
return (Line => Langkit_Support.Slocs.Line_Number (Line),
44-
Column => Langkit_Support.Slocs.Column_Number (Column));
43+
return (Natural (Line), Natural (Column));
4544
end Sloc;
4645

4746
----------------
4847
-- Start_Sloc --
4948
----------------
5049

51-
function Start_Sloc (N : Cursor_T) return Source_Location is
50+
function Start_Sloc (N : Cursor_T) return Local_Source_Location is
5251
Line, Column : aliased Interfaces.C.unsigned;
5352
Loc : constant Source_Location_T :=
5453
Get_Range_Start (Get_Cursor_Extent (N));
@@ -57,15 +56,14 @@ package body Instrument.C_Utils is
5756
Filename => null,
5857
Line => Line'Access,
5958
Column => Column'Access);
60-
return (Line => Langkit_Support.Slocs.Line_Number (Line),
61-
Column => Langkit_Support.Slocs.Column_Number (Column));
59+
return (Natural (Line), Natural (Column));
6260
end Start_Sloc;
6361

6462
--------------
6563
-- End_Sloc --
6664
--------------
6765

68-
function End_Sloc (N : Cursor_T) return Source_Location is
66+
function End_Sloc (N : Cursor_T) return Local_Source_Location is
6967
Line, Column : aliased Interfaces.C.unsigned;
7068
Loc : Source_Location_T :=
7169
Get_Range_End (Get_Cursor_Extent (N));
@@ -78,8 +76,7 @@ package body Instrument.C_Utils is
7876
Filename => null,
7977
Line => Line'Access,
8078
Column => Column'Access);
81-
return (Line => Langkit_Support.Slocs.Line_Number (Line),
82-
Column => Langkit_Support.Slocs.Column_Number (Column));
79+
return (Natural (Line), Natural (Column));
8380
end End_Sloc;
8481

8582
----------

tools/gnatcov/instrument-c_utils.ads

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ with Ada.Containers.Vectors;
2222
with Clang.Index; use Clang.Index;
2323
with Clang.Rewrite; use Clang.Rewrite;
2424

25-
with Langkit_Support.Slocs; use Langkit_Support.Slocs;
25+
with Slocs; use Slocs;
2626

2727
package Instrument.C_Utils is
2828

@@ -37,13 +37,13 @@ package Instrument.C_Utils is
3737
-- Location utilities --
3838
-------------------------
3939

40-
function Sloc (Loc : Source_Location_T) return Source_Location;
40+
function Sloc (Loc : Source_Location_T) return Local_Source_Location;
4141
-- Convert a Source_Location_T to a Source_Location
4242

43-
function Start_Sloc (N : Cursor_T) return Source_Location;
43+
function Start_Sloc (N : Cursor_T) return Local_Source_Location;
4444
-- Return the starting location of a node
4545

46-
function End_Sloc (N : Cursor_T) return Source_Location;
46+
function End_Sloc (N : Cursor_T) return Local_Source_Location;
4747
-- Return the end location of a node
4848

4949
function Kind (N : Cursor_T) return Cursor_Kind_T;

tools/gnatcov/instrument-common.adb

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,9 @@ package body Instrument.Common is
720720
begin
721721
for Couple of UIC.Annotations loop
722722
declare
723-
Sloc : constant Slocs.Source_Location :=
723+
Sloc : constant Source_Location :=
724724
(Source_File => UIC.SFI,
725-
L => (Line => Positive (Couple.Sloc.Line),
726-
Column => Positive (Couple.Sloc.Column)));
725+
L => Couple.Sloc);
727726
begin
728727
Couple.Annotation.CU := UIC.CU;
729728
ALI_Annotations.Insert
@@ -738,22 +737,20 @@ package body Instrument.Common is
738737

739738
procedure Append_SCO
740739
(C1, C2 : Character;
741-
From, To : Source_Location;
740+
From, To : Local_Source_Location;
742741
Last : Boolean;
743742
Pragma_Aspect_Name : Name_Id := Namet.No_Name)
744743
is
745744
begin
746745
SCOs.SCO_Table.Append
747-
((From =>
748-
(Line => Logical_Line_Number (From.Line),
749-
Col => Standard.Types.Column_Number (From.Column)),
750-
To =>
751-
(Line => Logical_Line_Number (To.Line),
752-
Col => Standard.Types.Column_Number (To.Column)),
753-
C1 => C1,
754-
C2 => C2,
755-
Last => Last,
756-
Pragma_Sloc => No_Location,
746+
((From =>
747+
(Logical_Line_Number (From.Line), Column_Number (From.Column)),
748+
To =>
749+
(Logical_Line_Number (To.Line), Column_Number (To.Column)),
750+
C1 => C1,
751+
C2 => C2,
752+
Last => Last,
753+
Pragma_Sloc => Types.No_Location,
757754
Pragma_Aspect_Name => Pragma_Aspect_Name));
758755
end Append_SCO;
759756

0 commit comments

Comments
 (0)