-- cannot be used to modify an already-initialized Nkind field. See also
-- Mutate_Nkind.
+ procedure Mutate_Nkind
+ (N : Node_Id; Val : Node_Kind; Old_Size : Field_Offset);
+ -- Called by the other Mutate_Nkind to do all the work. This is needed
+ -- because the call in Change_Node, which calls this one directly, happens
+ -- after zeroing N's slots, which destroys its Nkind, which prevents us
+ -- from properly computing Old_Size.
+
package Field_Checking is
function Field_Present
(Kind : Node_Kind; Field : Node_Field) return Boolean;
end Init_Nkind;
procedure Mutate_Nkind
- (N : Node_Id; Val : Node_Kind)
+ (N : Node_Id; Val : Node_Kind; Old_Size : Field_Offset)
is
- Old_Size : constant Field_Offset := Size_In_Slots (N);
New_Size : constant Field_Offset := Size_In_Slots_To_Alloc (Val);
All_Node_Offsets : Node_Offsets.Table_Type renames
pragma Debug (Validate_Node_Write (N));
end Mutate_Nkind;
+ procedure Mutate_Nkind (N : Node_Id; Val : Node_Kind) is
+ begin
+ Mutate_Nkind (N, Val, Old_Size => Size_In_Slots (N));
+ end Mutate_Nkind;
+
Ekind_Offset : constant Field_Offset :=
Entity_Field_Descriptors (Ekind).Offset;
end if;
if New_Size > Old_Size then
- pragma Debug (Zero_Slots (N));
- Node_Offsets.Table (N) := Alloc_Slots (New_Size);
- end if;
+ declare
+ New_Offset : constant Field_Offset := Alloc_Slots (New_Size);
+ begin
+ pragma Debug (Zero_Slots (N));
+ Node_Offsets.Table (N) := New_Offset;
+ Zero_Slots (New_Offset, New_Offset + New_Size - 1);
+ end;
- Zero_Slots (N);
+ else
+ Zero_Slots (N);
+ end if;
- Mutate_Nkind (N, New_Kind);
+ Mutate_Nkind (N, New_Kind, Old_Size);
Set_Sloc (N, Save_Sloc);
Set_In_List (N, Save_In_List);
function Size_In_Slots (N : Node_Or_Entity_Id) return Field_Offset is
begin
+ pragma Assert (Nkind (N) /= N_Unused_At_Start);
return
(if Nkind (N) in N_Entity then Einfo.Entities.Max_Entity_Size
else Sinfo.Nodes.Size (Nkind (N)));
(N : Entity_Id; Field : Entity_Field) return Boolean;
-- True if the field value is the initial zero value
- procedure Mutate_Nkind
- (N : Node_Id; Val : Node_Kind) with Inline;
+ procedure Mutate_Nkind (N : Node_Id; Val : Node_Kind) with Inline;
-- There is no Set_Nkind in Sinfo.Nodes. We use this instead. This is here,
-- and has a different name, because it does some extra checking. Nkind is
-- like a discriminant, in that it controls which fields exist, and that