annotate gcc/ada/sem_dim.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S E M _ D I M --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2011-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 -- This package provides support for numerical systems with dimensions. A
kono
parents:
diff changeset
27 -- "dimension" is a compile-time property of a numerical type which represents
kono
parents:
diff changeset
28 -- a relation between various quantifiers such as length, velocity, etc.
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 -- Package System.Dim.Mks offers a ready-to-use system of SI base units. In
kono
parents:
diff changeset
31 -- addition, the implementation of this feature offers the ability to define
kono
parents:
diff changeset
32 -- an arbitrary system of units through the use of Ada 2012 aspects.
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 -- Dimensionality checking is part of type analysis performed by the compiler.
kono
parents:
diff changeset
35 -- It ensures that manipulation of quantified numeric values is sensible with
kono
parents:
diff changeset
36 -- respect to the system of units.
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 -----------------------------
kono
parents:
diff changeset
39 -- Aspect_Dimension_System --
kono
parents:
diff changeset
40 -----------------------------
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 -- In order to enable the user to create their own dimension system, a new
kono
parents:
diff changeset
43 -- aspect: Aspect_Dimension_System has been created.
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 -- Note that this aspect applies for type declaration of type derived from any
kono
parents:
diff changeset
46 -- numeric type.
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 -- It defines the names of each dimension
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 ----------------------
kono
parents:
diff changeset
51 -- Aspect_Dimension --
kono
parents:
diff changeset
52 ----------------------
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 -- This new aspect applies for subtype and object declarations in order to
kono
parents:
diff changeset
55 -- define new dimensions.
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 -- Using this aspect, the user is able to create new subtype/object with any
kono
parents:
diff changeset
58 -- dimension needed.
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 -- Note that the base type of the subtype/object must be the type that defines
kono
parents:
diff changeset
61 -- the corresponding dimension system.
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 -- The expression of this aspect is an aggregate of rational values for each
kono
parents:
diff changeset
64 -- dimension in the corresponding dimension system.
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 -------------------------------------------
kono
parents:
diff changeset
67 -- Dimensionality checking & propagation --
kono
parents:
diff changeset
68 -------------------------------------------
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 -- For each node (when needed), a dimension analysis (Analyze_Dimension) is
kono
parents:
diff changeset
71 -- performed as part of the Resolution routine or the Analysis routine if no
kono
parents:
diff changeset
72 -- Resolution.
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 -- The dimension analysis is divided into two phases:
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 -- Phase 1: dimension checking
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 -- Phase 2: propagation of dimensions
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 -- Depending on the node kind, either none, one phase or two phases are
kono
parents:
diff changeset
81 -- executed.
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 -- Phase 2 is called only when the node allows a dimension (see body of
kono
parents:
diff changeset
84 -- Sem_Dim to get the list of nodes that permit dimensions).
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 -- In principle every node that is a component of a floating-point expression
kono
parents:
diff changeset
87 -- may have a dimension vector. However, the dimensionality checking is for
kono
parents:
diff changeset
88 -- the most part a bottom-up tree traversal, and the dimensions of operands
kono
parents:
diff changeset
89 -- become irrelevant once the dimensions of an operation have been computed.
kono
parents:
diff changeset
90 -- To minimize space use, the dimensions of operands are removed after the
kono
parents:
diff changeset
91 -- computation of the dimensions of the parent operation. This may complicate
kono
parents:
diff changeset
92 -- the analysis of nodes that have been constant-folded or otherwise rewritten
kono
parents:
diff changeset
93 -- when removing side effects. In such cases, the (sub)type of the expression
kono
parents:
diff changeset
94 -- is used to determine the applicable dimensions.
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 with Types; use Types;
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 package Sem_Dim is
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 procedure Analyze_Aspect_Dimension
kono
parents:
diff changeset
101 (N : Node_Id;
kono
parents:
diff changeset
102 Id : Entity_Id;
kono
parents:
diff changeset
103 Aggr : Node_Id);
kono
parents:
diff changeset
104 -- Analyze the contents of aspect Dimension. Associate the provided values
kono
parents:
diff changeset
105 -- and quantifiers with the related context N. Id is the corresponding
kono
parents:
diff changeset
106 -- Aspect_Id (Aspect_Dimension) Aggr is the corresponding expression for
kono
parents:
diff changeset
107 -- the aspect Dimension declared by the declaration of N.
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 procedure Analyze_Aspect_Dimension_System
kono
parents:
diff changeset
110 (N : Node_Id;
kono
parents:
diff changeset
111 Id : Entity_Id;
kono
parents:
diff changeset
112 Aggr : Node_Id);
kono
parents:
diff changeset
113 -- Analyze the contents of aspect Dimension_System. Extract the numerical
kono
parents:
diff changeset
114 -- type, unit name and corresponding symbol from each indivitual dimension.
kono
parents:
diff changeset
115 -- Id is the corresponding Aspect_Id (Aspect_Dimension_System). Aggr is
kono
parents:
diff changeset
116 -- the corresponding expression for the aspect Dimension_System from the
kono
parents:
diff changeset
117 -- declaration of N.
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 procedure Analyze_Dimension (N : Node_Id);
kono
parents:
diff changeset
120 -- N may denote any of the following contexts:
kono
parents:
diff changeset
121 -- * aggregate
kono
parents:
diff changeset
122 -- * assignment statement
kono
parents:
diff changeset
123 -- * attribute reference
kono
parents:
diff changeset
124 -- * binary operator
kono
parents:
diff changeset
125 -- * call
kono
parents:
diff changeset
126 -- * compontent declaration
kono
parents:
diff changeset
127 -- * extended return statement
kono
parents:
diff changeset
128 -- * expanded name
kono
parents:
diff changeset
129 -- * explicit dereference
kono
parents:
diff changeset
130 -- * identifier
kono
parents:
diff changeset
131 -- * indexed component
kono
parents:
diff changeset
132 -- * number declaration
kono
parents:
diff changeset
133 -- * object declaration
kono
parents:
diff changeset
134 -- * object renaming declaration
kono
parents:
diff changeset
135 -- * procedure call statement
kono
parents:
diff changeset
136 -- * qualified expression
kono
parents:
diff changeset
137 -- * selected component
kono
parents:
diff changeset
138 -- * simple return statement
kono
parents:
diff changeset
139 -- * slice
kono
parents:
diff changeset
140 -- * subtype declaration
kono
parents:
diff changeset
141 -- * type conversion
kono
parents:
diff changeset
142 -- * unary operator
kono
parents:
diff changeset
143 -- * unchecked type conversion
kono
parents:
diff changeset
144 -- Depending on the context, ensure that all expressions and entities
kono
parents:
diff changeset
145 -- involved do not violate the rules of a system.
kono
parents:
diff changeset
146
kono
parents:
diff changeset
147 procedure Analyze_Dimension_Array_Aggregate
kono
parents:
diff changeset
148 (N : Node_Id;
kono
parents:
diff changeset
149 Comp_Typ : Entity_Id);
kono
parents:
diff changeset
150 -- Check, for each component of the array aggregate denoted by N, the
kono
parents:
diff changeset
151 -- dimensions of the component expression match the dimensions of the
kono
parents:
diff changeset
152 -- component type Comp_Typ.
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 procedure Analyze_Dimension_Call (N : Node_Id; Nam : Entity_Id);
kono
parents:
diff changeset
155 -- This routine is split in two steps. Note the second step applies only to
kono
parents:
diff changeset
156 -- function calls.
kono
parents:
diff changeset
157 -- Step 1. Dimension checking:
kono
parents:
diff changeset
158 -- * General case: check the dimensions of each actual parameter match
kono
parents:
diff changeset
159 -- the dimensions of the corresponding formal parameter.
kono
parents:
diff changeset
160 -- * Elementary function case: check each actual is dimensionless except
kono
parents:
diff changeset
161 -- for Sqrt call.
kono
parents:
diff changeset
162 -- Step 2. Dimension propagation (only for functions):
kono
parents:
diff changeset
163 -- * General case: propagate the dimensions from the returned type to the
kono
parents:
diff changeset
164 -- function call.
kono
parents:
diff changeset
165 -- * Sqrt case: the resulting dimensions equal to half the dimensions of
kono
parents:
diff changeset
166 -- the actual
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 procedure Analyze_Dimension_Extension_Or_Record_Aggregate (N : Node_Id);
kono
parents:
diff changeset
169 -- Check, for each component of the extension or record aggregate denoted
kono
parents:
diff changeset
170 -- by N, the dimensions of the component expression match the dimensions of
kono
parents:
diff changeset
171 -- the component type.
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 procedure Analyze_Dimension_Formals (N : Node_Id; Formals : List_Id);
kono
parents:
diff changeset
174 -- For sub spec N, issue a warning for each dimensioned formal with a
kono
parents:
diff changeset
175 -- literal default value in the list of formals Formals.
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 procedure Check_Expression_Dimensions
kono
parents:
diff changeset
178 (Expr : Node_Id;
kono
parents:
diff changeset
179 Typ : Entity_Id);
kono
parents:
diff changeset
180 -- Compute dimensions of a floating-point expression and compare them with
kono
parents:
diff changeset
181 -- the dimensions of a the given type. Used to verify dimensions of the
kono
parents:
diff changeset
182 -- components of a multidimensional array type, for which components are
kono
parents:
diff changeset
183 -- typically themselves arrays. The resolution of such arrays delays the
kono
parents:
diff changeset
184 -- resolution of the ultimate components to a separate phase, which forces
kono
parents:
diff changeset
185 -- this separate dimension verification.
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 procedure Copy_Dimensions (From : Node_Id; To : Node_Id);
kono
parents:
diff changeset
188 -- Copy dimension vector of node From to node To. Note that To must be a
kono
parents:
diff changeset
189 -- node that is allowed to contain a dimension (see OK_For_Dimension in
kono
parents:
diff changeset
190 -- body of Sem_Dim).
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 procedure Copy_Dimensions_Of_Components (Rec : Entity_Id);
kono
parents:
diff changeset
193 -- Propagate the dimensions of the components of a record type T to the
kono
parents:
diff changeset
194 -- components of a record type derived from T. The derivation creates
kono
parents:
diff changeset
195 -- a full copy of the type declaration of the parent, and the dimension
kono
parents:
diff changeset
196 -- information of individual components must be transferred explicitly.
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 function Dimensions_Match (T1 : Entity_Id; T2 : Entity_Id) return Boolean;
kono
parents:
diff changeset
199 -- If the common base type has a dimension system, verify that two
kono
parents:
diff changeset
200 -- subtypes have the same dimensions. Used for conformance checking.
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 procedure Eval_Op_Expon_For_Dimensioned_Type
kono
parents:
diff changeset
203 (N : Node_Id;
kono
parents:
diff changeset
204 Btyp : Entity_Id);
kono
parents:
diff changeset
205 -- Evaluate the Expon operator for dimensioned type with rational exponent.
kono
parents:
diff changeset
206 -- Indeed the regular Eval_Op_Expon routine (see package Sem_Eval) is
kono
parents:
diff changeset
207 -- restricted to Integer exponent. This routine deals only with rational
kono
parents:
diff changeset
208 -- exponent which is not an integer if Btyp is a dimensioned type.
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 procedure Expand_Put_Call_With_Symbol (N : Node_Id);
kono
parents:
diff changeset
211 -- Determine whether N denotes a subprogram call to one of the routines
kono
parents:
diff changeset
212 -- defined in System.Dim.Float_IO or System.Dim.Integer_IO and add an
kono
parents:
diff changeset
213 -- extra actual to the call to represent the symbolic representation of
kono
parents:
diff changeset
214 -- a dimension.
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 function Has_Dimension_System (Typ : Entity_Id) return Boolean;
kono
parents:
diff changeset
217 -- Return True if type Typ has aspect Dimension_System applied to it
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 function Is_Dim_IO_Package_Instantiation (N : Node_Id) return Boolean;
kono
parents:
diff changeset
220 -- Return True if N is a package instantiation of System.Dim.Integer_IO or
kono
parents:
diff changeset
221 -- of System.Dim.Float_IO.
kono
parents:
diff changeset
222
kono
parents:
diff changeset
223 function New_Copy_Tree_And_Copy_Dimensions
kono
parents:
diff changeset
224 (Source : Node_Id;
kono
parents:
diff changeset
225 Map : Elist_Id := No_Elist;
kono
parents:
diff changeset
226 New_Sloc : Source_Ptr := No_Location;
kono
parents:
diff changeset
227 New_Scope : Entity_Id := Empty) return Node_Id;
kono
parents:
diff changeset
228 -- Same as New_Copy_Tree (defined in Sem_Util), except that this routine
kono
parents:
diff changeset
229 -- also copies the dimensions of Source to the returned node.
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 procedure Remove_Dimension_In_Statement (Stmt : Node_Id);
kono
parents:
diff changeset
232 -- Remove the dimensions associated with Stmt
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 end Sem_Dim;