aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sinfo-cn.adb
blob: 9fc4e00fcffdeefafd20aa0e3452f98594d1fa45 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
------------------------------------------------------------------------------
--                                                                          --
--                         GNAT COMPILER COMPONENTS                         --
--                                                                          --
--                             S I N F O . C N                              --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--          Copyright (C) 1992-2021, 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.      --
--                                                                          --
------------------------------------------------------------------------------

--  This child package of Sinfo contains some routines that permit in place
--  alteration of existing tree nodes by changing the value in the Nkind
--  field. Since Nkind functions logically in a manner similar to a variant
--  record discriminant part, such alterations cannot be permitted in a
--  general manner, but in some specific cases, the fields of related nodes
--  have been deliberately layed out in a manner that permits such alteration.

with Atree;    use Atree;
with Snames;   use Snames;
with Sinfo.Nodes; use Sinfo.Nodes;
with Sinfo.Utils; use Sinfo.Utils;

package body Sinfo.CN is

   procedure Assert_Expression_Fields_Zero (N : Node_Id);
   --  Asserts that all fields documented in Sinfo as "plus fields for
   --  expression" have their initial zero value. Note that N_Operator_Symbol
   --  is not documented as having "plus fields for expression", but it is in
   --  N_Subexpr, so it does.
   --  ????This is redundant with Check_Vanishing_Fields in Atree.

   -----------------------------------
   -- Assert_Expression_Fields_Zero --
   -----------------------------------

   procedure Assert_Expression_Fields_Zero (N : Node_Id) is
   begin
      pragma Assert (Paren_Count (N) = 0);
      pragma Assert (No (Etype (N)));
      pragma Assert (not Is_Overloaded (N));
      pragma Assert (not Is_Static_Expression (N));
      pragma Assert (not Raises_Constraint_Error (N));
      pragma Assert (not Must_Not_Freeze (N));
      pragma Assert (not Do_Range_Check (N));
      pragma Assert (not Has_Dynamic_Length_Check (N));
      pragma Assert (not Assignment_OK (N));
      pragma Assert (not Is_Controlling_Actual (N));
   end Assert_Expression_Fields_Zero;

   ------------------------------------------------------------
   -- Change_Character_Literal_To_Defining_Character_Literal --
   ------------------------------------------------------------

   procedure Change_Character_Literal_To_Defining_Character_Literal
     (N : Node_Id)
   is
   begin
      Reinit_Field_To_Zero (N, Char_Literal_Value);
--  ????pragma Assert (No (Node2 (N))); -- Char_Literal_Value is Uint2 out of r
      pragma Assert (No (Entity (N)));
      pragma Assert (No (Associated_Node (N)));
      pragma Assert (not Has_Private_View (N));
      Assert_Expression_Fields_Zero (N);

      Extend_Node (N);
   end Change_Character_Literal_To_Defining_Character_Literal;

   ------------------------------------
   -- Change_Conversion_To_Unchecked --
   ------------------------------------

   procedure Change_Conversion_To_Unchecked (N : Node_Id) is
   begin
      Set_Do_Overflow_Check (N, False);
      Set_Do_Tag_Check (N, False);
      Set_Do_Length_Check (N, False);
      Mutate_Nkind (N, N_Unchecked_Type_Conversion);
   end Change_Conversion_To_Unchecked;

   ----------------------------------------------
   -- Change_Identifier_To_Defining_Identifier --
   ----------------------------------------------

   procedure Change_Identifier_To_Defining_Identifier (N : Node_Id) is
   begin
      pragma Assert (No (Entity (N)));
      pragma Assert (No (Associated_Node (N)));
      pragma Assert (No (Original_Discriminant (N)));
      pragma Assert (not Is_Elaboration_Checks_OK_Node (N));
      pragma Assert (not Is_SPARK_Mode_On_Node (N));
      pragma Assert (not Is_Elaboration_Warnings_OK_Node (N));
      pragma Assert (not Has_Private_View (N));
      pragma Assert (not Redundant_Use (N));
      pragma Assert (not Atomic_Sync_Required (N));
      Assert_Expression_Fields_Zero (N);

      Extend_Node (N);
   end Change_Identifier_To_Defining_Identifier;

   ---------------------------------------------
   -- Change_Name_To_Procedure_Call_Statement --
   ---------------------------------------------

   procedure Change_Name_To_Procedure_Call_Statement (N : Node_Id) is
   begin
      --  Case of Indexed component, which is a procedure call with arguments

      if Nkind (N) = N_Indexed_Component then
         declare
            Prefix_Node : constant Node_Id := Prefix (N);
            Exprs_Node  : constant List_Id := Expressions (N);

         begin
            Change_Node (N, N_Procedure_Call_Statement);
            Set_Name (N, Prefix_Node);
            Set_Parameter_Associations (N, Exprs_Node);
         end;

      --  Case of function call node, which is a really a procedure call

      elsif Nkind (N) = N_Function_Call then
         declare
            Fname_Node  : constant Node_Id := Name (N);
            Params_List : constant List_Id := Parameter_Associations (N);

         begin
            Change_Node (N, N_Procedure_Call_Statement);
            Set_Name (N, Fname_Node);
            Set_Parameter_Associations (N, Params_List);
         end;

      --  Case of call to attribute that denotes a procedure. Here we just
      --  leave the attribute reference unchanged.

      elsif Nkind (N) = N_Attribute_Reference
        and then Is_Procedure_Attribute_Name (Attribute_Name (N))
      then
         null;

      --  All other cases of names are parameterless procedure calls

      else
         declare
            Name_Node : constant Node_Id := Relocate_Node (N);
         begin
            Change_Node (N, N_Procedure_Call_Statement);
            Set_Name (N, Name_Node);
         end;
      end if;
   end Change_Name_To_Procedure_Call_Statement;

   --------------------------------------------------------
   -- Change_Operator_Symbol_To_Defining_Operator_Symbol --
   --------------------------------------------------------

   procedure Change_Operator_Symbol_To_Defining_Operator_Symbol
     (N : Node_Id)
   is
   begin
      Reinit_Field_To_Zero (N, Strval);
--  ????pragma Assert (No (Node3 (N))); -- Strval is Str3, 0 is out of range
      pragma Assert (No (Entity (N)));
      pragma Assert (No (Associated_Node (N)));
      pragma Assert (No (Etype (N)));
      pragma Assert (not Has_Private_View (N));
      Assert_Expression_Fields_Zero (N);

      Extend_Node (N);
   end Change_Operator_Symbol_To_Defining_Operator_Symbol;

   ----------------------------------------------
   -- Change_Operator_Symbol_To_String_Literal --
   ----------------------------------------------

   procedure Change_Operator_Symbol_To_String_Literal (N : Node_Id) is
   begin
      Reinit_Field_To_Zero (N, Chars);
      Set_Entity (N, Empty);
--  ????pragma Assert (No (Node1 (N))); -- Chars is Name1 out of range
      pragma Assert (No (Entity (N)));
      pragma Assert (No (Associated_Node (N)));
      pragma Assert (No (Etype (N)));
      pragma Assert (not Has_Private_View (N));

      Mutate_Nkind (N, N_String_Literal);
   end Change_Operator_Symbol_To_String_Literal;

   ------------------------------------------------
   -- Change_Selected_Component_To_Expanded_Name --
   ------------------------------------------------

   procedure Change_Selected_Component_To_Expanded_Name (N : Node_Id) is
   begin
      Mutate_Nkind (N, N_Expanded_Name);
      Set_Chars (N, Chars (Selector_Name (N)));
   end Change_Selected_Component_To_Expanded_Name;

end Sinfo.CN;