Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / ada / xref_lib.adb
blobed213569e924cf15e290ce00e11ade508cfb15f2
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-2010, 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 Osint;
27 with Output; use Output;
28 with Types; use Types;
30 with Unchecked_Deallocation;
32 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
33 with Ada.Text_IO; use Ada.Text_IO;
35 with GNAT.Command_Line; use GNAT.Command_Line;
36 with GNAT.IO_Aux; use GNAT.IO_Aux;
38 package body Xref_Lib is
40 Type_Position : constant := 50;
41 -- Column for label identifying type of entity
43 ---------------------
44 -- Local Variables --
45 ---------------------
47 Pipe : constant Character := '|';
48 -- First character on xref lines in the .ali file
50 No_Xref_Information : exception;
51 -- Exception raised when there is no cross-referencing information in
52 -- the .ali files.
54 procedure Parse_EOL
55 (Source : not null access String;
56 Ptr : in out Positive;
57 Skip_Continuation_Line : Boolean := False);
58 -- On return Source (Ptr) is the first character of the next line
59 -- or EOF. Source.all must be terminated by EOF.
61 -- If Skip_Continuation_Line is True, this subprogram skips as many
62 -- lines as required when the second or more lines starts with '.'
63 -- (continuation lines in ALI files).
65 function Current_Xref_File (File : ALI_File) return File_Reference;
66 -- Return the file matching the last 'X' line we found while parsing
67 -- the ALI file.
69 function File_Name (File : ALI_File; Num : Positive) return File_Reference;
70 -- Returns the dependency file name number Num
72 function Get_Full_Type (Decl : Declaration_Reference) return String;
73 -- Returns the full type corresponding to a type letter as found in
74 -- the .ali files.
76 procedure Open
77 (Name : String;
78 File : out ALI_File;
79 Dependencies : Boolean := False);
80 -- Open a new ALI file. If Dependencies is True, the insert every library
81 -- file 'with'ed in the files database (used for gnatxref)
83 procedure Parse_Identifier_Info
84 (Pattern : Search_Pattern;
85 File : in out ALI_File;
86 Local_Symbols : Boolean;
87 Der_Info : Boolean := False;
88 Type_Tree : Boolean := False;
89 Wide_Search : Boolean := True;
90 Labels_As_Ref : Boolean := True);
91 -- Output the file and the line where the identifier was referenced,
92 -- If Local_Symbols is False then only the publicly visible symbols
93 -- will be processed.
95 -- If Labels_As_Ref is true, then the references to the entities after
96 -- the end statements ("end Foo") will be counted as actual references.
97 -- The entity will never be reported as unreferenced by gnatxref -u
99 procedure Parse_Token
100 (Source : not null access String;
101 Ptr : in out Positive;
102 Token_Ptr : out Positive);
103 -- Skips any separators and stores the start of the token in Token_Ptr.
104 -- Then stores the position of the next separator in Ptr. On return
105 -- Source (Token_Ptr .. Ptr - 1) is the token. Separators are space
106 -- and ASCII.HT. Parse_Token will never skip to the next line.
108 procedure Parse_Number
109 (Source : not null access String;
110 Ptr : in out Positive;
111 Number : out Natural);
112 -- Skips any separators and parses Source up to the first character that
113 -- is not a decimal digit. Returns value of parsed digits or 0 if none.
115 procedure Parse_X_Filename (File : in out ALI_File);
116 -- Reads and processes "X..." lines in the ALI file
117 -- and updates the File.X_File information.
119 procedure Skip_To_First_X_Line
120 (File : in out ALI_File;
121 D_Lines : Boolean;
122 W_Lines : Boolean);
123 -- Skip the lines in the ALI file until the first cross-reference line
124 -- (^X...) is found. Search is started from the beginning of the file.
125 -- If not such line is found, No_Xref_Information is raised.
126 -- If W_Lines is false, then the lines "^W" are not parsed.
127 -- If D_Lines is false, then the lines "^D" are not parsed.
129 ----------------
130 -- Add_Entity --
131 ----------------
133 procedure Add_Entity
134 (Pattern : in out Search_Pattern;
135 Entity : String;
136 Glob : Boolean := False)
138 File_Start : Natural;
139 Line_Start : Natural;
140 Col_Start : Natural;
141 Line_Num : Natural := 0;
142 Col_Num : Natural := 0;
144 File_Ref : File_Reference := Empty_File;
145 pragma Warnings (Off, File_Ref);
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 end if;
230 -- Parse the file name
232 Line_Start := Index (Entity (File_Start .. Entity'Last), ":");
234 -- Check if it was a disk:\directory item (for Windows)
236 if File_Start = Line_Start - 1
237 and then Line_Start < Entity'Last
238 and then Entity (Line_Start + 1) = '\'
239 then
240 Line_Start := Index (Entity (Line_Start + 1 .. Entity'Last), ":");
241 end if;
243 if Line_Start = 0 then
244 Line_Start := Entity'Length + 1;
246 elsif Line_Start /= Entity'Last then
247 Col_Start := Index (Entity (Line_Start + 1 .. Entity'Last), ":");
249 if Col_Start = 0 then
250 Col_Start := Entity'Last + 1;
251 end if;
253 if Col_Start > Line_Start + 1 then
254 begin
255 Line_Num := Natural'Value
256 (Entity (Line_Start + 1 .. Col_Start - 1));
258 exception
259 when Constraint_Error =>
260 raise Invalid_Argument;
261 end;
262 end if;
264 if Col_Start < Entity'Last then
265 begin
266 Col_Num := Natural'Value (Entity
267 (Col_Start + 1 .. Entity'Last));
269 exception
270 when Constraint_Error => raise Invalid_Argument;
271 end;
272 end if;
273 end if;
275 File_Ref :=
276 Add_To_Xref_File
277 (Entity (File_Start .. Line_Start - 1), Visited => True);
278 Pattern.File_Ref := File_Ref;
280 Add_Line (Pattern.File_Ref, Line_Num, Col_Num);
282 File_Ref :=
283 Add_To_Xref_File
284 (ALI_File_Name (Entity (File_Start .. Line_Start - 1)),
285 Visited => False,
286 Emit_Warning => True);
287 end Add_Entity;
289 -------------------
290 -- Add_Xref_File --
291 -------------------
293 procedure Add_Xref_File (File : String) is
294 File_Ref : File_Reference := Empty_File;
295 pragma Unreferenced (File_Ref);
297 Iterator : Expansion_Iterator;
299 procedure Add_Xref_File_Internal (File : String);
300 -- Do the actual addition of the file
302 ----------------------------
303 -- Add_Xref_File_Internal --
304 ----------------------------
306 procedure Add_Xref_File_Internal (File : String) is
307 begin
308 -- Case where we have an ALI file, accept it even though this is
309 -- not official usage, since the intention is obvious
311 if Tail (File, 4) = "." & Osint.ALI_Suffix.all then
312 File_Ref := Add_To_Xref_File
313 (File, Visited => False, Emit_Warning => True);
315 -- Normal non-ali file case
317 else
318 File_Ref := Add_To_Xref_File (File, Visited => True);
320 File_Ref := Add_To_Xref_File
321 (ALI_File_Name (File),
322 Visited => False, Emit_Warning => True);
323 end if;
324 end Add_Xref_File_Internal;
326 -- Start of processing for Add_Xref_File
328 begin
329 -- Check if we need to do the expansion
331 if Ada.Strings.Fixed.Index (File, "*") /= 0
332 or else Ada.Strings.Fixed.Index (File, "?") /= 0
333 then
334 Start_Expansion (Iterator, File);
336 loop
337 declare
338 S : constant String := Expansion (Iterator);
340 begin
341 exit when S'Length = 0;
342 Add_Xref_File_Internal (S);
343 end;
344 end loop;
346 else
347 Add_Xref_File_Internal (File);
348 end if;
349 end Add_Xref_File;
351 -----------------------
352 -- Current_Xref_File --
353 -----------------------
355 function Current_Xref_File (File : ALI_File) return File_Reference is
356 begin
357 return File.X_File;
358 end Current_Xref_File;
360 --------------------------
361 -- Default_Project_File --
362 --------------------------
364 function Default_Project_File (Dir_Name : String) return String is
365 My_Dir : Dir_Type;
366 Dir_Ent : File_Name_String;
367 Last : Natural;
369 begin
370 Open (My_Dir, Dir_Name);
372 loop
373 Read (My_Dir, Dir_Ent, Last);
374 exit when Last = 0;
376 if Tail (Dir_Ent (1 .. Last), 4) = ".adp" then
378 -- The first project file found is the good one
380 Close (My_Dir);
381 return Dir_Ent (1 .. Last);
382 end if;
383 end loop;
385 Close (My_Dir);
386 return String'(1 .. 0 => ' ');
388 exception
389 when Directory_Error => return String'(1 .. 0 => ' ');
390 end Default_Project_File;
392 ---------------
393 -- File_Name --
394 ---------------
396 function File_Name
397 (File : ALI_File;
398 Num : Positive) return File_Reference
400 begin
401 return File.Dep.Table (Num);
402 end File_Name;
404 --------------------
405 -- Find_ALI_Files --
406 --------------------
408 procedure Find_ALI_Files is
409 My_Dir : Rec_DIR;
410 Dir_Ent : File_Name_String;
411 Last : Natural;
413 File_Ref : File_Reference;
414 pragma Unreferenced (File_Ref);
416 function Open_Next_Dir return Boolean;
417 -- Tries to open the next object directory, and return False if
418 -- the directory cannot be opened.
420 -------------------
421 -- Open_Next_Dir --
422 -------------------
424 function Open_Next_Dir return Boolean is
425 begin
426 -- Until we are able to open a new directory
428 loop
429 declare
430 Obj_Dir : constant String := Next_Obj_Dir;
432 begin
433 -- Case of no more Obj_Dir lines
435 if Obj_Dir'Length = 0 then
436 return False;
437 end if;
439 Open (My_Dir.Dir, Obj_Dir);
440 exit;
442 exception
444 -- Could not open the directory
446 when Directory_Error => null;
447 end;
448 end loop;
450 return True;
451 end Open_Next_Dir;
453 -- Start of processing for Find_ALI_Files
455 begin
456 Reset_Obj_Dir;
458 if Open_Next_Dir then
459 loop
460 Read (My_Dir.Dir, Dir_Ent, Last);
462 if Last = 0 then
463 Close (My_Dir.Dir);
465 if not Open_Next_Dir then
466 return;
467 end if;
469 elsif Last > 4
470 and then Dir_Ent (Last - 3 .. Last) = "." & Osint.ALI_Suffix.all
471 then
472 File_Ref :=
473 Add_To_Xref_File (Dir_Ent (1 .. Last), Visited => False);
474 end if;
475 end loop;
476 end if;
477 end Find_ALI_Files;
479 -------------------
480 -- Get_Full_Type --
481 -------------------
483 function Get_Full_Type (Decl : Declaration_Reference) return String is
485 function Param_String return String;
486 -- Return the string to display depending on whether Decl is a parameter
488 ------------------
489 -- Param_String --
490 ------------------
492 function Param_String return String is
493 begin
494 if Is_Parameter (Decl) then
495 return "parameter ";
496 else
497 return "";
498 end if;
499 end Param_String;
501 -- Start of processing for Get_Full_Type
503 begin
504 case Get_Type (Decl) is
505 when 'A' => return "array type";
506 when 'B' => return "boolean type";
507 when 'C' => return "class-wide type";
508 when 'D' => return "decimal type";
509 when 'E' => return "enumeration type";
510 when 'F' => return "float type";
511 when 'H' => return "abstract type";
512 when 'I' => return "integer type";
513 when 'M' => return "modular type";
514 when 'O' => return "fixed type";
515 when 'P' => return "access type";
516 when 'R' => return "record type";
517 when 'S' => return "string type";
518 when 'T' => return "task type";
519 when 'W' => return "protected type";
521 when 'a' => return "array type";
522 when 'b' => return Param_String & "boolean object";
523 when 'c' => return Param_String & "class-wide object";
524 when 'd' => return Param_String & "decimal object";
525 when 'e' => return Param_String & "enumeration object";
526 when 'f' => return Param_String & "float object";
527 when 'i' => return Param_String & "integer object";
528 when 'm' => return Param_String & "modular object";
529 when 'o' => return Param_String & "fixed object";
530 when 'p' => return Param_String & "access object";
531 when 'r' => return Param_String & "record object";
532 when 's' => return Param_String & "string object";
533 when 't' => return Param_String & "task object";
534 when 'w' => return Param_String & "protected object";
535 when 'x' => return Param_String & "abstract procedure";
536 when 'y' => return Param_String & "abstract function";
538 when 'h' => return "interface";
539 when 'g' => return "macro";
540 when 'K' => return "package";
541 when 'k' => return "generic package";
542 when 'L' => return "statement label";
543 when 'l' => return "loop label";
544 when 'N' => return "named number";
545 when 'n' => return "enumeration literal";
546 when 'q' => return "block label";
547 when 'Q' => return "include file";
548 when 'U' => return "procedure";
549 when 'u' => return "generic procedure";
550 when 'V' => return "function";
551 when 'v' => return "generic function";
552 when 'X' => return "exception";
553 when 'Y' => return "entry";
555 when '+' => return "private type";
557 -- The above should be the only possibilities, but for this kind
558 -- of informational output, we don't want to bomb if we find
559 -- something else, so just return three question marks when we
560 -- have an unknown Abbrev value
562 when others =>
563 if Is_Parameter (Decl) then
564 return "parameter";
565 else
566 return "??? (" & Get_Type (Decl) & ")";
567 end if;
568 end case;
569 end Get_Full_Type;
571 --------------------------
572 -- Skip_To_First_X_Line --
573 --------------------------
575 procedure Skip_To_First_X_Line
576 (File : in out ALI_File;
577 D_Lines : Boolean;
578 W_Lines : Boolean)
580 Ali : String_Access renames File.Buffer;
581 Token : Positive;
582 Ptr : Positive := Ali'First;
583 Num_Dependencies : Natural := 0;
584 File_Start : Positive;
585 File_End : Positive;
586 Gnatchop_Offset : Integer;
587 Gnatchop_Name : Positive;
589 File_Ref : File_Reference;
590 pragma Unreferenced (File_Ref);
592 begin
593 -- Read all the lines possibly processing with-clauses and dependency
594 -- information and exit on finding the first Xref line.
595 -- A fall-through of the loop means that there is no xref information
596 -- which is an error condition.
598 while Ali (Ptr) /= EOF loop
599 if D_Lines and then Ali (Ptr) = 'D' then
601 -- Found dependency information. Format looks like:
602 -- D src-nam time-stmp checksum [subunit-name] [line:file-name]
604 -- Skip the D and parse the filenam
606 Ptr := Ptr + 1;
607 Parse_Token (Ali, Ptr, Token);
608 File_Start := Token;
609 File_End := Ptr - 1;
611 Num_Dependencies := Num_Dependencies + 1;
612 Set_Last (File.Dep, Num_Dependencies);
614 Parse_Token (Ali, Ptr, Token); -- Skip time-stamp
615 Parse_Token (Ali, Ptr, Token); -- Skip checksum
616 Parse_Token (Ali, Ptr, Token); -- Read next entity on the line
618 if not (Ali (Token) in '0' .. '9') then
619 Parse_Token (Ali, Ptr, Token); -- Was a subunit name
620 end if;
622 -- Did we have a gnatchop-ed file with a pragma Source_Reference ?
624 Gnatchop_Offset := 0;
626 if Ali (Token) in '0' .. '9' then
627 Gnatchop_Name := Token;
628 while Ali (Gnatchop_Name) /= ':' loop
629 Gnatchop_Name := Gnatchop_Name + 1;
630 end loop;
632 Gnatchop_Offset :=
633 2 - Natural'Value (Ali (Token .. Gnatchop_Name - 1));
634 Token := Gnatchop_Name + 1;
635 end if;
637 File.Dep.Table (Num_Dependencies) := Add_To_Xref_File
638 (Ali (File_Start .. File_End),
639 Gnatchop_File => Ali (Token .. Ptr - 1),
640 Gnatchop_Offset => Gnatchop_Offset);
642 elsif W_Lines and then Ali (Ptr) = 'W' then
644 -- Found with-clause information. Format looks like:
645 -- "W debug%s debug.adb debug.ali"
647 -- Skip the W and parse the .ali filename (3rd token)
649 Parse_Token (Ali, Ptr, Token);
650 Parse_Token (Ali, Ptr, Token);
651 Parse_Token (Ali, Ptr, Token);
653 File_Ref :=
654 Add_To_Xref_File (Ali (Token .. Ptr - 1), Visited => False);
656 elsif Ali (Ptr) = 'X' then
658 -- Found a cross-referencing line - stop processing
660 File.Current_Line := Ptr;
661 File.Xref_Line := Ptr;
662 return;
663 end if;
665 Parse_EOL (Ali, Ptr);
666 end loop;
668 raise No_Xref_Information;
669 end Skip_To_First_X_Line;
671 ----------
672 -- Open --
673 ----------
675 procedure Open
676 (Name : String;
677 File : out ALI_File;
678 Dependencies : Boolean := False)
680 Ali : String_Access renames File.Buffer;
681 pragma Warnings (Off, Ali);
683 begin
684 if File.Buffer /= null then
685 Free (File.Buffer);
686 end if;
688 Init (File.Dep);
690 begin
691 Read_File (Name, Ali);
693 exception
694 when Ada.Text_IO.Name_Error | Ada.Text_IO.End_Error =>
695 raise No_Xref_Information;
696 end;
698 Skip_To_First_X_Line (File, D_Lines => True, W_Lines => Dependencies);
699 end Open;
701 ---------------
702 -- Parse_EOL --
703 ---------------
705 procedure Parse_EOL
706 (Source : not null access String;
707 Ptr : in out Positive;
708 Skip_Continuation_Line : Boolean := False)
710 begin
711 loop
712 -- Skip to end of line
714 while Source (Ptr) /= ASCII.CR and then Source (Ptr) /= ASCII.LF
715 and then Source (Ptr) /= EOF
716 loop
717 Ptr := Ptr + 1;
718 end loop;
720 -- Skip CR or LF if not at end of file
722 if Source (Ptr) /= EOF then
723 Ptr := Ptr + 1;
724 end if;
726 -- Skip past CR/LF or LF/CR combination
728 if (Source (Ptr) = ASCII.CR or else Source (Ptr) = ASCII.LF)
729 and then Source (Ptr) /= Source (Ptr - 1)
730 then
731 Ptr := Ptr + 1;
732 end if;
734 exit when not Skip_Continuation_Line or else Source (Ptr) /= '.';
735 end loop;
736 end Parse_EOL;
738 ---------------------------
739 -- Parse_Identifier_Info --
740 ---------------------------
742 procedure Parse_Identifier_Info
743 (Pattern : Search_Pattern;
744 File : in out ALI_File;
745 Local_Symbols : Boolean;
746 Der_Info : Boolean := False;
747 Type_Tree : Boolean := False;
748 Wide_Search : Boolean := True;
749 Labels_As_Ref : Boolean := True)
751 Ptr : Positive renames File.Current_Line;
752 Ali : String_Access renames File.Buffer;
754 E_Line : Natural; -- Line number of current entity
755 E_Col : Natural; -- Column number of current entity
756 E_Type : Character; -- Type of current entity
757 E_Name : Positive; -- Pointer to begin of entity name
758 E_Global : Boolean; -- True iff entity is global
760 R_Line : Natural; -- Line number of current reference
761 R_Col : Natural; -- Column number of current reference
762 R_Type : Character; -- Type of current reference
764 Decl_Ref : Declaration_Reference;
765 File_Ref : File_Reference := Current_Xref_File (File);
767 function Get_Symbol_Name (Eun, Line, Col : Natural) return String;
768 -- Returns the symbol name for the entity defined at the specified
769 -- line and column in the dependent unit number Eun. For this we need
770 -- to parse the ali file again because the parent entity is not in
771 -- the declaration table if it did not match the search pattern.
773 procedure Skip_To_Matching_Closing_Bracket;
774 -- When Ptr points to an opening square bracket, moves it to the
775 -- character following the matching closing bracket
777 ---------------------
778 -- Get_Symbol_Name --
779 ---------------------
781 function Get_Symbol_Name (Eun, Line, Col : Natural) return String is
782 Ptr : Positive := 1;
783 E_Eun : Positive; -- Unit number of current entity
784 E_Line : Natural; -- Line number of current entity
785 E_Col : Natural; -- Column number of current entity
786 E_Name : Positive; -- Pointer to begin of entity name
788 begin
789 -- Look for the X lines corresponding to unit Eun
791 loop
792 if Ali (Ptr) = 'X' then
793 Ptr := Ptr + 1;
794 Parse_Number (Ali, Ptr, E_Eun);
795 exit when E_Eun = Eun;
796 end if;
798 Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
799 end loop;
801 -- Here we are in the right Ali section, we now look for the entity
802 -- declared at position (Line, Col).
804 loop
805 Parse_Number (Ali, Ptr, E_Line);
806 exit when Ali (Ptr) = EOF;
807 Ptr := Ptr + 1;
808 Parse_Number (Ali, Ptr, E_Col);
809 exit when Ali (Ptr) = EOF;
810 Ptr := Ptr + 1;
812 if Line = E_Line and then Col = E_Col then
813 Parse_Token (Ali, Ptr, E_Name);
814 return Ali (E_Name .. Ptr - 1);
815 end if;
817 Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
818 exit when Ali (Ptr) = EOF;
819 end loop;
821 -- We were not able to find the symbol, this should not happen but
822 -- since we don't want to stop here we return a string of three
823 -- question marks as the symbol name.
825 return "???";
826 end Get_Symbol_Name;
828 --------------------------------------
829 -- Skip_To_Matching_Closing_Bracket --
830 --------------------------------------
832 procedure Skip_To_Matching_Closing_Bracket is
833 Num_Brackets : Natural;
835 begin
836 Num_Brackets := 1;
837 while Num_Brackets /= 0 loop
838 Ptr := Ptr + 1;
839 if Ali (Ptr) = '[' then
840 Num_Brackets := Num_Brackets + 1;
841 elsif Ali (Ptr) = ']' then
842 Num_Brackets := Num_Brackets - 1;
843 end if;
844 end loop;
846 Ptr := Ptr + 1;
847 end Skip_To_Matching_Closing_Bracket;
849 -- Start of processing for Parse_Identifier_Info
851 begin
852 -- The identifier info looks like:
853 -- "38U9*Debug 12|36r6 36r19"
855 -- Extract the line, column and entity name information
857 Parse_Number (Ali, Ptr, E_Line);
859 if Ali (Ptr) > ' ' then
860 E_Type := Ali (Ptr);
861 Ptr := Ptr + 1;
862 end if;
864 -- Ignore some of the entities (labels,...)
866 case E_Type is
867 when 'l' | 'L' | 'q' =>
868 Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
869 return;
871 when others =>
872 null;
873 end case;
875 Parse_Number (Ali, Ptr, E_Col);
877 E_Global := False;
878 if Ali (Ptr) >= ' ' then
879 E_Global := (Ali (Ptr) = '*');
880 Ptr := Ptr + 1;
881 end if;
883 Parse_Token (Ali, Ptr, E_Name);
885 -- Exit if the symbol does not match
886 -- or if we have a local symbol and we do not want it
888 if (not Local_Symbols and not E_Global)
889 or else (Pattern.Initialized
890 and then not Match (Ali (E_Name .. Ptr - 1), Pattern.Entity))
891 or else (E_Name >= Ptr)
892 then
893 Decl_Ref := Add_Declaration
894 (File.X_File, Ali (E_Name .. Ptr - 1), E_Line, E_Col, E_Type,
895 Remove_Only => True);
896 Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
897 return;
898 end if;
900 -- Insert the declaration in the table
902 Decl_Ref := Add_Declaration
903 (File.X_File, Ali (E_Name .. Ptr - 1), E_Line, E_Col, E_Type);
905 if Ali (Ptr) = '[' then
906 Skip_To_Matching_Closing_Bracket;
907 end if;
909 -- Skip any renaming indication
911 if Ali (Ptr) = '=' then
912 declare
913 P_Line, P_Column : Natural;
914 pragma Warnings (Off, P_Line);
915 pragma Warnings (Off, P_Column);
916 begin
917 Ptr := Ptr + 1;
918 Parse_Number (Ali, Ptr, P_Line);
919 Ptr := Ptr + 1;
920 Parse_Number (Ali, Ptr, P_Column);
921 end;
922 end if;
924 if Ali (Ptr) = '<'
925 or else Ali (Ptr) = '('
926 or else Ali (Ptr) = '{'
927 then
928 -- Here we have a type derivation information. The format is
929 -- <3|12I45> which means that the current entity is derived from the
930 -- type defined in unit number 3, line 12 column 45. The pipe and
931 -- unit number is optional. It is specified only if the parent type
932 -- is not defined in the current unit.
934 -- We also have the format for generic instantiations, as in
935 -- 7a5*Uid(3|5I8[4|2]) 2|4r74
937 -- We could also have something like
938 -- 16I9*I<integer>
939 -- that indicates that I derives from the predefined type integer.
941 Ptr := Ptr + 1;
943 if Ali (Ptr) in '0' .. '9' then
944 Parse_Derived_Info : declare
945 P_Line : Natural; -- parent entity line
946 P_Column : Natural; -- parent entity column
947 P_Eun : Positive; -- parent entity file number
949 begin
950 Parse_Number (Ali, Ptr, P_Line);
952 -- If we have a pipe then the first number was the unit number
954 if Ali (Ptr) = '|' then
955 P_Eun := P_Line;
956 Ptr := Ptr + 1;
958 -- Now we have the line number
960 Parse_Number (Ali, Ptr, P_Line);
962 else
963 -- We don't have a unit number specified, so we set P_Eun to
964 -- the current unit.
966 for K in Dependencies_Tables.First .. Last (File.Dep) loop
967 P_Eun := K;
968 exit when File.Dep.Table (K) = File_Ref;
969 end loop;
970 end if;
972 -- Then parse the type and column number
974 Ptr := Ptr + 1;
975 Parse_Number (Ali, Ptr, P_Column);
977 -- Skip the information for generics instantiations
979 if Ali (Ptr) = '[' then
980 Skip_To_Matching_Closing_Bracket;
981 end if;
983 -- Skip '>', or ')' or '>'
985 Ptr := Ptr + 1;
987 -- The derived info is needed only is the derived info mode is
988 -- on or if we want to output the type hierarchy
990 if Der_Info or else Type_Tree then
991 declare
992 Symbol : constant String :=
993 Get_Symbol_Name (P_Eun, P_Line, P_Column);
994 begin
995 if Symbol /= "???" then
996 Add_Parent
997 (Decl_Ref,
998 Symbol,
999 P_Line,
1000 P_Column,
1001 File.Dep.Table (P_Eun));
1002 end if;
1003 end;
1004 end if;
1006 if Type_Tree
1007 and then (Pattern.File_Ref = Empty_File
1008 or else
1009 Pattern.File_Ref = Current_Xref_File (File))
1010 then
1011 Search_Parent_Tree : declare
1012 Pattern : Search_Pattern; -- Parent type pattern
1013 File_Pos_Backup : Positive;
1015 begin
1016 Add_Entity
1017 (Pattern,
1018 Get_Symbol_Name (P_Eun, P_Line, P_Column)
1019 & ':' & Get_Gnatchop_File (File.Dep.Table (P_Eun))
1020 & ':' & Get_Line (Get_Parent (Decl_Ref))
1021 & ':' & Get_Column (Get_Parent (Decl_Ref)),
1022 False);
1024 -- No default match is needed to look for the parent type
1025 -- since we are using the fully qualified symbol name:
1026 -- symbol:file:line:column
1028 Set_Default_Match (False);
1030 -- The parent hierarchy is defined in the same unit as
1031 -- the derived type. So we want to revisit the unit.
1033 File_Pos_Backup := File.Current_Line;
1035 Skip_To_First_X_Line
1036 (File, D_Lines => False, W_Lines => False);
1038 while File.Buffer (File.Current_Line) /= EOF loop
1039 Parse_X_Filename (File);
1040 Parse_Identifier_Info
1041 (Pattern => Pattern,
1042 File => File,
1043 Local_Symbols => False,
1044 Der_Info => Der_Info,
1045 Type_Tree => True,
1046 Wide_Search => False,
1047 Labels_As_Ref => Labels_As_Ref);
1048 end loop;
1050 File.Current_Line := File_Pos_Backup;
1051 end Search_Parent_Tree;
1052 end if;
1053 end Parse_Derived_Info;
1055 else
1056 while Ali (Ptr) /= '>'
1057 and then Ali (Ptr) /= ')'
1058 and then Ali (Ptr) /= '}'
1059 loop
1060 Ptr := Ptr + 1;
1061 end loop;
1062 Ptr := Ptr + 1;
1063 end if;
1064 end if;
1066 -- To find the body, we will have to parse the file too
1068 if Wide_Search then
1069 declare
1070 File_Ref : File_Reference;
1071 pragma Unreferenced (File_Ref);
1072 File_Name : constant String := Get_Gnatchop_File (File.X_File);
1073 begin
1074 File_Ref := Add_To_Xref_File (ALI_File_Name (File_Name), False);
1075 end;
1076 end if;
1078 -- Parse references to this entity.
1079 -- Ptr points to next reference with leading blanks
1081 loop
1082 -- Process references on current line
1084 while Ali (Ptr) = ' ' or else Ali (Ptr) = ASCII.HT loop
1086 -- For every reference read the line, type and column,
1087 -- optionally preceded by a file number and a pipe symbol.
1089 Parse_Number (Ali, Ptr, R_Line);
1091 if Ali (Ptr) = Pipe then
1092 Ptr := Ptr + 1;
1093 File_Ref := File_Name (File, R_Line);
1095 Parse_Number (Ali, Ptr, R_Line);
1096 end if;
1098 if Ali (Ptr) > ' ' then
1099 R_Type := Ali (Ptr);
1100 Ptr := Ptr + 1;
1101 end if;
1103 -- Imported entities might special indication as to their external
1104 -- name:
1105 -- 5U14*Foo2 5>20 6b<c,myfoo2>22
1107 if R_Type = 'b'
1108 and then Ali (Ptr) = '<'
1109 then
1110 while Ptr <= Ali'Last
1111 and then Ali (Ptr) /= '>'
1112 loop
1113 Ptr := Ptr + 1;
1114 end loop;
1115 Ptr := Ptr + 1;
1116 end if;
1118 Parse_Number (Ali, Ptr, R_Col);
1120 -- Insert the reference or body in the table
1122 Add_Reference
1123 (Decl_Ref, File_Ref, R_Line, R_Col, R_Type, Labels_As_Ref);
1125 -- Skip generic information, if any
1127 if Ali (Ptr) = '[' then
1128 declare
1129 Num_Nested : Integer := 1;
1131 begin
1132 Ptr := Ptr + 1;
1133 while Num_Nested /= 0 loop
1134 if Ali (Ptr) = ']' then
1135 Num_Nested := Num_Nested - 1;
1136 elsif Ali (Ptr) = '[' then
1137 Num_Nested := Num_Nested + 1;
1138 end if;
1140 Ptr := Ptr + 1;
1141 end loop;
1142 end;
1143 end if;
1145 end loop;
1147 Parse_EOL (Ali, Ptr);
1149 -- Loop until new line is no continuation line
1151 exit when Ali (Ptr) /= '.';
1152 Ptr := Ptr + 1;
1153 end loop;
1154 end Parse_Identifier_Info;
1156 ------------------
1157 -- Parse_Number --
1158 ------------------
1160 procedure Parse_Number
1161 (Source : not null access String;
1162 Ptr : in out Positive;
1163 Number : out Natural)
1165 begin
1166 -- Skip separators
1168 while Source (Ptr) = ' ' or else Source (Ptr) = ASCII.HT loop
1169 Ptr := Ptr + 1;
1170 end loop;
1172 Number := 0;
1173 while Source (Ptr) in '0' .. '9' loop
1174 Number :=
1175 10 * Number + (Character'Pos (Source (Ptr)) - Character'Pos ('0'));
1176 Ptr := Ptr + 1;
1177 end loop;
1178 end Parse_Number;
1180 -----------------
1181 -- Parse_Token --
1182 -----------------
1184 procedure Parse_Token
1185 (Source : not null access String;
1186 Ptr : in out Positive;
1187 Token_Ptr : out Positive)
1189 In_Quotes : Character := ASCII.NUL;
1191 begin
1192 -- Skip separators
1194 while Source (Ptr) = ' ' or else Source (Ptr) = ASCII.HT loop
1195 Ptr := Ptr + 1;
1196 end loop;
1198 Token_Ptr := Ptr;
1200 -- Find end-of-token
1202 while (In_Quotes /= ASCII.NUL or else
1203 not (Source (Ptr) = ' '
1204 or else Source (Ptr) = ASCII.HT
1205 or else Source (Ptr) = '<'
1206 or else Source (Ptr) = '{'
1207 or else Source (Ptr) = '['
1208 or else Source (Ptr) = '='
1209 or else Source (Ptr) = '('))
1210 and then Source (Ptr) >= ' '
1211 loop
1212 -- Double-quotes are used for operators
1213 -- Simple-quotes are used for character constants, for instance when
1214 -- they are found in an enumeration type "type A is ('+', '-');"
1216 case Source (Ptr) is
1217 when '"' | ''' =>
1218 if In_Quotes = Source (Ptr) then
1219 In_Quotes := ASCII.NUL;
1220 elsif In_Quotes = ASCII.NUL then
1221 In_Quotes := Source (Ptr);
1222 end if;
1224 when others =>
1225 null;
1226 end case;
1228 Ptr := Ptr + 1;
1229 end loop;
1230 end Parse_Token;
1232 ----------------------
1233 -- Parse_X_Filename --
1234 ----------------------
1236 procedure Parse_X_Filename (File : in out ALI_File) is
1237 Ali : String_Access renames File.Buffer;
1238 Ptr : Positive renames File.Current_Line;
1239 File_Nr : Natural;
1241 begin
1242 while Ali (Ptr) = 'X' loop
1244 -- The current line is the start of a new Xref file section,
1245 -- whose format looks like:
1247 -- " X 1 debug.ads"
1249 -- Skip the X and read the file number for the new X_File
1251 Ptr := Ptr + 1;
1252 Parse_Number (Ali, Ptr, File_Nr);
1254 if File_Nr > 0 then
1255 File.X_File := File.Dep.Table (File_Nr);
1256 end if;
1258 Parse_EOL (Ali, Ptr);
1259 end loop;
1260 end Parse_X_Filename;
1262 --------------------
1263 -- Print_Gnatfind --
1264 --------------------
1266 procedure Print_Gnatfind
1267 (References : Boolean;
1268 Full_Path_Name : Boolean)
1270 Decls : constant Declaration_Array_Access := Get_Declarations;
1271 Decl : Declaration_Reference;
1272 Arr : Reference_Array_Access;
1274 procedure Print_Ref
1275 (Ref : Reference;
1276 Msg : String := " ");
1277 -- Print a reference, according to the extended tag of the output
1279 ---------------
1280 -- Print_Ref --
1281 ---------------
1283 procedure Print_Ref
1284 (Ref : Reference;
1285 Msg : String := " ")
1287 F : String_Access :=
1288 Osint.To_Host_File_Spec
1289 (Get_Gnatchop_File (Ref, Full_Path_Name));
1291 Buffer : constant String :=
1292 F.all &
1293 ":" & Get_Line (Ref) &
1294 ":" & Get_Column (Ref) &
1295 ": ";
1297 Num_Blanks : Integer := Longest_File_Name + 10 - Buffer'Length;
1299 begin
1300 Free (F);
1301 Num_Blanks := Integer'Max (0, Num_Blanks);
1302 Write_Line
1303 (Buffer
1304 & String'(1 .. Num_Blanks => ' ')
1305 & Msg & " " & Get_Symbol (Decl));
1307 if Get_Source_Line (Ref)'Length /= 0 then
1308 Write_Line (" " & Get_Source_Line (Ref));
1309 end if;
1310 end Print_Ref;
1312 -- Start of processing for Print_Gnatfind
1314 begin
1315 for D in Decls'Range loop
1316 Decl := Decls (D);
1318 if Match (Decl) then
1320 -- Output the declaration
1322 declare
1323 Parent : constant Declaration_Reference := Get_Parent (Decl);
1325 F : String_Access :=
1326 Osint.To_Host_File_Spec
1327 (Get_Gnatchop_File (Decl, Full_Path_Name));
1329 Buffer : constant String :=
1330 F.all &
1331 ":" & Get_Line (Decl) &
1332 ":" & Get_Column (Decl) &
1333 ": ";
1335 Num_Blanks : Integer := Longest_File_Name + 10 - Buffer'Length;
1337 begin
1338 Free (F);
1339 Num_Blanks := Integer'Max (0, Num_Blanks);
1340 Write_Line
1341 (Buffer & String'(1 .. Num_Blanks => ' ')
1342 & "(spec) " & Get_Symbol (Decl));
1344 if Parent /= Empty_Declaration then
1345 F := Osint.To_Host_File_Spec (Get_Gnatchop_File (Parent));
1346 Write_Line
1347 (Buffer & String'(1 .. Num_Blanks => ' ')
1348 & " derived from " & Get_Symbol (Parent)
1349 & " ("
1350 & F.all
1351 & ':' & Get_Line (Parent)
1352 & ':' & Get_Column (Parent) & ')');
1353 Free (F);
1354 end if;
1355 end;
1357 if Get_Source_Line (Decl)'Length /= 0 then
1358 Write_Line (" " & Get_Source_Line (Decl));
1359 end if;
1361 -- Output the body (sorted)
1363 Arr := Get_References (Decl, Get_Bodies => True);
1365 for R in Arr'Range loop
1366 Print_Ref (Arr (R), "(body)");
1367 end loop;
1369 Free (Arr);
1371 if References then
1372 Arr := Get_References
1373 (Decl, Get_Writes => True, Get_Reads => True);
1375 for R in Arr'Range loop
1376 Print_Ref (Arr (R));
1377 end loop;
1379 Free (Arr);
1380 end if;
1381 end if;
1382 end loop;
1383 end Print_Gnatfind;
1385 ------------------
1386 -- Print_Unused --
1387 ------------------
1389 procedure Print_Unused (Full_Path_Name : Boolean) is
1390 Decls : constant Declaration_Array_Access := Get_Declarations;
1391 Decl : Declaration_Reference;
1392 Arr : Reference_Array_Access;
1393 F : String_Access;
1395 begin
1396 for D in Decls'Range loop
1397 Decl := Decls (D);
1399 if References_Count
1400 (Decl, Get_Reads => True, Get_Writes => True) = 0
1401 then
1402 F := Osint.To_Host_File_Spec
1403 (Get_Gnatchop_File (Decl, Full_Path_Name));
1404 Write_Str (Get_Symbol (Decl)
1405 & " ("
1406 & Get_Full_Type (Decl)
1407 & ") "
1408 & F.all
1409 & ':'
1410 & Get_Line (Decl)
1411 & ':'
1412 & Get_Column (Decl));
1413 Free (F);
1415 -- Print the body if any
1417 Arr := Get_References (Decl, Get_Bodies => True);
1419 for R in Arr'Range loop
1420 F := Osint.To_Host_File_Spec
1421 (Get_Gnatchop_File (Arr (R), Full_Path_Name));
1422 Write_Str (' '
1423 & F.all
1424 & ':' & Get_Line (Arr (R))
1425 & ':' & Get_Column (Arr (R)));
1426 Free (F);
1427 end loop;
1429 Write_Eol;
1430 Free (Arr);
1431 end if;
1432 end loop;
1433 end Print_Unused;
1435 --------------
1436 -- Print_Vi --
1437 --------------
1439 procedure Print_Vi (Full_Path_Name : Boolean) is
1440 Tab : constant Character := ASCII.HT;
1441 Decls : constant Declaration_Array_Access :=
1442 Get_Declarations (Sorted => False);
1443 Decl : Declaration_Reference;
1444 Arr : Reference_Array_Access;
1445 F : String_Access;
1447 begin
1448 for D in Decls'Range loop
1449 Decl := Decls (D);
1451 F := Osint.To_Host_File_Spec (Get_File (Decl, Full_Path_Name));
1452 Write_Line (Get_Symbol (Decl) & Tab & F.all & Tab & Get_Line (Decl));
1453 Free (F);
1455 -- Print the body if any
1457 Arr := Get_References (Decl, Get_Bodies => True);
1459 for R in Arr'Range loop
1460 F := Osint.To_Host_File_Spec (Get_File (Arr (R), Full_Path_Name));
1461 Write_Line
1462 (Get_Symbol (Decl) & Tab & F.all & Tab & Get_Line (Arr (R)));
1463 Free (F);
1464 end loop;
1466 Free (Arr);
1468 -- Print the modifications
1470 Arr := Get_References (Decl, Get_Writes => True, Get_Reads => True);
1472 for R in Arr'Range loop
1473 F := Osint.To_Host_File_Spec (Get_File (Arr (R), Full_Path_Name));
1474 Write_Line
1475 (Get_Symbol (Decl) & Tab & F.all & Tab & Get_Line (Arr (R)));
1476 Free (F);
1477 end loop;
1479 Free (Arr);
1480 end loop;
1481 end Print_Vi;
1483 ----------------
1484 -- Print_Xref --
1485 ----------------
1487 procedure Print_Xref (Full_Path_Name : Boolean) is
1488 Decls : constant Declaration_Array_Access := Get_Declarations;
1489 Decl : Declaration_Reference;
1491 Margin : constant := 10;
1492 -- Column where file names start
1494 procedure New_Line80;
1495 -- Go to start of new line
1497 procedure Print80 (S : String);
1498 -- Print the text, respecting the 80 columns rule
1500 procedure Print_Ref (Line, Column : String);
1501 -- The beginning of the output is aligned on a column multiple of 9
1503 procedure Print_List
1504 (Decl : Declaration_Reference;
1505 Msg : String;
1506 Get_Reads : Boolean := False;
1507 Get_Writes : Boolean := False;
1508 Get_Bodies : Boolean := False);
1509 -- Print a list of references. If the list is not empty, Msg will
1510 -- be printed prior to the list.
1512 ----------------
1513 -- New_Line80 --
1514 ----------------
1516 procedure New_Line80 is
1517 begin
1518 Write_Eol;
1519 Write_Str (String'(1 .. Margin - 1 => ' '));
1520 end New_Line80;
1522 -------------
1523 -- Print80 --
1524 -------------
1526 procedure Print80 (S : String) is
1527 Align : Natural := Margin - (Integer (Column) mod Margin);
1529 begin
1530 if Align = Margin then
1531 Align := 0;
1532 end if;
1534 Write_Str (String'(1 .. Align => ' ') & S);
1535 end Print80;
1537 ---------------
1538 -- Print_Ref --
1539 ---------------
1541 procedure Print_Ref (Line, Column : String) is
1542 Line_Align : constant Integer := 4 - Line'Length;
1544 S : constant String := String'(1 .. Line_Align => ' ')
1545 & Line & ':' & Column;
1547 Align : Natural := Margin - (Integer (Output.Column) mod Margin);
1549 begin
1550 if Align = Margin then
1551 Align := 0;
1552 end if;
1554 if Integer (Output.Column) + Align + S'Length > 79 then
1555 New_Line80;
1556 Align := 0;
1557 end if;
1559 Write_Str (String'(1 .. Align => ' ') & S);
1560 end Print_Ref;
1562 ----------------
1563 -- Print_List --
1564 ----------------
1566 procedure Print_List
1567 (Decl : Declaration_Reference;
1568 Msg : String;
1569 Get_Reads : Boolean := False;
1570 Get_Writes : Boolean := False;
1571 Get_Bodies : Boolean := False)
1573 Arr : Reference_Array_Access :=
1574 Get_References
1575 (Decl,
1576 Get_Writes => Get_Writes,
1577 Get_Reads => Get_Reads,
1578 Get_Bodies => Get_Bodies);
1579 File : File_Reference := Empty_File;
1580 F : String_Access;
1582 begin
1583 if Arr'Length /= 0 then
1584 Write_Eol;
1585 Write_Str (Msg);
1586 end if;
1588 for R in Arr'Range loop
1589 if Get_File_Ref (Arr (R)) /= File then
1590 if File /= Empty_File then
1591 New_Line80;
1592 end if;
1594 File := Get_File_Ref (Arr (R));
1595 F := Osint.To_Host_File_Spec
1596 (Get_Gnatchop_File (Arr (R), Full_Path_Name));
1598 if F = null then
1599 Write_Str ("<unknown> ");
1600 else
1601 Write_Str (F.all & ' ');
1602 Free (F);
1603 end if;
1604 end if;
1606 Print_Ref (Get_Line (Arr (R)), Get_Column (Arr (R)));
1607 end loop;
1609 Free (Arr);
1610 end Print_List;
1612 F : String_Access;
1614 -- Start of processing for Print_Xref
1616 begin
1617 for D in Decls'Range loop
1618 Decl := Decls (D);
1620 Write_Str (Get_Symbol (Decl));
1622 -- Put the declaration type in column Type_Position, but if the
1623 -- declaration name is too long, put at least one space between its
1624 -- name and its type.
1626 while Column < Type_Position - 1 loop
1627 Write_Char (' ');
1628 end loop;
1630 Write_Char (' ');
1632 Write_Line (Get_Full_Type (Decl));
1634 Write_Parent_Info : declare
1635 Parent : constant Declaration_Reference := Get_Parent (Decl);
1637 begin
1638 if Parent /= Empty_Declaration then
1639 Write_Str (" Ptype: ");
1640 F := Osint.To_Host_File_Spec (Get_Gnatchop_File (Parent));
1641 Print80 (F.all);
1642 Free (F);
1643 Print_Ref (Get_Line (Parent), Get_Column (Parent));
1644 Print80 (" " & Get_Symbol (Parent));
1645 Write_Eol;
1646 end if;
1647 end Write_Parent_Info;
1649 Write_Str (" Decl: ");
1650 F := Osint.To_Host_File_Spec
1651 (Get_Gnatchop_File (Decl, Full_Path_Name));
1653 if F = null then
1654 Print80 ("<unknown> ");
1655 else
1656 Print80 (F.all & ' ');
1657 Free (F);
1658 end if;
1660 Print_Ref (Get_Line (Decl), Get_Column (Decl));
1662 Print_List
1663 (Decl, " Body: ", Get_Bodies => True);
1664 Print_List
1665 (Decl, " Modi: ", Get_Writes => True);
1666 Print_List
1667 (Decl, " Ref: ", Get_Reads => True);
1668 Write_Eol;
1669 end loop;
1670 end Print_Xref;
1672 ------------
1673 -- Search --
1674 ------------
1676 procedure Search
1677 (Pattern : Search_Pattern;
1678 Local_Symbols : Boolean;
1679 Wide_Search : Boolean;
1680 Read_Only : Boolean;
1681 Der_Info : Boolean;
1682 Type_Tree : Boolean)
1684 type String_Access is access String;
1685 procedure Free is new Unchecked_Deallocation (String, String_Access);
1687 ALIfile : ALI_File;
1688 File_Ref : File_Reference;
1689 Strip_Num : Natural := 0;
1690 Ali_Name : String_Access;
1692 begin
1693 -- If we want all the .ali files, then find them
1695 if Wide_Search then
1696 Find_ALI_Files;
1697 end if;
1699 loop
1700 -- Get the next unread ali file
1702 File_Ref := Next_Unvisited_File;
1704 exit when File_Ref = Empty_File;
1706 -- Find the ALI file to use. Most of the time, it will be the unit
1707 -- name, with a different extension. However, when dealing with
1708 -- separates the ALI file is in fact the parent's ALI file (and this
1709 -- is recursive, in case the parent itself is a separate).
1711 Strip_Num := 0;
1712 loop
1713 Free (Ali_Name);
1714 Ali_Name := new String'
1715 (Get_File (File_Ref, With_Dir => True, Strip => Strip_Num));
1717 -- Stripped too many things...
1719 if Ali_Name.all = "" then
1720 if Get_Emit_Warning (File_Ref) then
1721 Set_Standard_Error;
1722 Write_Line
1723 ("warning : file " & Get_File (File_Ref, With_Dir => True)
1724 & " not found");
1725 Set_Standard_Output;
1726 end if;
1727 Free (Ali_Name);
1728 exit;
1730 -- If not found, try the parent's ALI file (this is needed for
1731 -- separate units and subprograms).
1733 -- Reset the cached directory first, in case the separate's
1734 -- ALI file is not in the same directory.
1736 elsif not File_Exists (Ali_Name.all) then
1737 Strip_Num := Strip_Num + 1;
1738 Reset_Directory (File_Ref);
1740 -- Else we finally found it
1742 else
1743 exit;
1744 end if;
1745 end loop;
1747 -- If we had to get the parent's ALI, insert it in the list as usual.
1748 -- This is to avoid parsing it twice in case it has already been
1749 -- parsed.
1751 if Ali_Name /= null and then Strip_Num /= 0 then
1752 File_Ref := Add_To_Xref_File
1753 (File_Name => Ali_Name.all,
1754 Visited => False);
1756 -- Now that we have a file name, parse it to find any reference to
1757 -- the entity.
1759 elsif Ali_Name /= null
1760 and then (Read_Only or else Is_Writable_File (Ali_Name.all))
1761 then
1762 begin
1763 Open (Ali_Name.all, ALIfile);
1764 while ALIfile.Buffer (ALIfile.Current_Line) /= EOF loop
1765 Parse_X_Filename (ALIfile);
1766 Parse_Identifier_Info
1767 (Pattern, ALIfile, Local_Symbols,
1768 Der_Info, Type_Tree, Wide_Search, Labels_As_Ref => True);
1769 end loop;
1771 exception
1772 when No_Xref_Information =>
1773 if Get_Emit_Warning (File_Ref) then
1774 Set_Standard_Error;
1775 Write_Line
1776 ("warning : No cross-referencing information in "
1777 & Ali_Name.all);
1778 Set_Standard_Output;
1779 end if;
1780 end;
1781 end if;
1782 end loop;
1784 Free (Ali_Name);
1785 end Search;
1787 -----------------
1788 -- Search_Xref --
1789 -----------------
1791 procedure Search_Xref
1792 (Local_Symbols : Boolean;
1793 Read_Only : Boolean;
1794 Der_Info : Boolean)
1796 ALIfile : ALI_File;
1797 File_Ref : File_Reference;
1798 Null_Pattern : Search_Pattern;
1800 begin
1801 Null_Pattern.Initialized := False;
1803 loop
1804 -- Find the next unvisited file
1806 File_Ref := Next_Unvisited_File;
1807 exit when File_Ref = Empty_File;
1809 -- Search the object directories for the .ali file
1811 declare
1812 F : constant String := Get_File (File_Ref, With_Dir => True);
1814 begin
1815 if Read_Only or else Is_Writable_File (F) then
1816 Open (F, ALIfile, True);
1818 while ALIfile.Buffer (ALIfile.Current_Line) /= EOF loop
1819 Parse_X_Filename (ALIfile);
1820 Parse_Identifier_Info
1821 (Null_Pattern, ALIfile, Local_Symbols, Der_Info,
1822 Labels_As_Ref => False);
1823 end loop;
1824 end if;
1826 exception
1827 when No_Xref_Information => null;
1828 end;
1829 end loop;
1830 end Search_Xref;
1832 end Xref_Lib;