diff mbox

[Ada] Documentation for GNAT dimensionality checking system

Message ID 20120208101449.GA27202@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Feb. 8, 2012, 10:14 a.m. UTC
Tested on x86_64-pc-linux-gnu, committed on trunk

2012-02-08  Vincent Pucci  <pucci@adacore.com>

	* impunit.adb: Dimension package names updated
	* Makefile.rtl: s-dim added
	* sem_dim.adb (Is_Procedure_Put_Call): minor changes
	(Is_Dim_IO_Package_Instantiation): minor changes
	* sem_dim.ads: minor changes in comments
	* snames.ads-tmpl: Name_Dim added Name_Dim_Float_IO and
	Name_Dim_Integer_IO removed
	* s-dim.ads: New package. Define the dimension terminology.
	* s-diflio.adb, s-diinio.adb, s-dimkio.ads, s-dimmks.ads,
	* s-dmotpr.ads: Package names updated.
	* s-diflio.ads, s-diinio.ads: Documentation added and package
	names updated.
diff mbox

Patch

Index: impunit.adb
===================================================================
--- impunit.adb	(revision 183996)
+++ impunit.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---           Copyright (C) 2000-2011, Free Software Foundation, Inc.        --
+--           Copyright (C) 2000-2012, Free Software Foundation, Inc.        --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -366,11 +366,11 @@ 
 
     ("s-addima", F),  -- System.Address_Image
     ("s-assert", F),  -- System.Assertions
-    ("s-diflio", F),  -- System.Dim_Float_IO
-    ("s-diinio", F),  -- System.Dim_Integer_IO
-    ("s-dimkio", F),  -- System.Dim_Mks_IO
-    ("s-dimmks", F),  -- System.Dim_Mks
-    ("s-dmotpr", F),  -- System.Dim_Mks.Other_Prefixes
+    ("s-diflio", F),  -- System.Dim.Float_IO
+    ("s-diinio", F),  -- System.Dim.Integer_IO
+    ("s-dimkio", F),  -- System.Dim.Mks_IO
+    ("s-dimmks", F),  -- System.Dim.Mks
+    ("s-dmotpr", F),  -- System.Dim.Mks.Other_Prefixes
     ("s-memory", F),  -- System.Memory
     ("s-parint", F),  -- System.Partition_Interface
     ("s-pooglo", F),  -- System.Pool_Global
Index: s-diinio.adb
===================================================================
--- s-diinio.adb	(revision 183996)
+++ s-diinio.adb	(working copy)
@@ -2,7 +2,7 @@ 
 --                                                                          --
 --                         GNAT RUN-TIME COMPONENTS                         --
 --                                                                          --
---                  S Y S T E M . D I M _ I N T E G E R _ I O               --
+--                  S Y S T E M . D I M . I N T E G E R _ I O               --
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
@@ -29,7 +29,7 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-package body System.Dim_Integer_IO is
+package body System.Dim.Integer_IO is
 
    package Num_Dim_Integer_IO is new Ada.Text_IO.Integer_IO (Num_Dim_Integer);
 
@@ -74,4 +74,4 @@ 
       To := To & Symbols;
    end Put;
 
-end System.Dim_Integer_IO;
+end System.Dim.Integer_IO;
Index: s-diinio.ads
===================================================================
--- s-diinio.ads	(revision 183996)
+++ s-diinio.ads	(working copy)
@@ -2,7 +2,7 @@ 
 --                                                                          --
 --                         GNAT RUN-TIME COMPONENTS                         --
 --                                                                          --
---                  S Y S T E M . D I M _ I N T E G E R _ I O               --
+--                  S Y S T E M . D I M . I N T E G E R _ I O               --
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
@@ -29,19 +29,81 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
---  This package is a generic package that provides IO facilities for integer
---  dimensioned types.
+--  This package provides output routines for integer dimensioned types. All
+--  Put routines are modelled after those in package Ada.Text_IO.Integer_IO
+--  with the addition of an extra default parameter.
 
---  Note that there is a default string parameter in every Put routine
---  rewritten at compile time to output the corresponding dimensions as a
---  suffix of the numeric value.
+--  All the examples in this package are based on the MKS system of units:
 
+--    type Mks_Type is new Integer
+--      with
+--       Dimension_System => ((Meter, 'm'),
+--         (Kilogram, "kg"),
+--         (Second,   's'),
+--         (Ampere,   'A'),
+--         (Kelvin,   'K'),
+--         (Mole,     "mol"),
+--         (Candela,  "cd"));
+
+--  Parameter Symbol may be used in the following manner:
+
+--  Case 1. A value is supplied for Symbol
+
+--    The string appears as a suffix of Item
+
+--      Obj : Mks_Type := 2;
+--      Put (Obj, Symbols => " dimensionless");
+
+--      The corresponding output is: 2 dimensionless
+
+--  Case 2. No value is supplied for Symbol and Item is dimensionless
+
+--    Item appears without a suffix
+
+--      Obj : Mks_Type := 2;
+--      Put (Obj);
+
+--      The corresponding output is: 2
+
+--  Case 3. No value is supplied for Symbol and Item has a dimension
+
+--    If the type of Item is a dimensioned subtype whose symbolic name is not
+--    empty, then the symbolic name appears as a suffix.
+
+--      subtype Length is Mks_Type
+--        with
+--         Dimension => ('m',
+--           Meter =>  1,
+--           others => 0);
+
+--      Obj : Length := 2;
+--      Put (Obj);
+
+--      The corresponding output is: 2 m
+
+--    Otherwise, a new string is created and appears as a suffix of Item.
+--    This string results in the successive concatanations between each
+--    dimension symbolic name raised by its corresponding dimension power from
+--    the dimensions of Item.
+
+--      subtype Random is Mks_Type
+--        with
+--         Dimension => ("",
+--         Meter =>   3,
+--         Candela => 2,
+--         others =>  0);
+
+--      Obj : Random := 5;
+--      Put (Obj);
+
+--      The corresponding output is: 5 m**3.cd**2
+
 with Ada.Text_IO; use Ada.Text_IO;
 
 generic
    type Num_Dim_Integer is range <>;
 
-package System.Dim_Integer_IO is
+package System.Dim.Integer_IO is
 
    Default_Width : Field       := Num_Dim_Integer'Width;
    Default_Base  : Number_Base := 10;
@@ -67,4 +129,4 @@ 
 
    pragma Inline (Put);
 
-end System.Dim_Integer_IO;
+end System.Dim.Integer_IO;
Index: sem_dim.adb
===================================================================
--- sem_dim.adb	(revision 183996)
+++ sem_dim.adb	(working copy)
@@ -2126,7 +2126,7 @@ 
    -- Expand_Put_Call_With_Dimension_Symbol --
    -------------------------------------------
 
-   --  For procedure Put defined in System.Dim_Float_IO/System.Dim_Integer_IO,
+   --  For procedure Put defined in System.Dim.Float_IO/System.Dim.Integer_IO,
    --  the default string parameter must be rewritten to include the dimension
    --  symbols in the output of a dimensioned object.
 
@@ -2175,8 +2175,8 @@ 
 
       function Is_Procedure_Put_Call return Boolean;
       --  Return True if the current call is a call of an instantiation of a
-      --  procedure Put defined in the package System.Dim_Float_IO and
-      --  System.Dim_Integer_IO.
+      --  procedure Put defined in the package System.Dim.Float_IO and
+      --  System.Dim.Integer_IO.
 
       function Item_Actual return Node_Id;
       --  Return the item actual parameter node in the put call
@@ -2240,16 +2240,17 @@ 
             then
                Ent := Cunit_Entity (Get_Source_Unit (Ent));
 
-               --  Verify that the generic package is System.Dim_Float_IO or
-               --  System.Dim_Integer_IO.
+               --  Verify that the generic package is System.Dim.Float_IO or
+               --  System.Dim.Integer_IO.
 
                if Is_Library_Level_Entity (Ent) then
                   Package_Name := Chars (Ent);
 
-                  return
-                    Package_Name = Name_Dim_Float_IO
-                      or else
-                    Package_Name = Name_Dim_Integer_IO;
+                  if Package_Name = Name_Float_IO
+                    or else Package_Name = Name_Integer_IO
+                  then
+                     return Chars (Scope (Ent)) = Name_Dim;
+                  end if;
                end if;
             end if;
          end if;
@@ -2511,11 +2512,13 @@ 
       if Is_Entity_Name (Gen_Id) then
          Ent := Entity (Gen_Id);
 
-         return
-           Is_Library_Level_Entity (Ent)
-             and then
-               (Chars (Ent) = Name_Dim_Float_IO
-                 or else Chars (Ent) = Name_Dim_Integer_IO);
+         if Is_Library_Level_Entity (Ent)
+           and then
+            (Chars (Ent) = Name_Float_IO
+               or else Chars (Ent) = Name_Integer_IO)
+         then
+            return Chars (Scope (Ent)) = Name_Dim;
+         end if;
       end if;
 
       return False;
Index: sem_dim.ads
===================================================================
--- sem_dim.ads	(revision 183996)
+++ sem_dim.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---            Copyright (C) 2011, Free Software Foundation, Inc.            --
+--           Copyright (C) 2011-2012, Free Software Foundation, Inc.        --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -27,7 +27,7 @@ 
 --  "dimension" is a compile-time property of a numerical type which represents
 --  a relation between various quantifiers such as length, velocity, etc.
 
---  Package System.Dim_Mks offers a ready-to-use system of SI base units. In
+--  Package System.Dim.Mks offers a ready-to-use system of SI base units. In
 --  addition, the implementation of this feature offers the ability to define
 --  an arbitrary system of units through the use of Ada 2012 aspects.
 
@@ -83,12 +83,6 @@ 
 --  Phase 2 is called only when the node allows a dimension (see body of
 --  Sem_Dim to get the list of nodes that permit dimensions).
 
-------------------
--- Dimension_IO --
-------------------
-
---  This section contains the routine used for IO purposes
-
 with Types; use Types;
 
 package Sem_Dim is
@@ -145,7 +139,7 @@ 
 
    procedure Expand_Put_Call_With_Dimension_Symbol (N : Node_Id);
    --  Determine whether N denotes a subprogram call to one of the routines
-   --  defined in System.Dim_Float_IO or System.Dim_Integer_IO and add an
+   --  defined in System.Dim.Float_IO or System.Dim.Integer_IO and add an
    --  extra actual to the call to represent the symbolic representation of
    --  a dimension.
 
@@ -153,8 +147,8 @@ 
    --  Return True if type Typ has aspect Dimension_System applied to it
 
    function Is_Dim_IO_Package_Instantiation (N : Node_Id) return Boolean;
-   --  Return True if N is a package instantiation of System.Dim_Integer_IO or
-   --  of System.Dim_Float_IO.
+   --  Return True if N is a package instantiation of System.Dim.Integer_IO or
+   --  of System.Dim.Float_IO.
 
    procedure Remove_Dimension_In_Call (Call : Node_Id);
    --  Remove the dimensions from all formal parameters of Call
Index: s-dmotpr.ads
===================================================================
--- s-dmotpr.ads	(revision 183996)
+++ s-dmotpr.ads	(working copy)
@@ -2,11 +2,11 @@ 
 --                                                                          --
 --                         GNAT RUN-TIME COMPONENTS                         --
 --                                                                          --
---         S Y S T E M . D I M _ M K S . O T H E R _ P R E F I X E S        --
+--         S Y S T E M . D I M . M K S . O T H E R _ P R E F I X E S        --
 --                                                                          --
 --                                  S p e c                                 --
 --                                                                          --
---            Copyright (C) 2011, Free Software Foundation, Inc.            --
+--           Copyright (C) 2011-2012, Free Software Foundation, Inc.        --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -34,7 +34,7 @@ 
 --  These prefixes have been defined in a child package in order to avoid too
 --  many constant declarations in System.Dim_Mks.
 
-package System.Dim_Mks.Other_Prefixes is
+package System.Dim.Mks.Other_Prefixes is
 
    --  SI prefixes for Meter
 
@@ -165,4 +165,4 @@ 
    Zecd : constant Luminous_Intensity := 1.0E+21;  -- zetta
    Yocd : constant Luminous_Intensity := 1.0E+24;  -- yotta
 
-end System.Dim_Mks.Other_Prefixes;
+end System.Dim.Mks.Other_Prefixes;
Index: s-dim.ads
===================================================================
--- s-dim.ads	(revision 0)
+++ s-dim.ads	(revision 0)
@@ -0,0 +1,69 @@ 
+------------------------------------------------------------------------------
+--                                                                          --
+--                         GNAT RUN-TIME COMPONENTS                         --
+--                                                                          --
+--                           S Y S T E M . D I M                            --
+--                                                                          --
+--                                 S p e c                                  --
+--                                                                          --
+--             Copyright (C) 2012, Free Software Foundation, Inc.           --
+--                                                                          --
+-- GNAT is free software;  you can  redistribute it  and/or modify it under --
+-- terms of the  GNU General Public License as published  by the Free Soft- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
+-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
+-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
+--                                                                          --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
+--                                                                          --
+-- GNAT was originally developed  by the GNAT team at  New York University. --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
+--                                                                          --
+------------------------------------------------------------------------------
+
+--  Defines the dimension terminology
+
+---------------------------
+-- Dimension Terminology --
+---------------------------
+
+--  * Dimensioned type
+
+--    A dimensioned type is a type (more accurately a first subtype) to which
+--    the aspect Dimension_System applies to.
+
+--      type Mks_Type is new Long_Long_Float
+--        with
+--         Dimension_System => ((Meter, 'm'),
+--           (Kilogram, "kg"),
+--           (Second,   's'),
+--           (Ampere,   'A'),
+--           (Kelvin,   'K'),
+--           (Mole,     "mol"),
+--           (Candela,  "cd"));
+
+--      'm' is the symbolic name of dimension Meter
+
+--  * Dimensioned subtype
+
+--    A dimensioned subtype is a subtype directly defined from the dimensioned
+--    type and to which the aspect Dimension applies to.
+
+--      subtype Length is Mks_Type
+--        with
+--         Dimension => ('m',
+--           Meter =>  1,
+--           others => 0);
+
+--      'm' is the symbolic name of dimensioned subtype Length
+
+package System.Dim is
+end System.Dim;
Index: s-diflio.adb
===================================================================
--- s-diflio.adb	(revision 183996)
+++ s-diflio.adb	(working copy)
@@ -2,7 +2,7 @@ 
 --                                                                          --
 --                         GNAT RUN-TIME COMPONENTS                         --
 --                                                                          --
---                    S Y S T E M . D I M _ F L O A T _ I O                 --
+--                    S Y S T E M . D I M . F L O A T _ I O                 --
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
@@ -29,7 +29,7 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-package body System.Dim_Float_IO is
+package body System.Dim.Float_IO is
 
    package Num_Dim_Float_IO is new Ada.Text_IO.Float_IO (Num_Dim_Float);
 
@@ -74,4 +74,4 @@ 
       To := To & Symbols;
    end Put;
 
-end System.Dim_Float_IO;
+end System.Dim.Float_IO;
Index: s-diflio.ads
===================================================================
--- s-diflio.ads	(revision 183996)
+++ s-diflio.ads	(working copy)
@@ -2,7 +2,7 @@ 
 --                                                                          --
 --                         GNAT RUN-TIME COMPONENTS                         --
 --                                                                          --
---                    S Y S T E M . D I M _ F L O A T _ I O                 --
+--                    S Y S T E M . D I M . F L O A T _ I O                 --
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
@@ -29,19 +29,74 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
---  This package is a generic package that provides IO facilities for float
---  dimensioned types.
+--  This package provides output routines for float dimensioned types. All Put
+--  routines are modelled after those in package Ada.Text_IO.Float_IO with the
+--  addition of an extra default parameter.
 
---  Note that there is a default string parameter in every Put routine
---  rewritten at compile time to output the corresponding dimensions as a
---  suffix of the numeric value.
+--  Parameter Symbol may be used in the following manner (all the examples are
+--  based on the MKS system of units as defined in package System.Dim.Mks):
 
+--  Case 1. A value is supplied for Symbol
+
+--    The string appears as a suffix of Item
+
+--      Obj : Mks_Type := 2.6;
+--      Put (Obj, 1, 1, 0, " dimensionless");
+
+--      The corresponding output is: 2.6 dimensionless
+
+--  Case 2. No value is supplied for Symbol and Item is dimensionless
+
+--    Item appears without a suffix
+
+--      Obj : Mks_Type := 2.6;
+--      Put (Obj, 1, 1, 0);
+
+--      The corresponding output is: 2.6
+
+--  Case 3. No value is supplied for Symbol and Item has a dimension
+
+--    If the type of Item is a dimensioned subtype whose symbolic name is not
+--    empty, then the symbolic name appears as a suffix.
+
+--      subtype Length is Mks_Type
+--        with
+--         Dimension => ('m',
+--           Meter =>  1,
+--           others => 0);
+
+--      Obj : Length := 2.3 * dm;
+--      Put (Obj, 1, 2, 0);
+
+--      The corresponding output is: 0.23 m
+
+--    Otherwise, a new string is created and appears as a suffix of Item.
+--    This string results in the successive concatanations between each
+--    dimension symbolic name raised by its corresponding dimension power from
+--    the dimensions of Item.
+
+--      subtype Random is Mks_Type
+--        with
+--         Dimension => ("",
+--         Meter =>   3,
+--         Candela => -1,
+--         others =>  0);
+
+--      Obj : Random := 5.0;
+--      Put (Obj);
+
+--      The corresponding output is: 5.0 m**3.cd**(-1)
+
+--      Put (3.3 * km * dm * min, 5, 1, 0);
+
+--      The corresponding output is: 19800.0 m**2.s
+
 with Ada.Text_IO; use Ada.Text_IO;
 
 generic
    type Num_Dim_Float is digits <>;
 
-package System.Dim_Float_IO is
+package System.Dim.Float_IO is
 
    Default_Fore : Field := 2;
    Default_Aft  : Field := Num_Dim_Float'Digits - 1;
@@ -71,4 +126,4 @@ 
 
    pragma Inline (Put);
 
-end System.Dim_Float_IO;
+end System.Dim.Float_IO;
Index: Makefile.rtl
===================================================================
--- Makefile.rtl	(revision 183996)
+++ Makefile.rtl	(working copy)
@@ -505,6 +505,7 @@ 
   s-crtl$(objext)   \
   s-crtrun$(objext) \
   s-diflio$(objext) \
+  s-dim$(objext)    \
   s-diinio$(objext) \
   s-dimkio$(objext) \
   s-dimmks$(objext) \
Index: s-dimmks.ads
===================================================================
--- s-dimmks.ads	(revision 183996)
+++ s-dimmks.ads	(working copy)
@@ -2,7 +2,7 @@ 
 --                                                                          --
 --                         GNAT RUN-TIME COMPONENTS                         --
 --                                                                          --
---                        S Y S T E M . D I M _ M K S                       --
+--                        S Y S T E M . D I M . M K S                       --
 --                                                                          --
 --                                  S p e c                                 --
 --                                                                          --
@@ -35,9 +35,11 @@ 
 --  System.Dim_Mks.Other_Prefixes) in order to avoid too many constant
 --  declarations in this package.
 
+--  The dimension terminology is defined in System.Dim_IO package
+
 with Ada.Numerics;
 
-package System.Dim_Mks is
+package System.Dim.Mks is
 
    e  : constant := Ada.Numerics.e;
    Pi : constant := Ada.Numerics.Pi;
@@ -54,7 +56,7 @@ 
         (Mole,     "mol"),
         (Candela,  "cd"));
 
-   --  SI Base
+   --  SI Base dimensioned subtype
 
    subtype Length is Mks_Type
      with
@@ -321,4 +323,4 @@ 
    kA  : constant Electric_Current := 1.0E+03;  -- kilo
    MeA : constant Electric_Current := 1.0E+06;  -- mega
 
-end System.Dim_Mks;
+end System.Dim.Mks;
Index: snames.ads-tmpl
===================================================================
--- snames.ads-tmpl	(revision 184003)
+++ snames.ads-tmpl	(working copy)
@@ -225,8 +225,7 @@ 
    --  Names used by the analyzer and expander for aspect Dimension and
    --  Dimension_System to deal with Sqrt and IO routines.
 
-   Name_Dim_Float_IO                 : constant Name_Id := N + $; -- Ada 12
-   Name_Dim_Integer_IO               : constant Name_Id := N + $; -- Ada 12
+   Name_Dim                          : constant Name_Id := N + $; -- Ada 12
    Name_Generic_Elementary_Functions : constant Name_Id := N + $; -- Ada 12
    Name_Item                         : constant Name_Id := N + $; -- Ada 12
    Name_Sqrt                         : constant Name_Id := N + $; -- Ada 12
Index: s-dimkio.ads
===================================================================
--- s-dimkio.ads	(revision 183996)
+++ s-dimkio.ads	(working copy)
@@ -2,11 +2,11 @@ 
 --                                                                          --
 --                         GNAT RUN-TIME COMPONENTS                         --
 --                                                                          --
---                     S Y S T E M . D I M _ M K S _ I O                    --
+--                     S Y S T E M . D I M . M K S _ I O                    --
 --                                                                          --
 --                                  S p e c                                 --
 --                                                                          --
---            Copyright (C) 2011, Free Software Foundation, Inc.            --
+--           Copyright (C) 2011-2012, Free Software Foundation, Inc.        --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -29,10 +29,10 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
---  This package provides IO routines for the MKS dimension system (see
---  System.Dim_Mks).
+--  Provides output facilities for the MKS dimension system (see System.Dim.Mks
+--  and System.Dim.Float_IO).
 
-with System.Dim_Mks; use System.Dim_Mks;
-with System.Dim_Float_IO;
+with System.Dim.Mks; use System.Dim.Mks;
+with System.Dim.Float_IO;
 
-package System.Dim_Mks_IO is new System.Dim_Float_IO (Mks_Type);
+package System.Dim.Mks_IO is new System.Dim.Float_IO (Mks_Type);