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