1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2021, 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
;
40 -- Make control characters visible
46 -- The following type represents an invocation construct
48 type Invocation_Construct_Record
is record
49 Body_Placement
: Declaration_Placement_Kind
:= No_Declaration_Placement
;
50 -- The location of the invocation construct's body with respect to the
51 -- unit where it is declared.
53 Kind
: Invocation_Construct_Kind
:= Regular_Construct
;
54 -- The nature of the invocation construct
56 Signature
: Invocation_Signature_Id
:= No_Invocation_Signature
;
57 -- The invocation signature that uniquely identifies the invocation
58 -- construct in the ALI space.
60 Spec_Placement
: Declaration_Placement_Kind
:= No_Declaration_Placement
;
61 -- The location of the invocation construct's spec with respect to the
62 -- unit where it is declared.
65 -- The following type represents an invocation relation. It associates an
66 -- invoker that activates/calls/instantiates with a target.
68 type Invocation_Relation_Record
is record
69 Extra
: Name_Id
:= No_Name
;
70 -- The name of an additional entity used in error diagnostics
72 Invoker
: Invocation_Signature_Id
:= No_Invocation_Signature
;
73 -- The invocation signature that uniquely identifies the invoker within
76 Kind
: Invocation_Kind
:= No_Invocation
;
77 -- The nature of the invocation
79 Target
: Invocation_Signature_Id
:= No_Invocation_Signature
;
80 -- The invocation signature that uniquely identifies the target within
84 -- The following type represents an invocation signature. Its purpose is
85 -- to uniquely identify an invocation construct within the ALI space. The
86 -- signature comprises several pieces, some of which are used in error
87 -- diagnostics by the binder. Identification issues are resolved as
90 -- * The Column, Line, and Locations attributes together differentiate
91 -- between homonyms. In most cases, the Column and Line are sufficient
92 -- except when generic instantiations are involved. Together, the three
93 -- attributes offer a sequence of column-line pairs that eventually
94 -- reflect the location within the generic template.
96 -- * The Name attribute differentiates between invocation constructs at
97 -- the scope level. Since it is illegal for two entities with the same
98 -- name to coexist in the same scope, the Name attribute is sufficient
99 -- to distinguish them. Overloaded entities are already handled by the
100 -- Column, Line, and Locations attributes.
102 -- * The Scope attribute differentiates between invocation constructs at
103 -- various levels of nesting.
105 type Invocation_Signature_Record
is record
107 -- The column number where the invocation construct is declared
110 -- The line number where the invocation construct is declared
112 Locations
: Name_Id
:= No_Name
;
113 -- Sequence of column and line numbers within nested instantiations
115 Name
: Name_Id
:= No_Name
;
116 -- The name of the invocation construct
118 Scope
: Name_Id
:= No_Name
;
119 -- The qualified name of the scope where the invocation construct is
123 ---------------------
124 -- Data structures --
125 ---------------------
127 package Invocation_Constructs
is new Table
.Table
128 (Table_Index_Type
=> Invocation_Construct_Id
,
129 Table_Component_Type
=> Invocation_Construct_Record
,
130 Table_Low_Bound
=> First_Invocation_Construct
,
131 Table_Initial
=> 2500,
132 Table_Increment
=> 200,
133 Table_Name
=> "Invocation_Constructs");
135 package Invocation_Relations
is new Table
.Table
136 (Table_Index_Type
=> Invocation_Relation_Id
,
137 Table_Component_Type
=> Invocation_Relation_Record
,
138 Table_Low_Bound
=> First_Invocation_Relation
,
139 Table_Initial
=> 2500,
140 Table_Increment
=> 200,
141 Table_Name
=> "Invocation_Relation");
143 package Invocation_Signatures
is new Table
.Table
144 (Table_Index_Type
=> Invocation_Signature_Id
,
145 Table_Component_Type
=> Invocation_Signature_Record
,
146 Table_Low_Bound
=> First_Invocation_Signature
,
147 Table_Initial
=> 2500,
148 Table_Increment
=> 200,
149 Table_Name
=> "Invocation_Signatures");
151 procedure Destroy
(IS_Id
: in out Invocation_Signature_Id
);
152 -- Destroy an invocation signature with id IS_Id
155 (IS_Rec
: Invocation_Signature_Record
) return Bucket_Range_Type
;
156 -- Obtain the hash of key IS_Rec
158 package Sig_Map
is new Dynamic_Hash_Tables
159 (Key_Type
=> Invocation_Signature_Record
,
160 Value_Type
=> Invocation_Signature_Id
,
161 No_Value
=> No_Invocation_Signature
,
162 Expansion_Threshold
=> 1.5,
163 Expansion_Factor
=> 2,
164 Compression_Threshold
=> 0.3,
165 Compression_Factor
=> 2,
167 Destroy_Value
=> Destroy
,
170 -- The following map relates invocation signature records to invocation
173 Sig_To_Sig_Map
: constant Sig_Map
.Dynamic_Hash_Table
:=
174 Sig_Map
.Create
(500);
176 -- The folowing table maps declaration placement kinds to character codes
177 -- for invocation construct encoding in ALI files.
179 Declaration_Placement_Codes
:
180 constant array (Declaration_Placement_Kind
) of Character :=
183 No_Declaration_Placement
=> 'Z');
185 Compile_Time_Invocation_Graph_Encoding
: Invocation_Graph_Encoding_Kind
:=
187 -- The invocation-graph encoding format as specified at compile time. Do
188 -- not manipulate this value directly.
190 -- The following table maps invocation kinds to character codes for
191 -- invocation relation encoding in ALI files.
194 constant array (Invocation_Kind
) of Character :=
195 (Accept_Alternative
=> 'a',
198 Controlled_Adjustment
=> 'd',
199 Controlled_Finalization
=> 'e',
200 Controlled_Initialization
=> 'f',
201 Default_Initial_Condition_Verification
=> 'g',
202 Initial_Condition_Verification
=> 'h',
203 Instantiation
=> 'i',
204 Internal_Controlled_Adjustment
=> 'j',
205 Internal_Controlled_Finalization
=> 'k',
206 Internal_Controlled_Initialization
=> 'l',
207 Invariant_Verification
=> 'm',
208 Postcondition_Verification
=> 'n',
209 Protected_Entry_Call
=> 'o',
210 Protected_Subprogram_Call
=> 'p',
211 Task_Activation
=> 'q',
212 Task_Entry_Call
=> 'r',
213 Type_Initialization
=> 's',
214 No_Invocation
=> 'Z');
216 -- The following table maps invocation construct kinds to character codes
217 -- for invocation construct encoding in ALI files.
219 Invocation_Construct_Codes
:
220 constant array (Invocation_Construct_Kind
) of Character :=
221 (Elaborate_Body_Procedure
=> 'b',
222 Elaborate_Spec_Procedure
=> 's',
223 Regular_Construct
=> 'Z');
225 -- The following table maps invocation-graph encoding kinds to character
226 -- codes for invocation-graph encoding in ALI files.
228 Invocation_Graph_Encoding_Codes
:
229 constant array (Invocation_Graph_Encoding_Kind
) of Character :=
230 (Full_Path_Encoding
=> 'f',
231 Endpoints_Encoding
=> 'e',
234 -- The following table maps invocation-graph line kinds to character codes
235 -- used in ALI files.
237 Invocation_Graph_Line_Codes
:
238 constant array (Invocation_Graph_Line_Kind
) of Character :=
239 (Invocation_Construct_Line
=> 'c',
240 Invocation_Graph_Attributes_Line
=> 'a',
241 Invocation_Relation_Line
=> 'r');
243 -- The following variable records which characters currently are used as
244 -- line type markers in the ALI file. This is used in Scan_ALI to detect
245 -- (or skip) invalid lines.
247 Known_ALI_Lines
: constant array (Character range 'A' .. 'Z') of Boolean :=
249 'C' |
-- SCO information
252 'G' |
-- invocation graph
254 'L' |
-- linker option
255 'M' |
-- main program
259 'S' |
-- specific dispatching
260 'T' |
-- task stack information
265 'Y' |
-- limited_with
266 'Z' -- implicit with from instantiation
271 'B' |
'F' |
'H' |
'J' |
'K' |
'O' |
'Q' => False);
273 ------------------------------
274 -- Add_Invocation_Construct --
275 ------------------------------
277 procedure Add_Invocation_Construct
278 (Body_Placement
: Declaration_Placement_Kind
;
279 Kind
: Invocation_Construct_Kind
;
280 Signature
: Invocation_Signature_Id
;
281 Spec_Placement
: Declaration_Placement_Kind
;
282 Update_Units
: Boolean := True)
285 pragma Assert
(Present
(Signature
));
287 -- Create a invocation construct from the scanned attributes
289 Invocation_Constructs
.Append
290 ((Body_Placement
=> Body_Placement
,
292 Signature
=> Signature
,
293 Spec_Placement
=> Spec_Placement
));
295 -- Update the invocation construct counter of the current unit only when
296 -- requested by the caller.
300 Curr_Unit
: Unit_Record
renames Units
.Table
(Units
.Last
);
303 Curr_Unit
.Last_Invocation_Construct
:= Invocation_Constructs
.Last
;
306 end Add_Invocation_Construct
;
308 -----------------------------
309 -- Add_Invocation_Relation --
310 -----------------------------
312 procedure Add_Invocation_Relation
314 Invoker
: Invocation_Signature_Id
;
315 Kind
: Invocation_Kind
;
316 Target
: Invocation_Signature_Id
;
317 Update_Units
: Boolean := True)
320 pragma Assert
(Present
(Invoker
));
321 pragma Assert
(Kind
/= No_Invocation
);
322 pragma Assert
(Present
(Target
));
324 -- Create an invocation relation from the scanned attributes
326 Invocation_Relations
.Append
332 -- Update the invocation relation counter of the current unit only when
333 -- requested by the caller.
337 Curr_Unit
: Unit_Record
renames Units
.Table
(Units
.Last
);
340 Curr_Unit
.Last_Invocation_Relation
:= Invocation_Relations
.Last
;
343 end Add_Invocation_Relation
;
349 function Body_Placement
350 (IC_Id
: Invocation_Construct_Id
) return Declaration_Placement_Kind
353 pragma Assert
(Present
(IC_Id
));
354 return Invocation_Constructs
.Table
(IC_Id
).Body_Placement
;
357 ----------------------------------------
358 -- Code_To_Declaration_Placement_Kind --
359 ----------------------------------------
361 function Code_To_Declaration_Placement_Kind
362 (Code
: Character) return Declaration_Placement_Kind
365 -- Determine which placement kind corresponds to the character code by
366 -- traversing the contents of the mapping table.
368 for Kind
in Declaration_Placement_Kind
loop
369 if Declaration_Placement_Codes
(Kind
) = Code
then
375 end Code_To_Declaration_Placement_Kind
;
377 ---------------------------------------
378 -- Code_To_Invocation_Construct_Kind --
379 ---------------------------------------
381 function Code_To_Invocation_Construct_Kind
382 (Code
: Character) return Invocation_Construct_Kind
385 -- Determine which invocation construct kind matches the character code
386 -- by traversing the contents of the mapping table.
388 for Kind
in Invocation_Construct_Kind
loop
389 if Invocation_Construct_Codes
(Kind
) = Code
then
395 end Code_To_Invocation_Construct_Kind
;
397 --------------------------------------------
398 -- Code_To_Invocation_Graph_Encoding_Kind --
399 --------------------------------------------
401 function Code_To_Invocation_Graph_Encoding_Kind
402 (Code
: Character) return Invocation_Graph_Encoding_Kind
405 -- Determine which invocation-graph encoding kind matches the character
406 -- code by traversing the contents of the mapping table.
408 for Kind
in Invocation_Graph_Encoding_Kind
loop
409 if Invocation_Graph_Encoding_Codes
(Kind
) = Code
then
415 end Code_To_Invocation_Graph_Encoding_Kind
;
417 -----------------------------
418 -- Code_To_Invocation_Kind --
419 -----------------------------
421 function Code_To_Invocation_Kind
422 (Code
: Character) return Invocation_Kind
425 -- Determine which invocation kind corresponds to the character code by
426 -- traversing the contents of the mapping table.
428 for Kind
in Invocation_Kind
loop
429 if Invocation_Codes
(Kind
) = Code
then
435 end Code_To_Invocation_Kind
;
437 ----------------------------------------
438 -- Code_To_Invocation_Graph_Line_Kind --
439 ----------------------------------------
441 function Code_To_Invocation_Graph_Line_Kind
442 (Code
: Character) return Invocation_Graph_Line_Kind
445 -- Determine which invocation-graph line kind matches the character
446 -- code by traversing the contents of the mapping table.
448 for Kind
in Invocation_Graph_Line_Kind
loop
449 if Invocation_Graph_Line_Codes
(Kind
) = Code
then
455 end Code_To_Invocation_Graph_Line_Kind
;
461 function Column
(IS_Id
: Invocation_Signature_Id
) return Nat
is
463 pragma Assert
(Present
(IS_Id
));
464 return Invocation_Signatures
.Table
(IS_Id
).Column
;
467 ----------------------------------------
468 -- Declaration_Placement_Kind_To_Code --
469 ----------------------------------------
471 function Declaration_Placement_Kind_To_Code
472 (Kind
: Declaration_Placement_Kind
) return Character
475 return Declaration_Placement_Codes
(Kind
);
476 end Declaration_Placement_Kind_To_Code
;
482 procedure Destroy
(IS_Id
: in out Invocation_Signature_Id
) is
483 pragma Unreferenced
(IS_Id
);
492 function Extra
(IR_Id
: Invocation_Relation_Id
) return Name_Id
is
494 pragma Assert
(Present
(IR_Id
));
495 return Invocation_Relations
.Table
(IR_Id
).Extra
;
498 -----------------------------------
499 -- For_Each_Invocation_Construct --
500 -----------------------------------
502 procedure For_Each_Invocation_Construct
503 (Processor
: Invocation_Construct_Processor_Ptr
)
506 pragma Assert
(Processor
/= null);
508 for IC_Id
in Invocation_Constructs
.First
..
509 Invocation_Constructs
.Last
511 Processor
.all (IC_Id
);
513 end For_Each_Invocation_Construct
;
515 -----------------------------------
516 -- For_Each_Invocation_Construct --
517 -----------------------------------
519 procedure For_Each_Invocation_Construct
521 Processor
: Invocation_Construct_Processor_Ptr
)
523 pragma Assert
(Present
(U_Id
));
524 pragma Assert
(Processor
/= null);
526 U_Rec
: Unit_Record
renames Units
.Table
(U_Id
);
529 for IC_Id
in U_Rec
.First_Invocation_Construct
..
530 U_Rec
.Last_Invocation_Construct
532 Processor
.all (IC_Id
);
534 end For_Each_Invocation_Construct
;
536 ----------------------------------
537 -- For_Each_Invocation_Relation --
538 ----------------------------------
540 procedure For_Each_Invocation_Relation
541 (Processor
: Invocation_Relation_Processor_Ptr
)
544 pragma Assert
(Processor
/= null);
546 for IR_Id
in Invocation_Relations
.First
..
547 Invocation_Relations
.Last
549 Processor
.all (IR_Id
);
551 end For_Each_Invocation_Relation
;
553 ----------------------------------
554 -- For_Each_Invocation_Relation --
555 ----------------------------------
557 procedure For_Each_Invocation_Relation
559 Processor
: Invocation_Relation_Processor_Ptr
)
561 pragma Assert
(Present
(U_Id
));
562 pragma Assert
(Processor
/= null);
564 U_Rec
: Unit_Record
renames Units
.Table
(U_Id
);
567 for IR_Id
in U_Rec
.First_Invocation_Relation
..
568 U_Rec
.Last_Invocation_Relation
570 Processor
.all (IR_Id
);
572 end For_Each_Invocation_Relation
;
579 (IS_Rec
: Invocation_Signature_Record
) return Bucket_Range_Type
581 Buffer
: Bounded_String
(2052);
585 -- The hash is obtained in the following manner:
587 -- * A String signature based on the scope, name, line number, column
588 -- number, and locations, in the following format:
590 -- scope__name__line_column__locations
592 -- * The String is converted into a Name_Id
594 -- * The absolute value of the Name_Id is used as the hash
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 IS_Nam
:= Name_Find
(Buffer
);
610 return Bucket_Range_Type
(abs IS_Nam
);
617 procedure Initialize_ALI
is
619 -- When (re)initializing ALI data structures the ALI user expects to
620 -- get a fresh set of data structures. Thus we first need to erase the
621 -- marks put in the name table by the previous set of ALI routine calls.
622 -- These two loops are empty and harmless the first time in.
624 for J
in ALIs
.First
.. ALIs
.Last
loop
625 Set_Name_Table_Int
(ALIs
.Table
(J
).Afile
, 0);
628 for J
in Units
.First
.. Units
.Last
loop
629 Set_Name_Table_Int
(Units
.Table
(J
).Uname
, 0);
632 -- Free argument table strings
634 for J
in Args
.First
.. Args
.Last
loop
635 Free
(Args
.Table
(J
));
638 -- Initialize all tables
641 Invocation_Constructs
.Init
;
642 Invocation_Relations
.Init
;
643 Invocation_Signatures
.Init
;
655 -- Add dummy zeroth item in Linker_Options and Notes for sort calls
657 Linker_Options
.Increment_Last
;
658 Notes
.Increment_Last
;
660 -- Initialize global variables recording cumulative options in all
661 -- ALI files that are read for a given processing run in gnatbind.
663 Dynamic_Elaboration_Checks_Specified
:= False;
664 Locking_Policy_Specified
:= ' ';
665 No_Normalize_Scalars_Specified
:= False;
666 No_Object_Specified
:= False;
667 No_Component_Reordering_Specified
:= False;
668 GNATprove_Mode_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 Frontend_Exceptions_Specified
:= False;
676 Zero_Cost_Exceptions_Specified
:= False;
679 ---------------------------------------
680 -- Invocation_Construct_Kind_To_Code --
681 ---------------------------------------
683 function Invocation_Construct_Kind_To_Code
684 (Kind
: Invocation_Construct_Kind
) return Character
687 return Invocation_Construct_Codes
(Kind
);
688 end Invocation_Construct_Kind_To_Code
;
690 -------------------------------
691 -- Invocation_Graph_Encoding --
692 -------------------------------
694 function Invocation_Graph_Encoding
return Invocation_Graph_Encoding_Kind
is
696 return Compile_Time_Invocation_Graph_Encoding
;
697 end Invocation_Graph_Encoding
;
699 --------------------------------------------
700 -- Invocation_Graph_Encoding_Kind_To_Code --
701 --------------------------------------------
703 function Invocation_Graph_Encoding_Kind_To_Code
704 (Kind
: Invocation_Graph_Encoding_Kind
) return Character
707 return Invocation_Graph_Encoding_Codes
(Kind
);
708 end Invocation_Graph_Encoding_Kind_To_Code
;
710 ----------------------------------------
711 -- Invocation_Graph_Line_Kind_To_Code --
712 ----------------------------------------
714 function Invocation_Graph_Line_Kind_To_Code
715 (Kind
: Invocation_Graph_Line_Kind
) return Character
718 return Invocation_Graph_Line_Codes
(Kind
);
719 end Invocation_Graph_Line_Kind_To_Code
;
721 -----------------------------
722 -- Invocation_Kind_To_Code --
723 -----------------------------
725 function Invocation_Kind_To_Code
726 (Kind
: Invocation_Kind
) return Character
729 return Invocation_Codes
(Kind
);
730 end Invocation_Kind_To_Code
;
732 -----------------------------
733 -- Invocation_Signature_Of --
734 -----------------------------
736 function Invocation_Signature_Of
741 Scope
: Name_Id
) return Invocation_Signature_Id
743 IS_Rec
: constant Invocation_Signature_Record
:=
746 Locations
=> Locations
,
749 IS_Id
: Invocation_Signature_Id
;
752 IS_Id
:= Sig_Map
.Get
(Sig_To_Sig_Map
, IS_Rec
);
754 -- The invocation signature lacks an id. This indicates that it
755 -- is encountered for the first time during the construction of
758 if not Present
(IS_Id
) then
759 Invocation_Signatures
.Append
(IS_Rec
);
760 IS_Id
:= Invocation_Signatures
.Last
;
762 -- Map the invocation signature record to its corresponding id
764 Sig_Map
.Put
(Sig_To_Sig_Map
, IS_Rec
, IS_Id
);
768 end Invocation_Signature_Of
;
775 (IR_Id
: Invocation_Relation_Id
) return Invocation_Signature_Id
778 pragma Assert
(Present
(IR_Id
));
779 return Invocation_Relations
.Table
(IR_Id
).Invoker
;
787 (IC_Id
: Invocation_Construct_Id
) return Invocation_Construct_Kind
790 pragma Assert
(Present
(IC_Id
));
791 return Invocation_Constructs
.Table
(IC_Id
).Kind
;
798 function Kind
(IR_Id
: Invocation_Relation_Id
) return Invocation_Kind
is
800 pragma Assert
(Present
(IR_Id
));
801 return Invocation_Relations
.Table
(IR_Id
).Kind
;
808 function Line
(IS_Id
: Invocation_Signature_Id
) return Nat
is
810 pragma Assert
(Present
(IS_Id
));
811 return Invocation_Signatures
.Table
(IS_Id
).Line
;
818 function Locations
(IS_Id
: Invocation_Signature_Id
) return Name_Id
is
820 pragma Assert
(Present
(IS_Id
));
821 return Invocation_Signatures
.Table
(IS_Id
).Locations
;
828 function Name
(IS_Id
: Invocation_Signature_Id
) return Name_Id
is
830 pragma Assert
(Present
(IS_Id
));
831 return Invocation_Signatures
.Table
(IS_Id
).Name
;
838 function Present
(IC_Id
: Invocation_Construct_Id
) return Boolean is
840 return IC_Id
/= No_Invocation_Construct
;
847 function Present
(IR_Id
: Invocation_Relation_Id
) return Boolean is
849 return IR_Id
/= No_Invocation_Relation
;
856 function Present
(IS_Id
: Invocation_Signature_Id
) return Boolean is
858 return IS_Id
/= No_Invocation_Signature
;
865 function Present
(Dep
: Sdep_Id
) return Boolean is
867 return Dep
/= No_Sdep_Id
;
874 function Present
(U_Id
: Unit_Id
) return Boolean is
876 return U_Id
/= No_Unit_Id
;
883 function Present
(W_Id
: With_Id
) return Boolean is
885 return W_Id
/= No_With_Id
;
896 Ignore_Lines
: String := "X";
897 Ignore_Errors
: Boolean := False;
898 Directly_Scanned
: Boolean := False) return ALI_Id
900 P
: Text_Ptr
:= T
'First;
901 Line
: Logical_Line_Number
:= 1;
907 Ignore
: array (Character range 'A' .. 'Z') of Boolean :=
909 -- Ignore (X) is set to True if lines starting with X are to
910 -- be ignored by Scan_ALI and skipped, and False if the lines
911 -- are to be read and processed.
913 Bad_ALI_Format
: exception;
914 -- Exception raised by Fatal_Error if Err is True
916 function At_Eol
return Boolean;
917 -- Test if at end of line
919 function At_End_Of_Field
return Boolean;
920 -- Test if at end of line, or if at blank or horizontal tab
922 procedure Check_At_End_Of_Field
;
923 -- Check if we are at end of field, fatal error if not
925 procedure Checkc
(C
: Character);
926 -- Check next character is C. If so bump past it, if not fatal error
928 procedure Check_Unknown_Line
;
929 -- If Ignore_Errors mode, then checks C to make sure that it is not
930 -- an unknown ALI line type characters, and if so, skips lines
931 -- until the first character of the line is one of these characters,
932 -- at which point it does a Getc to put that character in C. The
933 -- call has no effect if C is already an appropriate character.
934 -- If not in Ignore_Errors mode, a fatal error is signalled if the
935 -- line is unknown. Note that if C is an EOL on entry, the line is
936 -- skipped (it is assumed that blank lines are never significant).
937 -- If C is EOF on entry, the call has no effect (it is assumed that
938 -- the caller will properly handle this case).
940 procedure Fatal_Error
;
941 -- Generate fatal error message for badly formatted ALI file if
942 -- Err is false, or raise Bad_ALI_Format if Err is True.
944 procedure Fatal_Error_Ignore
;
945 pragma Inline
(Fatal_Error_Ignore
);
946 -- In Ignore_Errors mode, has no effect, otherwise same as Fatal_Error
948 function Getc
return Character;
949 -- Get next character, bumping P past the character obtained
951 function Get_File_Name
952 (Lower
: Boolean := False;
953 May_Be_Quoted
: Boolean := False) return File_Name_Type
;
954 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
955 -- with length in Name_Len, as well as returning a File_Name_Type value.
956 -- If May_Be_Quoted is True and the first non blank character is '"',
957 -- then remove starting and ending quotes and undoubled internal quotes.
958 -- If lower is false, the case is unchanged, if Lower is True then the
959 -- result is forced to all lower case for systems where file names are
960 -- not case sensitive. This ensures that gnatbind works correctly
961 -- regardless of the case of the file name on all systems. The scan
962 -- is terminated by a end of line, space or horizontal tab. Any other
963 -- special characters are included in the returned name.
966 (Ignore_Special
: Boolean := False;
967 May_Be_Quoted
: Boolean := False) return Name_Id
;
968 -- Skip blanks, then scan out a name (name is left in Name_Buffer with
969 -- length in Name_Len, as well as being returned in Name_Id form).
970 -- If Lower is set to True then the Name_Buffer will be converted to
971 -- all lower case, for systems where file names are not case sensitive.
972 -- This ensures that gnatbind works correctly regardless of the case
973 -- of the file name on all systems.
975 -- The scan is terminated by the normal end of field condition
976 -- (EOL, space, horizontal tab). Furthermore, the termination condition
977 -- depends on the setting of Ignore_Special:
979 -- If Ignore_Special is False (normal case), the scan is terminated by
980 -- a typeref bracket or an equal sign except for the special case of
981 -- an operator name starting with a double quote that is terminated
982 -- by another double quote.
984 -- If May_Be_Quoted is True and the first non blank character is '"'
985 -- the name is 'unquoted'. In this case Ignore_Special is ignored and
986 -- assumed to be True.
988 -- This function handles wide characters properly.
990 function Get_Nat
return Nat
;
991 -- Skip blanks, then scan out an unsigned integer value in Nat range
992 -- raises ALI_Reading_Error if the encoutered type is not natural.
994 function Get_Stamp
return Time_Stamp_Type
;
995 -- Skip blanks, then scan out a time stamp
997 function Get_Unit_Name
return Unit_Name_Type
;
998 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
999 -- with length in Name_Len, as well as returning a Unit_Name_Type value.
1000 -- The case is unchanged and terminated by a normal end of field.
1002 function Nextc
return Character;
1003 -- Return current character without modifying pointer P
1005 procedure Scan_Invocation_Graph_Line
;
1006 -- Parse a single line that encodes a piece of the invocation graph
1009 -- Skip past spaces, then skip past end of line (fatal error if not
1010 -- at end of line). Also skips past any following blank lines.
1012 procedure Skip_Line
;
1013 -- Skip rest of current line and any following blank lines
1015 procedure Skip_Space
;
1016 -- Skip past white space (blanks or horizontal tab)
1019 -- Skip past next character, does not affect value in C. This call
1020 -- is like calling Getc and ignoring the returned result.
1022 ---------------------
1023 -- At_End_Of_Field --
1024 ---------------------
1026 function At_End_Of_Field
return Boolean is
1028 return Nextc
<= ' ';
1029 end At_End_Of_Field
;
1035 function At_Eol
return Boolean is
1037 return Nextc
= EOF
or else Nextc
= CR
or else Nextc
= LF
;
1040 ---------------------------
1041 -- Check_At_End_Of_Field --
1042 ---------------------------
1044 procedure Check_At_End_Of_Field
is
1046 if not At_End_Of_Field
then
1047 if Ignore_Errors
then
1048 while Nextc
> ' ' loop
1055 end Check_At_End_Of_Field
;
1057 ------------------------
1058 -- Check_Unknown_Line --
1059 ------------------------
1061 procedure Check_Unknown_Line
is
1063 while C
not in 'A' .. 'Z'
1064 or else not Known_ALI_Lines
(C
)
1066 if C
= CR
or else C
= LF
then
1073 elsif Ignore_Errors
then
1081 end Check_Unknown_Line
;
1087 procedure Checkc
(C
: Character) is
1091 elsif Ignore_Errors
then
1102 procedure Fatal_Error
is
1107 procedure Wchar
(C
: Character);
1108 -- Write a single character, replacing horizontal tab by spaces
1110 procedure Wchar
(C
: Character) is
1115 exit when Col
mod 8 = 0;
1124 -- Start of processing for Fatal_Error
1128 raise Bad_ALI_Format
;
1132 Write_Str
("fatal error: file ");
1134 Write_Str
(" is incorrectly formatted");
1137 Write_Str
("make sure you are using consistent versions " &
1139 -- Split the following line so that it can easily be transformed for
1140 -- other back-ends where the compiler might have a different name.
1146 -- Find start of line
1149 while Ptr1
> T
'First
1150 and then T
(Ptr1
- 1) /= CR
1151 and then T
(Ptr1
- 1) /= LF
1156 Write_Int
(Int
(Line
));
1171 and then T
(Ptr2
) /= CR
1172 and then T
(Ptr2
) /= LF
1184 if T
(Ptr1
) = HT
then
1196 Exit_Program
(E_Fatal
);
1199 ------------------------
1200 -- Fatal_Error_Ignore --
1201 ------------------------
1203 procedure Fatal_Error_Ignore
is
1205 if not Ignore_Errors
then
1208 end Fatal_Error_Ignore
;
1214 function Get_File_Name
1215 (Lower
: Boolean := False;
1216 May_Be_Quoted
: Boolean := False) return File_Name_Type
1221 F
:= Get_Name
(Ignore_Special
=> True,
1222 May_Be_Quoted
=> May_Be_Quoted
);
1224 -- Convert file name to all lower case if file names are not case
1225 -- sensitive. This ensures that we handle names in the canonical
1226 -- lower case format, regardless of the actual case.
1228 if Lower
and not File_Names_Case_Sensitive
then
1229 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
1232 return File_Name_Type
(F
);
1241 (Ignore_Special
: Boolean := False;
1242 May_Be_Quoted
: Boolean := False) return Name_Id
1251 if Ignore_Errors
then
1260 -- Deal with quoted characters
1262 if May_Be_Quoted
and then Char
= '"' then
1265 if Ignore_Errors
then
1288 Add_Char_To_Name_Buffer
(Char
);
1291 -- Other than case of quoted character
1296 Add_Char_To_Name_Buffer
(Getc
);
1298 exit when At_End_Of_Field
;
1300 if not Ignore_Special
then
1301 if Name_Buffer
(1) = '"' then
1302 exit when Name_Len
> 1
1303 and then Name_Buffer
(Name_Len
) = '"';
1306 -- Terminate on parens or angle brackets or equal sign
1308 exit when Nextc
= '(' or else Nextc
= ')'
1309 or else Nextc
= '{' or else Nextc
= '}'
1310 or else Nextc
= '<' or else Nextc
= '>'
1311 or else Nextc
= '=';
1313 -- Terminate on comma
1315 exit when Nextc
= ',';
1317 -- Terminate if left bracket not part of wide char
1320 exit when Nextc
= '[' and then T
(P
+ 1) /= '"';
1322 -- Terminate if right bracket not part of wide char
1325 exit when Nextc
= ']' and then T
(P
- 1) /= '"';
1338 function Get_Unit_Name
return Unit_Name_Type
is
1340 return Unit_Name_Type
(Get_Name
);
1347 function Get_Nat
return Nat
is
1353 -- Check if we are on a number. In the case of bad ALI files, this
1356 if not (Nextc
in '0' .. '9') then
1362 V
:= V
* 10 + (Character'Pos (Getc
) - Character'Pos ('0'));
1364 exit when At_End_Of_Field
;
1365 exit when Nextc
< '0' or else Nextc
> '9';
1375 function Get_Stamp
return Time_Stamp_Type
is
1376 T
: Time_Stamp_Type
;
1383 if Ignore_Errors
then
1384 return Dummy_Time_Stamp
;
1390 -- Following reads old style time stamp missing first two digits
1392 if Nextc
in '7' .. '9' then
1397 -- Normal case of full year in time stamp
1403 for J
in Start
.. T
'Last loop
1414 function Getc
return Character is
1428 function Nextc
return Character is
1433 --------------------------------
1434 -- Scan_Invocation_Graph_Line --
1435 --------------------------------
1437 procedure Scan_Invocation_Graph_Line
is
1438 procedure Scan_Invocation_Construct_Line
;
1439 pragma Inline
(Scan_Invocation_Construct_Line
);
1440 -- Parse an invocation construct line and construct the corresponding
1441 -- construct. The following data structures are updated:
1443 -- * Invocation_Constructs
1446 procedure Scan_Invocation_Graph_Attributes_Line
;
1447 pragma Inline
(Scan_Invocation_Graph_Attributes_Line
);
1448 -- Parse an invocation-graph attributes line. The following data
1449 -- structures are updated:
1453 procedure Scan_Invocation_Relation_Line
;
1454 pragma Inline
(Scan_Invocation_Relation_Line
);
1455 -- Parse an invocation relation line and construct the corresponding
1456 -- relation. The following data structures are updated:
1458 -- * Invocation_Relations
1461 function Scan_Invocation_Signature
return Invocation_Signature_Id
;
1462 pragma Inline
(Scan_Invocation_Signature
);
1463 -- Parse a single invocation signature while populating the following
1466 -- * Invocation_Signatures
1469 ------------------------------------
1470 -- Scan_Invocation_Construct_Line --
1471 ------------------------------------
1473 procedure Scan_Invocation_Construct_Line
is
1474 Body_Placement
: Declaration_Placement_Kind
;
1475 Kind
: Invocation_Construct_Kind
;
1476 Signature
: Invocation_Signature_Id
;
1477 Spec_Placement
: Declaration_Placement_Kind
;
1482 Kind
:= Code_To_Invocation_Construct_Kind
(Getc
);
1486 -- construct-spec-placement
1488 Spec_Placement
:= Code_To_Declaration_Placement_Kind
(Getc
);
1492 -- construct-body-placement
1494 Body_Placement
:= Code_To_Declaration_Placement_Kind
(Getc
);
1498 -- construct-signature
1500 Signature
:= Scan_Invocation_Signature
;
1503 Add_Invocation_Construct
1504 (Body_Placement
=> Body_Placement
,
1506 Signature
=> Signature
,
1507 Spec_Placement
=> Spec_Placement
);
1508 end Scan_Invocation_Construct_Line
;
1510 -------------------------------------------
1511 -- Scan_Invocation_Graph_Attributes_Line --
1512 -------------------------------------------
1514 procedure Scan_Invocation_Graph_Attributes_Line
is
1518 Set_Invocation_Graph_Encoding
1519 (Code_To_Invocation_Graph_Encoding_Kind
(Getc
));
1521 end Scan_Invocation_Graph_Attributes_Line
;
1523 -----------------------------------
1524 -- Scan_Invocation_Relation_Line --
1525 -----------------------------------
1527 procedure Scan_Invocation_Relation_Line
is
1529 Invoker
: Invocation_Signature_Id
;
1530 Kind
: Invocation_Kind
;
1531 Target
: Invocation_Signature_Id
;
1536 Kind
:= Code_To_Invocation_Kind
(Getc
);
1540 -- (extra-name | "none")
1544 if Extra
= Name_None
then
1551 -- invoker-signature
1553 Invoker
:= Scan_Invocation_Signature
;
1559 Target
:= Scan_Invocation_Signature
;
1562 Add_Invocation_Relation
1567 end Scan_Invocation_Relation_Line
;
1569 -------------------------------
1570 -- Scan_Invocation_Signature --
1571 -------------------------------
1573 function Scan_Invocation_Signature
return Invocation_Signature_Id
is
1576 Locations
: Name_Id
;
1609 -- (locations | "none")
1611 Locations
:= Get_Name
;
1613 if Locations
= Name_None
then
1614 Locations
:= No_Name
;
1621 -- Create an invocation signature from the scanned attributes
1624 Invocation_Signature_Of
1627 Locations
=> Locations
,
1630 end Scan_Invocation_Signature
;
1634 Line
: Invocation_Graph_Line_Kind
;
1636 -- Start of processing for Scan_Invocation_Graph_Line
1639 if Ignore
('G') then
1648 Line
:= Code_To_Invocation_Graph_Line_Kind
(Getc
);
1655 when Invocation_Construct_Line
=>
1656 Scan_Invocation_Construct_Line
;
1658 when Invocation_Graph_Attributes_Line
=>
1659 Scan_Invocation_Graph_Attributes_Line
;
1661 when Invocation_Relation_Line
=>
1662 Scan_Invocation_Relation_Line
;
1664 end Scan_Invocation_Graph_Line
;
1670 procedure Skip_Eol
is
1675 if Ignore_Errors
then
1676 while not At_Eol
loop
1684 -- Loop to skip past blank lines (first time through skips this EOL)
1686 while Nextc
< ' ' and then Nextc
/= EOF
loop
1699 procedure Skip_Line
is
1701 while not At_Eol
loop
1712 procedure Skip_Space
is
1714 while Nextc
= ' ' or else Nextc
= HT
loop
1730 -- Start of processing for Scan_ALI
1733 First_Sdep_Entry
:= Sdep
.Last
+ 1;
1735 for J
in Ignore_Lines
'Range loop
1736 pragma Assert
(Ignore_Lines
(J
) /= 'U');
1737 Ignore
(Ignore_Lines
(J
)) := True;
1740 -- Setup ALI Table entry with appropriate defaults
1742 ALIs
.Increment_Last
;
1744 Set_Name_Table_Int
(F
, Int
(Id
));
1746 ALIs
.Table
(Id
) := (
1748 Compile_Errors
=> False,
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 Invocation_Graph_Encoding
=> No_Encoding
,
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 Frontend_Exceptions
=> False,
1780 Zero_Cost_Exceptions
=> False);
1782 -- Now we acquire the input lines from the ALI file. Note that the
1783 -- convention in the following code is that as we enter each section,
1784 -- C is set to contain the first character of the following line.
1789 -- Acquire library version
1793 -- The V line missing really indicates trouble, most likely it
1794 -- means we don't have an ALI file at all, so here we give a
1795 -- fatal error even if we are in Ignore_Errors mode.
1799 elsif Ignore
('V') then
1807 for J
in 1 .. Ver_Len_Max
loop
1810 ALIs
.Table
(Id
).Ver
(J
) := C
;
1811 ALIs
.Table
(Id
).Ver_Len
:= J
;
1820 -- Acquire main program line if present
1823 if Ignore
('M') then
1833 ALIs
.Table
(Id
).Main_Program
:= Func
;
1835 ALIs
.Table
(Id
).Main_Program
:= Proc
;
1845 ALIs
.Table
(Id
).Main_Priority
:= Get_Nat
;
1853 ALIs
.Table
(Id
).Time_Slice_Value
:= Get_Nat
;
1861 ALIs
.Table
(Id
).Main_CPU
:= Get_Nat
;
1868 ALIs
.Table
(Id
).WC_Encoding
:= Getc
;
1877 -- Acquire argument lines
1879 First_Arg
:= Args
.Last
+ 1;
1883 exit A_Loop
when C
/= 'A';
1885 if Ignore
('A') then
1891 -- Scan out argument
1894 while not At_Eol
loop
1895 Add_Char_To_Name_Buffer
(Getc
);
1898 -- If -fstack-check, record that it occurred. Note that an
1899 -- additional string parameter can be specified, in the form of
1900 -- -fstack-check={no|generic|specific}. "no" means no checking,
1901 -- "generic" means force the use of old-style checking, and
1902 -- "specific" means use the best checking method.
1905 and then Name_Buffer
(1 .. 13) = "-fstack-check"
1906 and then Name_Buffer
(1 .. Name_Len
) /= "-fstack-check=no"
1908 Stack_Check_Switch_Set
:= True;
1911 -- Store the argument
1913 Args
.Increment_Last
;
1914 Args
.Table
(Args
.Last
) := new String'(Name_Buffer (1 .. Name_Len));
1927 if Ignore_Errors then
1939 if Ignore ('P
') then
1947 while not At_Eol loop
1952 -- Processing for CE
1956 ALIs.Table (Id).Compile_Errors := True;
1958 -- Processing for DB
1962 Detect_Blocking := True;
1964 -- Processing for Ex
1967 Partition_Elaboration_Policy_Specified := Getc;
1968 ALIs.Table (Id).Partition_Elaboration_Policy :=
1969 Partition_Elaboration_Policy_Specified;
1971 -- Processing for FX
1977 ALIs.Table (Id).Frontend_Exceptions := True;
1978 Frontend_Exceptions_Specified := True;
1983 -- Processing for GP
1987 GNATprove_Mode_Specified := True;
1988 ALIs.Table (Id).GNATprove_Mode := True;
1990 -- Processing for Lx
1993 Locking_Policy_Specified := Getc;
1994 ALIs.Table (Id).Locking_Policy := Locking_Policy_Specified;
1996 -- Processing for flags starting with N
2001 -- Processing for NC
2004 ALIs.Table (Id).No_Component_Reordering := True;
2005 No_Component_Reordering_Specified := True;
2007 -- Processing for NO
2010 ALIs.Table (Id).No_Object := True;
2011 No_Object_Specified := True;
2013 -- Processing for NR
2016 No_Run_Time_Mode := True;
2017 Configurable_Run_Time_Mode := True;
2019 -- Processing for NS
2022 ALIs.Table (Id).Normalize_Scalars := True;
2023 Normalize_Scalars_Specified := True;
2026 -- Invalid switch starting with N
2032 -- Processing for OH/OL
2037 if C = 'L
' or else C = 'H
' then
2038 ALIs.Table (Id).SSO_Default := C;
2039 SSO_Default_Specified := True;
2045 -- Processing for Qx
2048 Queuing_Policy_Specified := Getc;
2049 ALIs.Table (Id).Queuing_Policy := Queuing_Policy_Specified;
2051 -- Processing for flags starting with S
2056 -- Processing for SL
2059 ALIs.Table (Id).SAL_Interface := True;
2061 -- Processing for SS
2064 Opt.Sec_Stack_Used := True;
2066 -- Invalid switch starting with S
2072 -- Processing for Tx
2075 Task_Dispatching_Policy_Specified := Getc;
2076 ALIs.Table (Id).Task_Dispatching_Policy :=
2077 Task_Dispatching_Policy_Specified;
2079 -- Processing for switch starting with U
2084 -- Processing for UA
2087 Unreserve_All_Interrupts_Specified := True;
2089 -- Processing for UX
2092 ALIs.Table (Id).Unit_Exception_Table := True;
2094 -- Invalid switches starting with U
2100 -- Processing for ZX
2106 ALIs.Table (Id).Zero_Cost_Exceptions := True;
2107 Zero_Cost_Exceptions_Specified := True;
2112 -- Invalid parameter
2120 if not NS_Found then
2121 No_Normalize_Scalars_Specified := True;
2130 -- Loop to skip to first restrictions line
2133 if Ignore_Errors then
2145 -- Ignore all 'R
' lines if that is required
2147 if Ignore ('R
') then
2153 -- Here we process the restrictions lines (other than unit name cases)
2156 Scan_Restrictions : declare
2157 Save_R : constant Restrictions_Info := Cumulative_Restrictions;
2158 -- Save cumulative restrictions in case we have a fatal error
2160 Bad_R_Line : exception;
2161 -- Signal bad restrictions line (raised on unexpected character)
2168 -- Named restriction case
2174 -- Loop through RR and RV lines
2176 while C = 'R
' and then Nextc /= ' ' loop
2180 -- Acquire restriction name
2183 while not At_Eol and then Nextc /= '=' loop
2184 Name_Len := Name_Len + 1;
2185 Name_Buffer (Name_Len) := Getc;
2188 -- Now search list of restrictions to find match
2191 RN : String renames Name_Buffer (1 .. Name_Len);
2194 R := Restriction_Id'First;
2195 while R /= Not_A_Restriction_Id loop
2196 if Restriction_Id'Image (R) = RN then
2200 R := Restriction_Id'Succ (R);
2203 -- We don't recognize the restriction. This might be
2204 -- thought of as an error, and it really is, but we
2205 -- want to allow building with inconsistent versions
2206 -- of the binder and ali files (see comments at the
2207 -- start of package System.Rident), so we just ignore
2210 goto Done_With_Restriction_Line;
2217 -- Boolean restriction case
2219 when All_Boolean_Restrictions =>
2222 ALIs.Table (Id).Restrictions.Violated (R) :=
2224 Cumulative_Restrictions.Violated (R) := True;
2227 ALIs.Table (Id).Restrictions.Set (R) := True;
2228 Cumulative_Restrictions.Set (R) := True;
2234 -- Parameter restriction case
2236 when All_Parameter_Restrictions =>
2237 if At_Eol or else Nextc /= '=' then
2243 N := Natural (Get_Nat);
2250 ALIs.Table (Id).Restrictions.Set (R) := True;
2251 ALIs.Table (Id).Restrictions.Value (R) := N;
2253 if Cumulative_Restrictions.Set (R) then
2254 Cumulative_Restrictions.Value (R) :=
2256 (Cumulative_Restrictions.Value (R), N);
2258 Cumulative_Restrictions.Set (R) := True;
2259 Cumulative_Restrictions.Value (R) := N;
2262 -- Restriction violated
2265 ALIs.Table (Id).Restrictions.Violated (R) :=
2267 Cumulative_Restrictions.Violated (R) := True;
2268 ALIs.Table (Id).Restrictions.Count (R) := N;
2270 -- Checked Max_Parameter case
2272 if R in Checked_Max_Parameter_Restrictions then
2273 Cumulative_Restrictions.Count (R) :=
2275 (Cumulative_Restrictions.Count (R), N);
2277 -- Other checked parameter cases
2281 pragma Unsuppress (Overflow_Check);
2284 Cumulative_Restrictions.Count (R) :=
2285 Cumulative_Restrictions.Count (R) + N;
2288 when Constraint_Error =>
2290 -- A constraint error comes from the
2291 -- addition. We reset to the maximum
2292 -- and indicate that the real value
2295 Cumulative_Restrictions.Value (R) :=
2297 Cumulative_Restrictions.Unknown (R) :=
2306 ALIs.Table (Id).Restrictions.Unknown (R) :=
2308 Cumulative_Restrictions.Unknown (R) := True;
2311 -- Other than 'R
' or 'V
'
2321 -- Bizarre error case NOT_A_RESTRICTION
2323 when Not_A_Restriction_Id =>
2331 <<Done_With_Restriction_Line>>
2336 -- Positional restriction case
2342 -- Acquire information for boolean restrictions
2344 for R in All_Boolean_Restrictions loop
2349 ALIs.Table (Id).Restrictions.Violated (R) := True;
2350 Cumulative_Restrictions.Violated (R) := True;
2353 ALIs.Table (Id).Restrictions.Set (R) := True;
2354 Cumulative_Restrictions.Set (R) := True;
2364 -- Acquire information for parameter restrictions
2366 for RP in All_Parameter_Restrictions loop
2372 ALIs.Table (Id).Restrictions.Set (RP) := True;
2375 N : constant Integer := Integer (Get_Nat);
2377 ALIs.Table (Id).Restrictions.Value (RP) := N;
2379 if Cumulative_Restrictions.Set (RP) then
2380 Cumulative_Restrictions.Value (RP) :=
2382 (Cumulative_Restrictions.Value (RP), N);
2384 Cumulative_Restrictions.Set (RP) := True;
2385 Cumulative_Restrictions.Value (RP) := N;
2393 -- Acquire restrictions violations information
2401 ALIs.Table (Id).Restrictions.Violated (RP) := True;
2402 Cumulative_Restrictions.Violated (RP) := True;
2405 N : constant Integer := Integer (Get_Nat);
2408 ALIs.Table (Id).Restrictions.Count (RP) := N;
2410 if RP in Checked_Max_Parameter_Restrictions then
2411 Cumulative_Restrictions.Count (RP) :=
2413 (Cumulative_Restrictions.Count (RP), N);
2417 pragma Unsuppress (Overflow_Check);
2420 Cumulative_Restrictions.Count (RP) :=
2421 Cumulative_Restrictions.Count (RP) + N;
2424 when Constraint_Error =>
2426 -- A constraint error comes from the add. We
2427 -- reset to the maximum and indicate that the
2428 -- real value is now unknown.
2430 Cumulative_Restrictions.Value (RP) :=
2432 Cumulative_Restrictions.Unknown (RP) := True;
2438 ALIs.Table (Id).Restrictions.Unknown (RP) := True;
2439 Cumulative_Restrictions.Unknown (RP) := True;
2456 -- Here if error during scanning of restrictions line
2461 -- In Ignore_Errors mode, undo any changes to restrictions
2462 -- from this unit, and continue on, skipping remaining R
2463 -- lines for this unit.
2465 if Ignore_Errors then
2466 Cumulative_Restrictions := Save_R;
2467 ALIs.Table (Id).Restrictions := No_Restrictions;
2475 -- In normal mode, this is a fatal error
2480 end Scan_Restrictions;
2483 -- Acquire additional restrictions (No_Dependence) lines if present
2486 if Ignore ('R
') then
2490 No_Deps.Append ((Id, Get_Name));
2497 -- Acquire 'I
' lines if present
2502 if Ignore ('I
') then
2508 I_State : Character;
2517 Interrupt_States.Append (
2518 (Interrupt_Id => Int_Num,
2519 Interrupt_State => I_State,
2520 IS_Pragma_Line => Line_No));
2522 ALIs.Table (Id).Last_Interrupt_State := Interrupt_States.Last;
2530 -- Acquire 'S
' lines if present
2535 if Ignore ('S
') then
2551 First_Prio := Get_Nat;
2552 Last_Prio := Get_Nat;
2555 Specific_Dispatching.Append (
2556 (Dispatching_Policy => Policy,
2557 First_Priority => First_Prio,
2558 Last_Priority => Last_Prio,
2559 PSD_Pragma_Line => Line_No));
2561 ALIs.Table (Id).Last_Specific_Dispatching :=
2562 Specific_Dispatching.Last;
2571 -- Loop to acquire unit entries
2575 exit U_Loop when C /= 'U
';
2577 -- Note: as per spec, we never ignore U lines
2581 Units.Increment_Last;
2583 if ALIs.Table (Id).First_Unit = No_Unit_Id then
2584 ALIs.Table (Id).First_Unit := Units.Last;
2588 UL : Unit_Record renames Units.Table (Units.Last);
2591 UL.Uname := Get_Unit_Name;
2592 UL.Predefined := Is_Predefined_Unit;
2593 UL.Internal := Is_Internal_Unit;
2595 UL.Sfile := Get_File_Name (Lower => True);
2597 UL.Preelab := False;
2598 UL.No_Elab := False;
2599 UL.Shared_Passive := False;
2601 UL.Remote_Types := False;
2602 UL.Serious_Errors := False;
2603 UL.Has_RACW := False;
2604 UL.Init_Scalars := False;
2605 UL.Is_Generic := False;
2606 UL.Icasing := Mixed_Case;
2607 UL.Kcasing := All_Lower_Case;
2608 UL.Dynamic_Elab := False;
2609 UL.Elaborate_Body := False;
2610 UL.Set_Elab_Entity := False;
2611 UL.Version := "00000000";
2612 UL.First_With := Withs.Last + 1;
2613 UL.First_Arg := First_Arg;
2614 UL.First_Invocation_Construct := Invocation_Constructs.Last + 1;
2615 UL.Last_Invocation_Construct := No_Invocation_Construct;
2616 UL.First_Invocation_Relation := Invocation_Relations.Last + 1;
2617 UL.Last_Invocation_Relation := No_Invocation_Relation;
2618 UL.Elab_Position := 0;
2619 UL.SAL_Interface := ALIs.Table (Id).SAL_Interface;
2620 UL.Directly_Scanned := Directly_Scanned;
2621 UL.Body_Needed_For_SAL := False;
2622 UL.Elaborate_Body_Desirable := False;
2623 UL.Optimize_Alignment := 'O
';
2624 UL.Has_Finalizer := False;
2625 UL.Primary_Stack_Count := 0;
2626 UL.Sec_Stack_Count := 0;
2628 if Debug_Flag_U then
2629 Write_Str (" ----> reading unit ");
2630 Write_Int (Int (Units.Last));
2632 Write_Unit_Name (UL.Uname);
2633 Write_Str (" from file ");
2634 Write_Name (UL.Sfile);
2639 -- Check for duplicated unit in different files
2642 Info : constant Int := Get_Name_Table_Int
2643 (Units.Table (Units.Last).Uname);
2646 and then Units.Table (Units.Last).Sfile /=
2647 Units.Table (Unit_Id (Info)).Sfile
2649 -- If Err is set then ignore duplicate unit name. This is the
2650 -- case of a call from gnatmake, where the situation can arise
2651 -- from substitution of source files. In such situations, the
2652 -- processing in gnatmake will always result in any required
2653 -- recompilations in any case, and if we consider this to be
2654 -- an error we get strange cases (for example when a generic
2655 -- instantiation is replaced by a normal package) where we
2656 -- read the old ali file, decide to recompile, and then decide
2657 -- that the old and new ali files are incompatible.
2662 -- If Err is not set, then this is a fatal error. This is
2663 -- the case of being called from the binder, where we must
2664 -- definitely diagnose this as an error.
2668 Write_Str ("error: duplicate unit name: ");
2671 Write_Str ("error: unit """);
2672 Write_Unit_Name (Units.Table (Units.Last).Uname);
2673 Write_Str (""" found in file """);
2674 Write_Name_Decoded (Units.Table (Units.Last).Sfile);
2678 Write_Str ("error
: unit
""");
2679 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
2680 Write_Str (""" found
in file
""");
2681 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
2685 Exit_Program (E_Fatal);
2691 (Units.Table (Units.Last).Uname, Int (Units.Last));
2693 -- Scan out possible version and other parameters
2702 if C in '0' .. '9' or else C in 'a
' .. 'f
' then
2703 Units.Table (Units.Last).Version (1) := C;
2705 for J in 2 .. 8 loop
2707 Units.Table (Units.Last).Version (J) := C;
2716 Check_At_End_Of_Field;
2717 Units.Table (Units.Last).Elaborate_Body_Desirable := True;
2720 Check_At_End_Of_Field;
2721 Units.Table (Units.Last).Body_Needed_For_SAL := True;
2727 -- DE parameter (Dynamic elaboration checks)
2733 Check_At_End_Of_Field;
2734 Units.Table (Units.Last).Dynamic_Elab := True;
2735 Dynamic_Elaboration_Checks_Specified := True;
2746 Units.Table (Units.Last).Elaborate_Body := True;
2748 Units.Table (Units.Last).Set_Elab_Entity := True;
2753 Check_At_End_Of_Field;
2755 -- GE parameter (generic)
2761 Check_At_End_Of_Field;
2762 Units.Table (Units.Last).Is_Generic := True;
2767 -- IL/IS/IU parameters
2773 Units.Table (Units.Last).Icasing := All_Lower_Case;
2775 Units.Table (Units.Last).Init_Scalars := True;
2776 Initialize_Scalars_Used := True;
2778 Units.Table (Units.Last).Icasing := All_Upper_Case;
2783 Check_At_End_Of_Field;
2791 Units.Table (Units.Last).Kcasing := Mixed_Case;
2793 Units.Table (Units.Last).Kcasing := All_Upper_Case;
2798 Check_At_End_Of_Field;
2806 Units.Table (Units.Last).No_Elab := True;
2807 Check_At_End_Of_Field;
2812 -- PF/PR/PU/PK parameters
2818 Units.Table (Units.Last).Has_Finalizer := True;
2820 Units.Table (Units.Last).Preelab := True;
2822 Units.Table (Units.Last).Pure := True;
2824 Units.Table (Units.Last).Unit_Kind := 'p
';
2829 Check_At_End_Of_Field;
2831 -- OL/OO/OS/OT parameters
2836 if C = 'L
' or else C = 'O
' or else C = 'S
' or else C = 'T
' then
2837 Units.Table (Units.Last).Optimize_Alignment := C;
2842 Check_At_End_Of_Field;
2850 Units.Table (Units.Last).RCI := True;
2852 Units.Table (Units.Last).Remote_Types := True;
2854 Units.Table (Units.Last).Has_RACW := True;
2859 Check_At_End_Of_Field;
2861 -- SE/SP/SU parameters
2867 Units.Table (Units.Last).Serious_Errors := True;
2869 Units.Table (Units.Last).Shared_Passive := True;
2871 Units.Table (Units.Last).Unit_Kind := 's
';
2876 Check_At_End_Of_Field;
2888 -- Scan out With lines for this unit
2892 exit With_Loop when C /= 'W
' and then C /= 'Y
' and then C /= 'Z
';
2894 if Ignore ('W
') then
2900 Withs.Increment_Last;
2901 Withs.Table (Withs.Last).Uname := Get_Unit_Name;
2902 Withs.Table (Withs.Last).Elaborate := False;
2903 Withs.Table (Withs.Last).Elaborate_All := False;
2904 Withs.Table (Withs.Last).Elab_Desirable := False;
2905 Withs.Table (Withs.Last).Elab_All_Desirable := False;
2906 Withs.Table (Withs.Last).SAL_Interface := False;
2907 Withs.Table (Withs.Last).Limited_With := (C = 'Y
');
2908 Withs.Table (Withs.Last).Implicit_With := (C = 'Z
');
2910 -- Generic case with no object file available
2913 Withs.Table (Withs.Last).Sfile := No_File;
2914 Withs.Table (Withs.Last).Afile := No_File;
2919 Withs.Table (Withs.Last).Sfile := Get_File_Name
2921 Withs.Table (Withs.Last).Afile := Get_File_Name
2924 -- Scan out possible E, EA, ED, and AD parameters
2926 while not At_Eol loop
2932 Check_At_End_Of_Field;
2934 -- Store AD indication unless ignore required
2936 Withs.Table (Withs.Last).Elab_All_Desirable := True;
2938 elsif Nextc = 'E
' then
2941 if At_End_Of_Field then
2942 Withs.Table (Withs.Last).Elaborate := True;
2944 elsif Nextc = 'A
' then
2946 Check_At_End_Of_Field;
2947 Withs.Table (Withs.Last).Elaborate_All := True;
2951 Check_At_End_Of_Field;
2953 -- Store ED indication
2955 Withs.Table (Withs.Last).Elab_Desirable := True;
2970 Units.Table (Units.Last).Last_With := Withs.Last;
2971 Units.Table (Units.Last).Last_Arg := Args.Last;
2973 -- Scan out task stack information for the unit if present
2978 if Ignore ('T
') then
2985 Units.Table (Units.Last).Primary_Stack_Count := Get_Nat;
2987 Units.Table (Units.Last).Sec_Stack_Count := Get_Nat;
2995 -- If there are linker options lines present, scan them
2999 Linker_Options_Loop : loop
3001 exit Linker_Options_Loop when C /= 'L
';
3003 if Ignore ('L
') then
3014 if C < Character'Val (16#20#)
3015 or else C > Character'Val (16#7E#)
3020 C := Character'Val (0);
3027 for J in 1 .. 2 loop
3030 if C in '0' .. '9' then
3033 Character'Pos ('0');
3035 elsif C in 'A' .. 'F' then
3038 Character'Pos ('A') +
3047 Add_Char_To_Name_Buffer (Character'Val (V));
3052 exit when Nextc /= '"';
3056 Add_Char_To_Name_Buffer (C);
3060 Add_Char_To_Name_Buffer (NUL);
3065 end loop Linker_Options_Loop;
3067 -- Store the linker options entry if one was found
3069 if Name_Len /= 0 then
3070 Linker_Options.Increment_Last;
3072 Linker_Options.Table (Linker_Options.Last).Name :=
3075 Linker_Options.Table (Linker_Options.Last).Unit :=
3078 Linker_Options.Table (Linker_Options.Last).Internal_File :=
3079 Is_Internal_File_Name (F);
3082 -- If there are notes present, scan them
3086 exit Notes_Loop when C /= 'N';
3088 if Ignore ('N') then
3094 Notes.Increment_Last;
3095 Notes.Table (Notes.Last).Pragma_Type := Getc;
3096 Notes.Table (Notes.Last).Pragma_Line := Get_Nat;
3098 Notes.Table (Notes.Last).Pragma_Col := Get_Nat;
3100 if not At_Eol and then Nextc = ':' then
3102 Notes.Table (Notes.Last).Pragma_Source_File :=
3103 Get_File_Name (Lower => True);
3105 Notes.Table (Notes.Last).Pragma_Source_File :=
3106 Units.Table (Units.Last).Sfile;
3110 Notes.Table (Notes.Last).Pragma_Args := No_Name;
3113 -- Note: can't use Get_Name here as the remainder of the
3114 -- line is unstructured text whose syntax depends on the
3115 -- particular pragma used.
3120 while not At_Eol loop
3121 Add_Char_To_Name_Buffer (Getc);
3129 end loop Notes_Loop;
3132 -- End loop through units for one ALI file
3134 ALIs.Table (Id).Last_Unit := Units.Last;
3135 ALIs.Table (Id).Sfile := Units.Table (ALIs.Table (Id).First_Unit).Sfile;
3137 -- Set types of the units (there can be at most 2 of them)
3139 if ALIs.Table (Id).First_Unit /= ALIs.Table (Id).Last_Unit then
3140 Units.Table (ALIs.Table (Id).First_Unit).Utype := Is_Body;
3141 Units.Table (ALIs.Table (Id).Last_Unit).Utype := Is_Spec;
3144 -- Deal with body only and spec only cases, note that the reason we
3145 -- do our own checking of the name (rather than using Is_Body_Name)
3146 -- is that Uname drags in far too much compiler junk.
3148 Get_Name_String (Units.Table (Units.Last).Uname);
3150 if Name_Buffer (Name_Len) = 'b' then
3151 Units.Table (Units.Last).Utype := Is_Body_Only;
3153 Units.Table (Units.Last).Utype := Is_Spec_Only;
3157 -- Scan out external version references and put in hash table
3161 exit E_Loop when C /= 'E';
3163 if Ignore ('E') then
3179 exit when At_End_Of_Field;
3180 Add_Char_To_Name_Buffer (C);
3183 Version_Ref.Set (new String'(Name_Buffer (1 .. Name_Len)), True);
3190 -- Scan out source dependency lines for this ALI file
3192 ALIs.Table (Id).First_Sdep := Sdep.Last + 1;
3196 exit D_Loop when C /= 'D';
3198 if Ignore ('D') then
3204 Sdep.Increment_Last;
3206 -- The file/path name may be quoted
3208 Sdep.Table (Sdep.Last).Sfile :=
3209 Get_File_Name (Lower => True, May_Be_Quoted => True);
3211 Sdep.Table (Sdep.Last).Stamp := Get_Stamp;
3212 Sdep.Table (Sdep.Last).Dummy_Entry :=
3213 (Sdep.Table (Sdep.Last).Stamp = Dummy_Time_Stamp);
3215 -- Acquire checksum value
3228 exit when At_Eol or else Ctr = 8;
3230 if Nextc in '0' .. '9' then
3232 Character'Pos (Nextc) - Character'Pos ('0');
3234 elsif Nextc in 'a' .. 'f' then
3236 Character'Pos (Nextc) - Character'Pos ('a') + 10;
3246 if Ctr = 8 and then At_End_Of_Field then
3247 Sdep.Table (Sdep.Last).Checksum := Chk;
3253 -- Acquire (sub)unit and reference file name entries
3255 Sdep.Table (Sdep.Last).Subunit_Name := No_Name;
3256 Sdep.Table (Sdep.Last).Unit_Name := No_Name;
3257 Sdep.Table (Sdep.Last).Rfile :=
3258 Sdep.Table (Sdep.Last).Sfile;
3259 Sdep.Table (Sdep.Last).Start_Line := 1;
3264 -- Here for (sub)unit name
3266 if Nextc not in '0' .. '9' then
3268 while not At_End_Of_Field loop
3269 Add_Char_To_Name_Buffer (Getc);
3272 -- Set the (sub)unit name. Note that we use Name_Find rather
3273 -- than Name_Enter here as the subunit name may already
3274 -- have been put in the name table by the Project Manager.
3277 or else Name_Buffer (Name_Len - 1) /= '%'
3279 Sdep.Table (Sdep.Last).Subunit_Name := Name_Find;
3281 Name_Len := Name_Len - 2;
3282 Sdep.Table (Sdep.Last).Unit_Name := Name_Find;
3288 -- Here for reference file name entry
3290 if Nextc in '0' .. '9' then
3291 Sdep.Table (Sdep.Last).Start_Line := Get_Nat;
3296 while not At_End_Of_Field loop
3297 Add_Char_To_Name_Buffer (Getc);
3300 Sdep.Table (Sdep.Last).Rfile := Name_Enter;
3310 ALIs.Table (Id).Last_Sdep := Sdep.Last;
3312 -- Loop through invocation-graph lines
3316 exit G_Loop when C /= 'G';
3318 Scan_Invocation_Graph_Line;
3323 -- We must at this stage be at an Xref line or the end of file
3335 -- This ALI parser does not care about Xref lines.
3340 when Bad_ALI_Format =>
3348 function IS_Scope (IS_Id : Invocation_Signature_Id) return Name_Id is
3350 pragma Assert (Present (IS_Id));
3351 return Invocation_Signatures.Table (IS_Id).Scope;
3358 function SEq (F1, F2 : String_Ptr) return Boolean is
3360 return F1.all = F2.all;
3363 -----------------------------------
3364 -- Set_Invocation_Graph_Encoding --
3365 -----------------------------------
3367 procedure Set_Invocation_Graph_Encoding
3368 (Kind : Invocation_Graph_Encoding_Kind;
3369 Update_Units : Boolean := True)
3372 Compile_Time_Invocation_Graph_Encoding := Kind;
3374 -- Update the invocation-graph encoding of the current unit only when
3375 -- requested by the caller.
3377 if Update_Units then
3379 Curr_Unit : Unit_Record renames Units.Table (Units.Last);
3380 Curr_ALI : ALIs_Record renames ALIs.Table (Curr_Unit.My_ALI);
3383 Curr_ALI.Invocation_Graph_Encoding := Kind;
3386 end Set_Invocation_Graph_Encoding;
3392 function SHash (S : String_Ptr) return Vindex is
3397 for J in S.all'Range loop
3398 H := H * 2 + Character'Pos (S (J));
3401 return Vindex (Vindex'First + Vindex (H mod Vindex'Range_Length));
3409 (IC_Id : Invocation_Construct_Id) return Invocation_Signature_Id
3412 pragma Assert (Present (IC_Id));
3413 return Invocation_Constructs.Table (IC_Id).Signature;
3416 --------------------
3417 -- Spec_Placement --
3418 --------------------
3420 function Spec_Placement
3421 (IC_Id : Invocation_Construct_Id) return Declaration_Placement_Kind
3424 pragma Assert (Present (IC_Id));
3425 return Invocation_Constructs.Table (IC_Id).Spec_Placement;
3433 (IR_Id : Invocation_Relation_Id) return Invocation_Signature_Id
3436 pragma Assert (Present (IR_Id));
3437 return Invocation_Relations.Table (IR_Id).Target;