[multiple changes]

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
This commit is contained in:
Arnaud Charlet 2009-04-17 15:31:42 +02:00
parent c4edb5791a
commit c5d91669f3
9 changed files with 200 additions and 23 deletions

View 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

View 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;

View 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;

View 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

View 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

View 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;

View 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

View 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;

View 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