]>
Commit | Line | Data |
---|---|---|
d23b8f57 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- A L I . U T I L -- | |
6 | -- -- | |
7 | -- S p e c -- | |
8 | -- -- | |
1d005acc | 9 | -- Copyright (C) 1992-2019, Free Software Foundation, Inc. -- |
d23b8f57 RK |
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- -- | |
b5c84c3c | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
d23b8f57 RK |
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. See the GNU General Public License -- | |
17 | -- for more details. You should have received a copy of the GNU General -- | |
b5c84c3c RD |
18 | -- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
19 | -- http://www.gnu.org/licenses for a complete copy of the license. -- | |
d23b8f57 RK |
20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
d23b8f57 RK |
23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
26 | -- This child unit provides utility data structures and procedures used | |
ed3fe8cc | 27 | -- for manipulation of ALI data by gnatbind and gnatmake. |
d23b8f57 RK |
28 | |
29 | package ALI.Util is | |
30 | ||
31 | ----------------------- | |
32 | -- Source File Table -- | |
33 | ----------------------- | |
34 | ||
b2cacbfe AC |
35 | -- A table entry is built for every source file that is in the source |
36 | -- dependency table of any ALI file that is part of the current program. | |
d23b8f57 RK |
37 | |
38 | No_Source_Id : constant Source_Id := Source_Id'First; | |
39 | -- Special value indicating no Source table entry | |
40 | ||
41 | First_Source_Entry : constant Source_Id := No_Source_Id + 1; | |
42 | -- Id of first actual entry in table | |
43 | ||
44 | type Source_Record is record | |
45 | ||
46 | Sfile : File_Name_Type; | |
47 | -- Name of source file | |
48 | ||
49 | Stamp : Time_Stamp_Type; | |
50 | -- Time stamp value. If Check_Source_Files is set and the source | |
51 | -- file is located, then Stamp is set from the source file. Otherwise | |
52 | -- Stamp is set from the latest stamp value found in any of the | |
53 | -- ALI files for the current program. | |
54 | ||
55 | Source_Found : Boolean; | |
56 | -- This flag is set to True if the corresponding source file was | |
57 | -- located and the Stamp value was set from the actual source file. | |
58 | -- It is always false if Check_Source_Files is not set. | |
59 | ||
b546e2a7 AC |
60 | Stamp_File : File_Name_Type; |
61 | -- File that Stamp came from. If Source_Found is True, then Stamp is the | |
62 | -- timestamp of the source file, and this is the name of the source | |
63 | -- file. If Source_Found is False, then Stamp comes from a dependency | |
64 | -- line in an ALI file, this is the name of that ALI file. Used only in | |
65 | -- verbose mode, for messages. | |
66 | ||
d23b8f57 RK |
67 | All_Timestamps_Match : Boolean; |
68 | -- This flag is set only if all files referencing this source file | |
69 | -- have a matching time stamp, and also, if Source_Found is True, | |
70 | -- then the stamp of the source file also matches. If this flag is | |
71 | -- True, then checksums for this file are never referenced. We only | |
72 | -- use checksums if there are time stamp mismatches. | |
73 | ||
74 | All_Checksums_Match : Boolean; | |
75 | -- This flag is set only if all files referencing this source file | |
76 | -- have checksums, and if all these checksums match. If this flag | |
77 | -- is set to True, then the binder will ignore a timestamp mismatch. | |
78 | -- An absent checksum causes this flag to be set False, and a mismatch | |
79 | -- of checksums also causes it to be set False. The checksum of the | |
80 | -- actual source file (if Source_Found is True) is included only if | |
81 | -- All_Timestamps_Match is False (since checksums are only interesting | |
82 | -- if we have time stamp mismatches, and we want to avoid computing the | |
83 | -- checksum of the source file if it is not needed.) | |
84 | ||
85 | Checksum : Word; | |
86 | -- If no dependency line has a checksum for this source file (i.e. the | |
87 | -- corresponding entries in the source dependency records all have the | |
88 | -- Checksum_Present flag set False), then this field is undefined. If | |
89 | -- at least one dependency entry has a checksum present, then this | |
90 | -- field contains one of the possible checksum values that has been | |
91 | -- seen. This is used to set All_Checksums_Match properly. | |
92 | ||
93 | end record; | |
94 | ||
95 | package Source is new Table.Table ( | |
96 | Table_Component_Type => Source_Record, | |
97 | Table_Index_Type => Source_Id, | |
98 | Table_Low_Bound => First_Source_Entry, | |
99 | Table_Initial => 1000, | |
100 | Table_Increment => 200, | |
101 | Table_Name => "Source"); | |
102 | ||
103 | procedure Initialize_ALI_Source; | |
104 | -- Initialize Source table | |
105 | ||
106 | -------------------------------------------------- | |
107 | -- Subprograms for Manipulating ALI Information -- | |
108 | -------------------------------------------------- | |
109 | ||
92167df3 | 110 | procedure Read_Withed_ALIs (Id : ALI_Id); |
6c994759 AC |
111 | -- Process an ALI file which has been read and scanned by looping through |
112 | -- all withed units in the ALI file, checking if they have been processed. | |
113 | -- Each unit that has not yet been processed will be read, scanned, and | |
92167df3 PT |
114 | -- processed recursively. In GNATprove mode a failure to read an ALI file |
115 | -- is not reported as an error, and scanning continues with other ALI | |
116 | -- files. | |
d23b8f57 RK |
117 | |
118 | procedure Set_Source_Table (A : ALI_Id); | |
39f4e199 | 119 | -- Build source table entry corresponding to the ALI file whose id is A |
d23b8f57 RK |
120 | |
121 | procedure Set_Source_Table; | |
39f4e199 | 122 | -- Build the entire source table |
d23b8f57 | 123 | |
fbf5a39b AC |
124 | function Time_Stamp_Mismatch |
125 | (A : ALI_Id; | |
39f4e199 | 126 | Read_Only : Boolean := False) return File_Name_Type; |
d23b8f57 RK |
127 | -- Looks in the Source_Table and checks time stamp mismatches between |
128 | -- the sources there and the sources in the Sdep section of ali file whose | |
129 | -- id is A. If no time stamp mismatches are found No_File is returned. | |
130 | -- Otherwise return the first file for which there is a mismatch. | |
131 | -- Note that in check source files mode (Check_Source_Files = True), the | |
132 | -- time stamp in the Source_Table should be the actual time stamp of the | |
133 | -- source files. In minimal recompilation mode (Minimal_Recompilation set | |
134 | -- to True, no mismatch is found if the file's timestamp has not changed. | |
fbf5a39b | 135 | -- If Read_Only is True, missing sources are not considered. |
d23b8f57 RK |
136 | |
137 | -------------------------------------------- | |
138 | -- Subprograms for manipulating checksums -- | |
139 | -------------------------------------------- | |
140 | ||
cfac6e9f PO |
141 | Checksum_Error : constant Word := 16#FFFF_FFFF#; |
142 | -- This value is used to indicate an error in computing the checksum. | |
143 | -- When comparing checksums for smart recompilation, the CRC_Error | |
144 | -- value is never considered to match. This could possibly result | |
145 | -- in a false negative, but that is never harmful, it just means | |
146 | -- that in unusual cases an unnecessary recompilation occurs. | |
147 | ||
39f4e199 | 148 | function Get_File_Checksum (Fname : File_Name_Type) return Word; |
d23b8f57 RK |
149 | -- Compute checksum for the given file. As far as possible, this circuit |
150 | -- computes exactly the same value computed by the compiler, but it does | |
151 | -- not matter if it gets it wrong in marginal cases, since the only result | |
152 | -- is to miss some smart recompilation cases, correct functioning is not | |
cfac6e9f PO |
153 | -- affected by a miscomputation. Returns Checksum_Error if the file is |
154 | -- missing or has an error. | |
155 | ||
156 | function Checksums_Match (Checksum1, Checksum2 : Word) return Boolean; | |
157 | pragma Inline (Checksums_Match); | |
158 | -- Returns True if Checksum1 and Checksum2 have the same value and are | |
159 | -- not equal to Checksum_Error, returns False in all other cases. This | |
160 | -- routine must always be used to compare for checksum equality, to | |
161 | -- ensure that the case of Checksum_Error is handled properly. | |
d23b8f57 RK |
162 | |
163 | end ALI.Util; |