1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Normalize_Scalars_Specified
:= False;
669 Partition_Elaboration_Policy_Specified
:= ' ';
670 Queuing_Policy_Specified
:= ' ';
671 SSO_Default_Specified
:= False;
672 Task_Dispatching_Policy_Specified
:= ' ';
673 Unreserve_All_Interrupts_Specified
:= False;
674 Zero_Cost_Exceptions_Specified
:= False;
677 ---------------------------------------
678 -- Invocation_Construct_Kind_To_Code --
679 ---------------------------------------
681 function Invocation_Construct_Kind_To_Code
682 (Kind
: Invocation_Construct_Kind
) return Character
685 return Invocation_Construct_Codes
(Kind
);
686 end Invocation_Construct_Kind_To_Code
;
688 -------------------------------
689 -- Invocation_Graph_Encoding --
690 -------------------------------
692 function Invocation_Graph_Encoding
return Invocation_Graph_Encoding_Kind
is
694 return Compile_Time_Invocation_Graph_Encoding
;
695 end Invocation_Graph_Encoding
;
697 --------------------------------------------
698 -- Invocation_Graph_Encoding_Kind_To_Code --
699 --------------------------------------------
701 function Invocation_Graph_Encoding_Kind_To_Code
702 (Kind
: Invocation_Graph_Encoding_Kind
) return Character
705 return Invocation_Graph_Encoding_Codes
(Kind
);
706 end Invocation_Graph_Encoding_Kind_To_Code
;
708 ----------------------------------------
709 -- Invocation_Graph_Line_Kind_To_Code --
710 ----------------------------------------
712 function Invocation_Graph_Line_Kind_To_Code
713 (Kind
: Invocation_Graph_Line_Kind
) return Character
716 return Invocation_Graph_Line_Codes
(Kind
);
717 end Invocation_Graph_Line_Kind_To_Code
;
719 -----------------------------
720 -- Invocation_Kind_To_Code --
721 -----------------------------
723 function Invocation_Kind_To_Code
724 (Kind
: Invocation_Kind
) return Character
727 return Invocation_Codes
(Kind
);
728 end Invocation_Kind_To_Code
;
730 -----------------------------
731 -- Invocation_Signature_Of --
732 -----------------------------
734 function Invocation_Signature_Of
739 Scope
: Name_Id
) return Invocation_Signature_Id
741 IS_Rec
: constant Invocation_Signature_Record
:=
744 Locations
=> Locations
,
747 IS_Id
: Invocation_Signature_Id
;
750 IS_Id
:= Sig_Map
.Get
(Sig_To_Sig_Map
, IS_Rec
);
752 -- The invocation signature lacks an id. This indicates that it
753 -- is encountered for the first time during the construction of
756 if not Present
(IS_Id
) then
757 Invocation_Signatures
.Append
(IS_Rec
);
758 IS_Id
:= Invocation_Signatures
.Last
;
760 -- Map the invocation signature record to its corresponding id
762 Sig_Map
.Put
(Sig_To_Sig_Map
, IS_Rec
, IS_Id
);
766 end Invocation_Signature_Of
;
773 (IR_Id
: Invocation_Relation_Id
) return Invocation_Signature_Id
776 pragma Assert
(Present
(IR_Id
));
777 return Invocation_Relations
.Table
(IR_Id
).Invoker
;
785 (IC_Id
: Invocation_Construct_Id
) return Invocation_Construct_Kind
788 pragma Assert
(Present
(IC_Id
));
789 return Invocation_Constructs
.Table
(IC_Id
).Kind
;
796 function Kind
(IR_Id
: Invocation_Relation_Id
) return Invocation_Kind
is
798 pragma Assert
(Present
(IR_Id
));
799 return Invocation_Relations
.Table
(IR_Id
).Kind
;
806 function Line
(IS_Id
: Invocation_Signature_Id
) return Nat
is
808 pragma Assert
(Present
(IS_Id
));
809 return Invocation_Signatures
.Table
(IS_Id
).Line
;
816 function Locations
(IS_Id
: Invocation_Signature_Id
) return Name_Id
is
818 pragma Assert
(Present
(IS_Id
));
819 return Invocation_Signatures
.Table
(IS_Id
).Locations
;
826 function Name
(IS_Id
: Invocation_Signature_Id
) return Name_Id
is
828 pragma Assert
(Present
(IS_Id
));
829 return Invocation_Signatures
.Table
(IS_Id
).Name
;
836 function Present
(IC_Id
: Invocation_Construct_Id
) return Boolean is
838 return IC_Id
/= No_Invocation_Construct
;
845 function Present
(IR_Id
: Invocation_Relation_Id
) return Boolean is
847 return IR_Id
/= No_Invocation_Relation
;
854 function Present
(IS_Id
: Invocation_Signature_Id
) return Boolean is
856 return IS_Id
/= No_Invocation_Signature
;
863 function Present
(Dep
: Sdep_Id
) return Boolean is
865 return Dep
/= No_Sdep_Id
;
872 function Present
(U_Id
: Unit_Id
) return Boolean is
874 return U_Id
/= No_Unit_Id
;
881 function Present
(W_Id
: With_Id
) return Boolean is
883 return W_Id
/= No_With_Id
;
894 Ignore_Lines
: String := "X";
895 Ignore_Errors
: Boolean := False;
896 Directly_Scanned
: Boolean := False) return ALI_Id
898 P
: Text_Ptr
:= T
'First;
899 Line
: Logical_Line_Number
:= 1;
905 Ignore
: array (Character range 'A' .. 'Z') of Boolean :=
907 -- Ignore (X) is set to True if lines starting with X are to
908 -- be ignored by Scan_ALI and skipped, and False if the lines
909 -- are to be read and processed.
911 Bad_ALI_Format
: exception;
912 -- Exception raised by Fatal_Error if Err is True
914 function At_Eol
return Boolean;
915 -- Test if at end of line
917 function At_End_Of_Field
return Boolean;
918 -- Test if at end of line, or if at blank or horizontal tab
920 procedure Check_At_End_Of_Field
;
921 -- Check if we are at end of field, fatal error if not
923 procedure Checkc
(C
: Character);
924 -- Check next character is C. If so bump past it, if not fatal error
926 procedure Check_Unknown_Line
;
927 -- If Ignore_Errors mode, then checks C to make sure that it is not
928 -- an unknown ALI line type characters, and if so, skips lines
929 -- until the first character of the line is one of these characters,
930 -- at which point it does a Getc to put that character in C. The
931 -- call has no effect if C is already an appropriate character.
932 -- If not in Ignore_Errors mode, a fatal error is signalled if the
933 -- line is unknown. Note that if C is an EOL on entry, the line is
934 -- skipped (it is assumed that blank lines are never significant).
935 -- If C is EOF on entry, the call has no effect (it is assumed that
936 -- the caller will properly handle this case).
938 procedure Fatal_Error
;
939 -- Generate fatal error message for badly formatted ALI file if
940 -- Err is false, or raise Bad_ALI_Format if Err is True.
942 procedure Fatal_Error_Ignore
;
943 pragma Inline
(Fatal_Error_Ignore
);
944 -- In Ignore_Errors mode, has no effect, otherwise same as Fatal_Error
946 function Getc
return Character;
947 -- Get next character, bumping P past the character obtained
949 function Get_File_Name
950 (Lower
: Boolean := False;
951 May_Be_Quoted
: Boolean := False) return File_Name_Type
;
952 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
953 -- with length in Name_Len, as well as returning a File_Name_Type value.
954 -- If May_Be_Quoted is True and the first non blank character is '"',
955 -- then remove starting and ending quotes and undoubled internal quotes.
956 -- If lower is false, the case is unchanged, if Lower is True then the
957 -- result is forced to all lower case for systems where file names are
958 -- not case sensitive. This ensures that gnatbind works correctly
959 -- regardless of the case of the file name on all systems. The scan
960 -- is terminated by a end of line, space or horizontal tab. Any other
961 -- special characters are included in the returned name.
964 (Ignore_Special
: Boolean := False;
965 May_Be_Quoted
: Boolean := False) return Name_Id
;
966 -- Skip blanks, then scan out a name (name is left in Name_Buffer with
967 -- length in Name_Len, as well as being returned in Name_Id form).
968 -- If Lower is set to True then the Name_Buffer will be converted to
969 -- all lower case, for systems where file names are not case sensitive.
970 -- This ensures that gnatbind works correctly regardless of the case
971 -- of the file name on all systems.
973 -- The scan is terminated by the normal end of field condition
974 -- (EOL, space, horizontal tab). Furthermore, the termination condition
975 -- depends on the setting of Ignore_Special:
977 -- If Ignore_Special is False (normal case), the scan is terminated by
978 -- a typeref bracket or an equal sign except for the special case of
979 -- an operator name starting with a double quote that is terminated
980 -- by another double quote.
982 -- If May_Be_Quoted is True and the first non blank character is '"'
983 -- the name is 'unquoted'. In this case Ignore_Special is ignored and
984 -- assumed to be True.
986 -- This function handles wide characters properly.
988 function Get_Nat
return Nat
;
989 -- Skip blanks, then scan out an unsigned integer value in Nat range
990 -- raises ALI_Reading_Error if the encoutered type is not natural.
992 function Get_Stamp
return Time_Stamp_Type
;
993 -- Skip blanks, then scan out a time stamp
995 function Get_Unit_Name
return Unit_Name_Type
;
996 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
997 -- with length in Name_Len, as well as returning a Unit_Name_Type value.
998 -- The case is unchanged and terminated by a normal end of field.
1000 function Nextc
return Character;
1001 -- Return current character without modifying pointer P
1003 procedure Scan_Invocation_Graph_Line
;
1004 -- Parse a single line that encodes a piece of the invocation graph
1007 -- Skip past spaces, then skip past end of line (fatal error if not
1008 -- at end of line). Also skips past any following blank lines.
1010 procedure Skip_Line
;
1011 -- Skip rest of current line and any following blank lines
1013 procedure Skip_Space
;
1014 -- Skip past white space (blanks or horizontal tab)
1017 -- Skip past next character, does not affect value in C. This call
1018 -- is like calling Getc and ignoring the returned result.
1020 ---------------------
1021 -- At_End_Of_Field --
1022 ---------------------
1024 function At_End_Of_Field
return Boolean is
1026 return Nextc
<= ' ';
1027 end At_End_Of_Field
;
1033 function At_Eol
return Boolean is
1035 return Nextc
= EOF
or else Nextc
= CR
or else Nextc
= LF
;
1038 ---------------------------
1039 -- Check_At_End_Of_Field --
1040 ---------------------------
1042 procedure Check_At_End_Of_Field
is
1044 if not At_End_Of_Field
then
1045 if Ignore_Errors
then
1046 while Nextc
> ' ' loop
1053 end Check_At_End_Of_Field
;
1055 ------------------------
1056 -- Check_Unknown_Line --
1057 ------------------------
1059 procedure Check_Unknown_Line
is
1061 while C
not in 'A' .. 'Z'
1062 or else not Known_ALI_Lines
(C
)
1064 if C
= CR
or else C
= LF
then
1071 elsif Ignore_Errors
then
1079 end Check_Unknown_Line
;
1085 procedure Checkc
(C
: Character) is
1089 elsif Ignore_Errors
then
1100 procedure Fatal_Error
is
1105 procedure Wchar
(C
: Character);
1106 -- Write a single character, replacing horizontal tab by spaces
1108 procedure Wchar
(C
: Character) is
1113 exit when Col
mod 8 = 0;
1122 -- Start of processing for Fatal_Error
1126 raise Bad_ALI_Format
;
1130 Write_Str
("fatal error: file ");
1132 Write_Str
(" is incorrectly formatted");
1135 Write_Str
("make sure you are using consistent versions " &
1137 -- Split the following line so that it can easily be transformed for
1138 -- other back-ends where the compiler might have a different name.
1144 -- Find start of line
1147 while Ptr1
> T
'First
1148 and then T
(Ptr1
- 1) /= CR
1149 and then T
(Ptr1
- 1) /= LF
1154 Write_Int
(Int
(Line
));
1169 and then T
(Ptr2
) /= CR
1170 and then T
(Ptr2
) /= LF
1182 if T
(Ptr1
) = HT
then
1194 Exit_Program
(E_Fatal
);
1197 ------------------------
1198 -- Fatal_Error_Ignore --
1199 ------------------------
1201 procedure Fatal_Error_Ignore
is
1203 if not Ignore_Errors
then
1206 end Fatal_Error_Ignore
;
1212 function Get_File_Name
1213 (Lower
: Boolean := False;
1214 May_Be_Quoted
: Boolean := False) return File_Name_Type
1219 F
:= Get_Name
(Ignore_Special
=> True,
1220 May_Be_Quoted
=> May_Be_Quoted
);
1222 -- Convert file name to all lower case if file names are not case
1223 -- sensitive. This ensures that we handle names in the canonical
1224 -- lower case format, regardless of the actual case.
1226 if Lower
and not File_Names_Case_Sensitive
then
1227 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1230 return File_Name_Type
(F
);
1239 (Ignore_Special
: Boolean := False;
1240 May_Be_Quoted
: Boolean := False) return Name_Id
1249 if Ignore_Errors
then
1258 -- Deal with quoted characters
1260 if May_Be_Quoted
and then Char
= '"' then
1263 if Ignore_Errors
then
1286 Add_Char_To_Name_Buffer
(Char
);
1289 -- Other than case of quoted character
1294 Add_Char_To_Name_Buffer
(Getc
);
1296 exit when At_End_Of_Field
;
1298 if not Ignore_Special
then
1299 if Name_Buffer
(1) = '"' then
1300 exit when Name_Len
> 1
1301 and then Name_Buffer
(Name_Len
) = '"';
1304 -- Terminate on parens or angle brackets or equal sign
1306 exit when Nextc
= '(' or else Nextc
= ')'
1307 or else Nextc
= '{' or else Nextc
= '}'
1308 or else Nextc
= '<' or else Nextc
= '>'
1309 or else Nextc
= '=';
1311 -- Terminate on comma
1313 exit when Nextc
= ',';
1315 -- Terminate if left bracket not part of wide char
1318 exit when Nextc
= '[' and then T
(P
+ 1) /= '"';
1320 -- Terminate if right bracket not part of wide char
1323 exit when Nextc
= ']' and then T
(P
- 1) /= '"';
1336 function Get_Unit_Name
return Unit_Name_Type
is
1338 return Unit_Name_Type
(Get_Name
);
1345 function Get_Nat
return Nat
is
1351 -- Check if we are on a number. In the case of bad ALI files, this
1354 if not (Nextc
in '0' .. '9') then
1360 V
:= V
* 10 + (Character'Pos (Getc
) - Character'Pos ('0'));
1362 exit when At_End_Of_Field
;
1363 exit when Nextc
< '0' or else Nextc
> '9';
1373 function Get_Stamp
return Time_Stamp_Type
is
1374 T
: Time_Stamp_Type
;
1381 if Ignore_Errors
then
1382 return Dummy_Time_Stamp
;
1388 -- Following reads old style time stamp missing first two digits
1390 if Nextc
in '7' .. '9' then
1395 -- Normal case of full year in time stamp
1401 for J
in Start
.. T
'Last loop
1412 function Getc
return Character is
1426 function Nextc
return Character is
1431 --------------------------------
1432 -- Scan_Invocation_Graph_Line --
1433 --------------------------------
1435 procedure Scan_Invocation_Graph_Line
is
1436 procedure Scan_Invocation_Construct_Line
;
1437 pragma Inline
(Scan_Invocation_Construct_Line
);
1438 -- Parse an invocation construct line and construct the corresponding
1439 -- construct. The following data structures are updated:
1441 -- * Invocation_Constructs
1444 procedure Scan_Invocation_Graph_Attributes_Line
;
1445 pragma Inline
(Scan_Invocation_Graph_Attributes_Line
);
1446 -- Parse an invocation-graph attributes line. The following data
1447 -- structures are updated:
1451 procedure Scan_Invocation_Relation_Line
;
1452 pragma Inline
(Scan_Invocation_Relation_Line
);
1453 -- Parse an invocation relation line and construct the corresponding
1454 -- relation. The following data structures are updated:
1456 -- * Invocation_Relations
1459 function Scan_Invocation_Signature
return Invocation_Signature_Id
;
1460 pragma Inline
(Scan_Invocation_Signature
);
1461 -- Parse a single invocation signature while populating the following
1464 -- * Invocation_Signatures
1467 ------------------------------------
1468 -- Scan_Invocation_Construct_Line --
1469 ------------------------------------
1471 procedure Scan_Invocation_Construct_Line
is
1472 Body_Placement
: Declaration_Placement_Kind
;
1473 Kind
: Invocation_Construct_Kind
;
1474 Signature
: Invocation_Signature_Id
;
1475 Spec_Placement
: Declaration_Placement_Kind
;
1480 Kind
:= Code_To_Invocation_Construct_Kind
(Getc
);
1484 -- construct-spec-placement
1486 Spec_Placement
:= Code_To_Declaration_Placement_Kind
(Getc
);
1490 -- construct-body-placement
1492 Body_Placement
:= Code_To_Declaration_Placement_Kind
(Getc
);
1496 -- construct-signature
1498 Signature
:= Scan_Invocation_Signature
;
1501 Add_Invocation_Construct
1502 (Body_Placement
=> Body_Placement
,
1504 Signature
=> Signature
,
1505 Spec_Placement
=> Spec_Placement
);
1506 end Scan_Invocation_Construct_Line
;
1508 -------------------------------------------
1509 -- Scan_Invocation_Graph_Attributes_Line --
1510 -------------------------------------------
1512 procedure Scan_Invocation_Graph_Attributes_Line
is
1516 Set_Invocation_Graph_Encoding
1517 (Code_To_Invocation_Graph_Encoding_Kind
(Getc
));
1519 end Scan_Invocation_Graph_Attributes_Line
;
1521 -----------------------------------
1522 -- Scan_Invocation_Relation_Line --
1523 -----------------------------------
1525 procedure Scan_Invocation_Relation_Line
is
1527 Invoker
: Invocation_Signature_Id
;
1528 Kind
: Invocation_Kind
;
1529 Target
: Invocation_Signature_Id
;
1534 Kind
:= Code_To_Invocation_Kind
(Getc
);
1538 -- (extra-name | "none")
1542 if Extra
= Name_None
then
1549 -- invoker-signature
1551 Invoker
:= Scan_Invocation_Signature
;
1557 Target
:= Scan_Invocation_Signature
;
1560 Add_Invocation_Relation
1565 end Scan_Invocation_Relation_Line
;
1567 -------------------------------
1568 -- Scan_Invocation_Signature --
1569 -------------------------------
1571 function Scan_Invocation_Signature
return Invocation_Signature_Id
is
1574 Locations
: Name_Id
;
1607 -- (locations | "none")
1609 Locations
:= Get_Name
;
1611 if Locations
= Name_None
then
1612 Locations
:= No_Name
;
1619 -- Create an invocation signature from the scanned attributes
1622 Invocation_Signature_Of
1625 Locations
=> Locations
,
1628 end Scan_Invocation_Signature
;
1632 Line
: Invocation_Graph_Line_Kind
;
1634 -- Start of processing for Scan_Invocation_Graph_Line
1637 if Ignore
('G') then
1646 Line
:= Code_To_Invocation_Graph_Line_Kind
(Getc
);
1653 when Invocation_Construct_Line
=>
1654 Scan_Invocation_Construct_Line
;
1656 when Invocation_Graph_Attributes_Line
=>
1657 Scan_Invocation_Graph_Attributes_Line
;
1659 when Invocation_Relation_Line
=>
1660 Scan_Invocation_Relation_Line
;
1662 end Scan_Invocation_Graph_Line
;
1668 procedure Skip_Eol
is
1673 if Ignore_Errors
then
1674 while not At_Eol
loop
1682 -- Loop to skip past blank lines (first time through skips this EOL)
1684 while Nextc
< ' ' and then Nextc
/= EOF
loop
1697 procedure Skip_Line
is
1699 while not At_Eol
loop
1710 procedure Skip_Space
is
1712 while Nextc
= ' ' or else Nextc
= HT
loop
1728 -- Start of processing for Scan_ALI
1731 First_Sdep_Entry
:= Sdep
.Last
+ 1;
1733 for J
in Ignore_Lines
'Range loop
1734 pragma Assert
(Ignore_Lines
(J
) /= 'U');
1735 Ignore
(Ignore_Lines
(J
)) := True;
1738 -- Setup ALI Table entry with appropriate defaults
1740 ALIs
.Increment_Last
;
1742 Set_Name_Table_Int
(F
, Int
(Id
));
1744 ALIs
.Table
(Id
) := (
1746 Compile_Errors
=> False,
1747 First_CUDA_Kernel
=> CUDA_Kernels
.Last
+ 1,
1748 First_Interrupt_State
=> Interrupt_States
.Last
+ 1,
1749 First_Sdep
=> No_Sdep_Id
,
1750 First_Specific_Dispatching
=> Specific_Dispatching
.Last
+ 1,
1751 First_Unit
=> No_Unit_Id
,
1752 GNATprove_Mode
=> False,
1753 Invocation_Graph_Encoding
=> No_Encoding
,
1754 Last_CUDA_Kernel
=> CUDA_Kernels
.Last
,
1755 Last_Interrupt_State
=> Interrupt_States
.Last
,
1756 Last_Sdep
=> No_Sdep_Id
,
1757 Last_Specific_Dispatching
=> Specific_Dispatching
.Last
,
1758 Last_Unit
=> No_Unit_Id
,
1759 Locking_Policy
=> ' ',
1760 Main_Priority
=> -1,
1762 Main_Program
=> None
,
1763 No_Component_Reordering
=> False,
1765 Normalize_Scalars
=> False,
1766 Ofile_Full_Name
=> Full_Object_File_Name
,
1767 Partition_Elaboration_Policy
=> ' ',
1768 Queuing_Policy
=> ' ',
1769 Restrictions
=> No_Restrictions
,
1770 SAL_Interface
=> False,
1773 Task_Dispatching_Policy
=> ' ',
1774 Time_Slice_Value
=> -1,
1776 Unit_Exception_Table
=> False,
1777 Ver
=> (others => ' '),
1779 Zero_Cost_Exceptions
=> False);
1781 -- Now we acquire the input lines from the ALI file. Note that the
1782 -- convention in the following code is that as we enter each section,
1783 -- C is set to contain the first character of the following line.
1788 -- Acquire library version
1792 -- The V line missing really indicates trouble, most likely it
1793 -- means we don't have an ALI file at all, so here we give a
1794 -- fatal error even if we are in Ignore_Errors mode.
1798 elsif Ignore
('V') then
1806 for J
in 1 .. Ver_Len_Max
loop
1809 ALIs
.Table
(Id
).Ver
(J
) := C
;
1810 ALIs
.Table
(Id
).Ver_Len
:= J
;
1819 -- Acquire main program line if present
1822 if Ignore
('M') then
1832 ALIs
.Table
(Id
).Main_Program
:= Func
;
1834 ALIs
.Table
(Id
).Main_Program
:= Proc
;
1844 ALIs
.Table
(Id
).Main_Priority
:= Get_Nat
;
1852 ALIs
.Table
(Id
).Time_Slice_Value
:= Get_Nat
;
1860 ALIs
.Table
(Id
).Main_CPU
:= Get_Nat
;
1867 ALIs
.Table
(Id
).WC_Encoding
:= Getc
;
1876 -- Acquire argument lines
1878 First_Arg
:= Args
.Last
+ 1;
1882 exit A_Loop
when C
/= 'A';
1884 if Ignore
('A') then
1890 -- Scan out argument
1893 while not At_Eol
loop
1894 Add_Char_To_Name_Buffer
(Getc
);
1897 -- If -fstack-check, record that it occurred. Note that an
1898 -- additional string parameter can be specified, in the form of
1899 -- -fstack-check={no|generic|specific}. "no" means no checking,
1900 -- "generic" means force the use of old-style checking, and
1901 -- "specific" means use the best checking method.
1904 and then Name_Buffer
(1 .. 13) = "-fstack-check"
1905 and then Name_Buffer
(1 .. Name_Len
) /= "-fstack-check=no"
1907 Stack_Check_Switch_Set
:= True;
1910 -- Store the argument
1912 Args
.Increment_Last
;
1913 Args
.Table
(Args
.Last
) := new String'(Name_Buffer (1 .. Name_Len));
1921 -- Acquire 'K
' lines if present
1926 if Ignore ('K
') then
1931 CUDA_Kernels.Append ((Kernel_Name => Get_Name));
1932 ALIs.Table (Id).Last_CUDA_Kernel := CUDA_Kernels.Last;
1944 if Ignore_Errors then
1956 if Ignore ('P
') then
1964 while not At_Eol loop
1969 -- Processing for CE
1973 ALIs.Table (Id).Compile_Errors := True;
1975 -- Processing for DB
1979 Detect_Blocking := True;
1981 -- Processing for Ex
1984 Partition_Elaboration_Policy_Specified := Getc;
1985 ALIs.Table (Id).Partition_Elaboration_Policy :=
1986 Partition_Elaboration_Policy_Specified;
1988 -- Processing for FX
1993 -- Old front-end exceptions marker, ignore
2001 -- Processing for GP
2005 GNATprove_Mode_Specified := True;
2006 ALIs.Table (Id).GNATprove_Mode := True;
2008 -- Processing for Lx
2011 Locking_Policy_Specified := Getc;
2012 ALIs.Table (Id).Locking_Policy := Locking_Policy_Specified;
2014 -- Processing for flags starting with N
2019 -- Processing for NC
2022 ALIs.Table (Id).No_Component_Reordering := True;
2023 No_Component_Reordering_Specified := True;
2025 -- Processing for NO
2028 ALIs.Table (Id).No_Object := True;
2029 No_Object_Specified := True;
2031 -- Processing for NR
2034 No_Run_Time_Mode := True;
2035 Configurable_Run_Time_Mode := True;
2037 -- Processing for NS
2040 ALIs.Table (Id).Normalize_Scalars := True;
2041 Normalize_Scalars_Specified := True;
2044 -- Invalid switch starting with N
2050 -- Processing for OH/OL
2055 if C = 'L
' or else C = 'H
' then
2056 ALIs.Table (Id).SSO_Default := C;
2057 SSO_Default_Specified := True;
2063 -- Processing for Qx
2066 Queuing_Policy_Specified := Getc;
2067 ALIs.Table (Id).Queuing_Policy := Queuing_Policy_Specified;
2069 -- Processing for flags starting with S
2074 -- Processing for SL
2077 ALIs.Table (Id).SAL_Interface := True;
2079 -- Processing for SS
2082 -- Special case: a-tags/i-c* by themselves should not set
2083 -- Sec_Stack_Used, only if other code uses the secondary
2084 -- stack should we set this flag. This ensures that we do
2085 -- not bring the secondary stack unnecessarily when using
2086 -- one of these packages and not actually using the
2090 File : constant String := Get_Name_String (F);
2092 if File /= "a-tags.ali"
2093 and then File /= "i-c.ali"
2094 and then File /= "i-cstrin.ali"
2095 and then File /= "i-cpoint.ali"
2097 Opt.Sec_Stack_Used := True;
2101 -- Invalid switch starting with S
2107 -- Processing for Tx
2110 Task_Dispatching_Policy_Specified := Getc;
2111 ALIs.Table (Id).Task_Dispatching_Policy :=
2112 Task_Dispatching_Policy_Specified;
2114 -- Processing for switch starting with U
2119 -- Processing for UA
2122 Unreserve_All_Interrupts_Specified := True;
2124 -- Processing for UX
2127 ALIs.Table (Id).Unit_Exception_Table := True;
2129 -- Invalid switches starting with U
2135 -- Processing for ZX
2141 ALIs.Table (Id).Zero_Cost_Exceptions := True;
2142 Zero_Cost_Exceptions_Specified := True;
2147 -- Invalid parameter
2155 if not NS_Found then
2156 No_Normalize_Scalars_Specified := True;
2165 -- Loop to skip to first restrictions line
2168 if Ignore_Errors then
2180 -- Ignore all 'R
' lines if that is required
2182 if Ignore ('R
') then
2188 -- Here we process the restrictions lines (other than unit name cases)
2191 Scan_Restrictions : declare
2192 Save_R : constant Restrictions_Info := Cumulative_Restrictions;
2193 -- Save cumulative restrictions in case we have a fatal error
2195 Bad_R_Line : exception;
2196 -- Signal bad restrictions line (raised on unexpected character)
2203 -- Named restriction case
2209 -- Loop through RR and RV lines
2211 while C = 'R
' and then Nextc /= ' ' loop
2215 -- Acquire restriction name
2218 while not At_Eol and then Nextc /= '=' loop
2219 Name_Len := Name_Len + 1;
2220 Name_Buffer (Name_Len) := Getc;
2223 -- Now search list of restrictions to find match
2226 RN : String renames Name_Buffer (1 .. Name_Len);
2229 R := Restriction_Id'First;
2230 while R /= Not_A_Restriction_Id loop
2231 if Restriction_Id'Image (R) = RN then
2235 R := Restriction_Id'Succ (R);
2238 -- We don't recognize the restriction. This might be
2239 -- thought of as an error, and it really is, but we
2240 -- want to allow building with inconsistent versions
2241 -- of the binder and ali files (see comments at the
2242 -- start of package System.Rident), so we just ignore
2245 goto Done_With_Restriction_Line;
2252 -- Boolean restriction case
2254 when All_Boolean_Restrictions =>
2257 ALIs.Table (Id).Restrictions.Violated (R) :=
2259 Cumulative_Restrictions.Violated (R) := True;
2262 ALIs.Table (Id).Restrictions.Set (R) := True;
2263 Cumulative_Restrictions.Set (R) := True;
2269 -- Parameter restriction case
2271 when All_Parameter_Restrictions =>
2272 if At_Eol or else Nextc /= '=' then
2278 N := Natural (Get_Nat);
2285 ALIs.Table (Id).Restrictions.Set (R) := True;
2286 ALIs.Table (Id).Restrictions.Value (R) := N;
2288 if Cumulative_Restrictions.Set (R) then
2289 Cumulative_Restrictions.Value (R) :=
2291 (Cumulative_Restrictions.Value (R), N);
2293 Cumulative_Restrictions.Set (R) := True;
2294 Cumulative_Restrictions.Value (R) := N;
2297 -- Restriction violated
2300 ALIs.Table (Id).Restrictions.Violated (R) :=
2302 Cumulative_Restrictions.Violated (R) := True;
2303 ALIs.Table (Id).Restrictions.Count (R) := N;
2305 -- Checked Max_Parameter case
2307 if R in Checked_Max_Parameter_Restrictions then
2308 Cumulative_Restrictions.Count (R) :=
2310 (Cumulative_Restrictions.Count (R), N);
2312 -- Other checked parameter cases
2316 pragma Unsuppress (Overflow_Check);
2319 Cumulative_Restrictions.Count (R) :=
2320 Cumulative_Restrictions.Count (R) + N;
2323 when Constraint_Error =>
2325 -- A constraint error comes from the
2326 -- addition. We reset to the maximum
2327 -- and indicate that the real value
2330 Cumulative_Restrictions.Value (R) :=
2332 Cumulative_Restrictions.Unknown (R) :=
2341 ALIs.Table (Id).Restrictions.Unknown (R) :=
2343 Cumulative_Restrictions.Unknown (R) := True;
2346 -- Other than 'R
' or 'V
'
2356 -- Bizarre error case NOT_A_RESTRICTION
2358 when Not_A_Restriction_Id =>
2366 <<Done_With_Restriction_Line>>
2371 -- Positional restriction case
2377 -- Acquire information for boolean restrictions
2379 for R in All_Boolean_Restrictions loop
2384 ALIs.Table (Id).Restrictions.Violated (R) := True;
2385 Cumulative_Restrictions.Violated (R) := True;
2388 ALIs.Table (Id).Restrictions.Set (R) := True;
2389 Cumulative_Restrictions.Set (R) := True;
2399 -- Acquire information for parameter restrictions
2401 for RP in All_Parameter_Restrictions loop
2407 ALIs.Table (Id).Restrictions.Set (RP) := True;
2410 N : constant Integer := Integer (Get_Nat);
2412 ALIs.Table (Id).Restrictions.Value (RP) := N;
2414 if Cumulative_Restrictions.Set (RP) then
2415 Cumulative_Restrictions.Value (RP) :=
2417 (Cumulative_Restrictions.Value (RP), N);
2419 Cumulative_Restrictions.Set (RP) := True;
2420 Cumulative_Restrictions.Value (RP) := N;
2428 -- Acquire restrictions violations information
2436 ALIs.Table (Id).Restrictions.Violated (RP) := True;
2437 Cumulative_Restrictions.Violated (RP) := True;
2440 N : constant Integer := Integer (Get_Nat);
2443 ALIs.Table (Id).Restrictions.Count (RP) := N;
2445 if RP in Checked_Max_Parameter_Restrictions then
2446 Cumulative_Restrictions.Count (RP) :=
2448 (Cumulative_Restrictions.Count (RP), N);
2452 pragma Unsuppress (Overflow_Check);
2455 Cumulative_Restrictions.Count (RP) :=
2456 Cumulative_Restrictions.Count (RP) + N;
2459 when Constraint_Error =>
2461 -- A constraint error comes from the add. We
2462 -- reset to the maximum and indicate that the
2463 -- real value is now unknown.
2465 Cumulative_Restrictions.Value (RP) :=
2467 Cumulative_Restrictions.Unknown (RP) := True;
2473 ALIs.Table (Id).Restrictions.Unknown (RP) := True;
2474 Cumulative_Restrictions.Unknown (RP) := True;
2491 -- Here if error during scanning of restrictions line
2496 -- In Ignore_Errors mode, undo any changes to restrictions
2497 -- from this unit, and continue on, skipping remaining R
2498 -- lines for this unit.
2500 if Ignore_Errors then
2501 Cumulative_Restrictions := Save_R;
2502 ALIs.Table (Id).Restrictions := No_Restrictions;
2510 -- In normal mode, this is a fatal error
2515 end Scan_Restrictions;
2518 -- Acquire additional restrictions (No_Dependence) lines if present
2521 if Ignore ('R
') then
2525 No_Deps.Append ((Id, Get_Name));
2532 -- Acquire 'I
' lines if present
2537 if Ignore ('I
') then
2543 I_State : Character;
2552 Interrupt_States.Append (
2553 (Interrupt_Id => Int_Num,
2554 Interrupt_State => I_State,
2555 IS_Pragma_Line => Line_No));
2557 ALIs.Table (Id).Last_Interrupt_State := Interrupt_States.Last;
2565 -- Acquire 'S
' lines if present
2570 if Ignore ('S
') then
2586 First_Prio := Get_Nat;
2587 Last_Prio := Get_Nat;
2590 Specific_Dispatching.Append (
2591 (Dispatching_Policy => Policy,
2592 First_Priority => First_Prio,
2593 Last_Priority => Last_Prio,
2594 PSD_Pragma_Line => Line_No));
2596 ALIs.Table (Id).Last_Specific_Dispatching :=
2597 Specific_Dispatching.Last;
2606 -- Loop to acquire unit entries
2610 exit U_Loop when C /= 'U
';
2612 -- Note: as per spec, we never ignore U lines
2616 Units.Increment_Last;
2618 if ALIs.Table (Id).First_Unit = No_Unit_Id then
2619 ALIs.Table (Id).First_Unit := Units.Last;
2623 UL : Unit_Record renames Units.Table (Units.Last);
2626 UL.Uname := Get_Unit_Name;
2627 UL.Predefined := Is_Predefined_Unit;
2628 UL.Internal := Is_Internal_Unit;
2630 UL.Sfile := Get_File_Name (Lower => True);
2632 UL.Preelab := False;
2633 UL.No_Elab := False;
2634 UL.Shared_Passive := False;
2636 UL.Remote_Types := False;
2637 UL.Serious_Errors := False;
2638 UL.Has_RACW := False;
2639 UL.Init_Scalars := False;
2640 UL.Is_Generic := False;
2641 UL.Icasing := Mixed_Case;
2642 UL.Kcasing := All_Lower_Case;
2643 UL.Dynamic_Elab := False;
2644 UL.Elaborate_Body := False;
2645 UL.Set_Elab_Entity := False;
2646 UL.Version := "00000000";
2647 UL.First_With := Withs.Last + 1;
2648 UL.First_Arg := First_Arg;
2649 UL.First_Invocation_Construct := Invocation_Constructs.Last + 1;
2650 UL.Last_Invocation_Construct := No_Invocation_Construct;
2651 UL.First_Invocation_Relation := Invocation_Relations.Last + 1;
2652 UL.Last_Invocation_Relation := No_Invocation_Relation;
2653 UL.Elab_Position := 0;
2654 UL.SAL_Interface := ALIs.Table (Id).SAL_Interface;
2655 UL.Directly_Scanned := Directly_Scanned;
2656 UL.Body_Needed_For_SAL := False;
2657 UL.Elaborate_Body_Desirable := False;
2658 UL.Optimize_Alignment := 'O
';
2659 UL.Has_Finalizer := False;
2660 UL.Primary_Stack_Count := 0;
2661 UL.Sec_Stack_Count := 0;
2663 if Debug_Flag_U then
2664 Write_Str (" ----> reading unit ");
2665 Write_Int (Int (Units.Last));
2667 Write_Unit_Name (UL.Uname);
2668 Write_Str (" from file ");
2669 Write_Name (UL.Sfile);
2674 -- Check for duplicated unit in different files
2677 Info : constant Int := Get_Name_Table_Int
2678 (Units.Table (Units.Last).Uname);
2681 and then Units.Table (Units.Last).Sfile /=
2682 Units.Table (Unit_Id (Info)).Sfile
2684 -- If Err is set then ignore duplicate unit name. This is the
2685 -- case of a call from gnatmake, where the situation can arise
2686 -- from substitution of source files. In such situations, the
2687 -- processing in gnatmake will always result in any required
2688 -- recompilations in any case, and if we consider this to be
2689 -- an error we get strange cases (for example when a generic
2690 -- instantiation is replaced by a normal package) where we
2691 -- read the old ali file, decide to recompile, and then decide
2692 -- that the old and new ali files are incompatible.
2697 -- If Err is not set, then this is a fatal error. This is
2698 -- the case of being called from the binder, where we must
2699 -- definitely diagnose this as an error.
2703 Write_Str ("error: duplicate unit name: ");
2706 Write_Str ("error: unit """);
2707 Write_Unit_Name (Units.Table (Units.Last).Uname);
2708 Write_Str (""" found in file """);
2709 Write_Name_Decoded (Units.Table (Units.Last).Sfile);
2713 Write_Str ("error
: unit
""");
2714 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
2715 Write_Str (""" found
in file
""");
2716 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
2720 Exit_Program (E_Fatal);
2726 (Units.Table (Units.Last).Uname, Int (Units.Last));
2728 -- Scan out possible version and other parameters
2737 if C in '0' .. '9' or else C in 'a
' .. 'f
' then
2738 Units.Table (Units.Last).Version (1) := C;
2740 for J in 2 .. 8 loop
2742 Units.Table (Units.Last).Version (J) := C;
2751 Check_At_End_Of_Field;
2752 Units.Table (Units.Last).Elaborate_Body_Desirable := True;
2755 Check_At_End_Of_Field;
2756 Units.Table (Units.Last).Body_Needed_For_SAL := True;
2762 -- DE parameter (Dynamic elaboration checks)
2768 Check_At_End_Of_Field;
2769 Units.Table (Units.Last).Dynamic_Elab := True;
2770 Dynamic_Elaboration_Checks_Specified := True;
2781 Units.Table (Units.Last).Elaborate_Body := True;
2783 Units.Table (Units.Last).Set_Elab_Entity := True;
2788 Check_At_End_Of_Field;
2790 -- GE parameter (generic)
2796 Check_At_End_Of_Field;
2797 Units.Table (Units.Last).Is_Generic := True;
2802 -- IL/IS/IU parameters
2808 Units.Table (Units.Last).Icasing := All_Lower_Case;
2810 Units.Table (Units.Last).Init_Scalars := True;
2811 Initialize_Scalars_Used := True;
2813 Units.Table (Units.Last).Icasing := All_Upper_Case;
2818 Check_At_End_Of_Field;
2826 Units.Table (Units.Last).Kcasing := Mixed_Case;
2828 Units.Table (Units.Last).Kcasing := All_Upper_Case;
2833 Check_At_End_Of_Field;
2841 Units.Table (Units.Last).No_Elab := True;
2842 Check_At_End_Of_Field;
2847 -- PF/PR/PU/PK parameters
2853 Units.Table (Units.Last).Has_Finalizer := True;
2855 Units.Table (Units.Last).Preelab := True;
2857 Units.Table (Units.Last).Pure := True;
2859 Units.Table (Units.Last).Unit_Kind := 'p
';
2864 Check_At_End_Of_Field;
2866 -- OL/OO/OS/OT parameters
2871 if C = 'L
' or else C = 'O
' or else C = 'S
' or else C = 'T
' then
2872 Units.Table (Units.Last).Optimize_Alignment := C;
2877 Check_At_End_Of_Field;
2885 Units.Table (Units.Last).RCI := True;
2887 Units.Table (Units.Last).Remote_Types := True;
2889 Units.Table (Units.Last).Has_RACW := True;
2894 Check_At_End_Of_Field;
2896 -- SE/SP/SU parameters
2902 Units.Table (Units.Last).Serious_Errors := True;
2904 Units.Table (Units.Last).Shared_Passive := True;
2906 Units.Table (Units.Last).Unit_Kind := 's
';
2911 Check_At_End_Of_Field;
2923 -- Scan out With lines for this unit
2927 exit With_Loop when C /= 'W
' and then C /= 'Y
' and then C /= 'Z
';
2929 if Ignore ('W
') then
2935 Withs.Increment_Last;
2936 Withs.Table (Withs.Last).Uname := Get_Unit_Name;
2937 Withs.Table (Withs.Last).Elaborate := False;
2938 Withs.Table (Withs.Last).Elaborate_All := False;
2939 Withs.Table (Withs.Last).Elab_Desirable := False;
2940 Withs.Table (Withs.Last).Elab_All_Desirable := False;
2941 Withs.Table (Withs.Last).SAL_Interface := False;
2942 Withs.Table (Withs.Last).Limited_With := (C = 'Y
');
2943 Withs.Table (Withs.Last).Implicit_With := (C = 'Z
');
2945 -- Generic case with no object file available
2948 Withs.Table (Withs.Last).Sfile := No_File;
2949 Withs.Table (Withs.Last).Afile := No_File;
2954 Withs.Table (Withs.Last).Sfile := Get_File_Name
2956 Withs.Table (Withs.Last).Afile := Get_File_Name
2959 -- Scan out possible E, EA, ED, and AD parameters
2961 while not At_Eol loop
2967 Check_At_End_Of_Field;
2969 -- Store AD indication unless ignore required
2971 Withs.Table (Withs.Last).Elab_All_Desirable := True;
2973 elsif Nextc = 'E
' then
2976 if At_End_Of_Field then
2977 Withs.Table (Withs.Last).Elaborate := True;
2979 elsif Nextc = 'A
' then
2981 Check_At_End_Of_Field;
2982 Withs.Table (Withs.Last).Elaborate_All := True;
2986 Check_At_End_Of_Field;
2988 -- Store ED indication
2990 Withs.Table (Withs.Last).Elab_Desirable := True;
3005 Units.Table (Units.Last).Last_With := Withs.Last;
3006 Units.Table (Units.Last).Last_Arg := Args.Last;
3008 -- Scan out task stack information for the unit if present
3013 if Ignore ('T
') then
3020 Units.Table (Units.Last).Primary_Stack_Count := Get_Nat;
3022 Units.Table (Units.Last).Sec_Stack_Count := Get_Nat;
3030 -- If there are linker options lines present, scan them
3034 Linker_Options_Loop : loop
3036 exit Linker_Options_Loop when C /= 'L
';
3038 if Ignore ('L
') then
3049 if C < Character'Val (16#20#)
3050 or else C > Character'Val (16#7E#)
3055 C := Character'Val (0);
3062 for J in 1 .. 2 loop
3065 if C in '0' .. '9' then
3068 Character'Pos ('0');
3070 elsif C in 'A' .. 'F' then
3073 Character'Pos ('A') +
3082 Add_Char_To_Name_Buffer (Character'Val (V));
3087 exit when Nextc /= '"';
3091 Add_Char_To_Name_Buffer (C);
3095 Add_Char_To_Name_Buffer (NUL);
3100 end loop Linker_Options_Loop;
3102 -- Store the linker options entry if one was found
3104 if Name_Len /= 0 then
3105 Linker_Options.Increment_Last;
3107 Linker_Options.Table (Linker_Options.Last).Name :=
3110 Linker_Options.Table (Linker_Options.Last).Unit :=
3113 Linker_Options.Table (Linker_Options.Last).Internal_File :=
3114 Is_Internal_File_Name (F);
3117 -- If there are notes present, scan them
3121 exit Notes_Loop when C /= 'N';
3123 if Ignore ('N') then
3129 Notes.Increment_Last;
3130 Notes.Table (Notes.Last).Pragma_Type := Getc;
3131 Notes.Table (Notes.Last).Pragma_Line := Get_Nat;
3133 Notes.Table (Notes.Last).Pragma_Col := Get_Nat;
3135 if not At_Eol and then Nextc = ':' then
3137 Notes.Table (Notes.Last).Pragma_Source_File :=
3138 Get_File_Name (Lower => True);
3140 Notes.Table (Notes.Last).Pragma_Source_File :=
3141 Units.Table (Units.Last).Sfile;
3145 Notes.Table (Notes.Last).Pragma_Args := No_Name;
3148 -- Note: can't use Get_Name here as the remainder of the
3149 -- line is unstructured text whose syntax depends on the
3150 -- particular pragma used.
3155 while not At_Eol loop
3156 Add_Char_To_Name_Buffer (Getc);
3164 end loop Notes_Loop;
3167 -- End loop through units for one ALI file
3169 ALIs.Table (Id).Last_Unit := Units.Last;
3170 ALIs.Table (Id).Sfile := Units.Table (ALIs.Table (Id).First_Unit).Sfile;
3172 -- Set types of the units (there can be at most 2 of them)
3174 if ALIs.Table (Id).First_Unit /= ALIs.Table (Id).Last_Unit then
3175 Units.Table (ALIs.Table (Id).First_Unit).Utype := Is_Body;
3176 Units.Table (ALIs.Table (Id).Last_Unit).Utype := Is_Spec;
3179 -- Deal with body only and spec only cases, note that the reason we
3180 -- do our own checking of the name (rather than using Is_Body_Name)
3181 -- is that Uname drags in far too much compiler junk.
3183 Get_Name_String (Units.Table (Units.Last).Uname);
3185 if Name_Buffer (Name_Len) = 'b' then
3186 Units.Table (Units.Last).Utype := Is_Body_Only;
3188 Units.Table (Units.Last).Utype := Is_Spec_Only;
3192 -- Scan out external version references and put in hash table
3196 exit E_Loop when C /= 'E';
3198 if Ignore ('E') then
3214 exit when At_End_Of_Field;
3215 Add_Char_To_Name_Buffer (C);
3218 Version_Ref.Set (new String'(Name_Buffer (1 .. Name_Len)), True);
3225 -- Scan out source dependency lines for this ALI file
3227 ALIs.Table (Id).First_Sdep := Sdep.Last + 1;
3231 exit D_Loop when C /= 'D';
3233 if Ignore ('D') then
3239 Sdep.Increment_Last;
3241 -- The file/path name may be quoted
3243 Sdep.Table (Sdep.Last).Sfile :=
3244 Get_File_Name (Lower => True, May_Be_Quoted => True);
3246 Sdep.Table (Sdep.Last).Stamp := Get_Stamp;
3247 Sdep.Table (Sdep.Last).Dummy_Entry :=
3248 (Sdep.Table (Sdep.Last).Stamp = Dummy_Time_Stamp);
3250 -- Acquire checksum value
3263 exit when At_Eol or else Ctr = 8;
3265 if Nextc in '0' .. '9' then
3267 Character'Pos (Nextc) - Character'Pos ('0');
3269 elsif Nextc in 'a' .. 'f' then
3271 Character'Pos (Nextc) - Character'Pos ('a') + 10;
3281 if Ctr = 8 and then At_End_Of_Field then
3282 Sdep.Table (Sdep.Last).Checksum := Chk;
3288 -- Acquire (sub)unit and reference file name entries
3290 Sdep.Table (Sdep.Last).Subunit_Name := No_Name;
3291 Sdep.Table (Sdep.Last).Unit_Name := No_Name;
3292 Sdep.Table (Sdep.Last).Rfile :=
3293 Sdep.Table (Sdep.Last).Sfile;
3294 Sdep.Table (Sdep.Last).Start_Line := 1;
3299 -- Here for (sub)unit name
3301 if Nextc not in '0' .. '9' then
3303 while not At_End_Of_Field loop
3304 Add_Char_To_Name_Buffer (Getc);
3307 -- Set the (sub)unit name. Note that we use Name_Find rather
3308 -- than Name_Enter here as the subunit name may already
3309 -- have been put in the name table by the Project Manager.
3312 or else Name_Buffer (Name_Len - 1) /= '%'
3314 Sdep.Table (Sdep.Last).Subunit_Name := Name_Find;
3316 Name_Len := Name_Len - 2;
3317 Sdep.Table (Sdep.Last).Unit_Name := Name_Find;
3323 -- Here for reference file name entry
3325 if Nextc in '0' .. '9' then
3326 Sdep.Table (Sdep.Last).Start_Line := Get_Nat;
3331 while not At_End_Of_Field loop
3332 Add_Char_To_Name_Buffer (Getc);
3335 Sdep.Table (Sdep.Last).Rfile := Name_Enter;
3345 ALIs.Table (Id).Last_Sdep := Sdep.Last;
3347 -- Loop through invocation-graph lines
3351 exit G_Loop when C /= 'G';
3353 Scan_Invocation_Graph_Line;
3358 -- We must at this stage be at an Xref line or the end of file
3370 -- This ALI parser does not care about Xref lines.
3375 when Bad_ALI_Format =>
3383 function IS_Scope (IS_Id : Invocation_Signature_Id) return Name_Id is
3385 pragma Assert (Present (IS_Id));
3386 return Invocation_Signatures.Table (IS_Id).Scope;
3393 function SEq (F1, F2 : String_Ptr) return Boolean is
3395 return F1.all = F2.all;
3398 -----------------------------------
3399 -- Set_Invocation_Graph_Encoding --
3400 -----------------------------------
3402 procedure Set_Invocation_Graph_Encoding
3403 (Kind : Invocation_Graph_Encoding_Kind;
3404 Update_Units : Boolean := True)
3407 Compile_Time_Invocation_Graph_Encoding := Kind;
3409 -- Update the invocation-graph encoding of the current unit only when
3410 -- requested by the caller.
3412 if Update_Units then
3414 Curr_Unit : Unit_Record renames Units.Table (Units.Last);
3415 Curr_ALI : ALIs_Record renames ALIs.Table (Curr_Unit.My_ALI);
3418 Curr_ALI.Invocation_Graph_Encoding := Kind;
3421 end Set_Invocation_Graph_Encoding;
3427 function SHash (S : String_Ptr) return Vindex is
3432 for J in S.all'Range loop
3433 H := H * 2 + Character'Pos (S (J));
3436 return Vindex (Vindex'First + Vindex (H mod Vindex'Range_Length));
3444 (IC_Id : Invocation_Construct_Id) return Invocation_Signature_Id
3447 pragma Assert (Present (IC_Id));
3448 return Invocation_Constructs.Table (IC_Id).Signature;
3451 --------------------
3452 -- Spec_Placement --
3453 --------------------
3455 function Spec_Placement
3456 (IC_Id : Invocation_Construct_Id) return Declaration_Placement_Kind
3459 pragma Assert (Present (IC_Id));
3460 return Invocation_Constructs.Table (IC_Id).Spec_Placement;
3468 (IR_Id : Invocation_Relation_Id) return Invocation_Signature_Id
3471 pragma Assert (Present (IR_Id));
3472 return Invocation_Relations.Table (IR_Id).Target;