1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S E M _ D I M --
-- --
-- S p e c --
-- --
-- Copyright (C) 2011, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package provides support for numerical systems with dimensions. A
-- "dimension" is a compile-time property of a numerical type which represents
-- a relation between various quantifiers such as length, velocity, etc.
-- Package System.Dim_Mks offers a ready-to-use system of SI base units. In
-- addition, the implementation of this feature offers the ability to define
-- an arbitrary system of units through the use of Ada 2012 aspects.
-- Dimensionality checking is part of type analysis performed by the compiler.
-- It ensures that manipulation of quantified numeric values is sensible with
-- respect to the system of units.
-----------------------------
-- Aspect_Dimension_System --
-----------------------------
-- In order to enable the user to create their own dimension system, a new
-- aspect: Aspect_Dimension_System has been created.
-- Note that this aspect applies for type declaration of type derived from any
-- numeric type.
-- It defines the names of each dimension
----------------------
-- Aspect_Dimension --
----------------------
-- This new aspect applies for subtype and object declarations in order to
-- define new dimensions.
-- Using this aspect, the user is able to create new subtype/object with any
-- dimension needed.
-- Note that the base type of the subtype/object must be the type that defines
-- the corresponding dimension system.
-- The expression of this aspect is an aggregate of rational values for each
-- dimension in the corresponding dimension system.
-------------------------------------------
-- Dimensionality checking & propagation --
-------------------------------------------
-- For each node (when needed), a dimension analysis (Analyze_Dimension) is
-- performed as part of the Resolution routine or the Analysis routine if no
-- Resolution.
-- The dimension analysis is divided into two phases:
-- Phase 1: dimension checking
-- Phase 2: propagation of dimensions
-- Depending on the node kind, either none, one phase or two phases are
-- executed.
-- Phase 2 is called only when the node allows a dimension (see body of
-- Sem_Dim to get the list of nodes that permit dimensions).
------------------
-- Dimension_IO --
------------------
-- This section contains the routine used for IO purposes
with Types; use Types;
package Sem_Dim is
procedure Analyze_Aspect_Dimension
(N : Node_Id;
Id : Entity_Id;
Aggr : Node_Id);
-- Analyze the contents of aspect Dimension. Associate the provided values
-- and quantifiers with the related context N. Id is the corresponding
-- Aspect_Id (Aspect_Dimension) Aggr is the corresponding expression for
-- the aspect Dimension declared by the declaration of N.
procedure Analyze_Aspect_Dimension_System
(N : Node_Id;
Id : Entity_Id;
Aggr : Node_Id);
-- Analyze the contents of aspect Dimension_System. Extract the numerical
-- type, unit name and corresponding symbol from each indivitual dimension.
-- Id is the corresponding Aspect_Id (Aspect_Dimension_System)
-- Aggr is the corresponding expression for the aspect Dimension_System
-- declared by the declaration of N.
procedure Analyze_Dimension (N : Node_Id);
-- N may denote any of the following contexts:
-- * assignment statement
-- * attribute reference
-- * binary operator
-- * compontent declaration
-- * extended return statement
-- * function call
-- * identifier
-- * indexed component
-- * object declaration
-- * object renaming declaration
-- * qualified expression
-- * selected component
-- * simple return statement
-- * slice
-- * subtype declaration
-- * type conversion
-- * unary operator
-- * unchecked type conversion
-- Depending on the context, ensure that all expressions and entities
-- involved do not violate the rules of a system.
procedure Eval_Op_Expon_For_Dimensioned_Type
(N : Node_Id;
Btyp : Entity_Id);
-- Evaluate the Expon operator for dimensioned type with rational exponent.
-- Indeed the regular Eval_Op_Expon routine (see package Sem_Eval) is
-- restricted to Integer exponent. This routine deals only with rational
-- exponent which is not an integer if Btyp is a dimensioned type.
procedure Expand_Put_Call_With_Dimension_Symbol (N : Node_Id);
-- Determine whether N denotes a subprogram call to one of the routines
-- defined in System.Dim_Float_IO or System.Dim_Integer_IO and add an
-- extra actual to the call to represent the symbolic representation of
-- a dimension.
function Has_Dimension_System (Typ : Entity_Id) return Boolean;
-- Return True if type Typ has aspect Dimension_System applied to it
function Is_Dim_IO_Package_Instantiation (N : Node_Id) return Boolean;
-- Return True if N is a package instantiation of System.Dim_Integer_IO or
-- of System.Dim_Float_IO.
procedure Remove_Dimension_In_Call (Call : Node_Id);
-- Remove the dimensions from all formal parameters of Call
procedure Remove_Dimension_In_Statement (Stmt : Node_Id);
-- Remove the dimensions associated with Stmt
end Sem_Dim;
|