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