From 7a6de2e28f76b03283097d1f2c36511cd7fe7dcc Mon Sep 17 00:00:00 2001 From: Arnaud Charlet Date: Thu, 26 Apr 2012 11:56:13 +0200 Subject: [PATCH] [multiple changes] 2012-04-26 Ed Schonberg * gnat_ugn.texi: Tweak dimensionality doc. 2012-04-26 Robert Dewar * sem_eval.adb: Minor reformatting. From-SVN: r186869 --- gcc/ada/ChangeLog | 8 ++++++++ gcc/ada/gnat_ugn.texi | 18 +++++++++++++----- gcc/ada/sem_eval.adb | 5 +++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index cf0cac643e0..2b65223d7d8 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,11 @@ +2012-04-26 Ed Schonberg + + * gnat_ugn.texi: Tweak dimensionality doc. + +2012-04-26 Robert Dewar + + * sem_eval.adb: Minor reformatting. + 2012-04-26 Robert Dewar * einfo.adb, einfo.ads, sem_res.adb, sem_ch4.adb, diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi index 57cb020fb82..996137cc17f 100644 --- a/gcc/ada/gnat_ugn.texi +++ b/gcc/ada/gnat_ugn.texi @@ -18534,6 +18534,10 @@ version 7.0.1 of GNAT onwards. The GNAT-specific aspect Dimension_System allows the user to define a system of units; the aspect Dimension then allows the user to declare dimensioned quantities within a given system. +The major advantage of this model is that it does not require the declaration of +multiple operators for all possible combinations of types: it is only necessary +to use the proper subtypes in object declarations. + The simplest way to impose dimensionality checking on a computation is to make use of the package System.Dim.Mks, which is part of the GNAT library. This package defines a floating-point type MKS_Type, for which a sequence of @@ -18592,11 +18596,12 @@ as well as useful multiples of these units: @noindent The user can then define a derived unit by providing the aspect that -specifies its dimensions within the MKS system: +specifies its dimensions within the MKS system, as well as the string to +be used for output of a value of that unit: @smallexample @c ada subtype Acceleration is Mks_Type - with Dimension => ("m/sec**2", 1, 0, -2, others => 0); + with Dimension => ("m/sec^^^2", Meter => 1, Second => -2, others => 0); @end smallexample @noindent @@ -18608,11 +18613,13 @@ with System.Dim.Mks_IO; use System.Dim.Mks_IO; with Text_IO; use Text_IO; procedure Free_Fall is subtype Acceleration is Mks_Type - with Dimension => ("m/sec**2", 1, 0, -2, others => 0); + with Dimension => ("m/sec^^^2", 1, 0, -2, others => 0); G : constant acceleration := 9.81 * m / (s ** 2); T : Time := 10.0*s; Distance : Length; begin + Put ("Gravitational constant: "); + Put (G, Aft => 2, Exp => 0); Put_Line (""); Distance := 0.5 * G * T ** 2; Put ("distance travelled in 10 seconds of free fall "); Put (Distance, Aft => 2, Exp => 0); @@ -18623,6 +18630,7 @@ end Free_Fall; @noindent Execution of this program yields: @smallexample +Gravitational constant: 9.81 m/sec^^^2 distance travelled in 10 seconds of free fall 490.50 m @end smallexample @@ -18650,8 +18658,8 @@ are rejected with the following diagnoses: @end smallexample @noindent -The dimensions of an expression are properly displayed. If we add to the -program: +The dimensions of an expression are properly displayed, even if there is +no explicit subtype for it. If we add to the program: @smallexample @c ada Put ("Final velocity: "); diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb index 27a0f629d20..2bd111b9bec 100644 --- a/gcc/ada/sem_eval.adb +++ b/gcc/ada/sem_eval.adb @@ -516,6 +516,8 @@ package body Sem_Eval is Subs : Nat; begin + -- Fixup only required for First/Last attribute reference + if Nkind (N) = N_Attribute_Reference and then (Attribute_Name (N) = Name_First or else @@ -577,8 +579,7 @@ package body Sem_Eval is if Attribute_Name (N) = Name_First then return Type_Low_Bound (Xtyp); - - else -- Attribute_Name (N) = Name_Last + else return Type_High_Bound (Xtyp); end if; end if; -- 2.30.2