1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 -- This child unit provides utility data structures and procedures used
30 -- for manipulation of ALI data by the gnatbind and gnatmake.
34 -----------------------
35 -- Source File Table --
36 -----------------------
38 -- A source file table entry is built for every source file that is
39 -- in the source dependency table of any of the ALI files that make
40 -- up the current program.
42 No_Source_Id
: constant Source_Id
:= Source_Id
'First;
43 -- Special value indicating no Source table entry
45 First_Source_Entry
: constant Source_Id
:= No_Source_Id
+ 1;
46 -- Id of first actual entry in table
48 type Source_Record
is record
50 Sfile
: File_Name_Type
;
51 -- Name of source file
53 Stamp
: Time_Stamp_Type
;
54 -- Time stamp value. If Check_Source_Files is set and the source
55 -- file is located, then Stamp is set from the source file. Otherwise
56 -- Stamp is set from the latest stamp value found in any of the
57 -- ALI files for the current program.
59 Source_Found
: Boolean;
60 -- This flag is set to True if the corresponding source file was
61 -- located and the Stamp value was set from the actual source file.
62 -- It is always false if Check_Source_Files is not set.
64 All_Timestamps_Match
: Boolean;
65 -- This flag is set only if all files referencing this source file
66 -- have a matching time stamp, and also, if Source_Found is True,
67 -- then the stamp of the source file also matches. If this flag is
68 -- True, then checksums for this file are never referenced. We only
69 -- use checksums if there are time stamp mismatches.
71 All_Checksums_Match
: Boolean;
72 -- This flag is set only if all files referencing this source file
73 -- have checksums, and if all these checksums match. If this flag
74 -- is set to True, then the binder will ignore a timestamp mismatch.
75 -- An absent checksum causes this flag to be set False, and a mismatch
76 -- of checksums also causes it to be set False. The checksum of the
77 -- actual source file (if Source_Found is True) is included only if
78 -- All_Timestamps_Match is False (since checksums are only interesting
79 -- if we have time stamp mismatches, and we want to avoid computing the
80 -- checksum of the source file if it is not needed.)
83 -- If no dependency line has a checksum for this source file (i.e. the
84 -- corresponding entries in the source dependency records all have the
85 -- Checksum_Present flag set False), then this field is undefined. If
86 -- at least one dependency entry has a checksum present, then this
87 -- field contains one of the possible checksum values that has been
88 -- seen. This is used to set All_Checksums_Match properly.
92 package Source
is new Table
.Table
(
93 Table_Component_Type
=> Source_Record
,
94 Table_Index_Type
=> Source_Id
,
95 Table_Low_Bound
=> First_Source_Entry
,
96 Table_Initial
=> 1000,
97 Table_Increment
=> 200,
98 Table_Name
=> "Source");
100 procedure Initialize_ALI_Source
;
101 -- Initialize Source table
103 --------------------------------------------------
104 -- Subprograms for Manipulating ALI Information --
105 --------------------------------------------------
107 procedure Read_ALI
(Id
: ALI_Id
);
108 -- Process an ALI file which has been read and scanned by looping
109 -- through all withed units in the ALI file; checking if they have
110 -- been processed; and for each that hasn't, reading, scanning, and
111 -- recursively processing.
113 procedure Set_Source_Table
(A
: ALI_Id
);
114 -- Build source table entry corresponding to the ALI file whose id is A.
116 procedure Set_Source_Table
;
117 -- Build the entire source table.
119 function Time_Stamp_Mismatch
(A
: ALI_Id
) return File_Name_Type
;
120 -- Looks in the Source_Table and checks time stamp mismatches between
121 -- the sources there and the sources in the Sdep section of ali file whose
122 -- id is A. If no time stamp mismatches are found No_File is returned.
123 -- Otherwise return the first file for which there is a mismatch.
124 -- Note that in check source files mode (Check_Source_Files = True), the
125 -- time stamp in the Source_Table should be the actual time stamp of the
126 -- source files. In minimal recompilation mode (Minimal_Recompilation set
127 -- to True, no mismatch is found if the file's timestamp has not changed.
129 --------------------------------------------
130 -- Subprograms for manipulating checksums --
131 --------------------------------------------
133 Checksum_Error
: constant Word
:= 16#FFFF_FFFF#
;
134 -- This value is used to indicate an error in computing the checksum.
135 -- When comparing checksums for smart recompilation, the CRC_Error
136 -- value is never considered to match. This could possibly result
137 -- in a false negative, but that is never harmful, it just means
138 -- that in unusual cases an unnecessary recompilation occurs.
140 function Get_File_Checksum
(Fname
: Name_Id
) return Word
;
141 -- Compute checksum for the given file. As far as possible, this circuit
142 -- computes exactly the same value computed by the compiler, but it does
143 -- not matter if it gets it wrong in marginal cases, since the only result
144 -- is to miss some smart recompilation cases, correct functioning is not
145 -- affected by a miscomputation. Returns Checksum_Error if the file is
146 -- missing or has an error.
148 function Checksums_Match
(Checksum1
, Checksum2
: Word
) return Boolean;
149 pragma Inline
(Checksums_Match
);
150 -- Returns True if Checksum1 and Checksum2 have the same value and are
151 -- not equal to Checksum_Error, returns False in all other cases. This
152 -- routine must always be used to compare for checksum equality, to
153 -- ensure that the case of Checksum_Error is handled properly.