1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2011-2014, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Einfo
; use Einfo
;
29 with Errout
; use Errout
;
31 with Namet
; use Namet
;
32 with Nlists
; use Nlists
;
33 with Nmake
; use Nmake
;
35 with Rtsfind
; use Rtsfind
;
37 with Sem_Eval
; use Sem_Eval
;
38 with Sem_Res
; use Sem_Res
;
39 with Sem_Util
; use Sem_Util
;
40 with Sinfo
; use Sinfo
;
41 with Sinput
; use Sinput
;
42 with Snames
; use Snames
;
43 with Stand
; use Stand
;
44 with Stringt
; use Stringt
;
46 with Tbuild
; use Tbuild
;
47 with Uintp
; use Uintp
;
48 with Urealp
; use Urealp
;
52 package body Sem_Dim
is
54 -------------------------
55 -- Rational Arithmetic --
56 -------------------------
58 type Whole
is new Int
;
59 subtype Positive_Whole
is Whole
range 1 .. Whole
'Last;
61 type Rational
is record
63 Denominator
: Positive_Whole
;
66 Zero
: constant Rational
:= Rational
'(Numerator => 0,
69 No_Rational : constant Rational := Rational'(Numerator
=> 0,
71 -- Used to indicate an expression that cannot be interpreted as a rational
72 -- Returned value of the Create_Rational_From routine when parameter Expr
73 -- is not a static representation of a rational.
75 -- Rational constructors
77 function "+" (Right
: Whole
) return Rational
;
78 function GCD
(Left
, Right
: Whole
) return Int
;
79 function Reduce
(X
: Rational
) return Rational
;
81 -- Unary operator for Rational
83 function "-" (Right
: Rational
) return Rational
;
84 function "abs" (Right
: Rational
) return Rational
;
86 -- Rational operations for Rationals
88 function "+" (Left
, Right
: Rational
) return Rational
;
89 function "-" (Left
, Right
: Rational
) return Rational
;
90 function "*" (Left
, Right
: Rational
) return Rational
;
91 function "/" (Left
, Right
: Rational
) return Rational
;
97 Max_Number_Of_Dimensions
: constant := 7;
98 -- Maximum number of dimensions in a dimension system
100 High_Position_Bound
: constant := Max_Number_Of_Dimensions
;
101 Invalid_Position
: constant := 0;
102 Low_Position_Bound
: constant := 1;
104 subtype Dimension_Position
is
105 Nat
range Invalid_Position
.. High_Position_Bound
;
108 array (Dimension_Position
range
109 Low_Position_Bound
.. High_Position_Bound
) of Name_Id
;
110 -- Store the names of all units within a system
112 No_Names
: constant Name_Array
:= (others => No_Name
);
115 array (Dimension_Position
range
116 Low_Position_Bound
.. High_Position_Bound
) of String_Id
;
117 -- Store the symbols of all units within a system
119 No_Symbols
: constant Symbol_Array
:= (others => No_String
);
121 -- The following record should be documented field by field
123 type System_Type
is record
125 Unit_Names
: Name_Array
;
126 Unit_Symbols
: Symbol_Array
;
127 Dim_Symbols
: Symbol_Array
;
128 Count
: Dimension_Position
;
131 Null_System
: constant System_Type
:=
132 (Empty
, No_Names
, No_Symbols
, No_Symbols
, Invalid_Position
);
134 subtype System_Id
is Nat
;
136 -- The following table maps types to systems
138 package System_Table
is new Table
.Table
(
139 Table_Component_Type
=> System_Type
,
140 Table_Index_Type
=> System_Id
,
141 Table_Low_Bound
=> 1,
143 Table_Increment
=> 5,
144 Table_Name
=> "System_Table");
150 type Dimension_Type
is
151 array (Dimension_Position
range
152 Low_Position_Bound
.. High_Position_Bound
) of Rational
;
154 Null_Dimension
: constant Dimension_Type
:= (others => Zero
);
156 type Dimension_Table_Range
is range 0 .. 510;
157 function Dimension_Table_Hash
(Key
: Node_Id
) return Dimension_Table_Range
;
159 -- The following table associates nodes with dimensions
161 package Dimension_Table
is new
162 GNAT
.HTable
.Simple_HTable
163 (Header_Num
=> Dimension_Table_Range
,
164 Element
=> Dimension_Type
,
165 No_Element
=> Null_Dimension
,
167 Hash
=> Dimension_Table_Hash
,
174 type Symbol_Table_Range
is range 0 .. 510;
175 function Symbol_Table_Hash
(Key
: Entity_Id
) return Symbol_Table_Range
;
177 -- Each subtype with a dimension has a symbolic representation of the
178 -- related unit. This table establishes a relation between the subtype
181 package Symbol_Table
is new
182 GNAT
.HTable
.Simple_HTable
183 (Header_Num
=> Symbol_Table_Range
,
184 Element
=> String_Id
,
185 No_Element
=> No_String
,
187 Hash
=> Symbol_Table_Hash
,
190 -- The following array enumerates all contexts which may contain or
191 -- produce a dimension.
193 OK_For_Dimension
: constant array (Node_Kind
) of Boolean :=
194 (N_Attribute_Reference
=> True,
195 N_Expanded_Name
=> True,
196 N_Defining_Identifier
=> True,
197 N_Function_Call
=> True,
198 N_Identifier
=> True,
199 N_Indexed_Component
=> True,
200 N_Integer_Literal
=> True,
207 N_Op_Multiply
=> True,
210 N_Op_Subtract
=> True,
211 N_Qualified_Expression
=> True,
212 N_Real_Literal
=> True,
213 N_Selected_Component
=> True,
215 N_Type_Conversion
=> True,
216 N_Unchecked_Type_Conversion
=> True,
220 -----------------------
221 -- Local Subprograms --
222 -----------------------
224 procedure Analyze_Dimension_Assignment_Statement
(N
: Node_Id
);
225 -- Subroutine of Analyze_Dimension for assignment statement. Check that the
226 -- dimensions of the left-hand side and the right-hand side of N match.
228 procedure Analyze_Dimension_Binary_Op
(N
: Node_Id
);
229 -- Subroutine of Analyze_Dimension for binary operators. Check the
230 -- dimensions of the right and the left operand permit the operation.
231 -- Then, evaluate the resulting dimensions for each binary operator.
233 procedure Analyze_Dimension_Component_Declaration
(N
: Node_Id
);
234 -- Subroutine of Analyze_Dimension for component declaration. Check that
235 -- the dimensions of the type of N and of the expression match.
237 procedure Analyze_Dimension_Extended_Return_Statement
(N
: Node_Id
);
238 -- Subroutine of Analyze_Dimension for extended return statement. Check
239 -- that the dimensions of the returned type and of the returned object
242 procedure Analyze_Dimension_Has_Etype
(N
: Node_Id
);
243 -- Subroutine of Analyze_Dimension for a subset of N_Has_Etype denoted by
245 -- N_Attribute_Reference
247 -- N_Indexed_Component
248 -- N_Qualified_Expression
249 -- N_Selected_Component
252 -- N_Unchecked_Type_Conversion
254 procedure Analyze_Dimension_Object_Declaration
(N
: Node_Id
);
255 -- Subroutine of Analyze_Dimension for object declaration. Check that
256 -- the dimensions of the object type and the dimensions of the expression
257 -- (if expression is present) match. Note that when the expression is
258 -- a literal, no error is returned. This special case allows object
259 -- declaration such as: m : constant Length := 1.0;
261 procedure Analyze_Dimension_Object_Renaming_Declaration
(N
: Node_Id
);
262 -- Subroutine of Analyze_Dimension for object renaming declaration. Check
263 -- the dimensions of the type and of the renamed object name of N match.
265 procedure Analyze_Dimension_Simple_Return_Statement
(N
: Node_Id
);
266 -- Subroutine of Analyze_Dimension for simple return statement
267 -- Check that the dimensions of the returned type and of the returned
270 procedure Analyze_Dimension_Subtype_Declaration
(N
: Node_Id
);
271 -- Subroutine of Analyze_Dimension for subtype declaration. Propagate the
272 -- dimensions from the parent type to the identifier of N. Note that if
273 -- both the identifier and the parent type of N are not dimensionless,
276 procedure Analyze_Dimension_Unary_Op
(N
: Node_Id
);
277 -- Subroutine of Analyze_Dimension for unary operators. For Plus, Minus and
278 -- Abs operators, propagate the dimensions from the operand to N.
280 function Create_Rational_From
282 Complain
: Boolean) return Rational
;
283 -- Given an arbitrary expression Expr, return a valid rational if Expr can
284 -- be interpreted as a rational. Otherwise return No_Rational and also an
285 -- error message if Complain is set to True.
287 function Dimensions_Of
(N
: Node_Id
) return Dimension_Type
;
288 -- Return the dimension vector of node N
290 function Dimensions_Msg_Of
292 Description_Needed
: Boolean := False) return String;
293 -- Given a node N, return the dimension symbols of N, preceded by "has
294 -- dimension" if Description_Needed. if N is dimensionless, return "'[']",
295 -- or "is dimensionless" if Description_Needed.
297 procedure Dim_Warning_For_Numeric_Literal
(N
: Node_Id
; Typ
: Entity_Id
);
298 -- Issue a warning on the given numeric literal N to indicate that the
299 -- compiler made the assumption that the literal is not dimensionless
300 -- but has the dimension of Typ.
302 procedure Eval_Op_Expon_With_Rational_Exponent
304 Exponent_Value
: Rational
);
305 -- Evaluate the exponent it is a rational and the operand has a dimension
307 function Exists
(Dim
: Dimension_Type
) return Boolean;
308 -- Returns True iff Dim does not denote the null dimension
310 function Exists
(Str
: String_Id
) return Boolean;
311 -- Returns True iff Str does not denote No_String
313 function Exists
(Sys
: System_Type
) return Boolean;
314 -- Returns True iff Sys does not denote the null system
316 function From_Dim_To_Str_Of_Dim_Symbols
317 (Dims
: Dimension_Type
;
318 System
: System_Type
;
319 In_Error_Msg
: Boolean := False) return String_Id
;
320 -- Given a dimension vector and a dimension system, return the proper
321 -- string of dimension symbols. If In_Error_Msg is True (i.e. the String_Id
322 -- will be used to issue an error message) then this routine has a special
323 -- handling for the insertion characters * or [ which must be preceded by
324 -- a quote ' to to be placed literally into the message.
326 function From_Dim_To_Str_Of_Unit_Symbols
327 (Dims
: Dimension_Type
;
328 System
: System_Type
) return String_Id
;
329 -- Given a dimension vector and a dimension system, return the proper
330 -- string of unit symbols.
332 function Is_Dim_IO_Package_Entity
(E
: Entity_Id
) return Boolean;
333 -- Return True if E is the package entity of System.Dim.Float_IO or
334 -- System.Dim.Integer_IO.
336 function Is_Invalid
(Position
: Dimension_Position
) return Boolean;
337 -- Return True if Pos denotes the invalid position
339 procedure Move_Dimensions
(From
: Node_Id
; To
: Node_Id
);
340 -- Copy dimension vector of From to To and delete dimension vector of From
342 procedure Remove_Dimensions
(N
: Node_Id
);
343 -- Remove the dimension vector of node N
345 procedure Set_Dimensions
(N
: Node_Id
; Val
: Dimension_Type
);
346 -- Associate a dimension vector with a node
348 procedure Set_Symbol
(E
: Entity_Id
; Val
: String_Id
);
349 -- Associate a symbol representation of a dimension vector with a subtype
351 function String_From_Numeric_Literal
(N
: Node_Id
) return String_Id
;
352 -- Return the string that corresponds to the numeric litteral N as it
353 -- appears in the source.
355 function Symbol_Of
(E
: Entity_Id
) return String_Id
;
356 -- E denotes a subtype with a dimension. Return the symbol representation
357 -- of the dimension vector.
359 function System_Of
(E
: Entity_Id
) return System_Type
;
360 -- E denotes a type, return associated system of the type if it has one
366 function "+" (Right
: Whole
) return Rational
is
368 return Rational
'(Numerator => Right, Denominator => 1);
371 function "+" (Left, Right : Rational) return Rational is
372 R : constant Rational :=
373 Rational'(Numerator
=> Left
.Numerator
* Right
.Denominator
+
374 Left
.Denominator
* Right
.Numerator
,
375 Denominator
=> Left
.Denominator
* Right
.Denominator
);
384 function "-" (Right
: Rational
) return Rational
is
386 return Rational
'(Numerator => -Right.Numerator,
387 Denominator => Right.Denominator);
390 function "-" (Left, Right : Rational) return Rational is
391 R : constant Rational :=
392 Rational'(Numerator
=> Left
.Numerator
* Right
.Denominator
-
393 Left
.Denominator
* Right
.Numerator
,
394 Denominator
=> Left
.Denominator
* Right
.Denominator
);
404 function "*" (Left
, Right
: Rational
) return Rational
is
405 R
: constant Rational
:=
406 Rational
'(Numerator => Left.Numerator * Right.Numerator,
407 Denominator => Left.Denominator * Right.Denominator);
416 function "/" (Left, Right : Rational) return Rational is
417 R : constant Rational := abs Right;
418 L : Rational := Left;
421 if Right.Numerator < 0 then
422 L.Numerator := Whole (-Integer (L.Numerator));
425 return Reduce (Rational'(Numerator
=> L
.Numerator
* R
.Denominator
,
426 Denominator
=> L
.Denominator
* R
.Numerator
));
433 function "abs" (Right
: Rational
) return Rational
is
435 return Rational
'(Numerator => abs Right.Numerator,
436 Denominator => Right.Denominator);
439 ------------------------------
440 -- Analyze_Aspect_Dimension --
441 ------------------------------
444 -- ([Symbol =>] SYMBOL, DIMENSION_VALUE {, DIMENSION_Value})
446 -- SYMBOL ::= STRING_LITERAL | CHARACTER_LITERAL
448 -- DIMENSION_VALUE ::=
450 -- | others => RATIONAL
451 -- | DISCRETE_CHOICE_LIST => RATIONAL
453 -- RATIONAL ::= [-] NUMERIC_LITERAL [/ NUMERIC_LITERAL]
455 -- Note that when the dimensioned type is an integer type, then any
456 -- dimension value must be an integer literal.
458 procedure Analyze_Aspect_Dimension
463 Def_Id : constant Entity_Id := Defining_Identifier (N);
465 Processed : array (Dimension_Type'Range) of Boolean := (others => False);
466 -- This array is used when processing ranges or Others_Choice as part of
467 -- the dimension aggregate.
469 Dimensions : Dimension_Type := Null_Dimension;
471 procedure Extract_Power
473 Position : Dimension_Position);
474 -- Given an expression with denotes a rational number, read the number
475 -- and associate it with Position in Dimensions.
477 function Position_In_System
479 System : System_Type) return Dimension_Position;
480 -- Given an identifier which denotes a dimension, return the position of
481 -- that dimension within System.
487 procedure Extract_Power
489 Position : Dimension_Position)
494 if Is_Integer_Type (Def_Id) then
496 -- Dimension value must be an integer literal
498 if Nkind (Expr) = N_Integer_Literal then
499 Dimensions (Position) := +Whole (UI_To_Int (Intval (Expr)));
501 Error_Msg_N ("integer literal expected", Expr);
507 Dimensions (Position) := Create_Rational_From (Expr, True);
510 Processed (Position) := True;
513 ------------------------
514 -- Position_In_System --
515 ------------------------
517 function Position_In_System
519 System : System_Type) return Dimension_Position
521 Dimension_Name : constant Name_Id := Chars (Id);
524 for Position in System.Unit_Names'Range loop
525 if Dimension_Name = System.Unit_Names (Position) then
530 return Invalid_Position;
531 end Position_In_System;
538 Num_Choices : Nat := 0;
539 Num_Dimensions : Nat := 0;
540 Others_Seen : Boolean := False;
543 Symbol : String_Id := No_String;
544 Symbol_Expr : Node_Id;
545 System : System_Type;
549 -- Errors_Count is a count of errors detected by the compiler so far
550 -- just before the extraction of symbol, names and values in the
551 -- aggregate (Step 2).
553 -- At the end of the analysis, there is a check to verify that this
554 -- count equals to Serious_Errors_Detected i.e. no erros have been
555 -- encountered during the process. Otherwise the Dimension_Table is
558 -- Start of processing for Analyze_Aspect_Dimension
561 -- STEP 1: Legality of aspect
563 if Nkind (N) /= N_Subtype_Declaration then
564 Error_Msg_NE ("aspect& must apply to subtype declaration", N, Id);
568 Sub_Ind := Subtype_Indication (N);
569 Typ := Etype (Sub_Ind);
570 System := System_Of (Typ);
572 if Nkind (Sub_Ind) = N_Subtype_Indication then
574 ("constraint not allowed with aspect&", Constraint (Sub_Ind), Id);
578 -- The dimension declarations are useless if the parent type does not
579 -- declare a valid system.
581 if not Exists (System) then
583 ("parent type of& lacks dimension system", Sub_Ind, Def_Id);
587 if Nkind (Aggr) /= N_Aggregate then
588 Error_Msg_N ("aggregate expected", Aggr);
592 -- STEP 2: Symbol, Names and values extraction
594 -- Get the number of errors detected by the compiler so far
596 Errors_Count := Serious_Errors_Detected;
598 -- STEP 2a: Symbol extraction
600 -- The first entry in the aggregate may be the symbolic representation
603 -- Positional symbol argument
605 Symbol_Expr := First (Expressions (Aggr));
607 -- Named symbol argument
610 or else not Nkind_In (Symbol_Expr, N_Character_Literal,
613 Symbol_Expr := Empty;
615 -- Component associations present
617 if Present (Component_Associations (Aggr)) then
618 Assoc := First (Component_Associations (Aggr));
619 Choice := First (Choices (Assoc));
621 if No (Next (Choice)) and then Nkind (Choice) = N_Identifier then
623 -- Symbol component association is present
625 if Chars (Choice) = Name_Symbol then
626 Num_Choices := Num_Choices + 1;
627 Symbol_Expr := Expression (Assoc);
629 -- Verify symbol expression is a string or a character
631 if not Nkind_In (Symbol_Expr, N_Character_Literal,
634 Symbol_Expr := Empty;
636 ("symbol expression must be character or string",
640 -- Special error if no Symbol choice but expression is string
643 elsif Nkind_In (Expression (Assoc), N_Character_Literal,
646 Num_Choices := Num_Choices + 1;
648 ("optional component Symbol expected, found&", Choice);
654 -- STEP 2b: Names and values extraction
656 -- Positional elements
658 Expr := First (Expressions (Aggr));
660 -- Skip the symbol expression when present
662 if Present (Symbol_Expr) and then Num_Choices = 0 then
666 Position := Low_Position_Bound;
667 while Present (Expr) loop
668 if Position > High_Position_Bound then
670 ("type& has more dimensions than system allows", Def_Id);
674 Extract_Power (Expr, Position);
676 Position := Position + 1;
677 Num_Dimensions := Num_Dimensions + 1;
684 Assoc := First (Component_Associations (Aggr));
686 -- Skip the symbol association when present
688 if Num_Choices = 1 then
692 while Present (Assoc) loop
693 Expr := Expression (Assoc);
695 Choice := First (Choices (Assoc));
696 while Present (Choice) loop
698 -- Identifier case: NAME => EXPRESSION
700 if Nkind (Choice) = N_Identifier then
701 Position := Position_In_System (Choice, System);
703 if Is_Invalid (Position) then
704 Error_Msg_N ("dimension name& not part of system", Choice);
706 Extract_Power (Expr, Position);
709 -- Range case: NAME .. NAME => EXPRESSION
711 elsif Nkind (Choice) = N_Range then
713 Low : constant Node_Id := Low_Bound (Choice);
714 High : constant Node_Id := High_Bound (Choice);
715 Low_Pos : Dimension_Position;
716 High_Pos : Dimension_Position;
719 if Nkind (Low) /= N_Identifier then
720 Error_Msg_N ("bound must denote a dimension name", Low);
722 elsif Nkind (High) /= N_Identifier then
723 Error_Msg_N ("bound must denote a dimension name", High);
726 Low_Pos := Position_In_System (Low, System);
727 High_Pos := Position_In_System (High, System);
729 if Is_Invalid (Low_Pos) then
730 Error_Msg_N ("dimension name& not part of system",
733 elsif Is_Invalid (High_Pos) then
734 Error_Msg_N ("dimension name& not part of system",
737 elsif Low_Pos > High_Pos then
738 Error_Msg_N ("expected low to high range", Choice);
741 for Position in Low_Pos .. High_Pos loop
742 Extract_Power (Expr, Position);
748 -- Others case: OTHERS => EXPRESSION
750 elsif Nkind (Choice) = N_Others_Choice then
751 if Present (Next (Choice)) or else Present (Prev (Choice)) then
753 ("OTHERS must appear alone in a choice list", Choice);
755 elsif Present (Next (Assoc)) then
757 ("OTHERS must appear last in an aggregate", Choice);
759 elsif Others_Seen then
760 Error_Msg_N ("multiple OTHERS not allowed", Choice);
763 -- Fill the non-processed dimensions with the default value
764 -- supplied by others.
766 for Position in Processed'Range loop
767 if not Processed (Position) then
768 Extract_Power (Expr, Position);
775 -- All other cases are illegal declarations of dimension names
778 Error_Msg_NE ("wrong syntax for aspect&", Choice, Id);
781 Num_Choices := Num_Choices + 1;
785 Num_Dimensions := Num_Dimensions + 1;
789 -- STEP 3: Consistency of system and dimensions
791 if Present (First (Expressions (Aggr)))
792 and then (First (Expressions (Aggr)) /= Symbol_Expr
793 or else Present (Next (Symbol_Expr)))
794 and then (Num_Choices > 1
795 or else (Num_Choices = 1 and then not Others_Seen))
798 ("named associations cannot follow positional associations", Aggr);
801 if Num_Dimensions > System.Count then
802 Error_Msg_N ("type& has more dimensions than system allows", Def_Id);
804 elsif Num_Dimensions < System.Count and then not Others_Seen then
805 Error_Msg_N ("type& has less dimensions than system allows", Def_Id);
808 -- STEP 4: Dimension symbol extraction
810 if Present (Symbol_Expr) then
811 if Nkind (Symbol_Expr) = N_Character_Literal then
813 Store_String_Char (UI_To_CC (Char_Literal_Value (Symbol_Expr)));
814 Symbol := End_String;
817 Symbol := Strval (Symbol_Expr);
820 if String_Length (Symbol) = 0 then
821 Error_Msg_N ("empty string not allowed here", Symbol_Expr);
825 -- STEP 5: Storage of extracted values
827 -- Check that no errors have been detected during the analysis
829 if Errors_Count = Serious_Errors_Detected then
831 -- Check for useless declaration
833 if Symbol = No_String and then not Exists (Dimensions) then
834 Error_Msg_N ("useless dimension declaration", Aggr);
837 if Symbol /= No_String then
838 Set_Symbol (Def_Id, Symbol);
841 if Exists (Dimensions) then
842 Set_Dimensions (Def_Id, Dimensions);
845 end Analyze_Aspect_Dimension;
847 -------------------------------------
848 -- Analyze_Aspect_Dimension_System --
849 -------------------------------------
851 -- with Dimension_System => (DIMENSION {, DIMENSION});
854 -- [Unit_Name =>] IDENTIFIER,
855 -- [Unit_Symbol =>] SYMBOL,
856 -- [Dim_Symbol =>] SYMBOL)
858 procedure Analyze_Aspect_Dimension_System
863 function Is_Derived_Numeric_Type (N : Node_Id) return Boolean;
864 -- Determine whether type declaration N denotes a numeric derived type
866 -------------------------------
867 -- Is_Derived_Numeric_Type --
868 -------------------------------
870 function Is_Derived_Numeric_Type (N : Node_Id) return Boolean is
873 Nkind (N) = N_Full_Type_Declaration
874 and then Nkind (Type_Definition (N)) = N_Derived_Type_Definition
875 and then Is_Numeric_Type
876 (Entity (Subtype_Indication (Type_Definition (N))));
877 end Is_Derived_Numeric_Type;
884 Dim_Symbol : Node_Id;
885 Dim_Symbols : Symbol_Array := No_Symbols;
886 Dim_System : System_Type := Null_System;
889 Unit_Names : Name_Array := No_Names;
890 Unit_Symbol : Node_Id;
891 Unit_Symbols : Symbol_Array := No_Symbols;
894 -- Errors_Count is a count of errors detected by the compiler so far
895 -- just before the extraction of names and symbols in the aggregate
898 -- At the end of the analysis, there is a check to verify that this
899 -- count equals Serious_Errors_Detected i.e. no errors have been
900 -- encountered during the process. Otherwise the System_Table is
903 -- Start of processing for Analyze_Aspect_Dimension_System
906 -- STEP 1: Legality of aspect
908 if not Is_Derived_Numeric_Type (N) then
910 ("aspect& must apply to numeric derived type declaration", N, Id);
914 if Nkind (Aggr) /= N_Aggregate then
915 Error_Msg_N ("aggregate expected", Aggr);
919 -- STEP 2: Structural verification of the dimension aggregate
921 if Present (Component_Associations (Aggr)) then
922 Error_Msg_N ("expected positional aggregate", Aggr);
926 -- STEP 3: Name and Symbol extraction
928 Dim_Aggr := First (Expressions (Aggr));
929 Errors_Count := Serious_Errors_Detected;
930 while Present (Dim_Aggr) loop
931 Position := Position + 1;
933 if Position > High_Position_Bound then
934 Error_Msg_N ("too many dimensions in system", Aggr);
938 if Nkind (Dim_Aggr) /= N_Aggregate then
939 Error_Msg_N ("aggregate expected", Dim_Aggr);
942 if Present (Component_Associations (Dim_Aggr))
943 and then Present (Expressions (Dim_Aggr))
946 ("mixed positional/named aggregate not allowed here",
949 -- Verify each dimension aggregate has three arguments
951 elsif List_Length (Component_Associations (Dim_Aggr)) /= 3
952 and then List_Length (Expressions (Dim_Aggr)) /= 3
955 ("three components expected in aggregate", Dim_Aggr);
958 -- Named dimension aggregate
960 if Present (Component_Associations (Dim_Aggr)) then
962 -- Check first argument denotes the unit name
964 Assoc := First (Component_Associations (Dim_Aggr));
965 Choice := First (Choices (Assoc));
966 Unit_Name := Expression (Assoc);
968 if Present (Next (Choice))
969 or else Nkind (Choice) /= N_Identifier
971 Error_Msg_NE ("wrong syntax for aspect&", Choice, Id);
973 elsif Chars (Choice) /= Name_Unit_Name then
974 Error_Msg_N ("expected Unit_Name, found&", Choice);
977 -- Check the second argument denotes the unit symbol
980 Choice := First (Choices (Assoc));
981 Unit_Symbol := Expression (Assoc);
983 if Present (Next (Choice))
984 or else Nkind (Choice) /= N_Identifier
986 Error_Msg_NE ("wrong syntax for aspect&", Choice, Id);
988 elsif Chars (Choice) /= Name_Unit_Symbol then
989 Error_Msg_N ("expected Unit_Symbol, found&", Choice);
992 -- Check the third argument denotes the dimension symbol
995 Choice := First (Choices (Assoc));
996 Dim_Symbol := Expression (Assoc);
998 if Present (Next (Choice))
999 or else Nkind (Choice) /= N_Identifier
1001 Error_Msg_NE ("wrong syntax for aspect&", Choice, Id);
1002 elsif Chars (Choice) /= Name_Dim_Symbol then
1003 Error_Msg_N ("expected Dim_Symbol, found&", Choice);
1006 -- Positional dimension aggregate
1009 Unit_Name := First (Expressions (Dim_Aggr));
1010 Unit_Symbol := Next (Unit_Name);
1011 Dim_Symbol := Next (Unit_Symbol);
1014 -- Check the first argument for each dimension aggregate is
1017 if Nkind (Unit_Name) = N_Identifier then
1018 Unit_Names (Position) := Chars (Unit_Name);
1020 Error_Msg_N ("expected unit name", Unit_Name);
1023 -- Check the second argument for each dimension aggregate is
1024 -- a string or a character.
1026 if not Nkind_In (Unit_Symbol, N_String_Literal,
1027 N_Character_Literal)
1030 ("expected unit symbol (string or character)",
1036 if Nkind (Unit_Symbol) = N_String_Literal then
1037 Unit_Symbols (Position) := Strval (Unit_Symbol);
1044 (UI_To_CC (Char_Literal_Value (Unit_Symbol)));
1045 Unit_Symbols (Position) := End_String;
1048 -- Verify that the string is not empty
1050 if String_Length (Unit_Symbols (Position)) = 0 then
1052 ("empty string not allowed here", Unit_Symbol);
1056 -- Check the third argument for each dimension aggregate is
1057 -- a string or a character.
1059 if not Nkind_In (Dim_Symbol, N_String_Literal,
1060 N_Character_Literal)
1063 ("expected dimension symbol (string or character)",
1069 if Nkind (Dim_Symbol) = N_String_Literal then
1070 Dim_Symbols (Position) := Strval (Dim_Symbol);
1077 (UI_To_CC (Char_Literal_Value (Dim_Symbol)));
1078 Dim_Symbols (Position) := End_String;
1081 -- Verify that the string is not empty
1083 if String_Length (Dim_Symbols (Position)) = 0 then
1084 Error_Msg_N ("empty string not allowed here", Dim_Symbol);
1093 -- STEP 4: Storage of extracted values
1095 -- Check that no errors have been detected during the analysis
1097 if Errors_Count = Serious_Errors_Detected then
1098 Dim_System.Type_Decl := N;
1099 Dim_System.Unit_Names := Unit_Names;
1100 Dim_System.Unit_Symbols := Unit_Symbols;
1101 Dim_System.Dim_Symbols := Dim_Symbols;
1102 Dim_System.Count := Position;
1103 System_Table.Append (Dim_System);
1105 end Analyze_Aspect_Dimension_System;
1107 -----------------------
1108 -- Analyze_Dimension --
1109 -----------------------
1111 -- This dispatch routine propagates dimensions for each node
1113 procedure Analyze_Dimension (N : Node_Id) is
1115 -- Aspect is an Ada 2012 feature. Note that there is no need to check
1116 -- dimensions for nodes that don't come from source.
1118 if Ada_Version < Ada_2012 or else not Comes_From_Source (N) then
1123 when N_Assignment_Statement =>
1124 Analyze_Dimension_Assignment_Statement (N);
1127 Analyze_Dimension_Binary_Op (N);
1129 when N_Component_Declaration =>
1130 Analyze_Dimension_Component_Declaration (N);
1132 when N_Extended_Return_Statement =>
1133 Analyze_Dimension_Extended_Return_Statement (N);
1135 when N_Attribute_Reference |
1139 N_Indexed_Component |
1140 N_Qualified_Expression |
1141 N_Selected_Component |
1144 N_Unchecked_Type_Conversion =>
1145 Analyze_Dimension_Has_Etype (N);
1147 when N_Object_Declaration =>
1148 Analyze_Dimension_Object_Declaration (N);
1150 when N_Object_Renaming_Declaration =>
1151 Analyze_Dimension_Object_Renaming_Declaration (N);
1153 when N_Simple_Return_Statement =>
1154 if not Comes_From_Extended_Return_Statement (N) then
1155 Analyze_Dimension_Simple_Return_Statement (N);
1158 when N_Subtype_Declaration =>
1159 Analyze_Dimension_Subtype_Declaration (N);
1162 Analyze_Dimension_Unary_Op (N);
1164 when others => null;
1167 end Analyze_Dimension;
1169 ---------------------------------------
1170 -- Analyze_Dimension_Array_Aggregate --
1171 ---------------------------------------
1173 procedure Analyze_Dimension_Array_Aggregate
1175 Comp_Typ : Entity_Id)
1177 Comp_Ass : constant List_Id := Component_Associations (N);
1178 Dims_Of_Comp_Typ : constant Dimension_Type := Dimensions_Of (Comp_Typ);
1179 Exps : constant List_Id := Expressions (N);
1184 Error_Detected : Boolean := False;
1185 -- This flag is used in order to indicate if an error has been detected
1186 -- so far by the compiler in this routine.
1189 -- Aspect is an Ada 2012 feature. Nothing to do here if the component
1190 -- base type is not a dimensioned type.
1192 -- Note that here the original node must come from source since the
1193 -- original array aggregate may not have been entirely decorated.
1195 if Ada_Version < Ada_2012
1196 or else not Comes_From_Source (Original_Node (N))
1197 or else not Has_Dimension_System (Base_Type (Comp_Typ))
1202 -- Check whether there is any positional component association
1204 if Is_Empty_List (Exps) then
1205 Comp := First (Comp_Ass);
1207 Comp := First (Exps);
1210 while Present (Comp) loop
1212 -- Get the expression from the component
1214 if Nkind (Comp) = N_Component_Association then
1215 Expr := Expression (Comp);
1220 -- Issue an error if the dimensions of the component type and the
1221 -- dimensions of the component mismatch.
1223 -- Note that we must ensure the expression has been fully analyzed
1224 -- since it may not be decorated at this point. We also don't want to
1225 -- issue the same error message multiple times on the same expression
1226 -- (may happen when an aggregate is converted into a positional
1229 if Comes_From_Source (Original_Node (Expr))
1230 and then Present (Etype (Expr))
1231 and then Dimensions_Of (Expr) /= Dims_Of_Comp_Typ
1232 and then Sloc (Comp) /= Sloc (Prev (Comp))
1234 -- Check if an error has already been encountered so far
1236 if not Error_Detected then
1237 Error_Msg_N ("dimensions mismatch in array aggregate", N);
1238 Error_Detected := True;
1242 ("\expected dimension " & Dimensions_Msg_Of (Comp_Typ)
1243 & ", found " & Dimensions_Msg_Of (Expr), Expr);
1246 -- Look at the named components right after the positional components
1248 if not Present (Next (Comp))
1249 and then List_Containing (Comp) = Exps
1251 Comp := First (Comp_Ass);
1256 end Analyze_Dimension_Array_Aggregate;
1258 --------------------------------------------
1259 -- Analyze_Dimension_Assignment_Statement --
1260 --------------------------------------------
1262 procedure Analyze_Dimension_Assignment_Statement (N : Node_Id) is
1263 Lhs : constant Node_Id := Name (N);
1264 Dims_Of_Lhs : constant Dimension_Type := Dimensions_Of (Lhs);
1265 Rhs : constant Node_Id := Expression (N);
1266 Dims_Of_Rhs : constant Dimension_Type := Dimensions_Of (Rhs);
1268 procedure Error_Dim_Msg_For_Assignment_Statement
1272 -- Error using Error_Msg_N at node N. Output the dimensions of left
1273 -- and right hand sides.
1275 --------------------------------------------
1276 -- Error_Dim_Msg_For_Assignment_Statement --
1277 --------------------------------------------
1279 procedure Error_Dim_Msg_For_Assignment_Statement
1285 Error_Msg_N ("dimensions mismatch in assignment", N);
1286 Error_Msg_N ("\left-hand side " & Dimensions_Msg_Of (Lhs, True), N);
1287 Error_Msg_N ("\right-hand side " & Dimensions_Msg_Of (Rhs, True), N);
1288 end Error_Dim_Msg_For_Assignment_Statement;
1290 -- Start of processing for Analyze_Dimension_Assignment
1293 if Dims_Of_Lhs /= Dims_Of_Rhs then
1294 Error_Dim_Msg_For_Assignment_Statement (N, Lhs, Rhs);
1296 end Analyze_Dimension_Assignment_Statement;
1298 ---------------------------------
1299 -- Analyze_Dimension_Binary_Op --
1300 ---------------------------------
1302 -- Check and propagate the dimensions for binary operators
1303 -- Note that when the dimensions mismatch, no dimension is propagated to N.
1305 procedure Analyze_Dimension_Binary_Op (N : Node_Id) is
1306 N_Kind : constant Node_Kind := Nkind (N);
1308 procedure Error_Dim_Msg_For_Binary_Op (N, L, R : Node_Id);
1309 -- Error using Error_Msg_NE and Error_Msg_N at node N. Output the
1310 -- dimensions of both operands.
1312 ---------------------------------
1313 -- Error_Dim_Msg_For_Binary_Op --
1314 ---------------------------------
1316 procedure Error_Dim_Msg_For_Binary_Op (N, L, R : Node_Id) is
1319 ("both operands for operation& must have same dimensions",
1321 Error_Msg_N ("\left operand " & Dimensions_Msg_Of (L, True), N);
1322 Error_Msg_N ("\right operand " & Dimensions_Msg_Of (R, True), N);
1323 end Error_Dim_Msg_For_Binary_Op;
1325 -- Start of processing for Analyze_Dimension_Binary_Op
1328 if Nkind_In (N_Kind, N_Op_Add, N_Op_Expon, N_Op_Subtract)
1329 or else N_Kind in N_Multiplying_Operator
1330 or else N_Kind in N_Op_Compare
1333 L : constant Node_Id := Left_Opnd (N);
1334 Dims_Of_L : constant Dimension_Type := Dimensions_Of (L);
1335 L_Has_Dimensions : constant Boolean := Exists (Dims_Of_L);
1336 R : constant Node_Id := Right_Opnd (N);
1337 Dims_Of_R : constant Dimension_Type := Dimensions_Of (R);
1338 R_Has_Dimensions : constant Boolean := Exists (Dims_Of_R);
1339 Dims_Of_N : Dimension_Type := Null_Dimension;
1342 -- N_Op_Add, N_Op_Mod, N_Op_Rem or N_Op_Subtract case
1344 if Nkind_In (N, N_Op_Add, N_Op_Mod, N_Op_Rem, N_Op_Subtract) then
1346 -- Check both operands have same dimension
1348 if Dims_Of_L /= Dims_Of_R then
1349 Error_Dim_Msg_For_Binary_Op (N, L, R);
1351 -- Check both operands are not dimensionless
1353 if Exists (Dims_Of_L) then
1354 Set_Dimensions (N, Dims_Of_L);
1358 -- N_Op_Multiply or N_Op_Divide case
1360 elsif Nkind_In (N_Kind, N_Op_Multiply, N_Op_Divide) then
1362 -- Check at least one operand is not dimensionless
1364 if L_Has_Dimensions or R_Has_Dimensions then
1366 -- Multiplication case
1368 -- Get both operands dimensions and add them
1370 if N_Kind = N_Op_Multiply then
1371 for Position in Dimension_Type'Range loop
1372 Dims_Of_N (Position) :=
1373 Dims_Of_L (Position) + Dims_Of_R (Position);
1378 -- Get both operands dimensions and subtract them
1381 for Position in Dimension_Type'Range loop
1382 Dims_Of_N (Position) :=
1383 Dims_Of_L (Position) - Dims_Of_R (Position);
1387 if Exists (Dims_Of_N) then
1388 Set_Dimensions (N, Dims_Of_N);
1392 -- Exponentiation case
1394 -- Note: a rational exponent is allowed for dimensioned operand
1396 elsif N_Kind = N_Op_Expon then
1398 -- Check the left operand is not dimensionless. Note that the
1399 -- value of the exponent must be known compile time. Otherwise,
1400 -- the exponentiation evaluation will return an error message.
1402 if L_Has_Dimensions then
1403 if not Compile_Time_Known_Value (R) then
1405 ("exponent of dimensioned operand must be "
1406 & "known at compile time", N);
1410 Exponent_Value : Rational := Zero;
1413 -- Real operand case
1415 if Is_Real_Type (Etype (L)) then
1417 -- Define the exponent as a Rational number
1419 Exponent_Value := Create_Rational_From (R, False);
1421 -- Verify that the exponent cannot be interpreted
1422 -- as a rational, otherwise interpret the exponent
1425 if Exponent_Value = No_Rational then
1427 +Whole (UI_To_Int (Expr_Value (R)));
1430 -- Integer operand case.
1432 -- For integer operand, the exponent cannot be
1433 -- interpreted as a rational.
1436 Exponent_Value := +Whole (UI_To_Int (Expr_Value (R)));
1439 for Position in Dimension_Type'Range loop
1440 Dims_Of_N (Position) :=
1441 Dims_Of_L (Position) * Exponent_Value;
1444 if Exists (Dims_Of_N) then
1445 Set_Dimensions (N, Dims_Of_N);
1452 -- For relational operations, only dimension checking is
1453 -- performed (no propagation).
1455 elsif N_Kind in N_Op_Compare then
1456 if (L_Has_Dimensions or R_Has_Dimensions)
1457 and then Dims_Of_L /= Dims_Of_R
1459 Error_Dim_Msg_For_Binary_Op (N, L, R);
1463 -- Removal of dimensions for each operands
1465 Remove_Dimensions (L);
1466 Remove_Dimensions (R);
1469 end Analyze_Dimension_Binary_Op;
1471 ----------------------------
1472 -- Analyze_Dimension_Call --
1473 ----------------------------
1475 procedure Analyze_Dimension_Call (N : Node_Id; Nam : Entity_Id) is
1476 Actuals : constant List_Id := Parameter_Associations (N);
1478 Dims_Of_Formal : Dimension_Type;
1480 Formal_Typ : Entity_Id;
1482 Error_Detected : Boolean := False;
1483 -- This flag is used in order to indicate if an error has been detected
1484 -- so far by the compiler in this routine.
1487 -- Aspect is an Ada 2012 feature. Note that there is no need to check
1488 -- dimensions for calls that don't come from source, or those that may
1489 -- have semantic errors.
1491 if Ada_Version < Ada_2012
1492 or else not Comes_From_Source (N)
1493 or else Error_Posted (N)
1498 -- Check the dimensions of the actuals, if any
1500 if not Is_Empty_List (Actuals) then
1502 -- Special processing for elementary functions
1504 -- For Sqrt call, the resulting dimensions equal to half the
1505 -- dimensions of the actual. For all other elementary calls, this
1506 -- routine check that every actual is dimensionless.
1508 if Nkind (N) = N_Function_Call then
1509 Elementary_Function_Calls : declare
1510 Dims_Of_Call : Dimension_Type;
1511 Ent : Entity_Id := Nam;
1513 function Is_Elementary_Function_Entity
1514 (Sub_Id : Entity_Id) return Boolean;
1515 -- Given Sub_Id, the original subprogram entity, return True
1516 -- if call is to an elementary function (see Ada.Numerics.
1517 -- Generic_Elementary_Functions).
1519 -----------------------------------
1520 -- Is_Elementary_Function_Entity --
1521 -----------------------------------
1523 function Is_Elementary_Function_Entity
1524 (Sub_Id : Entity_Id) return Boolean
1526 Loc : constant Source_Ptr := Sloc (Sub_Id);
1529 -- Is entity in Ada.Numerics.Generic_Elementary_Functions?
1535 (Cunit_Entity (Get_Source_Unit (Loc)),
1536 Ada_Numerics_Generic_Elementary_Functions);
1537 end Is_Elementary_Function_Entity;
1539 -- Start of processing for Elementary_Function_Calls
1542 -- Get original subprogram entity following the renaming chain
1544 if Present (Alias (Ent)) then
1548 -- Check the call is an Elementary function call
1550 if Is_Elementary_Function_Entity (Ent) then
1552 -- Sqrt function call case
1554 if Chars (Ent) = Name_Sqrt then
1555 Dims_Of_Call := Dimensions_Of (First_Actual (N));
1557 -- Evaluates the resulting dimensions (i.e. half the
1558 -- dimensions of the actual).
1560 if Exists (Dims_Of_Call) then
1561 for Position in Dims_Of_Call'Range loop
1562 Dims_Of_Call (Position) :=
1563 Dims_Of_Call (Position) *
1564 Rational'(Numerator
=> 1, Denominator
=> 2);
1567 Set_Dimensions
(N
, Dims_Of_Call
);
1570 -- All other elementary functions case. Note that every
1571 -- actual here should be dimensionless.
1574 Actual
:= First_Actual
(N
);
1575 while Present
(Actual
) loop
1576 if Exists
(Dimensions_Of
(Actual
)) then
1578 -- Check if error has already been encountered
1580 if not Error_Detected
then
1582 ("dimensions mismatch in call of&",
1584 Error_Detected
:= True;
1588 ("\expected dimension '['], found "
1589 & Dimensions_Msg_Of
(Actual
), Actual
);
1592 Next_Actual
(Actual
);
1596 -- Nothing more to do for elementary functions
1600 end Elementary_Function_Calls
;
1603 -- General case. Check, for each parameter, the dimensions of the
1604 -- actual and its corresponding formal match. Otherwise, complain.
1606 Actual
:= First_Actual
(N
);
1607 Formal
:= First_Formal
(Nam
);
1608 while Present
(Formal
) loop
1610 -- A missing corresponding actual indicates that the analysis of
1611 -- the call was aborted due to a previous error.
1614 Check_Error_Detected
;
1618 Formal_Typ
:= Etype
(Formal
);
1619 Dims_Of_Formal
:= Dimensions_Of
(Formal_Typ
);
1621 -- If the formal is not dimensionless, check dimensions of formal
1622 -- and actual match. Otherwise, complain.
1624 if Exists
(Dims_Of_Formal
)
1625 and then Dimensions_Of
(Actual
) /= Dims_Of_Formal
1627 -- Check if an error has already been encountered so far
1629 if not Error_Detected
then
1630 Error_Msg_NE
("dimensions mismatch in& call", N
, Name
(N
));
1631 Error_Detected
:= True;
1635 ("\expected dimension " & Dimensions_Msg_Of
(Formal_Typ
)
1636 & ", found " & Dimensions_Msg_Of
(Actual
), Actual
);
1639 Next_Actual
(Actual
);
1640 Next_Formal
(Formal
);
1644 -- For function calls, propagate the dimensions from the returned type
1646 if Nkind
(N
) = N_Function_Call
then
1647 Analyze_Dimension_Has_Etype
(N
);
1649 end Analyze_Dimension_Call
;
1651 ---------------------------------------------
1652 -- Analyze_Dimension_Component_Declaration --
1653 ---------------------------------------------
1655 procedure Analyze_Dimension_Component_Declaration
(N
: Node_Id
) is
1656 Expr
: constant Node_Id
:= Expression
(N
);
1657 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1658 Etyp
: constant Entity_Id
:= Etype
(Id
);
1659 Dims_Of_Etyp
: constant Dimension_Type
:= Dimensions_Of
(Etyp
);
1660 Dims_Of_Expr
: Dimension_Type
;
1662 procedure Error_Dim_Msg_For_Component_Declaration
1666 -- Error using Error_Msg_N at node N. Output the dimensions of the
1667 -- type Etyp and the expression Expr of N.
1669 ---------------------------------------------
1670 -- Error_Dim_Msg_For_Component_Declaration --
1671 ---------------------------------------------
1673 procedure Error_Dim_Msg_For_Component_Declaration
1678 Error_Msg_N
("dimensions mismatch in component declaration", N
);
1680 ("\expected dimension " & Dimensions_Msg_Of
(Etyp
) & ", found "
1681 & Dimensions_Msg_Of
(Expr
), Expr
);
1682 end Error_Dim_Msg_For_Component_Declaration
;
1684 -- Start of processing for Analyze_Dimension_Component_Declaration
1687 -- Expression is present
1689 if Present
(Expr
) then
1690 Dims_Of_Expr
:= Dimensions_Of
(Expr
);
1692 -- Check dimensions match
1694 if Dims_Of_Etyp
/= Dims_Of_Expr
then
1696 -- Numeric literal case. Issue a warning if the object type is not
1697 -- dimensionless to indicate the literal is treated as if its
1698 -- dimension matches the type dimension.
1700 if Nkind_In
(Original_Node
(Expr
), N_Real_Literal
,
1703 Dim_Warning_For_Numeric_Literal
(Expr
, Etyp
);
1705 -- Issue a dimension mismatch error for all other cases
1708 Error_Dim_Msg_For_Component_Declaration
(N
, Etyp
, Expr
);
1712 end Analyze_Dimension_Component_Declaration
;
1714 -------------------------------------------------
1715 -- Analyze_Dimension_Extended_Return_Statement --
1716 -------------------------------------------------
1718 procedure Analyze_Dimension_Extended_Return_Statement
(N
: Node_Id
) is
1719 Return_Ent
: constant Entity_Id
:= Return_Statement_Entity
(N
);
1720 Return_Etyp
: constant Entity_Id
:=
1721 Etype
(Return_Applies_To
(Return_Ent
));
1722 Return_Obj_Decls
: constant List_Id
:= Return_Object_Declarations
(N
);
1723 Return_Obj_Decl
: Node_Id
;
1724 Return_Obj_Id
: Entity_Id
;
1725 Return_Obj_Typ
: Entity_Id
;
1727 procedure Error_Dim_Msg_For_Extended_Return_Statement
1729 Return_Etyp
: Entity_Id
;
1730 Return_Obj_Typ
: Entity_Id
);
1731 -- Error using Error_Msg_N at node N. Output dimensions of the returned
1732 -- type Return_Etyp and the returned object type Return_Obj_Typ of N.
1734 -------------------------------------------------
1735 -- Error_Dim_Msg_For_Extended_Return_Statement --
1736 -------------------------------------------------
1738 procedure Error_Dim_Msg_For_Extended_Return_Statement
1740 Return_Etyp
: Entity_Id
;
1741 Return_Obj_Typ
: Entity_Id
)
1744 Error_Msg_N
("dimensions mismatch in extended return statement", N
);
1746 ("\expected dimension " & Dimensions_Msg_Of
(Return_Etyp
)
1747 & ", found " & Dimensions_Msg_Of
(Return_Obj_Typ
), N
);
1748 end Error_Dim_Msg_For_Extended_Return_Statement
;
1750 -- Start of processing for Analyze_Dimension_Extended_Return_Statement
1753 if Present
(Return_Obj_Decls
) then
1754 Return_Obj_Decl
:= First
(Return_Obj_Decls
);
1755 while Present
(Return_Obj_Decl
) loop
1756 if Nkind
(Return_Obj_Decl
) = N_Object_Declaration
then
1757 Return_Obj_Id
:= Defining_Identifier
(Return_Obj_Decl
);
1759 if Is_Return_Object
(Return_Obj_Id
) then
1760 Return_Obj_Typ
:= Etype
(Return_Obj_Id
);
1762 -- Issue an error message if dimensions mismatch
1764 if Dimensions_Of
(Return_Etyp
) /=
1765 Dimensions_Of
(Return_Obj_Typ
)
1767 Error_Dim_Msg_For_Extended_Return_Statement
1768 (N
, Return_Etyp
, Return_Obj_Typ
);
1774 Next
(Return_Obj_Decl
);
1777 end Analyze_Dimension_Extended_Return_Statement
;
1779 -----------------------------------------------------
1780 -- Analyze_Dimension_Extension_Or_Record_Aggregate --
1781 -----------------------------------------------------
1783 procedure Analyze_Dimension_Extension_Or_Record_Aggregate
(N
: Node_Id
) is
1785 Comp_Id
: Entity_Id
;
1786 Comp_Typ
: Entity_Id
;
1789 Error_Detected
: Boolean := False;
1790 -- This flag is used in order to indicate if an error has been detected
1791 -- so far by the compiler in this routine.
1794 -- Aspect is an Ada 2012 feature. Note that there is no need to check
1795 -- dimensions for aggregates that don't come from source.
1797 if Ada_Version
< Ada_2012
or else not Comes_From_Source
(N
) then
1801 Comp
:= First
(Component_Associations
(N
));
1802 while Present
(Comp
) loop
1803 Comp_Id
:= Entity
(First
(Choices
(Comp
)));
1804 Comp_Typ
:= Etype
(Comp_Id
);
1806 -- Check the component type is either a dimensioned type or a
1807 -- dimensioned subtype.
1809 if Has_Dimension_System
(Base_Type
(Comp_Typ
)) then
1810 Expr
:= Expression
(Comp
);
1812 -- Issue an error if the dimensions of the component type and the
1813 -- dimensions of the component mismatch.
1815 if Dimensions_Of
(Expr
) /= Dimensions_Of
(Comp_Typ
) then
1817 -- Check if an error has already been encountered so far
1819 if not Error_Detected
then
1821 -- Extension aggregate case
1823 if Nkind
(N
) = N_Extension_Aggregate
then
1825 ("dimensions mismatch in extension aggregate", N
);
1827 -- Record aggregate case
1831 ("dimensions mismatch in record aggregate", N
);
1834 Error_Detected
:= True;
1838 ("\expected dimension " & Dimensions_Msg_Of
(Comp_Typ
)
1839 & ", found " & Dimensions_Msg_Of
(Expr
), Comp
);
1845 end Analyze_Dimension_Extension_Or_Record_Aggregate
;
1847 -------------------------------
1848 -- Analyze_Dimension_Formals --
1849 -------------------------------
1851 procedure Analyze_Dimension_Formals
(N
: Node_Id
; Formals
: List_Id
) is
1852 Dims_Of_Typ
: Dimension_Type
;
1857 -- Aspect is an Ada 2012 feature. Note that there is no need to check
1858 -- dimensions for sub specs that don't come from source.
1860 if Ada_Version
< Ada_2012
or else not Comes_From_Source
(N
) then
1864 Formal
:= First
(Formals
);
1865 while Present
(Formal
) loop
1866 Typ
:= Parameter_Type
(Formal
);
1867 Dims_Of_Typ
:= Dimensions_Of
(Typ
);
1869 if Exists
(Dims_Of_Typ
) then
1871 Expr
: constant Node_Id
:= Expression
(Formal
);
1874 -- Issue a warning if Expr is a numeric literal and if its
1875 -- dimensions differ with the dimensions of the formal type.
1878 and then Dims_Of_Typ
/= Dimensions_Of
(Expr
)
1879 and then Nkind_In
(Original_Node
(Expr
), N_Real_Literal
,
1882 Dim_Warning_For_Numeric_Literal
(Expr
, Etype
(Typ
));
1889 end Analyze_Dimension_Formals
;
1891 ---------------------------------
1892 -- Analyze_Dimension_Has_Etype --
1893 ---------------------------------
1895 procedure Analyze_Dimension_Has_Etype
(N
: Node_Id
) is
1896 Etyp
: constant Entity_Id
:= Etype
(N
);
1897 Dims_Of_Etyp
: Dimension_Type
:= Dimensions_Of
(Etyp
);
1900 -- General case. Propagation of the dimensions from the type
1902 if Exists
(Dims_Of_Etyp
) then
1903 Set_Dimensions
(N
, Dims_Of_Etyp
);
1905 -- Identifier case. Propagate the dimensions from the entity for
1906 -- identifier whose entity is a non-dimensionless constant.
1908 elsif Nkind
(N
) = N_Identifier
then
1909 Analyze_Dimension_Identifier
: declare
1910 Id
: constant Entity_Id
:= Entity
(N
);
1913 -- If Id is missing, abnormal tree, assume previous error
1916 Check_Error_Detected
;
1919 elsif Ekind
(Id
) = E_Constant
1920 and then Exists
(Dimensions_Of
(Id
))
1922 Set_Dimensions
(N
, Dimensions_Of
(Id
));
1924 end Analyze_Dimension_Identifier
;
1926 -- Attribute reference case. Propagate the dimensions from the prefix.
1928 elsif Nkind
(N
) = N_Attribute_Reference
1929 and then Has_Dimension_System
(Base_Type
(Etyp
))
1931 Dims_Of_Etyp
:= Dimensions_Of
(Prefix
(N
));
1933 -- Check the prefix is not dimensionless
1935 if Exists
(Dims_Of_Etyp
) then
1936 Set_Dimensions
(N
, Dims_Of_Etyp
);
1940 -- Removal of dimensions in expression
1943 when N_Attribute_Reference |
1944 N_Indexed_Component
=>
1947 Exprs
: constant List_Id
:= Expressions
(N
);
1949 if Present
(Exprs
) then
1950 Expr
:= First
(Exprs
);
1951 while Present
(Expr
) loop
1952 Remove_Dimensions
(Expr
);
1958 when N_Qualified_Expression |
1960 N_Unchecked_Type_Conversion
=>
1961 Remove_Dimensions
(Expression
(N
));
1963 when N_Selected_Component
=>
1964 Remove_Dimensions
(Selector_Name
(N
));
1966 when others => null;
1968 end Analyze_Dimension_Has_Etype
;
1970 ------------------------------------------
1971 -- Analyze_Dimension_Object_Declaration --
1972 ------------------------------------------
1974 procedure Analyze_Dimension_Object_Declaration
(N
: Node_Id
) is
1975 Expr
: constant Node_Id
:= Expression
(N
);
1976 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1977 Etyp
: constant Entity_Id
:= Etype
(Id
);
1978 Dim_Of_Etyp
: constant Dimension_Type
:= Dimensions_Of
(Etyp
);
1979 Dim_Of_Expr
: Dimension_Type
;
1981 procedure Error_Dim_Msg_For_Object_Declaration
1985 -- Error using Error_Msg_N at node N. Output the dimensions of the
1986 -- type Etyp and of the expression Expr.
1988 ------------------------------------------
1989 -- Error_Dim_Msg_For_Object_Declaration --
1990 ------------------------------------------
1992 procedure Error_Dim_Msg_For_Object_Declaration
1997 Error_Msg_N
("dimensions mismatch in object declaration", N
);
1999 ("\expected dimension " & Dimensions_Msg_Of
(Etyp
) & ", found "
2000 & Dimensions_Msg_Of
(Expr
), Expr
);
2001 end Error_Dim_Msg_For_Object_Declaration
;
2003 -- Start of processing for Analyze_Dimension_Object_Declaration
2006 -- Expression is present
2008 if Present
(Expr
) then
2009 Dim_Of_Expr
:= Dimensions_Of
(Expr
);
2011 -- Check dimensions match
2013 if Dim_Of_Expr
/= Dim_Of_Etyp
then
2015 -- Numeric literal case. Issue a warning if the object type is not
2016 -- dimensionless to indicate the literal is treated as if its
2017 -- dimension matches the type dimension.
2019 if Nkind_In
(Original_Node
(Expr
), N_Real_Literal
,
2022 Dim_Warning_For_Numeric_Literal
(Expr
, Etyp
);
2024 -- Case of object is a constant whose type is a dimensioned type
2026 elsif Constant_Present
(N
) and then not Exists
(Dim_Of_Etyp
) then
2028 -- Propagate dimension from expression to object entity
2030 Set_Dimensions
(Id
, Dim_Of_Expr
);
2032 -- For all other cases, issue an error message
2035 Error_Dim_Msg_For_Object_Declaration
(N
, Etyp
, Expr
);
2039 -- Removal of dimensions in expression
2041 Remove_Dimensions
(Expr
);
2043 end Analyze_Dimension_Object_Declaration
;
2045 ---------------------------------------------------
2046 -- Analyze_Dimension_Object_Renaming_Declaration --
2047 ---------------------------------------------------
2049 procedure Analyze_Dimension_Object_Renaming_Declaration
(N
: Node_Id
) is
2050 Renamed_Name
: constant Node_Id
:= Name
(N
);
2051 Sub_Mark
: constant Node_Id
:= Subtype_Mark
(N
);
2053 procedure Error_Dim_Msg_For_Object_Renaming_Declaration
2056 Renamed_Name
: Node_Id
);
2057 -- Error using Error_Msg_N at node N. Output the dimensions of
2058 -- Sub_Mark and of Renamed_Name.
2060 ---------------------------------------------------
2061 -- Error_Dim_Msg_For_Object_Renaming_Declaration --
2062 ---------------------------------------------------
2064 procedure Error_Dim_Msg_For_Object_Renaming_Declaration
2067 Renamed_Name
: Node_Id
) is
2069 Error_Msg_N
("dimensions mismatch in object renaming declaration", N
);
2071 ("\expected dimension " & Dimensions_Msg_Of
(Sub_Mark
) & ", found "
2072 & Dimensions_Msg_Of
(Renamed_Name
), Renamed_Name
);
2073 end Error_Dim_Msg_For_Object_Renaming_Declaration
;
2075 -- Start of processing for Analyze_Dimension_Object_Renaming_Declaration
2078 if Dimensions_Of
(Renamed_Name
) /= Dimensions_Of
(Sub_Mark
) then
2079 Error_Dim_Msg_For_Object_Renaming_Declaration
2080 (N
, Sub_Mark
, Renamed_Name
);
2082 end Analyze_Dimension_Object_Renaming_Declaration
;
2084 -----------------------------------------------
2085 -- Analyze_Dimension_Simple_Return_Statement --
2086 -----------------------------------------------
2088 procedure Analyze_Dimension_Simple_Return_Statement
(N
: Node_Id
) is
2089 Expr
: constant Node_Id
:= Expression
(N
);
2090 Dims_Of_Expr
: constant Dimension_Type
:= Dimensions_Of
(Expr
);
2091 Return_Ent
: constant Entity_Id
:= Return_Statement_Entity
(N
);
2092 Return_Etyp
: constant Entity_Id
:=
2093 Etype
(Return_Applies_To
(Return_Ent
));
2094 Dims_Of_Return_Etyp
: constant Dimension_Type
:=
2095 Dimensions_Of
(Return_Etyp
);
2097 procedure Error_Dim_Msg_For_Simple_Return_Statement
2099 Return_Etyp
: Entity_Id
;
2101 -- Error using Error_Msg_N at node N. Output the dimensions of the
2102 -- returned type Return_Etyp and the returned expression Expr of N.
2104 -----------------------------------------------
2105 -- Error_Dim_Msg_For_Simple_Return_Statement --
2106 -----------------------------------------------
2108 procedure Error_Dim_Msg_For_Simple_Return_Statement
2110 Return_Etyp
: Entity_Id
;
2114 Error_Msg_N
("dimensions mismatch in return statement", N
);
2116 ("\expected dimension " & Dimensions_Msg_Of
(Return_Etyp
)
2117 & ", found " & Dimensions_Msg_Of
(Expr
), Expr
);
2118 end Error_Dim_Msg_For_Simple_Return_Statement
;
2120 -- Start of processing for Analyze_Dimension_Simple_Return_Statement
2123 if Dims_Of_Return_Etyp
/= Dims_Of_Expr
then
2124 Error_Dim_Msg_For_Simple_Return_Statement
(N
, Return_Etyp
, Expr
);
2125 Remove_Dimensions
(Expr
);
2127 end Analyze_Dimension_Simple_Return_Statement
;
2129 -------------------------------------------
2130 -- Analyze_Dimension_Subtype_Declaration --
2131 -------------------------------------------
2133 procedure Analyze_Dimension_Subtype_Declaration
(N
: Node_Id
) is
2134 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
2135 Dims_Of_Id
: constant Dimension_Type
:= Dimensions_Of
(Id
);
2136 Dims_Of_Etyp
: Dimension_Type
;
2140 -- No constraint case in subtype declaration
2142 if Nkind
(Subtype_Indication
(N
)) /= N_Subtype_Indication
then
2143 Etyp
:= Etype
(Subtype_Indication
(N
));
2144 Dims_Of_Etyp
:= Dimensions_Of
(Etyp
);
2146 if Exists
(Dims_Of_Etyp
) then
2148 -- If subtype already has a dimension (from Aspect_Dimension),
2149 -- it cannot inherit a dimension from its subtype.
2151 if Exists
(Dims_Of_Id
) then
2153 ("subtype& already" & Dimensions_Msg_Of
(Id
, True), N
);
2155 Set_Dimensions
(Id
, Dims_Of_Etyp
);
2156 Set_Symbol
(Id
, Symbol_Of
(Etyp
));
2160 -- Constraint present in subtype declaration
2163 Etyp
:= Etype
(Subtype_Mark
(Subtype_Indication
(N
)));
2164 Dims_Of_Etyp
:= Dimensions_Of
(Etyp
);
2166 if Exists
(Dims_Of_Etyp
) then
2167 Set_Dimensions
(Id
, Dims_Of_Etyp
);
2168 Set_Symbol
(Id
, Symbol_Of
(Etyp
));
2171 end Analyze_Dimension_Subtype_Declaration
;
2173 --------------------------------
2174 -- Analyze_Dimension_Unary_Op --
2175 --------------------------------
2177 procedure Analyze_Dimension_Unary_Op
(N
: Node_Id
) is
2180 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
2182 -- Propagate the dimension if the operand is not dimensionless
2185 R
: constant Node_Id
:= Right_Opnd
(N
);
2187 Move_Dimensions
(R
, N
);
2190 when others => null;
2193 end Analyze_Dimension_Unary_Op
;
2195 ---------------------
2196 -- Copy_Dimensions --
2197 ---------------------
2199 procedure Copy_Dimensions
(From
, To
: Node_Id
) is
2200 Dims_Of_From
: constant Dimension_Type
:= Dimensions_Of
(From
);
2203 -- Ignore if not Ada 2012 or beyond
2205 if Ada_Version
< Ada_2012
then
2208 -- For Ada 2012, Copy the dimension of 'From to 'To'
2210 elsif Exists
(Dims_Of_From
) then
2211 Set_Dimensions
(To
, Dims_Of_From
);
2213 end Copy_Dimensions
;
2215 --------------------------
2216 -- Create_Rational_From --
2217 --------------------------
2219 -- RATIONAL ::= [-] NUMERAL [/ NUMERAL]
2221 -- A rational number is a number that can be expressed as the quotient or
2222 -- fraction a/b of two integers, where b is non-zero positive.
2224 function Create_Rational_From
2226 Complain
: Boolean) return Rational
2228 Or_Node_Of_Expr
: constant Node_Id
:= Original_Node
(Expr
);
2229 Result
: Rational
:= No_Rational
;
2231 function Process_Minus
(N
: Node_Id
) return Rational
;
2232 -- Create a rational from a N_Op_Minus node
2234 function Process_Divide
(N
: Node_Id
) return Rational
;
2235 -- Create a rational from a N_Op_Divide node
2237 function Process_Literal
(N
: Node_Id
) return Rational
;
2238 -- Create a rational from a N_Integer_Literal node
2244 function Process_Minus
(N
: Node_Id
) return Rational
is
2245 Right
: constant Node_Id
:= Original_Node
(Right_Opnd
(N
));
2249 -- Operand is an integer literal
2251 if Nkind
(Right
) = N_Integer_Literal
then
2252 Result
:= -Process_Literal
(Right
);
2254 -- Operand is a divide operator
2256 elsif Nkind
(Right
) = N_Op_Divide
then
2257 Result
:= -Process_Divide
(Right
);
2260 Result
:= No_Rational
;
2263 -- Provide minimal semantic information on dimension expressions,
2264 -- even though they have no run-time existence. This is for use by
2265 -- ASIS tools, in particular pretty-printing. If generating code
2266 -- standard operator resolution will take place.
2269 Set_Entity
(N
, Standard_Op_Minus
);
2270 Set_Etype
(N
, Standard_Integer
);
2276 --------------------
2277 -- Process_Divide --
2278 --------------------
2280 function Process_Divide
(N
: Node_Id
) return Rational
is
2281 Left
: constant Node_Id
:= Original_Node
(Left_Opnd
(N
));
2282 Right
: constant Node_Id
:= Original_Node
(Right_Opnd
(N
));
2283 Left_Rat
: Rational
;
2284 Result
: Rational
:= No_Rational
;
2285 Right_Rat
: Rational
;
2288 -- Both left and right operands are integer literals
2290 if Nkind
(Left
) = N_Integer_Literal
2292 Nkind
(Right
) = N_Integer_Literal
2294 Left_Rat
:= Process_Literal
(Left
);
2295 Right_Rat
:= Process_Literal
(Right
);
2296 Result
:= Left_Rat
/ Right_Rat
;
2299 -- Provide minimal semantic information on dimension expressions,
2300 -- even though they have no run-time existence. This is for use by
2301 -- ASIS tools, in particular pretty-printing. If generating code
2302 -- standard operator resolution will take place.
2305 Set_Entity
(N
, Standard_Op_Divide
);
2306 Set_Etype
(N
, Standard_Integer
);
2312 ---------------------
2313 -- Process_Literal --
2314 ---------------------
2316 function Process_Literal
(N
: Node_Id
) return Rational
is
2318 return +Whole
(UI_To_Int
(Intval
(N
)));
2319 end Process_Literal
;
2321 -- Start of processing for Create_Rational_From
2324 -- Check the expression is either a division of two integers or an
2325 -- integer itself. Note that the check applies to the original node
2326 -- since the node could have already been rewritten.
2328 -- Integer literal case
2330 if Nkind
(Or_Node_Of_Expr
) = N_Integer_Literal
then
2331 Result
:= Process_Literal
(Or_Node_Of_Expr
);
2333 -- Divide operator case
2335 elsif Nkind
(Or_Node_Of_Expr
) = N_Op_Divide
then
2336 Result
:= Process_Divide
(Or_Node_Of_Expr
);
2338 -- Minus operator case
2340 elsif Nkind
(Or_Node_Of_Expr
) = N_Op_Minus
then
2341 Result
:= Process_Minus
(Or_Node_Of_Expr
);
2344 -- When Expr cannot be interpreted as a rational and Complain is true,
2345 -- generate an error message.
2347 if Complain
and then Result
= No_Rational
then
2348 Error_Msg_N
("rational expected", Expr
);
2352 end Create_Rational_From
;
2358 function Dimensions_Of
(N
: Node_Id
) return Dimension_Type
is
2360 return Dimension_Table
.Get
(N
);
2363 -----------------------
2364 -- Dimensions_Msg_Of --
2365 -----------------------
2367 function Dimensions_Msg_Of
2369 Description_Needed
: Boolean := False) return String
2371 Dims_Of_N
: constant Dimension_Type
:= Dimensions_Of
(N
);
2372 Dimensions_Msg
: Name_Id
;
2373 System
: System_Type
;
2376 -- Initialization of Name_Buffer
2380 -- N is not dimensionless
2382 if Exists
(Dims_Of_N
) then
2383 System
:= System_Of
(Base_Type
(Etype
(N
)));
2385 -- When Description_Needed, add to string "has dimension " before the
2386 -- actual dimension.
2388 if Description_Needed
then
2389 Add_Str_To_Name_Buffer
("has dimension ");
2392 Add_String_To_Name_Buffer
2393 (From_Dim_To_Str_Of_Dim_Symbols
(Dims_Of_N
, System
, True));
2395 -- N is dimensionless
2397 -- When Description_Needed, return "is dimensionless"
2399 elsif Description_Needed
then
2400 Add_Str_To_Name_Buffer
("is dimensionless");
2402 -- Otherwise, return "'[']"
2405 Add_Str_To_Name_Buffer
("'[']");
2408 Dimensions_Msg
:= Name_Find
;
2409 return Get_Name_String
(Dimensions_Msg
);
2410 end Dimensions_Msg_Of
;
2412 --------------------------
2413 -- Dimension_Table_Hash --
2414 --------------------------
2416 function Dimension_Table_Hash
2417 (Key
: Node_Id
) return Dimension_Table_Range
2420 return Dimension_Table_Range
(Key
mod 511);
2421 end Dimension_Table_Hash
;
2423 -------------------------------------
2424 -- Dim_Warning_For_Numeric_Literal --
2425 -------------------------------------
2427 procedure Dim_Warning_For_Numeric_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
2429 -- Initialize name buffer
2433 Add_String_To_Name_Buffer
(String_From_Numeric_Literal
(N
));
2435 -- Insert a blank between the literal and the symbol
2437 Add_Str_To_Name_Buffer
(" ");
2438 Add_String_To_Name_Buffer
(Symbol_Of
(Typ
));
2440 Error_Msg_Name_1
:= Name_Find
;
2441 Error_Msg_N
("assumed to be%%??", N
);
2442 end Dim_Warning_For_Numeric_Literal
;
2444 ----------------------------------------
2445 -- Eval_Op_Expon_For_Dimensioned_Type --
2446 ----------------------------------------
2448 -- Evaluate the expon operator for real dimensioned type.
2450 -- Note that if the exponent is an integer (denominator = 1) the node is
2451 -- evaluated by the regular Eval_Op_Expon routine (see Sem_Eval).
2453 procedure Eval_Op_Expon_For_Dimensioned_Type
2457 R
: constant Node_Id
:= Right_Opnd
(N
);
2458 R_Value
: Rational
:= No_Rational
;
2461 if Is_Real_Type
(Btyp
) then
2462 R_Value
:= Create_Rational_From
(R
, False);
2465 -- Check that the exponent is not an integer
2467 if R_Value
/= No_Rational
and then R_Value
.Denominator
/= 1 then
2468 Eval_Op_Expon_With_Rational_Exponent
(N
, R_Value
);
2472 end Eval_Op_Expon_For_Dimensioned_Type
;
2474 ------------------------------------------
2475 -- Eval_Op_Expon_With_Rational_Exponent --
2476 ------------------------------------------
2478 -- For dimensioned operand in exponentiation, exponent is allowed to be a
2479 -- Rational and not only an Integer like for dimensionless operands. For
2480 -- that particular case, the left operand is rewritten as a function call
2481 -- using the function Expon_LLF from s-llflex.ads.
2483 procedure Eval_Op_Expon_With_Rational_Exponent
2485 Exponent_Value
: Rational
)
2487 Loc
: constant Source_Ptr
:= Sloc
(N
);
2488 Dims_Of_N
: constant Dimension_Type
:= Dimensions_Of
(N
);
2489 L
: constant Node_Id
:= Left_Opnd
(N
);
2490 Etyp_Of_L
: constant Entity_Id
:= Etype
(L
);
2491 Btyp_Of_L
: constant Entity_Id
:= Base_Type
(Etyp_Of_L
);
2494 Dim_Power
: Rational
;
2495 List_Of_Dims
: List_Id
;
2496 New_Aspect
: Node_Id
;
2497 New_Aspects
: List_Id
;
2500 New_Subtyp_Decl_For_L
: Node_Id
;
2501 System
: System_Type
;
2504 -- Case when the operand is not dimensionless
2506 if Exists
(Dims_Of_N
) then
2508 -- Get the corresponding System_Type to know the exact number of
2509 -- dimensions in the system.
2511 System
:= System_Of
(Btyp_Of_L
);
2513 -- Generation of a new subtype with the proper dimensions
2515 -- In order to rewrite the operator as a type conversion, a new
2516 -- dimensioned subtype with the resulting dimensions of the
2517 -- exponentiation must be created.
2521 -- Btyp_Of_L : constant Entity_Id := Base_Type (Etyp_Of_L);
2522 -- System : constant System_Id :=
2523 -- Get_Dimension_System_Id (Btyp_Of_L);
2524 -- Num_Of_Dims : constant Number_Of_Dimensions :=
2525 -- Dimension_Systems.Table (System).Dimension_Count;
2527 -- subtype T is Btyp_Of_L
2530 -- Dims_Of_N (1).Numerator / Dims_Of_N (1).Denominator,
2531 -- Dims_Of_N (2).Numerator / Dims_Of_N (2).Denominator,
2533 -- Dims_Of_N (Num_Of_Dims).Numerator /
2534 -- Dims_Of_N (Num_Of_Dims).Denominator);
2536 -- Step 1: Generate the new aggregate for the aspect Dimension
2538 New_Aspects
:= Empty_List
;
2540 List_Of_Dims
:= New_List
;
2541 for Position
in Dims_Of_N
'First .. System
.Count
loop
2542 Dim_Power
:= Dims_Of_N
(Position
);
2543 Append_To
(List_Of_Dims
,
2544 Make_Op_Divide
(Loc
,
2546 Make_Integer_Literal
(Loc
, Int
(Dim_Power
.Numerator
)),
2548 Make_Integer_Literal
(Loc
, Int
(Dim_Power
.Denominator
))));
2551 -- Step 2: Create the new Aspect Specification for Aspect Dimension
2554 Make_Aspect_Specification
(Loc
,
2555 Identifier
=> Make_Identifier
(Loc
, Name_Dimension
),
2556 Expression
=> Make_Aggregate
(Loc
, Expressions
=> List_Of_Dims
));
2558 -- Step 3: Make a temporary identifier for the new subtype
2560 New_Id
:= Make_Temporary
(Loc
, 'T');
2561 Set_Is_Internal
(New_Id
);
2563 -- Step 4: Declaration of the new subtype
2565 New_Subtyp_Decl_For_L
:=
2566 Make_Subtype_Declaration
(Loc
,
2567 Defining_Identifier
=> New_Id
,
2568 Subtype_Indication
=> New_Occurrence_Of
(Btyp_Of_L
, Loc
));
2570 Append
(New_Aspect
, New_Aspects
);
2571 Set_Parent
(New_Aspects
, New_Subtyp_Decl_For_L
);
2572 Set_Aspect_Specifications
(New_Subtyp_Decl_For_L
, New_Aspects
);
2574 Analyze
(New_Subtyp_Decl_For_L
);
2576 -- Case where the operand is dimensionless
2579 New_Id
:= Btyp_Of_L
;
2582 -- Replacement of N by New_N
2586 -- Actual_1 := Long_Long_Float (L),
2588 -- Actual_2 := Long_Long_Float (Exponent_Value.Numerator) /
2589 -- Long_Long_Float (Exponent_Value.Denominator);
2591 -- (T (Expon_LLF (Actual_1, Actual_2)));
2593 -- where T is the subtype declared in step 1
2595 -- The node is rewritten as a type conversion
2597 -- Step 1: Creation of the two parameters of Expon_LLF function call
2600 Make_Type_Conversion
(Loc
,
2601 Subtype_Mark
=> New_Occurrence_Of
(Standard_Long_Long_Float
, Loc
),
2602 Expression
=> Relocate_Node
(L
));
2605 Make_Op_Divide
(Loc
,
2607 Make_Real_Literal
(Loc
,
2608 UR_From_Uint
(UI_From_Int
(Int
(Exponent_Value
.Numerator
)))),
2610 Make_Real_Literal
(Loc
,
2611 UR_From_Uint
(UI_From_Int
(Int
(Exponent_Value
.Denominator
)))));
2613 -- Step 2: Creation of New_N
2616 Make_Type_Conversion
(Loc
,
2617 Subtype_Mark
=> New_Occurrence_Of
(New_Id
, Loc
),
2619 Make_Function_Call
(Loc
,
2620 Name
=> New_Occurrence_Of
(RTE
(RE_Expon_LLF
), Loc
),
2621 Parameter_Associations
=> New_List
(
2622 Actual_1
, Actual_2
)));
2624 -- Step 3: Rewrite N with the result
2627 Set_Etype
(N
, New_Id
);
2628 Analyze_And_Resolve
(N
, New_Id
);
2629 end Eval_Op_Expon_With_Rational_Exponent
;
2635 function Exists
(Dim
: Dimension_Type
) return Boolean is
2637 return Dim
/= Null_Dimension
;
2640 function Exists
(Str
: String_Id
) return Boolean is
2642 return Str
/= No_String
;
2645 function Exists
(Sys
: System_Type
) return Boolean is
2647 return Sys
/= Null_System
;
2650 ---------------------------------
2651 -- Expand_Put_Call_With_Symbol --
2652 ---------------------------------
2654 -- For procedure Put (resp. Put_Dim_Of) defined in System.Dim.Float_IO
2655 -- (System.Dim.Integer_IO), the default string parameter must be rewritten
2656 -- to include the unit symbols (resp. dimension symbols) in the output
2657 -- of a dimensioned object. Note that if a value is already supplied for
2658 -- parameter Symbol, this routine doesn't do anything.
2660 -- Case 1. Item is dimensionless
2662 -- * Put : Item appears without a suffix
2664 -- * Put_Dim_Of : the output is []
2666 -- Obj : Mks_Type := 2.6;
2667 -- Put (Obj, 1, 1, 0);
2668 -- Put_Dim_Of (Obj);
2670 -- The corresponding outputs are:
2674 -- Case 2. Item has a dimension
2676 -- * Put : If the type of Item is a dimensioned subtype whose
2677 -- symbol is not empty, then the symbol appears as a
2678 -- suffix. Otherwise, a new string is created and appears
2679 -- as a suffix of Item. This string results in the
2680 -- successive concatanations between each unit symbol
2681 -- raised by its corresponding dimension power from the
2682 -- dimensions of Item.
2684 -- * Put_Dim_Of : The output is a new string resulting in the successive
2685 -- concatanations between each dimension symbol raised by
2686 -- its corresponding dimension power from the dimensions of
2689 -- subtype Random is Mks_Type
2696 -- Obj : Random := 5.0;
2698 -- Put_Dim_Of (Obj);
2700 -- The corresponding outputs are:
2701 -- $5.0 m**3.cd**(-1)
2704 procedure Expand_Put_Call_With_Symbol
(N
: Node_Id
) is
2705 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
2706 Loc
: constant Source_Ptr
:= Sloc
(N
);
2707 Name_Call
: constant Node_Id
:= Name
(N
);
2708 New_Actuals
: constant List_Id
:= New_List
;
2710 Dims_Of_Actual
: Dimension_Type
;
2712 New_Str_Lit
: Node_Id
:= Empty
;
2713 Symbols
: String_Id
;
2715 Is_Put_Dim_Of
: Boolean := False;
2716 -- This flag is used in order to differentiate routines Put and
2717 -- Put_Dim_Of. Set to True if the procedure is one of the Put_Dim_Of
2718 -- defined in System.Dim.Float_IO or System.Dim.Integer_IO.
2720 function Has_Symbols
return Boolean;
2721 -- Return True if the current Put call already has a parameter
2722 -- association for parameter "Symbols" with the correct string of
2725 function Is_Procedure_Put_Call
return Boolean;
2726 -- Return True if the current call is a call of an instantiation of a
2727 -- procedure Put defined in the package System.Dim.Float_IO and
2728 -- System.Dim.Integer_IO.
2730 function Item_Actual
return Node_Id
;
2731 -- Return the item actual parameter node in the output call
2737 function Has_Symbols
return Boolean is
2739 Actual_Str
: Node_Id
;
2742 -- Look for a symbols parameter association in the list of actuals
2744 Actual
:= First
(Actuals
);
2745 while Present
(Actual
) loop
2747 -- Positional parameter association case when the actual is a
2750 if Nkind
(Actual
) = N_String_Literal
then
2751 Actual_Str
:= Actual
;
2753 -- Named parameter association case when selector name is Symbol
2755 elsif Nkind
(Actual
) = N_Parameter_Association
2756 and then Chars
(Selector_Name
(Actual
)) = Name_Symbol
2758 Actual_Str
:= Explicit_Actual_Parameter
(Actual
);
2760 -- Ignore all other cases
2763 Actual_Str
:= Empty
;
2766 if Present
(Actual_Str
) then
2768 -- Return True if the actual comes from source or if the string
2769 -- of symbols doesn't have the default value (i.e. it is "").
2771 if Comes_From_Source
(Actual
)
2772 or else String_Length
(Strval
(Actual_Str
)) /= 0
2774 -- Complain only if the actual comes from source or if it
2775 -- hasn't been fully analyzed yet.
2777 if Comes_From_Source
(Actual
)
2778 or else not Analyzed
(Actual
)
2780 Error_Msg_N
("Symbol parameter should not be provided",
2782 Error_Msg_N
("\reserved for compiler use only", Actual
);
2795 -- At this point, the call has no parameter association. Look to the
2796 -- last actual since the symbols parameter is the last one.
2798 return Nkind
(Last
(Actuals
)) = N_String_Literal
;
2801 ---------------------------
2802 -- Is_Procedure_Put_Call --
2803 ---------------------------
2805 function Is_Procedure_Put_Call
return Boolean is
2810 -- There are three different Put (resp. Put_Dim_Of) routines in each
2811 -- generic dim IO package. Verify the current procedure call is one
2814 if Is_Entity_Name
(Name_Call
) then
2815 Ent
:= Entity
(Name_Call
);
2817 -- Get the original subprogram entity following the renaming chain
2819 if Present
(Alias
(Ent
)) then
2825 -- Check the name of the entity subprogram is Put (resp.
2826 -- Put_Dim_Of) and verify this entity is located in either
2827 -- System.Dim.Float_IO or System.Dim.Integer_IO.
2829 if Loc
> No_Location
2830 and then Is_Dim_IO_Package_Entity
2831 (Cunit_Entity
(Get_Source_Unit
(Loc
)))
2833 if Chars
(Ent
) = Name_Put_Dim_Of
then
2834 Is_Put_Dim_Of
:= True;
2837 elsif Chars
(Ent
) = Name_Put
then
2844 end Is_Procedure_Put_Call
;
2850 function Item_Actual
return Node_Id
is
2854 -- Look for the item actual as a parameter association
2856 Actual
:= First
(Actuals
);
2857 while Present
(Actual
) loop
2858 if Nkind
(Actual
) = N_Parameter_Association
2859 and then Chars
(Selector_Name
(Actual
)) = Name_Item
2861 return Explicit_Actual_Parameter
(Actual
);
2867 -- Case where the item has been defined without an association
2869 Actual
:= First
(Actuals
);
2871 -- Depending on the procedure Put, Item actual could be first or
2872 -- second in the list of actuals.
2874 if Has_Dimension_System
(Base_Type
(Etype
(Actual
))) then
2877 return Next
(Actual
);
2881 -- Start of processing for Expand_Put_Call_With_Symbol
2884 if Is_Procedure_Put_Call
and then not Has_Symbols
then
2885 Actual
:= Item_Actual
;
2886 Dims_Of_Actual
:= Dimensions_Of
(Actual
);
2887 Etyp
:= Etype
(Actual
);
2891 if Is_Put_Dim_Of
then
2893 -- Check that the item is not dimensionless
2895 -- Create the new String_Literal with the new String_Id generated
2896 -- by the routine From_Dim_To_Str_Of_Dim_Symbols.
2898 if Exists
(Dims_Of_Actual
) then
2900 Make_String_Literal
(Loc
,
2901 From_Dim_To_Str_Of_Dim_Symbols
2902 (Dims_Of_Actual
, System_Of
(Base_Type
(Etyp
))));
2904 -- If dimensionless, the output is []
2908 Make_String_Literal
(Loc
, "[]");
2914 -- Add the symbol as a suffix of the value if the subtype has a
2915 -- unit symbol or if the parameter is not dimensionless.
2917 if Exists
(Symbol_Of
(Etyp
)) then
2918 Symbols
:= Symbol_Of
(Etyp
);
2920 Symbols
:= From_Dim_To_Str_Of_Unit_Symbols
2921 (Dims_Of_Actual
, System_Of
(Base_Type
(Etyp
)));
2924 -- Check Symbols exists
2926 if Exists
(Symbols
) then
2929 -- Put a space between the value and the dimension
2931 Store_String_Char
(' ');
2932 Store_String_Chars
(Symbols
);
2933 New_Str_Lit
:= Make_String_Literal
(Loc
, End_String
);
2937 if Present
(New_Str_Lit
) then
2939 -- Insert all actuals in New_Actuals
2941 Actual
:= First
(Actuals
);
2942 while Present
(Actual
) loop
2944 -- Copy every actuals in New_Actuals except the Symbols
2945 -- parameter association.
2947 if Nkind
(Actual
) = N_Parameter_Association
2948 and then Chars
(Selector_Name
(Actual
)) /= Name_Symbol
2950 Append_To
(New_Actuals
,
2951 Make_Parameter_Association
(Loc
,
2952 Selector_Name
=> New_Copy
(Selector_Name
(Actual
)),
2953 Explicit_Actual_Parameter
=>
2954 New_Copy
(Explicit_Actual_Parameter
(Actual
))));
2956 elsif Nkind
(Actual
) /= N_Parameter_Association
then
2957 Append_To
(New_Actuals
, New_Copy
(Actual
));
2963 -- Create new Symbols param association and append to New_Actuals
2965 Append_To
(New_Actuals
,
2966 Make_Parameter_Association
(Loc
,
2967 Selector_Name
=> Make_Identifier
(Loc
, Name_Symbol
),
2968 Explicit_Actual_Parameter
=> New_Str_Lit
));
2970 -- Rewrite and analyze the procedure call
2973 Make_Procedure_Call_Statement
(Loc
,
2974 Name
=> New_Copy
(Name_Call
),
2975 Parameter_Associations
=> New_Actuals
));
2980 end Expand_Put_Call_With_Symbol
;
2982 ------------------------------------
2983 -- From_Dim_To_Str_Of_Dim_Symbols --
2984 ------------------------------------
2986 -- Given a dimension vector and the corresponding dimension system, create
2987 -- a String_Id to output dimension symbols corresponding to the dimensions
2988 -- Dims. If In_Error_Msg is True, there is a special handling for character
2989 -- asterisk * which is an insertion character in error messages.
2991 function From_Dim_To_Str_Of_Dim_Symbols
2992 (Dims
: Dimension_Type
;
2993 System
: System_Type
;
2994 In_Error_Msg
: Boolean := False) return String_Id
2996 Dim_Power
: Rational
;
2997 First_Dim
: Boolean := True;
2999 procedure Store_String_Oexpon
;
3000 -- Store the expon operator symbol "**" in the string. In error
3001 -- messages, asterisk * is a special character and must be quoted
3002 -- to be placed literally into the message.
3004 -------------------------
3005 -- Store_String_Oexpon --
3006 -------------------------
3008 procedure Store_String_Oexpon
is
3010 if In_Error_Msg
then
3011 Store_String_Chars
("'*'*");
3013 Store_String_Chars
("**");
3015 end Store_String_Oexpon
;
3017 -- Start of processing for From_Dim_To_Str_Of_Dim_Symbols
3020 -- Initialization of the new String_Id
3024 -- Store the dimension symbols inside boxes
3026 if In_Error_Msg
then
3027 Store_String_Chars
("'[");
3029 Store_String_Char
('[');
3032 for Position
in Dimension_Type
'Range loop
3033 Dim_Power
:= Dims
(Position
);
3034 if Dim_Power
/= Zero
then
3039 Store_String_Char
('.');
3042 Store_String_Chars
(System
.Dim_Symbols
(Position
));
3044 -- Positive dimension case
3046 if Dim_Power
.Numerator
> 0 then
3050 if Dim_Power
.Denominator
= 1 then
3051 if Dim_Power
.Numerator
/= 1 then
3052 Store_String_Oexpon
;
3053 Store_String_Int
(Int
(Dim_Power
.Numerator
));
3056 -- Rational case when denominator /= 1
3059 Store_String_Oexpon
;
3060 Store_String_Char
('(');
3061 Store_String_Int
(Int
(Dim_Power
.Numerator
));
3062 Store_String_Char
('/');
3063 Store_String_Int
(Int
(Dim_Power
.Denominator
));
3064 Store_String_Char
(')');
3067 -- Negative dimension case
3070 Store_String_Oexpon
;
3071 Store_String_Char
('(');
3072 Store_String_Char
('-');
3073 Store_String_Int
(Int
(-Dim_Power
.Numerator
));
3077 if Dim_Power
.Denominator
= 1 then
3078 Store_String_Char
(')');
3080 -- Rational case when denominator /= 1
3083 Store_String_Char
('/');
3084 Store_String_Int
(Int
(Dim_Power
.Denominator
));
3085 Store_String_Char
(')');
3091 if In_Error_Msg
then
3092 Store_String_Chars
("']");
3094 Store_String_Char
(']');
3098 end From_Dim_To_Str_Of_Dim_Symbols
;
3100 -------------------------------------
3101 -- From_Dim_To_Str_Of_Unit_Symbols --
3102 -------------------------------------
3104 -- Given a dimension vector and the corresponding dimension system,
3105 -- create a String_Id to output the unit symbols corresponding to the
3108 function From_Dim_To_Str_Of_Unit_Symbols
3109 (Dims
: Dimension_Type
;
3110 System
: System_Type
) return String_Id
3112 Dim_Power
: Rational
;
3113 First_Dim
: Boolean := True;
3116 -- Return No_String if dimensionless
3118 if not Exists
(Dims
) then
3122 -- Initialization of the new String_Id
3126 for Position
in Dimension_Type
'Range loop
3127 Dim_Power
:= Dims
(Position
);
3129 if Dim_Power
/= Zero
then
3133 Store_String_Char
('.');
3136 Store_String_Chars
(System
.Unit_Symbols
(Position
));
3138 -- Positive dimension case
3140 if Dim_Power
.Numerator
> 0 then
3144 if Dim_Power
.Denominator
= 1 then
3145 if Dim_Power
.Numerator
/= 1 then
3146 Store_String_Chars
("**");
3147 Store_String_Int
(Int
(Dim_Power
.Numerator
));
3150 -- Rational case when denominator /= 1
3153 Store_String_Chars
("**");
3154 Store_String_Char
('(');
3155 Store_String_Int
(Int
(Dim_Power
.Numerator
));
3156 Store_String_Char
('/');
3157 Store_String_Int
(Int
(Dim_Power
.Denominator
));
3158 Store_String_Char
(')');
3161 -- Negative dimension case
3164 Store_String_Chars
("**");
3165 Store_String_Char
('(');
3166 Store_String_Char
('-');
3167 Store_String_Int
(Int
(-Dim_Power
.Numerator
));
3171 if Dim_Power
.Denominator
= 1 then
3172 Store_String_Char
(')');
3174 -- Rational case when denominator /= 1
3177 Store_String_Char
('/');
3178 Store_String_Int
(Int
(Dim_Power
.Denominator
));
3179 Store_String_Char
(')');
3186 end From_Dim_To_Str_Of_Unit_Symbols
;
3192 function GCD
(Left
, Right
: Whole
) return Int
is
3212 --------------------------
3213 -- Has_Dimension_System --
3214 --------------------------
3216 function Has_Dimension_System
(Typ
: Entity_Id
) return Boolean is
3218 return Exists
(System_Of
(Typ
));
3219 end Has_Dimension_System
;
3221 ------------------------------
3222 -- Is_Dim_IO_Package_Entity --
3223 ------------------------------
3225 function Is_Dim_IO_Package_Entity
(E
: Entity_Id
) return Boolean is
3227 -- Check the package entity corresponds to System.Dim.Float_IO or
3228 -- System.Dim.Integer_IO.
3231 Is_RTU
(E
, System_Dim_Float_IO
)
3233 Is_RTU
(E
, System_Dim_Integer_IO
);
3234 end Is_Dim_IO_Package_Entity
;
3236 -------------------------------------
3237 -- Is_Dim_IO_Package_Instantiation --
3238 -------------------------------------
3240 function Is_Dim_IO_Package_Instantiation
(N
: Node_Id
) return Boolean is
3241 Gen_Id
: constant Node_Id
:= Name
(N
);
3244 -- Check that the instantiated package is either System.Dim.Float_IO
3245 -- or System.Dim.Integer_IO.
3248 Is_Entity_Name
(Gen_Id
)
3249 and then Is_Dim_IO_Package_Entity
(Entity
(Gen_Id
));
3250 end Is_Dim_IO_Package_Instantiation
;
3256 function Is_Invalid
(Position
: Dimension_Position
) return Boolean is
3258 return Position
= Invalid_Position
;
3261 ---------------------
3262 -- Move_Dimensions --
3263 ---------------------
3265 procedure Move_Dimensions
(From
, To
: Node_Id
) is
3267 if Ada_Version
< Ada_2012
then
3271 -- Copy the dimension of 'From to 'To' and remove dimension of 'From'
3273 Copy_Dimensions
(From
, To
);
3274 Remove_Dimensions
(From
);
3275 end Move_Dimensions
;
3281 function Reduce
(X
: Rational
) return Rational
is
3283 if X
.Numerator
= 0 then
3288 G
: constant Int
:= GCD
(X
.Numerator
, X
.Denominator
);
3290 return Rational
'(Numerator => Whole (Int (X.Numerator) / G),
3291 Denominator => Whole (Int (X.Denominator) / G));
3295 -----------------------
3296 -- Remove_Dimensions --
3297 -----------------------
3299 procedure Remove_Dimensions (N : Node_Id) is
3300 Dims_Of_N : constant Dimension_Type := Dimensions_Of (N);
3302 if Exists (Dims_Of_N) then
3303 Dimension_Table.Remove (N);
3305 end Remove_Dimensions;
3307 -----------------------------------
3308 -- Remove_Dimension_In_Statement --
3309 -----------------------------------
3311 -- Removal of dimension in statement as part of the Analyze_Statements
3312 -- routine (see package Sem_Ch5).
3314 procedure Remove_Dimension_In_Statement (Stmt : Node_Id) is
3316 if Ada_Version < Ada_2012 then
3320 -- Remove dimension in parameter specifications for accept statement
3322 if Nkind (Stmt) = N_Accept_Statement then
3324 Param : Node_Id := First (Parameter_Specifications (Stmt));
3326 while Present (Param) loop
3327 Remove_Dimensions (Param);
3332 -- Remove dimension of name and expression in assignments
3334 elsif Nkind (Stmt) = N_Assignment_Statement then
3335 Remove_Dimensions (Expression (Stmt));
3336 Remove_Dimensions (Name (Stmt));
3338 end Remove_Dimension_In_Statement;
3340 --------------------
3341 -- Set_Dimensions --
3342 --------------------
3344 procedure Set_Dimensions (N : Node_Id; Val : Dimension_Type) is
3346 pragma Assert (OK_For_Dimension (Nkind (N)));
3347 pragma Assert (Exists (Val));
3349 Dimension_Table.Set (N, Val);
3356 procedure Set_Symbol (E : Entity_Id; Val : String_Id) is
3358 Symbol_Table.Set (E, Val);
3361 ---------------------------------
3362 -- String_From_Numeric_Literal --
3363 ---------------------------------
3365 function String_From_Numeric_Literal (N : Node_Id) return String_Id is
3366 Loc : constant Source_Ptr := Sloc (N);
3367 Sbuffer : constant Source_Buffer_Ptr :=
3368 Source_Text (Get_Source_File_Index (Loc));
3369 Src_Ptr : Source_Ptr := Loc;
3371 C : Character := Sbuffer (Src_Ptr);
3372 -- Current source program character
3374 function Belong_To_Numeric_Literal (C : Character) return Boolean;
3375 -- Return True if C belongs to a numeric literal
3377 -------------------------------
3378 -- Belong_To_Numeric_Literal --
3379 -------------------------------
3381 function Belong_To_Numeric_Literal (C : Character) return Boolean is
3397 -- Make sure '+' or '-' is part of an exponent.
3401 Prev_C : constant Character := Sbuffer (Src_Ptr - 1);
3403 return Prev_C = 'e
' or else Prev_C = 'E
';
3406 -- All other character doesn't belong to a numeric literal
3411 end Belong_To_Numeric_Literal;
3413 -- Start of processing for String_From_Numeric_Literal
3417 while Belong_To_Numeric_Literal (C) loop
3418 Store_String_Char (C);
3419 Src_Ptr := Src_Ptr + 1;
3420 C := Sbuffer (Src_Ptr);
3424 end String_From_Numeric_Literal;
3430 function Symbol_Of (E : Entity_Id) return String_Id is
3431 Subtype_Symbol : constant String_Id := Symbol_Table.Get (E);
3433 if Subtype_Symbol /= No_String then
3434 return Subtype_Symbol;
3436 return From_Dim_To_Str_Of_Unit_Symbols
3437 (Dimensions_Of (E), System_Of (Base_Type (E)));
3441 -----------------------
3442 -- Symbol_Table_Hash --
3443 -----------------------
3445 function Symbol_Table_Hash (Key : Entity_Id) return Symbol_Table_Range is
3447 return Symbol_Table_Range (Key mod 511);
3448 end Symbol_Table_Hash;
3454 function System_Of (E : Entity_Id) return System_Type is
3455 Type_Decl : constant Node_Id := Parent (E);
3458 -- Look for Type_Decl in System_Table
3460 for Dim_Sys in 1 .. System_Table.Last loop
3461 if Type_Decl = System_Table.Table (Dim_Sys).Type_Decl then
3462 return System_Table.Table (Dim_Sys);