1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2024, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Butil
; use Butil
;
27 with Debug
; use Debug
;
28 with Fname
; use Fname
;
30 with Osint
; use Osint
;
31 with Output
; use Output
;
32 with Snames
; use Snames
;
35 with GNAT
.Dynamic_HTables
; use GNAT
.Dynamic_HTables
;
36 with System
.String_Hash
;
41 -- Make control characters visible
47 -- The following type represents an invocation construct
49 type Invocation_Construct_Record
is record
50 Body_Placement
: Declaration_Placement_Kind
:= No_Declaration_Placement
;
51 -- The location of the invocation construct's body with respect to the
52 -- unit where it is declared.
54 Kind
: Invocation_Construct_Kind
:= Regular_Construct
;
55 -- The nature of the invocation construct
57 Signature
: Invocation_Signature_Id
:= No_Invocation_Signature
;
58 -- The invocation signature that uniquely identifies the invocation
59 -- construct in the ALI space.
61 Spec_Placement
: Declaration_Placement_Kind
:= No_Declaration_Placement
;
62 -- The location of the invocation construct's spec with respect to the
63 -- unit where it is declared.
66 -- The following type represents an invocation relation. It associates an
67 -- invoker that activates/calls/instantiates with a target.
69 type Invocation_Relation_Record
is record
70 Extra
: Name_Id
:= No_Name
;
71 -- The name of an additional entity used in error diagnostics
73 Invoker
: Invocation_Signature_Id
:= No_Invocation_Signature
;
74 -- The invocation signature that uniquely identifies the invoker within
77 Kind
: Invocation_Kind
:= No_Invocation
;
78 -- The nature of the invocation
80 Target
: Invocation_Signature_Id
:= No_Invocation_Signature
;
81 -- The invocation signature that uniquely identifies the target within
85 -- The following type represents an invocation signature. Its purpose is
86 -- to uniquely identify an invocation construct within the ALI space. The
87 -- signature comprises several pieces, some of which are used in error
88 -- diagnostics by the binder. Identification issues are resolved as
91 -- * The Column, Line, and Locations attributes together differentiate
92 -- between homonyms. In most cases, the Column and Line are sufficient
93 -- except when generic instantiations are involved. Together, the three
94 -- attributes offer a sequence of column-line pairs that eventually
95 -- reflect the location within the generic template.
97 -- * The Name attribute differentiates between invocation constructs at
98 -- the scope level. Since it is illegal for two entities with the same
99 -- name to coexist in the same scope, the Name attribute is sufficient
100 -- to distinguish them. Overloaded entities are already handled by the
101 -- Column, Line, and Locations attributes.
103 -- * The Scope attribute differentiates between invocation constructs at
104 -- various levels of nesting.
106 type Invocation_Signature_Record
is record
108 -- The column number where the invocation construct is declared
111 -- The line number where the invocation construct is declared
113 Locations
: Name_Id
:= No_Name
;
114 -- Sequence of column and line numbers within nested instantiations
116 Name
: Name_Id
:= No_Name
;
117 -- The name of the invocation construct
119 Scope
: Name_Id
:= No_Name
;
120 -- The qualified name of the scope where the invocation construct is
124 ---------------------
125 -- Data structures --
126 ---------------------
128 package Invocation_Constructs
is new Table
.Table
129 (Table_Index_Type
=> Invocation_Construct_Id
,
130 Table_Component_Type
=> Invocation_Construct_Record
,
131 Table_Low_Bound
=> First_Invocation_Construct
,
132 Table_Initial
=> 2500,
133 Table_Increment
=> 200,
134 Table_Name
=> "Invocation_Constructs");
136 package Invocation_Relations
is new Table
.Table
137 (Table_Index_Type
=> Invocation_Relation_Id
,
138 Table_Component_Type
=> Invocation_Relation_Record
,
139 Table_Low_Bound
=> First_Invocation_Relation
,
140 Table_Initial
=> 2500,
141 Table_Increment
=> 200,
142 Table_Name
=> "Invocation_Relation");
144 package Invocation_Signatures
is new Table
.Table
145 (Table_Index_Type
=> Invocation_Signature_Id
,
146 Table_Component_Type
=> Invocation_Signature_Record
,
147 Table_Low_Bound
=> First_Invocation_Signature
,
148 Table_Initial
=> 2500,
149 Table_Increment
=> 200,
150 Table_Name
=> "Invocation_Signatures");
152 procedure Destroy
(IS_Id
: in out Invocation_Signature_Id
);
153 -- Destroy an invocation signature with id IS_Id
156 (IS_Rec
: Invocation_Signature_Record
) return Bucket_Range_Type
;
157 -- Obtain the hash of key IS_Rec
159 package Sig_Map
is new Dynamic_Hash_Tables
160 (Key_Type
=> Invocation_Signature_Record
,
161 Value_Type
=> Invocation_Signature_Id
,
162 No_Value
=> No_Invocation_Signature
,
163 Expansion_Threshold
=> 1.5,
164 Expansion_Factor
=> 2,
165 Compression_Threshold
=> 0.3,
166 Compression_Factor
=> 2,
168 Destroy_Value
=> Destroy
,
171 -- The following map relates invocation signature records to invocation
174 Sig_To_Sig_Map
: constant Sig_Map
.Dynamic_Hash_Table
:=
175 Sig_Map
.Create
(500);
177 -- The folowing table maps declaration placement kinds to character codes
178 -- for invocation construct encoding in ALI files.
180 Declaration_Placement_Codes
:
181 constant array (Declaration_Placement_Kind
) of Character :=
184 No_Declaration_Placement
=> 'Z');
186 Compile_Time_Invocation_Graph_Encoding
: Invocation_Graph_Encoding_Kind
:=
188 -- The invocation-graph encoding format as specified at compile time. Do
189 -- not manipulate this value directly.
191 -- The following table maps invocation kinds to character codes for
192 -- invocation relation encoding in ALI files.
195 constant array (Invocation_Kind
) of Character :=
196 (Accept_Alternative
=> 'a',
199 Controlled_Adjustment
=> 'd',
200 Controlled_Finalization
=> 'e',
201 Controlled_Initialization
=> 'f',
202 Default_Initial_Condition_Verification
=> 'g',
203 Initial_Condition_Verification
=> 'h',
204 Instantiation
=> 'i',
205 Internal_Controlled_Adjustment
=> 'j',
206 Internal_Controlled_Finalization
=> 'k',
207 Internal_Controlled_Initialization
=> 'l',
208 Invariant_Verification
=> 'm',
209 Postcondition_Verification
=> 'n',
210 Protected_Entry_Call
=> 'o',
211 Protected_Subprogram_Call
=> 'p',
212 Task_Activation
=> 'q',
213 Task_Entry_Call
=> 'r',
214 Type_Initialization
=> 's',
215 No_Invocation
=> 'Z');
217 -- The following table maps invocation construct kinds to character codes
218 -- for invocation construct encoding in ALI files.
220 Invocation_Construct_Codes
:
221 constant array (Invocation_Construct_Kind
) of Character :=
222 (Elaborate_Body_Procedure
=> 'b',
223 Elaborate_Spec_Procedure
=> 's',
224 Regular_Construct
=> 'Z');
226 -- The following table maps invocation-graph encoding kinds to character
227 -- codes for invocation-graph encoding in ALI files.
229 Invocation_Graph_Encoding_Codes
:
230 constant array (Invocation_Graph_Encoding_Kind
) of Character :=
231 (Full_Path_Encoding
=> 'f',
232 Endpoints_Encoding
=> 'e',
235 -- The following table maps invocation-graph line kinds to character codes
236 -- used in ALI files.
238 Invocation_Graph_Line_Codes
:
239 constant array (Invocation_Graph_Line_Kind
) of Character :=
240 (Invocation_Construct_Line
=> 'c',
241 Invocation_Graph_Attributes_Line
=> 'a',
242 Invocation_Relation_Line
=> 'r');
244 -- The following variable records which characters currently are used as
245 -- line type markers in the ALI file. This is used in Scan_ALI to detect
246 -- (or skip) invalid lines.
248 Known_ALI_Lines
: constant array (Character range 'A' .. 'Z') of Boolean :=
250 'C' |
-- SCO information
253 'G' |
-- invocation graph
255 'K' |
-- CUDA kernels
256 'L' |
-- linker option
257 'M' |
-- main program
261 'S' |
-- specific dispatching
262 'T' |
-- task stack information
267 'Y' |
-- limited_with
268 'Z' -- implicit with from instantiation
273 'B' |
'F' |
'H' |
'J' |
'O' |
'Q' => False);
275 ------------------------------
276 -- Add_Invocation_Construct --
277 ------------------------------
279 procedure Add_Invocation_Construct
280 (Body_Placement
: Declaration_Placement_Kind
;
281 Kind
: Invocation_Construct_Kind
;
282 Signature
: Invocation_Signature_Id
;
283 Spec_Placement
: Declaration_Placement_Kind
;
284 Update_Units
: Boolean := True)
287 pragma Assert
(Present
(Signature
));
289 -- Create a invocation construct from the scanned attributes
291 Invocation_Constructs
.Append
292 ((Body_Placement
=> Body_Placement
,
294 Signature
=> Signature
,
295 Spec_Placement
=> Spec_Placement
));
297 -- Update the invocation construct counter of the current unit only when
298 -- requested by the caller.
302 Curr_Unit
: Unit_Record
renames Units
.Table
(Units
.Last
);
305 Curr_Unit
.Last_Invocation_Construct
:= Invocation_Constructs
.Last
;
308 end Add_Invocation_Construct
;
310 -----------------------------
311 -- Add_Invocation_Relation --
312 -----------------------------
314 procedure Add_Invocation_Relation
316 Invoker
: Invocation_Signature_Id
;
317 Kind
: Invocation_Kind
;
318 Target
: Invocation_Signature_Id
;
319 Update_Units
: Boolean := True)
322 pragma Assert
(Present
(Invoker
));
323 pragma Assert
(Kind
/= No_Invocation
);
324 pragma Assert
(Present
(Target
));
326 -- Create an invocation relation from the scanned attributes
328 Invocation_Relations
.Append
334 -- Update the invocation relation counter of the current unit only when
335 -- requested by the caller.
339 Curr_Unit
: Unit_Record
renames Units
.Table
(Units
.Last
);
342 Curr_Unit
.Last_Invocation_Relation
:= Invocation_Relations
.Last
;
345 end Add_Invocation_Relation
;
351 function Body_Placement
352 (IC_Id
: Invocation_Construct_Id
) return Declaration_Placement_Kind
355 pragma Assert
(Present
(IC_Id
));
356 return Invocation_Constructs
.Table
(IC_Id
).Body_Placement
;
359 ----------------------------------------
360 -- Code_To_Declaration_Placement_Kind --
361 ----------------------------------------
363 function Code_To_Declaration_Placement_Kind
364 (Code
: Character) return Declaration_Placement_Kind
367 -- Determine which placement kind corresponds to the character code by
368 -- traversing the contents of the mapping table.
370 for Kind
in Declaration_Placement_Kind
loop
371 if Declaration_Placement_Codes
(Kind
) = Code
then
377 end Code_To_Declaration_Placement_Kind
;
379 ---------------------------------------
380 -- Code_To_Invocation_Construct_Kind --
381 ---------------------------------------
383 function Code_To_Invocation_Construct_Kind
384 (Code
: Character) return Invocation_Construct_Kind
387 -- Determine which invocation construct kind matches the character code
388 -- by traversing the contents of the mapping table.
390 for Kind
in Invocation_Construct_Kind
loop
391 if Invocation_Construct_Codes
(Kind
) = Code
then
397 end Code_To_Invocation_Construct_Kind
;
399 --------------------------------------------
400 -- Code_To_Invocation_Graph_Encoding_Kind --
401 --------------------------------------------
403 function Code_To_Invocation_Graph_Encoding_Kind
404 (Code
: Character) return Invocation_Graph_Encoding_Kind
407 -- Determine which invocation-graph encoding kind matches the character
408 -- code by traversing the contents of the mapping table.
410 for Kind
in Invocation_Graph_Encoding_Kind
loop
411 if Invocation_Graph_Encoding_Codes
(Kind
) = Code
then
417 end Code_To_Invocation_Graph_Encoding_Kind
;
419 -----------------------------
420 -- Code_To_Invocation_Kind --
421 -----------------------------
423 function Code_To_Invocation_Kind
424 (Code
: Character) return Invocation_Kind
427 -- Determine which invocation kind corresponds to the character code by
428 -- traversing the contents of the mapping table.
430 for Kind
in Invocation_Kind
loop
431 if Invocation_Codes
(Kind
) = Code
then
437 end Code_To_Invocation_Kind
;
439 ----------------------------------------
440 -- Code_To_Invocation_Graph_Line_Kind --
441 ----------------------------------------
443 function Code_To_Invocation_Graph_Line_Kind
444 (Code
: Character) return Invocation_Graph_Line_Kind
447 -- Determine which invocation-graph line kind matches the character
448 -- code by traversing the contents of the mapping table.
450 for Kind
in Invocation_Graph_Line_Kind
loop
451 if Invocation_Graph_Line_Codes
(Kind
) = Code
then
457 end Code_To_Invocation_Graph_Line_Kind
;
463 function Column
(IS_Id
: Invocation_Signature_Id
) return Nat
is
465 pragma Assert
(Present
(IS_Id
));
466 return Invocation_Signatures
.Table
(IS_Id
).Column
;
469 ----------------------------------------
470 -- Declaration_Placement_Kind_To_Code --
471 ----------------------------------------
473 function Declaration_Placement_Kind_To_Code
474 (Kind
: Declaration_Placement_Kind
) return Character
477 return Declaration_Placement_Codes
(Kind
);
478 end Declaration_Placement_Kind_To_Code
;
484 procedure Destroy
(IS_Id
: in out Invocation_Signature_Id
) is
485 pragma Unreferenced
(IS_Id
);
494 function Extra
(IR_Id
: Invocation_Relation_Id
) return Name_Id
is
496 pragma Assert
(Present
(IR_Id
));
497 return Invocation_Relations
.Table
(IR_Id
).Extra
;
500 -----------------------------------
501 -- For_Each_Invocation_Construct --
502 -----------------------------------
504 procedure For_Each_Invocation_Construct
505 (Processor
: Invocation_Construct_Processor_Ptr
)
508 pragma Assert
(Processor
/= null);
510 for IC_Id
in Invocation_Constructs
.First
..
511 Invocation_Constructs
.Last
513 Processor
.all (IC_Id
);
515 end For_Each_Invocation_Construct
;
517 -----------------------------------
518 -- For_Each_Invocation_Construct --
519 -----------------------------------
521 procedure For_Each_Invocation_Construct
523 Processor
: Invocation_Construct_Processor_Ptr
)
525 pragma Assert
(Present
(U_Id
));
526 pragma Assert
(Processor
/= null);
528 U_Rec
: Unit_Record
renames Units
.Table
(U_Id
);
531 for IC_Id
in U_Rec
.First_Invocation_Construct
..
532 U_Rec
.Last_Invocation_Construct
534 Processor
.all (IC_Id
);
536 end For_Each_Invocation_Construct
;
538 ----------------------------------
539 -- For_Each_Invocation_Relation --
540 ----------------------------------
542 procedure For_Each_Invocation_Relation
543 (Processor
: Invocation_Relation_Processor_Ptr
)
546 pragma Assert
(Processor
/= null);
548 for IR_Id
in Invocation_Relations
.First
..
549 Invocation_Relations
.Last
551 Processor
.all (IR_Id
);
553 end For_Each_Invocation_Relation
;
555 ----------------------------------
556 -- For_Each_Invocation_Relation --
557 ----------------------------------
559 procedure For_Each_Invocation_Relation
561 Processor
: Invocation_Relation_Processor_Ptr
)
563 pragma Assert
(Present
(U_Id
));
564 pragma Assert
(Processor
/= null);
566 U_Rec
: Unit_Record
renames Units
.Table
(U_Id
);
569 for IR_Id
in U_Rec
.First_Invocation_Relation
..
570 U_Rec
.Last_Invocation_Relation
572 Processor
.all (IR_Id
);
574 end For_Each_Invocation_Relation
;
581 (IS_Rec
: Invocation_Signature_Record
) return Bucket_Range_Type
583 function String_Hash
is new System
.String_Hash
.Hash
584 (Char_Type
=> Character,
586 Hash_Type
=> Bucket_Range_Type
);
588 Buffer
: Bounded_String
(2052);
591 -- The hash is obtained from a signature based on the scope, name, line
592 -- number, column number, and locations, in the following format:
594 -- scope__name__line_column__locations
596 Append
(Buffer
, IS_Rec
.Scope
);
597 Append
(Buffer
, "__");
598 Append
(Buffer
, IS_Rec
.Name
);
599 Append
(Buffer
, "__");
600 Append
(Buffer
, IS_Rec
.Line
);
601 Append
(Buffer
, '_');
602 Append
(Buffer
, IS_Rec
.Column
);
604 if IS_Rec
.Locations
/= No_Name
then
605 Append
(Buffer
, "__");
606 Append
(Buffer
, IS_Rec
.Locations
);
609 return String_Hash
(To_String
(Buffer
));
616 procedure Initialize_ALI
is
618 -- When (re)initializing ALI data structures the ALI user expects to
619 -- get a fresh set of data structures. Thus we first need to erase the
620 -- marks put in the name table by the previous set of ALI routine calls.
621 -- These two loops are empty and harmless the first time in.
623 for J
in ALIs
.First
.. ALIs
.Last
loop
624 Set_Name_Table_Int
(ALIs
.Table
(J
).Afile
, 0);
627 for J
in Units
.First
.. Units
.Last
loop
628 Set_Name_Table_Int
(Units
.Table
(J
).Uname
, 0);
631 -- Free argument table strings
633 for J
in Args
.First
.. Args
.Last
loop
634 Free
(Args
.Table
(J
));
637 -- Initialize all tables
640 Invocation_Constructs
.Init
;
641 Invocation_Relations
.Init
;
642 Invocation_Signatures
.Init
;
654 -- Add dummy zeroth item in Linker_Options and Notes for sort calls
656 Linker_Options
.Increment_Last
;
657 Notes
.Increment_Last
;
659 -- Initialize global variables recording cumulative options in all
660 -- ALI files that are read for a given processing run in gnatbind.
662 Dynamic_Elaboration_Checks_Specified
:= False;
663 Locking_Policy_Specified
:= ' ';
664 No_Normalize_Scalars_Specified
:= False;
665 No_Object_Specified
:= False;
666 No_Component_Reordering_Specified
:= False;
667 GNATprove_Mode_Specified
:= False;
668 Interrupts_Default_To_System_Specified
:= False;
669 Normalize_Scalars_Specified
:= False;
670 Partition_Elaboration_Policy_Specified
:= ' ';
671 Queuing_Policy_Specified
:= ' ';
672 SSO_Default_Specified
:= False;
673 Task_Dispatching_Policy_Specified
:= ' ';
674 Unreserve_All_Interrupts_Specified
:= False;
675 Zero_Cost_Exceptions_Specified
:= False;
678 ---------------------------------------
679 -- Invocation_Construct_Kind_To_Code --
680 ---------------------------------------
682 function Invocation_Construct_Kind_To_Code
683 (Kind
: Invocation_Construct_Kind
) return Character
686 return Invocation_Construct_Codes
(Kind
);
687 end Invocation_Construct_Kind_To_Code
;
689 -------------------------------
690 -- Invocation_Graph_Encoding --
691 -------------------------------
693 function Invocation_Graph_Encoding
return Invocation_Graph_Encoding_Kind
is
695 return Compile_Time_Invocation_Graph_Encoding
;
696 end Invocation_Graph_Encoding
;
698 --------------------------------------------
699 -- Invocation_Graph_Encoding_Kind_To_Code --
700 --------------------------------------------
702 function Invocation_Graph_Encoding_Kind_To_Code
703 (Kind
: Invocation_Graph_Encoding_Kind
) return Character
706 return Invocation_Graph_Encoding_Codes
(Kind
);
707 end Invocation_Graph_Encoding_Kind_To_Code
;
709 ----------------------------------------
710 -- Invocation_Graph_Line_Kind_To_Code --
711 ----------------------------------------
713 function Invocation_Graph_Line_Kind_To_Code
714 (Kind
: Invocation_Graph_Line_Kind
) return Character
717 return Invocation_Graph_Line_Codes
(Kind
);
718 end Invocation_Graph_Line_Kind_To_Code
;
720 -----------------------------
721 -- Invocation_Kind_To_Code --
722 -----------------------------
724 function Invocation_Kind_To_Code
725 (Kind
: Invocation_Kind
) return Character
728 return Invocation_Codes
(Kind
);
729 end Invocation_Kind_To_Code
;
731 -----------------------------
732 -- Invocation_Signature_Of --
733 -----------------------------
735 function Invocation_Signature_Of
740 Scope
: Name_Id
) return Invocation_Signature_Id
742 IS_Rec
: constant Invocation_Signature_Record
:=
745 Locations
=> Locations
,
748 IS_Id
: Invocation_Signature_Id
;
751 IS_Id
:= Sig_Map
.Get
(Sig_To_Sig_Map
, IS_Rec
);
753 -- The invocation signature lacks an id. This indicates that it
754 -- is encountered for the first time during the construction of
757 if not Present
(IS_Id
) then
758 Invocation_Signatures
.Append
(IS_Rec
);
759 IS_Id
:= Invocation_Signatures
.Last
;
761 -- Map the invocation signature record to its corresponding id
763 Sig_Map
.Put
(Sig_To_Sig_Map
, IS_Rec
, IS_Id
);
767 end Invocation_Signature_Of
;
774 (IR_Id
: Invocation_Relation_Id
) return Invocation_Signature_Id
777 pragma Assert
(Present
(IR_Id
));
778 return Invocation_Relations
.Table
(IR_Id
).Invoker
;
786 (IC_Id
: Invocation_Construct_Id
) return Invocation_Construct_Kind
789 pragma Assert
(Present
(IC_Id
));
790 return Invocation_Constructs
.Table
(IC_Id
).Kind
;
797 function Kind
(IR_Id
: Invocation_Relation_Id
) return Invocation_Kind
is
799 pragma Assert
(Present
(IR_Id
));
800 return Invocation_Relations
.Table
(IR_Id
).Kind
;
807 function Line
(IS_Id
: Invocation_Signature_Id
) return Nat
is
809 pragma Assert
(Present
(IS_Id
));
810 return Invocation_Signatures
.Table
(IS_Id
).Line
;
817 function Locations
(IS_Id
: Invocation_Signature_Id
) return Name_Id
is
819 pragma Assert
(Present
(IS_Id
));
820 return Invocation_Signatures
.Table
(IS_Id
).Locations
;
827 function Name
(IS_Id
: Invocation_Signature_Id
) return Name_Id
is
829 pragma Assert
(Present
(IS_Id
));
830 return Invocation_Signatures
.Table
(IS_Id
).Name
;
837 function Present
(IC_Id
: Invocation_Construct_Id
) return Boolean is
839 return IC_Id
/= No_Invocation_Construct
;
846 function Present
(IR_Id
: Invocation_Relation_Id
) return Boolean is
848 return IR_Id
/= No_Invocation_Relation
;
855 function Present
(IS_Id
: Invocation_Signature_Id
) return Boolean is
857 return IS_Id
/= No_Invocation_Signature
;
864 function Present
(Dep
: Sdep_Id
) return Boolean is
866 return Dep
/= No_Sdep_Id
;
873 function Present
(U_Id
: Unit_Id
) return Boolean is
875 return U_Id
/= No_Unit_Id
;
882 function Present
(W_Id
: With_Id
) return Boolean is
884 return W_Id
/= No_With_Id
;
895 Ignore_Lines
: String := "X";
896 Ignore_Errors
: Boolean := False;
897 Directly_Scanned
: Boolean := False) return ALI_Id
899 P
: Text_Ptr
:= T
'First;
900 Line
: Logical_Line_Number
:= 1;
906 Ignore
: array (Character range 'A' .. 'Z') of Boolean :=
908 -- Ignore (X) is set to True if lines starting with X are to
909 -- be ignored by Scan_ALI and skipped, and False if the lines
910 -- are to be read and processed.
912 Bad_ALI_Format
: exception;
913 -- Exception raised by Fatal_Error if Err is True
915 function At_Eol
return Boolean;
916 -- Test if at end of line
918 function At_End_Of_Field
return Boolean;
919 -- Test if at end of line, or if at blank or horizontal tab
921 procedure Check_At_End_Of_Field
;
922 -- Check if we are at end of field, fatal error if not
924 procedure Checkc
(C
: Character);
925 -- Check next character is C. If so bump past it, if not fatal error
927 procedure Check_Unknown_Line
;
928 -- If Ignore_Errors mode, then checks C to make sure that it is not
929 -- an unknown ALI line type characters, and if so, skips lines
930 -- until the first character of the line is one of these characters,
931 -- at which point it does a Getc to put that character in C. The
932 -- call has no effect if C is already an appropriate character.
933 -- If not in Ignore_Errors mode, a fatal error is signalled if the
934 -- line is unknown. Note that if C is an EOL on entry, the line is
935 -- skipped (it is assumed that blank lines are never significant).
936 -- If C is EOF on entry, the call has no effect (it is assumed that
937 -- the caller will properly handle this case).
939 procedure Fatal_Error
;
940 -- Generate fatal error message for badly formatted ALI file if
941 -- Err is false, or raise Bad_ALI_Format if Err is True.
943 procedure Fatal_Error_Ignore
;
944 pragma Inline
(Fatal_Error_Ignore
);
945 -- In Ignore_Errors mode, has no effect, otherwise same as Fatal_Error
947 function Getc
return Character;
948 -- Get next character, bumping P past the character obtained
950 function Get_File_Name
951 (Lower
: Boolean := False;
952 May_Be_Quoted
: Boolean := False) return File_Name_Type
;
953 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
954 -- with length in Name_Len, as well as returning a File_Name_Type value.
955 -- If May_Be_Quoted is True and the first non blank character is '"',
956 -- then remove starting and ending quotes and undoubled internal quotes.
957 -- If lower is false, the case is unchanged, if Lower is True then the
958 -- result is forced to all lower case for systems where file names are
959 -- not case sensitive. This ensures that gnatbind works correctly
960 -- regardless of the case of the file name on all systems. The scan
961 -- is terminated by a end of line, space or horizontal tab. Any other
962 -- special characters are included in the returned name.
965 (Ignore_Special
: Boolean := False;
966 May_Be_Quoted
: Boolean := False) return Name_Id
;
967 -- Skip blanks, then scan out a name (name is left in Name_Buffer with
968 -- length in Name_Len, as well as being returned in Name_Id form).
969 -- If Lower is set to True then the Name_Buffer will be converted to
970 -- all lower case, for systems where file names are not case sensitive.
971 -- This ensures that gnatbind works correctly regardless of the case
972 -- of the file name on all systems.
974 -- The scan is terminated by the normal end of field condition
975 -- (EOL, space, horizontal tab). Furthermore, the termination condition
976 -- depends on the setting of Ignore_Special:
978 -- If Ignore_Special is False (normal case), the scan is terminated by
979 -- a typeref bracket or an equal sign except for the special case of
980 -- an operator name starting with a double quote that is terminated
981 -- by another double quote.
983 -- If May_Be_Quoted is True and the first non blank character is '"'
984 -- the name is 'unquoted'. In this case Ignore_Special is ignored and
985 -- assumed to be True.
987 -- This function handles wide characters properly.
989 function Get_Nat
return Nat
;
990 -- Skip blanks, then scan out an unsigned integer value in Nat range
991 -- raises ALI_Reading_Error if the encoutered type is not natural.
993 function Get_Stamp
return Time_Stamp_Type
;
994 -- Skip blanks, then scan out a time stamp
996 function Get_Unit_Name
return Unit_Name_Type
;
997 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
998 -- with length in Name_Len, as well as returning a Unit_Name_Type value.
999 -- The case is unchanged and terminated by a normal end of field.
1001 function Nextc
return Character;
1002 -- Return current character without modifying pointer P
1004 procedure Scan_Invocation_Graph_Line
;
1005 -- Parse a single line that encodes a piece of the invocation graph
1008 -- Skip past spaces, then skip past end of line (fatal error if not
1009 -- at end of line). Also skips past any following blank lines.
1011 procedure Skip_Line
;
1012 -- Skip rest of current line and any following blank lines
1014 procedure Skip_Space
;
1015 -- Skip past white space (blanks or horizontal tab)
1018 -- Skip past next character, does not affect value in C. This call
1019 -- is like calling Getc and ignoring the returned result.
1021 ---------------------
1022 -- At_End_Of_Field --
1023 ---------------------
1025 function At_End_Of_Field
return Boolean is
1027 return Nextc
<= ' ';
1028 end At_End_Of_Field
;
1034 function At_Eol
return Boolean is
1036 return Nextc
= EOF
or else Nextc
= CR
or else Nextc
= LF
;
1039 ---------------------------
1040 -- Check_At_End_Of_Field --
1041 ---------------------------
1043 procedure Check_At_End_Of_Field
is
1045 if not At_End_Of_Field
then
1046 if Ignore_Errors
then
1047 while Nextc
> ' ' loop
1054 end Check_At_End_Of_Field
;
1056 ------------------------
1057 -- Check_Unknown_Line --
1058 ------------------------
1060 procedure Check_Unknown_Line
is
1062 while C
not in 'A' .. 'Z'
1063 or else not Known_ALI_Lines
(C
)
1065 if C
= CR
or else C
= LF
then
1072 elsif Ignore_Errors
then
1080 end Check_Unknown_Line
;
1086 procedure Checkc
(C
: Character) is
1090 elsif Ignore_Errors
then
1101 procedure Fatal_Error
is
1106 procedure Wchar
(C
: Character);
1107 -- Write a single character, replacing horizontal tab by spaces
1109 procedure Wchar
(C
: Character) is
1114 exit when Col
mod 8 = 0;
1123 -- Start of processing for Fatal_Error
1127 raise Bad_ALI_Format
;
1131 Write_Str
("fatal error: file ");
1133 Write_Str
(" is incorrectly formatted");
1136 Write_Str
("make sure you are using consistent versions " &
1138 -- Split the following line so that it can easily be transformed for
1139 -- other back-ends where the compiler might have a different name.
1145 -- Find start of line
1148 while Ptr1
> T
'First
1149 and then T
(Ptr1
- 1) /= CR
1150 and then T
(Ptr1
- 1) /= LF
1155 Write_Int
(Int
(Line
));
1170 and then T
(Ptr2
) /= CR
1171 and then T
(Ptr2
) /= LF
1183 if T
(Ptr1
) = HT
then
1195 Exit_Program
(E_Fatal
);
1198 ------------------------
1199 -- Fatal_Error_Ignore --
1200 ------------------------
1202 procedure Fatal_Error_Ignore
is
1204 if not Ignore_Errors
then
1207 end Fatal_Error_Ignore
;
1213 function Get_File_Name
1214 (Lower
: Boolean := False;
1215 May_Be_Quoted
: Boolean := False) return File_Name_Type
1220 F
:= Get_Name
(Ignore_Special
=> True,
1221 May_Be_Quoted
=> May_Be_Quoted
);
1223 -- Convert file name to all lower case if file names are not case
1224 -- sensitive. This ensures that we handle names in the canonical
1225 -- lower case format, regardless of the actual case.
1227 if Lower
and not File_Names_Case_Sensitive
then
1228 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1231 return File_Name_Type
(F
);
1240 (Ignore_Special
: Boolean := False;
1241 May_Be_Quoted
: Boolean := False) return Name_Id
1250 if Ignore_Errors
then
1259 -- Deal with quoted characters
1261 if May_Be_Quoted
and then Char
= '"' then
1264 if Ignore_Errors
then
1287 Add_Char_To_Name_Buffer
(Char
);
1290 -- Other than case of quoted character
1295 Add_Char_To_Name_Buffer
(Getc
);
1297 exit when At_End_Of_Field
;
1299 if not Ignore_Special
then
1300 if Name_Buffer
(1) = '"' then
1301 exit when Name_Len
> 1
1302 and then Name_Buffer
(Name_Len
) = '"';
1305 -- Terminate on parens or angle brackets or equal sign
1307 exit when Nextc
= '(' or else Nextc
= ')'
1308 or else Nextc
= '{' or else Nextc
= '}'
1309 or else Nextc
= '<' or else Nextc
= '>'
1310 or else Nextc
= '=';
1312 -- Terminate on comma
1314 exit when Nextc
= ',';
1316 -- Terminate if left bracket not part of wide char
1319 exit when Nextc
= '[' and then T
(P
+ 1) /= '"';
1321 -- Terminate if right bracket not part of wide char
1324 exit when Nextc
= ']' and then T
(P
- 1) /= '"';
1337 function Get_Unit_Name
return Unit_Name_Type
is
1339 return Unit_Name_Type
(Get_Name
);
1346 function Get_Nat
return Nat
is
1352 -- Check if we are on a number. In the case of bad ALI files, this
1355 if Nextc
not in '0' .. '9' then
1361 V
:= V
* 10 + (Character'Pos (Getc
) - Character'Pos ('0'));
1363 exit when At_End_Of_Field
;
1364 exit when Nextc
< '0' or else Nextc
> '9';
1374 function Get_Stamp
return Time_Stamp_Type
is
1375 T
: Time_Stamp_Type
;
1382 if Ignore_Errors
then
1383 return Dummy_Time_Stamp
;
1389 -- Following reads old style time stamp missing first two digits
1391 if Nextc
in '7' .. '9' then
1396 -- Normal case of full year in time stamp
1402 for J
in Start
.. T
'Last loop
1413 function Getc
return Character is
1427 function Nextc
return Character is
1432 --------------------------------
1433 -- Scan_Invocation_Graph_Line --
1434 --------------------------------
1436 procedure Scan_Invocation_Graph_Line
is
1437 procedure Scan_Invocation_Construct_Line
;
1438 pragma Inline
(Scan_Invocation_Construct_Line
);
1439 -- Parse an invocation construct line and construct the corresponding
1440 -- construct. The following data structures are updated:
1442 -- * Invocation_Constructs
1445 procedure Scan_Invocation_Graph_Attributes_Line
;
1446 pragma Inline
(Scan_Invocation_Graph_Attributes_Line
);
1447 -- Parse an invocation-graph attributes line. The following data
1448 -- structures are updated:
1452 procedure Scan_Invocation_Relation_Line
;
1453 pragma Inline
(Scan_Invocation_Relation_Line
);
1454 -- Parse an invocation relation line and construct the corresponding
1455 -- relation. The following data structures are updated:
1457 -- * Invocation_Relations
1460 function Scan_Invocation_Signature
return Invocation_Signature_Id
;
1461 pragma Inline
(Scan_Invocation_Signature
);
1462 -- Parse a single invocation signature while populating the following
1465 -- * Invocation_Signatures
1468 ------------------------------------
1469 -- Scan_Invocation_Construct_Line --
1470 ------------------------------------
1472 procedure Scan_Invocation_Construct_Line
is
1473 Body_Placement
: Declaration_Placement_Kind
;
1474 Kind
: Invocation_Construct_Kind
;
1475 Signature
: Invocation_Signature_Id
;
1476 Spec_Placement
: Declaration_Placement_Kind
;
1481 Kind
:= Code_To_Invocation_Construct_Kind
(Getc
);
1485 -- construct-spec-placement
1487 Spec_Placement
:= Code_To_Declaration_Placement_Kind
(Getc
);
1491 -- construct-body-placement
1493 Body_Placement
:= Code_To_Declaration_Placement_Kind
(Getc
);
1497 -- construct-signature
1499 Signature
:= Scan_Invocation_Signature
;
1502 Add_Invocation_Construct
1503 (Body_Placement
=> Body_Placement
,
1505 Signature
=> Signature
,
1506 Spec_Placement
=> Spec_Placement
);
1507 end Scan_Invocation_Construct_Line
;
1509 -------------------------------------------
1510 -- Scan_Invocation_Graph_Attributes_Line --
1511 -------------------------------------------
1513 procedure Scan_Invocation_Graph_Attributes_Line
is
1517 Set_Invocation_Graph_Encoding
1518 (Code_To_Invocation_Graph_Encoding_Kind
(Getc
));
1520 end Scan_Invocation_Graph_Attributes_Line
;
1522 -----------------------------------
1523 -- Scan_Invocation_Relation_Line --
1524 -----------------------------------
1526 procedure Scan_Invocation_Relation_Line
is
1528 Invoker
: Invocation_Signature_Id
;
1529 Kind
: Invocation_Kind
;
1530 Target
: Invocation_Signature_Id
;
1535 Kind
:= Code_To_Invocation_Kind
(Getc
);
1539 -- (extra-name | "none")
1543 if Extra
= Name_None
then
1550 -- invoker-signature
1552 Invoker
:= Scan_Invocation_Signature
;
1558 Target
:= Scan_Invocation_Signature
;
1561 Add_Invocation_Relation
1566 end Scan_Invocation_Relation_Line
;
1568 -------------------------------
1569 -- Scan_Invocation_Signature --
1570 -------------------------------
1572 function Scan_Invocation_Signature
return Invocation_Signature_Id
is
1575 Locations
: Name_Id
;
1608 -- (locations | "none")
1610 Locations
:= Get_Name
;
1612 if Locations
= Name_None
then
1613 Locations
:= No_Name
;
1620 -- Create an invocation signature from the scanned attributes
1623 Invocation_Signature_Of
1626 Locations
=> Locations
,
1629 end Scan_Invocation_Signature
;
1633 Line
: Invocation_Graph_Line_Kind
;
1635 -- Start of processing for Scan_Invocation_Graph_Line
1638 if Ignore
('G') then
1647 Line
:= Code_To_Invocation_Graph_Line_Kind
(Getc
);
1654 when Invocation_Construct_Line
=>
1655 Scan_Invocation_Construct_Line
;
1657 when Invocation_Graph_Attributes_Line
=>
1658 Scan_Invocation_Graph_Attributes_Line
;
1660 when Invocation_Relation_Line
=>
1661 Scan_Invocation_Relation_Line
;
1663 end Scan_Invocation_Graph_Line
;
1669 procedure Skip_Eol
is
1674 if Ignore_Errors
then
1675 while not At_Eol
loop
1683 -- Loop to skip past blank lines (first time through skips this EOL)
1685 while Nextc
< ' ' and then Nextc
/= EOF
loop
1698 procedure Skip_Line
is
1700 while not At_Eol
loop
1711 procedure Skip_Space
is
1713 while Nextc
= ' ' or else Nextc
= HT
loop
1729 -- Start of processing for Scan_ALI
1732 First_Sdep_Entry
:= Sdep
.Last
+ 1;
1734 for J
in Ignore_Lines
'Range loop
1735 pragma Assert
(Ignore_Lines
(J
) /= 'U');
1736 Ignore
(Ignore_Lines
(J
)) := True;
1739 -- Setup ALI Table entry with appropriate defaults
1741 ALIs
.Increment_Last
;
1743 Set_Name_Table_Int
(F
, Int
(Id
));
1745 ALIs
.Table
(Id
) := (
1747 Compile_Errors
=> False,
1748 First_CUDA_Kernel
=> CUDA_Kernels
.Last
+ 1,
1749 First_Interrupt_State
=> Interrupt_States
.Last
+ 1,
1750 First_Sdep
=> No_Sdep_Id
,
1751 First_Specific_Dispatching
=> Specific_Dispatching
.Last
+ 1,
1752 First_Unit
=> No_Unit_Id
,
1753 GNATprove_Mode
=> False,
1754 Interrupts_Default_To_System
=> False,
1755 Invocation_Graph_Encoding
=> No_Encoding
,
1756 Last_CUDA_Kernel
=> CUDA_Kernels
.Last
,
1757 Last_Interrupt_State
=> Interrupt_States
.Last
,
1758 Last_Sdep
=> No_Sdep_Id
,
1759 Last_Specific_Dispatching
=> Specific_Dispatching
.Last
,
1760 Last_Unit
=> No_Unit_Id
,
1761 Locking_Policy
=> ' ',
1762 Main_Priority
=> -1,
1764 Main_Program
=> None
,
1765 No_Component_Reordering
=> False,
1767 Normalize_Scalars
=> False,
1768 Ofile_Full_Name
=> Full_Object_File_Name
,
1769 Partition_Elaboration_Policy
=> ' ',
1770 Queuing_Policy
=> ' ',
1771 Restrictions
=> No_Restrictions
,
1772 SAL_Interface
=> False,
1775 Task_Dispatching_Policy
=> ' ',
1776 Time_Slice_Value
=> -1,
1778 Unit_Exception_Table
=> False,
1779 Ver
=> (others => ' '),
1781 Zero_Cost_Exceptions
=> False);
1783 -- Now we acquire the input lines from the ALI file. Note that the
1784 -- convention in the following code is that as we enter each section,
1785 -- C is set to contain the first character of the following line.
1790 -- Acquire library version
1794 -- The V line missing really indicates trouble, most likely it
1795 -- means we don't have an ALI file at all, so here we give a
1796 -- fatal error even if we are in Ignore_Errors mode.
1800 elsif Ignore
('V') then
1808 for J
in 1 .. Ver_Len_Max
loop
1811 ALIs
.Table
(Id
).Ver
(J
) := C
;
1812 ALIs
.Table
(Id
).Ver_Len
:= J
;
1821 -- Acquire main program line if present
1824 if Ignore
('M') then
1834 ALIs
.Table
(Id
).Main_Program
:= Func
;
1836 ALIs
.Table
(Id
).Main_Program
:= Proc
;
1846 ALIs
.Table
(Id
).Main_Priority
:= Get_Nat
;
1854 ALIs
.Table
(Id
).Time_Slice_Value
:= Get_Nat
;
1862 ALIs
.Table
(Id
).Main_CPU
:= Get_Nat
;
1869 ALIs
.Table
(Id
).WC_Encoding
:= Getc
;
1878 -- Acquire argument lines
1880 First_Arg
:= Args
.Last
+ 1;
1884 exit A_Loop
when C
/= 'A';
1886 if Ignore
('A') then
1892 -- Scan out argument
1895 while not At_Eol
loop
1896 Add_Char_To_Name_Buffer
(Getc
);
1899 -- If -fstack-check, record that it occurred. Note that an
1900 -- additional string parameter can be specified, in the form of
1901 -- -fstack-check={no|generic|specific}. "no" means no checking,
1902 -- "generic" means force the use of old-style checking, and
1903 -- "specific" means use the best checking method.
1906 and then Name_Buffer
(1 .. 13) = "-fstack-check"
1907 and then Name_Buffer
(1 .. Name_Len
) /= "-fstack-check=no"
1909 Stack_Check_Switch_Set
:= True;
1912 -- Store the argument
1914 Args
.Increment_Last
;
1915 Args
.Table
(Args
.Last
) := new String'(Name_Buffer (1 .. Name_Len));
1923 -- Acquire 'K
' lines if present
1928 if Ignore ('K
') then
1933 CUDA_Kernels.Append ((Kernel_Name => Get_Name));
1934 ALIs.Table (Id).Last_CUDA_Kernel := CUDA_Kernels.Last;
1946 if Ignore_Errors then
1958 if Ignore ('P
') then
1966 while not At_Eol loop
1971 -- Processing for CE
1975 ALIs.Table (Id).Compile_Errors := True;
1977 -- Processing for DB
1981 Detect_Blocking := True;
1983 -- Processing for Ex
1986 Partition_Elaboration_Policy_Specified := Getc;
1987 ALIs.Table (Id).Partition_Elaboration_Policy :=
1988 Partition_Elaboration_Policy_Specified;
1990 -- Processing for FX
1995 -- Old front-end exceptions marker, ignore
2003 -- Processing for GP
2007 GNATprove_Mode_Specified := True;
2008 ALIs.Table (Id).GNATprove_Mode := True;
2010 -- Processing for ID (Interrupts Default to System)
2014 Interrupts_Default_To_System_Specified := True;
2015 ALIs.Table (Id).Interrupts_Default_To_System := True;
2017 -- Processing for Lx
2020 Locking_Policy_Specified := Getc;
2021 ALIs.Table (Id).Locking_Policy := Locking_Policy_Specified;
2023 -- Processing for flags starting with N
2028 -- Processing for NC
2031 ALIs.Table (Id).No_Component_Reordering := True;
2032 No_Component_Reordering_Specified := True;
2034 -- Processing for NO
2037 ALIs.Table (Id).No_Object := True;
2038 No_Object_Specified := True;
2040 -- Processing for NR
2043 No_Run_Time_Mode := True;
2044 Configurable_Run_Time_Mode := True;
2046 -- Processing for NS
2049 ALIs.Table (Id).Normalize_Scalars := True;
2050 Normalize_Scalars_Specified := True;
2053 -- Invalid switch starting with N
2059 -- Processing for OH/OL
2064 if C = 'L
' or else C = 'H
' then
2065 ALIs.Table (Id).SSO_Default := C;
2066 SSO_Default_Specified := True;
2072 -- Processing for Qx
2075 Queuing_Policy_Specified := Getc;
2076 ALIs.Table (Id).Queuing_Policy := Queuing_Policy_Specified;
2078 -- Processing for flags starting with S
2083 -- Processing for SL
2086 ALIs.Table (Id).SAL_Interface := True;
2088 -- Processing for SS
2091 -- Special case: a-tags/i-c* by themselves should not set
2092 -- Sec_Stack_Used, only if other code uses the secondary
2093 -- stack should we set this flag. This ensures that we do
2094 -- not bring the secondary stack unnecessarily when using
2095 -- one of these packages and not actually using the
2099 File : constant String := Get_Name_String (F);
2101 if File /= "a-tags.ali"
2102 and then File /= "i-c.ali"
2103 and then File /= "i-cstrin.ali"
2104 and then File /= "i-cpoint.ali"
2106 Opt.Sec_Stack_Used := True;
2110 -- Invalid switch starting with S
2116 -- Processing for Tx
2119 Task_Dispatching_Policy_Specified := Getc;
2120 ALIs.Table (Id).Task_Dispatching_Policy :=
2121 Task_Dispatching_Policy_Specified;
2123 -- Processing for switch starting with U
2128 -- Processing for UA
2131 Unreserve_All_Interrupts_Specified := True;
2133 -- Processing for UX
2136 ALIs.Table (Id).Unit_Exception_Table := True;
2138 -- Invalid switches starting with U
2144 -- Processing for ZX
2150 ALIs.Table (Id).Zero_Cost_Exceptions := True;
2151 Zero_Cost_Exceptions_Specified := True;
2156 -- Invalid parameter
2164 if not NS_Found then
2165 No_Normalize_Scalars_Specified := True;
2174 -- Loop to skip to first restrictions line
2177 if Ignore_Errors then
2189 -- Ignore all 'R
' lines if that is required
2191 if Ignore ('R
') then
2197 -- Here we process the restrictions lines (other than unit name cases)
2200 Scan_Restrictions : declare
2201 Save_R : constant Restrictions_Info := Cumulative_Restrictions;
2202 -- Save cumulative restrictions in case we have a fatal error
2204 Bad_R_Line : exception;
2205 -- Signal bad restrictions line (raised on unexpected character)
2212 -- Named restriction case
2218 -- Loop through RR and RV lines
2220 while C = 'R
' and then Nextc /= ' ' loop
2224 -- Acquire restriction name
2227 while not At_Eol and then Nextc /= '=' loop
2228 Name_Len := Name_Len + 1;
2229 Name_Buffer (Name_Len) := Getc;
2232 -- Now search list of restrictions to find match
2235 RN : String renames Name_Buffer (1 .. Name_Len);
2238 R := Restriction_Id'First;
2239 while R /= Not_A_Restriction_Id loop
2240 if Restriction_Id'Image (R) = RN then
2244 R := Restriction_Id'Succ (R);
2247 -- We don't recognize the restriction. This might be
2248 -- thought of as an error, and it really is, but we
2249 -- want to allow building with inconsistent versions
2250 -- of the binder and ali files (see comments at the
2251 -- start of package System.Rident), so we just ignore
2254 goto Done_With_Restriction_Line;
2261 -- Boolean restriction case
2263 when All_Boolean_Restrictions =>
2266 ALIs.Table (Id).Restrictions.Violated (R) :=
2268 Cumulative_Restrictions.Violated (R) := True;
2271 ALIs.Table (Id).Restrictions.Set (R) := True;
2272 Cumulative_Restrictions.Set (R) := True;
2278 -- Parameter restriction case
2280 when All_Parameter_Restrictions =>
2281 if At_Eol or else Nextc /= '=' then
2287 N := Natural (Get_Nat);
2294 ALIs.Table (Id).Restrictions.Set (R) := True;
2295 ALIs.Table (Id).Restrictions.Value (R) := N;
2297 if Cumulative_Restrictions.Set (R) then
2298 Cumulative_Restrictions.Value (R) :=
2300 (Cumulative_Restrictions.Value (R), N);
2302 Cumulative_Restrictions.Set (R) := True;
2303 Cumulative_Restrictions.Value (R) := N;
2306 -- Restriction violated
2309 ALIs.Table (Id).Restrictions.Violated (R) :=
2311 Cumulative_Restrictions.Violated (R) := True;
2312 ALIs.Table (Id).Restrictions.Count (R) := N;
2314 -- Checked Max_Parameter case
2316 if R in Checked_Max_Parameter_Restrictions then
2317 Cumulative_Restrictions.Count (R) :=
2319 (Cumulative_Restrictions.Count (R), N);
2321 -- Other checked parameter cases
2325 pragma Unsuppress (Overflow_Check);
2328 Cumulative_Restrictions.Count (R) :=
2329 Cumulative_Restrictions.Count (R) + N;
2332 when Constraint_Error =>
2334 -- A constraint error comes from the
2335 -- addition. We reset to the maximum
2336 -- and indicate that the real value
2339 Cumulative_Restrictions.Value (R) :=
2341 Cumulative_Restrictions.Unknown (R) :=
2350 ALIs.Table (Id).Restrictions.Unknown (R) :=
2352 Cumulative_Restrictions.Unknown (R) := True;
2355 -- Other than 'R
' or 'V
'
2365 -- Bizarre error case NOT_A_RESTRICTION
2367 when Not_A_Restriction_Id =>
2375 <<Done_With_Restriction_Line>>
2380 -- Positional restriction case
2386 -- Acquire information for boolean restrictions
2388 for R in All_Boolean_Restrictions loop
2393 ALIs.Table (Id).Restrictions.Violated (R) := True;
2394 Cumulative_Restrictions.Violated (R) := True;
2397 ALIs.Table (Id).Restrictions.Set (R) := True;
2398 Cumulative_Restrictions.Set (R) := True;
2408 -- Acquire information for parameter restrictions
2410 for RP in All_Parameter_Restrictions loop
2416 ALIs.Table (Id).Restrictions.Set (RP) := True;
2419 N : constant Integer := Integer (Get_Nat);
2421 ALIs.Table (Id).Restrictions.Value (RP) := N;
2423 if Cumulative_Restrictions.Set (RP) then
2424 Cumulative_Restrictions.Value (RP) :=
2426 (Cumulative_Restrictions.Value (RP), N);
2428 Cumulative_Restrictions.Set (RP) := True;
2429 Cumulative_Restrictions.Value (RP) := N;
2437 -- Acquire restrictions violations information
2445 ALIs.Table (Id).Restrictions.Violated (RP) := True;
2446 Cumulative_Restrictions.Violated (RP) := True;
2449 N : constant Integer := Integer (Get_Nat);
2452 ALIs.Table (Id).Restrictions.Count (RP) := N;
2454 if RP in Checked_Max_Parameter_Restrictions then
2455 Cumulative_Restrictions.Count (RP) :=
2457 (Cumulative_Restrictions.Count (RP), N);
2461 pragma Unsuppress (Overflow_Check);
2464 Cumulative_Restrictions.Count (RP) :=
2465 Cumulative_Restrictions.Count (RP) + N;
2468 when Constraint_Error =>
2470 -- A constraint error comes from the add. We
2471 -- reset to the maximum and indicate that the
2472 -- real value is now unknown.
2474 Cumulative_Restrictions.Value (RP) :=
2476 Cumulative_Restrictions.Unknown (RP) := True;
2482 ALIs.Table (Id).Restrictions.Unknown (RP) := True;
2483 Cumulative_Restrictions.Unknown (RP) := True;
2500 -- Here if error during scanning of restrictions line
2505 -- In Ignore_Errors mode, undo any changes to restrictions
2506 -- from this unit, and continue on, skipping remaining R
2507 -- lines for this unit.
2509 if Ignore_Errors then
2510 Cumulative_Restrictions := Save_R;
2511 ALIs.Table (Id).Restrictions := No_Restrictions;
2519 -- In normal mode, this is a fatal error
2524 end Scan_Restrictions;
2527 -- Acquire additional restrictions (No_Dependence) lines if present
2530 if Ignore ('R
') then
2534 No_Deps.Append ((Id, Get_Name));
2541 -- Acquire 'I
' lines if present
2546 if Ignore ('I
') then
2552 I_State : Character;
2561 Interrupt_States.Append (
2562 (Interrupt_Id => Int_Num,
2563 Interrupt_State => I_State,
2564 IS_Pragma_Line => Line_No));
2566 ALIs.Table (Id).Last_Interrupt_State := Interrupt_States.Last;
2574 -- Acquire 'S
' lines if present
2579 if Ignore ('S
') then
2595 First_Prio := Get_Nat;
2596 Last_Prio := Get_Nat;
2599 Specific_Dispatching.Append (
2600 (Dispatching_Policy => Policy,
2601 First_Priority => First_Prio,
2602 Last_Priority => Last_Prio,
2603 PSD_Pragma_Line => Line_No));
2605 ALIs.Table (Id).Last_Specific_Dispatching :=
2606 Specific_Dispatching.Last;
2615 -- Loop to acquire unit entries
2619 exit U_Loop when C /= 'U
';
2621 -- Note: as per spec, we never ignore U lines
2625 Units.Increment_Last;
2627 if ALIs.Table (Id).First_Unit = No_Unit_Id then
2628 ALIs.Table (Id).First_Unit := Units.Last;
2632 UL : Unit_Record renames Units.Table (Units.Last);
2635 UL.Uname := Get_Unit_Name;
2636 UL.Predefined := Is_Predefined_Unit;
2637 UL.Internal := Is_Internal_Unit;
2639 UL.Sfile := Get_File_Name (Lower => True);
2641 UL.Preelab := False;
2642 UL.No_Elab := False;
2643 UL.Shared_Passive := False;
2645 UL.Remote_Types := False;
2646 UL.Serious_Errors := False;
2647 UL.Has_RACW := False;
2648 UL.Init_Scalars := False;
2649 UL.Is_Generic := False;
2650 UL.Icasing := Mixed_Case;
2651 UL.Kcasing := All_Lower_Case;
2652 UL.Dynamic_Elab := False;
2653 UL.Elaborate_Body := False;
2654 UL.Set_Elab_Entity := False;
2655 UL.Version := "00000000";
2656 UL.First_With := Withs.Last + 1;
2657 UL.First_Arg := First_Arg;
2658 UL.First_Invocation_Construct := Invocation_Constructs.Last + 1;
2659 UL.Last_Invocation_Construct := No_Invocation_Construct;
2660 UL.First_Invocation_Relation := Invocation_Relations.Last + 1;
2661 UL.Last_Invocation_Relation := No_Invocation_Relation;
2662 UL.Elab_Position := 0;
2663 UL.SAL_Interface := ALIs.Table (Id).SAL_Interface;
2664 UL.Directly_Scanned := Directly_Scanned;
2665 UL.Body_Needed_For_SAL := False;
2666 UL.Elaborate_Body_Desirable := False;
2667 UL.Optimize_Alignment := 'O
';
2668 UL.Has_Finalizer := False;
2669 UL.Primary_Stack_Count := 0;
2670 UL.Sec_Stack_Count := 0;
2672 if Debug_Flag_U then
2673 Write_Str (" ----> reading unit ");
2674 Write_Int (Int (Units.Last));
2676 Write_Unit_Name (UL.Uname);
2677 Write_Str (" from file ");
2678 Write_Name (UL.Sfile);
2683 -- Check for duplicated unit in different files
2686 Info : constant Int := Get_Name_Table_Int
2687 (Units.Table (Units.Last).Uname);
2690 and then Units.Table (Units.Last).Sfile /=
2691 Units.Table (Unit_Id (Info)).Sfile
2693 -- If Err is set then ignore duplicate unit name. This is the
2694 -- case of a call from gnatmake, where the situation can arise
2695 -- from substitution of source files. In such situations, the
2696 -- processing in gnatmake will always result in any required
2697 -- recompilations in any case, and if we consider this to be
2698 -- an error we get strange cases (for example when a generic
2699 -- instantiation is replaced by a normal package) where we
2700 -- read the old ali file, decide to recompile, and then decide
2701 -- that the old and new ali files are incompatible.
2706 -- If Err is not set, then this is a fatal error. This is
2707 -- the case of being called from the binder, where we must
2708 -- definitely diagnose this as an error.
2712 Write_Str ("error: duplicate unit name: ");
2715 Write_Str ("error: unit """);
2716 Write_Unit_Name (Units.Table (Units.Last).Uname);
2717 Write_Str (""" found in file """);
2718 Write_Name_Decoded (Units.Table (Units.Last).Sfile);
2722 Write_Str ("error
: unit
""");
2723 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
2724 Write_Str (""" found
in file
""");
2725 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
2729 Exit_Program (E_Fatal);
2735 (Units.Table (Units.Last).Uname, Int (Units.Last));
2737 -- Scan out possible version and other parameters
2746 if C in '0' .. '9' or else C in 'a
' .. 'f
' then
2747 Units.Table (Units.Last).Version (1) := C;
2749 for J in 2 .. 8 loop
2751 Units.Table (Units.Last).Version (J) := C;
2760 Check_At_End_Of_Field;
2761 Units.Table (Units.Last).Elaborate_Body_Desirable := True;
2764 Check_At_End_Of_Field;
2765 Units.Table (Units.Last).Body_Needed_For_SAL := True;
2771 -- DE parameter (Dynamic elaboration checks)
2777 Check_At_End_Of_Field;
2778 Units.Table (Units.Last).Dynamic_Elab := True;
2779 Dynamic_Elaboration_Checks_Specified := True;
2790 Units.Table (Units.Last).Elaborate_Body := True;
2792 Units.Table (Units.Last).Set_Elab_Entity := True;
2797 Check_At_End_Of_Field;
2799 -- GE parameter (generic)
2805 Check_At_End_Of_Field;
2806 Units.Table (Units.Last).Is_Generic := True;
2811 -- IL/IS/IU parameters
2817 Units.Table (Units.Last).Icasing := All_Lower_Case;
2819 Units.Table (Units.Last).Init_Scalars := True;
2820 Initialize_Scalars_Used := True;
2822 Units.Table (Units.Last).Icasing := All_Upper_Case;
2827 Check_At_End_Of_Field;
2835 Units.Table (Units.Last).Kcasing := Mixed_Case;
2837 Units.Table (Units.Last).Kcasing := All_Upper_Case;
2842 Check_At_End_Of_Field;
2850 Units.Table (Units.Last).No_Elab := True;
2851 Check_At_End_Of_Field;
2856 -- PF/PR/PU/PK parameters
2862 Units.Table (Units.Last).Has_Finalizer := True;
2864 Units.Table (Units.Last).Preelab := True;
2866 Units.Table (Units.Last).Pure := True;
2868 Units.Table (Units.Last).Unit_Kind := 'p
';
2873 Check_At_End_Of_Field;
2875 -- OL/OO/OS/OT parameters
2880 if C = 'L
' or else C = 'O
' or else C = 'S
' or else C = 'T
' then
2881 Units.Table (Units.Last).Optimize_Alignment := C;
2886 Check_At_End_Of_Field;
2894 Units.Table (Units.Last).RCI := True;
2896 Units.Table (Units.Last).Remote_Types := True;
2898 Units.Table (Units.Last).Has_RACW := True;
2903 Check_At_End_Of_Field;
2905 -- SE/SP/SU parameters
2911 Units.Table (Units.Last).Serious_Errors := True;
2913 Units.Table (Units.Last).Shared_Passive := True;
2915 Units.Table (Units.Last).Unit_Kind := 's
';
2920 Check_At_End_Of_Field;
2932 -- Scan out With lines for this unit
2936 exit With_Loop when C /= 'W
' and then C /= 'Y
' and then C /= 'Z
';
2938 if Ignore ('W
') then
2944 Withs.Increment_Last;
2945 Withs.Table (Withs.Last).Uname := Get_Unit_Name;
2946 Withs.Table (Withs.Last).Elaborate := False;
2947 Withs.Table (Withs.Last).Elaborate_All := False;
2948 Withs.Table (Withs.Last).Elab_Desirable := False;
2949 Withs.Table (Withs.Last).Elab_All_Desirable := False;
2950 Withs.Table (Withs.Last).SAL_Interface := False;
2951 Withs.Table (Withs.Last).Limited_With := (C = 'Y
');
2952 Withs.Table (Withs.Last).Implicit_With := (C = 'Z
');
2954 -- Generic case with no object file available
2957 Withs.Table (Withs.Last).Sfile := No_File;
2958 Withs.Table (Withs.Last).Afile := No_File;
2963 Withs.Table (Withs.Last).Sfile := Get_File_Name
2965 Withs.Table (Withs.Last).Afile := Get_File_Name
2968 -- Scan out possible E, EA, ED, and AD parameters
2970 while not At_Eol loop
2976 Check_At_End_Of_Field;
2978 -- Store AD indication unless ignore required
2980 Withs.Table (Withs.Last).Elab_All_Desirable := True;
2982 elsif Nextc = 'E
' then
2985 if At_End_Of_Field then
2986 Withs.Table (Withs.Last).Elaborate := True;
2988 elsif Nextc = 'A
' then
2990 Check_At_End_Of_Field;
2991 Withs.Table (Withs.Last).Elaborate_All := True;
2995 Check_At_End_Of_Field;
2997 -- Store ED indication
2999 Withs.Table (Withs.Last).Elab_Desirable := True;
3014 Units.Table (Units.Last).Last_With := Withs.Last;
3015 Units.Table (Units.Last).Last_Arg := Args.Last;
3017 -- Scan out task stack information for the unit if present
3022 if Ignore ('T
') then
3029 Units.Table (Units.Last).Primary_Stack_Count := Get_Nat;
3031 Units.Table (Units.Last).Sec_Stack_Count := Get_Nat;
3039 -- If there are linker options lines present, scan them
3043 Linker_Options_Loop : loop
3045 exit Linker_Options_Loop when C /= 'L
';
3047 if Ignore ('L
') then
3058 if C < Character'Val (16#20#)
3059 or else C > Character'Val (16#7E#)
3064 C := Character'Val (0);
3071 for J in 1 .. 2 loop
3074 if C in '0' .. '9' then
3077 Character'Pos ('0');
3079 elsif C in 'A' .. 'F' then
3082 Character'Pos ('A') +
3091 Add_Char_To_Name_Buffer (Character'Val (V));
3096 exit when Nextc /= '"';
3100 Add_Char_To_Name_Buffer (C);
3104 Add_Char_To_Name_Buffer (NUL);
3109 end loop Linker_Options_Loop;
3111 -- Store the linker options entry if one was found
3113 if Name_Len /= 0 then
3114 Linker_Options.Increment_Last;
3116 Linker_Options.Table (Linker_Options.Last).Name :=
3119 Linker_Options.Table (Linker_Options.Last).Unit :=
3122 Linker_Options.Table (Linker_Options.Last).Internal_File :=
3123 Is_Internal_File_Name (F);
3126 -- If there are notes present, scan them
3130 exit Notes_Loop when C /= 'N';
3132 if Ignore ('N') then
3138 Notes.Increment_Last;
3139 Notes.Table (Notes.Last).Pragma_Type := Getc;
3140 Notes.Table (Notes.Last).Pragma_Line := Get_Nat;
3142 Notes.Table (Notes.Last).Pragma_Col := Get_Nat;
3144 if not At_Eol and then Nextc = ':' then
3146 Notes.Table (Notes.Last).Pragma_Source_File :=
3147 Get_File_Name (Lower => True);
3149 Notes.Table (Notes.Last).Pragma_Source_File :=
3150 Units.Table (Units.Last).Sfile;
3154 Notes.Table (Notes.Last).Pragma_Args := No_Name;
3157 -- Note: can't use Get_Name here as the remainder of the
3158 -- line is unstructured text whose syntax depends on the
3159 -- particular pragma used.
3164 while not At_Eol loop
3165 Add_Char_To_Name_Buffer (Getc);
3173 end loop Notes_Loop;
3176 -- End loop through units for one ALI file
3178 ALIs.Table (Id).Last_Unit := Units.Last;
3179 ALIs.Table (Id).Sfile := Units.Table (ALIs.Table (Id).First_Unit).Sfile;
3181 -- Set types of the units (there can be at most 2 of them)
3183 if ALIs.Table (Id).First_Unit /= ALIs.Table (Id).Last_Unit then
3184 Units.Table (ALIs.Table (Id).First_Unit).Utype := Is_Body;
3185 Units.Table (ALIs.Table (Id).Last_Unit).Utype := Is_Spec;
3188 -- Deal with body only and spec only cases, note that the reason we
3189 -- do our own checking of the name (rather than using Is_Body_Name)
3190 -- is that Uname drags in far too much compiler junk.
3192 Get_Name_String (Units.Table (Units.Last).Uname);
3194 if Name_Buffer (Name_Len) = 'b' then
3195 Units.Table (Units.Last).Utype := Is_Body_Only;
3197 Units.Table (Units.Last).Utype := Is_Spec_Only;
3201 -- Scan out external version references and put in hash table
3205 exit E_Loop when C /= 'E';
3207 if Ignore ('E') then
3223 exit when At_End_Of_Field;
3224 Add_Char_To_Name_Buffer (C);
3227 Version_Ref.Set (new String'(Name_Buffer (1 .. Name_Len)), True);
3234 -- Scan out source dependency lines for this ALI file
3236 ALIs.Table (Id).First_Sdep := Sdep.Last + 1;
3240 exit D_Loop when C /= 'D';
3242 if Ignore ('D') then
3248 Sdep.Increment_Last;
3250 -- The file/path name may be quoted
3252 Sdep.Table (Sdep.Last).Sfile :=
3253 Get_File_Name (Lower => True, May_Be_Quoted => True);
3255 Sdep.Table (Sdep.Last).Stamp := Get_Stamp;
3256 Sdep.Table (Sdep.Last).Dummy_Entry :=
3257 (Sdep.Table (Sdep.Last).Stamp = Dummy_Time_Stamp);
3259 -- Acquire checksum value
3272 exit when At_Eol or else Ctr = 8;
3274 if Nextc in '0' .. '9' then
3276 Character'Pos (Nextc) - Character'Pos ('0');
3278 elsif Nextc in 'a' .. 'f' then
3280 Character'Pos (Nextc) - Character'Pos ('a') + 10;
3290 if Ctr = 8 and then At_End_Of_Field then
3291 Sdep.Table (Sdep.Last).Checksum := Chk;
3297 -- Acquire (sub)unit and reference file name entries
3299 Sdep.Table (Sdep.Last).Subunit_Name := No_Unit_Name;
3300 Sdep.Table (Sdep.Last).Unit_Name := No_Unit_Name;
3301 Sdep.Table (Sdep.Last).Rfile :=
3302 Sdep.Table (Sdep.Last).Sfile;
3303 Sdep.Table (Sdep.Last).Start_Line := 1;
3308 -- Here for (sub)unit name
3310 if Nextc not in '0' .. '9' then
3312 while not At_End_Of_Field loop
3313 Add_Char_To_Name_Buffer (Getc);
3316 -- Set the (sub)unit name.
3319 or else Name_Buffer (Name_Len - 1) /= '%'
3321 Sdep.Table (Sdep.Last).Subunit_Name := Name_Find;
3323 Sdep.Table (Sdep.Last).Unit_Name := Name_Find;
3329 -- Here for reference file name entry
3331 if Nextc in '0' .. '9' then
3332 Sdep.Table (Sdep.Last).Start_Line := Get_Nat;
3337 while not At_End_Of_Field loop
3338 Add_Char_To_Name_Buffer (Getc);
3341 Sdep.Table (Sdep.Last).Rfile := Name_Enter;
3351 ALIs.Table (Id).Last_Sdep := Sdep.Last;
3353 -- Loop through invocation-graph lines
3357 exit G_Loop when C /= 'G';
3359 Scan_Invocation_Graph_Line;
3364 -- We must at this stage be at an Xref line or the end of file
3376 -- This ALI parser does not care about Xref lines.
3381 when Bad_ALI_Format =>
3389 function IS_Scope (IS_Id : Invocation_Signature_Id) return Name_Id is
3391 pragma Assert (Present (IS_Id));
3392 return Invocation_Signatures.Table (IS_Id).Scope;
3399 function SEq (F1, F2 : String_Ptr) return Boolean is
3401 return F1.all = F2.all;
3404 -----------------------------------
3405 -- Set_Invocation_Graph_Encoding --
3406 -----------------------------------
3408 procedure Set_Invocation_Graph_Encoding
3409 (Kind : Invocation_Graph_Encoding_Kind;
3410 Update_Units : Boolean := True)
3413 Compile_Time_Invocation_Graph_Encoding := Kind;
3415 -- Update the invocation-graph encoding of the current unit only when
3416 -- requested by the caller.
3418 if Update_Units then
3420 Curr_Unit : Unit_Record renames Units.Table (Units.Last);
3421 Curr_ALI : ALIs_Record renames ALIs.Table (Curr_Unit.My_ALI);
3424 Curr_ALI.Invocation_Graph_Encoding := Kind;
3427 end Set_Invocation_Graph_Encoding;
3433 function SHash (S : String_Ptr) return Vindex is
3438 for J in S.all'Range loop
3439 H := H * 2 + Character'Pos (S (J));
3442 return Vindex (Vindex'First + Vindex (H mod Vindex'Range_Length));
3450 (IC_Id : Invocation_Construct_Id) return Invocation_Signature_Id
3453 pragma Assert (Present (IC_Id));
3454 return Invocation_Constructs.Table (IC_Id).Signature;
3457 --------------------
3458 -- Spec_Placement --
3459 --------------------
3461 function Spec_Placement
3462 (IC_Id : Invocation_Construct_Id) return Declaration_Placement_Kind
3465 pragma Assert (Present (IC_Id));
3466 return Invocation_Constructs.Table (IC_Id).Spec_Placement;
3474 (IR_Id : Invocation_Relation_Id) return Invocation_Signature_Id
3477 pragma Assert (Present (IR_Id));
3478 return Invocation_Relations.Table (IR_Id).Target;