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] |
The system is implemented in the GNAT compiler, and performs compile-time checks to verify the dimensional consistency of physical computations. The system allows the user to define his own system of units, and imposes no run-time changes nor multiple compilation passes on the user. Indeed, the user is now able to create his own dimension system, to assign a dimension with any subtypes and to run operations with dimensionned objects. In that case, a dimensionnality checking will be performed. If no dimension has been assigned, the compiler assumes that the item is dimensionless. The following gives an overall example of the dimensionality checking system: -- with System.Dim_Float_IO; procedure Dimension_Test is -- CGS dimensioned type type CGS_Type is new Long_Float with Dimension_System => ((Centimeter, "cm"), (Gram, 'g'), (Second, 's')); -- IO package for CGS_Type package CGS_IO is new System.Dim_Float_IO (CGS_Type); use CGS_IO; -- CGS dimensioned subtypes subtype Length is CGS_Type with Dimension => ("cm", Centimeter => 1, others => 0); subtype Mass is CGS_Type with Dimension => ("g", Gram => 1, others => 0); subtype Time is CGS_Type with Dimension => ('s', Second => 1, others => 0); -- CGS units cm : constant Length := 1.0; g : constant Mass := 1.0; s : constant Time := 1.0; -- Force dimensioned subtype subtype Force is CGS_Type with Dimension => ("dyn", 1, 1, -2); Random_Force : Force; begin Random_Force := 2.1E+02 * cm * g * s**(-2); Put (Random_Force); end Dimension_Test; Tested on x86_64-pc-linux-gnu, committed on trunk 2011-12-15 Vincent Pucci <pucci@adacore.com> * aspects.adb, aspects.ads Aspect_Dimension and Aspect_Dimension_System added * exp_ch6.adb (Expand_Call): Expand_Put_Call_With_Dimension_String case added * gcc-interface/Make-lang.in: s-llflex, sem_dim added. * impunit.adb :s-diflio and s-diinio defined as GNAT Defined Additions to System. * Makefile.rtl: s-diflio, s-diinio and s-llflex added * par-prag.adb, sem_prag.adb: Pragma_Dimension removed * rtsfind.ads: Expon_LLF added * sem_aggr.adb (Resolve_Aggregate): handles aggregate for Aspect_Dimension case * sem_attr.adb (Resolve_Attribute): analyze dimension for attribute * sem_ch10.adb (Analyze_With_Clause): Avoid the warning messages due to the use of a GNAT library for Dimension packages * sem_ch13.adb (Analyze_Aspect_Specifications): Aspect_Dimension and Aspect_Dimension_System cases added (Check_Aspect_At_Freeze_Point): Aspect_Dimension and Aspect_Dimension_System cases added * sem_ch2.adb (Analyze_Identifier): analyze dimension for identifier * sem_ch3.adb (Analyze_Component_Declaration): analyze dimension for component declaration (Analyze_Object_Declaration): analyze dimension for object declaration (Analyze_Subtype_Declaration): analyze dimension for subtype declaration * sem_ch4.adb (Operator_Check): checks exponent is a rational for dimensioned operand for a N_Op_Expon * sem_ch5.adb (Analyze_Assignment): analyze dimension for assignment (Analyze_Statements): removal of dimensions in all statements * sem_ch6.adb (Analyze_Return_Statement): analyze dimension for return statement * sem_ch8.adb (Analyze_Object_Renaming): analyze dimension for object renaming * sem_dim.adb, sem_dim.ads (Analyze_Aspect_Dimension): analyze the expression for aspect dimension and store the values in a Htable. (Analyze_Aspect_Dimension_System): analyze the expression for aspect dimension system and store the new system in a Table. (Analyze_Dimension): propagates dimension (Expand_Put_Call_With_Dimension_String): add the dimension string as a suffix of the numeric value in the output (Has_Dimension): return True if the node has a dimension (Remove_Dimension_In_Declaration): removal of dimension in the expression of the declaration. (Remove_Dimension_In_Statement): removal of dimension in statement * sem_res.adb (Resolve): analyze dimension if the node has already been analyzed. (Resolve_Arithmetic_Op): analyze dimension for arithmetic op. (Resolve_Call): analyze dimension for function call. (Resolve_Comparison_Op): analyze dimension for comparison op. (Resolve_Equality_Op): analyze dimension for equality op. (Resolve_Indexed_Component): analyze dimension for indexed component. (Resolve_Op_Expon): analyze dimension for op expon. (Resolve_Selected_Component): analyze dimension for selected component. (Resolve_Slice): analyze dimension for slice. (Resolve_Unary_Op): analyze dimension for unary op (Resolve_Type_Conversion): analyze dimension for type conversion (Resolve_Unchecked_Type_Conversion): analyze dimension for unchecked type conversion * snames.ads-tmpl Name_Dimension, Name_Dimension_System, Name_Dim_Float_IO, Name_Dim_Integer_IO, Name_Generic_Elementary_Functions, Name_Sqrt added. Pragma_Dimension removed * s-diflio.adb, s-diflio.ads New GNAT library generic package for dimensioned float type IO * s-diinio.adb, s-diinio.ads New GNAT library generic package for dimensioned integer type IO * s-llflex.ads (Expon_LLF): exponentiation routine for long long floats operand and exponent
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] |