This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Named association and new component Dim_Symbol implemented for GNAT dimensionality checking system.


This patch implements a new component Dim_Symbol for aspect Dimension_System
and enables named associations for both aspect Dimension and Dimension_System.

The test provided below illustrates the changes introduced by this patch.

-------------
--  Source --
-------------

with System.Dim.Float_IO;

procedure Main is
   --  Foot-Pound-Second system (Absolute English System)

   type AE_type is new Long_Long_Float
     with
      Dimension_System => (
        (Unit_Name => Foot,   Unit_Symbol => "ft", Dim_Symbol => 'L'),
        (Unit_Name => Pound,  Unit_Symbol => "lb", Dim_Symbol => 'M'),
        (Unit_Name => Second, Unit_Symbol => 's',  Dim_Symbol => 'T'));

   package AE_IO is new System.Dim.Float_IO (AE_type);
   use AE_IO;

   subtype Length is AE_type
     with
      Dimension => (Symbol => 'm',
        Foot   => 1,
        others => 0);
   subtype Mass is AE_type
     with
      Dimension => (Symbol => "kg",
        Pound  => 1,
        others =>   0);
   subtype Time is AE_type
     with
      Dimension => (Symbol => 's',
        Second => 1,
        others => 0);

   ft : constant Length := 1.0;
   lb : constant Mass   := 1.0;
   s  : constant Time   := 1.0;

begin
   Put_Dim_Of (ft**(2/3) * lb / (s**2));
end Main;

-------------------------------
-- Compilation and Execution --
-------------------------------

gnatmake -q -gnat12 main.adb
$./main

------------
-- Output --
------------

$[L**(2/3).M.T**(-2)]

Tested on x86_64-pc-linux-gnu, committed on trunk

2012-06-14  Vincent Pucci  <pucci@adacore.com>

	* exp_ch6.adb (Expand_Call): Expand_Put_Call_With_Dimension_Symbol
	call replaced by Expand_Put_Call_With_Symbol call.
	* sem_dim.adb: New fields Unit_Names, Unit_Symbols
	and Dim_Symbols for record type System_Type.
	(From_Dimension_To_String_Of_Symbols): Removed.
	(From_Dim_To_Str_Of_Dim_Symbols): Renames previous
	routine From_Dimension_To_String_Of_Symbols.
	(From_Dim_To_Str_Of_Unit_Symbols): New routine.
	(Analyze_Aspect_Dimension): argument Symbol in aspect
	Dimension aggregate is optional. Named association implemented.
	(Has_Compile_Time_Known_Expressions): Removed.
	(Analyze_Aspect_Dimension_System): New
	component Dim_Symbol in each Dimension aggregate in
	aspect Dimension_System. Named associations implemented.
	(Add_Dimension_Vector_To_Buffer): Removed.
	(Add_Whole_To_Buffer): Removed.
	(Expand_Put_Call_With_Dimension_Symbol.): Removed.
	(Expand_Put_Call_With_Symbol): Renames previous routine
	Expand_Put_Call_With_Dimension_Symbol.
	(Has_Dimension_Symbols): Removed.
	(Has_Symbols): Renames previous routine
	Has_Dimension_Symbols.	(Store_String_Oexpon): New routine.
	* sem_dim.ads (Expand_Put_Call_With_Dimension_Symbol.): Removed.
	(Expand_Put_Call_With_Symbol): Renames previous routine
	Expand_Put_Call_With_Dimension_Symbol.
	* s-diflio.adb, s-diinio.adb (Put): Symbol renames Symbols.
	(Put_Dim_Of): New routines.
	* s-diflio.ads, s-diinio.ads: documentation updated.
	(Put): Symbol renames Symbols.
	(Put_Dim_Of): New routines.
	* s-dim.ads: documentation updated.
	* s-dimmks.ads: dimensioned type and subtypes updated.
	* snames.ads-tmpl: Name_Dim_Symbol, Name_Put_Dim_Of, Name_Symbol,
	and Name_Unit_Symbol added. Name_Symbols removed.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]