Patchwork [Ada,RFC] Fortran Interface: Update comment, add some of the Star/Kind type definitions

login
register
mail settings
Submitter Tobias Burnus
Date March 19, 2013, 6:47 p.m.
Message ID <5148B2AE.1030902@net-b.de>
Download mbox | patch
Permalink /patch/229177/
State New
Headers show

Comments

Tobias Burnus - March 19, 2013, 6:47 p.m.
This patch updates one comment regarding "logical":
* The Fortran standard requires that (default-kind) "logical" and 
"integer" have the same size; that's generally the case, i.e. also for 
arrays or in structures (derived types)
* Fortran does not use zero/nonzero semantics but only .true. and 
.false. However, the standard does not specify the value of .true. and 
.false. While .false. seems to be universally 0, I have seen .true. 
being 1 (majority of compilers) and -1 (few compilers, but one popular 
among them). GCC's gfortran uses 0 and 1 - and will give wrong code with 
a "-1" .true. (when ".not." is applied to it, it will become -2, which 
is also regarded as ".true."). Hence, for GCC/gfortran interop, the 
semantic matches gnat's; but for wider compatibility, keeping the 
nonzero/zero semantics is reasonable.


In addition, Ada 2012 allows optionally to define types for Fortran's 
"real*8" and "integer(kind=2)". The former syntax is not permitted by 
any Fortran standard but an extremely common vendor extension, 
effectively supported by all compilers. The second one is standard 
conform since Fortran 90; however, the value (here "2") is not defined 
by the standard. By far most compilers use the byte size for that value. 
I know of one compiler, which doesn't by default (only with -kind=byte). 
Thus, that addition should be interop with effectively all compilers.

See Fortran interop appendix B.5 to Ada 2012. Quickest link to the 
standard: Look at the attachment of the email 
http://mailman.j3-fortran.org/pipermail/j3/2013-February/006162.html – 
or in the standard itself (also linked from that email).


I would like if some of the Ada/GNAT experts could have a look - as this 
is really my first look at Ada code.

Tobias
Arnaud Charlet - March 19, 2013, 9:51 p.m.
> I would like if some of the Ada/GNAT experts could have a look - as
> this is really my first look at Ada code.

Patch looks reasonable to me at first sight, but I'm not a Fortran specialist.

Ed, Robert, could you have a look?

> 2013-03-19  Tobias Burnus  <burnus@net-b.de>
> 
> 	* i-fortra.ads: Update comment, add Ada 2012's optional
> 	Star and Kind data types for enhanced interoperability.
> 
> diff --git a/gcc/ada/i-fortra.ads b/gcc/ada/i-fortra.ads
> index 992eb28..270c819 100644
> --- a/gcc/ada/i-fortra.ads
> +++ b/gcc/ada/i-fortra.ads
> @@ -26,11 +26,11 @@ package Interfaces.Fortran is
>     type Logical is new Boolean;
>     for Logical'Size use Integer'Size;
>     pragma Convention (Fortran, Logical);
> -   --  As required by Fortran standard, stand alone logical allocates same
> -   --  space as integer (but what about the array case???). The convention
> -   --  is important, since in Fortran, Booleans have zero/non-zero semantics
> -   --  for False/True, and the pragma Convention (Fortran) activates the
> -   --  special handling required in this case.
> +   --  As required by Fortran standard, logical allocates same space as
> +   --  an integer. The convention is important, since in Fortran, Booleans
> +   --  are implemented with zero/non-zero semantics for False/True, and the
> +   --  pragma Convention (Fortran) activates the special handling required
> +   --  in this case.
>  
>     package Single_Precision_Complex_Types is
>        new Ada.Numerics.Generic_Complex_Types (Real);
> @@ -50,6 +50,53 @@ package Interfaces.Fortran is
>  
>     type Fortran_Character is array (Positive range <>) of
>     Character_Set;
>  
> +   --  Additional declarations as permitted by Ada 2012, p.608, paragraph 21.
> +   --  Interoperability with Fortran 77's vendor extension using star
> +   --  notation and Fortran 90's intrinsic types with kind=n parameter.
> +   --  The following assumes that `n' matches the byte size, which
> +   --  most Fortran compiler, including GCC's follow.
> +
> +   type Integer_Star_1  is new Integer_8;
> +   type Integer_Kind_1  is new Integer_8;
> +   type Integer_Star_2  is new Integer_16;
> +   type Integer_Kind_2  is new Integer_16;
> +   type Integer_Star_4  is new Integer_32;
> +   type Integer_Kind_4  is new Integer_32;
> +   type Integer_Star_8  is new Integer_64;
> +   type Integer_Kind_8  is new Integer_64;
> +
> +   type Logical_Star_1  is new Boolean;
> +   type Logical_Star_2  is new Boolean;
> +   type Logical_Star_4  is new Boolean;
> +   type Logical_Star_8  is new Boolean;
> +   for Logical_Star_1'Size use Integer_8'Size;
> +   for Logical_Star_2'Size use Integer_16'Size;
> +   for Logical_Star_4'Size use Integer_32'Size;
> +   for Logical_Star_8'Size use Integer_64'Size;
> +   pragma Convention (Fortran, Logical_Star_1);
> +   pragma Convention (Fortran, Logical_Star_2);
> +   pragma Convention (Fortran, Logical_Star_4);
> +   pragma Convention (Fortran, Logical_Star_8);
> +
> +   type Logical_Kind_1  is new Logical_Star_1;
> +   type Logical_Kind_2  is new Logical_Star_2;
> +   type Logical_Kind_4  is new Logical_Star_4;
> +   type Logical_Kind_8  is new Logical_Star_8;
> +
> +   type Real_Star_4  is new Float;
> +   type Real_Kind_4  is new Float;
> +   type Real_Star_8  is new Long_Float;
> +   type Real_Kind_8  is new Long_Float;
> +
> +   --  In the kind syntax, n is the same as the associated real kind.
> +   --  In the star syntax, n is twice as large (real+imaginary size)
> +   type Complex_Star_8  is new Complex;
> +   type Complex_Kind_4  is new Complex;
> +   type Complex_Star_16 is new Double_Complex;
> +   type Complex_Kind_8  is new Double_Complex;
> +
> +   type Character_Kind_n is new Fortran_Character;
> +
>     function To_Fortran (Item : Character)     return Character_Set;
>     function To_Ada     (Item : Character_Set) return Character;
Edmond Schonberg - March 19, 2013, 10:10 p.m.
Looks fine, including the factor of 2 distinction between Kind and Star for Complex types.  I don't have any opinion on how complete
this is, someone who uses Fortran more extensively will know whether other interface types might be useful.


Ed


On Mar 19, 2013, at 5:51 PM, Arnaud Charlet wrote:

>> I would like if some of the Ada/GNAT experts could have a look - as
>> this is really my first look at Ada code.
> 
> Patch looks reasonable to me at first sight, but I'm not a Fortran specialist.
> 
> Ed, Robert, could you have a look?
> 
>> 2013-03-19  Tobias Burnus  <burnus@net-b.de>
>> 
>> 	* i-fortra.ads: Update comment, add Ada 2012's optional
>> 	Star and Kind data types for enhanced interoperability.
>> 
>> diff --git a/gcc/ada/i-fortra.ads b/gcc/ada/i-fortra.ads
>> index 992eb28..270c819 100644
>> --- a/gcc/ada/i-fortra.ads
>> +++ b/gcc/ada/i-fortra.ads
>> @@ -26,11 +26,11 @@ package Interfaces.Fortran is
>>    type Logical is new Boolean;
>>    for Logical'Size use Integer'Size;
>>    pragma Convention (Fortran, Logical);
>> -   --  As required by Fortran standard, stand alone logical allocates same
>> -   --  space as integer (but what about the array case???). The convention
>> -   --  is important, since in Fortran, Booleans have zero/non-zero semantics
>> -   --  for False/True, and the pragma Convention (Fortran) activates the
>> -   --  special handling required in this case.
>> +   --  As required by Fortran standard, logical allocates same space as
>> +   --  an integer. The convention is important, since in Fortran, Booleans
>> +   --  are implemented with zero/non-zero semantics for False/True, and the
>> +   --  pragma Convention (Fortran) activates the special handling required
>> +   --  in this case.
>> 
>>    package Single_Precision_Complex_Types is
>>       new Ada.Numerics.Generic_Complex_Types (Real);
>> @@ -50,6 +50,53 @@ package Interfaces.Fortran is
>> 
>>    type Fortran_Character is array (Positive range <>) of
>>    Character_Set;
>> 
>> +   --  Additional declarations as permitted by Ada 2012, p.608, paragraph 21.
>> +   --  Interoperability with Fortran 77's vendor extension using star
>> +   --  notation and Fortran 90's intrinsic types with kind=n parameter.
>> +   --  The following assumes that `n' matches the byte size, which
>> +   --  most Fortran compiler, including GCC's follow.
>> +
>> +   type Integer_Star_1  is new Integer_8;
>> +   type Integer_Kind_1  is new Integer_8;
>> +   type Integer_Star_2  is new Integer_16;
>> +   type Integer_Kind_2  is new Integer_16;
>> +   type Integer_Star_4  is new Integer_32;
>> +   type Integer_Kind_4  is new Integer_32;
>> +   type Integer_Star_8  is new Integer_64;
>> +   type Integer_Kind_8  is new Integer_64;
>> +
>> +   type Logical_Star_1  is new Boolean;
>> +   type Logical_Star_2  is new Boolean;
>> +   type Logical_Star_4  is new Boolean;
>> +   type Logical_Star_8  is new Boolean;
>> +   for Logical_Star_1'Size use Integer_8'Size;
>> +   for Logical_Star_2'Size use Integer_16'Size;
>> +   for Logical_Star_4'Size use Integer_32'Size;
>> +   for Logical_Star_8'Size use Integer_64'Size;
>> +   pragma Convention (Fortran, Logical_Star_1);
>> +   pragma Convention (Fortran, Logical_Star_2);
>> +   pragma Convention (Fortran, Logical_Star_4);
>> +   pragma Convention (Fortran, Logical_Star_8);
>> +
>> +   type Logical_Kind_1  is new Logical_Star_1;
>> +   type Logical_Kind_2  is new Logical_Star_2;
>> +   type Logical_Kind_4  is new Logical_Star_4;
>> +   type Logical_Kind_8  is new Logical_Star_8;
>> +
>> +   type Real_Star_4  is new Float;
>> +   type Real_Kind_4  is new Float;
>> +   type Real_Star_8  is new Long_Float;
>> +   type Real_Kind_8  is new Long_Float;
>> +
>> +   --  In the kind syntax, n is the same as the associated real kind.
>> +   --  In the star syntax, n is twice as large (real+imaginary size)
>> +   type Complex_Star_8  is new Complex;
>> +   type Complex_Kind_4  is new Complex;
>> +   type Complex_Star_16 is new Double_Complex;
>> +   type Complex_Kind_8  is new Double_Complex;
>> +
>> +   type Character_Kind_n is new Fortran_Character;
>> +
>>    function To_Fortran (Item : Character)     return Character_Set;
>>    function To_Ada     (Item : Character_Set) return Character;
Arnaud Charlet - March 19, 2013, 10:11 p.m.
> Looks fine, including the factor of 2 distinction between Kind and Star for
> Complex types.  I don't have any opinion on how complete
> this is, someone who uses Fortran more extensively will know whether other
> interface types might be useful.

Thanks Ed.

So Tobias: you can go ahead and commit these changes, assuming a clean
build/test for Ada.

Arno
Tobias Burnus - March 20, 2013, 9:26 a.m.
Arnaud Charlet wrote:
> So Tobias: you can go ahead and commit these changes, assuming a clean 
> build/test for Ada.

I did a successful bootstrap (true all languages (all+ada+go+Obj-c(++))) 
and "make check-ada" without any failures on x86-64-gnu-linux.

Committed as Rev. 196814.

Thanks for the review!

Tobias

Patch

2013-03-19  Tobias Burnus  <burnus@net-b.de>

	* i-fortra.ads: Update comment, add Ada 2012's optional
	Star and Kind data types for enhanced interoperability.

diff --git a/gcc/ada/i-fortra.ads b/gcc/ada/i-fortra.ads
index 992eb28..270c819 100644
--- a/gcc/ada/i-fortra.ads
+++ b/gcc/ada/i-fortra.ads
@@ -26,11 +26,11 @@  package Interfaces.Fortran is
    type Logical is new Boolean;
    for Logical'Size use Integer'Size;
    pragma Convention (Fortran, Logical);
-   --  As required by Fortran standard, stand alone logical allocates same
-   --  space as integer (but what about the array case???). The convention
-   --  is important, since in Fortran, Booleans have zero/non-zero semantics
-   --  for False/True, and the pragma Convention (Fortran) activates the
-   --  special handling required in this case.
+   --  As required by Fortran standard, logical allocates same space as
+   --  an integer. The convention is important, since in Fortran, Booleans
+   --  are implemented with zero/non-zero semantics for False/True, and the
+   --  pragma Convention (Fortran) activates the special handling required
+   --  in this case.
 
    package Single_Precision_Complex_Types is
       new Ada.Numerics.Generic_Complex_Types (Real);
@@ -50,6 +50,53 @@  package Interfaces.Fortran is
 
    type Fortran_Character is array (Positive range <>) of Character_Set;
 
+   --  Additional declarations as permitted by Ada 2012, p.608, paragraph 21.
+   --  Interoperability with Fortran 77's vendor extension using star
+   --  notation and Fortran 90's intrinsic types with kind=n parameter.
+   --  The following assumes that `n' matches the byte size, which
+   --  most Fortran compiler, including GCC's follow.
+
+   type Integer_Star_1  is new Integer_8;
+   type Integer_Kind_1  is new Integer_8;
+   type Integer_Star_2  is new Integer_16;
+   type Integer_Kind_2  is new Integer_16;
+   type Integer_Star_4  is new Integer_32;
+   type Integer_Kind_4  is new Integer_32;
+   type Integer_Star_8  is new Integer_64;
+   type Integer_Kind_8  is new Integer_64;
+
+   type Logical_Star_1  is new Boolean;
+   type Logical_Star_2  is new Boolean;
+   type Logical_Star_4  is new Boolean;
+   type Logical_Star_8  is new Boolean;
+   for Logical_Star_1'Size use Integer_8'Size;
+   for Logical_Star_2'Size use Integer_16'Size;
+   for Logical_Star_4'Size use Integer_32'Size;
+   for Logical_Star_8'Size use Integer_64'Size;
+   pragma Convention (Fortran, Logical_Star_1);
+   pragma Convention (Fortran, Logical_Star_2);
+   pragma Convention (Fortran, Logical_Star_4);
+   pragma Convention (Fortran, Logical_Star_8);
+
+   type Logical_Kind_1  is new Logical_Star_1;
+   type Logical_Kind_2  is new Logical_Star_2;
+   type Logical_Kind_4  is new Logical_Star_4;
+   type Logical_Kind_8  is new Logical_Star_8;
+
+   type Real_Star_4  is new Float;
+   type Real_Kind_4  is new Float;
+   type Real_Star_8  is new Long_Float;
+   type Real_Kind_8  is new Long_Float;
+
+   --  In the kind syntax, n is the same as the associated real kind.
+   --  In the star syntax, n is twice as large (real+imaginary size)
+   type Complex_Star_8  is new Complex;
+   type Complex_Kind_4  is new Complex;
+   type Complex_Star_16 is new Double_Complex;
+   type Complex_Kind_8  is new Double_Complex;
+
+   type Character_Kind_n is new Fortran_Character;
+
    function To_Fortran (Item : Character)     return Character_Set;
    function To_Ada     (Item : Character_Set) return Character;