1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2011-2013, 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 -- A data structure used to 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 -- A data structure used to 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 "[]", or
295 -- "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 the
299 -- compilateur 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 character asterisk * which must be precede 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,
372 function "+" (Left, Right : Rational) return Rational is
373 R : constant Rational :=
374 Rational'(Numerator
=> Left
.Numerator
* Right
.Denominator
+
375 Left
.Denominator
* Right
.Numerator
,
376 Denominator
=> Left
.Denominator
* Right
.Denominator
);
385 function "-" (Right
: Rational
) return Rational
is
387 return Rational
'(Numerator => -Right.Numerator,
388 Denominator => Right.Denominator);
391 function "-" (Left, Right : Rational) return Rational is
392 R : constant Rational :=
393 Rational'(Numerator
=> Left
.Numerator
* Right
.Denominator
-
394 Left
.Denominator
* Right
.Numerator
,
395 Denominator
=> Left
.Denominator
* Right
.Denominator
);
405 function "*" (Left
, Right
: Rational
) return Rational
is
406 R
: constant Rational
:=
407 Rational
'(Numerator => Left.Numerator * Right.Numerator,
408 Denominator => Left.Denominator * Right.Denominator);
417 function "/" (Left, Right : Rational) return Rational is
418 R : constant Rational := abs Right;
419 L : Rational := Left;
422 if Right.Numerator < 0 then
423 L.Numerator := Whole (-Integer (L.Numerator));
426 return Reduce (Rational'(Numerator
=> L
.Numerator
* R
.Denominator
,
427 Denominator
=> L
.Denominator
* R
.Numerator
));
434 function "abs" (Right
: Rational
) return Rational
is
436 return Rational
'(Numerator => abs Right.Numerator,
437 Denominator => Right.Denominator);
440 ------------------------------
441 -- Analyze_Aspect_Dimension --
442 ------------------------------
445 -- ([Symbol =>] SYMBOL, DIMENSION_VALUE {, DIMENSION_Value})
447 -- SYMBOL ::= STRING_LITERAL | CHARACTER_LITERAL
449 -- DIMENSION_VALUE ::=
451 -- | others => RATIONAL
452 -- | DISCRETE_CHOICE_LIST => RATIONAL
454 -- RATIONAL ::= [-] NUMERIC_LITERAL [/ NUMERIC_LITERAL]
456 -- Note that when the dimensioned type is an integer type, then any
457 -- dimension value must be an integer literal.
459 procedure Analyze_Aspect_Dimension
464 Def_Id : constant Entity_Id := Defining_Identifier (N);
466 Processed : array (Dimension_Type'Range) of Boolean := (others => False);
467 -- This array is used when processing ranges or Others_Choice as part of
468 -- the dimension aggregate.
470 Dimensions : Dimension_Type := Null_Dimension;
472 procedure Extract_Power
474 Position : Dimension_Position);
475 -- Given an expression with denotes a rational number, read the number
476 -- and associate it with Position in Dimensions.
478 function Position_In_System
480 System : System_Type) return Dimension_Position;
481 -- Given an identifier which denotes a dimension, return the position of
482 -- that dimension within System.
488 procedure Extract_Power
490 Position : Dimension_Position)
495 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;
647 Error_Msg_N ("optional component Symbol expected, found&",
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 erroneous 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
935 ("too many dimensions in system", Aggr);
939 if Nkind (Dim_Aggr) /= N_Aggregate then
940 Error_Msg_N ("aggregate expected", Dim_Aggr);
943 if Present (Component_Associations (Dim_Aggr))
944 and then Present (Expressions (Dim_Aggr))
947 ("mixed positional/named aggregate not allowed here",
950 -- Verify each dimension aggregate has three arguments
952 elsif List_Length (Component_Associations (Dim_Aggr)) /= 3
953 and then List_Length (Expressions (Dim_Aggr)) /= 3
956 ("three components expected in aggregate", Dim_Aggr);
959 -- Named dimension aggregate
961 if Present (Component_Associations (Dim_Aggr)) then
963 -- Check first argument denotes the unit name
965 Assoc := First (Component_Associations (Dim_Aggr));
966 Choice := First (Choices (Assoc));
967 Unit_Name := Expression (Assoc);
969 if Present (Next (Choice))
970 or else Nkind (Choice) /= N_Identifier
972 Error_Msg_NE ("wrong syntax for aspect&", Choice, Id);
974 elsif Chars (Choice) /= Name_Unit_Name then
975 Error_Msg_N ("expected Unit_Name, found&", Choice);
978 -- Check the second argument denotes the unit symbol
981 Choice := First (Choices (Assoc));
982 Unit_Symbol := Expression (Assoc);
984 if Present (Next (Choice))
985 or else Nkind (Choice) /= N_Identifier
987 Error_Msg_NE ("wrong syntax for aspect&", Choice, Id);
989 elsif Chars (Choice) /= Name_Unit_Symbol then
990 Error_Msg_N ("expected Unit_Symbol, found&", Choice);
993 -- Check the third argument denotes the dimension symbol
996 Choice := First (Choices (Assoc));
997 Dim_Symbol := Expression (Assoc);
999 if Present (Next (Choice))
1000 or else Nkind (Choice) /= N_Identifier
1002 Error_Msg_NE ("wrong syntax for aspect&", Choice, Id);
1004 elsif Chars (Choice) /= Name_Dim_Symbol then
1005 Error_Msg_N ("expected Dim_Symbol, found&", Choice);
1008 -- Positional dimension aggregate
1011 Unit_Name := First (Expressions (Dim_Aggr));
1012 Unit_Symbol := Next (Unit_Name);
1013 Dim_Symbol := Next (Unit_Symbol);
1016 -- Check the first argument for each dimension aggregate is
1019 if Nkind (Unit_Name) = N_Identifier then
1020 Unit_Names (Position) := Chars (Unit_Name);
1022 Error_Msg_N ("expected unit name", Unit_Name);
1025 -- Check the second argument for each dimension aggregate is
1026 -- a string or a character.
1028 if not Nkind_In (Unit_Symbol, N_String_Literal,
1029 N_Character_Literal)
1032 ("expected unit symbol (string or character)",
1038 if Nkind (Unit_Symbol) = N_String_Literal then
1039 Unit_Symbols (Position) := Strval (Unit_Symbol);
1046 (UI_To_CC (Char_Literal_Value (Unit_Symbol)));
1047 Unit_Symbols (Position) := End_String;
1050 -- Verify that the string is not empty
1052 if String_Length (Unit_Symbols (Position)) = 0 then
1054 ("empty string not allowed here", Unit_Symbol);
1058 -- Check the third argument for each dimension aggregate is
1059 -- a string or a character.
1061 if not Nkind_In (Dim_Symbol, N_String_Literal,
1062 N_Character_Literal)
1065 ("expected dimension symbol (string or character)",
1071 if Nkind (Dim_Symbol) = N_String_Literal then
1072 Dim_Symbols (Position) := Strval (Dim_Symbol);
1079 (UI_To_CC (Char_Literal_Value (Dim_Symbol)));
1080 Dim_Symbols (Position) := End_String;
1083 -- Verify that the string is not empty
1085 if String_Length (Dim_Symbols (Position)) = 0 then
1087 ("empty string not allowed here", Dim_Symbol);
1096 -- STEP 4: Storage of extracted values
1098 -- Check that no errors have been detected during the analysis
1100 if Errors_Count = Serious_Errors_Detected then
1101 Dim_System.Type_Decl := N;
1102 Dim_System.Unit_Names := Unit_Names;
1103 Dim_System.Unit_Symbols := Unit_Symbols;
1104 Dim_System.Dim_Symbols := Dim_Symbols;
1105 Dim_System.Count := Position;
1106 System_Table.Append (Dim_System);
1108 end Analyze_Aspect_Dimension_System;
1110 -----------------------
1111 -- Analyze_Dimension --
1112 -----------------------
1114 -- This dispatch routine propagates dimensions for each node
1116 procedure Analyze_Dimension (N : Node_Id) is
1118 -- Aspect is an Ada 2012 feature. Note that there is no need to check
1119 -- dimensions for nodes that don't come from source.
1121 if Ada_Version < Ada_2012 or else not Comes_From_Source (N) then
1126 when N_Assignment_Statement =>
1127 Analyze_Dimension_Assignment_Statement (N);
1130 Analyze_Dimension_Binary_Op (N);
1132 when N_Component_Declaration =>
1133 Analyze_Dimension_Component_Declaration (N);
1135 when N_Extended_Return_Statement =>
1136 Analyze_Dimension_Extended_Return_Statement (N);
1138 when N_Attribute_Reference |
1142 N_Indexed_Component |
1143 N_Qualified_Expression |
1144 N_Selected_Component |
1147 N_Unchecked_Type_Conversion =>
1148 Analyze_Dimension_Has_Etype (N);
1150 when N_Object_Declaration =>
1151 Analyze_Dimension_Object_Declaration (N);
1153 when N_Object_Renaming_Declaration =>
1154 Analyze_Dimension_Object_Renaming_Declaration (N);
1156 when N_Simple_Return_Statement =>
1157 if not Comes_From_Extended_Return_Statement (N) then
1158 Analyze_Dimension_Simple_Return_Statement (N);
1161 when N_Subtype_Declaration =>
1162 Analyze_Dimension_Subtype_Declaration (N);
1165 Analyze_Dimension_Unary_Op (N);
1167 when others => null;
1170 end Analyze_Dimension;
1172 ---------------------------------------
1173 -- Analyze_Dimension_Array_Aggregate --
1174 ---------------------------------------
1176 procedure Analyze_Dimension_Array_Aggregate
1178 Comp_Typ : Entity_Id)
1180 Comp_Ass : constant List_Id := Component_Associations (N);
1181 Dims_Of_Comp_Typ : constant Dimension_Type := Dimensions_Of (Comp_Typ);
1182 Exps : constant List_Id := Expressions (N);
1187 Error_Detected : Boolean := False;
1188 -- This flag is used in order to indicate if an error has been detected
1189 -- so far by the compiler in this routine.
1192 -- Aspect is an Ada 2012 feature. Nothing to do here if the component
1193 -- base type is not a dimensioned type.
1195 -- Note that here the original node must come from source since the
1196 -- original array aggregate may not have been entirely decorated.
1198 if Ada_Version < Ada_2012
1199 or else not Comes_From_Source (Original_Node (N))
1200 or else not Has_Dimension_System (Base_Type (Comp_Typ))
1205 -- Check whether there is any positional component association
1207 if Is_Empty_List (Exps) then
1208 Comp := First (Comp_Ass);
1210 Comp := First (Exps);
1213 while Present (Comp) loop
1215 -- Get the expression from the component
1217 if Nkind (Comp) = N_Component_Association then
1218 Expr := Expression (Comp);
1223 -- Issue an error if the dimensions of the component type and the
1224 -- dimensions of the component mismatch.
1226 -- Note that we must ensure the expression has been fully analyzed
1227 -- since it may not be decorated at this point. We also don't want to
1228 -- issue the same error message multiple times on the same expression
1229 -- (may happen when an aggregate is converted into a positional
1232 if Comes_From_Source (Original_Node (Expr))
1233 and then Present (Etype (Expr))
1234 and then Dimensions_Of (Expr) /= Dims_Of_Comp_Typ
1235 and then Sloc (Comp) /= Sloc (Prev (Comp))
1237 -- Check if an error has already been encountered so far
1239 if not Error_Detected then
1240 Error_Msg_N ("dimensions mismatch in array aggregate", N);
1241 Error_Detected := True;
1245 ("\expected dimension "
1246 & Dimensions_Msg_Of (Comp_Typ)
1248 & Dimensions_Msg_Of (Expr),
1252 -- Look at the named components right after the positional components
1254 if not Present (Next (Comp))
1255 and then List_Containing (Comp) = Exps
1257 Comp := First (Comp_Ass);
1262 end Analyze_Dimension_Array_Aggregate;
1264 --------------------------------------------
1265 -- Analyze_Dimension_Assignment_Statement --
1266 --------------------------------------------
1268 procedure Analyze_Dimension_Assignment_Statement (N : Node_Id) is
1269 Lhs : constant Node_Id := Name (N);
1270 Dims_Of_Lhs : constant Dimension_Type := Dimensions_Of (Lhs);
1271 Rhs : constant Node_Id := Expression (N);
1272 Dims_Of_Rhs : constant Dimension_Type := Dimensions_Of (Rhs);
1274 procedure Error_Dim_Msg_For_Assignment_Statement
1278 -- Error using Error_Msg_N at node N. Output the dimensions of left
1279 -- and right hand sides.
1281 --------------------------------------------
1282 -- Error_Dim_Msg_For_Assignment_Statement --
1283 --------------------------------------------
1285 procedure Error_Dim_Msg_For_Assignment_Statement
1291 Error_Msg_N ("dimensions mismatch in assignment", N);
1292 Error_Msg_N ("\left-hand side " & Dimensions_Msg_Of (Lhs, True), N);
1293 Error_Msg_N ("\right-hand side " & Dimensions_Msg_Of (Rhs, True), N);
1294 end Error_Dim_Msg_For_Assignment_Statement;
1296 -- Start of processing for Analyze_Dimension_Assignment
1299 if Dims_Of_Lhs /= Dims_Of_Rhs then
1300 Error_Dim_Msg_For_Assignment_Statement (N, Lhs, Rhs);
1302 end Analyze_Dimension_Assignment_Statement;
1304 ---------------------------------
1305 -- Analyze_Dimension_Binary_Op --
1306 ---------------------------------
1308 -- Check and propagate the dimensions for binary operators
1309 -- Note that when the dimensions mismatch, no dimension is propagated to N.
1311 procedure Analyze_Dimension_Binary_Op (N : Node_Id) is
1312 N_Kind : constant Node_Kind := Nkind (N);
1314 procedure Error_Dim_Msg_For_Binary_Op (N, L, R : Node_Id);
1315 -- Error using Error_Msg_NE and Error_Msg_N at node N. Output the
1316 -- dimensions of both operands.
1318 ---------------------------------
1319 -- Error_Dim_Msg_For_Binary_Op --
1320 ---------------------------------
1322 procedure Error_Dim_Msg_For_Binary_Op (N, L, R : Node_Id) is
1324 Error_Msg_NE ("both operands for operation& must have same " &
1328 Error_Msg_N ("\left operand " & Dimensions_Msg_Of (L, True), N);
1329 Error_Msg_N ("\right operand " & Dimensions_Msg_Of (R, True), N);
1330 end Error_Dim_Msg_For_Binary_Op;
1332 -- Start of processing for Analyze_Dimension_Binary_Op
1335 if Nkind_In (N_Kind, N_Op_Add, N_Op_Expon, N_Op_Subtract)
1336 or else N_Kind in N_Multiplying_Operator
1337 or else N_Kind in N_Op_Compare
1340 L : constant Node_Id := Left_Opnd (N);
1341 Dims_Of_L : constant Dimension_Type := Dimensions_Of (L);
1342 L_Has_Dimensions : constant Boolean := Exists (Dims_Of_L);
1343 R : constant Node_Id := Right_Opnd (N);
1344 Dims_Of_R : constant Dimension_Type := Dimensions_Of (R);
1345 R_Has_Dimensions : constant Boolean := Exists (Dims_Of_R);
1346 Dims_Of_N : Dimension_Type := Null_Dimension;
1349 -- N_Op_Add, N_Op_Mod, N_Op_Rem or N_Op_Subtract case
1351 if Nkind_In (N, N_Op_Add, N_Op_Mod, N_Op_Rem, N_Op_Subtract) then
1353 -- Check both operands have same dimension
1355 if Dims_Of_L /= Dims_Of_R then
1356 Error_Dim_Msg_For_Binary_Op (N, L, R);
1358 -- Check both operands are not dimensionless
1360 if Exists (Dims_Of_L) then
1361 Set_Dimensions (N, Dims_Of_L);
1365 -- N_Op_Multiply or N_Op_Divide case
1367 elsif Nkind_In (N_Kind, N_Op_Multiply, N_Op_Divide) then
1369 -- Check at least one operand is not dimensionless
1371 if L_Has_Dimensions or R_Has_Dimensions then
1373 -- Multiplication case
1375 -- Get both operands dimensions and add them
1377 if N_Kind = N_Op_Multiply then
1378 for Position in Dimension_Type'Range loop
1379 Dims_Of_N (Position) :=
1380 Dims_Of_L (Position) + Dims_Of_R (Position);
1385 -- Get both operands dimensions and subtract them
1388 for Position in Dimension_Type'Range loop
1389 Dims_Of_N (Position) :=
1390 Dims_Of_L (Position) - Dims_Of_R (Position);
1394 if Exists (Dims_Of_N) then
1395 Set_Dimensions (N, Dims_Of_N);
1399 -- Exponentiation case
1401 -- Note: a rational exponent is allowed for dimensioned operand
1403 elsif N_Kind = N_Op_Expon then
1405 -- Check the left operand is not dimensionless. Note that the
1406 -- value of the exponent must be known compile time. Otherwise,
1407 -- the exponentiation evaluation will return an error message.
1409 if L_Has_Dimensions then
1410 if not Compile_Time_Known_Value (R) then
1411 Error_Msg_N ("exponent of dimensioned operand must be " &
1412 "known at compile time", N);
1416 Exponent_Value : Rational := Zero;
1419 -- Real operand case
1421 if Is_Real_Type (Etype (L)) then
1423 -- Define the exponent as a Rational number
1425 Exponent_Value := Create_Rational_From (R, False);
1427 -- Verify that the exponent cannot be interpreted
1428 -- as a rational, otherwise interpret the exponent
1431 if Exponent_Value = No_Rational then
1433 +Whole (UI_To_Int (Expr_Value (R)));
1436 -- Integer operand case.
1438 -- For integer operand, the exponent cannot be
1439 -- interpreted as a rational.
1442 Exponent_Value := +Whole (UI_To_Int (Expr_Value (R)));
1445 for Position in Dimension_Type'Range loop
1446 Dims_Of_N (Position) :=
1447 Dims_Of_L (Position) * Exponent_Value;
1450 if Exists (Dims_Of_N) then
1451 Set_Dimensions (N, Dims_Of_N);
1458 -- For relational operations, only dimension checking is
1459 -- performed (no propagation).
1461 elsif N_Kind in N_Op_Compare then
1462 if (L_Has_Dimensions or R_Has_Dimensions)
1463 and then Dims_Of_L /= Dims_Of_R
1465 Error_Dim_Msg_For_Binary_Op (N, L, R);
1469 -- Removal of dimensions for each operands
1471 Remove_Dimensions (L);
1472 Remove_Dimensions (R);
1475 end Analyze_Dimension_Binary_Op;
1477 ----------------------------
1478 -- Analyze_Dimension_Call --
1479 ----------------------------
1481 procedure Analyze_Dimension_Call (N : Node_Id; Nam : Entity_Id) is
1482 Actuals : constant List_Id := Parameter_Associations (N);
1484 Dims_Of_Formal : Dimension_Type;
1486 Formal_Typ : Entity_Id;
1488 Error_Detected : Boolean := False;
1489 -- This flag is used in order to indicate if an error has been detected
1490 -- so far by the compiler in this routine.
1493 -- Aspect is an Ada 2012 feature. Note that there is no need to check
1494 -- dimensions for calls that don't come from source, or those that may
1495 -- have semantic errors.
1497 if Ada_Version < Ada_2012
1498 or else not Comes_From_Source (N)
1499 or else Error_Posted (N)
1504 -- Check the dimensions of the actuals, if any
1506 if not Is_Empty_List (Actuals) then
1508 -- Special processing for elementary functions
1510 -- For Sqrt call, the resulting dimensions equal to half the
1511 -- dimensions of the actual. For all other elementary calls, this
1512 -- routine check that every actual is dimensionless.
1514 if Nkind (N) = N_Function_Call then
1515 Elementary_Function_Calls : declare
1516 Dims_Of_Call : Dimension_Type;
1517 Ent : Entity_Id := Nam;
1519 function Is_Elementary_Function_Entity
1520 (Sub_Id : Entity_Id) return Boolean;
1521 -- Given Sub_Id, the original subprogram entity, return True
1522 -- if call is to an elementary function (see Ada.Numerics.
1523 -- Generic_Elementary_Functions).
1525 -----------------------------------
1526 -- Is_Elementary_Function_Entity --
1527 -----------------------------------
1529 function Is_Elementary_Function_Entity
1530 (Sub_Id : Entity_Id) return Boolean
1532 Loc : constant Source_Ptr := Sloc (Sub_Id);
1535 -- Is entity in Ada.Numerics.Generic_Elementary_Functions?
1541 (Cunit_Entity (Get_Source_Unit (Loc)),
1542 Ada_Numerics_Generic_Elementary_Functions);
1543 end Is_Elementary_Function_Entity;
1545 -- Start of processing for Elementary_Function_Calls
1548 -- Get original subprogram entity following the renaming chain
1550 if Present (Alias (Ent)) then
1554 -- Check the call is an Elementary function call
1556 if Is_Elementary_Function_Entity (Ent) then
1558 -- Sqrt function call case
1560 if Chars (Ent) = Name_Sqrt then
1561 Dims_Of_Call := Dimensions_Of (First_Actual (N));
1563 -- Evaluates the resulting dimensions (i.e. half the
1564 -- dimensions of the actual).
1566 if Exists (Dims_Of_Call) then
1567 for Position in Dims_Of_Call'Range loop
1568 Dims_Of_Call (Position) :=
1569 Dims_Of_Call (Position) *
1570 Rational'(Numerator
=> 1, Denominator
=> 2);
1573 Set_Dimensions
(N
, Dims_Of_Call
);
1576 -- All other elementary functions case. Note that every
1577 -- actual here should be dimensionless.
1580 Actual
:= First_Actual
(N
);
1581 while Present
(Actual
) loop
1582 if Exists
(Dimensions_Of
(Actual
)) then
1584 -- Check if error has already been encountered
1586 if not Error_Detected
then
1587 Error_Msg_NE
("dimensions mismatch in call of&",
1589 Error_Detected
:= True;
1592 Error_Msg_N
("\expected dimension [], found " &
1593 Dimensions_Msg_Of
(Actual
),
1597 Next_Actual
(Actual
);
1601 -- Nothing more to do for elementary functions
1605 end Elementary_Function_Calls
;
1608 -- General case. Check, for each parameter, the dimensions of the
1609 -- actual and its corresponding formal match. Otherwise, complain.
1611 Actual
:= First_Actual
(N
);
1612 Formal
:= First_Formal
(Nam
);
1614 while Present
(Formal
) loop
1616 -- A missing corresponding actual indicates that the analysis of
1617 -- the call was aborted due to a previous error.
1620 Check_Error_Detected
;
1624 Formal_Typ
:= Etype
(Formal
);
1625 Dims_Of_Formal
:= Dimensions_Of
(Formal_Typ
);
1627 -- If the formal is not dimensionless, check dimensions of formal
1628 -- and actual match. Otherwise, complain.
1630 if Exists
(Dims_Of_Formal
)
1631 and then Dimensions_Of
(Actual
) /= Dims_Of_Formal
1633 -- Check if an error has already been encountered so far
1635 if not Error_Detected
then
1636 Error_Msg_NE
("dimensions mismatch in& call", N
, Name
(N
));
1637 Error_Detected
:= True;
1641 ("\expected dimension " & Dimensions_Msg_Of
(Formal_Typ
)
1642 & ", found " & Dimensions_Msg_Of
(Actual
), Actual
);
1645 Next_Actual
(Actual
);
1646 Next_Formal
(Formal
);
1650 -- For function calls, propagate the dimensions from the returned type
1652 if Nkind
(N
) = N_Function_Call
then
1653 Analyze_Dimension_Has_Etype
(N
);
1655 end Analyze_Dimension_Call
;
1657 ---------------------------------------------
1658 -- Analyze_Dimension_Component_Declaration --
1659 ---------------------------------------------
1661 procedure Analyze_Dimension_Component_Declaration
(N
: Node_Id
) is
1662 Expr
: constant Node_Id
:= Expression
(N
);
1663 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1664 Etyp
: constant Entity_Id
:= Etype
(Id
);
1665 Dims_Of_Etyp
: constant Dimension_Type
:= Dimensions_Of
(Etyp
);
1666 Dims_Of_Expr
: Dimension_Type
;
1668 procedure Error_Dim_Msg_For_Component_Declaration
1672 -- Error using Error_Msg_N at node N. Output the dimensions of the
1673 -- type Etyp and the expression Expr of N.
1675 ---------------------------------------------
1676 -- Error_Dim_Msg_For_Component_Declaration --
1677 ---------------------------------------------
1679 procedure Error_Dim_Msg_For_Component_Declaration
1684 Error_Msg_N
("dimensions mismatch in component declaration", N
);
1685 Error_Msg_N
("\expected dimension "
1686 & Dimensions_Msg_Of
(Etyp
)
1688 & Dimensions_Msg_Of
(Expr
),
1690 end Error_Dim_Msg_For_Component_Declaration
;
1692 -- Start of processing for Analyze_Dimension_Component_Declaration
1695 -- Expression is present
1697 if Present
(Expr
) then
1698 Dims_Of_Expr
:= Dimensions_Of
(Expr
);
1700 -- Check dimensions match
1702 if Dims_Of_Etyp
/= Dims_Of_Expr
then
1703 -- Numeric literal case. Issue a warning if the object type is not
1704 -- dimensionless to indicate the literal is treated as if its
1705 -- dimension matches the type dimension.
1707 if Nkind_In
(Original_Node
(Expr
), N_Real_Literal
,
1710 Dim_Warning_For_Numeric_Literal
(Expr
, Etyp
);
1712 -- Issue a dimension mismatch error for all other cases
1715 Error_Dim_Msg_For_Component_Declaration
(N
, Etyp
, Expr
);
1719 end Analyze_Dimension_Component_Declaration
;
1721 -------------------------------------------------
1722 -- Analyze_Dimension_Extended_Return_Statement --
1723 -------------------------------------------------
1725 procedure Analyze_Dimension_Extended_Return_Statement
(N
: Node_Id
) is
1726 Return_Ent
: constant Entity_Id
:= Return_Statement_Entity
(N
);
1727 Return_Etyp
: constant Entity_Id
:=
1728 Etype
(Return_Applies_To
(Return_Ent
));
1729 Return_Obj_Decls
: constant List_Id
:= Return_Object_Declarations
(N
);
1730 Return_Obj_Decl
: Node_Id
;
1731 Return_Obj_Id
: Entity_Id
;
1732 Return_Obj_Typ
: Entity_Id
;
1734 procedure Error_Dim_Msg_For_Extended_Return_Statement
1736 Return_Etyp
: Entity_Id
;
1737 Return_Obj_Typ
: Entity_Id
);
1738 -- Error using Error_Msg_N at node N. Output the dimensions of the
1739 -- returned type Return_Etyp and the returned object type Return_Obj_Typ
1742 -------------------------------------------------
1743 -- Error_Dim_Msg_For_Extended_Return_Statement --
1744 -------------------------------------------------
1746 procedure Error_Dim_Msg_For_Extended_Return_Statement
1748 Return_Etyp
: Entity_Id
;
1749 Return_Obj_Typ
: Entity_Id
)
1752 Error_Msg_N
("dimensions mismatch in extended return statement", N
);
1753 Error_Msg_N
("\expected dimension "
1754 & Dimensions_Msg_Of
(Return_Etyp
)
1756 & Dimensions_Msg_Of
(Return_Obj_Typ
),
1758 end Error_Dim_Msg_For_Extended_Return_Statement
;
1760 -- Start of processing for Analyze_Dimension_Extended_Return_Statement
1763 if Present
(Return_Obj_Decls
) then
1764 Return_Obj_Decl
:= First
(Return_Obj_Decls
);
1765 while Present
(Return_Obj_Decl
) loop
1766 if Nkind
(Return_Obj_Decl
) = N_Object_Declaration
then
1767 Return_Obj_Id
:= Defining_Identifier
(Return_Obj_Decl
);
1769 if Is_Return_Object
(Return_Obj_Id
) then
1770 Return_Obj_Typ
:= Etype
(Return_Obj_Id
);
1772 -- Issue an error message if dimensions mismatch
1774 if Dimensions_Of
(Return_Etyp
) /=
1775 Dimensions_Of
(Return_Obj_Typ
)
1777 Error_Dim_Msg_For_Extended_Return_Statement
1778 (N
, Return_Etyp
, Return_Obj_Typ
);
1784 Next
(Return_Obj_Decl
);
1787 end Analyze_Dimension_Extended_Return_Statement
;
1789 -----------------------------------------------------
1790 -- Analyze_Dimension_Extension_Or_Record_Aggregate --
1791 -----------------------------------------------------
1793 procedure Analyze_Dimension_Extension_Or_Record_Aggregate
(N
: Node_Id
) is
1795 Comp_Id
: Entity_Id
;
1796 Comp_Typ
: Entity_Id
;
1799 Error_Detected
: Boolean := False;
1800 -- This flag is used in order to indicate if an error has been detected
1801 -- so far by the compiler in this routine.
1804 -- Aspect is an Ada 2012 feature. Note that there is no need to check
1805 -- dimensions for aggregates that don't come from source.
1807 if Ada_Version
< Ada_2012
or else not Comes_From_Source
(N
) then
1811 Comp
:= First
(Component_Associations
(N
));
1812 while Present
(Comp
) loop
1813 Comp_Id
:= Entity
(First
(Choices
(Comp
)));
1814 Comp_Typ
:= Etype
(Comp_Id
);
1816 -- Check the component type is either a dimensioned type or a
1817 -- dimensioned subtype.
1819 if Has_Dimension_System
(Base_Type
(Comp_Typ
)) then
1820 Expr
:= Expression
(Comp
);
1822 -- Issue an error if the dimensions of the component type and the
1823 -- dimensions of the component mismatch.
1825 if Dimensions_Of
(Expr
) /= Dimensions_Of
(Comp_Typ
) then
1827 -- Check if an error has already been encountered so far
1829 if not Error_Detected
then
1831 -- Extension aggregate case
1833 if Nkind
(N
) = N_Extension_Aggregate
then
1835 ("dimensions mismatch in extension aggregate", N
);
1837 -- Record aggregate case
1841 ("dimensions mismatch in record aggregate", N
);
1844 Error_Detected
:= True;
1848 ("\expected dimension "
1849 & Dimensions_Msg_Of
(Comp_Typ
)
1851 & Dimensions_Msg_Of
(Expr
),
1858 end Analyze_Dimension_Extension_Or_Record_Aggregate
;
1860 -------------------------------
1861 -- Analyze_Dimension_Formals --
1862 -------------------------------
1864 procedure Analyze_Dimension_Formals
(N
: Node_Id
; Formals
: List_Id
) is
1865 Dims_Of_Typ
: Dimension_Type
;
1870 -- Aspect is an Ada 2012 feature. Note that there is no need to check
1871 -- dimensions for sub specs that don't come from source.
1873 if Ada_Version
< Ada_2012
or else not Comes_From_Source
(N
) then
1877 Formal
:= First
(Formals
);
1878 while Present
(Formal
) loop
1879 Typ
:= Parameter_Type
(Formal
);
1880 Dims_Of_Typ
:= Dimensions_Of
(Typ
);
1882 if Exists
(Dims_Of_Typ
) then
1884 Expr
: constant Node_Id
:= Expression
(Formal
);
1887 -- Issue a warning if Expr is a numeric literal and if its
1888 -- dimensions differ with the dimensions of the formal type.
1891 and then Dims_Of_Typ
/= Dimensions_Of
(Expr
)
1892 and then Nkind_In
(Original_Node
(Expr
), N_Real_Literal
,
1895 Dim_Warning_For_Numeric_Literal
(Expr
, Etype
(Typ
));
1902 end Analyze_Dimension_Formals
;
1904 ---------------------------------
1905 -- Analyze_Dimension_Has_Etype --
1906 ---------------------------------
1908 procedure Analyze_Dimension_Has_Etype
(N
: Node_Id
) is
1909 Etyp
: constant Entity_Id
:= Etype
(N
);
1910 Dims_Of_Etyp
: Dimension_Type
:= Dimensions_Of
(Etyp
);
1913 -- General case. Propagation of the dimensions from the type
1915 if Exists
(Dims_Of_Etyp
) then
1916 Set_Dimensions
(N
, Dims_Of_Etyp
);
1918 -- Identifier case. Propagate the dimensions from the entity for
1919 -- identifier whose entity is a non-dimensionless constant.
1921 elsif Nkind
(N
) = N_Identifier
then
1922 Analyze_Dimension_Identifier
: declare
1923 Id
: constant Entity_Id
:= Entity
(N
);
1925 if Ekind
(Id
) = E_Constant
1926 and then Exists
(Dimensions_Of
(Id
))
1928 Set_Dimensions
(N
, Dimensions_Of
(Id
));
1930 end Analyze_Dimension_Identifier
;
1932 -- Attribute reference case. Propagate the dimensions from the prefix.
1934 elsif Nkind
(N
) = N_Attribute_Reference
1935 and then Has_Dimension_System
(Base_Type
(Etyp
))
1937 Dims_Of_Etyp
:= Dimensions_Of
(Prefix
(N
));
1939 -- Check the prefix is not dimensionless
1941 if Exists
(Dims_Of_Etyp
) then
1942 Set_Dimensions
(N
, Dims_Of_Etyp
);
1946 -- Removal of dimensions in expression
1949 when N_Attribute_Reference |
1950 N_Indexed_Component
=>
1953 Exprs
: constant List_Id
:= Expressions
(N
);
1956 if Present
(Exprs
) then
1957 Expr
:= First
(Exprs
);
1958 while Present
(Expr
) loop
1959 Remove_Dimensions
(Expr
);
1965 when N_Qualified_Expression |
1967 N_Unchecked_Type_Conversion
=>
1968 Remove_Dimensions
(Expression
(N
));
1970 when N_Selected_Component
=>
1971 Remove_Dimensions
(Selector_Name
(N
));
1973 when others => null;
1975 end Analyze_Dimension_Has_Etype
;
1977 ------------------------------------------
1978 -- Analyze_Dimension_Object_Declaration --
1979 ------------------------------------------
1981 procedure Analyze_Dimension_Object_Declaration
(N
: Node_Id
) is
1982 Expr
: constant Node_Id
:= Expression
(N
);
1983 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
1984 Etyp
: constant Entity_Id
:= Etype
(Id
);
1985 Dim_Of_Etyp
: constant Dimension_Type
:= Dimensions_Of
(Etyp
);
1986 Dim_Of_Expr
: Dimension_Type
;
1988 procedure Error_Dim_Msg_For_Object_Declaration
1992 -- Error using Error_Msg_N at node N. Output the dimensions of the
1993 -- type Etyp and of the expression Expr.
1995 ------------------------------------------
1996 -- Error_Dim_Msg_For_Object_Declaration --
1997 ------------------------------------------
1999 procedure Error_Dim_Msg_For_Object_Declaration
2004 Error_Msg_N
("dimensions mismatch in object declaration", N
);
2006 ("\expected dimension "
2007 & Dimensions_Msg_Of
(Etyp
)
2009 & Dimensions_Msg_Of
(Expr
),
2011 end Error_Dim_Msg_For_Object_Declaration
;
2013 -- Start of processing for Analyze_Dimension_Object_Declaration
2016 -- Expression is present
2018 if Present
(Expr
) then
2019 Dim_Of_Expr
:= Dimensions_Of
(Expr
);
2021 -- Check dimensions match
2023 if Dim_Of_Expr
/= Dim_Of_Etyp
then
2025 -- Numeric literal case. Issue a warning if the object type is not
2026 -- dimensionless to indicate the literal is treated as if its
2027 -- dimension matches the type dimension.
2029 if Nkind_In
(Original_Node
(Expr
), N_Real_Literal
,
2032 Dim_Warning_For_Numeric_Literal
(Expr
, Etyp
);
2034 -- Case of object is a constant whose type is a dimensioned type
2036 elsif Constant_Present
(N
) and then not Exists
(Dim_Of_Etyp
) then
2038 -- Propagate dimension from expression to object entity
2040 Set_Dimensions
(Id
, Dim_Of_Expr
);
2042 -- For all other cases, issue an error message
2045 Error_Dim_Msg_For_Object_Declaration
(N
, Etyp
, Expr
);
2049 -- Removal of dimensions in expression
2051 Remove_Dimensions
(Expr
);
2053 end Analyze_Dimension_Object_Declaration
;
2055 ---------------------------------------------------
2056 -- Analyze_Dimension_Object_Renaming_Declaration --
2057 ---------------------------------------------------
2059 procedure Analyze_Dimension_Object_Renaming_Declaration
(N
: Node_Id
) is
2060 Renamed_Name
: constant Node_Id
:= Name
(N
);
2061 Sub_Mark
: constant Node_Id
:= Subtype_Mark
(N
);
2063 procedure Error_Dim_Msg_For_Object_Renaming_Declaration
2066 Renamed_Name
: Node_Id
);
2067 -- Error using Error_Msg_N at node N. Output the dimensions of
2068 -- Sub_Mark and of Renamed_Name.
2070 ---------------------------------------------------
2071 -- Error_Dim_Msg_For_Object_Renaming_Declaration --
2072 ---------------------------------------------------
2074 procedure Error_Dim_Msg_For_Object_Renaming_Declaration
2077 Renamed_Name
: Node_Id
) is
2079 Error_Msg_N
("dimensions mismatch in object renaming declaration", N
);
2081 ("\expected dimension "
2082 & Dimensions_Msg_Of
(Sub_Mark
)
2084 & Dimensions_Msg_Of
(Renamed_Name
),
2086 end Error_Dim_Msg_For_Object_Renaming_Declaration
;
2088 -- Start of processing for Analyze_Dimension_Object_Renaming_Declaration
2091 if Dimensions_Of
(Renamed_Name
) /= Dimensions_Of
(Sub_Mark
) then
2092 Error_Dim_Msg_For_Object_Renaming_Declaration
2093 (N
, Sub_Mark
, Renamed_Name
);
2095 end Analyze_Dimension_Object_Renaming_Declaration
;
2097 -----------------------------------------------
2098 -- Analyze_Dimension_Simple_Return_Statement --
2099 -----------------------------------------------
2101 procedure Analyze_Dimension_Simple_Return_Statement
(N
: Node_Id
) is
2102 Expr
: constant Node_Id
:= Expression
(N
);
2103 Dims_Of_Expr
: constant Dimension_Type
:= Dimensions_Of
(Expr
);
2104 Return_Ent
: constant Entity_Id
:= Return_Statement_Entity
(N
);
2105 Return_Etyp
: constant Entity_Id
:=
2106 Etype
(Return_Applies_To
(Return_Ent
));
2107 Dims_Of_Return_Etyp
: constant Dimension_Type
:=
2108 Dimensions_Of
(Return_Etyp
);
2110 procedure Error_Dim_Msg_For_Simple_Return_Statement
2112 Return_Etyp
: Entity_Id
;
2114 -- Error using Error_Msg_N at node N. Output the dimensions of the
2115 -- returned type Return_Etyp and the returned expression Expr of N.
2117 -----------------------------------------------
2118 -- Error_Dim_Msg_For_Simple_Return_Statement --
2119 -----------------------------------------------
2121 procedure Error_Dim_Msg_For_Simple_Return_Statement
2123 Return_Etyp
: Entity_Id
;
2127 Error_Msg_N
("dimensions mismatch in return statement", N
);
2129 ("\expected dimension "
2130 & Dimensions_Msg_Of
(Return_Etyp
)
2132 & Dimensions_Msg_Of
(Expr
),
2134 end Error_Dim_Msg_For_Simple_Return_Statement
;
2136 -- Start of processing for Analyze_Dimension_Simple_Return_Statement
2139 if Dims_Of_Return_Etyp
/= Dims_Of_Expr
then
2140 Error_Dim_Msg_For_Simple_Return_Statement
(N
, Return_Etyp
, Expr
);
2141 Remove_Dimensions
(Expr
);
2143 end Analyze_Dimension_Simple_Return_Statement
;
2145 -------------------------------------------
2146 -- Analyze_Dimension_Subtype_Declaration --
2147 -------------------------------------------
2149 procedure Analyze_Dimension_Subtype_Declaration
(N
: Node_Id
) is
2150 Id
: constant Entity_Id
:= Defining_Identifier
(N
);
2151 Dims_Of_Id
: constant Dimension_Type
:= Dimensions_Of
(Id
);
2152 Dims_Of_Etyp
: Dimension_Type
;
2156 -- No constraint case in subtype declaration
2158 if Nkind
(Subtype_Indication
(N
)) /= N_Subtype_Indication
then
2159 Etyp
:= Etype
(Subtype_Indication
(N
));
2160 Dims_Of_Etyp
:= Dimensions_Of
(Etyp
);
2162 if Exists
(Dims_Of_Etyp
) then
2164 -- If subtype already has a dimension (from Aspect_Dimension),
2165 -- it cannot inherit a dimension from its subtype.
2167 if Exists
(Dims_Of_Id
) then
2169 ("subtype& already" & Dimensions_Msg_Of
(Id
, True), N
);
2172 Set_Dimensions
(Id
, Dims_Of_Etyp
);
2173 Set_Symbol
(Id
, Symbol_Of
(Etyp
));
2177 -- Constraint present in subtype declaration
2180 Etyp
:= Etype
(Subtype_Mark
(Subtype_Indication
(N
)));
2181 Dims_Of_Etyp
:= Dimensions_Of
(Etyp
);
2183 if Exists
(Dims_Of_Etyp
) then
2184 Set_Dimensions
(Id
, Dims_Of_Etyp
);
2185 Set_Symbol
(Id
, Symbol_Of
(Etyp
));
2188 end Analyze_Dimension_Subtype_Declaration
;
2190 --------------------------------
2191 -- Analyze_Dimension_Unary_Op --
2192 --------------------------------
2194 procedure Analyze_Dimension_Unary_Op
(N
: Node_Id
) is
2197 when N_Op_Plus | N_Op_Minus | N_Op_Abs
=>
2199 R
: constant Node_Id
:= Right_Opnd
(N
);
2202 -- Propagate the dimension if the operand is not dimensionless
2204 Move_Dimensions
(R
, N
);
2207 when others => null;
2210 end Analyze_Dimension_Unary_Op
;
2212 ---------------------
2213 -- Copy_Dimensions --
2214 ---------------------
2216 procedure Copy_Dimensions
(From
, To
: Node_Id
) is
2217 Dims_Of_From
: constant Dimension_Type
:= Dimensions_Of
(From
);
2220 -- Ignore if not Ada 2012 or beyond
2222 if Ada_Version
< Ada_2012
then
2225 -- For Ada 2012, Copy the dimension of 'From to 'To'
2227 elsif Exists
(Dims_Of_From
) then
2228 Set_Dimensions
(To
, Dims_Of_From
);
2230 end Copy_Dimensions
;
2232 --------------------------
2233 -- Create_Rational_From --
2234 --------------------------
2236 -- RATIONAL ::= [-] NUMERAL [/ NUMERAL]
2238 -- A rational number is a number that can be expressed as the quotient or
2239 -- fraction a/b of two integers, where b is non-zero positive.
2241 function Create_Rational_From
2243 Complain
: Boolean) return Rational
2245 Or_Node_Of_Expr
: constant Node_Id
:= Original_Node
(Expr
);
2246 Result
: Rational
:= No_Rational
;
2248 function Process_Minus
(N
: Node_Id
) return Rational
;
2249 -- Create a rational from a N_Op_Minus node
2251 function Process_Divide
(N
: Node_Id
) return Rational
;
2252 -- Create a rational from a N_Op_Divide node
2254 function Process_Literal
(N
: Node_Id
) return Rational
;
2255 -- Create a rational from a N_Integer_Literal node
2261 function Process_Minus
(N
: Node_Id
) return Rational
is
2262 Right
: constant Node_Id
:= Original_Node
(Right_Opnd
(N
));
2266 -- Operand is an integer literal
2268 if Nkind
(Right
) = N_Integer_Literal
then
2269 Result
:= -Process_Literal
(Right
);
2271 -- Operand is a divide operator
2273 elsif Nkind
(Right
) = N_Op_Divide
then
2274 Result
:= -Process_Divide
(Right
);
2277 Result
:= No_Rational
;
2280 -- Provide minimal semantic information on dimension expressions,
2281 -- even though they have no run-time existence. This is for use by
2282 -- ASIS tools, in particular pretty-printing.
2284 Set_Entity
(N
, Standard_Op_Minus
);
2285 Set_Etype
(N
, Standard_Integer
);
2289 --------------------
2290 -- Process_Divide --
2291 --------------------
2293 function Process_Divide
(N
: Node_Id
) return Rational
is
2294 Left
: constant Node_Id
:= Original_Node
(Left_Opnd
(N
));
2295 Right
: constant Node_Id
:= Original_Node
(Right_Opnd
(N
));
2296 Left_Rat
: Rational
;
2297 Result
: Rational
:= No_Rational
;
2298 Right_Rat
: Rational
;
2301 -- Both left and right operands are an integer literal
2303 if Nkind
(Left
) = N_Integer_Literal
2304 and then Nkind
(Right
) = N_Integer_Literal
2306 Left_Rat
:= Process_Literal
(Left
);
2307 Right_Rat
:= Process_Literal
(Right
);
2308 Result
:= Left_Rat
/ Right_Rat
;
2311 -- Provide minimal semantic information on dimension expressions,
2312 -- even though they have no run-time existence. This is for use by
2313 -- ASIS tools, in particular pretty-printing.
2315 Set_Entity
(N
, Standard_Op_Divide
);
2316 Set_Etype
(N
, Standard_Integer
);
2320 ---------------------
2321 -- Process_Literal --
2322 ---------------------
2324 function Process_Literal
(N
: Node_Id
) return Rational
is
2326 return +Whole
(UI_To_Int
(Intval
(N
)));
2327 end Process_Literal
;
2329 -- Start of processing for Create_Rational_From
2332 -- Check the expression is either a division of two integers or an
2333 -- integer itself. Note that the check applies to the original node
2334 -- since the node could have already been rewritten.
2336 -- Integer literal case
2338 if Nkind
(Or_Node_Of_Expr
) = N_Integer_Literal
then
2339 Result
:= Process_Literal
(Or_Node_Of_Expr
);
2341 -- Divide operator case
2343 elsif Nkind
(Or_Node_Of_Expr
) = N_Op_Divide
then
2344 Result
:= Process_Divide
(Or_Node_Of_Expr
);
2346 -- Minus operator case
2348 elsif Nkind
(Or_Node_Of_Expr
) = N_Op_Minus
then
2349 Result
:= Process_Minus
(Or_Node_Of_Expr
);
2352 -- When Expr cannot be interpreted as a rational and Complain is true,
2353 -- generate an error message.
2355 if Complain
and then Result
= No_Rational
then
2356 Error_Msg_N
("rational expected", Expr
);
2360 end Create_Rational_From
;
2366 function Dimensions_Of
(N
: Node_Id
) return Dimension_Type
is
2368 return Dimension_Table
.Get
(N
);
2371 -----------------------
2372 -- Dimensions_Msg_Of --
2373 -----------------------
2375 function Dimensions_Msg_Of
2377 Description_Needed
: Boolean := False) return String
2379 Dims_Of_N
: constant Dimension_Type
:= Dimensions_Of
(N
);
2380 Dimensions_Msg
: Name_Id
;
2381 System
: System_Type
;
2384 -- Initialization of Name_Buffer
2388 -- N is not dimensionless
2390 if Exists
(Dims_Of_N
) then
2391 System
:= System_Of
(Base_Type
(Etype
(N
)));
2393 -- When Description_Needed, add to string "has dimension " before the
2394 -- actual dimension.
2396 if Description_Needed
then
2397 Add_Str_To_Name_Buffer
("has dimension ");
2400 Add_String_To_Name_Buffer
2401 (From_Dim_To_Str_Of_Dim_Symbols
(Dims_Of_N
, System
, True));
2403 -- N is dimensionless
2405 -- When Description_Needed, return "is dimensionless"
2407 elsif Description_Needed
then
2408 Add_Str_To_Name_Buffer
("is dimensionless");
2410 -- Otherwise, return "[]"
2413 Add_Str_To_Name_Buffer
("[]");
2416 Dimensions_Msg
:= Name_Find
;
2417 return Get_Name_String
(Dimensions_Msg
);
2418 end Dimensions_Msg_Of
;
2420 --------------------------
2421 -- Dimension_Table_Hash --
2422 --------------------------
2424 function Dimension_Table_Hash
2425 (Key
: Node_Id
) return Dimension_Table_Range
2428 return Dimension_Table_Range
(Key
mod 511);
2429 end Dimension_Table_Hash
;
2431 -------------------------------------
2432 -- Dim_Warning_For_Numeric_Literal --
2433 -------------------------------------
2435 procedure Dim_Warning_For_Numeric_Literal
(N
: Node_Id
; Typ
: Entity_Id
) is
2437 -- Initialize name buffer
2441 Add_String_To_Name_Buffer
(String_From_Numeric_Literal
(N
));
2443 -- Insert a blank between the literal and the symbol
2444 Add_Str_To_Name_Buffer
(" ");
2446 Add_String_To_Name_Buffer
(Symbol_Of
(Typ
));
2448 Error_Msg_Name_1
:= Name_Find
;
2449 Error_Msg_N
("??assumed to be%%", N
);
2450 end Dim_Warning_For_Numeric_Literal
;
2452 ----------------------------------------
2453 -- Eval_Op_Expon_For_Dimensioned_Type --
2454 ----------------------------------------
2456 -- Evaluate the expon operator for real dimensioned type.
2458 -- Note that if the exponent is an integer (denominator = 1) the node is
2459 -- evaluated by the regular Eval_Op_Expon routine (see Sem_Eval).
2461 procedure Eval_Op_Expon_For_Dimensioned_Type
2465 R
: constant Node_Id
:= Right_Opnd
(N
);
2466 R_Value
: Rational
:= No_Rational
;
2469 if Is_Real_Type
(Btyp
) then
2470 R_Value
:= Create_Rational_From
(R
, False);
2473 -- Check that the exponent is not an integer
2475 if R_Value
/= No_Rational
and then R_Value
.Denominator
/= 1 then
2476 Eval_Op_Expon_With_Rational_Exponent
(N
, R_Value
);
2480 end Eval_Op_Expon_For_Dimensioned_Type
;
2482 ------------------------------------------
2483 -- Eval_Op_Expon_With_Rational_Exponent --
2484 ------------------------------------------
2486 -- For dimensioned operand in exponentiation, exponent is allowed to be a
2487 -- Rational and not only an Integer like for dimensionless operands. For
2488 -- that particular case, the left operand is rewritten as a function call
2489 -- using the function Expon_LLF from s-llflex.ads.
2491 procedure Eval_Op_Expon_With_Rational_Exponent
2493 Exponent_Value
: Rational
)
2495 Dims_Of_N
: constant Dimension_Type
:= Dimensions_Of
(N
);
2496 L
: constant Node_Id
:= Left_Opnd
(N
);
2497 Etyp_Of_L
: constant Entity_Id
:= Etype
(L
);
2498 Btyp_Of_L
: constant Entity_Id
:= Base_Type
(Etyp_Of_L
);
2499 Loc
: constant Source_Ptr
:= Sloc
(N
);
2502 Dim_Power
: Rational
;
2503 List_Of_Dims
: List_Id
;
2504 New_Aspect
: Node_Id
;
2505 New_Aspects
: List_Id
;
2508 New_Subtyp_Decl_For_L
: Node_Id
;
2509 System
: System_Type
;
2512 -- Case when the operand is not dimensionless
2514 if Exists
(Dims_Of_N
) then
2516 -- Get the corresponding System_Type to know the exact number of
2517 -- dimensions in the system.
2519 System
:= System_Of
(Btyp_Of_L
);
2521 -- Generation of a new subtype with the proper dimensions
2523 -- In order to rewrite the operator as a type conversion, a new
2524 -- dimensioned subtype with the resulting dimensions of the
2525 -- exponentiation must be created.
2529 -- Btyp_Of_L : constant Entity_Id := Base_Type (Etyp_Of_L);
2530 -- System : constant System_Id :=
2531 -- Get_Dimension_System_Id (Btyp_Of_L);
2532 -- Num_Of_Dims : constant Number_Of_Dimensions :=
2533 -- Dimension_Systems.Table (System).Dimension_Count;
2535 -- subtype T is Btyp_Of_L
2538 -- Dims_Of_N (1).Numerator / Dims_Of_N (1).Denominator,
2539 -- Dims_Of_N (2).Numerator / Dims_Of_N (2).Denominator,
2541 -- Dims_Of_N (Num_Of_Dims).Numerator /
2542 -- Dims_Of_N (Num_Of_Dims).Denominator);
2544 -- Step 1: Generate the new aggregate for the aspect Dimension
2546 New_Aspects
:= Empty_List
;
2547 List_Of_Dims
:= New_List
;
2549 for Position
in Dims_Of_N
'First .. System
.Count
loop
2550 Dim_Power
:= Dims_Of_N
(Position
);
2551 Append_To
(List_Of_Dims
,
2552 Make_Op_Divide
(Loc
,
2554 Make_Integer_Literal
(Loc
,
2555 Int
(Dim_Power
.Numerator
)),
2557 Make_Integer_Literal
(Loc
,
2558 Int
(Dim_Power
.Denominator
))));
2561 -- Step 2: Create the new Aspect Specification for Aspect Dimension
2564 Make_Aspect_Specification
(Loc
,
2565 Identifier
=> Make_Identifier
(Loc
, Name_Dimension
),
2566 Expression
=> Make_Aggregate
(Loc
, Expressions
=> List_Of_Dims
));
2568 -- Step 3: Make a temporary identifier for the new subtype
2570 New_Id
:= Make_Temporary
(Loc
, 'T');
2571 Set_Is_Internal
(New_Id
);
2573 -- Step 4: Declaration of the new subtype
2575 New_Subtyp_Decl_For_L
:=
2576 Make_Subtype_Declaration
(Loc
,
2577 Defining_Identifier
=> New_Id
,
2578 Subtype_Indication
=> New_Occurrence_Of
(Btyp_Of_L
, Loc
));
2580 Append
(New_Aspect
, New_Aspects
);
2581 Set_Parent
(New_Aspects
, New_Subtyp_Decl_For_L
);
2582 Set_Aspect_Specifications
(New_Subtyp_Decl_For_L
, New_Aspects
);
2584 Analyze
(New_Subtyp_Decl_For_L
);
2586 -- Case where the operand is dimensionless
2589 New_Id
:= Btyp_Of_L
;
2592 -- Replacement of N by New_N
2596 -- Actual_1 := Long_Long_Float (L),
2598 -- Actual_2 := Long_Long_Float (Exponent_Value.Numerator) /
2599 -- Long_Long_Float (Exponent_Value.Denominator);
2601 -- (T (Expon_LLF (Actual_1, Actual_2)));
2603 -- where T is the subtype declared in step 1
2605 -- The node is rewritten as a type conversion
2607 -- Step 1: Creation of the two parameters of Expon_LLF function call
2610 Make_Type_Conversion
(Loc
,
2611 Subtype_Mark
=> New_Reference_To
(Standard_Long_Long_Float
, Loc
),
2612 Expression
=> Relocate_Node
(L
));
2615 Make_Op_Divide
(Loc
,
2617 Make_Real_Literal
(Loc
,
2618 UR_From_Uint
(UI_From_Int
(Int
(Exponent_Value
.Numerator
)))),
2620 Make_Real_Literal
(Loc
,
2621 UR_From_Uint
(UI_From_Int
(Int
(Exponent_Value
.Denominator
)))));
2623 -- Step 2: Creation of New_N
2626 Make_Type_Conversion
(Loc
,
2627 Subtype_Mark
=> New_Reference_To
(New_Id
, Loc
),
2629 Make_Function_Call
(Loc
,
2630 Name
=> New_Reference_To
(RTE
(RE_Expon_LLF
), Loc
),
2631 Parameter_Associations
=> New_List
(
2632 Actual_1
, Actual_2
)));
2634 -- Step 3: Rewrite N with the result
2637 Set_Etype
(N
, New_Id
);
2638 Analyze_And_Resolve
(N
, New_Id
);
2639 end Eval_Op_Expon_With_Rational_Exponent
;
2645 function Exists
(Dim
: Dimension_Type
) return Boolean is
2647 return Dim
/= Null_Dimension
;
2650 function Exists
(Str
: String_Id
) return Boolean is
2652 return Str
/= No_String
;
2655 function Exists
(Sys
: System_Type
) return Boolean is
2657 return Sys
/= Null_System
;
2660 ---------------------------------
2661 -- Expand_Put_Call_With_Symbol --
2662 ---------------------------------
2664 -- For procedure Put (resp. Put_Dim_Of) defined in System.Dim.Float_IO
2665 -- (System.Dim.Integer_IO), the default string parameter must be rewritten
2666 -- to include the unit symbols (resp. dimension symbols) in the output
2667 -- of a dimensioned object. Note that if a value is already supplied for
2668 -- parameter Symbol, this routine doesn't do anything.
2670 -- Case 1. Item is dimensionless
2672 -- * Put : Item appears without a suffix
2674 -- * Put_Dim_Of : the output is []
2676 -- Obj : Mks_Type := 2.6;
2677 -- Put (Obj, 1, 1, 0);
2678 -- Put_Dim_Of (Obj);
2680 -- The corresponding outputs are:
2684 -- Case 2. Item has a dimension
2686 -- * Put : If the type of Item is a dimensioned subtype whose
2687 -- symbol is not empty, then the symbol appears as a
2688 -- suffix. Otherwise, a new string is created and appears
2689 -- as a suffix of Item. This string results in the
2690 -- successive concatanations between each unit symbol
2691 -- raised by its corresponding dimension power from the
2692 -- dimensions of Item.
2694 -- * Put_Dim_Of : The output is a new string resulting in the successive
2695 -- concatanations between each dimension symbol raised by
2696 -- its corresponding dimension power from the dimensions of
2699 -- subtype Random is Mks_Type
2706 -- Obj : Random := 5.0;
2708 -- Put_Dim_Of (Obj);
2710 -- The corresponding outputs are:
2711 -- $5.0 m**3.cd**(-1)
2714 procedure Expand_Put_Call_With_Symbol
(N
: Node_Id
) is
2715 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
2716 Loc
: constant Source_Ptr
:= Sloc
(N
);
2717 Name_Call
: constant Node_Id
:= Name
(N
);
2718 New_Actuals
: constant List_Id
:= New_List
;
2720 Dims_Of_Actual
: Dimension_Type
;
2722 New_Str_Lit
: Node_Id
:= Empty
;
2723 Symbols
: String_Id
;
2725 Is_Put_Dim_Of
: Boolean := False;
2726 -- This flag is used in order to differentiate routines Put and
2727 -- Put_Dim_Of. Set to True if the procedure is one of the Put_Dim_Of
2728 -- defined in System.Dim.Float_IO or System.Dim.Integer_IO.
2730 function Has_Symbols
return Boolean;
2731 -- Return True if the current Put call already has a parameter
2732 -- association for parameter "Symbols" with the correct string of
2735 function Is_Procedure_Put_Call
return Boolean;
2736 -- Return True if the current call is a call of an instantiation of a
2737 -- procedure Put defined in the package System.Dim.Float_IO and
2738 -- System.Dim.Integer_IO.
2740 function Item_Actual
return Node_Id
;
2741 -- Return the item actual parameter node in the output call
2747 function Has_Symbols
return Boolean is
2749 Actual_Str
: Node_Id
;
2752 Actual
:= First
(Actuals
);
2754 -- Look for a symbols parameter association in the list of actuals
2756 while Present
(Actual
) loop
2758 -- Positional parameter association case when the actual is a
2761 if Nkind
(Actual
) = N_String_Literal
then
2762 Actual_Str
:= Actual
;
2764 -- Named parameter association case when selector name is Symbol
2766 elsif Nkind
(Actual
) = N_Parameter_Association
2767 and then Chars
(Selector_Name
(Actual
)) = Name_Symbol
2769 Actual_Str
:= Explicit_Actual_Parameter
(Actual
);
2771 -- Ignore all other cases
2774 Actual_Str
:= Empty
;
2777 if Present
(Actual_Str
) then
2779 -- Return True if the actual comes from source or if the string
2780 -- of symbols doesn't have the default value (i.e. it is "").
2782 if Comes_From_Source
(Actual
)
2783 or else String_Length
(Strval
(Actual_Str
)) /= 0
2785 -- Complain only if the actual comes from source or if it
2786 -- hasn't been fully analyzed yet.
2788 if Comes_From_Source
(Actual
)
2789 or else not Analyzed
(Actual
)
2791 Error_Msg_N
("Symbol parameter should not be provided",
2793 Error_Msg_N
("\reserved for compiler use only", Actual
);
2806 -- At this point, the call has no parameter association. Look to the
2807 -- last actual since the symbols parameter is the last one.
2809 return Nkind
(Last
(Actuals
)) = N_String_Literal
;
2812 ---------------------------
2813 -- Is_Procedure_Put_Call --
2814 ---------------------------
2816 function Is_Procedure_Put_Call
return Boolean is
2821 -- There are three different Put (resp. Put_Dim_Of) routines in each
2822 -- generic dim IO package. Verify the current procedure call is one
2825 if Is_Entity_Name
(Name_Call
) then
2826 Ent
:= Entity
(Name_Call
);
2828 -- Get the original subprogram entity following the renaming chain
2830 if Present
(Alias
(Ent
)) then
2836 -- Check the name of the entity subprogram is Put (resp.
2837 -- Put_Dim_Of) and verify this entity is located in either
2838 -- System.Dim.Float_IO or System.Dim.Integer_IO.
2840 if Loc
> No_Location
2841 and then Is_Dim_IO_Package_Entity
2842 (Cunit_Entity
(Get_Source_Unit
(Loc
)))
2844 if Chars
(Ent
) = Name_Put_Dim_Of
then
2845 Is_Put_Dim_Of
:= True;
2848 elsif Chars
(Ent
) = Name_Put
then
2855 end Is_Procedure_Put_Call
;
2861 function Item_Actual
return Node_Id
is
2865 -- Look for the item actual as a parameter association
2867 Actual
:= First
(Actuals
);
2868 while Present
(Actual
) loop
2869 if Nkind
(Actual
) = N_Parameter_Association
2870 and then Chars
(Selector_Name
(Actual
)) = Name_Item
2872 return Explicit_Actual_Parameter
(Actual
);
2878 -- Case where the item has been defined without an association
2880 Actual
:= First
(Actuals
);
2882 -- Depending on the procedure Put, Item actual could be first or
2883 -- second in the list of actuals.
2885 if Has_Dimension_System
(Base_Type
(Etype
(Actual
))) then
2888 return Next
(Actual
);
2892 -- Start of processing for Expand_Put_Call_With_Symbol
2895 if Is_Procedure_Put_Call
and then not Has_Symbols
then
2896 Actual
:= Item_Actual
;
2897 Dims_Of_Actual
:= Dimensions_Of
(Actual
);
2898 Etyp
:= Etype
(Actual
);
2902 if Is_Put_Dim_Of
then
2904 -- Check that the item is not dimensionless
2906 -- Create the new String_Literal with the new String_Id generated
2907 -- by the routine From_Dim_To_Str_Of_Dim_Symbols.
2909 if Exists
(Dims_Of_Actual
) then
2911 Make_String_Literal
(Loc
,
2912 From_Dim_To_Str_Of_Dim_Symbols
2913 (Dims_Of_Actual
, System_Of
(Base_Type
(Etyp
))));
2915 -- If dimensionless, the output is []
2919 Make_String_Literal
(Loc
, "[]");
2925 -- Add the symbol as a suffix of the value if the subtype has a
2926 -- unit symbol or if the parameter is not dimensionless.
2928 if Exists
(Symbol_Of
(Etyp
)) then
2929 Symbols
:= Symbol_Of
(Etyp
);
2931 Symbols
:= From_Dim_To_Str_Of_Unit_Symbols
2932 (Dims_Of_Actual
, System_Of
(Base_Type
(Etyp
)));
2935 -- Check Symbols exists
2937 if Exists
(Symbols
) then
2940 -- Put a space between the value and the dimension
2942 Store_String_Char
(' ');
2943 Store_String_Chars
(Symbols
);
2944 New_Str_Lit
:= Make_String_Literal
(Loc
, End_String
);
2948 if Present
(New_Str_Lit
) then
2950 -- Insert all actuals in New_Actuals
2952 Actual
:= First
(Actuals
);
2953 while Present
(Actual
) loop
2955 -- Copy every actuals in New_Actuals except the Symbols
2956 -- parameter association.
2958 if Nkind
(Actual
) = N_Parameter_Association
2959 and then Chars
(Selector_Name
(Actual
)) /= Name_Symbol
2961 Append_To
(New_Actuals
,
2962 Make_Parameter_Association
(Loc
,
2963 Selector_Name
=> New_Copy
(Selector_Name
(Actual
)),
2964 Explicit_Actual_Parameter
=>
2965 New_Copy
(Explicit_Actual_Parameter
(Actual
))));
2967 elsif Nkind
(Actual
) /= N_Parameter_Association
then
2968 Append_To
(New_Actuals
, New_Copy
(Actual
));
2974 -- Create new Symbols param association and append to New_Actuals
2976 Append_To
(New_Actuals
,
2977 Make_Parameter_Association
(Loc
,
2978 Selector_Name
=> Make_Identifier
(Loc
, Name_Symbol
),
2979 Explicit_Actual_Parameter
=> New_Str_Lit
));
2981 -- Rewrite and analyze the procedure call
2984 Make_Procedure_Call_Statement
(Loc
,
2985 Name
=> New_Copy
(Name_Call
),
2986 Parameter_Associations
=> New_Actuals
));
2991 end Expand_Put_Call_With_Symbol
;
2993 ------------------------------------
2994 -- From_Dim_To_Str_Of_Dim_Symbols --
2995 ------------------------------------
2997 -- Given a dimension vector and the corresponding dimension system, create
2998 -- a String_Id to output dimension symbols corresponding to the dimensions
2999 -- Dims. If In_Error_Msg is True, there is a special handling for character
3000 -- asterisk * which is an insertion character in error messages.
3002 function From_Dim_To_Str_Of_Dim_Symbols
3003 (Dims
: Dimension_Type
;
3004 System
: System_Type
;
3005 In_Error_Msg
: Boolean := False) return String_Id
3007 Dim_Power
: Rational
;
3008 First_Dim
: Boolean := True;
3010 procedure Store_String_Oexpon
;
3011 -- Store the expon operator symbol "**" in the string. In error
3012 -- messages, asterisk * is a special character and must be quoted
3013 -- to be placed literally into the message.
3015 -------------------------
3016 -- Store_String_Oexpon --
3017 -------------------------
3019 procedure Store_String_Oexpon
is
3021 if In_Error_Msg
then
3022 Store_String_Chars
("'*'*");
3024 Store_String_Chars
("**");
3026 end Store_String_Oexpon
;
3028 -- Start of processing for From_Dim_To_Str_Of_Dim_Symbols
3031 -- Initialization of the new String_Id
3035 -- Store the dimension symbols inside boxes
3037 Store_String_Char
('[');
3039 for Position
in Dimension_Type
'Range loop
3040 Dim_Power
:= Dims
(Position
);
3041 if Dim_Power
/= Zero
then
3046 Store_String_Char
('.');
3049 Store_String_Chars
(System
.Dim_Symbols
(Position
));
3051 -- Positive dimension case
3053 if Dim_Power
.Numerator
> 0 then
3056 if Dim_Power
.Denominator
= 1 then
3057 if Dim_Power
.Numerator
/= 1 then
3058 Store_String_Oexpon
;
3059 Store_String_Int
(Int
(Dim_Power
.Numerator
));
3062 -- Rational case when denominator /= 1
3065 Store_String_Oexpon
;
3066 Store_String_Char
('(');
3067 Store_String_Int
(Int
(Dim_Power
.Numerator
));
3068 Store_String_Char
('/');
3069 Store_String_Int
(Int
(Dim_Power
.Denominator
));
3070 Store_String_Char
(')');
3073 -- Negative dimension case
3076 Store_String_Oexpon
;
3077 Store_String_Char
('(');
3078 Store_String_Char
('-');
3079 Store_String_Int
(Int
(-Dim_Power
.Numerator
));
3083 if Dim_Power
.Denominator
= 1 then
3084 Store_String_Char
(')');
3086 -- Rational case when denominator /= 1
3089 Store_String_Char
('/');
3090 Store_String_Int
(Int
(Dim_Power
.Denominator
));
3091 Store_String_Char
(')');
3097 Store_String_Char
(']');
3099 end From_Dim_To_Str_Of_Dim_Symbols
;
3101 -------------------------------------
3102 -- From_Dim_To_Str_Of_Unit_Symbols --
3103 -------------------------------------
3105 -- Given a dimension vector and the corresponding dimension system,
3106 -- create a String_Id to output the unit symbols corresponding to the
3109 function From_Dim_To_Str_Of_Unit_Symbols
3110 (Dims
: Dimension_Type
;
3111 System
: System_Type
) return String_Id
3113 Dim_Power
: Rational
;
3114 First_Dim
: Boolean := True;
3117 -- Return No_String if dimensionless
3119 if not Exists
(Dims
) then
3123 -- Initialization of the new String_Id
3127 for Position
in Dimension_Type
'Range loop
3128 Dim_Power
:= Dims
(Position
);
3130 if Dim_Power
/= Zero
then
3135 Store_String_Char
('.');
3138 Store_String_Chars
(System
.Unit_Symbols
(Position
));
3140 -- Positive dimension case
3142 if Dim_Power
.Numerator
> 0 then
3146 if Dim_Power
.Denominator
= 1 then
3147 if Dim_Power
.Numerator
/= 1 then
3148 Store_String_Chars
("**");
3149 Store_String_Int
(Int
(Dim_Power
.Numerator
));
3152 -- Rational case when denominator /= 1
3155 Store_String_Chars
("**");
3156 Store_String_Char
('(');
3157 Store_String_Int
(Int
(Dim_Power
.Numerator
));
3158 Store_String_Char
('/');
3159 Store_String_Int
(Int
(Dim_Power
.Denominator
));
3160 Store_String_Char
(')');
3163 -- Negative dimension case
3166 Store_String_Chars
("**");
3167 Store_String_Char
('(');
3168 Store_String_Char
('-');
3169 Store_String_Int
(Int
(-Dim_Power
.Numerator
));
3173 if Dim_Power
.Denominator
= 1 then
3174 Store_String_Char
(')');
3176 -- Rational case when denominator /= 1
3179 Store_String_Char
('/');
3180 Store_String_Int
(Int
(Dim_Power
.Denominator
));
3181 Store_String_Char
(')');
3188 end From_Dim_To_Str_Of_Unit_Symbols
;
3194 function GCD
(Left
, Right
: Whole
) return Int
is
3214 --------------------------
3215 -- Has_Dimension_System --
3216 --------------------------
3218 function Has_Dimension_System
(Typ
: Entity_Id
) return Boolean is
3220 return Exists
(System_Of
(Typ
));
3221 end Has_Dimension_System
;
3223 ------------------------------
3224 -- Is_Dim_IO_Package_Entity --
3225 ------------------------------
3227 function Is_Dim_IO_Package_Entity
(E
: Entity_Id
) return Boolean is
3229 -- Check the package entity corresponds to System.Dim.Float_IO or
3230 -- System.Dim.Integer_IO.
3233 Is_RTU
(E
, System_Dim_Float_IO
)
3235 Is_RTU
(E
, System_Dim_Integer_IO
);
3236 end Is_Dim_IO_Package_Entity
;
3238 -------------------------------------
3239 -- Is_Dim_IO_Package_Instantiation --
3240 -------------------------------------
3242 function Is_Dim_IO_Package_Instantiation
(N
: Node_Id
) return Boolean is
3243 Gen_Id
: constant Node_Id
:= Name
(N
);
3246 -- Check that the instantiated package is either System.Dim.Float_IO
3247 -- or System.Dim.Integer_IO.
3250 Is_Entity_Name
(Gen_Id
)
3251 and then Is_Dim_IO_Package_Entity
(Entity
(Gen_Id
));
3252 end Is_Dim_IO_Package_Instantiation
;
3258 function Is_Invalid
(Position
: Dimension_Position
) return Boolean is
3260 return Position
= Invalid_Position
;
3263 ---------------------
3264 -- Move_Dimensions --
3265 ---------------------
3267 procedure Move_Dimensions
(From
, To
: Node_Id
) is
3269 if Ada_Version
< Ada_2012
then
3273 -- Copy the dimension of 'From to 'To' and remove dimension of 'From'
3275 Copy_Dimensions
(From
, To
);
3276 Remove_Dimensions
(From
);
3277 end Move_Dimensions
;
3283 function Reduce
(X
: Rational
) return Rational
is
3285 if X
.Numerator
= 0 then
3290 G
: constant Int
:= GCD
(X
.Numerator
, X
.Denominator
);
3292 return Rational
'(Numerator => Whole (Int (X.Numerator) / G),
3293 Denominator => Whole (Int (X.Denominator) / G));
3297 -----------------------
3298 -- Remove_Dimensions --
3299 -----------------------
3301 procedure Remove_Dimensions (N : Node_Id) is
3302 Dims_Of_N : constant Dimension_Type := Dimensions_Of (N);
3304 if Exists (Dims_Of_N) then
3305 Dimension_Table.Remove (N);
3307 end Remove_Dimensions;
3309 -----------------------------------
3310 -- Remove_Dimension_In_Statement --
3311 -----------------------------------
3313 -- Removal of dimension in statement as part of the Analyze_Statements
3314 -- routine (see package Sem_Ch5).
3316 procedure Remove_Dimension_In_Statement (Stmt : Node_Id) is
3318 if Ada_Version < Ada_2012 then
3322 -- Remove dimension in parameter specifications for accept statement
3324 if Nkind (Stmt) = N_Accept_Statement then
3326 Param : Node_Id := First (Parameter_Specifications (Stmt));
3328 while Present (Param) loop
3329 Remove_Dimensions (Param);
3334 -- Remove dimension of name and expression in assignments
3336 elsif Nkind (Stmt) = N_Assignment_Statement then
3337 Remove_Dimensions (Expression (Stmt));
3338 Remove_Dimensions (Name (Stmt));
3340 end Remove_Dimension_In_Statement;
3342 --------------------
3343 -- Set_Dimensions --
3344 --------------------
3346 procedure Set_Dimensions (N : Node_Id; Val : Dimension_Type) is
3348 pragma Assert (OK_For_Dimension (Nkind (N)));
3349 pragma Assert (Exists (Val));
3351 Dimension_Table.Set (N, Val);
3358 procedure Set_Symbol (E : Entity_Id; Val : String_Id) is
3360 Symbol_Table.Set (E, Val);
3363 ---------------------------------
3364 -- String_From_Numeric_Literal --
3365 ---------------------------------
3367 function String_From_Numeric_Literal (N : Node_Id) return String_Id is
3368 Loc : constant Source_Ptr := Sloc (N);
3369 Sbuffer : constant Source_Buffer_Ptr :=
3370 Source_Text (Get_Source_File_Index (Loc));
3371 Src_Ptr : Source_Ptr := Loc;
3372 C : Character := Sbuffer (Src_Ptr);
3373 -- Current source program character
3375 function Belong_To_Numeric_Literal (C : Character) return Boolean;
3376 -- Return True if C belongs to a numeric literal
3378 -------------------------------
3379 -- Belong_To_Numeric_Literal --
3380 -------------------------------
3382 function Belong_To_Numeric_Literal (C : Character) return Boolean is
3398 -- Make sure '+' or '-' is part of an exponent.
3402 Prev_C : constant Character := Sbuffer (Src_Ptr - 1);
3404 return Prev_C = 'e
' or else Prev_C = 'E
';
3407 -- All other character doesn't belong to a numeric literal
3412 end Belong_To_Numeric_Literal;
3414 -- Start of processing for String_From_Numeric_Literal
3418 while Belong_To_Numeric_Literal (C) loop
3419 Store_String_Char (C);
3420 Src_Ptr := Src_Ptr + 1;
3421 C := Sbuffer (Src_Ptr);
3425 end String_From_Numeric_Literal;
3431 function Symbol_Of (E : Entity_Id) return String_Id is
3432 Subtype_Symbol : constant String_Id := Symbol_Table.Get (E);
3434 if Subtype_Symbol /= No_String then
3435 return Subtype_Symbol;
3437 return From_Dim_To_Str_Of_Unit_Symbols
3438 (Dimensions_Of (E), System_Of (Base_Type (E)));
3442 -----------------------
3443 -- Symbol_Table_Hash --
3444 -----------------------
3446 function Symbol_Table_Hash (Key : Entity_Id) return Symbol_Table_Range is
3448 return Symbol_Table_Range (Key mod 511);
3449 end Symbol_Table_Hash;
3455 function System_Of (E : Entity_Id) return System_Type is
3456 Type_Decl : constant Node_Id := Parent (E);
3459 -- Look for Type_Decl in System_Table
3461 for Dim_Sys in 1 .. System_Table.Last loop
3462 if Type_Decl = System_Table.Table (Dim_Sys).Type_Decl then
3463 return System_Table.Table (Dim_Sys);