2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / ada / xref_lib.adb
blobcca42856270b5d60f3727ce1730db7c06351f720
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- X R E F _ L I B --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1998-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 ------------------------------------------------------------------------------
27 with Osint;
28 with Output; use Output;
29 with Types; use Types;
31 with Unchecked_Deallocation;
33 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
34 with Ada.Text_IO; use Ada.Text_IO;
36 with GNAT.Command_Line; use GNAT.Command_Line;
37 with GNAT.IO_Aux; use GNAT.IO_Aux;
39 package body Xref_Lib is
41 Type_Position : constant := 50;
42 -- Column for label identifying type of entity
44 ---------------------
45 -- Local Variables --
46 ---------------------
48 Pipe : constant Character := '|';
49 -- First character on xref lines in the .ali file
51 No_Xref_Information : exception;
52 -- Exception raised when there is no cross-referencing information in
53 -- the .ali files
55 procedure Parse_EOL
56 (Source : access String;
57 Ptr : in out Positive;
58 Skip_Continuation_Line : Boolean := False);
59 -- On return Source (Ptr) is the first character of the next line
60 -- or EOF. Source.all must be terminated by EOF.
62 -- If Skip_Continuation_Line is True, this subprogram skips as many
63 -- lines as required when the second or more lines starts with '.'
64 -- (continuation lines in ALI files).
66 function Current_Xref_File (File : ALI_File) return File_Reference;
67 -- Return the file matching the last 'X' line we found while parsing
68 -- the ALI file.
70 function File_Name (File : ALI_File; Num : Positive) return File_Reference;
71 -- Returns the dependency file name number Num
73 function Get_Full_Type (Decl : Declaration_Reference) return String;
74 -- Returns the full type corresponding to a type letter as found in
75 -- the .ali files.
77 procedure Open
78 (Name : in String;
79 File : out ALI_File;
80 Dependencies : in Boolean := False);
81 -- Open a new ALI file. If Dependencies is True, the insert every library
82 -- file 'with'ed in the files database (used for gnatxref)
84 procedure Parse_Identifier_Info
85 (Pattern : Search_Pattern;
86 File : in out ALI_File;
87 Local_Symbols : Boolean;
88 Der_Info : Boolean := False;
89 Type_Tree : Boolean := False;
90 Wide_Search : Boolean := True;
91 Labels_As_Ref : Boolean := True);
92 -- Output the file and the line where the identifier was referenced,
93 -- If Local_Symbols is False then only the publicly visible symbols
94 -- will be processed.
96 -- If Labels_As_Ref is true, then the references to the entities after
97 -- the end statements ("end Foo") will be counted as actual references.
98 -- The entity will never be reported as unreferenced by gnatxref -u
100 procedure Parse_Token
101 (Source : access String;
102 Ptr : in out Positive;
103 Token_Ptr : out Positive);
104 -- Skips any separators and stores the start of the token in Token_Ptr.
105 -- Then stores the position of the next separator in Ptr. On return
106 -- Source (Token_Ptr .. Ptr - 1) is the token. Separators are space
107 -- and ASCII.HT. Parse_Token will never skip to the next line.
109 procedure Parse_Number
110 (Source : access String;
111 Ptr : in out Positive;
112 Number : out Natural);
113 -- Skips any separators and parses Source upto the first character that
114 -- is not a decimal digit. Returns value of parsed digits or 0 if none.
116 procedure Parse_X_Filename (File : in out ALI_File);
117 -- Reads and processes "X..." lines in the ALI file
118 -- and updates the File.X_File information.
120 procedure Skip_To_First_X_Line
121 (File : in out ALI_File;
122 D_Lines : Boolean;
123 W_Lines : Boolean);
124 -- Skip the lines in the ALI file until the first cross-reference line
125 -- (^X...) is found. Search is started from the beginning of the file.
126 -- If not such line is found, No_Xref_Information is raised.
127 -- If W_Lines is false, then the lines "^W" are not parsed.
128 -- If D_Lines is false, then the lines "^D" are not parsed.
130 ----------------
131 -- Add_Entity --
132 ----------------
134 procedure Add_Entity
135 (Pattern : in out Search_Pattern;
136 Entity : String;
137 Glob : Boolean := False)
139 File_Start : Natural;
140 Line_Start : Natural;
141 Col_Start : Natural;
142 Line_Num : Natural := 0;
143 Col_Num : Natural := 0;
144 File_Ref : File_Reference := Empty_File;
145 Has_Pattern : Boolean := False;
147 begin
148 -- Find the end of the first item in Entity (pattern or file?)
149 -- If there is no ':', we only have a pattern
151 File_Start := Index (Entity, ":");
153 -- If the regular expression is invalid, just consider it as a string
155 if File_Start = 0 then
156 begin
157 Pattern.Entity := Compile (Entity, Glob, False);
158 Pattern.Initialized := True;
160 exception
161 when Error_In_Regexp =>
163 -- The basic idea is to insert a \ before every character
165 declare
166 Tmp_Regexp : String (1 .. 2 * Entity'Length);
167 Index : Positive := 1;
169 begin
170 for J in Entity'Range loop
171 Tmp_Regexp (Index) := '\';
172 Tmp_Regexp (Index + 1) := Entity (J);
173 Index := Index + 2;
174 end loop;
176 Pattern.Entity := Compile (Tmp_Regexp, True, False);
177 Pattern.Initialized := True;
178 end;
179 end;
181 Set_Default_Match (True);
182 return;
183 end if;
185 -- If there is a dot in the pattern, then it is a file name
187 if (Glob and then
188 Index (Entity (Entity'First .. File_Start - 1), ".") /= 0)
189 or else
190 (not Glob
191 and then Index (Entity (Entity'First .. File_Start - 1),
192 "\.") /= 0)
193 then
194 Pattern.Entity := Compile (".*", False);
195 Pattern.Initialized := True;
196 File_Start := Entity'First;
198 else
199 -- If the regular expression is invalid, just consider it as a string
201 begin
202 Pattern.Entity :=
203 Compile (Entity (Entity'First .. File_Start - 1), Glob, False);
204 Pattern.Initialized := True;
206 exception
207 when Error_In_Regexp =>
209 -- The basic idea is to insert a \ before every character
211 declare
212 Tmp_Regexp : String (1 .. 2 * (File_Start - Entity'First));
213 Index : Positive := 1;
215 begin
216 for J in Entity'First .. File_Start - 1 loop
217 Tmp_Regexp (Index) := '\';
218 Tmp_Regexp (Index + 1) := Entity (J);
219 Index := Index + 2;
220 end loop;
222 Pattern.Entity := Compile (Tmp_Regexp, True, False);
223 Pattern.Initialized := True;
224 end;
225 end;
227 File_Start := File_Start + 1;
228 Has_Pattern := True;
229 end if;
231 -- Parse the file name
233 Line_Start := Index (Entity (File_Start .. Entity'Last), ":");
235 -- Check if it was a disk:\directory item (for NT and OS/2)
237 if File_Start = Line_Start - 1
238 and then Line_Start < Entity'Last
239 and then Entity (Line_Start + 1) = '\'
240 then
241 Line_Start := Index (Entity (Line_Start + 1 .. Entity'Last), ":");
242 end if;
244 if Line_Start = 0 then
245 Line_Start := Entity'Length + 1;
247 elsif Line_Start /= Entity'Last then
248 Col_Start := Index (Entity (Line_Start + 1 .. Entity'Last), ":");
250 if Col_Start = 0 then
251 Col_Start := Entity'Last + 1;
252 end if;
254 if Col_Start > Line_Start + 1 then
255 begin
256 Line_Num := Natural'Value
257 (Entity (Line_Start + 1 .. Col_Start - 1));
259 exception
260 when Constraint_Error =>
261 raise Invalid_Argument;
262 end;
263 end if;
265 if Col_Start < Entity'Last then
266 begin
267 Col_Num := Natural'Value (Entity
268 (Col_Start + 1 .. Entity'Last));
270 exception
271 when Constraint_Error => raise Invalid_Argument;
272 end;
273 end if;
274 end if;
276 File_Ref :=
277 Add_To_Xref_File
278 (Entity (File_Start .. Line_Start - 1), Visited => True);
279 Pattern.File_Ref := File_Ref;
280 Add_Line (Pattern.File_Ref, Line_Num, Col_Num);
281 File_Ref :=
282 Add_To_Xref_File
283 (ALI_File_Name (Entity (File_Start .. Line_Start - 1)),
284 Visited => False,
285 Emit_Warning => True);
286 end Add_Entity;
288 -------------------
289 -- Add_Xref_File --
290 -------------------
292 procedure Add_Xref_File (File : String) is
293 File_Ref : File_Reference := Empty_File;
294 Iterator : Expansion_Iterator;
296 procedure Add_Xref_File_Internal (File : String);
297 -- Do the actual addition of the file
299 ----------------------------
300 -- Add_Xref_File_Internal --
301 ----------------------------
303 procedure Add_Xref_File_Internal (File : String) is
304 begin
305 -- Case where we have an ALI file, accept it even though this is
306 -- not official usage, since the intention is obvious
308 if Tail (File, 4) = ".ali" then
309 File_Ref := Add_To_Xref_File
310 (File, Visited => False, Emit_Warning => True);
312 -- Normal non-ali file case
314 else
315 File_Ref := Add_To_Xref_File (File, Visited => True);
317 File_Ref := Add_To_Xref_File
318 (ALI_File_Name (File),
319 Visited => False,
320 Emit_Warning => True);
321 end if;
322 end Add_Xref_File_Internal;
324 -- Start of processing for Add_Xref_File
326 begin
327 -- Check if we need to do the expansion
329 if Ada.Strings.Fixed.Index (File, "*") /= 0
330 or else Ada.Strings.Fixed.Index (File, "?") /= 0
331 then
332 Start_Expansion (Iterator, File);
334 loop
335 declare
336 S : constant String := Expansion (Iterator);
338 begin
339 exit when S'Length = 0;
340 Add_Xref_File_Internal (S);
341 end;
342 end loop;
344 else
345 Add_Xref_File_Internal (File);
346 end if;
347 end Add_Xref_File;
349 -----------------------
350 -- Current_Xref_File --
351 -----------------------
353 function Current_Xref_File (File : ALI_File) return File_Reference is
354 begin
355 return File.X_File;
356 end Current_Xref_File;
358 --------------------------
359 -- Default_Project_File --
360 --------------------------
362 function Default_Project_File (Dir_Name : String) return String is
363 My_Dir : Dir_Type;
364 Dir_Ent : File_Name_String;
365 Last : Natural;
367 begin
368 Open (My_Dir, Dir_Name);
370 loop
371 Read (My_Dir, Dir_Ent, Last);
372 exit when Last = 0;
374 if Tail (Dir_Ent (1 .. Last), 4) = ".adp" then
376 -- The first project file found is the good one.
378 Close (My_Dir);
379 return Dir_Ent (1 .. Last);
380 end if;
381 end loop;
383 Close (My_Dir);
384 return String'(1 .. 0 => ' ');
386 exception
387 when Directory_Error => return String'(1 .. 0 => ' ');
388 end Default_Project_File;
390 ---------------
391 -- File_Name --
392 ---------------
394 function File_Name
395 (File : ALI_File;
396 Num : Positive) return File_Reference
398 begin
399 return File.Dep.Table (Num);
400 end File_Name;
402 --------------------
403 -- Find_ALI_Files --
404 --------------------
406 procedure Find_ALI_Files is
407 My_Dir : Rec_DIR;
408 Dir_Ent : File_Name_String;
409 Last : Natural;
410 File_Ref : File_Reference;
412 function Open_Next_Dir return Boolean;
413 -- Tries to open the next object directory, and return False if
414 -- the directory cannot be opened.
416 -------------------
417 -- Open_Next_Dir --
418 -------------------
420 function Open_Next_Dir return Boolean is
421 begin
422 -- Until we are able to open a new directory
424 loop
425 declare
426 Obj_Dir : constant String := Next_Obj_Dir;
428 begin
429 -- Case of no more Obj_Dir lines
431 if Obj_Dir'Length = 0 then
432 return False;
433 end if;
435 Open (My_Dir.Dir, Obj_Dir);
436 exit;
438 exception
440 -- Could not open the directory
442 when Directory_Error => null;
443 end;
444 end loop;
446 return True;
447 end Open_Next_Dir;
449 -- Start of processing for Find_ALI_Files
451 begin
452 Reset_Obj_Dir;
454 if Open_Next_Dir then
455 loop
456 Read (My_Dir.Dir, Dir_Ent, Last);
458 if Last = 0 then
459 Close (My_Dir.Dir);
461 if not Open_Next_Dir then
462 return;
463 end if;
465 elsif Last > 4 and then Dir_Ent (Last - 3 .. Last) = ".ali" then
466 File_Ref :=
467 Add_To_Xref_File (Dir_Ent (1 .. Last), Visited => False);
468 end if;
469 end loop;
470 end if;
471 end Find_ALI_Files;
473 -------------------
474 -- Get_Full_Type --
475 -------------------
477 function Get_Full_Type (Decl : Declaration_Reference) return String is
479 function Param_String return String;
480 -- Return the string to display depending on whether Decl is a
481 -- parameter or not
483 ------------------
484 -- Param_String --
485 ------------------
487 function Param_String return String is
488 begin
489 if Is_Parameter (Decl) then
490 return "parameter ";
491 else
492 return "";
493 end if;
494 end Param_String;
496 -- Start of processing for Get_Full_Type
498 begin
499 case Get_Type (Decl) is
500 when 'A' => return "array type";
501 when 'B' => return "boolean type";
502 when 'C' => return "class-wide type";
503 when 'D' => return "decimal type";
504 when 'E' => return "enumeration type";
505 when 'F' => return "float type";
506 when 'I' => return "integer type";
507 when 'M' => return "modular type";
508 when 'O' => return "fixed type";
509 when 'P' => return "access type";
510 when 'R' => return "record type";
511 when 'S' => return "string type";
512 when 'T' => return "task type";
513 when 'W' => return "protected type";
515 when 'a' => return "array type";
516 when 'b' => return Param_String & "boolean object";
517 when 'c' => return Param_String & "class-wide object";
518 when 'd' => return Param_String & "decimal object";
519 when 'e' => return Param_String & "enumeration object";
520 when 'f' => return Param_String & "float object";
521 when 'i' => return Param_String & "integer object";
522 when 'm' => return Param_String & "modular object";
523 when 'o' => return Param_String & "fixed object";
524 when 'p' => return Param_String & "access object";
525 when 'r' => return Param_String & "record object";
526 when 's' => return Param_String & "string object";
527 when 't' => return Param_String & "task object";
528 when 'w' => return Param_String & "protected object";
529 when 'x' => return Param_String & "abstract procedure";
530 when 'y' => return Param_String & "abstract function";
532 when 'K' => return "package";
533 when 'k' => return "generic package";
534 when 'L' => return "statement label";
535 when 'l' => return "loop label";
536 when 'N' => return "named number";
537 when 'n' => return "enumeration literal";
538 when 'q' => return "block label";
539 when 'U' => return "procedure";
540 when 'u' => return "generic procedure";
541 when 'V' => return "function";
542 when 'v' => return "generic function";
543 when 'X' => return "exception";
544 when 'Y' => return "entry";
546 when '+' => return "private type";
548 -- The above should be the only possibilities, but for this kind
549 -- of informational output, we don't want to bomb if we find
550 -- something else, so just return three question marks when we
551 -- have an unknown Abbrev value
553 when others =>
554 return "??? (" & Get_Type (Decl) & ")";
555 end case;
556 end Get_Full_Type;
558 --------------------------
559 -- Skip_To_First_X_Line --
560 --------------------------
562 procedure Skip_To_First_X_Line
563 (File : in out ALI_File;
564 D_Lines : Boolean;
565 W_Lines : Boolean)
567 Ali : String_Access renames File.Buffer;
568 Token : Positive;
569 Ptr : Positive := Ali'First;
570 Num_Dependencies : Natural := 0;
571 File_Ref : File_Reference;
572 File_Start : Positive;
573 File_End : Positive;
574 Gnatchop_Offset : Integer;
575 Gnatchop_Name : Positive;
577 begin
578 -- Read all the lines possibly processing with-clauses and dependency
579 -- information and exit on finding the first Xref line.
580 -- A fall-through of the loop means that there is no xref information
581 -- which is an error condition.
583 while Ali (Ptr) /= EOF loop
585 if D_Lines and then Ali (Ptr) = 'D' then
587 -- Found dependency information. Format looks like:
588 -- D src-nam time-stmp checksum [subunit-name] [line:file-name]
590 -- Skip the D and parse the filenam
592 Ptr := Ptr + 1;
593 Parse_Token (Ali, Ptr, Token);
594 File_Start := Token;
595 File_End := Ptr - 1;
597 Num_Dependencies := Num_Dependencies + 1;
598 Set_Last (File.Dep, Num_Dependencies);
600 Parse_Token (Ali, Ptr, Token); -- Skip time-stamp
601 Parse_Token (Ali, Ptr, Token); -- Skip checksum
602 Parse_Token (Ali, Ptr, Token); -- Read next entity on the line
604 if not (Ali (Token) in '0' .. '9') then
605 Parse_Token (Ali, Ptr, Token); -- Was a subunit name
606 end if;
608 -- Did we have a gnatchop-ed file with a pragma Source_Reference ?
610 Gnatchop_Offset := 0;
612 if Ali (Token) in '0' .. '9' then
613 Gnatchop_Name := Token;
614 while Ali (Gnatchop_Name) /= ':' loop
615 Gnatchop_Name := Gnatchop_Name + 1;
616 end loop;
618 Gnatchop_Offset :=
619 2 - Natural'Value (Ali (Token .. Gnatchop_Name - 1));
620 Token := Gnatchop_Name + 1;
621 end if;
623 File.Dep.Table (Num_Dependencies) := Add_To_Xref_File
624 (Ali (File_Start .. File_End),
625 Gnatchop_File => Ali (Token .. Ptr - 1),
626 Gnatchop_Offset => Gnatchop_Offset);
628 elsif W_Lines and then Ali (Ptr) = 'W' then
630 -- Found with-clause information. Format looks like:
631 -- "W debug%s debug.adb debug.ali"
633 -- Skip the W and parse the .ali filename (3rd token)
635 Parse_Token (Ali, Ptr, Token);
636 Parse_Token (Ali, Ptr, Token);
637 Parse_Token (Ali, Ptr, Token);
639 File_Ref := Add_To_Xref_File
640 (Ali (Token .. Ptr - 1), Visited => False);
642 elsif Ali (Ptr) = 'X' then
644 -- Found a cross-referencing line - stop processing
646 File.Current_Line := Ptr;
647 File.Xref_Line := Ptr;
648 return;
649 end if;
651 Parse_EOL (Ali, Ptr);
652 end loop;
654 raise No_Xref_Information;
655 end Skip_To_First_X_Line;
657 ----------
658 -- Open --
659 ----------
661 procedure Open
662 (Name : String;
663 File : out ALI_File;
664 Dependencies : Boolean := False)
666 Ali : String_Access renames File.Buffer;
668 begin
669 if File.Buffer /= null then
670 Free (File.Buffer);
671 end if;
673 Init (File.Dep);
675 begin
676 Read_File (Name, Ali);
678 exception
679 when Ada.Text_IO.Name_Error | Ada.Text_IO.End_Error =>
680 raise No_Xref_Information;
681 end;
683 Skip_To_First_X_Line (File, D_Lines => True, W_Lines => Dependencies);
684 end Open;
686 ---------------
687 -- Parse_EOL --
688 ---------------
690 procedure Parse_EOL
691 (Source : access String;
692 Ptr : in out Positive;
693 Skip_Continuation_Line : Boolean := False)
695 begin
696 loop
697 -- Skip to end of line
699 while Source (Ptr) /= ASCII.CR and then Source (Ptr) /= ASCII.LF
700 and then Source (Ptr) /= EOF
701 loop
702 Ptr := Ptr + 1;
703 end loop;
705 if Source (Ptr) /= EOF then
706 Ptr := Ptr + 1; -- skip CR or LF
707 end if;
709 -- Skip past CR/LF or LF/CR combination
711 if (Source (Ptr) = ASCII.CR or else Source (Ptr) = ASCII.LF)
712 and then Source (Ptr) /= Source (Ptr - 1)
713 then
714 Ptr := Ptr + 1;
715 end if;
717 exit when not Skip_Continuation_Line or else Source (Ptr) /= '.';
718 end loop;
719 end Parse_EOL;
721 ---------------------------
722 -- Parse_Identifier_Info --
723 ---------------------------
725 procedure Parse_Identifier_Info
726 (Pattern : Search_Pattern;
727 File : in out ALI_File;
728 Local_Symbols : Boolean;
729 Der_Info : Boolean := False;
730 Type_Tree : Boolean := False;
731 Wide_Search : Boolean := True;
732 Labels_As_Ref : Boolean := True)
734 Ptr : Positive renames File.Current_Line;
735 Ali : String_Access renames File.Buffer;
737 E_Line : Natural; -- Line number of current entity
738 E_Col : Natural; -- Column number of current entity
739 E_Type : Character; -- Type of current entity
740 E_Name : Positive; -- Pointer to begin of entity name
741 E_Global : Boolean; -- True iff entity is global
743 R_Line : Natural; -- Line number of current reference
744 R_Col : Natural; -- Column number of current reference
745 R_Type : Character; -- Type of current reference
747 Decl_Ref : Declaration_Reference;
748 File_Ref : File_Reference := Current_Xref_File (File);
750 function Get_Symbol_Name (Eun, Line, Col : Natural) return String;
751 -- Returns the symbol name for the entity defined at the specified
752 -- line and column in the dependent unit number Eun. For this we need
753 -- to parse the ali file again because the parent entity is not in
754 -- the declaration table if it did not match the search pattern.
756 ---------------------
757 -- Get_Symbol_Name --
758 ---------------------
760 function Get_Symbol_Name (Eun, Line, Col : Natural) return String is
761 Ptr : Positive := 1;
762 E_Eun : Positive; -- Unit number of current entity
763 E_Line : Natural; -- Line number of current entity
764 E_Col : Natural; -- Column number of current entity
765 E_Name : Positive; -- Pointer to begin of entity name
766 E_Type : Character; -- Type of current entity
768 begin
769 -- Look for the X lines corresponding to unit Eun
771 loop
772 if Ali (Ptr) = 'X' then
773 Ptr := Ptr + 1;
774 Parse_Number (Ali, Ptr, E_Eun);
775 exit when E_Eun = Eun;
776 end if;
778 Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
779 end loop;
781 -- Here we are in the right Ali section, we now look for the entity
782 -- declared at position (Line, Col).
784 loop
785 Parse_Number (Ali, Ptr, E_Line);
786 E_Type := Ali (Ptr);
787 exit when Ali (Ptr) = EOF;
788 Ptr := Ptr + 1;
789 Parse_Number (Ali, Ptr, E_Col);
790 exit when Ali (Ptr) = EOF;
791 Ptr := Ptr + 1;
793 if Line = E_Line and then Col = E_Col then
794 Parse_Token (Ali, Ptr, E_Name);
795 return Ali (E_Name .. Ptr - 1);
796 end if;
798 Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
799 exit when Ali (Ptr) = EOF;
800 end loop;
802 -- We were not able to find the symbol, this should not happend but
803 -- since we don't want to stop here we return a string of three
804 -- question marks as the symbol name.
806 return "???";
807 end Get_Symbol_Name;
809 -- Start of processing for Parse_Identifier_Info
811 begin
812 -- The identifier info looks like:
813 -- "38U9*Debug 12|36r6 36r19"
815 -- Extract the line, column and entity name information
817 Parse_Number (Ali, Ptr, E_Line);
819 if Ali (Ptr) > ' ' then
820 E_Type := Ali (Ptr);
821 Ptr := Ptr + 1;
822 end if;
824 -- Ignore some of the entities (labels,...)
826 case E_Type is
827 when 'l' | 'L' | 'q' =>
828 Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
829 return;
831 when others =>
832 null;
833 end case;
835 Parse_Number (Ali, Ptr, E_Col);
837 E_Global := False;
838 if Ali (Ptr) >= ' ' then
839 E_Global := (Ali (Ptr) = '*');
840 Ptr := Ptr + 1;
841 end if;
843 Parse_Token (Ali, Ptr, E_Name);
845 -- Exit if the symbol does not match
846 -- or if we have a local symbol and we do not want it
848 if (not Local_Symbols and not E_Global)
849 or else (Pattern.Initialized
850 and then not Match (Ali (E_Name .. Ptr - 1), Pattern.Entity))
851 or else (E_Name >= Ptr)
852 then
853 Decl_Ref := Add_Declaration
854 (File.X_File, Ali (E_Name .. Ptr - 1), E_Line, E_Col, E_Type,
855 Remove_Only => True);
856 Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
857 return;
858 end if;
860 -- Insert the declaration in the table
862 Decl_Ref := Add_Declaration
863 (File.X_File, Ali (E_Name .. Ptr - 1), E_Line, E_Col, E_Type);
865 if Ali (Ptr) = '<'
866 or else Ali (Ptr) = '('
867 or else Ali (Ptr) = '{'
868 then
869 -- Here we have a type derivation information. The format is
870 -- <3|12I45> which means that the current entity is derived from the
871 -- type defined in unit number 3, line 12 column 45. The pipe and
872 -- unit number is optional. It is specified only if the parent type
873 -- is not defined in the current unit.
875 -- We also have the format for generic instantiations, as in
876 -- 7a5*Uid(3|5I8[4|2]) 2|4r74
878 -- We could also have something like
879 -- 16I9*I<integer>
880 -- that indicates that I derives from the predefined type integer.
882 Ptr := Ptr + 1;
884 if Ali (Ptr) in '0' .. '9' then
885 Parse_Derived_Info : declare
886 P_Line : Natural; -- parent entity line
887 P_Column : Natural; -- parent entity column
888 P_Type : Character; -- parent entity type
889 P_Eun : Positive; -- parent entity file number
891 begin
892 Parse_Number (Ali, Ptr, P_Line);
894 -- If we have a pipe then the first number was the unit number
896 if Ali (Ptr) = '|' then
897 P_Eun := P_Line;
898 Ptr := Ptr + 1;
900 -- Now we have the line number
902 Parse_Number (Ali, Ptr, P_Line);
904 else
905 -- We don't have a unit number specified, so we set P_Eun to
906 -- the current unit.
908 for K in Dependencies_Tables.First .. Last (File.Dep) loop
909 P_Eun := K;
910 exit when File.Dep.Table (K) = File_Ref;
911 end loop;
912 end if;
914 -- Then parse the type and column number
916 P_Type := Ali (Ptr);
917 Ptr := Ptr + 1;
918 Parse_Number (Ali, Ptr, P_Column);
920 -- Skip the information for generics instantiations
922 if Ali (Ptr) = '[' then
923 declare
924 Num_Brackets : Natural := 1;
925 begin
926 while Num_Brackets /= 0 loop
927 Ptr := Ptr + 1;
928 if Ali (Ptr) = '[' then
929 Num_Brackets := Num_Brackets + 1;
930 elsif Ali (Ptr) = ']' then
931 Num_Brackets := Num_Brackets - 1;
932 end if;
933 end loop;
935 Ptr := Ptr + 1;
936 end;
937 end if;
939 -- Skip '>', or ')' or '>'
941 Ptr := Ptr + 1;
943 -- The derived info is needed only is the derived info mode is
944 -- on or if we want to output the type hierarchy
946 if Der_Info or else Type_Tree then
947 declare
948 Symbol : constant String :=
949 Get_Symbol_Name (P_Eun, P_Line, P_Column);
950 begin
951 if Symbol /= "???" then
952 Add_Parent
953 (Decl_Ref,
954 Symbol,
955 P_Line,
956 P_Column,
957 File.Dep.Table (P_Eun));
958 end if;
959 end;
960 end if;
962 if Type_Tree
963 and then (Pattern.File_Ref = Empty_File
964 or else
965 Pattern.File_Ref = Current_Xref_File (File))
966 then
967 Search_Parent_Tree : declare
968 Pattern : Search_Pattern; -- Parent type pattern
969 File_Pos_Backup : Positive;
971 begin
972 Add_Entity
973 (Pattern,
974 Get_Symbol_Name (P_Eun, P_Line, P_Column)
975 & ':' & Get_Gnatchop_File (File.Dep.Table (P_Eun))
976 & ':' & Get_Line (Get_Parent (Decl_Ref))
977 & ':' & Get_Column (Get_Parent (Decl_Ref)),
978 False);
980 -- No default match is needed to look for the parent type
981 -- since we are using the fully qualified symbol name:
982 -- symbol:file:line:column
984 Set_Default_Match (False);
986 -- The parent hierarchy is defined in the same unit as
987 -- the derived type. So we want to revisit the unit.
989 File_Pos_Backup := File.Current_Line;
991 Skip_To_First_X_Line
992 (File, D_Lines => False, W_Lines => False);
994 while File.Buffer (File.Current_Line) /= EOF loop
995 Parse_X_Filename (File);
996 Parse_Identifier_Info
997 (Pattern => Pattern,
998 File => File,
999 Local_Symbols => False,
1000 Der_Info => Der_Info,
1001 Type_Tree => True,
1002 Wide_Search => False,
1003 Labels_As_Ref => Labels_As_Ref);
1004 end loop;
1006 File.Current_Line := File_Pos_Backup;
1007 end Search_Parent_Tree;
1008 end if;
1009 end Parse_Derived_Info;
1011 else
1012 while Ali (Ptr) /= '>'
1013 and then Ali (Ptr) /= ')'
1014 and then Ali (Ptr) /= '}'
1015 loop
1016 Ptr := Ptr + 1;
1017 end loop;
1018 Ptr := Ptr + 1;
1019 end if;
1021 elsif Ali (Ptr) = '=' then
1022 declare
1023 P_Line, P_Column : Natural;
1025 begin
1026 Ptr := Ptr + 1;
1027 Parse_Number (Ali, Ptr, P_Line);
1028 Ptr := Ptr + 1;
1029 Parse_Number (Ali, Ptr, P_Column);
1030 end;
1031 end if;
1033 -- To find the body, we will have to parse the file too
1035 if Wide_Search then
1036 declare
1037 File_Ref : File_Reference;
1038 File_Name : constant String :=
1039 Get_Gnatchop_File (File.X_File);
1040 begin
1041 File_Ref := Add_To_Xref_File (ALI_File_Name (File_Name), False);
1042 end;
1043 end if;
1045 -- Parse references to this entity.
1046 -- Ptr points to next reference with leading blanks
1048 loop
1049 -- Process references on current line
1051 while Ali (Ptr) = ' ' or Ali (Ptr) = ASCII.HT loop
1053 -- For every reference read the line, type and column,
1054 -- optionally preceded by a file number and a pipe symbol.
1056 Parse_Number (Ali, Ptr, R_Line);
1058 if Ali (Ptr) = Pipe then
1059 Ptr := Ptr + 1;
1060 File_Ref := File_Name (File, R_Line);
1062 Parse_Number (Ali, Ptr, R_Line);
1063 end if;
1065 if Ali (Ptr) > ' ' then
1066 R_Type := Ali (Ptr);
1067 Ptr := Ptr + 1;
1068 end if;
1070 -- Imported entities might special indication as to their external
1071 -- name:
1072 -- 5U14*Foo2 5>20 6b<c,myfoo2>22
1074 if R_Type = 'b'
1075 and then Ali (Ptr) = '<'
1076 then
1077 while Ptr <= Ali'Last
1078 and then Ali (Ptr) /= '>'
1079 loop
1080 Ptr := Ptr + 1;
1081 end loop;
1082 Ptr := Ptr + 1;
1083 end if;
1085 Parse_Number (Ali, Ptr, R_Col);
1087 -- Insert the reference or body in the table
1089 Add_Reference
1090 (Decl_Ref, File_Ref, R_Line, R_Col, R_Type, Labels_As_Ref);
1092 -- Skip generic information, if any
1094 if Ali (Ptr) = '[' then
1095 declare
1096 Num_Nested : Integer := 1;
1098 begin
1099 Ptr := Ptr + 1;
1100 while Num_Nested /= 0 loop
1101 if Ali (Ptr) = ']' then
1102 Num_Nested := Num_Nested - 1;
1103 elsif Ali (Ptr) = '[' then
1104 Num_Nested := Num_Nested + 1;
1105 end if;
1107 Ptr := Ptr + 1;
1108 end loop;
1109 end;
1110 end if;
1112 end loop;
1114 Parse_EOL (Ali, Ptr);
1116 -- Loop until new line is no continuation line
1118 exit when Ali (Ptr) /= '.';
1119 Ptr := Ptr + 1;
1120 end loop;
1121 end Parse_Identifier_Info;
1123 ------------------
1124 -- Parse_Number --
1125 ------------------
1127 procedure Parse_Number
1128 (Source : access String;
1129 Ptr : in out Positive;
1130 Number : out Natural)
1132 begin
1133 -- Skip separators
1135 while Source (Ptr) = ' ' or else Source (Ptr) = ASCII.HT loop
1136 Ptr := Ptr + 1;
1137 end loop;
1139 Number := 0;
1140 while Source (Ptr) in '0' .. '9' loop
1141 Number :=
1142 10 * Number + (Character'Pos (Source (Ptr)) - Character'Pos ('0'));
1143 Ptr := Ptr + 1;
1144 end loop;
1145 end Parse_Number;
1147 -----------------
1148 -- Parse_Token --
1149 -----------------
1151 procedure Parse_Token
1152 (Source : access String;
1153 Ptr : in out Positive;
1154 Token_Ptr : out Positive)
1156 In_Quotes : Character := ASCII.NUL;
1158 begin
1159 -- Skip separators
1161 while Source (Ptr) = ' ' or else Source (Ptr) = ASCII.HT loop
1162 Ptr := Ptr + 1;
1163 end loop;
1165 Token_Ptr := Ptr;
1167 -- Find end-of-token
1169 while (In_Quotes /= ASCII.NUL or else
1170 not (Source (Ptr) = ' '
1171 or else Source (Ptr) = ASCII.HT
1172 or else Source (Ptr) = '<'
1173 or else Source (Ptr) = '{'
1174 or else Source (Ptr) = '='
1175 or else Source (Ptr) = '('))
1176 and then Source (Ptr) >= ' '
1177 loop
1178 -- Double-quotes are used for operators
1179 -- Simple-quotes are used for character constants, for instance when
1180 -- they are found in an enumeration type "type A is ('+', '-');"
1182 case Source (Ptr) is
1183 when '"' | ''' =>
1184 if In_Quotes = Source (Ptr) then
1185 In_Quotes := ASCII.NUL;
1186 elsif In_Quotes = ASCII.NUL then
1187 In_Quotes := Source (Ptr);
1188 end if;
1190 when others =>
1191 null;
1192 end case;
1194 Ptr := Ptr + 1;
1195 end loop;
1196 end Parse_Token;
1198 ----------------------
1199 -- Parse_X_Filename --
1200 ----------------------
1202 procedure Parse_X_Filename (File : in out ALI_File) is
1203 Ali : String_Access renames File.Buffer;
1204 Ptr : Positive renames File.Current_Line;
1205 File_Nr : Natural;
1207 begin
1208 while Ali (Ptr) = 'X' loop
1210 -- The current line is the start of a new Xref file section,
1211 -- whose format looks like:
1213 -- " X 1 debug.ads"
1215 -- Skip the X and read the file number for the new X_File
1217 Ptr := Ptr + 1;
1218 Parse_Number (Ali, Ptr, File_Nr);
1220 if File_Nr > 0 then
1221 File.X_File := File.Dep.Table (File_Nr);
1222 end if;
1224 Parse_EOL (Ali, Ptr);
1225 end loop;
1226 end Parse_X_Filename;
1228 --------------------
1229 -- Print_Gnatfind --
1230 --------------------
1232 procedure Print_Gnatfind
1233 (References : Boolean;
1234 Full_Path_Name : Boolean)
1236 Decls : constant Declaration_Array_Access := Get_Declarations;
1237 Decl : Declaration_Reference;
1238 Arr : Reference_Array_Access;
1240 procedure Print_Ref
1241 (Ref : Reference;
1242 Msg : String := " ");
1243 -- Print a reference, according to the extended tag of the output
1245 ---------------
1246 -- Print_Ref --
1247 ---------------
1249 procedure Print_Ref
1250 (Ref : Reference;
1251 Msg : String := " ")
1253 F : String_Access :=
1254 Osint.To_Host_File_Spec
1255 (Get_Gnatchop_File (Ref, Full_Path_Name));
1257 Buffer : constant String :=
1258 F.all &
1259 ":" & Get_Line (Ref) &
1260 ":" & Get_Column (Ref) &
1261 ": ";
1263 Num_Blanks : Integer := Longest_File_Name + 10 - Buffer'Length;
1265 begin
1266 Free (F);
1267 Num_Blanks := Integer'Max (0, Num_Blanks);
1268 Write_Line
1269 (Buffer
1270 & String'(1 .. Num_Blanks => ' ')
1271 & Msg & " " & Get_Symbol (Decl));
1273 if Get_Source_Line (Ref)'Length /= 0 then
1274 Write_Line (" " & Get_Source_Line (Ref));
1275 end if;
1276 end Print_Ref;
1278 -- Start of processing for Print_Gnatfind
1280 begin
1281 for D in Decls'Range loop
1282 Decl := Decls (D);
1284 if Match (Decl) then
1286 -- Output the declaration
1288 declare
1289 Parent : constant Declaration_Reference := Get_Parent (Decl);
1291 F : String_Access :=
1292 Osint.To_Host_File_Spec
1293 (Get_Gnatchop_File (Decl, Full_Path_Name));
1295 Buffer : constant String :=
1296 F.all &
1297 ":" & Get_Line (Decl) &
1298 ":" & Get_Column (Decl) &
1299 ": ";
1301 Num_Blanks : Integer := Longest_File_Name + 10 - Buffer'Length;
1303 begin
1304 Free (F);
1305 Num_Blanks := Integer'Max (0, Num_Blanks);
1306 Write_Line
1307 (Buffer & String'(1 .. Num_Blanks => ' ')
1308 & "(spec) " & Get_Symbol (Decl));
1310 if Parent /= Empty_Declaration then
1311 F := Osint.To_Host_File_Spec (Get_Gnatchop_File (Parent));
1312 Write_Line
1313 (Buffer & String'(1 .. Num_Blanks => ' ')
1314 & " derived from " & Get_Symbol (Parent)
1315 & " ("
1316 & F.all
1317 & ':' & Get_Line (Parent)
1318 & ':' & Get_Column (Parent) & ')');
1319 Free (F);
1320 end if;
1321 end;
1323 if Get_Source_Line (Decl)'Length /= 0 then
1324 Write_Line (" " & Get_Source_Line (Decl));
1325 end if;
1327 -- Output the body (sorted)
1329 Arr := Get_References (Decl, Get_Bodies => True);
1331 for R in Arr'Range loop
1332 Print_Ref (Arr (R), "(body)");
1333 end loop;
1335 Free (Arr);
1337 if References then
1338 Arr := Get_References
1339 (Decl, Get_Writes => True, Get_Reads => True);
1341 for R in Arr'Range loop
1342 Print_Ref (Arr (R));
1343 end loop;
1345 Free (Arr);
1346 end if;
1347 end if;
1348 end loop;
1349 end Print_Gnatfind;
1351 ------------------
1352 -- Print_Unused --
1353 ------------------
1355 procedure Print_Unused (Full_Path_Name : in Boolean) is
1356 Decls : constant Declaration_Array_Access := Get_Declarations;
1357 Decl : Declaration_Reference;
1358 Arr : Reference_Array_Access;
1359 F : String_Access;
1361 begin
1362 for D in Decls'Range loop
1363 Decl := Decls (D);
1365 if References_Count
1366 (Decl, Get_Reads => True, Get_Writes => True) = 0
1367 then
1368 F := Osint.To_Host_File_Spec
1369 (Get_Gnatchop_File (Decl, Full_Path_Name));
1370 Write_Str (Get_Symbol (Decl)
1371 & " ("
1372 & Get_Full_Type (Decl)
1373 & ") "
1374 & F.all
1375 & ':'
1376 & Get_Line (Decl)
1377 & ':'
1378 & Get_Column (Decl));
1379 Free (F);
1381 -- Print the body if any
1383 Arr := Get_References (Decl, Get_Bodies => True);
1385 for R in Arr'Range loop
1386 F := Osint.To_Host_File_Spec
1387 (Get_Gnatchop_File (Arr (R), Full_Path_Name));
1388 Write_Str (' '
1389 & F.all
1390 & ':' & Get_Line (Arr (R))
1391 & ':' & Get_Column (Arr (R)));
1392 Free (F);
1393 end loop;
1395 Write_Eol;
1396 Free (Arr);
1397 end if;
1398 end loop;
1399 end Print_Unused;
1401 --------------
1402 -- Print_Vi --
1403 --------------
1405 procedure Print_Vi (Full_Path_Name : in Boolean) is
1406 Tab : constant Character := ASCII.HT;
1407 Decls : constant Declaration_Array_Access :=
1408 Get_Declarations (Sorted => False);
1409 Decl : Declaration_Reference;
1410 Arr : Reference_Array_Access;
1411 F : String_Access;
1413 begin
1414 for D in Decls'Range loop
1415 Decl := Decls (D);
1417 F := Osint.To_Host_File_Spec (Get_File (Decl, Full_Path_Name));
1418 Write_Line (Get_Symbol (Decl) & Tab & F.all & Tab & Get_Line (Decl));
1419 Free (F);
1421 -- Print the body if any
1423 Arr := Get_References (Decl, Get_Bodies => True);
1425 for R in Arr'Range loop
1426 F := Osint.To_Host_File_Spec (Get_File (Arr (R), Full_Path_Name));
1427 Write_Line
1428 (Get_Symbol (Decl) & Tab & F.all & Tab & Get_Line (Arr (R)));
1429 Free (F);
1430 end loop;
1432 Free (Arr);
1434 -- Print the modifications
1436 Arr := Get_References (Decl, Get_Writes => True, Get_Reads => True);
1438 for R in Arr'Range loop
1439 F := Osint.To_Host_File_Spec (Get_File (Arr (R), Full_Path_Name));
1440 Write_Line
1441 (Get_Symbol (Decl) & Tab & F.all & Tab & Get_Line (Arr (R)));
1442 Free (F);
1443 end loop;
1445 Free (Arr);
1446 end loop;
1447 end Print_Vi;
1449 ----------------
1450 -- Print_Xref --
1451 ----------------
1453 procedure Print_Xref (Full_Path_Name : in Boolean) is
1454 Decls : constant Declaration_Array_Access := Get_Declarations;
1455 Decl : Declaration_Reference;
1457 Margin : constant := 10;
1458 -- Column where file names start
1460 procedure New_Line80;
1461 -- Go to start of new line
1463 procedure Print80 (S : in String);
1464 -- Print the text, respecting the 80 columns rule.
1466 procedure Print_Ref (Line, Column : String);
1467 -- The beginning of the output is aligned on a column multiple of 9
1469 procedure Print_List
1470 (Decl : Declaration_Reference;
1471 Msg : String;
1472 Get_Reads : Boolean := False;
1473 Get_Writes : Boolean := False;
1474 Get_Bodies : Boolean := False);
1475 -- Print a list of references. If the list is not empty, Msg will
1476 -- be printed prior to the list.
1478 ----------------
1479 -- New_Line80 --
1480 ----------------
1482 procedure New_Line80 is
1483 begin
1484 Write_Eol;
1485 Write_Str (String'(1 .. Margin - 1 => ' '));
1486 end New_Line80;
1488 -------------
1489 -- Print80 --
1490 -------------
1492 procedure Print80 (S : in String) is
1493 Align : Natural := Margin - (Integer (Column) mod Margin);
1495 begin
1496 if Align = Margin then
1497 Align := 0;
1498 end if;
1500 Write_Str (String'(1 .. Align => ' ') & S);
1501 end Print80;
1503 ---------------
1504 -- Print_Ref --
1505 ---------------
1507 procedure Print_Ref (Line, Column : String) is
1508 Line_Align : constant Integer := 4 - Line'Length;
1510 S : constant String := String'(1 .. Line_Align => ' ')
1511 & Line & ':' & Column;
1513 Align : Natural := Margin - (Integer (Output.Column) mod Margin);
1515 begin
1516 if Align = Margin then
1517 Align := 0;
1518 end if;
1520 if Integer (Output.Column) + Align + S'Length > 79 then
1521 New_Line80;
1522 Align := 0;
1523 end if;
1525 Write_Str (String'(1 .. Align => ' ') & S);
1526 end Print_Ref;
1528 ----------------
1529 -- Print_List --
1530 ----------------
1532 procedure Print_List
1533 (Decl : Declaration_Reference;
1534 Msg : String;
1535 Get_Reads : Boolean := False;
1536 Get_Writes : Boolean := False;
1537 Get_Bodies : Boolean := False)
1539 Arr : Reference_Array_Access :=
1540 Get_References
1541 (Decl,
1542 Get_Writes => Get_Writes,
1543 Get_Reads => Get_Reads,
1544 Get_Bodies => Get_Bodies);
1545 File : File_Reference := Empty_File;
1546 F : String_Access;
1548 begin
1549 if Arr'Length /= 0 then
1550 Write_Eol;
1551 Write_Str (Msg);
1552 end if;
1554 for R in Arr'Range loop
1555 if Get_File_Ref (Arr (R)) /= File then
1556 if File /= Empty_File then
1557 New_Line80;
1558 end if;
1560 File := Get_File_Ref (Arr (R));
1561 F := Osint.To_Host_File_Spec
1562 (Get_Gnatchop_File (Arr (R), Full_Path_Name));
1563 Write_Str (F.all & ' ');
1564 Free (F);
1565 end if;
1567 Print_Ref (Get_Line (Arr (R)), Get_Column (Arr (R)));
1568 end loop;
1570 Free (Arr);
1571 end Print_List;
1573 F : String_Access;
1575 -- Start of processing for Print_Xref
1577 begin
1578 for D in Decls'Range loop
1579 Decl := Decls (D);
1581 Write_Str (Get_Symbol (Decl));
1583 while Column < Type_Position loop
1584 Write_Char (' ');
1585 end loop;
1587 Write_Line (Get_Full_Type (Decl));
1589 Write_Parent_Info : declare
1590 Parent : constant Declaration_Reference := Get_Parent (Decl);
1592 begin
1593 if Parent /= Empty_Declaration then
1594 Write_Str (" Ptype: ");
1595 F := Osint.To_Host_File_Spec (Get_Gnatchop_File (Parent));
1596 Print80 (F.all);
1597 Free (F);
1598 Print_Ref (Get_Line (Parent), Get_Column (Parent));
1599 Print80 (" " & Get_Symbol (Parent));
1600 Write_Eol;
1601 end if;
1602 end Write_Parent_Info;
1604 Write_Str (" Decl: ");
1605 F := Osint.To_Host_File_Spec
1606 (Get_Gnatchop_File (Decl, Full_Path_Name));
1607 Print80 (F.all & ' ');
1608 Free (F);
1609 Print_Ref (Get_Line (Decl), Get_Column (Decl));
1611 Print_List
1612 (Decl, " Body: ", Get_Bodies => True);
1613 Print_List
1614 (Decl, " Modi: ", Get_Writes => True);
1615 Print_List
1616 (Decl, " Ref: ", Get_Reads => True);
1617 Write_Eol;
1618 end loop;
1619 end Print_Xref;
1621 ------------
1622 -- Search --
1623 ------------
1625 procedure Search
1626 (Pattern : Search_Pattern;
1627 Local_Symbols : Boolean;
1628 Wide_Search : Boolean;
1629 Read_Only : Boolean;
1630 Der_Info : Boolean;
1631 Type_Tree : Boolean)
1633 type String_Access is access String;
1634 procedure Free is new Unchecked_Deallocation (String, String_Access);
1636 ALIfile : ALI_File;
1637 File_Ref : File_Reference;
1638 Strip_Num : Natural := 0;
1639 Ali_Name : String_Access;
1641 begin
1642 -- If we want all the .ali files, then find them
1644 if Wide_Search then
1645 Find_ALI_Files;
1646 end if;
1648 loop
1649 -- Get the next unread ali file
1651 File_Ref := Next_Unvisited_File;
1653 exit when File_Ref = Empty_File;
1655 -- Find the ALI file to use. Most of the time, it will be the unit
1656 -- name, with a different extension. However, when dealing with
1657 -- separates the ALI file is in fact the parent's ALI file (and this
1658 -- is recursive, in case the parent itself is a separate).
1660 Strip_Num := 0;
1661 loop
1662 Free (Ali_Name);
1663 Ali_Name := new String'
1664 (Get_File (File_Ref, With_Dir => True, Strip => Strip_Num));
1666 -- Stripped too many things...
1668 if Ali_Name.all = "" then
1669 if Get_Emit_Warning (File_Ref) then
1670 Set_Standard_Error;
1671 Write_Line
1672 ("warning : file " & Get_File (File_Ref, With_Dir => True)
1673 & " not found");
1674 Set_Standard_Output;
1675 end if;
1676 Free (Ali_Name);
1677 exit;
1679 -- If not found, try the parent's ALI file (this is needed for
1680 -- separate units and subprograms).
1682 -- Reset the cached directory first, in case the separate's
1683 -- ALI file is not in the same directory.
1685 elsif not File_Exists (Ali_Name.all) then
1686 Strip_Num := Strip_Num + 1;
1687 Reset_Directory (File_Ref);
1689 -- Else we finally found it
1691 else
1692 exit;
1693 end if;
1694 end loop;
1696 -- If we had to get the parent's ALI, insert it in the list as usual.
1697 -- This is to avoid parsing it twice in case it has already been
1698 -- parsed.
1700 if Ali_Name /= null and then Strip_Num /= 0 then
1701 File_Ref := Add_To_Xref_File
1702 (File_Name => Ali_Name.all,
1703 Visited => False);
1705 -- Now that we have a file name, parse it to find any reference to
1706 -- the entity.
1708 elsif Ali_Name /= null
1709 and then (Read_Only or else Is_Writable_File (Ali_Name.all))
1710 then
1711 begin
1712 Open (Ali_Name.all, ALIfile);
1713 while ALIfile.Buffer (ALIfile.Current_Line) /= EOF loop
1714 Parse_X_Filename (ALIfile);
1715 Parse_Identifier_Info
1716 (Pattern, ALIfile, Local_Symbols,
1717 Der_Info, Type_Tree, Wide_Search, Labels_As_Ref => True);
1718 end loop;
1720 exception
1721 when No_Xref_Information =>
1722 if Get_Emit_Warning (File_Ref) then
1723 Set_Standard_Error;
1724 Write_Line
1725 ("warning : No cross-referencing information in "
1726 & Ali_Name.all);
1727 Set_Standard_Output;
1728 end if;
1729 end;
1730 end if;
1731 end loop;
1733 Free (Ali_Name);
1734 end Search;
1736 -----------------
1737 -- Search_Xref --
1738 -----------------
1740 procedure Search_Xref
1741 (Local_Symbols : Boolean;
1742 Read_Only : Boolean;
1743 Der_Info : Boolean)
1745 ALIfile : ALI_File;
1746 File_Ref : File_Reference;
1747 Null_Pattern : Search_Pattern;
1749 begin
1750 Null_Pattern.Initialized := False;
1752 loop
1753 -- Find the next unvisited file
1755 File_Ref := Next_Unvisited_File;
1756 exit when File_Ref = Empty_File;
1758 -- Search the object directories for the .ali file
1760 declare
1761 F : constant String := Get_File (File_Ref, With_Dir => True);
1763 begin
1764 if Read_Only or else Is_Writable_File (F) then
1765 Open (F, ALIfile, True);
1767 while ALIfile.Buffer (ALIfile.Current_Line) /= EOF loop
1768 Parse_X_Filename (ALIfile);
1769 Parse_Identifier_Info
1770 (Null_Pattern, ALIfile, Local_Symbols, Der_Info,
1771 Labels_As_Ref => False);
1772 end loop;
1773 end if;
1775 exception
1776 when No_Xref_Information => null;
1777 end;
1778 end loop;
1779 end Search_Xref;
1781 end Xref_Lib;