1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Casing
; use Casing
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Errout
; use Errout
;
32 with Fname
; use Fname
;
33 with Fname
.UF
; use Fname
.UF
;
34 with Lib
.Util
; use Lib
.Util
;
35 with Lib
.Xref
; use Lib
.Xref
;
36 with Nlists
; use Nlists
;
37 with Gnatvsn
; use Gnatvsn
;
39 with Osint
; use Osint
;
40 with Osint
.C
; use Osint
.C
;
41 with Output
; use Output
;
43 with Par_SCO
; use Par_SCO
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
47 with Sem_Eval
; use Sem_Eval
;
48 with Sinfo
; use Sinfo
;
49 with Sinput
; use Sinput
;
50 with Snames
; use Snames
;
51 with Stringt
; use Stringt
;
52 with Tbuild
; use Tbuild
;
53 with Uname
; use Uname
;
55 with System
.Case_Util
; use System
.Case_Util
;
56 with System
.WCh_Con
; use System
.WCh_Con
;
58 package body Lib
.Writ
is
60 -----------------------
61 -- Local Subprograms --
62 -----------------------
64 procedure Write_Unit_Name
(N
: Node_Id
);
65 -- Used to write out the unit name for R (pragma Restriction) lines
66 -- for uses of Restriction (No_Dependence => unit-name).
68 ----------------------------------
69 -- Add_Preprocessing_Dependency --
70 ----------------------------------
72 procedure Add_Preprocessing_Dependency
(S
: Source_File_Index
) is
75 Units
.Table
(Units
.Last
) :=
76 (Unit_File_Name
=> File_Name
(S
),
77 Unit_Name
=> No_Unit_Name
,
78 Expected_Unit
=> No_Unit_Name
,
81 Cunit_Entity
=> Empty
,
83 Dynamic_Elab
=> False,
85 Generate_Code
=> False,
88 Ident_String
=> Empty
,
93 No_Elab_Code_All
=> False,
96 Error_Location
=> No_Location
,
98 SPARK_Mode_Pragma
=> Empty
);
99 end Add_Preprocessing_Dependency
;
101 ------------------------------
102 -- Ensure_System_Dependency --
103 ------------------------------
105 procedure Ensure_System_Dependency
is
106 System_Uname
: Unit_Name_Type
;
107 -- Unit name for system spec if needed for dummy entry
109 System_Fname
: File_Name_Type
;
110 -- File name for system spec if needed for dummy entry
113 -- Nothing to do if we already compiled System
115 for Unum
in Units
.First
.. Last_Unit
loop
116 if Units
.Table
(Unum
).Source_Index
= System_Source_File_Index
then
121 -- If no entry for system.ads in the units table, then add a entry
122 -- to the units table for system.ads, which will be referenced when
123 -- the ali file is generated. We need this because every unit depends
124 -- on system as a result of Targparm scanning the system.ads file to
125 -- determine the target dependent parameters for the compilation.
128 Name_Buffer
(1 .. 6) := "system";
129 System_Uname
:= Name_To_Unit_Name
(Name_Enter
);
130 System_Fname
:= File_Name
(System_Source_File_Index
);
132 Units
.Increment_Last
;
133 Units
.Table
(Units
.Last
) := (
134 Unit_File_Name
=> System_Fname
,
135 Unit_Name
=> System_Uname
,
136 Expected_Unit
=> System_Uname
,
137 Source_Index
=> System_Source_File_Index
,
139 Cunit_Entity
=> Empty
,
141 Dynamic_Elab
=> False,
142 Fatal_Error
=> False,
143 Generate_Code
=> False,
146 Ident_String
=> Empty
,
151 No_Elab_Code_All
=> False,
154 Error_Location
=> No_Location
,
156 SPARK_Mode_Pragma
=> Empty
);
158 -- Parse system.ads so that the checksum is set right
159 -- Style checks are not applied.
162 Save_Mindex
: constant Nat
:= Multiple_Unit_Index
;
163 Save_Style
: constant Boolean := Style_Check
;
165 Multiple_Unit_Index
:= 0;
166 Style_Check
:= False;
167 Initialize_Scanner
(Units
.Last
, System_Source_File_Index
);
168 Discard_List
(Par
(Configuration_Pragmas
=> False));
169 Style_Check
:= Save_Style
;
170 Multiple_Unit_Index
:= Save_Mindex
;
172 end Ensure_System_Dependency
;
178 procedure Write_ALI
(Object
: Boolean) is
184 Last_Unit
: constant Unit_Number_Type
:= Units
.Last
;
185 -- Record unit number of last unit. We capture this in case we
186 -- have to add a dummy entry to the unit table for package System.
188 With_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
189 -- Array of flags to show which units are with'ed
191 Elab_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
192 -- Array of flags to show which units have pragma Elaborate set
194 Elab_All_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
195 -- Array of flags to show which units have pragma Elaborate All set
197 Elab_Des_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
198 -- Array of flags to show which units have Elaborate_Desirable set
200 Elab_All_Des_Flags
: array (Units
.First
.. Last_Unit
) of Boolean;
201 -- Array of flags to show which units have Elaborate_All_Desirable set
203 type Yes_No
is (Unknown
, Yes
, No
);
204 Implicit_With
: array (Units
.First
.. Last_Unit
) of Yes_No
;
205 -- Indicates if an implicit with has been given for the unit. Yes if
206 -- certainly present, no if certainly absent, unkonwn if not known.
208 Sdep_Table
: Unit_Ref_Table
(1 .. Pos
(Last_Unit
- Units
.First
+ 2));
209 -- Sorted table of source dependencies. One extra entry in case we
210 -- have to add a dummy entry for System.
213 -- Number of active entries in Sdep_Table
215 flag_compare_debug
: Int
;
216 pragma Import
(C
, flag_compare_debug
);
217 -- Import from toplev.c
219 -----------------------
220 -- Local Subprograms --
221 -----------------------
223 procedure Collect_Withs
(Cunit
: Node_Id
);
224 -- Collect with lines for entries in the context clause of the
225 -- given compilation unit, Cunit.
227 procedure Update_Tables_From_ALI_File
;
228 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
229 -- function), update tables from the ALI information, including
230 -- specifically the Compilation_Switches table.
232 function Up_To_Date_ALI_File_Exists
return Boolean;
233 -- If there exists an ALI file that is up to date, then this function
234 -- initializes the tables in the ALI spec to contain information on
235 -- this file (using Scan_ALI) and returns True. If no file exists,
236 -- or the file is not up to date, then False is returned.
238 procedure Write_Unit_Information
(Unit_Num
: Unit_Number_Type
);
239 -- Write out the library information for one unit for which code is
240 -- generated (includes unit line and with lines).
242 procedure Write_With_Lines
;
243 -- Write out with lines collected by calls to Collect_Withs
249 procedure Collect_Withs
(Cunit
: Node_Id
) is
251 Unum
: Unit_Number_Type
;
254 Item
:= First
(Context_Items
(Cunit
));
255 while Present
(Item
) loop
257 -- Process with clause
259 -- Ada 2005 (AI-50217): limited with_clauses do not create
260 -- dependencies, but must be recorded as components of the
261 -- partition, in case there is no regular with_clause for
262 -- the unit anywhere else.
264 if Nkind
(Item
) = N_With_Clause
then
265 Unum
:= Get_Cunit_Unit_Number
(Library_Unit
(Item
));
266 With_Flags
(Unum
) := True;
268 if not Limited_Present
(Item
) then
269 if Elaborate_Present
(Item
) then
270 Elab_Flags
(Unum
) := True;
273 if Elaborate_All_Present
(Item
) then
274 Elab_All_Flags
(Unum
) := True;
277 if Elaborate_All_Desirable
(Item
) then
278 Elab_All_Des_Flags
(Unum
) := True;
281 if Elaborate_Desirable
(Item
) then
282 Elab_Des_Flags
(Unum
) := True;
286 Set_From_Limited_With
(Cunit_Entity
(Unum
));
289 if Implicit_With
(Unum
) /= Yes
then
290 if Implicit_With_From_Instantiation
(Item
) then
291 Implicit_With
(Unum
) := Yes
;
293 Implicit_With
(Unum
) := No
;
302 --------------------------------
303 -- Up_To_Date_ALI_File_Exists --
304 --------------------------------
306 function Up_To_Date_ALI_File_Exists
return Boolean is
307 Name
: File_Name_Type
;
308 Text
: Text_Buffer_Ptr
;
310 Sind
: Source_File_Index
;
313 Opt
.Check_Object_Consistency
:= True;
314 Read_Library_Info
(Name
, Text
);
316 -- Return if we could not find an ALI file
322 -- Return if ALI file has bad format
326 if Scan_ALI
(Name
, Text
, False, Err
=> True) = No_ALI_Id
then
330 -- If we have an OK ALI file, check if it is up to date
331 -- Note that we assume that the ALI read has all the entries
332 -- we have in our table, plus some additional ones (that can
333 -- come from expansion).
335 Id
:= First_Sdep_Entry
;
336 for J
in 1 .. Num_Sdep
loop
337 Sind
:= Units
.Table
(Sdep_Table
(J
)).Source_Index
;
339 while Sdep
.Table
(Id
).Sfile
/= File_Name
(Sind
) loop
340 if Id
= Sdep
.Last
then
347 if Sdep
.Table
(Id
).Stamp
/= Time_Stamp
(Sind
) then
353 end Up_To_Date_ALI_File_Exists
;
355 ---------------------------------
356 -- Update_Tables_From_ALI_File --
357 ---------------------------------
359 procedure Update_Tables_From_ALI_File
is
361 -- Build Compilation_Switches table
363 Compilation_Switches
.Init
;
365 for J
in First_Arg_Entry
.. Args
.Last
loop
366 Compilation_Switches
.Increment_Last
;
367 Compilation_Switches
.Table
(Compilation_Switches
.Last
) :=
370 end Update_Tables_From_ALI_File
;
372 ----------------------------
373 -- Write_Unit_Information --
374 ----------------------------
376 procedure Write_Unit_Information
(Unit_Num
: Unit_Number_Type
) is
377 Unode
: constant Node_Id
:= Cunit
(Unit_Num
);
378 Ukind
: constant Node_Kind
:= Nkind
(Unit
(Unode
));
379 Uent
: constant Entity_Id
:= Cunit_Entity
(Unit_Num
);
383 Write_Info_Initiate
('U');
384 Write_Info_Char
(' ');
385 Write_Info_Name
(Unit_Name
(Unit_Num
));
387 Write_Info_Name
(Unit_File_Name
(Unit_Num
));
390 Write_Info_Str
(Version_Get
(Unit_Num
));
392 -- Add BD parameter if Elaborate_Body pragma desirable
394 if Ekind
(Uent
) = E_Package
395 and then Elaborate_Body_Desirable
(Uent
)
397 Write_Info_Str
(" BD");
400 -- Add BN parameter if body needed for SAL
402 if (Is_Subprogram
(Uent
)
403 or else Ekind
(Uent
) = E_Package
404 or else Is_Generic_Unit
(Uent
))
405 and then Body_Needed_For_SAL
(Uent
)
407 Write_Info_Str
(" BN");
410 if Dynamic_Elab
(Unit_Num
) then
411 Write_Info_Str
(" DE");
414 -- Set the Elaborate_Body indication if either an explicit pragma
415 -- was present, or if this is an instantiation.
417 if Has_Pragma_Elaborate_Body
(Uent
)
418 or else (Ukind
= N_Package_Declaration
419 and then Is_Generic_Instance
(Uent
)
420 and then Present
(Corresponding_Body
(Unit
(Unode
))))
422 Write_Info_Str
(" EB");
425 -- Now see if we should tell the binder that an elaboration entity
426 -- is present, which must be set to true during elaboration.
427 -- We generate the indication if the following condition is met:
429 -- If this is a spec ...
431 if (Is_Subprogram
(Uent
)
432 or else Ekind
(Uent
) = E_Package
433 or else Is_Generic_Unit
(Uent
))
435 -- and an elaboration entity was declared ...
437 and then Present
(Elaboration_Entity
(Uent
))
439 -- and either the elaboration flag is required ...
441 and then (Elaboration_Entity_Required
(Uent
)
443 -- or this unit has elaboration code ...
445 or else not Has_No_Elaboration_Code
(Unode
)
447 -- or this unit has a separate body and this
448 -- body has elaboration code.
451 (Ekind
(Uent
) = E_Package
452 and then Present
(Body_Entity
(Uent
))
454 not Has_No_Elaboration_Code
455 (Parent
(Declaration_Node
(Body_Entity
(Uent
))))))
457 if Convention
(Uent
) = Convention_CIL
then
459 -- Special case for generic CIL packages which never have
462 Write_Info_Str
(" NE");
465 Write_Info_Str
(" EE");
469 if Has_No_Elaboration_Code
(Unode
) then
470 Write_Info_Str
(" NE");
473 Write_Info_Str
(" O");
474 Write_Info_Char
(OA_Setting
(Unit_Num
));
476 if Ekind_In
(Uent
, E_Package
, E_Package_Body
)
477 and then Present
(Finalizer
(Uent
))
479 Write_Info_Str
(" PF");
482 if Is_Preelaborated
(Uent
) then
483 Write_Info_Str
(" PR");
486 if Is_Pure
(Uent
) then
487 Write_Info_Str
(" PU");
490 if Has_RACW
(Unit_Num
) then
491 Write_Info_Str
(" RA");
494 if Is_Remote_Call_Interface
(Uent
) then
495 Write_Info_Str
(" RC");
498 if Is_Remote_Types
(Uent
) then
499 Write_Info_Str
(" RT");
502 if Is_Shared_Passive
(Uent
) then
503 Write_Info_Str
(" SP");
506 if Ukind
= N_Subprogram_Declaration
507 or else Ukind
= N_Subprogram_Body
509 Write_Info_Str
(" SU");
511 elsif Ukind
= N_Package_Declaration
513 Ukind
= N_Package_Body
515 -- If this is a wrapper package for a subprogram instantiation,
516 -- the user view is the subprogram. Note that in this case the
517 -- ali file contains both the spec and body of the instance.
519 if Is_Wrapper_Package
(Uent
) then
520 Write_Info_Str
(" SU");
522 Write_Info_Str
(" PK");
525 elsif Ukind
= N_Generic_Package_Declaration
then
526 Write_Info_Str
(" PK");
530 if Ukind
in N_Generic_Declaration
532 (Present
(Library_Unit
(Unode
))
534 Nkind
(Unit
(Library_Unit
(Unode
))) in N_Generic_Declaration
)
536 Write_Info_Str
(" GE");
539 if not Is_Internal_File_Name
(Unit_File_Name
(Unit_Num
), True) then
540 case Identifier_Casing
(Source_Index
(Unit_Num
)) is
541 when All_Lower_Case
=> Write_Info_Str
(" IL");
542 when All_Upper_Case
=> Write_Info_Str
(" IU");
546 case Keyword_Casing
(Source_Index
(Unit_Num
)) is
547 when Mixed_Case
=> Write_Info_Str
(" KM");
548 when All_Upper_Case
=> Write_Info_Str
(" KU");
553 if Initialize_Scalars
or else Invalid_Value_Used
then
554 Write_Info_Str
(" IS");
559 -- Generate with lines, first those that are directly with'ed
561 for J
in With_Flags
'Range loop
562 With_Flags
(J
) := False;
563 Elab_Flags
(J
) := False;
564 Elab_All_Flags
(J
) := False;
565 Elab_Des_Flags
(J
) := False;
566 Elab_All_Des_Flags
(J
) := False;
567 Implicit_With
(J
) := Unknown
;
570 Collect_Withs
(Unode
);
572 -- For a body, we must also check for any subunits which belong to
573 -- it and which have context clauses of their own, since these
574 -- with'ed units are part of its own elaboration dependencies.
576 if Nkind
(Unit
(Unode
)) in N_Unit_Body
then
577 for S
in Units
.First
.. Last_Unit
loop
579 -- We are only interested in subunits. For preproc. data and
580 -- def. files, Cunit is Empty, so we need to test that first.
582 if Cunit
(S
) /= Empty
583 and then Nkind
(Unit
(Cunit
(S
))) = N_Subunit
585 Pnode
:= Library_Unit
(Cunit
(S
));
587 -- In gnatc mode, the errors in the subunits will not have
588 -- been recorded, but the analysis of the subunit may have
589 -- failed. There is no information to add to ALI file in
596 -- Find ultimate parent of the subunit
598 while Nkind
(Unit
(Pnode
)) = N_Subunit
loop
599 Pnode
:= Library_Unit
(Pnode
);
602 -- See if it belongs to current unit, and if so, include
605 if Pnode
= Unode
then
606 Collect_Withs
(Cunit
(S
));
614 -- Generate the linker option lines
616 for J
in 1 .. Linker_Option_Lines
.Last
loop
618 -- Pragma Linker_Options is not allowed in predefined generic
619 -- units. This is because they won't be read, due to the fact that
620 -- with lines for generic units lack the file name and lib name
621 -- parameters (see Lib_Writ spec for an explanation).
623 if Is_Generic_Unit
(Cunit_Entity
(Main_Unit
))
625 Is_Predefined_File_Name
(Unit_File_Name
(Current_Sem_Unit
))
626 and then Linker_Option_Lines
.Table
(J
).Unit
= Unit_Num
630 ("linker options not allowed in predefined generic unit");
631 raise Unrecoverable_Error
;
634 -- Output one linker option line
637 S
: Linker_Option_Entry
renames Linker_Option_Lines
.Table
(J
);
639 if S
.Unit
= Unit_Num
then
640 Write_Info_Initiate
('L');
641 Write_Info_Char
(' ');
642 Write_Info_Slit
(S
.Option
);
650 for J
in 1 .. Notes
.Last
loop
652 N
: constant Node_Id
:= Notes
.Table
(J
);
653 L
: constant Source_Ptr
:= Sloc
(N
);
654 U
: constant Unit_Number_Type
:=
655 Unit
(Get_Source_File_Index
(L
));
658 Note_Unit
: Unit_Number_Type
;
659 -- The unit in whose U section this note must be emitted:
660 -- notes for subunits are emitted along with the main unit;
661 -- all other notes are emitted as part of the enclosing
665 if U
/= No_Unit
and then Nkind
(Unit
(Cunit
(U
))) = N_Subunit
667 Note_Unit
:= Main_Unit
;
672 if Note_Unit
= Unit_Num
then
673 Write_Info_Initiate
('N');
674 Write_Info_Char
(' ');
676 case Chars
(Pragma_Identifier
(N
)) is
677 when Name_Annotate
=>
685 when Name_Subtitle
=>
692 Write_Info_Int
(Int
(Get_Logical_Line_Number
(L
)));
693 Write_Info_Char
(':');
694 Write_Info_Int
(Int
(Get_Column_Number
(L
)));
696 -- Indicate source file of annotation if different from
697 -- compilation unit source file (case of annotation coming
700 if Get_Source_File_Index
(L
) /= Source_Index
(Unit_Num
) then
701 Write_Info_Char
(':');
702 Write_Info_Name
(File_Name
(Get_Source_File_Index
(L
)));
709 A
:= First
(Pragma_Argument_Associations
(N
));
710 while Present
(A
) loop
711 Write_Info_Char
(' ');
713 if Chars
(A
) /= No_Name
then
714 Write_Info_Name
(Chars
(A
));
715 Write_Info_Char
(':');
719 Expr
: constant Node_Id
:= Expression
(A
);
722 if Nkind
(Expr
) = N_Identifier
then
723 Write_Info_Name
(Chars
(Expr
));
725 elsif Nkind
(Expr
) = N_Integer_Literal
726 and then Is_OK_Static_Expression
(Expr
)
728 Write_Info_Uint
(Intval
(Expr
));
730 elsif Nkind
(Expr
) = N_String_Literal
731 and then Is_OK_Static_Expression
(Expr
)
733 Write_Info_Slit
(Strval
(Expr
));
736 Write_Info_Str
("<expr>");
748 end Write_Unit_Information
;
750 ----------------------
751 -- Write_With_Lines --
752 ----------------------
754 procedure Write_With_Lines
is
755 With_Table
: Unit_Ref_Table
(1 .. Pos
(Last_Unit
- Units
.First
+ 1));
756 Num_Withs
: Int
:= 0;
757 Unum
: Unit_Number_Type
;
759 Uname
: Unit_Name_Type
;
760 Fname
: File_Name_Type
;
761 Pname
: constant Unit_Name_Type
:=
762 Get_Parent_Spec_Name
(Unit_Name
(Main_Unit
));
763 Body_Fname
: File_Name_Type
;
766 procedure Write_With_File_Names
767 (Nam
: in out File_Name_Type
;
769 -- Write source file name Nam and ALI file name for unit index Idx.
770 -- Possibly change Nam to lowercase (generating a new file name).
772 --------------------------
773 -- Write_With_File_Name --
774 --------------------------
776 procedure Write_With_File_Names
777 (Nam
: in out File_Name_Type
;
781 if not File_Names_Case_Sensitive
then
782 Get_Name_String
(Nam
);
783 To_Lower
(Name_Buffer
(1 .. Name_Len
));
787 Write_Info_Name
(Nam
);
789 Write_Info_Name
(Lib_File_Name
(Nam
, Idx
));
790 end Write_With_File_Names
;
792 -- Start of processing for Write_With_Lines
795 -- Loop to build the with table. A with on the main unit itself
796 -- is ignored (AARM 10.2(14a)). Such a with-clause can occur if
797 -- the main unit is a subprogram with no spec, and a subunit of
798 -- it unnecessarily withs the parent.
800 for J
in Units
.First
+ 1 .. Last_Unit
loop
802 -- Add element to with table if it is with'ed or if it is the
803 -- parent spec of the main unit (case of main unit is a child
804 -- unit). The latter with is not needed for semantic purposes,
805 -- but is required by the binder for elaboration purposes. For
806 -- preprocessing data and definition files, there is no Unit_Name,
807 -- check for that first.
809 if Unit_Name
(J
) /= No_Unit_Name
810 and then (With_Flags
(J
) or else Unit_Name
(J
) = Pname
)
812 Num_Withs
:= Num_Withs
+ 1;
813 With_Table
(Num_Withs
) := J
;
817 -- Sort and output the table
819 Sort
(With_Table
(1 .. Num_Withs
));
821 for J
in 1 .. Num_Withs
loop
822 Unum
:= With_Table
(J
);
823 Cunit
:= Units
.Table
(Unum
).Cunit
;
824 Uname
:= Units
.Table
(Unum
).Unit_Name
;
825 Fname
:= Units
.Table
(Unum
).Unit_File_Name
;
827 if Implicit_With
(Unum
) = Yes
then
828 Write_Info_Initiate
('Z');
830 elsif Ekind
(Cunit_Entity
(Unum
)) = E_Package
831 and then From_Limited_With
(Cunit_Entity
(Unum
))
833 Write_Info_Initiate
('Y');
836 Write_Info_Initiate
('W');
839 Write_Info_Char
(' ');
840 Write_Info_Name
(Uname
);
842 -- Now we need to figure out the names of the files that contain
843 -- the with'ed unit. These will usually be the files for the body,
844 -- except in the case of a package that has no body. Note that we
845 -- have a specific exemption here for predefined library generics
846 -- (see comments for Generic_May_Lack_ALI). We do not generate
847 -- dependency upon the ALI file for such units. Older compilers
848 -- used to not support generating code (and ALI) for generics, and
849 -- we want to avoid having different processing (namely, different
850 -- lists of files to be compiled) for different stages of the
853 if not ((Nkind
(Unit
(Cunit
)) in N_Generic_Declaration
855 Nkind
(Unit
(Cunit
)) in N_Generic_Renaming_Declaration
)
856 and then Generic_May_Lack_ALI
(Fname
))
858 -- In SPARK mode, always generate the dependencies on ALI
859 -- files, which are required to compute frame conditions
862 or else GNATprove_Mode
866 if Is_Spec_Name
(Uname
) then
869 (Get_Body_Name
(Uname
),
870 Subunit
=> False, May_Fail
=> True);
874 (Get_Body_Name
(Uname
));
876 if Body_Fname
= No_File
then
877 Body_Fname
:= Get_File_Name
(Uname
, Subunit
=> False);
878 Body_Index
:= Get_Unit_Index
(Uname
);
882 Body_Fname
:= Get_File_Name
(Uname
, Subunit
=> False);
883 Body_Index
:= Get_Unit_Index
(Uname
);
886 -- A package is considered to have a body if it requires
887 -- a body or if a body is present in Ada 83 mode.
889 if Body_Required
(Cunit
)
890 or else (Ada_Version
= Ada_83
891 and then Full_Source_Name
(Body_Fname
) /= No_File
)
893 Write_With_File_Names
(Body_Fname
, Body_Index
);
895 Write_With_File_Names
(Fname
, Munit_Index
(Unum
));
898 if Ekind
(Cunit_Entity
(Unum
)) = E_Package
899 and then From_Limited_With
(Cunit_Entity
(Unum
))
903 if Elab_Flags
(Unum
) then
904 Write_Info_Str
(" E");
907 if Elab_All_Flags
(Unum
) then
908 Write_Info_Str
(" EA");
911 if Elab_Des_Flags
(Unum
) then
912 Write_Info_Str
(" ED");
915 if Elab_All_Des_Flags
(Unum
) then
916 Write_Info_Str
(" AD");
924 -- Finally generate the special lines for cases of Restriction_Set
925 -- with No_Dependence and no restriction present.
928 Unam
: Unit_Name_Type
;
931 for J
in Restriction_Set_Dependences
.First
..
932 Restriction_Set_Dependences
.Last
934 Unam
:= Restriction_Set_Dependences
.Table
(J
);
936 -- Don't need an entry if already in the unit table
938 for U
in 0 .. Last_Unit
loop
939 if Unit_Name
(U
) = Unam
then
944 -- Otherwise generate the entry
946 Write_Info_Initiate
('W');
947 Write_Info_Char
(' ');
948 Write_Info_Name
(Unam
);
955 end Write_With_Lines
;
957 -- Start of processing for Write_ALI
960 -- We never write an ALI file if the original operating mode was
961 -- syntax-only (-gnats switch used in compiler invocation line)
963 if Original_Operating_Mode
= Check_Syntax
964 or flag_compare_debug
/= 0
969 -- Generation of ALI files may be disabled, e.g. for formal verification
972 if Disable_ALI_File
then
976 -- Build sorted source dependency table. We do this right away, because
977 -- it is referenced by Up_To_Date_ALI_File_Exists.
979 for Unum
in Units
.First
.. Last_Unit
loop
980 if Cunit_Entity
(Unum
) = Empty
981 or else not From_Limited_With
(Cunit_Entity
(Unum
))
983 Num_Sdep
:= Num_Sdep
+ 1;
984 Sdep_Table
(Num_Sdep
) := Unum
;
988 -- Sort the table so that the D lines are in order
990 Lib
.Sort
(Sdep_Table
(1 .. Num_Sdep
));
992 -- If we are not generating code, and there is an up to date ALI file
993 -- file accessible, read it, and acquire the compilation arguments from
994 -- this file. In GNATprove mode, always generate the ALI file, which
995 -- contains a special section for formal verification.
997 if Operating_Mode
/= Generate_Code
and then not GNATprove_Mode
then
998 if Up_To_Date_ALI_File_Exists
then
999 Update_Tables_From_ALI_File
;
1004 -- Otherwise acquire compilation arguments and prepare to write
1005 -- out a new ali file.
1007 Create_Output_Library_Info
;
1009 -- Output version line
1011 Write_Info_Initiate
('V');
1012 Write_Info_Str
(" """);
1013 Write_Info_Str
(Verbose_Library_Version
);
1014 Write_Info_Char
('"');
1018 -- Output main program line if this is acceptable main program
1020 Output_Main_Program_Line
: declare
1021 U
: Node_Id
:= Unit
(Units
.Table
(Main_Unit
).Cunit
);
1024 procedure M_Parameters
;
1025 -- Output parameters for main program line
1031 procedure M_Parameters
is
1033 if Main_Priority
(Main_Unit
) /= Default_Main_Priority
then
1034 Write_Info_Char
(' ');
1035 Write_Info_Nat
(Main_Priority
(Main_Unit
));
1038 if Opt
.Time_Slice_Set
then
1039 Write_Info_Str
(" T=");
1040 Write_Info_Nat
(Opt
.Time_Slice_Value
);
1043 if Main_CPU
(Main_Unit
) /= Default_Main_CPU
then
1044 Write_Info_Str
(" C=");
1045 Write_Info_Nat
(Main_CPU
(Main_Unit
));
1048 Write_Info_Str
(" W=");
1050 (WC_Encoding_Letters
(Wide_Character_Encoding_Method
));
1055 -- Start of processing for Output_Main_Program_Line
1058 if Nkind
(U
) = N_Subprogram_Body
1060 (Nkind
(U
) = N_Package_Body
1062 Nkind
(Original_Node
(U
)) in N_Subprogram_Instantiation
)
1064 -- If the unit is a subprogram instance, the entity for the
1065 -- subprogram is the alias of the visible entity, which is the
1066 -- related instance of the wrapper package. We retrieve the
1067 -- subprogram declaration of the desired entity.
1069 if Nkind
(U
) = N_Package_Body
then
1070 U
:= Parent
(Parent
(
1071 Alias
(Related_Instance
(Defining_Unit_Name
1072 (Specification
(Unit
(Library_Unit
(Parent
(U
)))))))));
1075 S
:= Specification
(U
);
1077 -- A generic subprogram is never a main program
1079 if Nkind
(U
) = N_Subprogram_Body
1080 and then Present
(Corresponding_Spec
(U
))
1082 Ekind_In
(Corresponding_Spec
(U
), E_Generic_Procedure
,
1087 elsif No
(Parameter_Specifications
(S
)) then
1088 if Nkind
(S
) = N_Procedure_Specification
then
1089 Write_Info_Initiate
('M');
1090 Write_Info_Str
(" P");
1095 Nam
: Node_Id
:= Defining_Unit_Name
(S
);
1098 -- If it is a child unit, get its simple name
1100 if Nkind
(Nam
) = N_Defining_Program_Unit_Name
then
1101 Nam
:= Defining_Identifier
(Nam
);
1104 if Is_Integer_Type
(Etype
(Nam
)) then
1105 Write_Info_Initiate
('M');
1106 Write_Info_Str
(" F");
1113 end Output_Main_Program_Line
;
1115 -- Write command argument ('A') lines
1117 for A
in 1 .. Compilation_Switches
.Last
loop
1118 Write_Info_Initiate
('A');
1119 Write_Info_Char
(' ');
1120 Write_Info_Str
(Compilation_Switches
.Table
(A
).all);
1121 Write_Info_Terminate
;
1124 -- Output parameters ('P') line
1126 Write_Info_Initiate
('P');
1128 if Compilation_Errors
then
1129 Write_Info_Str
(" CE");
1132 if Opt
.Detect_Blocking
then
1133 Write_Info_Str
(" DB");
1137 and then not Is_Predefined_File_Name
(Unit_File_Name
(Main_Unit
))
1139 if Locking_Policy
/= ' ' then
1140 Write_Info_Str
(" L");
1141 Write_Info_Char
(Locking_Policy
);
1144 if Queuing_Policy
/= ' ' then
1145 Write_Info_Str
(" Q");
1146 Write_Info_Char
(Queuing_Policy
);
1149 if Task_Dispatching_Policy
/= ' ' then
1150 Write_Info_Str
(" T");
1151 Write_Info_Char
(Task_Dispatching_Policy
);
1152 Write_Info_Char
(' ');
1156 if GNATprove_Mode
then
1157 Write_Info_Str
(" GP");
1160 if Partition_Elaboration_Policy
/= ' ' then
1161 Write_Info_Str
(" E");
1162 Write_Info_Char
(Partition_Elaboration_Policy
);
1166 Write_Info_Str
(" NO");
1169 if No_Run_Time_Mode
then
1170 Write_Info_Str
(" NR");
1173 if Normalize_Scalars
then
1174 Write_Info_Str
(" NS");
1177 if Default_SSO_Config
/= ' ' then
1178 Write_Info_Str
(" O");
1179 Write_Info_Char
(Default_SSO_Config
);
1182 if Sec_Stack_Used
then
1183 Write_Info_Str
(" SS");
1186 if Unreserve_All_Interrupts
then
1187 Write_Info_Str
(" UA");
1190 if Exception_Mechanism
= Back_End_Exceptions
then
1191 Write_Info_Str
(" ZX");
1196 -- Before outputting the restrictions line, update the setting of
1197 -- the No_Elaboration_Code flag. Violations of this restriction
1198 -- cannot be detected until after the backend has been called since
1199 -- it is the backend that sets this flag. We have to check all units
1200 -- for which we have generated code
1202 for Unit
in Units
.First
.. Last_Unit
loop
1203 if Units
.Table
(Unit
).Generate_Code
or else Unit
= Main_Unit
then
1204 if not Has_No_Elaboration_Code
(Cunit
(Unit
)) then
1205 Main_Restrictions
.Violated
(No_Elaboration_Code
) := True;
1210 -- Positional case (only if debug flag -gnatd.R is set)
1212 if Debug_Flag_Dot_RR
then
1214 -- Output first restrictions line
1216 Write_Info_Initiate
('R');
1217 Write_Info_Char
(' ');
1219 -- First the information for the boolean restrictions
1221 for R
in All_Boolean_Restrictions
loop
1222 if Main_Restrictions
.Set
(R
)
1223 and then not Restriction_Warnings
(R
)
1225 Write_Info_Char
('r');
1226 elsif Main_Restrictions
.Violated
(R
) then
1227 Write_Info_Char
('v');
1229 Write_Info_Char
('n');
1233 -- And now the information for the parameter restrictions
1235 for RP
in All_Parameter_Restrictions
loop
1236 if Main_Restrictions
.Set
(RP
)
1237 and then not Restriction_Warnings
(RP
)
1239 Write_Info_Char
('r');
1240 Write_Info_Nat
(Nat
(Main_Restrictions
.Value
(RP
)));
1242 Write_Info_Char
('n');
1245 if not Main_Restrictions
.Violated
(RP
)
1246 or else RP
not in Checked_Parameter_Restrictions
1248 Write_Info_Char
('n');
1250 Write_Info_Char
('v');
1251 Write_Info_Nat
(Nat
(Main_Restrictions
.Count
(RP
)));
1253 if Main_Restrictions
.Unknown
(RP
) then
1254 Write_Info_Char
('+');
1261 -- Named case (if debug flag -gnatd.R is not set)
1268 -- Write RN header line with preceding blank line
1271 Write_Info_Initiate
('R');
1272 Write_Info_Char
('N');
1275 -- First the lines for the boolean restrictions
1277 for R
in All_Boolean_Restrictions
loop
1278 if Main_Restrictions
.Set
(R
)
1279 and then not Restriction_Warnings
(R
)
1282 elsif Main_Restrictions
.Violated
(R
) then
1288 Write_Info_Initiate
('R');
1289 Write_Info_Char
(C
);
1290 Write_Info_Char
(' ');
1291 Write_Info_Str
(All_Boolean_Restrictions
'Image (R
));
1299 -- And now the lines for the parameter restrictions
1301 for RP
in All_Parameter_Restrictions
loop
1302 if Main_Restrictions
.Set
(RP
)
1303 and then not Restriction_Warnings
(RP
)
1305 Write_Info_Initiate
('R');
1306 Write_Info_Str
("R ");
1307 Write_Info_Str
(All_Parameter_Restrictions
'Image (RP
));
1308 Write_Info_Char
('=');
1309 Write_Info_Nat
(Nat
(Main_Restrictions
.Value
(RP
)));
1313 if not Main_Restrictions
.Violated
(RP
)
1314 or else RP
not in Checked_Parameter_Restrictions
1318 Write_Info_Initiate
('R');
1319 Write_Info_Str
("V ");
1320 Write_Info_Str
(All_Parameter_Restrictions
'Image (RP
));
1321 Write_Info_Char
('=');
1322 Write_Info_Nat
(Nat
(Main_Restrictions
.Count
(RP
)));
1324 if Main_Restrictions
.Unknown
(RP
) then
1325 Write_Info_Char
('+');
1333 -- Output R lines for No_Dependence entries
1335 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
1336 if In_Extended_Main_Source_Unit
(No_Dependences
.Table
(J
).Unit
)
1337 and then not No_Dependences
.Table
(J
).Warn
1339 Write_Info_Initiate
('R');
1340 Write_Info_Char
(' ');
1341 Write_Unit_Name
(No_Dependences
.Table
(J
).Unit
);
1346 -- Output interrupt state lines
1348 for J
in Interrupt_States
.First
.. Interrupt_States
.Last
loop
1349 Write_Info_Initiate
('I');
1350 Write_Info_Char
(' ');
1351 Write_Info_Nat
(Interrupt_States
.Table
(J
).Interrupt_Number
);
1352 Write_Info_Char
(' ');
1353 Write_Info_Char
(Interrupt_States
.Table
(J
).Interrupt_State
);
1354 Write_Info_Char
(' ');
1356 (Nat
(Get_Logical_Line_Number
1357 (Interrupt_States
.Table
(J
).Pragma_Loc
)));
1361 -- Output priority specific dispatching lines
1363 for J
in Specific_Dispatching
.First
.. Specific_Dispatching
.Last
loop
1364 Write_Info_Initiate
('S');
1365 Write_Info_Char
(' ');
1366 Write_Info_Char
(Specific_Dispatching
.Table
(J
).Dispatching_Policy
);
1367 Write_Info_Char
(' ');
1368 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).First_Priority
);
1369 Write_Info_Char
(' ');
1370 Write_Info_Nat
(Specific_Dispatching
.Table
(J
).Last_Priority
);
1371 Write_Info_Char
(' ');
1373 (Nat
(Get_Logical_Line_Number
1374 (Specific_Dispatching
.Table
(J
).Pragma_Loc
)));
1378 -- Loop through file table to output information for all units for which
1379 -- we have generated code, as marked by the Generate_Code flag.
1381 for Unit
in Units
.First
.. Last_Unit
loop
1382 if Units
.Table
(Unit
).Generate_Code
1383 or else Unit
= Main_Unit
1385 Write_Info_EOL
; -- blank line
1386 Write_Unit_Information
(Unit
);
1390 Write_Info_EOL
; -- blank line
1392 -- Output external version reference lines
1394 for J
in 1 .. Version_Ref
.Last
loop
1395 Write_Info_Initiate
('E');
1396 Write_Info_Char
(' ');
1398 for K
in 1 .. String_Length
(Version_Ref
.Table
(J
)) loop
1399 Write_Info_Char_Code
(Get_String_Char
(Version_Ref
.Table
(J
), K
));
1405 -- Prepare to output the source dependency lines
1408 Unum
: Unit_Number_Type
;
1409 -- Number of unit being output
1411 Sind
: Source_File_Index
;
1412 -- Index of corresponding source file
1414 Fname
: File_Name_Type
;
1417 for J
in 1 .. Num_Sdep
loop
1418 Unum
:= Sdep_Table
(J
);
1419 Units
.Table
(Unum
).Dependency_Num
:= J
;
1420 Sind
:= Units
.Table
(Unum
).Source_Index
;
1422 Write_Info_Initiate
('D');
1423 Write_Info_Char
(' ');
1425 -- Normal case of a unit entry with a source index
1427 if Sind
/= No_Source_File
then
1428 Fname
:= File_Name
(Sind
);
1430 -- Ensure that on platforms where the file names are not case
1431 -- sensitive, the recorded file name is in lower case.
1433 if not File_Names_Case_Sensitive
then
1434 Get_Name_String
(Fname
);
1435 To_Lower
(Name_Buffer
(1 .. Name_Len
));
1439 Write_Info_Name_May_Be_Quoted
(Fname
);
1440 Write_Info_Tab
(25);
1441 Write_Info_Str
(String (Time_Stamp
(Sind
)));
1442 Write_Info_Char
(' ');
1443 Write_Info_Str
(Get_Hex_String
(Source_Checksum
(Sind
)));
1445 -- If subunit, add unit name, omitting the %b at the end
1447 if Present
(Cunit
(Unum
)) then
1448 Get_Decoded_Name_String
(Unit_Name
(Unum
));
1449 Write_Info_Char
(' ');
1451 if Nkind
(Unit
(Cunit
(Unum
))) = N_Subunit
then
1452 Write_Info_Str
(Name_Buffer
(1 .. Name_Len
- 2));
1454 Write_Info_Str
(Name_Buffer
(1 .. Name_Len
));
1458 -- If Source_Reference pragma used, output information
1460 if Num_SRef_Pragmas
(Sind
) > 0 then
1461 Write_Info_Char
(' ');
1463 if Num_SRef_Pragmas
(Sind
) = 1 then
1464 Write_Info_Nat
(Int
(First_Mapped_Line
(Sind
)));
1469 Write_Info_Char
(':');
1470 Write_Info_Name
(Reference_Name
(Sind
));
1473 -- Case where there is no source index (happens for missing
1474 -- files). In this case we write a dummy time stamp.
1477 Write_Info_Name
(Unit_File_Name
(Unum
));
1478 Write_Info_Tab
(25);
1479 Write_Info_Str
(String (Dummy_Time_Stamp
));
1480 Write_Info_Char
(' ');
1481 Write_Info_Str
(Get_Hex_String
(0));
1488 -- Output cross-references
1490 if Opt
.Xref_Active
then
1494 -- Output SCO information if present
1496 if Generate_SCO
then
1500 -- Output SPARK cross-reference information if needed
1502 if Opt
.Xref_Active
and then GNATprove_Mode
then
1503 SPARK_Specific
.Collect_SPARK_Xrefs
(Sdep_Table
=> Sdep_Table
,
1504 Num_Sdep
=> Num_Sdep
);
1505 SPARK_Specific
.Output_SPARK_Xrefs
;
1508 -- Output final blank line and we are done. This final blank line is
1509 -- probably junk, but we don't feel like making an incompatible change.
1511 Write_Info_Terminate
;
1512 Close_Output_Library_Info
;
1515 ---------------------
1516 -- Write_Unit_Name --
1517 ---------------------
1519 procedure Write_Unit_Name
(N
: Node_Id
) is
1521 if Nkind
(N
) = N_Identifier
then
1522 Write_Info_Name
(Chars
(N
));
1525 pragma Assert
(Nkind
(N
) = N_Selected_Component
);
1526 Write_Unit_Name
(Prefix
(N
));
1527 Write_Info_Char
('.');
1528 Write_Unit_Name
(Selector_Name
(N
));
1530 end Write_Unit_Name
;