ada: Avoid duplicated streaming subprograms
commit82a205ebf656aa349f46c541a2a22303ca5b92fc
authorSteve Baird <baird@adacore.com>
Fri, 3 Mar 2023 00:51:57 +0000 (2 16:51 -0800)
committerMarc Poulhiès <poulhies@adacore.com>
Thu, 25 May 2023 07:44:17 +0000 (25 09:44 +0200)
tree0ac8f2f9a4290649540ff7cd1287923594fcfa0f
parent9f355ec846c6dd7a9f4f5ba22eb8642c0b4f37ff
ada: Avoid duplicated streaming subprograms

In some common cases, a reference to Some_Type'Some_Streaming_Attribute
causes the needed subprogram to be generated "on demand". If there are
multiple such references (e.g., two calls to Some_Type'Write) then we
want to avoid generating multiple essentially-identical subprograms.
This change implies that a generated streaming subprogram may now have
multiple call sites, so we can no longer use the source position information
from the (one and only) call site. If an exception is raised during a
streaming operation, this can make a difference in the reported raise location.

gcc/ada/

* exp_attr.adb
(Cached_Streaming_Ops): A new package, providing maps to save
previously-generated Read/Write/Input/Output procedures.
(Expand_N_Attribute_Reference): When a new subprogram is generated
for a Read/Write/Input/Output attribute reference, record that
type/subp pair in the appropriate Cached_Streaming_Ops map.
(Find_Stream_Subprogram): Check the appropriate
Cached_Streaming_Ops map to see if an appropriate subprogram has
already been generated. If so, then return it. The appropriateness
test includes a call to a new nested subprogram,
In_Available_Context.
* exp_strm.ads, exp_strm.adb: Do not pass in a Loc parameter (or a
source-location-bearing Nod parameter) to the 16 procedures
provided for building streaming-related subprograms. Use the
source location of the type instead.
* exp_dist.adb, exp_ch3.adb: Adapt to Exp_Strm spec changes. For
these calls the source location of the type was already being
used.
gcc/ada/exp_attr.adb
gcc/ada/exp_ch3.adb
gcc/ada/exp_dist.adb
gcc/ada/exp_strm.adb
gcc/ada/exp_strm.ads