diff options
author | Bob Duff <duff@adacore.com> | 2024-10-17 12:04:45 -0400 |
---|---|---|
committer | Marc Poulhiès <dkm@gcc.gnu.org> | 2024-11-04 16:57:59 +0100 |
commit | 16007e34ef4019f7cba9c9b718f5e43cc045e920 (patch) | |
tree | c5ed4f4e1f4d3cd772a61edc2aef17e7493fa3f1 /gcc/ada/sinfo-utils.ads | |
parent | f6a8c07743d74430da761e3ca7a8516ac663ef94 (diff) | |
download | gcc-16007e34ef4019f7cba9c9b718f5e43cc045e920.zip gcc-16007e34ef4019f7cba9c9b718f5e43cc045e920.tar.gz gcc-16007e34ef4019f7cba9c9b718f5e43cc045e920.tar.bz2 |
ada: Split Library_Unit using multiple wrappers
The Library_Unit field was used for all sorts of different purposes,
which led to confusing code.
This patch splits Library_Unit into much more specific wrapper
subprograms that should be called instead of [Set_]Library_Unit.
Predicates and pragmas Assert are used to catch misuses of these.
We document the semantics, especially "surprising" cases (e.g.
internally-generated with clauses can refer to package bodies).
This change does not fix gigi, codepeer, spark, or llvm
to use the new wrappers; so far, they are used only in
the GNAT front end.
gcc/ada/ChangeLog:
* sinfo.ads (Library_Unit): Rewrite documentation. Note that
the "??? not (always) true..." comment was not true;
the Subunit_Parent never points to the spec.
(N_Compilation_Unit): Improve documentation. The Aux_ node
was not created to solve the mentioned problems; it was
created because the size of nodes was limited.
Misc doc improvements.
* sinfo-utils.ads: Add new wrappers for Library_Unit field.
Use subtypes with predicates for the parameters.
(First_Real_Statement): Still used in codepeer.
* sinfo-utils.adb: Add new wrappers for Library_Unit field,
with suitable assertions.
* sem_prag.adb: Use new field wrapper names.
(Matching_Name): New name for Same_Name to avoid
potential confusion with the other function with the
same name (Sem_Util.Same_Name), which is also called
in this same file.
(Matching_Convention): Change Same_Convention to match
Matching_Name.
* sem_util.ads (Same_Name): Improve comments; the old comment
implied that it works for all names, which was not true.
* sem_util.adb: Use new field wrapper names.
* gen_il-gen.adb: Rename N_Unit_Body to be N_Lib_Unit_Body.
Plain "unit" is ambiguous in Ada (library unit, compilation
unit, program unit, etc).
Add new union types N_Lib_Unit_Declaration and
N_Lib_Unit_Renaming_Declaration.
* gen_il-gen-gen_nodes.adb (Compute_Ranges): Raise exception
earlier (it is already raised later, in Verify_Type_Table).
Add a comment explaining why it might be raised.
* gen_il-types.ads: Rename N_Unit_Body to be N_Lib_Unit_Body, and add
new N_Lib_Unit_Declaration and N_Lib_Unit_Renaming_Declaration.
* einfo.ads: Fix obsolete comment (was left over from before
the "variable-sized nodes").
* exp_ch7.adb: Use new field wrapper names.
* exp_disp.adb: Use new field wrapper names.
* exp_unst.adb: Use new field wrapper names.
* exp_util.adb: Use new field wrapper names.
* fe.h: Add new field wrapper names. These are currently not
used in gigi, but this change prepares for using them in
gigi.
* inline.adb: Use new field wrapper names.
* lib.adb: Use new field wrapper names.
Comment improvements.
* lib-load.adb: Use new field wrapper names.
Minor cleanup.
* lib-writ.adb: Use new field wrapper names.
* live.adb: Use new field wrapper names.
* par-load.adb: Use new field wrapper names.
Comment improvements. Minor cleanup.
* rtsfind.adb: Use new field wrapper names.
* sem.adb: Use new field wrapper names.
* sem_ch10.adb: Use new field wrapper names.
Comment improvements. Minor cleanup.
* sem_ch12.adb: Use new field wrapper names.
* sem_ch7.adb: Use new field wrapper names.
* sem_ch8.adb: Use new field wrapper names.
* sem_elab.adb: Use new field wrapper names.
Comment improvements.
* errout.adb (Output_Source_Line): Fix blowup in some
obscure cases, where List_Pragmas is not fully set up.
Diffstat (limited to 'gcc/ada/sinfo-utils.ads')
-rw-r--r-- | gcc/ada/sinfo-utils.ads | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/gcc/ada/sinfo-utils.ads b/gcc/ada/sinfo-utils.ads index 9acb620..ebb9699 100644 --- a/gcc/ada/sinfo-utils.ads +++ b/gcc/ada/sinfo-utils.ads @@ -27,6 +27,65 @@ with Sinfo.Nodes; use Sinfo.Nodes; package Sinfo.Utils is + -- We would like to get rid of the Library_Unit field, and replace it with + -- Other_Comp_Unit (on N_Compilation_Unit), Withed_Lib_Unit (on + -- N_With_Clause), and Subunit (on N_Body_Stub). Or we could split + -- Other_Comp_Unit into Spec_Lib_Unit, Body_Lib_Unit, Subunit_Parent. + -- However, gnat-llvm, codepeer, and spark are still using Library_Unit. + -- Therefore, we use the wrappers below. + -- + -- The call site should always know whether it has an N_Compilation_Unit, + -- N_Body_Stub, or N_With_Clause. In the N_Compilation_Unit case, it should + -- also know whether it's looking for the spec of a body, the body of a + -- spec, or the parent of a subunit. Spec_Or_Body_Lib_Unit and + -- Other_Comp_Unit should be avoided when possible; these are for the + -- N_Compilation_Unit cases where the call site does NOT know what it's + -- looking for. + + function Spec_Lib_Unit + (N : N_Compilation_Unit_Id) return Opt_N_Compilation_Unit_Id; + procedure Set_Spec_Lib_Unit (N, Val : N_Compilation_Unit_Id); + -- The spec compilation unit of a body compilation unit. + -- It can be an acts-as-spec subprogram body; in that case + -- Spec_Lib_Unit points to itself. + + function Body_Lib_Unit + (N : N_Compilation_Unit_Id) return Opt_N_Compilation_Unit_Id; + procedure Set_Body_Lib_Unit (N, Val : N_Compilation_Unit_Id); + -- The body compilation unit of a spec compilation unit. + -- Empty if not present. + + function Spec_Or_Body_Lib_Unit + (N : N_Compilation_Unit_Id) return Opt_N_Compilation_Unit_Id; + -- Same as Spec_Lib_Unit or Body_Lib_Unit, depending on whether + -- N is a body or spec. Used when we know N is a library unit + -- (not a subunit), but we don't know whether it's the spec + -- or the body. + + function Subunit_Parent + (N : N_Compilation_Unit_Id) return Opt_N_Compilation_Unit_Id; + procedure Set_Subunit_Parent (N, Val : N_Compilation_Unit_Id); + -- The parent body of a subunit + + function Other_Comp_Unit + (N : N_Compilation_Unit_Id) return Opt_N_Compilation_Unit_Id; + -- Same as Spec_Lib_Unit, Body_Lib_Unit, or Subunit_Parent, + -- as appropriate. Used when we don't know whether N is a + -- a library unit spec, library unit body, or subunit. + + function Stub_Subunit (N : N_Body_Stub_Id) return Opt_N_Compilation_Unit_Id; + procedure Set_Stub_Subunit + (N : N_Body_Stub_Id; Val : N_Compilation_Unit_Id); + -- Subunit corresponding to a stub + + function Withed_Lib_Unit + (N : N_With_Clause_Id) return Opt_N_Compilation_Unit_Id; + procedure Set_Withed_Lib_Unit + (N : N_With_Clause_Id; Val : N_Compilation_Unit_Id); + -- The compilation unit that a with clause refers to. + -- Note that the Sem_Elab creates with clauses that point to bodies + -- (including non-Acts_As_Spec bodies). + ------------------------------- -- Parent-related operations -- ------------------------------- @@ -54,9 +113,9 @@ package Sinfo.Utils is -- Miscellaneous Tree Access Subprograms -- ------------------------------------------- - function First_Real_Statement -- ???? + function First_Real_Statement -- ??? (Ignored : N_Handled_Sequence_Of_Statements_Id) return Node_Id is (Empty); - -- The First_Real_Statement field is going away, but it is referenced in + -- The First_Real_Statement field has been removed, but it is referenced in -- codepeer and gnat-llvm. This is a temporary version, always returning -- Empty, to ease the transition. |