diff mbox

[Ada] 'Version and 'Body_Version in Stand-Alone Libraries

Message ID 20100614092255.GA1042@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet June 14, 2010, 9:22 a.m. UTC
Symbols for 'Version and 'Body_Version of units in Stand-Alone Libraries
are now properly generated.
The test for this is to have a SAL where 'Version for a non interface
unit is used.

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

2010-06-14  Vincent Celier  <celier@adacore.com>

	* ali.adb (Scan_ALI): Set component Directly_Scanned of the unit(s) to
	the same value as the parameter of the same name.
	* ali.ads (Scan_ALI): New Boolean parameter Directly_Scanned, defaulted
	to False.
	* bindgen.adb (Gen_Versions_Ada): Never emit version symbols for
	Stand-Alone Library interfaces. When binding Stand-Alone Libraries,
	emit version symbols only for the units of the library.
	(Gen_Versions_C): Ditto.
diff mbox

Patch

Index: bindgen.adb
===================================================================
--- bindgen.adb	(revision 160705)
+++ bindgen.adb	(working copy)
@@ -2969,12 +2969,9 @@ 
    -- Gen_Versions_Ada --
    ----------------------
 
-   --  This routine generates two sets of lines. The first set has the form:
+   --  This routine generates lines such as:
 
    --    unnnnn : constant Integer := 16#hhhhhhhh#;
-
-   --  The second set has the form
-
    --    pragma Export (C, unnnnn, unam);
 
    --  for each unit, where unam is the unit name suffixed by either B or
@@ -2999,57 +2996,44 @@ 
    --  Start of processing for Gen_Versions_Ada
 
    begin
-      if Bind_For_Library then
-
-         --  When building libraries, the version number of each unit can
-         --  not be computed, since the binder does not know the full list
-         --  of units. Therefore, the 'Version and 'Body_Version
-         --  attributes cannot supported in this case.
-
-         return;
-      end if;
-
       WBI ("");
 
       WBI ("   type Version_32 is mod 2 ** 32;");
       for U in Units.First .. Units.Last loop
-         Increment_Ubuf;
-         WBI ("   " & Ubuf & " : constant Version_32 := 16#" &
-              Units.Table (U).Version & "#;");
-      end loop;
+         if not Units.Table (U).SAL_Interface and then
+           ((not Bind_For_Library) or else Units.Table (U).Directly_Scanned)
+         then
+            Increment_Ubuf;
+            WBI ("   " & Ubuf & " : constant Version_32 := 16#" &
+                 Units.Table (U).Version & "#;");
+            Set_String ("   pragma Export (C, ");
+            Set_String (Ubuf);
+            Set_String (", """);
 
-      WBI ("");
-      Ubuf := "u00000";
+            Get_Name_String (Units.Table (U).Uname);
 
-      for U in Units.First .. Units.Last loop
-         Increment_Ubuf;
-         Set_String ("   pragma Export (C, ");
-         Set_String (Ubuf);
-         Set_String (", """);
+            for K in 1 .. Name_Len loop
+               if Name_Buffer (K) = '.' then
+                  Set_Char ('_');
+                  Set_Char ('_');
 
-         Get_Name_String (Units.Table (U).Uname);
+               elsif Name_Buffer (K) = '%' then
+                  exit;
 
-         for K in 1 .. Name_Len loop
-            if Name_Buffer (K) = '.' then
-               Set_Char ('_');
-               Set_Char ('_');
+               else
+                  Set_Char (Name_Buffer (K));
+               end if;
+            end loop;
 
-            elsif Name_Buffer (K) = '%' then
-               exit;
-
+            if Name_Buffer (Name_Len) = 's' then
+               Set_Char ('S');
             else
-               Set_Char (Name_Buffer (K));
+               Set_Char ('B');
             end if;
-         end loop;
 
-         if Name_Buffer (Name_Len) = 's' then
-            Set_Char ('S');
-         else
-            Set_Char ('B');
+            Set_String (""");");
+            Write_Statement_Buffer;
          end if;
-
-         Set_String (""");");
-         Write_Statement_Buffer;
       end loop;
 
    end Gen_Versions_Ada;
@@ -3067,43 +3051,37 @@ 
 
    procedure Gen_Versions_C is
    begin
-      if Bind_For_Library then
-
-         --  When building libraries, the version number of each unit can
-         --  not be computed, since the binder does not know the full list
-         --  of units. Therefore, the 'Version and 'Body_Version
-         --  attributes cannot supported.
-
-         return;
-      end if;
-
       for U in Units.First .. Units.Last loop
-         Set_String ("unsigned ");
+         if not Units.Table (U).SAL_Interface and then
+           ((not Bind_For_Library) or else Units.Table (U).Directly_Scanned)
+         then
+            Set_String ("unsigned ");
 
-         Get_Name_String (Units.Table (U).Uname);
+            Get_Name_String (Units.Table (U).Uname);
 
-         for K in 1 .. Name_Len loop
-            if Name_Buffer (K) = '.' then
-               Set_String ("__");
+            for K in 1 .. Name_Len loop
+               if Name_Buffer (K) = '.' then
+                  Set_String ("__");
 
-            elsif Name_Buffer (K) = '%' then
-               exit;
+               elsif Name_Buffer (K) = '%' then
+                  exit;
 
+               else
+                  Set_Char (Name_Buffer (K));
+               end if;
+            end loop;
+
+            if Name_Buffer (Name_Len) = 's' then
+               Set_Char ('S');
             else
-               Set_Char (Name_Buffer (K));
+               Set_Char ('B');
             end if;
-         end loop;
 
-         if Name_Buffer (Name_Len) = 's' then
-            Set_Char ('S');
-         else
-            Set_Char ('B');
+            Set_String (" = 0x");
+            Set_String (Units.Table (U).Version);
+            Set_Char   (';');
+            Write_Statement_Buffer;
          end if;
-
-         Set_String (" = 0x");
-         Set_String (Units.Table (U).Version);
-         Set_Char   (';');
-         Write_Statement_Buffer;
       end loop;
 
    end Gen_Versions_C;
Index: ali.adb
===================================================================
--- ali.adb	(revision 160705)
+++ ali.adb	(working copy)
@@ -119,14 +119,15 @@ 
    --------------
 
    function Scan_ALI
-     (F             : File_Name_Type;
-      T             : Text_Buffer_Ptr;
-      Ignore_ED     : Boolean;
-      Err           : Boolean;
-      Read_Xref     : Boolean := False;
-      Read_Lines    : String  := "";
-      Ignore_Lines  : String  := "X";
-      Ignore_Errors : Boolean := False) return ALI_Id
+     (F                : File_Name_Type;
+      T                : Text_Buffer_Ptr;
+      Ignore_ED        : Boolean;
+      Err              : Boolean;
+      Read_Xref        : Boolean := False;
+      Read_Lines       : String  := "";
+      Ignore_Lines     : String  := "X";
+      Ignore_Errors    : Boolean := False;
+      Directly_Scanned : Boolean := False) return ALI_Id
    is
       P         : Text_Ptr := T'First;
       Line      : Logical_Line_Number := 1;
@@ -1415,6 +1416,7 @@ 
             UL.First_Arg                := First_Arg;
             UL.Elab_Position            := 0;
             UL.SAL_Interface            := ALIs.Table (Id).SAL_Interface;
+            UL.Directly_Scanned         := Directly_Scanned;
             UL.Body_Needed_For_SAL      := False;
             UL.Elaborate_Body_Desirable := False;
             UL.Optimize_Alignment       := 'O';
Index: ali.ads
===================================================================
--- ali.ads	(revision 160705)
+++ ali.ads	(working copy)
@@ -342,6 +342,9 @@ 
       SAL_Interface : Boolean;
       --  Set True when this is an interface to a standalone library
 
+      Directly_Scanned : Boolean;
+      --  True iff it is a unit from an ALI file specified to gnatbind
+
       Body_Needed_For_SAL : Boolean;
       --  Indicates that the source for the body of the unit (subprogram,
       --  package, or generic unit) must be included in a standalone library.
@@ -933,14 +936,15 @@ 
    --  Initialize the ALI tables. Also resets all switch values to defaults
 
    function Scan_ALI
-     (F             : File_Name_Type;
-      T             : Text_Buffer_Ptr;
-      Ignore_ED     : Boolean;
-      Err           : Boolean;
-      Read_Xref     : Boolean := False;
-      Read_Lines    : String  := "";
-      Ignore_Lines  : String  := "X";
-      Ignore_Errors : Boolean := False) return ALI_Id;
+     (F                : File_Name_Type;
+      T                : Text_Buffer_Ptr;
+      Ignore_ED        : Boolean;
+      Err              : Boolean;
+      Read_Xref        : Boolean := False;
+      Read_Lines       : String  := "";
+      Ignore_Lines     : String  := "X";
+      Ignore_Errors    : Boolean := False;
+      Directly_Scanned : Boolean := False) return ALI_Id;
    --  Given the text, T, of an ALI file, F, scan and store the information
    --  from the file, and return the Id of the resulting entry in the ALI
    --  table. Switch settings may be modified as described above in the
@@ -986,5 +990,11 @@ 
    --    Scan_ALI was completely unable to process the file (e.g. it did not
    --    look like an ALI file at all). Ignore_Errors is intended to improve
    --    the downward compatibility of new compilers with old tools.
+   --
+   --    Directly_Scanned is normally False. If it is set to True, then the
+   --    units (spec and/or body) corresponding to the ALI file are marked as
+   --    such. It is used to decide for what units gnatbind should generate
+   --    the symbols corresponding to 'Version or 'Body_Version in
+   --    Stand-Alone Libraries.
 
 end ALI;