objc-act.c (synth_module_prologue): Use TREE_NO_WARNING instead of DECL_IN_SYSTEM_HEADER.
[official-gcc.git] / gcc / ada / ali-util.adb
blob322ec5ca87c51917553166331f4e03d1d6a622c9
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- A L I . U T I L --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2007, 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. 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Debug; use Debug;
27 with Binderr; use Binderr;
28 with Opt; use Opt;
29 with Output; use Output;
30 with Osint; use Osint;
31 with Scans; use Scans;
32 with Scng;
33 with Sinput.C;
34 with Snames; use Snames;
35 with Styleg;
37 package body ALI.Util is
39 -- Empty procedures needed to instantiate Scng. Error procedures are
40 -- empty, because we don't want to report any errors when computing
41 -- a source checksum.
43 procedure Post_Scan;
45 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr);
47 procedure Error_Msg_S (Msg : String);
49 procedure Error_Msg_SC (Msg : String);
51 procedure Error_Msg_SP (Msg : String);
53 procedure Obsolescent_Check (S : Source_Ptr);
55 -- Instantiation of Styleg, needed to instantiate Scng
57 package Style is new Styleg
58 (Error_Msg, Error_Msg_S, Error_Msg_SC, Error_Msg_SP);
60 -- A Scanner is needed to get checksum of a source (procedure
61 -- Get_File_Checksum).
63 package Scanner is new Scng
64 (Post_Scan, Error_Msg, Error_Msg_S, Error_Msg_SC, Error_Msg_SP,
65 Obsolescent_Check, Style);
67 type Header_Num is range 0 .. 1_000;
69 function Hash (F : File_Name_Type) return Header_Num;
70 -- Function used to compute hash of ALI file name
72 package Interfaces is new Simple_HTable (
73 Header_Num => Header_Num,
74 Element => Boolean,
75 No_Element => False,
76 Key => File_Name_Type,
77 Hash => Hash,
78 Equal => "=");
80 ---------------------
81 -- Checksums_Match --
82 ---------------------
84 function Checksums_Match (Checksum1, Checksum2 : Word) return Boolean is
85 begin
86 return Checksum1 = Checksum2 and then Checksum1 /= Checksum_Error;
87 end Checksums_Match;
89 ---------------
90 -- Error_Msg --
91 ---------------
93 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
94 pragma Warnings (Off, Msg);
95 pragma Warnings (Off, Flag_Location);
96 begin
97 null;
98 end Error_Msg;
100 -----------------
101 -- Error_Msg_S --
102 -----------------
104 procedure Error_Msg_S (Msg : String) is
105 pragma Warnings (Off, Msg);
106 begin
107 null;
108 end Error_Msg_S;
110 ------------------
111 -- Error_Msg_SC --
112 ------------------
114 procedure Error_Msg_SC (Msg : String) is
115 pragma Warnings (Off, Msg);
116 begin
117 null;
118 end Error_Msg_SC;
120 ------------------
121 -- Error_Msg_SP --
122 ------------------
124 procedure Error_Msg_SP (Msg : String) is
125 pragma Warnings (Off, Msg);
126 begin
127 null;
128 end Error_Msg_SP;
130 -----------------------
131 -- Get_File_Checksum --
132 -----------------------
134 function Get_File_Checksum (Fname : File_Name_Type) return Word is
135 Full_Name : File_Name_Type;
136 Source_Index : Source_File_Index;
138 begin
139 Full_Name := Find_File (Fname, Osint.Source);
141 -- If we cannot find the file, then return an impossible checksum,
142 -- impossible becaues checksums have the high order bit zero, so
143 -- that checksums do not match.
145 if Full_Name = No_File then
146 return Checksum_Error;
147 end if;
149 Source_Index := Sinput.C.Load_File (Get_Name_String (Full_Name));
151 if Source_Index = No_Source_File then
152 return Checksum_Error;
153 end if;
155 Scanner.Initialize_Scanner (Source_Index);
157 -- Make sure that the project language reserved words are not
158 -- recognized as reserved words, but as identifiers. The byte info for
159 -- those names have been set if we are in gnatmake.
161 Set_Name_Table_Byte (Name_Project, 0);
162 Set_Name_Table_Byte (Name_Extends, 0);
163 Set_Name_Table_Byte (Name_External, 0);
165 -- Scan the complete file to compute its checksum
167 loop
168 Scanner.Scan;
169 exit when Token = Tok_EOF;
170 end loop;
172 return Scans.Checksum;
173 end Get_File_Checksum;
175 ----------
176 -- Hash --
177 ----------
179 function Hash (F : File_Name_Type) return Header_Num is
180 begin
181 return Header_Num (Int (F) rem Header_Num'Range_Length);
182 end Hash;
184 ---------------------------
185 -- Initialize_ALI_Source --
186 ---------------------------
188 procedure Initialize_ALI_Source is
189 begin
190 -- When (re)initializing ALI data structures the ALI user expects to
191 -- get a fresh set of data structures. Thus we first need to erase the
192 -- marks put in the name table by the previous set of ALI routine calls.
193 -- This loop is empty and harmless the first time in.
195 for J in Source.First .. Source.Last loop
196 Set_Name_Table_Info (Source.Table (J).Sfile, 0);
197 Source.Table (J).Source_Found := False;
198 end loop;
200 Source.Init;
201 Interfaces.Reset;
202 end Initialize_ALI_Source;
204 -----------------------
205 -- Obsolescent_Check --
206 -----------------------
208 procedure Obsolescent_Check (S : Source_Ptr) is
209 pragma Warnings (Off, S);
210 begin
211 null;
212 end Obsolescent_Check;
214 ---------------
215 -- Post_Scan --
216 ---------------
218 procedure Post_Scan is
219 begin
220 null;
221 end Post_Scan;
223 --------------
224 -- Read_ALI --
225 --------------
227 procedure Read_ALI (Id : ALI_Id) is
228 Afile : File_Name_Type;
229 Text : Text_Buffer_Ptr;
230 Idread : ALI_Id;
232 begin
233 -- Process all dependent units
235 for U in ALIs.Table (Id).First_Unit .. ALIs.Table (Id).Last_Unit loop
237 W in Units.Table (U).First_With .. Units.Table (U).Last_With
238 loop
239 Afile := Withs.Table (W).Afile;
241 -- Only process if not a generic (Afile /= No_File) and if
242 -- file has not been processed already.
244 if Afile /= No_File
245 and then Get_Name_Table_Info (Afile) = 0
246 then
247 Text := Read_Library_Info (Afile);
249 -- Return with an error if source cannot be found. We used to
250 -- skip this check when we did not compile library generics
251 -- separately, but we now always do, so there is no special
252 -- case here anymore.
254 if Text = null then
255 Error_Msg_File_1 := Afile;
256 Error_Msg_File_2 := Withs.Table (W).Sfile;
257 Error_Msg ("{ not found, { must be compiled");
258 Set_Name_Table_Info (Afile, Int (No_Unit_Id));
259 return;
260 end if;
262 -- Enter in ALIs table
264 Idread :=
265 Scan_ALI
266 (F => Afile,
267 T => Text,
268 Ignore_ED => False,
269 Err => False);
271 Free (Text);
273 if ALIs.Table (Idread).Compile_Errors then
274 Error_Msg_File_1 := Withs.Table (W).Sfile;
275 Error_Msg ("{ had errors, must be fixed, and recompiled");
276 Set_Name_Table_Info (Afile, Int (No_Unit_Id));
278 elsif ALIs.Table (Idread).No_Object then
279 Error_Msg_File_1 := Withs.Table (W).Sfile;
280 Error_Msg ("{ must be recompiled");
281 Set_Name_Table_Info (Afile, Int (No_Unit_Id));
282 end if;
284 -- If the Unit is an Interface to a Stand-Alone Library,
285 -- set the Interface flag in the Withs table, so that its
286 -- dependant are not considered for elaboration order.
288 if ALIs.Table (Idread).SAL_Interface then
289 Withs.Table (W).SAL_Interface := True;
290 Interface_Library_Unit := True;
292 -- Set the entry in the Interfaces hash table, so that other
293 -- units that import this unit will set the flag in their
294 -- entry in the Withs table.
296 Interfaces.Set (Afile, True);
298 else
299 -- Otherwise, recurse to get new dependents
301 Read_ALI (Idread);
302 end if;
304 -- If the ALI file has already been processed and is an interface,
305 -- set the flag in the entry of the Withs table.
307 elsif Interface_Library_Unit and then Interfaces.Get (Afile) then
308 Withs.Table (W).SAL_Interface := True;
309 end if;
310 end loop;
311 end loop;
312 end Read_ALI;
314 ----------------------
315 -- Set_Source_Table --
316 ----------------------
318 procedure Set_Source_Table (A : ALI_Id) is
319 F : File_Name_Type;
320 S : Source_Id;
321 Stamp : Time_Stamp_Type;
323 begin
324 Sdep_Loop : for D in
325 ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep
326 loop
327 F := Sdep.Table (D).Sfile;
329 if F /= No_File then
331 -- If this is the first time we are seeing this source file,
332 -- then make a new entry in the source table.
334 if Get_Name_Table_Info (F) = 0 then
335 Source.Increment_Last;
336 S := Source.Last;
337 Set_Name_Table_Info (F, Int (S));
338 Source.Table (S).Sfile := F;
339 Source.Table (S).All_Timestamps_Match := True;
341 -- Initialize checksum fields
343 Source.Table (S).Checksum := Sdep.Table (D).Checksum;
344 Source.Table (S).All_Checksums_Match := True;
346 -- In check source files mode, try to get time stamp from file
348 if Opt.Check_Source_Files then
349 Stamp := Source_File_Stamp (F);
351 -- If we got the stamp, then set the stamp in the source
352 -- table entry and mark it as set from the source so that
353 -- it does not get subsequently changed.
355 if Stamp (Stamp'First) /= ' ' then
356 Source.Table (S).Stamp := Stamp;
357 Source.Table (S).Source_Found := True;
359 -- If we could not find the file, then the stamp is set
360 -- from the dependency table entry (to be possibly reset
361 -- if we find a later stamp in subsequent processing)
363 else
364 Source.Table (S).Stamp := Sdep.Table (D).Stamp;
365 Source.Table (S).Source_Found := False;
367 -- In All_Sources mode, flag error of file not found
369 if Opt.All_Sources then
370 Error_Msg_File_1 := F;
371 Error_Msg ("cannot locate {");
372 end if;
373 end if;
375 -- First time for this source file, but Check_Source_Files
376 -- is off, so simply initialize the stamp from the Sdep entry
378 else
379 Source.Table (S).Source_Found := False;
380 Source.Table (S).Stamp := Sdep.Table (D).Stamp;
381 end if;
383 -- Here if this is not the first time for this source file,
384 -- so that the source table entry is already constructed.
386 else
387 S := Source_Id (Get_Name_Table_Info (F));
389 -- Update checksum flag
391 if not Checksums_Match
392 (Sdep.Table (D).Checksum, Source.Table (S).Checksum)
393 then
394 Source.Table (S).All_Checksums_Match := False;
395 end if;
397 -- Check for time stamp mismatch
399 if Sdep.Table (D).Stamp /= Source.Table (S).Stamp then
400 Source.Table (S).All_Timestamps_Match := False;
402 -- When we have a time stamp mismatch, we go look for the
403 -- source file even if Check_Source_Files is false, since
404 -- if we find it, then we can use it to resolve which of the
405 -- two timestamps in the ALI files is likely to be correct.
407 if not Check_Source_Files then
408 Stamp := Source_File_Stamp (F);
410 if Stamp (Stamp'First) /= ' ' then
411 Source.Table (S).Stamp := Stamp;
412 Source.Table (S).Source_Found := True;
413 end if;
414 end if;
416 -- If the stamp in the source table entry was set from the
417 -- source file, then we do not change it (the stamp in the
418 -- source file is always taken as the "right" one).
420 if Source.Table (S).Source_Found then
421 null;
423 -- Otherwise, we have no source file available, so we guess
424 -- that the later of the two timestamps is the right one.
425 -- Note that this guess only affects which error messages
426 -- are issued later on, not correct functionality.
428 else
429 if Sdep.Table (D).Stamp > Source.Table (S).Stamp then
430 Source.Table (S).Stamp := Sdep.Table (D).Stamp;
431 end if;
432 end if;
433 end if;
434 end if;
436 -- Set the checksum value in the source table
438 S := Source_Id (Get_Name_Table_Info (F));
439 Source.Table (S).Checksum := Sdep.Table (D).Checksum;
440 end if;
442 end loop Sdep_Loop;
443 end Set_Source_Table;
445 ----------------------
446 -- Set_Source_Table --
447 ----------------------
449 procedure Set_Source_Table is
450 begin
451 for A in ALIs.First .. ALIs.Last loop
452 Set_Source_Table (A);
453 end loop;
454 end Set_Source_Table;
456 -------------------------
457 -- Time_Stamp_Mismatch --
458 -------------------------
460 function Time_Stamp_Mismatch
461 (A : ALI_Id;
462 Read_Only : Boolean := False) return File_Name_Type
464 Src : Source_Id;
465 -- Source file Id for the current Sdep entry
467 begin
468 for D in ALIs.Table (A).First_Sdep .. ALIs.Table (A).Last_Sdep loop
469 Src := Source_Id (Get_Name_Table_Info (Sdep.Table (D).Sfile));
471 if Opt.Minimal_Recompilation
472 and then Sdep.Table (D).Stamp /= Source.Table (Src).Stamp
473 then
474 -- If minimal recompilation is in action, replace the stamp
475 -- of the source file in the table if checksums match.
477 -- ??? It is probably worth updating the ALI file with a new
478 -- field to avoid recomputing it each time.
480 if Checksums_Match
481 (Get_File_Checksum (Sdep.Table (D).Sfile),
482 Source.Table (Src).Checksum)
483 then
484 Sdep.Table (D).Stamp := Source.Table (Src).Stamp;
485 end if;
487 end if;
489 if (not Read_Only) or else Source.Table (Src).Source_Found then
490 if not Source.Table (Src).Source_Found
491 or else Sdep.Table (D).Stamp /= Source.Table (Src).Stamp
492 then
493 -- If -t debug flag set, output time stamp found/expected
495 if Source.Table (Src).Source_Found and Debug_Flag_T then
496 Write_Str ("Source: """);
497 Get_Name_String (Sdep.Table (D).Sfile);
498 Write_Str (Name_Buffer (1 .. Name_Len));
499 Write_Line ("""");
501 Write_Str (" time stamp expected: ");
502 Write_Line (String (Sdep.Table (D).Stamp));
504 Write_Str (" time stamp found: ");
505 Write_Line (String (Source.Table (Src).Stamp));
506 end if;
508 -- Return the source file
510 return Source.Table (Src).Sfile;
511 end if;
512 end if;
513 end loop;
515 return No_File;
516 end Time_Stamp_Mismatch;
518 end ALI.Util;