1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT COMPILER COMPONENTS                         --
4--                                                                          --
5--                                T Y P E S                                 --
6--                                                                          --
7--                                 S p e c                                  --
8--                                                                          --
9--          Copyright (C) 1992-2019, Free Software Foundation, Inc.         --
10--                                                                          --
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.                                     --
17--                                                                          --
18-- As a special exception under Section 7 of GPL version 3, you are granted --
19-- additional permissions described in the GCC Runtime Library Exception,   --
20-- version 3.1, as published by the Free Software Foundation.               --
21--                                                                          --
22-- You should have received a copy of the GNU General Public License and    --
23-- a copy of the GCC Runtime Library Exception along with this program;     --
24-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25-- <http://www.gnu.org/licenses/>.                                          --
26--                                                                          --
27-- GNAT was originally developed  by the GNAT team at  New York University. --
28-- Extensive contributions were provided by Ada Core Technologies Inc.      --
29--                                                                          --
30------------------------------------------------------------------------------
31
32--  This package contains host independent type definitions which are used
33--  in more than one unit in the compiler. They are gathered here for easy
34--  reference, although in some cases the full description is found in the
35--  relevant module which implements the definition. The main reason that they
36--  are not in their "natural" specs is that this would cause a lot of inter-
37--  spec dependencies, and in particular some awkward circular dependencies
38--  would have to be dealt with.
39
40--  WARNING: There is a C version of this package. Any changes to this source
41--  file must be properly reflected in the C header file types.h declarations.
42
43--  Note: the declarations in this package reflect an expectation that the host
44--  machine has an efficient integer base type with a range at least 32 bits
45--  2s-complement. If there are any machines for which this is not a correct
46--  assumption, a significant number of changes will be required.
47
48with System;
49with Unchecked_Conversion;
50with Unchecked_Deallocation;
51
52package Types is
53   pragma Preelaborate;
54
55   -------------------------------
56   -- General Use Integer Types --
57   -------------------------------
58
59   type Int is range -2 ** 31 .. +2 ** 31 - 1;
60   --  Signed 32-bit integer
61
62   subtype Nat is Int range 0 .. Int'Last;
63   --  Non-negative Int values
64
65   subtype Pos is Int range 1 .. Int'Last;
66   --  Positive Int values
67
68   type Word is mod 2 ** 32;
69   --  Unsigned 32-bit integer
70
71   type Short is range -32768 .. +32767;
72   for Short'Size use 16;
73   --  16-bit signed integer
74
75   type Byte is mod 2 ** 8;
76   for Byte'Size use 8;
77   --  8-bit unsigned integer
78
79   type size_t is mod 2 ** Standard'Address_Size;
80   --  Memory size value, for use in calls to C routines
81
82   --------------------------------------
83   -- 8-Bit Character and String Types --
84   --------------------------------------
85
86   --  We use Standard.Character and Standard.String freely, since we are
87   --  compiling ourselves, and we properly implement the required 8-bit
88   --  character code as required in Ada 95. This section defines a few
89   --  general use constants and subtypes.
90
91   EOF : constant Character := ASCII.SUB;
92   --  The character SUB (16#1A#) is used in DOS and other systems derived
93   --  from DOS (XP, NT etc) to signal the end of a text file. Internally
94   --  all source files are ended by an EOF character, even on Unix systems.
95   --  An EOF character acts as the end of file only as the last character
96   --  of a source buffer, in any other position, it is treated as a blank
97   --  if it appears between tokens, and as an illegal character otherwise.
98   --  This makes life easier dealing with files that originated from DOS,
99   --  including concatenated files with interspersed EOF characters.
100
101   subtype Graphic_Character is Character range ' ' .. '~';
102   --  Graphic characters, as defined in ARM
103
104   subtype Line_Terminator is Character range ASCII.LF .. ASCII.CR;
105   --  Line terminator characters (LF, VT, FF, CR). For further details, see
106   --  the extensive discussion of line termination in the Sinput spec.
107
108   subtype Upper_Half_Character is
109     Character range Character'Val (16#80#) .. Character'Val (16#FF#);
110   --  8-bit Characters with the upper bit set
111
112   type Character_Ptr    is access all Character;
113   type String_Ptr       is access all String;
114   type String_Ptr_Const is access constant String;
115   --  Standard character and string pointers
116
117   procedure Free is new Unchecked_Deallocation (String, String_Ptr);
118   --  Procedure for freeing dynamically allocated String values
119
120   subtype Big_String is String (Positive);
121   type Big_String_Ptr is access all Big_String;
122   --  Virtual type for handling imported big strings. Note that we should
123   --  never have any allocators for this type, but we don't give a storage
124   --  size of zero, since there are legitimate deallocations going on.
125
126   function To_Big_String_Ptr is
127     new Unchecked_Conversion (System.Address, Big_String_Ptr);
128   --  Used to obtain Big_String_Ptr values from external addresses
129
130   subtype Word_Hex_String is String (1 .. 8);
131   --  Type used to represent Word value as 8 hex digits, with lower case
132   --  letters for the alphabetic cases.
133
134   function Get_Hex_String (W : Word) return Word_Hex_String;
135   --  Convert word value to 8-character hex string
136
137   -----------------------------------------
138   -- Types Used for Text Buffer Handling --
139   -----------------------------------------
140
141   --  We cannot use type String for text buffers, since we must use the
142   --  standard 32-bit integer as an index value, since we count on all index
143   --  values being the same size.
144
145   type Text_Ptr is new Int;
146   --  Type used for subscripts in text buffer
147
148   type Text_Buffer is array (Text_Ptr range <>) of Character;
149   --  Text buffer used to hold source file or library information file
150
151   type Text_Buffer_Ptr is access all Text_Buffer;
152   --  Text buffers for input files are allocated dynamically and this type
153   --  is used to reference these text buffers.
154
155   procedure Free is new Unchecked_Deallocation (Text_Buffer, Text_Buffer_Ptr);
156   --  Procedure for freeing dynamically allocated text buffers
157
158   ------------------------------------------
159   -- Types Used for Source Input Handling --
160   ------------------------------------------
161
162   type Logical_Line_Number is range 0 .. Int'Last;
163   for Logical_Line_Number'Size use 32;
164   --  Line number type, used for storing logical line numbers (i.e. line
165   --  numbers that include effects of any Source_Reference pragmas in the
166   --  source file). The value zero indicates a line containing a source
167   --  reference pragma.
168
169   No_Line_Number : constant Logical_Line_Number := 0;
170   --  Special value used to indicate no line number
171
172   type Physical_Line_Number is range 1 .. Int'Last;
173   for Physical_Line_Number'Size use 32;
174   --  Line number type, used for storing physical line numbers (i.e. line
175   --  numbers in the physical file being compiled, unaffected by the presence
176   --  of source reference pragmas).
177
178   type Column_Number is range 0 .. 32767;
179   for Column_Number'Size use 16;
180   --  Column number (assume that 2**15 - 1 is large enough). The range for
181   --  this type is used to compute Hostparm.Max_Line_Length. See also the
182   --  processing for -gnatyM in Stylesw).
183
184   No_Column_Number : constant Column_Number := 0;
185   --  Special value used to indicate no column number
186
187   Source_Align : constant := 2 ** 12;
188   --  Alignment requirement for source buffers (by keeping source buffers
189   --  aligned, we can optimize the implementation of Get_Source_File_Index.
190   --  See this routine in Sinput for details.
191
192   subtype Source_Buffer is Text_Buffer;
193   --  Type used to store text of a source file. The buffer for the main
194   --  source (the source specified on the command line) has a lower bound
195   --  starting at zero. Subsequent subsidiary sources have lower bounds
196   --  which are one greater than the previous upper bound, rounded up to
197   --  a multiple of Source_Align.
198
199   type Source_Buffer_Ptr_Var is access all Source_Buffer;
200   type Source_Buffer_Ptr is access constant Source_Buffer;
201   --  Pointer to source buffer. Source_Buffer_Ptr_Var is used for allocation
202   --  and deallocation; Source_Buffer_Ptr is used for all other uses of source
203   --  buffers.
204
205   function Null_Source_Buffer_Ptr (X : Source_Buffer_Ptr) return Boolean;
206   --  True if X = null
207
208   function Source_Buffer_Ptr_Equal (X, Y : Source_Buffer_Ptr) return Boolean
209     renames "=";
210   --  Squirrel away the predefined "=", for use in Null_Source_Buffer_Ptr.
211   --  Do not call this elsewhere.
212
213   function "=" (X, Y : Source_Buffer_Ptr) return Boolean is abstract;
214   --  Make "=" abstract. Note that this makes "/=" abstract as well. This is a
215   --  vestige of the zero-origin array indexing we used to use, where "=" is
216   --  always wrong (including the one in Null_Source_Buffer_Ptr). We keep this
217   --  just because we never need to compare Source_Buffer_Ptrs other than to
218   --  null.
219
220   subtype Source_Ptr is Text_Ptr;
221   --  Type used to represent a source location, which is a subscript of a
222   --  character in the source buffer. As noted above, different source buffers
223   --  have different ranges, so it is possible to tell from a Source_Ptr value
224   --  which source it refers to. Note that negative numbers are allowed to
225   --  accommodate the following special values.
226
227   No_Location : constant Source_Ptr := -1;
228   --  Value used to indicate no source position set in a node. A test for a
229   --  Source_Ptr value being > No_Location is the approved way to test for a
230   --  standard value that does not include No_Location or any of the following
231   --  special definitions. One important use of No_Location is to label
232   --  generated nodes that we don't want the debugger to see in normal mode
233   --  (very often we conditionalize so that we set No_Location in normal mode
234   --  and the corresponding source line in -gnatD mode).
235
236   Standard_Location : constant Source_Ptr := -2;
237   --  Used for all nodes in the representation of package Standard other than
238   --  nodes representing the contents of Standard.ASCII. Note that testing for
239   --  a value being <= Standard_Location tests for both Standard_Location and
240   --  for Standard_ASCII_Location.
241
242   Standard_ASCII_Location : constant Source_Ptr := -3;
243   --  Used for all nodes in the presentation of package Standard.ASCII
244
245   System_Location : constant Source_Ptr := -4;
246   --  Used to identify locations of pragmas scanned by Targparm, where we know
247   --  the location is in System, but we don't know exactly what line.
248
249   First_Source_Ptr : constant Source_Ptr := 0;
250   --  Starting source pointer index value for first source program
251
252   -------------------------------------
253   -- Range Definitions for Tree Data --
254   -------------------------------------
255
256   --  The tree has fields that can hold any of the following types:
257
258   --    Pointers to other tree nodes (type Node_Id)
259   --    List pointers (type List_Id)
260   --    Element list pointers (type Elist_Id)
261   --    Names (type Name_Id)
262   --    Strings (type String_Id)
263   --    Universal integers (type Uint)
264   --    Universal reals (type Ureal)
265
266   --  These types are represented as integer indices into various tables.
267   --  However, they should be treated as private, except in a few documented
268   --  cases. In particular it is never appropriate to perform arithmetic
269   --  operations using these types.
270
271   --  In most contexts, the strongly typed interface determines which of these
272   --  types is present. However, there are some situations (involving untyped
273   --  traversals of the tree), where it is convenient to be easily able to
274   --  distinguish these values. The underlying representation in all cases is
275   --  an integer type Union_Id, and we ensure that the range of the various
276   --  possible values for each of the above types is disjoint so that this
277   --  distinction is possible.
278
279   --  Note: it is also helpful for debugging purposes to make these ranges
280   --  distinct. If a bug leads to misidentification of a value, then it will
281   --  typically result in an out of range value and a Constraint_Error.
282
283   type Union_Id is new Int;
284   --  The type in the tree for a union of possible ID values
285
286   List_Low_Bound : constant := -100_000_000;
287   --  The List_Id values are subscripts into an array of list headers which
288   --  has List_Low_Bound as its lower bound. This value is chosen so that all
289   --  List_Id values are negative, and the value zero is in the range of both
290   --  List_Id and Node_Id values (see further description below).
291
292   List_High_Bound : constant := 0;
293   --  Maximum List_Id subscript value. This allows up to 100 million list Id
294   --  values, which is in practice infinite, and there is no need to check the
295   --  range. The range overlaps the node range by one element (with value
296   --  zero), which is used both for the Empty node, and for indicating no
297   --  list. The fact that the same value is used is convenient because it
298   --  means that the default value of Empty applies to both nodes and lists,
299   --  and also is more efficient to test for.
300
301   Node_Low_Bound : constant := 0;
302   --  The tree Id values start at zero, because we use zero for Empty (to
303   --  allow a zero test for Empty). Actual tree node subscripts start at 0
304   --  since Empty is a legitimate node value.
305
306   Node_High_Bound : constant := 099_999_999;
307   --  Maximum number of nodes that can be allocated is 100 million, which
308   --  is in practice infinite, and there is no need to check the range.
309
310   Elist_Low_Bound : constant := 100_000_000;
311   --  The Elist_Id values are subscripts into an array of elist headers which
312   --  has Elist_Low_Bound as its lower bound.
313
314   Elist_High_Bound : constant := 199_999_999;
315   --  Maximum Elist_Id subscript value. This allows up to 100 million Elists,
316   --  which is in practice infinite and there is no need to check the range.
317
318   Elmt_Low_Bound : constant := 200_000_000;
319   --  Low bound of element Id values. The use of these values is internal to
320   --  the Elists package, but the definition of the range is included here
321   --  since it must be disjoint from other Id values. The Elmt_Id values are
322   --  subscripts into an array of list elements which has this as lower bound.
323
324   Elmt_High_Bound : constant := 299_999_999;
325   --  Upper bound of Elmt_Id values. This allows up to 100 million element
326   --  list members, which is in practice infinite (no range check needed).
327
328   Names_Low_Bound : constant := 300_000_000;
329   --  Low bound for name Id values
330
331   Names_High_Bound : constant := 399_999_999;
332   --  Maximum number of names that can be allocated is 100 million, which is
333   --  in practice infinite and there is no need to check the range.
334
335   Strings_Low_Bound : constant := 400_000_000;
336   --  Low bound for string Id values
337
338   Strings_High_Bound : constant := 499_999_999;
339   --  Maximum number of strings that can be allocated is 100 million, which
340   --  is in practice infinite and there is no need to check the range.
341
342   Ureal_Low_Bound : constant := 500_000_000;
343   --  Low bound for Ureal values
344
345   Ureal_High_Bound : constant := 599_999_999;
346   --  Maximum number of Ureal values stored is 100_000_000 which is in
347   --  practice infinite so that no check is required.
348
349   Uint_Low_Bound : constant := 600_000_000;
350   --  Low bound for Uint values
351
352   Uint_Table_Start : constant := 2_000_000_000;
353   --  Location where table entries for universal integers start (see
354   --  Uintp spec for details of the representation of Uint values).
355
356   Uint_High_Bound : constant := 2_099_999_999;
357   --  The range of Uint values is very large, since a substantial part
358   --  of this range is used to store direct values, see Uintp for details.
359
360   --  The following subtype definitions are used to provide convenient names
361   --  for membership tests on Int values to see what data type range they
362   --  lie in. Such tests appear only in the lowest level packages.
363
364   subtype List_Range      is Union_Id
365     range List_Low_Bound    .. List_High_Bound;
366
367   subtype Node_Range      is Union_Id
368     range Node_Low_Bound    .. Node_High_Bound;
369
370   subtype Elist_Range     is Union_Id
371     range Elist_Low_Bound   .. Elist_High_Bound;
372
373   subtype Elmt_Range      is Union_Id
374     range Elmt_Low_Bound    .. Elmt_High_Bound;
375
376   subtype Names_Range     is Union_Id
377     range Names_Low_Bound   .. Names_High_Bound;
378
379   subtype Strings_Range   is Union_Id
380     range Strings_Low_Bound .. Strings_High_Bound;
381
382   subtype Uint_Range      is Union_Id
383     range Uint_Low_Bound    .. Uint_High_Bound;
384
385   subtype Ureal_Range     is Union_Id
386     range Ureal_Low_Bound   .. Ureal_High_Bound;
387
388   -----------------------------
389   -- Types for Atree Package --
390   -----------------------------
391
392   --  Node_Id values are used to identify nodes in the tree. They are
393   --  subscripts into the Nodes table declared in package Atree. Note that
394   --  the special values Empty and Error are subscripts into this table.
395   --  See package Atree for further details.
396
397   type Node_Id is range Node_Low_Bound .. Node_High_Bound;
398   --  Type used to identify nodes in the tree
399
400   subtype Entity_Id is Node_Id;
401   --  A synonym for node types, used in the Einfo package to refer to nodes
402   --  that are entities (i.e. nodes with an Nkind of N_Defining_xxx). All such
403   --  nodes are extended nodes and these are the only extended nodes, so that
404   --  in practice entity and extended nodes are synonymous.
405
406   subtype Node_Or_Entity_Id is Node_Id;
407   --  A synonym for node types, used in cases where a given value may be used
408   --  to represent either a node or an entity. We like to minimize such uses
409   --  for obvious reasons of logical type consistency, but where such uses
410   --  occur, they should be documented by use of this type.
411
412   Empty : constant Node_Id := Node_Low_Bound;
413   --  Used to indicate null node. A node is actually allocated with this
414   --  Id value, so that Nkind (Empty) = N_Empty. Note that Node_Low_Bound
415   --  is zero, so Empty = No_List = zero.
416
417   Empty_List_Or_Node : constant := 0;
418   --  This constant is used in situations (e.g. initializing empty fields)
419   --  where the value set will be used to represent either an empty node or
420   --  a non-existent list, depending on the context.
421
422   Error : constant Node_Id := Node_Low_Bound + 1;
423   --  Used to indicate an error in the source program. A node is actually
424   --  allocated with this Id value, so that Nkind (Error) = N_Error.
425
426   Empty_Or_Error : constant Node_Id := Error;
427   --  Since Empty and Error are the first two Node_Id values, the test for
428   --  N <= Empty_Or_Error tests to see if N is Empty or Error. This definition
429   --  provides convenient self-documentation for such tests.
430
431   First_Node_Id  : constant Node_Id := Node_Low_Bound;
432   --  Subscript of first allocated node. Note that Empty and Error are both
433   --  allocated nodes, whose Nkind fields can be accessed without error.
434
435   ------------------------------
436   -- Types for Nlists Package --
437   ------------------------------
438
439   --  List_Id values are used to identify node lists stored in the tree, so
440   --  that each node can be on at most one such list (see package Nlists for
441   --  further details). Note that the special value Error_List is a subscript
442   --  in this table, but the value No_List is *not* a valid subscript, and any
443   --  attempt to apply list operations to No_List will cause a (detected)
444   --  error.
445
446   type List_Id is range List_Low_Bound .. List_High_Bound;
447   --  Type used to identify a node list
448
449   No_List : constant List_Id := List_High_Bound;
450   --  Used to indicate absence of a list. Note that the value is zero, which
451   --  is the same as Empty, which is helpful in initializing nodes where a
452   --  value of zero can represent either an empty node or an empty list.
453
454   Error_List : constant List_Id := List_Low_Bound;
455   --  Used to indicate that there was an error in the source program in a
456   --  context which would normally require a list. This node appears to be
457   --  an empty list to the list operations (a null list is actually allocated
458   --  which has this Id value).
459
460   First_List_Id : constant List_Id := Error_List;
461   --  Subscript of first allocated list header
462
463   ------------------------------
464   -- Types for Elists Package --
465   ------------------------------
466
467   --  Element list Id values are used to identify element lists stored outside
468   --  of the tree, allowing nodes to be members of more than one such list
469   --  (see package Elists for further details).
470
471   type Elist_Id is range Elist_Low_Bound .. Elist_High_Bound;
472   --  Type used to identify an element list (Elist header table subscript)
473
474   No_Elist : constant Elist_Id := Elist_Low_Bound;
475   --  Used to indicate absence of an element list. Note that this is not an
476   --  actual Elist header, so element list operations on this value are not
477   --  valid.
478
479   First_Elist_Id : constant Elist_Id := No_Elist + 1;
480   --  Subscript of first allocated Elist header
481
482   --  Element Id values are used to identify individual elements of an element
483   --  list (see package Elists for further details).
484
485   type Elmt_Id is range Elmt_Low_Bound .. Elmt_High_Bound;
486   --  Type used to identify an element list
487
488   No_Elmt : constant Elmt_Id := Elmt_Low_Bound;
489   --  Used to represent empty element
490
491   First_Elmt_Id : constant Elmt_Id := No_Elmt + 1;
492   --  Subscript of first allocated Elmt table entry
493
494   -------------------------------
495   -- Types for Stringt Package --
496   -------------------------------
497
498   --  String_Id values are used to identify entries in the strings table. They
499   --  are subscripts into the Strings table defined in package Stringt.
500
501   type String_Id is range Strings_Low_Bound .. Strings_High_Bound;
502   --  Type used to identify entries in the strings table
503
504   No_String : constant String_Id := Strings_Low_Bound;
505   --  Used to indicate missing string Id. Note that the value zero is used
506   --  to indicate a missing data value for all the Int types in this section.
507
508   First_String_Id : constant String_Id := No_String + 1;
509   --  First subscript allocated in string table
510
511   -------------------------
512   -- Character Code Type --
513   -------------------------
514
515   --  The type Char is used for character data internally in the compiler, but
516   --  character codes in the source are represented by the Char_Code type.
517   --  Each character literal in the source is interpreted as being one of the
518   --  16#7FFF_FFFF# possible Wide_Wide_Character codes, and a unique Integer
519   --  value is assigned, corresponding to the UTF-32 value, which also
520   --  corresponds to the Pos value in the Wide_Wide_Character type, and also
521   --  corresponds to the Pos value in the Wide_Character and Character types
522   --  for values that are in appropriate range. String literals are similarly
523   --  interpreted as a sequence of such codes.
524
525   type Char_Code_Base is mod 2 ** 32;
526   for Char_Code_Base'Size use 32;
527
528   subtype Char_Code is Char_Code_Base range 0 .. 16#7FFF_FFFF#;
529   for Char_Code'Value_Size use 32;
530   for Char_Code'Object_Size use 32;
531
532   function Get_Char_Code (C : Character) return Char_Code;
533   pragma Inline (Get_Char_Code);
534   --  Function to obtain internal character code from source character. For
535   --  the moment, the internal character code is simply the Pos value of the
536   --  input source character, but we provide this interface for possible
537   --  later support of alternative character sets.
538
539   function In_Character_Range (C : Char_Code) return Boolean;
540   pragma Inline (In_Character_Range);
541   --  Determines if the given character code is in range of type Character,
542   --  and if so, returns True. If not, returns False.
543
544   function In_Wide_Character_Range (C : Char_Code) return Boolean;
545   pragma Inline (In_Wide_Character_Range);
546   --  Determines if the given character code is in range of the type
547   --  Wide_Character, and if so, returns True. If not, returns False.
548
549   function Get_Character (C : Char_Code) return Character;
550   pragma Inline (Get_Character);
551   --  For a character C that is in Character range (see above function), this
552   --  function returns the corresponding Character value. It is an error to
553   --  call Get_Character if C is not in Character range.
554
555   function Get_Wide_Character (C : Char_Code) return Wide_Character;
556   --  For a character C that is in Wide_Character range (see above function),
557   --  this function returns the corresponding Wide_Character value. It is an
558   --  error to call Get_Wide_Character if C is not in Wide_Character range.
559
560   ---------------------------------------
561   -- Types used for Library Management --
562   ---------------------------------------
563
564   type Unit_Number_Type is new Int range -1 .. Int'Last;
565   --  Unit number. The main source is unit 0, and subsidiary sources have
566   --  non-zero numbers starting with 1. Unit numbers are used to index the
567   --  Units table in package Lib.
568
569   Main_Unit : constant Unit_Number_Type := 0;
570   --  Unit number value for main unit
571
572   No_Unit : constant Unit_Number_Type := -1;
573   --  Special value used to signal no unit
574
575   type Source_File_Index is new Int range -1 .. Int'Last;
576   --  Type used to index the source file table (see package Sinput)
577
578   No_Source_File : constant Source_File_Index := 0;
579   --  Value used to indicate no source file present
580
581   No_Access_To_Source_File : constant Source_File_Index := -1;
582   --  Value used to indicate a source file is present but unreadable
583
584   -----------------------------------
585   -- Representation of Time Stamps --
586   -----------------------------------
587
588   --  All compiled units are marked with a time stamp which is derived from
589   --  the source file (we assume that the host system has the concept of a
590   --  file time stamp which is modified when a file is modified). These
591   --  time stamps are used to ensure consistency of the set of units that
592   --  constitutes a library. Time stamps are 14-character strings with
593   --  with the following format:
594
595   --     YYYYMMDDHHMMSS
596
597   --       YYYY   year
598   --       MM     month (2 digits 01-12)
599   --       DD     day (2 digits 01-31)
600   --       HH     hour (2 digits 00-23)
601   --       MM     minutes (2 digits 00-59)
602   --       SS     seconds (2 digits 00-59)
603
604   --  In the case of Unix systems (and other systems which keep the time in
605   --  GMT), the time stamp is the GMT time of the file, not the local time.
606   --  This solves problems in using libraries across networks with clients
607   --  spread across multiple time-zones.
608
609   Time_Stamp_Length : constant := 14;
610   --  Length of time stamp value
611
612   subtype Time_Stamp_Index is Natural range 1 .. Time_Stamp_Length;
613   type Time_Stamp_Type is new String (Time_Stamp_Index);
614   --  Type used to represent time stamp
615
616   Empty_Time_Stamp : constant Time_Stamp_Type := (others => ' ');
617   --  Value representing an empty or missing time stamp. Looks less than any
618   --  real time stamp if two time stamps are compared. Note that although this
619   --  is not private, clients should not rely on the exact way in which this
620   --  string is represented, and instead should use the subprograms below.
621
622   Dummy_Time_Stamp : constant Time_Stamp_Type := (others => '0');
623   --  This is used for dummy time stamp values used in the D lines for
624   --  non-existent files, and is intended to be an impossible value.
625
626   function "="  (Left, Right : Time_Stamp_Type) return Boolean;
627   function "<=" (Left, Right : Time_Stamp_Type) return Boolean;
628   function ">=" (Left, Right : Time_Stamp_Type) return Boolean;
629   function "<"  (Left, Right : Time_Stamp_Type) return Boolean;
630   function ">"  (Left, Right : Time_Stamp_Type) return Boolean;
631   --  Comparison functions on time stamps. Note that two time stamps are
632   --  defined as being equal if they have the same day/month/year and the
633   --  hour/minutes/seconds values are within 2 seconds of one another. This
634   --  deals with rounding effects in library file time stamps caused by
635   --  copying operations during installation. We have particularly noticed
636   --  that WinNT seems susceptible to such changes.
637   --
638   --  Note: the Empty_Time_Stamp value looks equal to itself, and less than
639   --  any non-empty time stamp value.
640
641   procedure Split_Time_Stamp
642     (TS      : Time_Stamp_Type;
643      Year    : out Nat;
644      Month   : out Nat;
645      Day     : out Nat;
646      Hour    : out Nat;
647      Minutes : out Nat;
648      Seconds : out Nat);
649   --  Given a time stamp, decompose it into its components
650
651   procedure Make_Time_Stamp
652     (Year    : Nat;
653      Month   : Nat;
654      Day     : Nat;
655      Hour    : Nat;
656      Minutes : Nat;
657      Seconds : Nat;
658      TS      : out Time_Stamp_Type);
659   --  Given the components of a time stamp, initialize the value
660
661   -------------------------------------
662   -- Types used for Check Management --
663   -------------------------------------
664
665   type Check_Id is new Nat;
666   --  Type used to represent a check id
667
668   No_Check_Id : constant := 0;
669   --  Check_Id value used to indicate no check
670
671   Access_Check           : constant :=  1;
672   Accessibility_Check    : constant :=  2;
673   Alignment_Check        : constant :=  3;
674   Allocation_Check       : constant :=  4;
675   Atomic_Synchronization : constant :=  5;
676   Discriminant_Check     : constant :=  6;
677   Division_Check         : constant :=  7;
678   Duplicated_Tag_Check   : constant :=  8;
679   Elaboration_Check      : constant :=  9;
680   Index_Check            : constant := 10;
681   Length_Check           : constant := 11;
682   Overflow_Check         : constant := 12;
683   Predicate_Check        : constant := 13;
684   Range_Check            : constant := 14;
685   Storage_Check          : constant := 15;
686   Tag_Check              : constant := 16;
687   Validity_Check         : constant := 17;
688   Container_Checks       : constant := 18;
689   Tampering_Check        : constant := 19;
690   --  Values used to represent individual predefined checks (including the
691   --  setting of Atomic_Synchronization, which is implemented internally using
692   --  a "check" whose name is Atomic_Synchronization).
693
694   All_Checks : constant := 20;
695   --  Value used to represent All_Checks value
696
697   subtype Predefined_Check_Id is Check_Id range 1 .. All_Checks;
698   --  Subtype for predefined checks, including All_Checks
699
700   --  The following array contains an entry for each recognized check name
701   --  for pragma Suppress. It is used to represent current settings of scope
702   --  based suppress actions from pragma Suppress or command line settings.
703
704   --  Note: when Suppress_Array (All_Checks) is True, then generally all other
705   --  specific check entries are set True, except for the Elaboration_Check
706   --  entry which is set only if an explicit Suppress for this check is given.
707   --  The reason for this non-uniformity is that we do not want All_Checks to
708   --  suppress elaboration checking when using the static elaboration model.
709   --  We recognize only an explicit suppress of Elaboration_Check as a signal
710   --  that the static elaboration checking should skip a compile time check.
711
712   type Suppress_Array is array (Predefined_Check_Id) of Boolean;
713   pragma Pack (Suppress_Array);
714
715   --  To add a new check type to GNAT, the following steps are required:
716
717   --    1.  Add an entry to Snames spec for the new name
718   --    2.  Add an entry to the definition of Check_Id above
719   --    3.  Add a new function to Checks to handle the new check test
720   --    4.  Add a new Do_xxx_Check flag to Sinfo (if required)
721   --    5.  Add appropriate checks for the new test
722
723   --  The following provides precise details on the mode used to generate
724   --  code for intermediate operations in expressions for signed integer
725   --  arithmetic (and how to generate overflow checks if enabled). Note
726   --  that this only affects handling of intermediate results. The final
727   --  result must always fit within the target range, and if overflow
728   --  checking is enabled, the check on the final result is against this
729   --  target range.
730
731   type Overflow_Mode_Type is (
732      Not_Set,
733      --  Dummy value used during initialization process to show that the
734      --  corresponding value has not yet been initialized.
735
736      Strict,
737      --  Operations are done in the base type of the subexpression. If
738      --  overflow checks are enabled, then the check is against the range
739      --  of this base type.
740
741      Minimized,
742      --  Where appropriate, intermediate arithmetic operations are performed
743      --  with an extended range, using Long_Long_Integer if necessary. If
744      --  overflow checking is enabled, then the check is against the range
745      --  of Long_Long_Integer.
746
747      Eliminated);
748      --  In this mode arbitrary precision arithmetic is used as needed to
749      --  ensure that it is impossible for intermediate arithmetic to cause an
750      --  overflow. In this mode, intermediate expressions are not affected by
751      --  the overflow checking mode, since overflows are eliminated.
752
753   subtype Minimized_Or_Eliminated is
754     Overflow_Mode_Type range Minimized .. Eliminated;
755   --  Define subtype so that clients don't need to know ordering. Note that
756   --  Overflow_Mode_Type is not marked as an ordered enumeration type.
757
758   --  The following structure captures the state of check suppression or
759   --  activation at a particular point in the program execution.
760
761   type Suppress_Record is record
762      Suppress : Suppress_Array;
763      --  Indicates suppression status of each possible check
764
765      Overflow_Mode_General : Overflow_Mode_Type;
766      --  This field indicates the mode for handling code generation and
767      --  overflow checking (if enabled) for intermediate expression values.
768      --  This applies to general expressions outside assertions.
769
770      Overflow_Mode_Assertions : Overflow_Mode_Type;
771      --  This field indicates the mode for handling code generation and
772      --  overflow checking (if enabled) for intermediate expression values.
773      --  This applies to any expression occuring inside assertions.
774   end record;
775
776   -----------------------------------
777   -- Global Exception Declarations --
778   -----------------------------------
779
780   --  This section contains declarations of exceptions that are used
781   --  throughout the compiler or in other GNAT tools.
782
783   Unrecoverable_Error : exception;
784   --  This exception is raised to immediately terminate the compilation of the
785   --  current source program. Used in situations where things are bad enough
786   --  that it doesn't seem worth continuing (e.g. max errors reached, or a
787   --  required file is not found). Also raised when the compiler finds itself
788   --  in trouble after an error (see Comperr).
789
790   Terminate_Program : exception;
791   --  This exception is raised to immediately terminate the tool being
792   --  executed. Each tool where this exception may be raised must have a
793   --  single exception handler that contains only a null statement and that is
794   --  the last statement of the program. If needed, procedure Set_Exit_Status
795   --  is called with the appropriate exit status before raising
796   --  Terminate_Program.
797
798   ---------------------------------
799   -- Parameter Mechanism Control --
800   ---------------------------------
801
802   --  Function and parameter entities have a field that records the passing
803   --  mechanism. See specification of Sem_Mech for full details. The following
804   --  subtype is used to represent values of this type:
805
806   subtype Mechanism_Type is Int range -2 .. Int'Last;
807   --  Type used to represent a mechanism value. This is a subtype rather than
808   --  a type to avoid some annoying processing problems with certain routines
809   --  in Einfo (processing them to create the corresponding C). The values in
810   --  the range -2 .. 0 are used to represent mechanism types declared as
811   --  named constants in the spec of Sem_Mech. Positive values are used for
812   --  the case of a pragma C_Pass_By_Copy that sets a threshold value for the
813   --  mechanism to be used. For example if pragma C_Pass_By_Copy (32) is given
814   --  then Default_C_Record_Mechanism is set to 32, and the meaning is to use
815   --  By_Reference if the size is greater than 32, and By_Copy otherwise.
816
817   ------------------------------
818   -- Run-Time Exception Codes --
819   ------------------------------
820
821   --  When the code generator generates a run-time exception, it provides a
822   --  reason code which is one of the following. This reason code is used to
823   --  select the appropriate run-time routine to be called, determining both
824   --  the exception to be raised, and the message text to be added.
825
826   --  The prefix CE/PE/SE indicates the exception to be raised
827   --    CE = Constraint_Error
828   --    PE = Program_Error
829   --    SE = Storage_Error
830
831   --  The remaining part of the name indicates the message text to be added,
832   --  where all letters are lower case, and underscores are converted to
833   --  spaces (for example CE_Invalid_Data adds the text "invalid data").
834
835   --  To add a new code, you need to do the following:
836
837   --    1. Assign a new number to the reason. Do not renumber existing codes,
838   --       since this causes compatibility/bootstrap issues, so always add the
839   --       new code at the end of the list.
840
841   --    2. Update the contents of the array Kind
842
843   --    3. Modify the corresponding definitions in types.h, including the
844   --       definition of last_reason_code.
845
846   --    4. Add the name of the routines in exp_ch11.Get_RT_Exception_Name
847
848   --    5. Add a new routine in Ada.Exceptions with the appropriate call and
849   --       static string constant. Note that there is more than one version
850   --       of a-except.adb which must be modified.
851
852   --  Note on ordering of references. For the tables in Ada.Exceptions units,
853   --  usually the ordering does not matter, and we use the same ordering as
854   --  is used here.
855
856   type RT_Exception_Code is
857     (CE_Access_Check_Failed,            -- 00
858      CE_Access_Parameter_Is_Null,       -- 01
859      CE_Discriminant_Check_Failed,      -- 02
860      CE_Divide_By_Zero,                 -- 03
861      CE_Explicit_Raise,                 -- 04
862      CE_Index_Check_Failed,             -- 05
863      CE_Invalid_Data,                   -- 06
864      CE_Length_Check_Failed,            -- 07
865      CE_Null_Exception_Id,              -- 08
866      CE_Null_Not_Allowed,               -- 09
867
868      CE_Overflow_Check_Failed,          -- 10
869      CE_Partition_Check_Failed,         -- 11
870      CE_Range_Check_Failed,             -- 12
871      CE_Tag_Check_Failed,               -- 13
872      PE_Access_Before_Elaboration,      -- 14
873      PE_Accessibility_Check_Failed,     -- 15
874      PE_Address_Of_Intrinsic,           -- 16
875      PE_Aliased_Parameters,             -- 17
876      PE_All_Guards_Closed,              -- 18
877      PE_Bad_Predicated_Generic_Type,    -- 19
878
879      PE_Current_Task_In_Entry_Body,     -- 20
880      PE_Duplicated_Entry_Address,       -- 21
881      PE_Explicit_Raise,                 -- 22
882      PE_Finalize_Raised_Exception,      -- 23
883      PE_Implicit_Return,                -- 24
884      PE_Misaligned_Address_Value,       -- 25
885      PE_Missing_Return,                 -- 26
886      PE_Overlaid_Controlled_Object,     -- 27
887      PE_Potentially_Blocking_Operation, -- 28
888      PE_Stubbed_Subprogram_Called,      -- 29
889
890      PE_Unchecked_Union_Restriction,    -- 30
891      PE_Non_Transportable_Actual,       -- 31
892      SE_Empty_Storage_Pool,             -- 32
893      SE_Explicit_Raise,                 -- 33
894      SE_Infinite_Recursion,             -- 34
895      SE_Object_Too_Large,               -- 35
896      PE_Stream_Operation_Not_Allowed,   -- 36
897      PE_Build_In_Place_Mismatch);       -- 37
898
899   Last_Reason_Code : constant :=
900     RT_Exception_Code'Pos (RT_Exception_Code'Last);
901   --  Last reason code
902
903   type Reason_Kind is (CE_Reason, PE_Reason, SE_Reason);
904   --  Categorization of reason codes by exception raised
905
906   Rkind : constant array (RT_Exception_Code range <>) of Reason_Kind :=
907             (CE_Access_Check_Failed            => CE_Reason,
908              CE_Access_Parameter_Is_Null       => CE_Reason,
909              CE_Discriminant_Check_Failed      => CE_Reason,
910              CE_Divide_By_Zero                 => CE_Reason,
911              CE_Explicit_Raise                 => CE_Reason,
912              CE_Index_Check_Failed             => CE_Reason,
913              CE_Invalid_Data                   => CE_Reason,
914              CE_Length_Check_Failed            => CE_Reason,
915              CE_Null_Exception_Id              => CE_Reason,
916              CE_Null_Not_Allowed               => CE_Reason,
917              CE_Overflow_Check_Failed          => CE_Reason,
918              CE_Partition_Check_Failed         => CE_Reason,
919              CE_Range_Check_Failed             => CE_Reason,
920              CE_Tag_Check_Failed               => CE_Reason,
921
922              PE_Access_Before_Elaboration      => PE_Reason,
923              PE_Accessibility_Check_Failed     => PE_Reason,
924              PE_Address_Of_Intrinsic           => PE_Reason,
925              PE_Aliased_Parameters             => PE_Reason,
926              PE_All_Guards_Closed              => PE_Reason,
927              PE_Bad_Predicated_Generic_Type    => PE_Reason,
928              PE_Current_Task_In_Entry_Body     => PE_Reason,
929              PE_Duplicated_Entry_Address       => PE_Reason,
930              PE_Explicit_Raise                 => PE_Reason,
931              PE_Finalize_Raised_Exception      => PE_Reason,
932              PE_Implicit_Return                => PE_Reason,
933              PE_Misaligned_Address_Value       => PE_Reason,
934              PE_Missing_Return                 => PE_Reason,
935              PE_Overlaid_Controlled_Object     => PE_Reason,
936              PE_Potentially_Blocking_Operation => PE_Reason,
937              PE_Stubbed_Subprogram_Called      => PE_Reason,
938              PE_Unchecked_Union_Restriction    => PE_Reason,
939              PE_Non_Transportable_Actual       => PE_Reason,
940              PE_Stream_Operation_Not_Allowed   => PE_Reason,
941              PE_Build_In_Place_Mismatch        => PE_Reason,
942
943              SE_Empty_Storage_Pool             => SE_Reason,
944              SE_Explicit_Raise                 => SE_Reason,
945              SE_Infinite_Recursion             => SE_Reason,
946              SE_Object_Too_Large               => SE_Reason);
947
948end Types;
949