aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/exp_put_image.ads
blob: 011cafb29e310730fd009688151f0d447bf426ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
------------------------------------------------------------------------------
--                                                                          --
--                         GNAT COMPILER COMPONENTS                         --
--                                                                          --
--                        E X P _ P U T _ I M A G E                         --
--                                                                          --
--                                 S p e c                                  --
--                                                                          --
--             Copyright (C) 2020-2024, Free Software Foundation, Inc.      --
--                                                                          --
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license.          --
--                                                                          --
-- GNAT was originally developed  by the GNAT team at  New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
--                                                                          --
------------------------------------------------------------------------------

with Types; use Types;

package Exp_Put_Image is

   --  Routines to build Put_Image calls. See Ada.Strings.Text_Buffers.Utils
   --  and System.Put_Images for the run-time routines we are generating calls
   --  to.

   --  For a call to T'Put_Image, if T is elementary, we expand the code
   --  inline. If T is a tagged type, then Put_Image is a primitive procedure
   --  of T, and can be dispatched to in the class-wide case. For untagged
   --  composite types, we generate a procedure the first time we see a call,
   --  and call it. Subsequent calls call the same procedure. Thus, if there
   --  are calls to T'Put_Image in different units, there will be duplicates;
   --  each unit will get a copy of the T'Put_Image procedure.

   function Put_Image_Enabled (Typ : Entity_Id) return Boolean;
   --  True if the predefined Put_Image should be enabled for type T. Put_Image
   --  is always enabled if there is a user-specified one.

   function Build_Put_Image_Profile
     (Loc : Source_Ptr; Typ : Entity_Id) return List_Id;
   --  Builds the parameter profile for Put_Image. This is used for the tagged
   --  case to build the spec for the primitive operation.

   --  In the following Build_... routines, N is the attribute reference node,
   --  from which the procedure to call and the parameters to pass can be
   --  determined.

   function Build_Elementary_Put_Image_Call (N : Node_Id) return Node_Id;
   --  Builds a Put_Image call for an elementary type.

   function Build_String_Put_Image_Call (N : Node_Id) return Node_Id;
   --  Builds a Put_Image call for a standard string type.

   function Build_Protected_Put_Image_Call (N : Node_Id) return Node_Id;
   --  Builds a Put_Image call for a protected type.

   function Build_Task_Put_Image_Call (N : Node_Id) return Node_Id;
   --  Builds a Put_Image call for a task type.

   --  The following routines build the Put_Image procedure for composite
   --  types. Typ is the base type to which the procedure applies (i.e. the
   --  base type of the Put_Image attribute prefix). The returned results are
   --  the declaration and name (entity) of the procedure.

   procedure Build_Array_Put_Image_Procedure
     (Nod  : Node_Id;
      Typ  : Entity_Id;
      Decl : out Node_Id;
      Pnam : out Entity_Id);
   --  Nod provides the Sloc value for the generated code

   procedure Build_Record_Put_Image_Procedure
     (Loc  : Source_Ptr;
      Typ  : Entity_Id;
      Decl : out Node_Id;
      Pnam : out Entity_Id);
   --  Loc is the location of the subprogram declaration

   function Build_Unknown_Put_Image_Call (N : Node_Id) return Node_Id;
   --  Build a call to Put_Image_Unknown

   function Image_Should_Call_Put_Image (N : Node_Id) return Boolean;
   --  True if T'Image should call T'Put_Image. N is the attribute_reference
   --  T'Image.

   function Build_Image_Call (N : Node_Id) return Node_Id;
   --  N is a call to T'[[Wide_]Wide_]Image, and this translates it into the
   --  appropriate code to call T'Put_Image into a buffer and then extract the
   --  [[wide] wide] string from the buffer.

   procedure Preload_Root_Buffer_Type (Compilation_Unit : Node_Id);
   --  Call RTE (RE_Root_Buffer_Type) if necessary, to load the packages
   --  involved in Put_Image. We need to do this explicitly, fairly early
   --  during compilation, because otherwise it happens during freezing, which
   --  triggers visibility bugs in generic instantiations.

end Exp_Put_Image;