Rationale Update for Ada 2012

John Barnes
Contents   Index   References   Previous   Next 

Chapter 7: Predefined library

The main improvements in the standard library in Ada 2012 concern containers and these are addressed in the next section. There were also other additions such as UTF encoding packages, extensions to directories and the package Locales.
The following Ada Issues cover this area:
28*
Import of variadic C functions
30
Formal derived types and stream attribute availability
31
All_Calls_Remote and indirect calls
34
Remote stream attribute calls
37*
New types in Ada.Locales cannot be converted to/from strings
88
UTF_Encoding.Conversions and overlong characters on input
102
Stream_IO.File_Type has Preelaborable_Initialization
106
Write'Class attribute
121
Stream-oriented aspects
130
All I/O packages should have Flush
135
Enumeration types should be eligible for convention C
146
Should say stream-oriented attribute
These changes can be grouped as follows.
A number of issues concern streams, their aspects and attributes (30, 34, 102, 106, 121, 146).
Two issues concern interfacing to the C language (28, 135).
Minor issues concern I/O packages and Flush (130), the aspect All_Calls_Remote (31), and UTF_Encoding (88).
Finally, there is a major revision to the new package Ada.Locales (37).

AI-121 points out that the stream-oriented attributes such as 'Read and 'Write can be given using an aspect specification as well as by an attribute definition clause. Thus for a type Date we can declare a procedure Date_Write and associate them using
for Date'Write use Date_Write;
Alternatively, we can declare Date as
type Date is record ... end record
   with Write => Date_Write, ... ;
and then declare the procedure Date_Write.
AI-146 just corrects a bit of wording; strictly we always talk about stream-oriented attributes and not stream attributes. AI-30 clarifies the use of stream-oriented attributes with untagged formal derived types but ironically refers to them as stream attributes. AI-34 concerns the use of streams and Remote_Types packages; in summary, dereferencing a remote access-to-classwide type to make a dispatching call to a stream-oriented attribute such as 'Write is not allowed.
AI-106 clarifies the way in which a class wide stream-oriented aspect is given. For example
type My_Type is abstract tagged null record
   with Write'Class => My_Write;
AI-102 adds the pragma Preelaborable_Initialization to the type File_Type in the package Ada.Streams.Stream_IO. It points out that the package was made preelaborable in Ada 2012 so that it was more useful but the corresponding change to the private type File_Type was forgotten.
Two issues concern interfacing to C. AI-28 discusses the import of variadic C functions (that is functions with a variable number of parameters). In Ada 95, it was expected that such functions would use the same calling conventions as normal C functions; however, that is not true for some targets today. Accordingly, this AI adds additional conventions to describe variadic C functions so that the Ada compiler can compile the correct calling sequence. The other issue (135) concerns enumeration types and makes them eligible for convention C provided certain range conditions are satisfied.
With regard to input-output in general AI-130 adds the procedure Flush to the packages Sequential_IO and Direct_IO so that any internal buffers can be flushed in the same way as in Text_IO and Stream_IO.
A rather specialized change is made by AI-31 concerning the aspect All_Calls_Remote. It states that the aspect applies to all indirect or dispatching remote subprogram calls to the RCI (remote call interface unit) as well as to direct calls from outside. All indirect or dispatching calls should go through the PCS (partition communication subsystem).
A number of packages for UTF encoding were added in Ada 2012. AI-88 addresses a minor issue regarding overlong characters on input, that is as a parameter to a function Encode or Convert. It confirms that such overlong encodings do not raise Encoding_Error.
Finally, AI-37 discusses a curious difficulty found in attempting to use the seemingly innocuous new package Ada.Locales. It was mentioned in the Ada 2012 Rationale which we repeat.
The types Language_Code and Country_Code were originally declared as
type Language_Code is array (1 .. 3) of Character
                range 'a' .. 'z';
type Country_Code is array (1 .. 2) of Character
                range 'A' .. 'Z';
The problem is that a value of these types is not a string and cannot easily be converted into a string because of the range constraints and so cannot be a simple parameter of a subprogram such as Put. If LC is of type Language_Code then we have to write something tedious such as
Put(LC(1));  Put(LC(2));  Put(LC(3));
Accordingly, these types are changed so that they are derived from the type String and the constraints on the letters are then imposed by dynamic predicates. So we have
type Language_Code is new String(1 .. 3)
   with Dynamic_Predicate =>
      (for all E of Language_Code => E in 'a' .. 'z';
with a similar construction for Country_Code.
Readers might like to continue to contemplate whether this is an excellent illustration of some of the new features of Ada 2012 or simply an illustration of static strong or maybe string typing going astray.

Contents   Index   References   Previous   Next 
© 2016 John Barnes Informatics.