Patchwork [Ada] SCOs for pragmas

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 29, 2011, 8:49 a.m.
Message ID <20110829084954.GA6029@adacore.com>
Download mbox | patch
Permalink /patch/111992/
State New
Headers show

Comments

Arnaud Charlet - Aug. 29, 2011, 8:49 a.m.
This change enhances the SCO information for pragmas: the pragma name is
now recorded in the SCO, to allow Xcov to apply differentiated processing
for different pragmas.

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-08-29  Thomas Quinot  <quinot@adacore.com>

	* par_sco.adb, scos.adb, scos.ads, put_scos.adb, get_scos.adb: Record
	pragma name for each SCO statement corresponding to a pragma.

Patch

Index: par_sco.adb
===================================================================
--- par_sco.adb	(revision 178162)
+++ par_sco.adb	(working copy)
@@ -124,7 +124,8 @@ 
       From        : Source_Ptr;
       To          : Source_Ptr;
       Last        : Boolean;
-      Pragma_Sloc : Source_Ptr := No_Location);
+      Pragma_Sloc : Source_Ptr := No_Location;
+      Pragma_Name : Pragma_Id  := Unknown_Pragma);
    --  Append an entry to SCO_Table with fields set as per arguments
 
    procedure Traverse_Declarations_Or_Statements  (L : List_Id);
@@ -916,7 +917,8 @@ 
       From        : Source_Ptr;
       To          : Source_Ptr;
       Last        : Boolean;
-      Pragma_Sloc : Source_Ptr := No_Location)
+      Pragma_Sloc : Source_Ptr := No_Location;
+      Pragma_Name : Pragma_Id  := Unknown_Pragma)
    is
       function To_Source_Location (S : Source_Ptr) return Source_Location;
       --  Converts Source_Ptr value to Source_Location (line/col) format
@@ -939,13 +941,14 @@ 
    --  Start of processing for Set_Table_Entry
 
    begin
-      Add_SCO
-        (C1          => C1,
-         C2          => C2,
-         From        => To_Source_Location (From),
-         To          => To_Source_Location (To),
-         Last        => Last,
-         Pragma_Sloc => Pragma_Sloc);
+      SCO_Table.Append
+        ((C1          => C1,
+          C2          => C2,
+          From        => To_Source_Location (From),
+          To          => To_Source_Location (To),
+          Last        => Last,
+          Pragma_Sloc => Pragma_Sloc,
+          Pragma_Name => Pragma_Name));
    end Set_Table_Entry;
 
    -----------------------------------------
@@ -957,6 +960,7 @@ 
    --  since they are shared by recursive calls to this procedure.
 
    type SC_Entry is record
+      N    : Node_Id;
       From : Source_Ptr;
       To   : Source_Ptr;
       Typ  : Character;
@@ -1080,6 +1084,7 @@ 
             declare
                SCE         : SC_Entry renames SC.Table (J);
                Pragma_Sloc : Source_Ptr := No_Location;
+               Pragma_Name : Pragma_Id  := Unknown_Pragma;
             begin
                --  For the case of a statement SCO for a pragma controlled by
                --  Set_SCO_Pragma_Enabled, set Pragma_Sloc so that the SCO (and
@@ -1090,6 +1095,10 @@ 
                   Pragma_Sloc := SCE.From;
                   Condition_Pragma_Hash_Table.Set
                     (Pragma_Sloc, SCO_Table.Last + 1);
+                  Pragma_Name := Get_Pragma_Id (Sinfo.Pragma_Name (SCE.N));
+
+               elsif SCE.Typ = 'P' then
+                  Pragma_Name := Get_Pragma_Id (Sinfo.Pragma_Name (SCE.N));
                end if;
 
                Set_Table_Entry
@@ -1098,7 +1107,8 @@ 
                   From        => SCE.From,
                   To          => SCE.To,
                   Last        => (J = SC_Last),
-                  Pragma_Sloc => Pragma_Sloc);
+                  Pragma_Sloc => Pragma_Sloc,
+                  Pragma_Name => Pragma_Name);
             end;
          end loop;
 
@@ -1134,7 +1144,7 @@ 
          T : Source_Ptr;
       begin
          Sloc_Range (N, F, T);
-         SC.Append ((F, T, Typ));
+         SC.Append ((N, F, T, Typ));
       end Extend_Statement_Sequence;
 
       procedure Extend_Statement_Sequence
@@ -1147,7 +1157,7 @@ 
       begin
          Sloc_Range (From, F, Dummy);
          Sloc_Range (To, Dummy, T);
-         SC.Append ((F, T, Typ));
+         SC.Append ((From, F, T, Typ));
       end Extend_Statement_Sequence;
 
       -----------------------------
Index: scos.adb
===================================================================
--- scos.adb	(revision 178155)
+++ scos.adb	(working copy)
@@ -25,22 +25,6 @@ 
 
 package body SCOs is
 
-   -------------
-   -- Add_SCO --
-   -------------
-
-   procedure Add_SCO
-     (From        : Source_Location := No_Source_Location;
-      To          : Source_Location := No_Source_Location;
-      C1          : Character       := ' ';
-      C2          : Character       := ' ';
-      Last        : Boolean         := False;
-      Pragma_Sloc : Source_Ptr      := No_Location)
-   is
-   begin
-      SCO_Table.Append ((From, To, C1, C2, Last, Pragma_Sloc));
-   end Add_SCO;
-
    ----------------
    -- Initialize --
    ----------------
Index: scos.ads
===================================================================
--- scos.ads	(revision 178162)
+++ scos.ads	(working copy)
@@ -28,8 +28,12 @@ 
 --  the ALI file, and by Get_SCO/Put_SCO to read and write the text form that
 --  is used in the ALI file.
 
-with Types; use Types;
+with Snames; use Snames;
+--  Note: used for Pragma_Id only, no other feature from Snames should be used,
+--  as a simplified version is maintained in Xcov.
 
+with Types;  use Types;
+
 with GNAT.Table;
 
 package SCOs is
@@ -143,18 +147,18 @@ 
    --    where each sloc-range corresponds to a single statement, and * is
    --    one of:
 
-   --      t  type declaration
-   --      s  subtype declaration
-   --      o  object declaration
-   --      r  renaming declaration
-   --      i  generic instantiation
-   --      C  CASE statement (from CASE through end of expression)
-   --      E  EXIT statement
-   --      F  FOR loop statement (from FOR through end of iteration scheme)
-   --      I  IF statement (from IF through end of condition)
-   --      P  PRAGMA
-   --      R  extended RETURN statement
-   --      W  WHILE loop statement (from WHILE through end of condition)
+   --      t        type declaration
+   --      s        subtype declaration
+   --      o        object declaration
+   --      r        renaming declaration
+   --      i        generic instantiation
+   --      C        CASE statement (from CASE through end of expression)
+   --      E        EXIT statement
+   --      F        FOR loop (from FOR through end of iteration scheme)
+   --      I        IF statement (from IF through end of condition)
+   --      P[name:] PRAGMA with the indicated name
+   --      R        extended RETURN statement
+   --      W        WHILE loop statement (from WHILE through end of condition)
 
    --      Note: for I and W, condition above is in the RM syntax sense (this
    --      condition is a decision in SCO terminology).
@@ -352,16 +356,19 @@ 
    No_Source_Location : Source_Location := (No_Line_Number, No_Column_Number);
 
    type SCO_Table_Entry is record
-      From : Source_Location;
-      To   : Source_Location;
-      C1   : Character;
-      C2   : Character;
-      Last : Boolean;
+      From : Source_Location := No_Source_Location;
+      To   : Source_Location := No_Source_Location;
+      C1   : Character       := ' ';
+      C2   : Character       := ' ';
+      Last : Boolean         := False;
 
       Pragma_Sloc : Source_Ptr := No_Location;
       --  For the statement SCO for a pragma, or for any expression SCO nested
       --  in a pragma Debug/Assert/PPC, location of PRAGMA token (used for
       --  control of SCO output, value not recorded in ALI file).
+
+      Pragma_Name : Pragma_Id := Unknown_Pragma;
+      --  For the statement SCO for a pragma, gives the pragma name
    end record;
 
    package SCO_Table is new GNAT.Table (
@@ -486,13 +493,4 @@ 
    procedure Initialize;
    --  Reset tables for a new compilation
 
-   procedure Add_SCO
-     (From        : Source_Location := No_Source_Location;
-      To          : Source_Location := No_Source_Location;
-      C1          : Character       := ' ';
-      C2          : Character       := ' ';
-      Last        : Boolean         := False;
-      Pragma_Sloc : Source_Ptr      := No_Location);
-   --  Adds one entry to SCO table with given field values
-
 end SCOs;
Index: put_scos.adb
===================================================================
--- put_scos.adb	(revision 178162)
+++ put_scos.adb	(working copy)
@@ -25,6 +25,7 @@ 
 
 with Par_SCO; use Par_SCO;
 with SCOs;    use SCOs;
+with Snames;  use Snames;
 
 procedure Put_SCOs is
    Ctr : Nat;
@@ -35,6 +36,9 @@ 
    procedure Output_Source_Location (Loc : Source_Location);
    --  Output source location in line:col format
 
+   procedure Output_String (S : String);
+   --  Output S
+
    ------------------
    -- Output_Range --
    ------------------
@@ -57,6 +61,17 @@ 
       Write_Info_Nat  (Nat (Loc.Col));
    end Output_Source_Location;
 
+   -------------------
+   -- Output_String --
+   -------------------
+
+   procedure Output_String (S : String) is
+   begin
+      for J in S'Range loop
+         Write_Info_Char (S (J));
+      end loop;
+   end Output_String;
+
 --  Start of processing for Put_SCOs
 
 begin
@@ -81,9 +96,7 @@ 
             Write_Info_Nat (SUT.Dep_Num);
             Write_Info_Char (' ');
 
-            for N in SUT.File_Name'Range loop
-               Write_Info_Char (SUT.File_Name (N));
-            end loop;
+            Output_String (SUT.File_Name.all);
 
             Write_Info_Terminate;
          end if;
@@ -125,12 +138,31 @@ 
 
                         Write_Info_Char (' ');
 
-                        if SCO_Table.Table (Start).C2 /= ' ' then
-                           Write_Info_Char (SCO_Table.Table (Start).C2);
-                        end if;
+                        declare
+                           Sent : SCO_Table_Entry
+                                    renames SCO_Table.Table (Start);
+                        begin
+                           if Sent.C2 /= ' ' then
+                              Write_Info_Char (Sent.C2);
+                              if Sent.C2 = 'P'
+                                   and then Sent.Pragma_Name /= Unknown_Pragma
+                              then
+                                 declare
+                                    Pnam : constant String :=
+                                             Sent.Pragma_Name'Img;
+                                 begin
+                                    --  Strip leading "PRAGMA_"
 
-                        Output_Range (SCO_Table.Table (Start));
+                                    Output_String
+                                      (Pnam (Pnam'First + 7 .. Pnam'Last));
+                                    Write_Info_Char (':');
+                                 end;
+                              end if;
+                           end if;
 
+                           Output_Range (Sent);
+                        end;
+
                         --  Increment entry counter (up to 6 entries per line,
                         --  continuation lines are marked Cs).
 
Index: get_scos.adb
===================================================================
--- get_scos.adb	(revision 178163)
+++ get_scos.adb	(working copy)
@@ -23,9 +23,12 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-with SCOs;  use SCOs;
-with Types; use Types;
+pragma Ada_2005;
 
+with SCOs;   use SCOs;
+with Snames; use Snames;
+with Types;  use Types;
+
 with Ada.IO_Exceptions; use Ada.IO_Exceptions;
 
 procedure Get_SCOs is
@@ -193,6 +196,10 @@ 
       end loop;
    end Skip_Spaces;
 
+   Buf : String (1 .. 32_768);
+   N   : Natural;
+   --  Scratch buffer, and index into it
+
 --  Start of processing for Get_Scos
 
 begin
@@ -228,39 +235,32 @@ 
 
             --  Scan out dependency number and file name
 
-            declare
-               Ptr : String_Ptr := new String (1 .. 32768);
-               N   : Integer;
+            Skip_Spaces;
+            Dnum := Get_Int;
 
-            begin
-               Skip_Spaces;
-               Dnum := Get_Int;
+            Skip_Spaces;
 
-               Skip_Spaces;
+            N := 0;
+            while Nextc > ' ' loop
+               N := N + 1;
+               Buf (N) := Getc;
+            end loop;
 
-               N := 0;
-               while Nextc > ' ' loop
-                  N := N + 1;
-                  Ptr.all (N) := Getc;
-               end loop;
+            --  Make new unit table entry (will fill in To later)
 
-               --  Make new unit table entry (will fill in To later)
+            SCO_Unit_Table.Append (
+              (File_Name => new String'(Buf (1 .. N)),
+               Dep_Num   => Dnum,
+               From      => SCO_Table.Last + 1,
+               To        => 0));
 
-               SCO_Unit_Table.Append (
-                 (File_Name => new String'(Ptr.all (1 .. N)),
-                  Dep_Num   => Dnum,
-                  From      => SCO_Table.Last + 1,
-                  To        => 0));
-
-               Free (Ptr);
-            end;
-
          --  Statement entry
 
          when 'S' | 's' =>
             declare
                Typ : Character;
                Key : Character;
+               Pid : Pragma_Id;
 
             begin
                --  If continuation, reset Last indication in last entry
@@ -290,16 +290,33 @@ 
                      Typ := ' ';
                   else
                      Skipc;
+                     if Typ = 'P' and then Nextc not in '1' .. '9' then
+                        N := 1;
+                        loop
+                           Buf (N) := Getc;
+                           exit when Nextc = ':';
+                           N := N + 1;
+                        end loop;
+                        begin
+                           Pid := Pragma_Id'Value (Buf (1 .. N));
+                        exception
+                           when Constraint_Error =>
+                              Pid := Unknown_Pragma;
+                        end;
+                        Skipc;
+                     end if;
                   end if;
 
                   Get_Source_Location_Range (Loc1, Loc2);
 
-                  Add_SCO
-                    (C1   => Key,
-                     C2   => Typ,
-                     From => Loc1,
-                     To   => Loc2,
-                     Last => At_EOL);
+                  SCO_Table.Append
+                    ((C1          => Key,
+                      C2          => Typ,
+                      From        => Loc1,
+                      To          => Loc2,
+                      Last        => At_EOL,
+                      Pragma_Sloc => No_Location,
+                      Pragma_Name => Pid));
 
                   exit when At_EOL;
                   Key := 's';
@@ -326,12 +343,13 @@ 
                   Get_Source_Location (Loc);
                end if;
 
-               Add_SCO
-                 (C1   => Dtyp,
-                  C2   => ' ',
-                  From => Loc,
-                  To   => No_Source_Location,
-                  Last => False);
+               SCO_Table.Append
+                 ((C1     => Dtyp,
+                   C2     => ' ',
+                   From   => Loc,
+                   To     => No_Source_Location,
+                   Last   => False,
+                   others => <>));
             end;
 
             --  Loop through terms in complex expression
@@ -342,11 +360,12 @@ 
                   Cond := C;
                   Skipc;
                   Get_Source_Location_Range (Loc1, Loc2);
-                  Add_SCO
-                    (C2   => Cond,
-                     From => Loc1,
-                     To   => Loc2,
-                     Last => False);
+                  SCO_Table.Append
+                    ((C2     => Cond,
+                      From   => Loc1,
+                      To     => Loc2,
+                      Last   => False,
+                      others => <>));
 
                elsif C = '!' or else
                      C = '&' or else
@@ -358,7 +377,11 @@ 
                      Loc : Source_Location;
                   begin
                      Get_Source_Location (Loc);
-                     Add_SCO (C1 => C, From => Loc, Last => False);
+                     SCO_Table.Append
+                       ((C1     => C,
+                         From   => Loc,
+                         Last   => False,
+                         others => <>));
                   end;
 
                elsif C = ' ' then