]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[multiple changes]
authorArnaud Charlet <charlet@gcc.gnu.org>
Fri, 17 Apr 2009 13:31:42 +0000 (15:31 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Fri, 17 Apr 2009 13:31:42 +0000 (15:31 +0200)
2009-04-17  Robert Dewar  <dewar@adacore.com>

* exp_disp.adb: Minor reformatting
Minor code reorganization (use Nkind_In)

* prepcomp.adb: Minor reformatting

* sem_ch3.adb: Minor reformatting

* sem_res.adb: Minor comment addition

* exp_ch5.adb (Expand_Assign_Array): Use Has_Address_Clause to test
for address clause

* lib-xref.adb (Generate_Reference): Exclude recursive calls from
setting Is_Referenced

* types.ads: Minor reformatting

2009-04-17  Arnaud Charlet  <charlet@adacore.com>

* gnat_ugn.texi: Initial documentation on binding generator.

From-SVN: r146266

gcc/ada/ChangeLog
gcc/ada/exp_ch5.adb
gcc/ada/exp_disp.adb
gcc/ada/gnat_ugn.texi
gcc/ada/lib-xref.adb
gcc/ada/prepcomp.adb
gcc/ada/sem_ch3.adb
gcc/ada/sem_res.adb
gcc/ada/types.ads

index 3ace58e3e97567b4d4b9e2f6e3640cfde1696454..44f54c6769a5deb9ae943787359e04564ae4958d 100644 (file)
@@ -1,3 +1,26 @@
+2009-04-17  Robert Dewar  <dewar@adacore.com>
+
+       * exp_disp.adb: Minor reformatting
+       Minor code reorganization (use Nkind_In)
+
+       * prepcomp.adb: Minor reformatting
+
+       * sem_ch3.adb: Minor reformatting
+
+       * sem_res.adb: Minor comment addition
+
+       * exp_ch5.adb (Expand_Assign_Array): Use Has_Address_Clause to test
+       for address clause
+
+       * lib-xref.adb (Generate_Reference): Exclude recursive calls from
+       setting Is_Referenced
+
+       * types.ads: Minor reformatting
+
+2009-04-17  Arnaud Charlet  <charlet@adacore.com>
+
+       * gnat_ugn.texi: Initial documentation on binding generator.
+
 2009-04-17  Ed Schonberg  <schonberg@adacore.com>
 
        * einfo.ads, einfo.adb: New attribute Underlying_Record_View, to handle
index c025f5814c464c274f4b25bd0470a71b00f1f9d8..5008f4c1eed37bf4b540577cd46a51d03d071ea2 100644 (file)
@@ -311,12 +311,7 @@ package body Exp_Ch5 is
       --  If either operand has an address clause clear Backwards_OK and
       --  Forwards_OK, since we cannot tell if the operands overlap.
 
-      if (Is_Entity_Name (Lhs)
-           and then Present (Address_Clause (Entity (Lhs))))
-        or else
-         (Is_Entity_Name (Lhs)
-          and then Present (Address_Clause (Entity (Lhs))))
-      then
+      if Has_Address_Clause (Lhs) or else Has_Address_Clause (Rhs) then
          Set_Forwards_OK  (N, False);
          Set_Backwards_OK (N, False);
       end if;
index 6a125ecbec211607e1989f7d5628b97694405a38..d0903200a59f1cee71d0a6e72200fb035e4e7f77 100644 (file)
@@ -164,13 +164,12 @@ package body Exp_Disp is
             --  Handle full type declarations and derivations of library
             --  level tagged types
 
-            elsif (Nkind (D) = N_Full_Type_Declaration
-                     or else Nkind (D) = N_Derived_Type_Definition)
+            elsif Nkind_In (D, N_Full_Type_Declaration,
+                               N_Derived_Type_Definition)
               and then Is_Library_Level_Tagged_Type (Defining_Entity (D))
               and then Ekind (Defining_Entity (D)) /= E_Record_Subtype
               and then not Is_Private_Type (Defining_Entity (D))
             then
-
                --  We do not generate dispatch tables for the internal type
                --  created for a type extension with unknown discriminants
                --  The needed information is shared with the source type,
@@ -180,7 +179,7 @@ package body Exp_Disp is
                  and then
                    Has_Unknown_Discriminants (Etype (Defining_Entity (D)))
                  and then
-                    not Comes_From_Source (First_Subtype (Defining_Entity (D)))
+                   not Comes_From_Source (First_Subtype (Defining_Entity (D)))
                then
                   null;
 
index c645682bbbe2b191316e29a259de030112602e87..771aff7b6d516fd759e01463170dc024f6eaffdb 100644 (file)
@@ -187,6 +187,7 @@ AdaCore@*
 * Stack Related Facilities::
 * Verifying Properties Using gnatcheck::
 * Creating Sample Bodies Using gnatstub::
+* Generating Ada Bindings for C and C++ headers::
 * Other Utility Programs::
 * Running and Debugging Ada Programs::
 @ifclear vms
@@ -845,6 +846,10 @@ a utility that checks Ada code against a set of rules.
 @ref{Creating Sample Bodies Using gnatstub}, discusses @code{gnatstub},
 a utility that generates empty but compilable bodies for library units.
 
+@item
+@ref{Generating Ada Bindings for C and C++ headers}, describes how to
+generate automatically Ada bindings from C and C++ headers.
+
 @item
 @ref{Other Utility Programs}, discusses several other GNAT utilities,
 including @code{gnathtml}.
@@ -22247,6 +22252,148 @@ Verbose mode: generate version information.
 
 @end table
 
+@c *********************************
+@node Generating Ada Bindings for C and C++ headers
+@chapter Generating Ada Bindings for C and C++ headers
+@findex binding
+
+@noindent
+GNAT now comes with a new experimental binding generator for C and C++
+headers which is intended to do 95% of the tedious work of generating
+Ada specs from C or C++ header files. Note that this still is a work in
+progress, not designed to generate 100% correct Ada specs.
+
+Note that the code generated is using the Ada 2005 syntax, which makes it
+easier to inteface with other languages than previous versions of Ada.
+
+@menu
+* Running the binding generator::
+* Generating bindings for C++ headers::
+* Switches::
+@end menu
+
+@node Running the binding generator
+@section Running the binding generator
+
+@noindent
+The binding generator is part of the @command{gcc} compiler and can be
+invoked via the @option{-fdump-ada-spec} switch, which will generate Ada
+spec files for the header files specified on the command line, and all
+header files needed by these files transitivitely. For example:
+
+@smallexample
+$ g++ -c -fdump-ada-spec -C /usr/include/time.h
+$ gcc -c -gnat05 *.ads
+@end smallexample
+
+will generate, under GNU/Linux, the following files: @file{bits_time_h.ads},
+@code{bits_types_h.ads}, @code{stddef_h.ads}, @code{time_h.ads} which
+correspond to the files @file{/usr/include/time.h},
+@file{/usr/include/bits/time.h}, etc@dots{}, and will then compile in Ada 2005
+mode these Ada specs.
+
+The @code{-C} switch tells @command{gcc} to extract comments from headers,
+and will attempt to generate corresponding Ada comments.
+
+If you want to generate a single Ada file and not the transitive closure, you
+can use instead the @option{-fdump-ada-spec-slim} switch.
+
+Note that we recommend when possible to use the @command{g++} driver to
+generate bindings, even for most C headers, since this will in general
+generate better Ada specs. For generating bindings for C++ headers, it is
+mandatory to use the @command{g++} command, or @command{gcc -x c++} which
+is equivalent in this case. If @command{g++} cannot work on your C headers
+because of incompatibilities between C and C++, then you can fallback to
+@command{gcc} instead.
+
+For an example of better bindings generated from the C++ front-end,
+the name of the parameters (when available) are actually ignored by the C
+front-end. Consider the following C header:
+
+@smallexample
+extern void foo (int variable);
+@end smallexample
+
+with the C front-end, @code{variable} is ignored, and the above is handled as:
+
+@smallexample
+extern void foo (int);
+@end smallexample
+
+generating a generic:
+
+@smallexample
+procedure foo (param1 : int);
+@end smallexample
+
+with the C++ front-end, the name is available, and we generate:
+
+@smallexample
+procedure foo (variable : int);
+@end smallexample
+
+In some cases, the generated bindings will be more complete or more meaningful
+when defining some macros, which you can do via the @option{-D} switch. this
+is for example the case with @file{Xlib.h} under GNU/Linux:
+
+@smallexample
+g++ -c -fdump-ada-spec -DXLIB_ILLEGAL_ACCESS -C /usr/include/X11/Xlib.h
+@end smallexample
+
+The above will generate more complete bindings than a straight call without
+the @option{-DXLIB_ILLEGAL_ACCESS} switch.
+
+In other cases, it is not possible to parse a header file in a stand alone
+manner, because other include files need to be included first. In this
+case, the solution is to create a small header file including the needed
+@code{#include} and possible @code{#define} directives. For example, to
+generate Ada bindings for @file{readline/readlin.h}, you need to first
+include @file{stdio.h}, so you can create a file with the following two
+lines in e.g. @file{readline1.h}:
+
+@smallexample
+#include <stdio.h>
+#include <readline/readline.h>
+@end smallexample
+
+and then generate Ada bindings from this file:
+
+@smallexample
+$ g++ -c -fdump-ada-spec readline1.h
+@end smallexample
+
+@node Generating bindings for C++ headers
+@section Generating bindings for C++ headers
+
+@noindent
+Generating bindings for C++ headers is done using the same options, always
+with the @command{g++} compiler.
+
+In this mode, C++ classes will be mapped to Ada tagged types, constructors
+will be mapped using the @code{CPP_Constructor} pragma, and when possible,
+multiple inheritance of abstract classes will be mapped to Ada interfaces
+(@xref{Interfacing to C++,,,gnat_rm, GNAT Reference Manual}, for additional
+information on interfacing to C++).
+
+@node Switches
+@section Switches
+
+@table @option
+@item -fdump-ada-spec
+@cindex @option{-fdump-ada-spec} (@command{gcc})
+Generate Ada spec files for the given header files transitively (including
+all header files that these headers depend upon).
+
+@item -fdump-ada-spec-slim
+@cindex @option{-fdump-ada-spec-slim} (@command{gcc})
+Generate Ada spec files for the header files specified on the command line
+only.
+
+@item -C
+@item @option{-C} (@command{gcc})
+Extract comments from headers and generate Ada comments in the Ada spec files.
+@end table
+
 @node Other Utility Programs
 @chapter Other Utility Programs
 
index 3e36d0c84edb2bae66015d84047264c5e9df5353..fac486425698a696831e105fdf6fde437446a2f7 100644 (file)
@@ -564,6 +564,15 @@ package body Lib.Xref is
                   Set_Referenced_As_LHS (E, False);
                end if;
 
+            --  Don't count a recursive reference within a subprogram as a
+            --  reference (that allows detection of a recursive subprogram
+            --  whose only references are recursive calls as unreferenced).
+
+            elsif Is_Subprogram (E)
+              and then E = Nearest_Dynamic_Scope (Current_Scope)
+            then
+               null;
+
             --  Any other occurrence counts as referencing the entity
 
             elsif OK_To_Set_Referenced then
index 63d64e7c8fff4bff023cbedff63ac91ca5ad17ba..18c2686e491bf15e87ce776659512ab7a02c00f4 100644 (file)
@@ -47,9 +47,9 @@ package body Prepcomp is
 
    --  The following variable should be a constant, but this is not possible
    --  because its type GNAT.Dynamic_Tables.Instance has a component P of
-   --  unitialized private type GNAT.Dynamic_Tables.Table_Private and there are
-   --  no exported values for this private type.
-   --  Warnings are Off because it is never assigned a value.
+   --  unitialized private type GNAT.Dynamic_Tables.Table_Private and there
+   --  are no exported values for this private type. Warnings are Off because
+   --  it is never assigned a value.
 
    pragma Warnings (Off);
    No_Mapping : Prep.Symbol_Table.Instance;
index 11c64914ed79bf59da0336348052f92f367bdc6b..e6be49e35688247abeb380783e7ab7e00b05cfb2 100644 (file)
@@ -5522,11 +5522,12 @@ package body Sem_Ch3 is
          then
             declare
                Full_Der : constant Entity_Id :=
-                 Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
-               Decl : Node_Id;
-               New_Ext : constant Node_Id :=
-                           Copy_Separate_Tree
-                             (Record_Extension_Part (Type_Definition (N)));
+                            Make_Defining_Identifier (Loc,
+                              Chars => New_Internal_Name ('T'));
+               Decl     : Node_Id;
+               New_Ext  : constant Node_Id :=
+                            Copy_Separate_Tree
+                              (Record_Extension_Part (Type_Definition (N)));
 
             begin
                Build_Derived_Record_Type
@@ -5561,7 +5562,7 @@ package body Sem_Ch3 is
                Set_Underlying_Record_View (Derived_Type, Full_Der);
             end;
 
-         --  if discriminants are known, build derived record.
+         --  if discriminants are known, build derived record
 
          else
             Build_Derived_Record_Type
@@ -5600,8 +5601,8 @@ package body Sem_Ch3 is
                      Build_Underlying_Full_View (N, Derived_Type, Parent_Type);
 
                   elsif Is_Constrained (Full_View (Parent_Type)) then
-                     Set_Underlying_Full_View (Derived_Type,
-                       Full_View (Parent_Type));
+                     Set_Underlying_Full_View
+                       (Derived_Type, Full_View (Parent_Type));
                   end if;
 
                else
index 31242c6eb57180797485357d0f813ea7e817cf61..676cbc2bf42453e463473c86cae0409a1613896b 100644 (file)
@@ -5231,6 +5231,9 @@ package body Sem_Res is
         and then Present (Controlling_Argument (N))
       then
          Generate_Reference (Nam, Subp, 'R');
+
+      --  Normal case, not a dispatching call
+
       else
          Generate_Reference (Nam, Subp);
       end if;
index 3b89ab25d0b62549f5eb7870a73ed9a9cd86eb3e..96b60b579de60f4e258ef6f959c78ae8cfb64b9b 100644 (file)
@@ -192,8 +192,8 @@ package Types is
    subtype Source_Buffer is Text_Buffer;
    --  Type used to store text of a source file . The buffer for the main
    --  source (the source specified on the command line) has a lower bound
-   --  starting at zero. Subsequent subsidiary sources have lower bounds which
-   --  are one greater than the previous upper bound.
+   --  starting at zero. Subsequent subsidiary sources have lower bounds
+   --  which are one greater than the previous upper bound.
 
    subtype Big_Source_Buffer is Text_Buffer (0 .. Text_Ptr'Last);
    --  This is a virtual type used as the designated type of the access