* gimplify.c (find_single_pointer_decl_1): New static function.
[official-gcc.git] / gcc / ada / xref_lib.adb
blob454acccd9c2051701647758ca5b35cfaca4c73d6
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-2005 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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;
146 begin
147 -- Find the end of the first item in Entity (pattern or file?)
148 -- If there is no ':', we only have a pattern
150 File_Start := Index (Entity, ":");
152 -- If the regular expression is invalid, just consider it as a string
154 if File_Start = 0 then
155 begin
156 Pattern.Entity := Compile (Entity, Glob, False);
157 Pattern.Initialized := True;
159 exception
160 when Error_In_Regexp =>
162 -- The basic idea is to insert a \ before every character
164 declare
165 Tmp_Regexp : String (1 .. 2 * Entity'Length);
166 Index : Positive := 1;
168 begin
169 for J in Entity'Range loop
170 Tmp_Regexp (Index) := '\';
171 Tmp_Regexp (Index + 1) := Entity (J);
172 Index := Index + 2;
173 end loop;
175 Pattern.Entity := Compile (Tmp_Regexp, True, False);
176 Pattern.Initialized := True;
177 end;
178 end;
180 Set_Default_Match (True);
181 return;
182 end if;
184 -- If there is a dot in the pattern, then it is a file name
186 if (Glob and then
187 Index (Entity (Entity'First .. File_Start - 1), ".") /= 0)
188 or else
189 (not Glob
190 and then Index (Entity (Entity'First .. File_Start - 1),
191 "\.") /= 0)
192 then
193 Pattern.Entity := Compile (".*", False);
194 Pattern.Initialized := True;
195 File_Start := Entity'First;
197 else
198 -- If the regular expression is invalid, just consider it as a string
200 begin
201 Pattern.Entity :=
202 Compile (Entity (Entity'First .. File_Start - 1), Glob, False);
203 Pattern.Initialized := True;
205 exception
206 when Error_In_Regexp =>
208 -- The basic idea is to insert a \ before every character
210 declare
211 Tmp_Regexp : String (1 .. 2 * (File_Start - Entity'First));
212 Index : Positive := 1;
214 begin
215 for J in Entity'First .. File_Start - 1 loop
216 Tmp_Regexp (Index) := '\';
217 Tmp_Regexp (Index + 1) := Entity (J);
218 Index := Index + 2;
219 end loop;
221 Pattern.Entity := Compile (Tmp_Regexp, True, False);
222 Pattern.Initialized := True;
223 end;
224 end;
226 File_Start := File_Start + 1;
227 end if;
229 -- Parse the file name
231 Line_Start := Index (Entity (File_Start .. Entity'Last), ":");
233 -- Check if it was a disk:\directory item (for NT and OS/2)
235 if File_Start = Line_Start - 1
236 and then Line_Start < Entity'Last
237 and then Entity (Line_Start + 1) = '\'
238 then
239 Line_Start := Index (Entity (Line_Start + 1 .. Entity'Last), ":");
240 end if;
242 if Line_Start = 0 then
243 Line_Start := Entity'Length + 1;
245 elsif Line_Start /= Entity'Last then
246 Col_Start := Index (Entity (Line_Start + 1 .. Entity'Last), ":");
248 if Col_Start = 0 then
249 Col_Start := Entity'Last + 1;
250 end if;
252 if Col_Start > Line_Start + 1 then
253 begin
254 Line_Num := Natural'Value
255 (Entity (Line_Start + 1 .. Col_Start - 1));
257 exception
258 when Constraint_Error =>
259 raise Invalid_Argument;
260 end;
261 end if;
263 if Col_Start < Entity'Last then
264 begin
265 Col_Num := Natural'Value (Entity
266 (Col_Start + 1 .. Entity'Last));
268 exception
269 when Constraint_Error => raise Invalid_Argument;
270 end;
271 end if;
272 end if;
274 File_Ref :=
275 Add_To_Xref_File
276 (Entity (File_Start .. Line_Start - 1), Visited => True);
277 Pattern.File_Ref := File_Ref;
278 Add_Line (Pattern.File_Ref, Line_Num, Col_Num);
279 File_Ref :=
280 Add_To_Xref_File
281 (ALI_File_Name (Entity (File_Start .. Line_Start - 1)),
282 Visited => False,
283 Emit_Warning => True);
284 end Add_Entity;
286 -------------------
287 -- Add_Xref_File --
288 -------------------
290 procedure Add_Xref_File (File : String) is
291 File_Ref : File_Reference := Empty_File;
292 pragma Unreferenced (File_Ref);
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, Emit_Warning => True);
320 end if;
321 end Add_Xref_File_Internal;
323 -- Start of processing for Add_Xref_File
325 begin
326 -- Check if we need to do the expansion
328 if Ada.Strings.Fixed.Index (File, "*") /= 0
329 or else Ada.Strings.Fixed.Index (File, "?") /= 0
330 then
331 Start_Expansion (Iterator, File);
333 loop
334 declare
335 S : constant String := Expansion (Iterator);
337 begin
338 exit when S'Length = 0;
339 Add_Xref_File_Internal (S);
340 end;
341 end loop;
343 else
344 Add_Xref_File_Internal (File);
345 end if;
346 end Add_Xref_File;
348 -----------------------
349 -- Current_Xref_File --
350 -----------------------
352 function Current_Xref_File (File : ALI_File) return File_Reference is
353 begin
354 return File.X_File;
355 end Current_Xref_File;
357 --------------------------
358 -- Default_Project_File --
359 --------------------------
361 function Default_Project_File (Dir_Name : String) return String is
362 My_Dir : Dir_Type;
363 Dir_Ent : File_Name_String;
364 Last : Natural;
366 begin
367 Open (My_Dir, Dir_Name);
369 loop
370 Read (My_Dir, Dir_Ent, Last);
371 exit when Last = 0;
373 if Tail (Dir_Ent (1 .. Last), 4) = ".adp" then
375 -- The first project file found is the good one.
377 Close (My_Dir);
378 return Dir_Ent (1 .. Last);
379 end if;
380 end loop;
382 Close (My_Dir);
383 return String'(1 .. 0 => ' ');
385 exception
386 when Directory_Error => return String'(1 .. 0 => ' ');
387 end Default_Project_File;
389 ---------------
390 -- File_Name --
391 ---------------
393 function File_Name
394 (File : ALI_File;
395 Num : Positive) return File_Reference
397 begin
398 return File.Dep.Table (Num);
399 end File_Name;
401 --------------------
402 -- Find_ALI_Files --
403 --------------------
405 procedure Find_ALI_Files is
406 My_Dir : Rec_DIR;
407 Dir_Ent : File_Name_String;
408 Last : Natural;
410 File_Ref : File_Reference;
411 pragma Unreferenced (File_Ref);
413 function Open_Next_Dir return Boolean;
414 -- Tries to open the next object directory, and return False if
415 -- the directory cannot be opened.
417 -------------------
418 -- Open_Next_Dir --
419 -------------------
421 function Open_Next_Dir return Boolean is
422 begin
423 -- Until we are able to open a new directory
425 loop
426 declare
427 Obj_Dir : constant String := Next_Obj_Dir;
429 begin
430 -- Case of no more Obj_Dir lines
432 if Obj_Dir'Length = 0 then
433 return False;
434 end if;
436 Open (My_Dir.Dir, Obj_Dir);
437 exit;
439 exception
441 -- Could not open the directory
443 when Directory_Error => null;
444 end;
445 end loop;
447 return True;
448 end Open_Next_Dir;
450 -- Start of processing for Find_ALI_Files
452 begin
453 Reset_Obj_Dir;
455 if Open_Next_Dir then
456 loop
457 Read (My_Dir.Dir, Dir_Ent, Last);
459 if Last = 0 then
460 Close (My_Dir.Dir);
462 if not Open_Next_Dir then
463 return;
464 end if;
466 elsif Last > 4 and then Dir_Ent (Last - 3 .. Last) = ".ali" then
467 File_Ref :=
468 Add_To_Xref_File (Dir_Ent (1 .. Last), Visited => False);
469 end if;
470 end loop;
471 end if;
472 end Find_ALI_Files;
474 -------------------
475 -- Get_Full_Type --
476 -------------------
478 function Get_Full_Type (Decl : Declaration_Reference) return String is
480 function Param_String return String;
481 -- Return the string to display depending on whether Decl is a
482 -- parameter or not
484 ------------------
485 -- Param_String --
486 ------------------
488 function Param_String return String is
489 begin
490 if Is_Parameter (Decl) then
491 return "parameter ";
492 else
493 return "";
494 end if;
495 end Param_String;
497 -- Start of processing for Get_Full_Type
499 begin
500 case Get_Type (Decl) is
501 when 'A' => return "array type";
502 when 'B' => return "boolean type";
503 when 'C' => return "class-wide type";
504 when 'D' => return "decimal type";
505 when 'E' => return "enumeration type";
506 when 'F' => return "float type";
507 when 'I' => return "integer type";
508 when 'M' => return "modular type";
509 when 'O' => return "fixed type";
510 when 'P' => return "access type";
511 when 'R' => return "record type";
512 when 'S' => return "string type";
513 when 'T' => return "task type";
514 when 'W' => return "protected type";
516 when 'a' => return "array type";
517 when 'b' => return Param_String & "boolean object";
518 when 'c' => return Param_String & "class-wide object";
519 when 'd' => return Param_String & "decimal object";
520 when 'e' => return Param_String & "enumeration object";
521 when 'f' => return Param_String & "float object";
522 when 'i' => return Param_String & "integer object";
523 when 'm' => return Param_String & "modular object";
524 when 'o' => return Param_String & "fixed object";
525 when 'p' => return Param_String & "access object";
526 when 'r' => return Param_String & "record object";
527 when 's' => return Param_String & "string object";
528 when 't' => return Param_String & "task object";
529 when 'w' => return Param_String & "protected object";
530 when 'x' => return Param_String & "abstract procedure";
531 when 'y' => return Param_String & "abstract function";
533 when 'K' => return "package";
534 when 'k' => return "generic package";
535 when 'L' => return "statement label";
536 when 'l' => return "loop label";
537 when 'N' => return "named number";
538 when 'n' => return "enumeration literal";
539 when 'q' => return "block label";
540 when 'U' => return "procedure";
541 when 'u' => return "generic procedure";
542 when 'V' => return "function";
543 when 'v' => return "generic function";
544 when 'X' => return "exception";
545 when 'Y' => return "entry";
547 when '+' => return "private type";
549 -- The above should be the only possibilities, but for this kind
550 -- of informational output, we don't want to bomb if we find
551 -- something else, so just return three question marks when we
552 -- have an unknown Abbrev value
554 when others =>
555 return "??? (" & Get_Type (Decl) & ")";
556 end case;
557 end Get_Full_Type;
559 --------------------------
560 -- Skip_To_First_X_Line --
561 --------------------------
563 procedure Skip_To_First_X_Line
564 (File : in out ALI_File;
565 D_Lines : Boolean;
566 W_Lines : Boolean)
568 Ali : String_Access renames File.Buffer;
569 Token : Positive;
570 Ptr : Positive := Ali'First;
571 Num_Dependencies : Natural := 0;
572 File_Start : Positive;
573 File_End : Positive;
574 Gnatchop_Offset : Integer;
575 Gnatchop_Name : Positive;
577 File_Ref : File_Reference;
578 pragma Unreferenced (File_Ref);
580 begin
581 -- Read all the lines possibly processing with-clauses and dependency
582 -- information and exit on finding the first Xref line.
583 -- A fall-through of the loop means that there is no xref information
584 -- which is an error condition.
586 while Ali (Ptr) /= EOF loop
587 if D_Lines and then Ali (Ptr) = 'D' then
589 -- Found dependency information. Format looks like:
590 -- D src-nam time-stmp checksum [subunit-name] [line:file-name]
592 -- Skip the D and parse the filenam
594 Ptr := Ptr + 1;
595 Parse_Token (Ali, Ptr, Token);
596 File_Start := Token;
597 File_End := Ptr - 1;
599 Num_Dependencies := Num_Dependencies + 1;
600 Set_Last (File.Dep, Num_Dependencies);
602 Parse_Token (Ali, Ptr, Token); -- Skip time-stamp
603 Parse_Token (Ali, Ptr, Token); -- Skip checksum
604 Parse_Token (Ali, Ptr, Token); -- Read next entity on the line
606 if not (Ali (Token) in '0' .. '9') then
607 Parse_Token (Ali, Ptr, Token); -- Was a subunit name
608 end if;
610 -- Did we have a gnatchop-ed file with a pragma Source_Reference ?
612 Gnatchop_Offset := 0;
614 if Ali (Token) in '0' .. '9' then
615 Gnatchop_Name := Token;
616 while Ali (Gnatchop_Name) /= ':' loop
617 Gnatchop_Name := Gnatchop_Name + 1;
618 end loop;
620 Gnatchop_Offset :=
621 2 - Natural'Value (Ali (Token .. Gnatchop_Name - 1));
622 Token := Gnatchop_Name + 1;
623 end if;
625 File.Dep.Table (Num_Dependencies) := Add_To_Xref_File
626 (Ali (File_Start .. File_End),
627 Gnatchop_File => Ali (Token .. Ptr - 1),
628 Gnatchop_Offset => Gnatchop_Offset);
630 elsif W_Lines and then Ali (Ptr) = 'W' then
632 -- Found with-clause information. Format looks like:
633 -- "W debug%s debug.adb debug.ali"
635 -- Skip the W and parse the .ali filename (3rd token)
637 Parse_Token (Ali, Ptr, Token);
638 Parse_Token (Ali, Ptr, Token);
639 Parse_Token (Ali, Ptr, Token);
641 File_Ref :=
642 Add_To_Xref_File (Ali (Token .. Ptr - 1), Visited => False);
644 elsif Ali (Ptr) = 'X' then
646 -- Found a cross-referencing line - stop processing
648 File.Current_Line := Ptr;
649 File.Xref_Line := Ptr;
650 return;
651 end if;
653 Parse_EOL (Ali, Ptr);
654 end loop;
656 raise No_Xref_Information;
657 end Skip_To_First_X_Line;
659 ----------
660 -- Open --
661 ----------
663 procedure Open
664 (Name : String;
665 File : out ALI_File;
666 Dependencies : Boolean := False)
668 Ali : String_Access renames File.Buffer;
670 begin
671 if File.Buffer /= null then
672 Free (File.Buffer);
673 end if;
675 Init (File.Dep);
677 begin
678 Read_File (Name, Ali);
680 exception
681 when Ada.Text_IO.Name_Error | Ada.Text_IO.End_Error =>
682 raise No_Xref_Information;
683 end;
685 Skip_To_First_X_Line (File, D_Lines => True, W_Lines => Dependencies);
686 end Open;
688 ---------------
689 -- Parse_EOL --
690 ---------------
692 procedure Parse_EOL
693 (Source : access String;
694 Ptr : in out Positive;
695 Skip_Continuation_Line : Boolean := False)
697 begin
698 loop
699 -- Skip to end of line
701 while Source (Ptr) /= ASCII.CR and then Source (Ptr) /= ASCII.LF
702 and then Source (Ptr) /= EOF
703 loop
704 Ptr := Ptr + 1;
705 end loop;
707 if Source (Ptr) /= EOF then
708 Ptr := Ptr + 1; -- skip CR or LF
709 end if;
711 -- Skip past CR/LF or LF/CR combination
713 if (Source (Ptr) = ASCII.CR or else Source (Ptr) = ASCII.LF)
714 and then Source (Ptr) /= Source (Ptr - 1)
715 then
716 Ptr := Ptr + 1;
717 end if;
719 exit when not Skip_Continuation_Line or else Source (Ptr) /= '.';
720 end loop;
721 end Parse_EOL;
723 ---------------------------
724 -- Parse_Identifier_Info --
725 ---------------------------
727 procedure Parse_Identifier_Info
728 (Pattern : Search_Pattern;
729 File : in out ALI_File;
730 Local_Symbols : Boolean;
731 Der_Info : Boolean := False;
732 Type_Tree : Boolean := False;
733 Wide_Search : Boolean := True;
734 Labels_As_Ref : Boolean := True)
736 Ptr : Positive renames File.Current_Line;
737 Ali : String_Access renames File.Buffer;
739 E_Line : Natural; -- Line number of current entity
740 E_Col : Natural; -- Column number of current entity
741 E_Type : Character; -- Type of current entity
742 E_Name : Positive; -- Pointer to begin of entity name
743 E_Global : Boolean; -- True iff entity is global
745 R_Line : Natural; -- Line number of current reference
746 R_Col : Natural; -- Column number of current reference
747 R_Type : Character; -- Type of current reference
749 Decl_Ref : Declaration_Reference;
750 File_Ref : File_Reference := Current_Xref_File (File);
752 function Get_Symbol_Name (Eun, Line, Col : Natural) return String;
753 -- Returns the symbol name for the entity defined at the specified
754 -- line and column in the dependent unit number Eun. For this we need
755 -- to parse the ali file again because the parent entity is not in
756 -- the declaration table if it did not match the search pattern.
758 procedure Skip_To_Matching_Closing_Bracket;
759 -- When Ptr points to an opening square bracket, moves it to the
760 -- character following the matching closing bracket
762 ---------------------
763 -- Get_Symbol_Name --
764 ---------------------
766 function Get_Symbol_Name (Eun, Line, Col : Natural) return String is
767 Ptr : Positive := 1;
768 E_Eun : Positive; -- Unit number of current entity
769 E_Line : Natural; -- Line number of current entity
770 E_Col : Natural; -- Column number of current entity
771 E_Name : Positive; -- Pointer to begin of entity name
773 begin
774 -- Look for the X lines corresponding to unit Eun
776 loop
777 if Ali (Ptr) = 'X' then
778 Ptr := Ptr + 1;
779 Parse_Number (Ali, Ptr, E_Eun);
780 exit when E_Eun = Eun;
781 end if;
783 Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
784 end loop;
786 -- Here we are in the right Ali section, we now look for the entity
787 -- declared at position (Line, Col).
789 loop
790 Parse_Number (Ali, Ptr, E_Line);
791 exit when Ali (Ptr) = EOF;
792 Ptr := Ptr + 1;
793 Parse_Number (Ali, Ptr, E_Col);
794 exit when Ali (Ptr) = EOF;
795 Ptr := Ptr + 1;
797 if Line = E_Line and then Col = E_Col then
798 Parse_Token (Ali, Ptr, E_Name);
799 return Ali (E_Name .. Ptr - 1);
800 end if;
802 Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
803 exit when Ali (Ptr) = EOF;
804 end loop;
806 -- We were not able to find the symbol, this should not happend but
807 -- since we don't want to stop here we return a string of three
808 -- question marks as the symbol name.
810 return "???";
811 end Get_Symbol_Name;
813 --------------------------------------
814 -- Skip_To_Matching_Closing_Bracket --
815 --------------------------------------
817 procedure Skip_To_Matching_Closing_Bracket is
818 Num_Brackets : Natural;
820 begin
821 Num_Brackets := 1;
822 while Num_Brackets /= 0 loop
823 Ptr := Ptr + 1;
824 if Ali (Ptr) = '[' then
825 Num_Brackets := Num_Brackets + 1;
826 elsif Ali (Ptr) = ']' then
827 Num_Brackets := Num_Brackets - 1;
828 end if;
829 end loop;
831 Ptr := Ptr + 1;
832 end Skip_To_Matching_Closing_Bracket;
834 -- Start of processing for Parse_Identifier_Info
836 begin
837 -- The identifier info looks like:
838 -- "38U9*Debug 12|36r6 36r19"
840 -- Extract the line, column and entity name information
842 Parse_Number (Ali, Ptr, E_Line);
844 if Ali (Ptr) > ' ' then
845 E_Type := Ali (Ptr);
846 Ptr := Ptr + 1;
847 end if;
849 -- Ignore some of the entities (labels,...)
851 case E_Type is
852 when 'l' | 'L' | 'q' =>
853 Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
854 return;
856 when others =>
857 null;
858 end case;
860 Parse_Number (Ali, Ptr, E_Col);
862 E_Global := False;
863 if Ali (Ptr) >= ' ' then
864 E_Global := (Ali (Ptr) = '*');
865 Ptr := Ptr + 1;
866 end if;
868 Parse_Token (Ali, Ptr, E_Name);
870 -- Exit if the symbol does not match
871 -- or if we have a local symbol and we do not want it
873 if (not Local_Symbols and not E_Global)
874 or else (Pattern.Initialized
875 and then not Match (Ali (E_Name .. Ptr - 1), Pattern.Entity))
876 or else (E_Name >= Ptr)
877 then
878 Decl_Ref := Add_Declaration
879 (File.X_File, Ali (E_Name .. Ptr - 1), E_Line, E_Col, E_Type,
880 Remove_Only => True);
881 Parse_EOL (Ali, Ptr, Skip_Continuation_Line => True);
882 return;
883 end if;
885 -- Insert the declaration in the table
887 Decl_Ref := Add_Declaration
888 (File.X_File, Ali (E_Name .. Ptr - 1), E_Line, E_Col, E_Type);
890 if Ali (Ptr) = '[' then
891 Skip_To_Matching_Closing_Bracket;
893 elsif Ali (Ptr) = '<'
894 or else Ali (Ptr) = '('
895 or else Ali (Ptr) = '{'
896 then
897 -- Here we have a type derivation information. The format is
898 -- <3|12I45> which means that the current entity is derived from the
899 -- type defined in unit number 3, line 12 column 45. The pipe and
900 -- unit number is optional. It is specified only if the parent type
901 -- is not defined in the current unit.
903 -- We also have the format for generic instantiations, as in
904 -- 7a5*Uid(3|5I8[4|2]) 2|4r74
906 -- We could also have something like
907 -- 16I9*I<integer>
908 -- that indicates that I derives from the predefined type integer.
910 Ptr := Ptr + 1;
912 if Ali (Ptr) in '0' .. '9' then
913 Parse_Derived_Info : declare
914 P_Line : Natural; -- parent entity line
915 P_Column : Natural; -- parent entity column
916 P_Eun : Positive; -- parent entity file number
918 begin
919 Parse_Number (Ali, Ptr, P_Line);
921 -- If we have a pipe then the first number was the unit number
923 if Ali (Ptr) = '|' then
924 P_Eun := P_Line;
925 Ptr := Ptr + 1;
927 -- Now we have the line number
929 Parse_Number (Ali, Ptr, P_Line);
931 else
932 -- We don't have a unit number specified, so we set P_Eun to
933 -- the current unit.
935 for K in Dependencies_Tables.First .. Last (File.Dep) loop
936 P_Eun := K;
937 exit when File.Dep.Table (K) = File_Ref;
938 end loop;
939 end if;
941 -- Then parse the type and column number
943 Ptr := Ptr + 1;
944 Parse_Number (Ali, Ptr, P_Column);
946 -- Skip the information for generics instantiations
948 if Ali (Ptr) = '[' then
949 Skip_To_Matching_Closing_Bracket;
950 end if;
952 -- Skip '>', or ')' or '>'
954 Ptr := Ptr + 1;
956 -- The derived info is needed only is the derived info mode is
957 -- on or if we want to output the type hierarchy
959 if Der_Info or else Type_Tree then
960 declare
961 Symbol : constant String :=
962 Get_Symbol_Name (P_Eun, P_Line, P_Column);
963 begin
964 if Symbol /= "???" then
965 Add_Parent
966 (Decl_Ref,
967 Symbol,
968 P_Line,
969 P_Column,
970 File.Dep.Table (P_Eun));
971 end if;
972 end;
973 end if;
975 if Type_Tree
976 and then (Pattern.File_Ref = Empty_File
977 or else
978 Pattern.File_Ref = Current_Xref_File (File))
979 then
980 Search_Parent_Tree : declare
981 Pattern : Search_Pattern; -- Parent type pattern
982 File_Pos_Backup : Positive;
984 begin
985 Add_Entity
986 (Pattern,
987 Get_Symbol_Name (P_Eun, P_Line, P_Column)
988 & ':' & Get_Gnatchop_File (File.Dep.Table (P_Eun))
989 & ':' & Get_Line (Get_Parent (Decl_Ref))
990 & ':' & Get_Column (Get_Parent (Decl_Ref)),
991 False);
993 -- No default match is needed to look for the parent type
994 -- since we are using the fully qualified symbol name:
995 -- symbol:file:line:column
997 Set_Default_Match (False);
999 -- The parent hierarchy is defined in the same unit as
1000 -- the derived type. So we want to revisit the unit.
1002 File_Pos_Backup := File.Current_Line;
1004 Skip_To_First_X_Line
1005 (File, D_Lines => False, W_Lines => False);
1007 while File.Buffer (File.Current_Line) /= EOF loop
1008 Parse_X_Filename (File);
1009 Parse_Identifier_Info
1010 (Pattern => Pattern,
1011 File => File,
1012 Local_Symbols => False,
1013 Der_Info => Der_Info,
1014 Type_Tree => True,
1015 Wide_Search => False,
1016 Labels_As_Ref => Labels_As_Ref);
1017 end loop;
1019 File.Current_Line := File_Pos_Backup;
1020 end Search_Parent_Tree;
1021 end if;
1022 end Parse_Derived_Info;
1024 else
1025 while Ali (Ptr) /= '>'
1026 and then Ali (Ptr) /= ')'
1027 and then Ali (Ptr) /= '}'
1028 loop
1029 Ptr := Ptr + 1;
1030 end loop;
1031 Ptr := Ptr + 1;
1032 end if;
1034 elsif Ali (Ptr) = '=' then
1035 declare
1036 P_Line, P_Column : Natural;
1038 begin
1039 Ptr := Ptr + 1;
1040 Parse_Number (Ali, Ptr, P_Line);
1041 Ptr := Ptr + 1;
1042 Parse_Number (Ali, Ptr, P_Column);
1043 end;
1044 end if;
1046 -- To find the body, we will have to parse the file too
1048 if Wide_Search then
1049 declare
1050 File_Ref : File_Reference;
1051 pragma Unreferenced (File_Ref);
1052 File_Name : constant String := Get_Gnatchop_File (File.X_File);
1053 begin
1054 File_Ref := Add_To_Xref_File (ALI_File_Name (File_Name), False);
1055 end;
1056 end if;
1058 -- Parse references to this entity.
1059 -- Ptr points to next reference with leading blanks
1061 loop
1062 -- Process references on current line
1064 while Ali (Ptr) = ' ' or Ali (Ptr) = ASCII.HT loop
1066 -- For every reference read the line, type and column,
1067 -- optionally preceded by a file number and a pipe symbol.
1069 Parse_Number (Ali, Ptr, R_Line);
1071 if Ali (Ptr) = Pipe then
1072 Ptr := Ptr + 1;
1073 File_Ref := File_Name (File, R_Line);
1075 Parse_Number (Ali, Ptr, R_Line);
1076 end if;
1078 if Ali (Ptr) > ' ' then
1079 R_Type := Ali (Ptr);
1080 Ptr := Ptr + 1;
1081 end if;
1083 -- Imported entities might special indication as to their external
1084 -- name:
1085 -- 5U14*Foo2 5>20 6b<c,myfoo2>22
1087 if R_Type = 'b'
1088 and then Ali (Ptr) = '<'
1089 then
1090 while Ptr <= Ali'Last
1091 and then Ali (Ptr) /= '>'
1092 loop
1093 Ptr := Ptr + 1;
1094 end loop;
1095 Ptr := Ptr + 1;
1096 end if;
1098 Parse_Number (Ali, Ptr, R_Col);
1100 -- Insert the reference or body in the table
1102 Add_Reference
1103 (Decl_Ref, File_Ref, R_Line, R_Col, R_Type, Labels_As_Ref);
1105 -- Skip generic information, if any
1107 if Ali (Ptr) = '[' then
1108 declare
1109 Num_Nested : Integer := 1;
1111 begin
1112 Ptr := Ptr + 1;
1113 while Num_Nested /= 0 loop
1114 if Ali (Ptr) = ']' then
1115 Num_Nested := Num_Nested - 1;
1116 elsif Ali (Ptr) = '[' then
1117 Num_Nested := Num_Nested + 1;
1118 end if;
1120 Ptr := Ptr + 1;
1121 end loop;
1122 end;
1123 end if;
1125 end loop;
1127 Parse_EOL (Ali, Ptr);
1129 -- Loop until new line is no continuation line
1131 exit when Ali (Ptr) /= '.';
1132 Ptr := Ptr + 1;
1133 end loop;
1134 end Parse_Identifier_Info;
1136 ------------------
1137 -- Parse_Number --
1138 ------------------
1140 procedure Parse_Number
1141 (Source : access String;
1142 Ptr : in out Positive;
1143 Number : out Natural)
1145 begin
1146 -- Skip separators
1148 while Source (Ptr) = ' ' or else Source (Ptr) = ASCII.HT loop
1149 Ptr := Ptr + 1;
1150 end loop;
1152 Number := 0;
1153 while Source (Ptr) in '0' .. '9' loop
1154 Number :=
1155 10 * Number + (Character'Pos (Source (Ptr)) - Character'Pos ('0'));
1156 Ptr := Ptr + 1;
1157 end loop;
1158 end Parse_Number;
1160 -----------------
1161 -- Parse_Token --
1162 -----------------
1164 procedure Parse_Token
1165 (Source : access String;
1166 Ptr : in out Positive;
1167 Token_Ptr : out Positive)
1169 In_Quotes : Character := ASCII.NUL;
1171 begin
1172 -- Skip separators
1174 while Source (Ptr) = ' ' or else Source (Ptr) = ASCII.HT loop
1175 Ptr := Ptr + 1;
1176 end loop;
1178 Token_Ptr := Ptr;
1180 -- Find end-of-token
1182 while (In_Quotes /= ASCII.NUL or else
1183 not (Source (Ptr) = ' '
1184 or else Source (Ptr) = ASCII.HT
1185 or else Source (Ptr) = '<'
1186 or else Source (Ptr) = '{'
1187 or else Source (Ptr) = '['
1188 or else Source (Ptr) = '='
1189 or else Source (Ptr) = '('))
1190 and then Source (Ptr) >= ' '
1191 loop
1192 -- Double-quotes are used for operators
1193 -- Simple-quotes are used for character constants, for instance when
1194 -- they are found in an enumeration type "type A is ('+', '-');"
1196 case Source (Ptr) is
1197 when '"' | ''' =>
1198 if In_Quotes = Source (Ptr) then
1199 In_Quotes := ASCII.NUL;
1200 elsif In_Quotes = ASCII.NUL then
1201 In_Quotes := Source (Ptr);
1202 end if;
1204 when others =>
1205 null;
1206 end case;
1208 Ptr := Ptr + 1;
1209 end loop;
1210 end Parse_Token;
1212 ----------------------
1213 -- Parse_X_Filename --
1214 ----------------------
1216 procedure Parse_X_Filename (File : in out ALI_File) is
1217 Ali : String_Access renames File.Buffer;
1218 Ptr : Positive renames File.Current_Line;
1219 File_Nr : Natural;
1221 begin
1222 while Ali (Ptr) = 'X' loop
1224 -- The current line is the start of a new Xref file section,
1225 -- whose format looks like:
1227 -- " X 1 debug.ads"
1229 -- Skip the X and read the file number for the new X_File
1231 Ptr := Ptr + 1;
1232 Parse_Number (Ali, Ptr, File_Nr);
1234 if File_Nr > 0 then
1235 File.X_File := File.Dep.Table (File_Nr);
1236 end if;
1238 Parse_EOL (Ali, Ptr);
1239 end loop;
1240 end Parse_X_Filename;
1242 --------------------
1243 -- Print_Gnatfind --
1244 --------------------
1246 procedure Print_Gnatfind
1247 (References : Boolean;
1248 Full_Path_Name : Boolean)
1250 Decls : constant Declaration_Array_Access := Get_Declarations;
1251 Decl : Declaration_Reference;
1252 Arr : Reference_Array_Access;
1254 procedure Print_Ref
1255 (Ref : Reference;
1256 Msg : String := " ");
1257 -- Print a reference, according to the extended tag of the output
1259 ---------------
1260 -- Print_Ref --
1261 ---------------
1263 procedure Print_Ref
1264 (Ref : Reference;
1265 Msg : String := " ")
1267 F : String_Access :=
1268 Osint.To_Host_File_Spec
1269 (Get_Gnatchop_File (Ref, Full_Path_Name));
1271 Buffer : constant String :=
1272 F.all &
1273 ":" & Get_Line (Ref) &
1274 ":" & Get_Column (Ref) &
1275 ": ";
1277 Num_Blanks : Integer := Longest_File_Name + 10 - Buffer'Length;
1279 begin
1280 Free (F);
1281 Num_Blanks := Integer'Max (0, Num_Blanks);
1282 Write_Line
1283 (Buffer
1284 & String'(1 .. Num_Blanks => ' ')
1285 & Msg & " " & Get_Symbol (Decl));
1287 if Get_Source_Line (Ref)'Length /= 0 then
1288 Write_Line (" " & Get_Source_Line (Ref));
1289 end if;
1290 end Print_Ref;
1292 -- Start of processing for Print_Gnatfind
1294 begin
1295 for D in Decls'Range loop
1296 Decl := Decls (D);
1298 if Match (Decl) then
1300 -- Output the declaration
1302 declare
1303 Parent : constant Declaration_Reference := Get_Parent (Decl);
1305 F : String_Access :=
1306 Osint.To_Host_File_Spec
1307 (Get_Gnatchop_File (Decl, Full_Path_Name));
1309 Buffer : constant String :=
1310 F.all &
1311 ":" & Get_Line (Decl) &
1312 ":" & Get_Column (Decl) &
1313 ": ";
1315 Num_Blanks : Integer := Longest_File_Name + 10 - Buffer'Length;
1317 begin
1318 Free (F);
1319 Num_Blanks := Integer'Max (0, Num_Blanks);
1320 Write_Line
1321 (Buffer & String'(1 .. Num_Blanks => ' ')
1322 & "(spec) " & Get_Symbol (Decl));
1324 if Parent /= Empty_Declaration then
1325 F := Osint.To_Host_File_Spec (Get_Gnatchop_File (Parent));
1326 Write_Line
1327 (Buffer & String'(1 .. Num_Blanks => ' ')
1328 & " derived from " & Get_Symbol (Parent)
1329 & " ("
1330 & F.all
1331 & ':' & Get_Line (Parent)
1332 & ':' & Get_Column (Parent) & ')');
1333 Free (F);
1334 end if;
1335 end;
1337 if Get_Source_Line (Decl)'Length /= 0 then
1338 Write_Line (" " & Get_Source_Line (Decl));
1339 end if;
1341 -- Output the body (sorted)
1343 Arr := Get_References (Decl, Get_Bodies => True);
1345 for R in Arr'Range loop
1346 Print_Ref (Arr (R), "(body)");
1347 end loop;
1349 Free (Arr);
1351 if References then
1352 Arr := Get_References
1353 (Decl, Get_Writes => True, Get_Reads => True);
1355 for R in Arr'Range loop
1356 Print_Ref (Arr (R));
1357 end loop;
1359 Free (Arr);
1360 end if;
1361 end if;
1362 end loop;
1363 end Print_Gnatfind;
1365 ------------------
1366 -- Print_Unused --
1367 ------------------
1369 procedure Print_Unused (Full_Path_Name : in Boolean) is
1370 Decls : constant Declaration_Array_Access := Get_Declarations;
1371 Decl : Declaration_Reference;
1372 Arr : Reference_Array_Access;
1373 F : String_Access;
1375 begin
1376 for D in Decls'Range loop
1377 Decl := Decls (D);
1379 if References_Count
1380 (Decl, Get_Reads => True, Get_Writes => True) = 0
1381 then
1382 F := Osint.To_Host_File_Spec
1383 (Get_Gnatchop_File (Decl, Full_Path_Name));
1384 Write_Str (Get_Symbol (Decl)
1385 & " ("
1386 & Get_Full_Type (Decl)
1387 & ") "
1388 & F.all
1389 & ':'
1390 & Get_Line (Decl)
1391 & ':'
1392 & Get_Column (Decl));
1393 Free (F);
1395 -- Print the body if any
1397 Arr := Get_References (Decl, Get_Bodies => True);
1399 for R in Arr'Range loop
1400 F := Osint.To_Host_File_Spec
1401 (Get_Gnatchop_File (Arr (R), Full_Path_Name));
1402 Write_Str (' '
1403 & F.all
1404 & ':' & Get_Line (Arr (R))
1405 & ':' & Get_Column (Arr (R)));
1406 Free (F);
1407 end loop;
1409 Write_Eol;
1410 Free (Arr);
1411 end if;
1412 end loop;
1413 end Print_Unused;
1415 --------------
1416 -- Print_Vi --
1417 --------------
1419 procedure Print_Vi (Full_Path_Name : in Boolean) is
1420 Tab : constant Character := ASCII.HT;
1421 Decls : constant Declaration_Array_Access :=
1422 Get_Declarations (Sorted => False);
1423 Decl : Declaration_Reference;
1424 Arr : Reference_Array_Access;
1425 F : String_Access;
1427 begin
1428 for D in Decls'Range loop
1429 Decl := Decls (D);
1431 F := Osint.To_Host_File_Spec (Get_File (Decl, Full_Path_Name));
1432 Write_Line (Get_Symbol (Decl) & Tab & F.all & Tab & Get_Line (Decl));
1433 Free (F);
1435 -- Print the body if any
1437 Arr := Get_References (Decl, Get_Bodies => True);
1439 for R in Arr'Range loop
1440 F := Osint.To_Host_File_Spec (Get_File (Arr (R), Full_Path_Name));
1441 Write_Line
1442 (Get_Symbol (Decl) & Tab & F.all & Tab & Get_Line (Arr (R)));
1443 Free (F);
1444 end loop;
1446 Free (Arr);
1448 -- Print the modifications
1450 Arr := Get_References (Decl, Get_Writes => True, Get_Reads => True);
1452 for R in Arr'Range loop
1453 F := Osint.To_Host_File_Spec (Get_File (Arr (R), Full_Path_Name));
1454 Write_Line
1455 (Get_Symbol (Decl) & Tab & F.all & Tab & Get_Line (Arr (R)));
1456 Free (F);
1457 end loop;
1459 Free (Arr);
1460 end loop;
1461 end Print_Vi;
1463 ----------------
1464 -- Print_Xref --
1465 ----------------
1467 procedure Print_Xref (Full_Path_Name : in Boolean) is
1468 Decls : constant Declaration_Array_Access := Get_Declarations;
1469 Decl : Declaration_Reference;
1471 Margin : constant := 10;
1472 -- Column where file names start
1474 procedure New_Line80;
1475 -- Go to start of new line
1477 procedure Print80 (S : in String);
1478 -- Print the text, respecting the 80 columns rule.
1480 procedure Print_Ref (Line, Column : String);
1481 -- The beginning of the output is aligned on a column multiple of 9
1483 procedure Print_List
1484 (Decl : Declaration_Reference;
1485 Msg : String;
1486 Get_Reads : Boolean := False;
1487 Get_Writes : Boolean := False;
1488 Get_Bodies : Boolean := False);
1489 -- Print a list of references. If the list is not empty, Msg will
1490 -- be printed prior to the list.
1492 ----------------
1493 -- New_Line80 --
1494 ----------------
1496 procedure New_Line80 is
1497 begin
1498 Write_Eol;
1499 Write_Str (String'(1 .. Margin - 1 => ' '));
1500 end New_Line80;
1502 -------------
1503 -- Print80 --
1504 -------------
1506 procedure Print80 (S : in String) is
1507 Align : Natural := Margin - (Integer (Column) mod Margin);
1509 begin
1510 if Align = Margin then
1511 Align := 0;
1512 end if;
1514 Write_Str (String'(1 .. Align => ' ') & S);
1515 end Print80;
1517 ---------------
1518 -- Print_Ref --
1519 ---------------
1521 procedure Print_Ref (Line, Column : String) is
1522 Line_Align : constant Integer := 4 - Line'Length;
1524 S : constant String := String'(1 .. Line_Align => ' ')
1525 & Line & ':' & Column;
1527 Align : Natural := Margin - (Integer (Output.Column) mod Margin);
1529 begin
1530 if Align = Margin then
1531 Align := 0;
1532 end if;
1534 if Integer (Output.Column) + Align + S'Length > 79 then
1535 New_Line80;
1536 Align := 0;
1537 end if;
1539 Write_Str (String'(1 .. Align => ' ') & S);
1540 end Print_Ref;
1542 ----------------
1543 -- Print_List --
1544 ----------------
1546 procedure Print_List
1547 (Decl : Declaration_Reference;
1548 Msg : String;
1549 Get_Reads : Boolean := False;
1550 Get_Writes : Boolean := False;
1551 Get_Bodies : Boolean := False)
1553 Arr : Reference_Array_Access :=
1554 Get_References
1555 (Decl,
1556 Get_Writes => Get_Writes,
1557 Get_Reads => Get_Reads,
1558 Get_Bodies => Get_Bodies);
1559 File : File_Reference := Empty_File;
1560 F : String_Access;
1562 begin
1563 if Arr'Length /= 0 then
1564 Write_Eol;
1565 Write_Str (Msg);
1566 end if;
1568 for R in Arr'Range loop
1569 if Get_File_Ref (Arr (R)) /= File then
1570 if File /= Empty_File then
1571 New_Line80;
1572 end if;
1574 File := Get_File_Ref (Arr (R));
1575 F := Osint.To_Host_File_Spec
1576 (Get_Gnatchop_File (Arr (R), Full_Path_Name));
1577 Write_Str (F.all & ' ');
1578 Free (F);
1579 end if;
1581 Print_Ref (Get_Line (Arr (R)), Get_Column (Arr (R)));
1582 end loop;
1584 Free (Arr);
1585 end Print_List;
1587 F : String_Access;
1589 -- Start of processing for Print_Xref
1591 begin
1592 for D in Decls'Range loop
1593 Decl := Decls (D);
1595 Write_Str (Get_Symbol (Decl));
1597 while Column < Type_Position loop
1598 Write_Char (' ');
1599 end loop;
1601 Write_Line (Get_Full_Type (Decl));
1603 Write_Parent_Info : declare
1604 Parent : constant Declaration_Reference := Get_Parent (Decl);
1606 begin
1607 if Parent /= Empty_Declaration then
1608 Write_Str (" Ptype: ");
1609 F := Osint.To_Host_File_Spec (Get_Gnatchop_File (Parent));
1610 Print80 (F.all);
1611 Free (F);
1612 Print_Ref (Get_Line (Parent), Get_Column (Parent));
1613 Print80 (" " & Get_Symbol (Parent));
1614 Write_Eol;
1615 end if;
1616 end Write_Parent_Info;
1618 Write_Str (" Decl: ");
1619 F := Osint.To_Host_File_Spec
1620 (Get_Gnatchop_File (Decl, Full_Path_Name));
1621 Print80 (F.all & ' ');
1622 Free (F);
1623 Print_Ref (Get_Line (Decl), Get_Column (Decl));
1625 Print_List
1626 (Decl, " Body: ", Get_Bodies => True);
1627 Print_List
1628 (Decl, " Modi: ", Get_Writes => True);
1629 Print_List
1630 (Decl, " Ref: ", Get_Reads => True);
1631 Write_Eol;
1632 end loop;
1633 end Print_Xref;
1635 ------------
1636 -- Search --
1637 ------------
1639 procedure Search
1640 (Pattern : Search_Pattern;
1641 Local_Symbols : Boolean;
1642 Wide_Search : Boolean;
1643 Read_Only : Boolean;
1644 Der_Info : Boolean;
1645 Type_Tree : Boolean)
1647 type String_Access is access String;
1648 procedure Free is new Unchecked_Deallocation (String, String_Access);
1650 ALIfile : ALI_File;
1651 File_Ref : File_Reference;
1652 Strip_Num : Natural := 0;
1653 Ali_Name : String_Access;
1655 begin
1656 -- If we want all the .ali files, then find them
1658 if Wide_Search then
1659 Find_ALI_Files;
1660 end if;
1662 loop
1663 -- Get the next unread ali file
1665 File_Ref := Next_Unvisited_File;
1667 exit when File_Ref = Empty_File;
1669 -- Find the ALI file to use. Most of the time, it will be the unit
1670 -- name, with a different extension. However, when dealing with
1671 -- separates the ALI file is in fact the parent's ALI file (and this
1672 -- is recursive, in case the parent itself is a separate).
1674 Strip_Num := 0;
1675 loop
1676 Free (Ali_Name);
1677 Ali_Name := new String'
1678 (Get_File (File_Ref, With_Dir => True, Strip => Strip_Num));
1680 -- Stripped too many things...
1682 if Ali_Name.all = "" then
1683 if Get_Emit_Warning (File_Ref) then
1684 Set_Standard_Error;
1685 Write_Line
1686 ("warning : file " & Get_File (File_Ref, With_Dir => True)
1687 & " not found");
1688 Set_Standard_Output;
1689 end if;
1690 Free (Ali_Name);
1691 exit;
1693 -- If not found, try the parent's ALI file (this is needed for
1694 -- separate units and subprograms).
1696 -- Reset the cached directory first, in case the separate's
1697 -- ALI file is not in the same directory.
1699 elsif not File_Exists (Ali_Name.all) then
1700 Strip_Num := Strip_Num + 1;
1701 Reset_Directory (File_Ref);
1703 -- Else we finally found it
1705 else
1706 exit;
1707 end if;
1708 end loop;
1710 -- If we had to get the parent's ALI, insert it in the list as usual.
1711 -- This is to avoid parsing it twice in case it has already been
1712 -- parsed.
1714 if Ali_Name /= null and then Strip_Num /= 0 then
1715 File_Ref := Add_To_Xref_File
1716 (File_Name => Ali_Name.all,
1717 Visited => False);
1719 -- Now that we have a file name, parse it to find any reference to
1720 -- the entity.
1722 elsif Ali_Name /= null
1723 and then (Read_Only or else Is_Writable_File (Ali_Name.all))
1724 then
1725 begin
1726 Open (Ali_Name.all, ALIfile);
1727 while ALIfile.Buffer (ALIfile.Current_Line) /= EOF loop
1728 Parse_X_Filename (ALIfile);
1729 Parse_Identifier_Info
1730 (Pattern, ALIfile, Local_Symbols,
1731 Der_Info, Type_Tree, Wide_Search, Labels_As_Ref => True);
1732 end loop;
1734 exception
1735 when No_Xref_Information =>
1736 if Get_Emit_Warning (File_Ref) then
1737 Set_Standard_Error;
1738 Write_Line
1739 ("warning : No cross-referencing information in "
1740 & Ali_Name.all);
1741 Set_Standard_Output;
1742 end if;
1743 end;
1744 end if;
1745 end loop;
1747 Free (Ali_Name);
1748 end Search;
1750 -----------------
1751 -- Search_Xref --
1752 -----------------
1754 procedure Search_Xref
1755 (Local_Symbols : Boolean;
1756 Read_Only : Boolean;
1757 Der_Info : Boolean)
1759 ALIfile : ALI_File;
1760 File_Ref : File_Reference;
1761 Null_Pattern : Search_Pattern;
1763 begin
1764 Null_Pattern.Initialized := False;
1766 loop
1767 -- Find the next unvisited file
1769 File_Ref := Next_Unvisited_File;
1770 exit when File_Ref = Empty_File;
1772 -- Search the object directories for the .ali file
1774 declare
1775 F : constant String := Get_File (File_Ref, With_Dir => True);
1777 begin
1778 if Read_Only or else Is_Writable_File (F) then
1779 Open (F, ALIfile, True);
1781 while ALIfile.Buffer (ALIfile.Current_Line) /= EOF loop
1782 Parse_X_Filename (ALIfile);
1783 Parse_Identifier_Info
1784 (Null_Pattern, ALIfile, Local_Symbols, Der_Info,
1785 Labels_As_Ref => False);
1786 end loop;
1787 end if;
1789 exception
1790 when No_Xref_Information => null;
1791 end;
1792 end loop;
1793 end Search_Xref;
1795 end Xref_Lib;