with Atree; use Atree;
with Checks; use Checks;
with Einfo; use Einfo;
with Elists; use Elists;
with Exp_Ch2; use Exp_Ch2;
with Exp_Ch9; use Exp_Ch9;
with Exp_Imgv; use Exp_Imgv;
with Exp_Pakd; use Exp_Pakd;
with Exp_Strm; use Exp_Strm;
with Exp_Tss; use Exp_Tss;
with Exp_Util; use Exp_Util;
with Gnatvsn; use Gnatvsn;
with Hostparm; use Hostparm;
with Lib; use Lib;
with Namet; use Namet;
with Nmake; use Nmake;
with Nlists; use Nlists;
with Opt; use Opt;
with Restrict; use Restrict;
with Rident; use Rident;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Ch7; use Sem_Ch7;
with Sem_Ch8; use Sem_Ch8;
with Sem_Eval; use Sem_Eval;
with Sem_Res; use Sem_Res;
with Sem_Util; use Sem_Util;
with Sinfo; use Sinfo;
with Snames; use Snames;
with Stand; use Stand;
with Stringt; use Stringt;
with Tbuild; use Tbuild;
with Ttypes; use Ttypes;
with Uintp; use Uintp;
with Uname; use Uname;
with Validsw; use Validsw;
package body Exp_Attr is
procedure Compile_Stream_Body_In_Scope
(N : Node_Id;
Decl : Node_Id;
Arr : Entity_Id;
Check : Boolean);
procedure Expand_Fpt_Attribute
(N : Node_Id;
Rtp : Entity_Id;
Nam : Name_Id;
Args : List_Id);
procedure Expand_Fpt_Attribute_R (N : Node_Id);
procedure Expand_Fpt_Attribute_RI (N : Node_Id);
procedure Expand_Fpt_Attribute_RR (N : Node_Id);
procedure Expand_Pred_Succ (N : Node_Id);
function Get_Index_Subtype (N : Node_Id) return Entity_Id;
procedure Expand_Access_To_Type (N : Node_Id);
function Find_Inherited_TSS
(Typ : Entity_Id;
Nam : TSS_Name_Type) return Entity_Id;
function Find_Stream_Subprogram
(Typ : Entity_Id;
Nam : TSS_Name_Type) return Entity_Id;
function Get_Stream_Convert_Pragma (T : Entity_Id) return Node_Id;
function Is_Constrained_Packed_Array (Typ : Entity_Id) return Boolean;
procedure Compile_Stream_Body_In_Scope
(N : Node_Id;
Decl : Node_Id;
Arr : Entity_Id;
Check : Boolean)
is
Installed : Boolean := False;
Scop : constant Entity_Id := Scope (Arr);
Curr : constant Entity_Id := Current_Scope;
begin
if Is_Hidden (Arr)
and then not In_Open_Scopes (Scop)
and then Ekind (Scop) = E_Package
then
New_Scope (Scop);
Install_Visible_Declarations (Scop);
Install_Private_Declarations (Scop);
Installed := True;
New_Scope (Curr);
end if;
if Check then
Insert_Action (N, Decl);
else
Insert_Action (N, Decl, All_Checks);
end if;
if Installed then
Pop_Scope;
End_Package_Scope (Scop);
end if;
end Compile_Stream_Body_In_Scope;
procedure Expand_Access_To_Type (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Pref : constant Node_Id := Prefix (N);
Par : Node_Id;
Formal : Entity_Id;
begin
if Is_Entity_Name (Pref)
and then Is_Type (Entity (Pref))
then
if Is_Task_Type (Entity (Pref)) then
Formal :=
First_Entity (Get_Task_Body_Procedure (Entity (Pref)));
while Present (Formal) loop
exit when Chars (Formal) = Name_uTask;
Next_Entity (Formal);
end loop;
pragma Assert (Present (Formal));
Rewrite (N,
Unchecked_Convert_To (Typ, New_Occurrence_Of (Formal, Loc)));
Set_Etype (N, Typ);
else
Par := Parent (N);
while Present (Par) loop
exit when Nkind (Par) = N_Assignment_Statement;
if Nkind (Par) = N_Component_Declaration then
return;
end if;
Par := Parent (Par);
end loop;
if Present (Par) then
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => Make_Identifier (Loc, Name_uInit),
Attribute_Name => Attribute_Name (N)));
Analyze_And_Resolve (N, Typ);
end if;
end if;
end if;
end Expand_Access_To_Type;
procedure Expand_Fpt_Attribute
(N : Node_Id;
Rtp : Entity_Id;
Nam : Name_Id;
Args : List_Id)
is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Pkg : RE_Id;
Fnm : Node_Id;
begin
if Rtp = Standard_Short_Float then
Pkg := RE_Fat_Short_Float;
elsif Rtp = Standard_Float then
Pkg := RE_Fat_Float;
elsif Rtp = Standard_Long_Float then
Pkg := RE_Fat_Long_Float;
else
Pkg := RE_Fat_Long_Long_Float;
end if;
Fnm :=
Make_Selected_Component (Loc,
Prefix => New_Reference_To (RTE (Pkg), Loc),
Selector_Name => Make_Identifier (Loc, Nam));
Rewrite (N,
Unchecked_Convert_To (Base_Type (Etype (N)),
Make_Function_Call (Loc,
Name => Fnm,
Parameter_Associations => Args)));
Analyze_And_Resolve (N, Typ);
end Expand_Fpt_Attribute;
procedure Expand_Fpt_Attribute_R (N : Node_Id) is
E1 : constant Node_Id := First (Expressions (N));
Rtp : constant Entity_Id := Root_Type (Etype (E1));
begin
Expand_Fpt_Attribute
(N, Rtp, Attribute_Name (N),
New_List (Unchecked_Convert_To (Rtp, Relocate_Node (E1))));
end Expand_Fpt_Attribute_R;
procedure Expand_Fpt_Attribute_RI (N : Node_Id) is
E1 : constant Node_Id := First (Expressions (N));
Rtp : constant Entity_Id := Root_Type (Etype (E1));
E2 : constant Node_Id := Next (E1);
begin
Expand_Fpt_Attribute
(N, Rtp, Attribute_Name (N),
New_List (
Unchecked_Convert_To (Rtp, Relocate_Node (E1)),
Unchecked_Convert_To (Standard_Integer, Relocate_Node (E2))));
end Expand_Fpt_Attribute_RI;
procedure Expand_Fpt_Attribute_RR (N : Node_Id) is
E1 : constant Node_Id := First (Expressions (N));
Rtp : constant Entity_Id := Root_Type (Etype (E1));
E2 : constant Node_Id := Next (E1);
begin
Expand_Fpt_Attribute
(N, Rtp, Attribute_Name (N),
New_List (
Unchecked_Convert_To (Rtp, Relocate_Node (E1)),
Unchecked_Convert_To (Rtp, Relocate_Node (E2))));
end Expand_Fpt_Attribute_RR;
procedure Expand_N_Attribute_Reference (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Typ : constant Entity_Id := Etype (N);
Btyp : constant Entity_Id := Base_Type (Typ);
Pref : constant Node_Id := Prefix (N);
Exprs : constant List_Id := Expressions (N);
Id : constant Attribute_Id := Get_Attribute_Id (Attribute_Name (N));
procedure Rewrite_Stream_Proc_Call (Pname : Entity_Id);
procedure Rewrite_Stream_Proc_Call (Pname : Entity_Id) is
Item : constant Node_Id := Next (First (Exprs));
Formal : constant Entity_Id := Next_Formal (First_Formal (Pname));
Formal_Typ : constant Entity_Id := Etype (Formal);
Is_Written : constant Boolean := (Ekind (Formal) /= E_In_Parameter);
begin
if Nkind (Item) = N_Indexed_Component
and then Is_Packed (Base_Type (Etype (Prefix (Item))))
and then Base_Type (Etype (Item)) /= Base_Type (Formal_Typ)
and then Is_Written
then
declare
Temp : constant Entity_Id :=
Make_Defining_Identifier
(Loc, New_Internal_Name ('V'));
Decl : Node_Id;
Assn : Node_Id;
begin
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Temp,
Object_Definition =>
New_Occurrence_Of (Formal_Typ, Loc));
Set_Etype (Temp, Formal_Typ);
Assn :=
Make_Assignment_Statement (Loc,
Name => New_Copy_Tree (Item),
Expression =>
Unchecked_Convert_To
(Etype (Item), New_Occurrence_Of (Temp, Loc)));
Rewrite (Item, New_Occurrence_Of (Temp, Loc));
Insert_Actions (N,
New_List (
Decl,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Pname, Loc),
Parameter_Associations => Exprs),
Assn));
Rewrite (N, Make_Null_Statement (Loc));
return;
end;
end if;
if not Is_Class_Wide_Type (Entity (Pref))
and then not Is_Class_Wide_Type (Etype (Item))
and then Base_Type (Etype (Item)) /= Base_Type (Formal_Typ)
then
Rewrite (Item,
Unchecked_Convert_To (Formal_Typ, Relocate_Node (Item)));
if Is_Untagged_Derivation (Etype (Expression (Item))) then
Set_Assignment_OK (Item);
end if;
end if;
Rewrite (N,
Make_Procedure_Call_Statement (Loc,
Name => New_Occurrence_Of (Pname, Loc),
Parameter_Associations => Exprs));
Analyze (N);
end Rewrite_Stream_Proc_Call;
begin
if Validity_Checks_On and then Validity_Check_Operands
and then Id /= Attribute_Asm_Output
then
declare
Expr : Node_Id;
begin
Expr := First (Expressions (N));
while Present (Expr) loop
Ensure_Valid (Expr);
Next (Expr);
end loop;
end;
end if;
case Id is
when Attribute_Access =>
if Ekind (Btyp) = E_Access_Protected_Subprogram_Type then
declare
Agg : Node_Id;
Sub : Entity_Id;
E_T : constant Entity_Id := Equivalent_Type (Btyp);
Acc : constant Entity_Id :=
Etype (Next_Component (First_Component (E_T)));
Obj_Ref : Node_Id;
Curr : Entity_Id;
begin
if Is_Entity_Name (Pref) then
pragma Assert (In_Open_Scopes (Scope (Entity (Pref))));
Sub :=
New_Occurrence_Of
(Protected_Body_Subprogram (Entity (Pref)), Loc);
Curr := Current_Scope;
while Scope (Curr) /= Scope (Entity (Pref)) loop
Curr := Scope (Curr);
end loop;
Obj_Ref :=
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of
(First_Formal
(Protected_Body_Subprogram (Curr)), Loc),
Attribute_Name => Name_Address);
else
Sub :=
New_Occurrence_Of
(External_Subprogram
(Entity (Selector_Name (Pref))), Loc);
Obj_Ref :=
Make_Attribute_Reference (Loc,
Prefix => Relocate_Node (Prefix (Pref)),
Attribute_Name => Name_Address);
end if;
Agg :=
Make_Aggregate (Loc,
Expressions =>
New_List (
Obj_Ref,
Unchecked_Convert_To (Acc,
Make_Attribute_Reference (Loc,
Prefix => Sub,
Attribute_Name => Name_Address))));
Rewrite (N, Agg);
Analyze_And_Resolve (N, E_T);
Set_Etype (N, Typ);
end;
elsif Ekind (Btyp) = E_General_Access_Type then
declare
Ref_Object : constant Node_Id := Get_Referenced_Object (Pref);
Parm_Ent : Entity_Id;
Conversion : Node_Id;
begin
if Nkind (Ref_Object) = N_Explicit_Dereference
and then Is_Entity_Name (Prefix (Ref_Object))
then
Parm_Ent := Entity (Prefix (Ref_Object));
if Ekind (Parm_Ent) in Formal_Kind
and then Ekind (Etype (Parm_Ent)) = E_Anonymous_Access_Type
and then Present (Extra_Accessibility (Parm_Ent))
then
Conversion :=
Convert_To (Typ, New_Copy_Tree (Prefix (Ref_Object)));
Rewrite (N, Conversion);
Analyze_And_Resolve (N, Typ);
end if;
end if;
end;
else
Expand_Access_To_Type (N);
end if;
when Attribute_Adjacent =>
Expand_Fpt_Attribute_RR (N);
when Attribute_Address => Address : declare
Task_Proc : Entity_Id;
begin
if Is_Entity_Name (Pref)
and then Is_Task_Type (Entity (Pref))
then
Task_Proc := Next_Entity (Root_Type (Etype (Pref)));
while Present (Task_Proc) loop
exit when Ekind (Task_Proc) = E_Procedure
and then Etype (First_Formal (Task_Proc)) =
Corresponding_Record_Type (Etype (Pref));
Next_Entity (Task_Proc);
end loop;
if Present (Task_Proc) then
Set_Entity (Pref, Task_Proc);
Set_Etype (Pref, Etype (Task_Proc));
end if;
elsif Nkind (Pref) = N_Selected_Component
and then Is_Subprogram (Entity (Selector_Name (Pref)))
and then Is_Protected_Type (Scope (Entity (Selector_Name (Pref))))
then
Rewrite (Pref,
New_Occurrence_Of (
External_Subprogram (Entity (Selector_Name (Pref))), Loc));
elsif Nkind (Pref) = N_Explicit_Dereference
and then Ekind (Etype (Pref)) = E_Subprogram_Type
and then Convention (Etype (Pref)) = Convention_Protected
then
declare
Addr : constant Entity_Id := Etype (N);
Ptr : constant Node_Id := Prefix (Pref);
T : constant Entity_Id :=
Equivalent_Type (Base_Type (Etype (Ptr)));
begin
Rewrite (N,
Unchecked_Convert_To (Addr,
Make_Selected_Component (Loc,
Prefix => Unchecked_Convert_To (T, Ptr),
Selector_Name => New_Occurrence_Of (
Next_Entity (First_Entity (T)), Loc))));
Analyze_And_Resolve (N, Addr);
end;
end if;
if Involves_Packed_Array_Reference (Pref) then
Expand_Packed_Address_Reference (N);
end if;
end Address;
when Attribute_Alignment => Alignment : declare
Ptyp : constant Entity_Id := Etype (Pref);
New_Node : Node_Id;
begin
if Is_Entity_Name (Pref)
and then Is_Class_Wide_Type (Entity (Pref))
then
Rewrite (Prefix (N), New_Occurrence_Of (Entity (Pref), Loc));
return;
elsif Is_Class_Wide_Type (Ptyp) then
New_Node :=
Make_Function_Call (Loc,
Name => New_Reference_To
(Find_Prim_Op (Ptyp, Name_uAlignment), Loc),
Parameter_Associations => New_List (Pref));
if Typ /= Standard_Integer then
New_Node := Convert_To (Typ, New_Node);
end if;
Rewrite (N, New_Node);
Analyze_And_Resolve (N, Typ);
return;
else
Apply_Universal_Integer_Attribute_Checks (N);
end if;
end Alignment;
when Attribute_AST_Entry => AST_Entry : declare
Ttyp : Entity_Id;
T_Id : Node_Id;
Eent : Entity_Id;
Entry_Ref : Node_Id;
Index : Node_Id;
begin
if Nkind (Pref) = N_Indexed_Component then
Entry_Ref := Prefix (Pref);
Index := First (Expressions (Pref));
else
Entry_Ref := Pref;
Index := Empty;
end if;
if Nkind (Entry_Ref) = N_Selected_Component then
T_Id :=
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Identity,
Prefix => Prefix (Entry_Ref));
Ttyp := Etype (Prefix (Entry_Ref));
Eent := Entity (Selector_Name (Entry_Ref));
else
T_Id :=
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Current_Task), Loc));
Eent := Entity (Entry_Ref);
Ttyp := Current_Scope;
while not Is_Task_Type (Ttyp) loop
Ttyp := Scope (Ttyp);
end loop;
end if;
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Create_AST_Handler), Loc),
Parameter_Associations => New_List (
T_Id,
Entry_Index_Expression (Loc, Eent, Index, Ttyp))));
Analyze_And_Resolve (N, RTE (RE_AST_Handler));
end AST_Entry;
when Attribute_Bit_Position => Bit_Position :
declare
CE : Entity_Id;
begin
if Nkind (Pref) = N_Identifier then
CE := Entity (Pref);
else
CE := Entity (Selector_Name (Pref));
end if;
if Known_Static_Component_Bit_Offset (CE) then
Rewrite (N,
Make_Integer_Literal (Loc,
Intval => Component_Bit_Offset (CE)));
Analyze_And_Resolve (N, Typ);
else
Apply_Universal_Integer_Attribute_Checks (N);
end if;
end Bit_Position;
when Attribute_Body_Version | Attribute_Version => Version : declare
E : constant Entity_Id :=
Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
Pent : Entity_Id := Entity (Pref);
S : String_Id;
begin
while Pent /= Standard_Standard
and then Scope (Pent) /= Standard_Standard
loop
Pent := Scope (Pent);
end loop;
if Pent = Standard_Standard
or else Pent = Standard_ASCII
then
Rewrite (N,
Make_String_Literal (Loc,
Strval => Verbose_Library_Version));
else
Get_Name_String (Get_Unit_Name (Pent));
Start_String;
for J in 1 .. Name_Len - 2 loop
if Name_Buffer (J) = '.' then
Store_String_Chars ("__");
else
Store_String_Char (Get_Char_Code (Name_Buffer (J)));
end if;
end loop;
if Nkind (Declaration_Node (Pent)) in N_Subprogram_Specification
and then Nkind (Parent (Declaration_Node (Pent))) =
N_Subprogram_Body
and then Acts_As_Spec (Parent (Declaration_Node (Pent)))
then
Store_String_Chars ("B");
elsif not Unit_Requires_Body (Pent) then
Store_String_Chars ("S");
elsif Id = Attribute_Body_Version then
Store_String_Chars ("B");
else
Store_String_Chars ("S");
end if;
S := End_String;
Lib.Version_Referenced (S);
Insert_Actions (N, New_List (
Make_Object_Declaration (Loc,
Defining_Identifier => E,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Unsigned), Loc))));
Set_Is_Imported (E);
Set_Interface_Name (E, Make_String_Literal (Loc, S));
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Reference_To (RTE (RE_Get_Version_String), Loc),
Parameter_Associations => New_List (
New_Occurrence_Of (E, Loc))));
end if;
Analyze_And_Resolve (N, RTE (RE_Version_String));
end Version;
when Attribute_Ceiling =>
Expand_Fpt_Attribute_R (N);
when Attribute_Callable => Callable :
begin
Rewrite (N,
Build_Call_With_Task (Pref, RTE (RE_Callable)));
Analyze_And_Resolve (N, Standard_Boolean);
end Callable;
when Attribute_Caller => Caller : declare
Id_Kind : constant Entity_Id := RTE (RO_AT_Task_Id);
Ent : constant Entity_Id := Entity (Pref);
Conctype : constant Entity_Id := Scope (Ent);
Nest_Depth : Integer := 0;
Name : Node_Id;
S : Entity_Id;
begin
if Is_Protected_Type (Conctype) then
if Abort_Allowed
or else Restriction_Active (No_Entry_Queue) = False
or else Number_Entries (Conctype) > 1
then
Name :=
New_Reference_To
(RTE (RE_Protected_Entry_Caller), Loc);
else
Name :=
New_Reference_To
(RTE (RE_Protected_Single_Entry_Caller), Loc);
end if;
Rewrite (N,
Unchecked_Convert_To (Id_Kind,
Make_Function_Call (Loc,
Name => Name,
Parameter_Associations => New_List
(New_Reference_To (
Object_Ref
(Corresponding_Body (Parent (Conctype))), Loc)))));
else
for J in reverse 0 .. Scope_Stack.Last loop
S := Scope_Stack.Table (J).Entity;
pragma Assert (S /= Conctype);
if S = Ent then
exit;
elsif Is_Entry (S) then
Nest_Depth := Nest_Depth + 1;
end if;
end loop;
Rewrite (N,
Unchecked_Convert_To (Id_Kind,
Make_Function_Call (Loc,
Name => New_Reference_To (
RTE (RE_Task_Entry_Caller), Loc),
Parameter_Associations => New_List (
Make_Integer_Literal (Loc,
Intval => Int (Nest_Depth))))));
end if;
Analyze_And_Resolve (N, Id_Kind);
end Caller;
when Attribute_Compose =>
Expand_Fpt_Attribute_RI (N);
when Attribute_Constrained => Constrained : declare
Formal_Ent : constant Entity_Id := Param_Entity (Pref);
begin
if Present (Formal_Ent)
and then Ekind (Formal_Ent) /= E_Constant
and then Present (Extra_Constrained (Formal_Ent))
then
Rewrite (N,
New_Occurrence_Of
(Extra_Constrained (Formal_Ent), Sloc (N)));
elsif Nkind (Pref) = N_Identifier
and then Ekind (Entity (Pref)) = E_Variable
and then Present (Extra_Constrained (Entity (Pref)))
then
Rewrite (N,
New_Occurrence_Of
(Extra_Constrained (Entity (Pref)), Sloc (N)));
elsif Is_Entity_Name (Pref) then
declare
Ent : constant Entity_Id := Entity (Pref);
Res : Boolean;
begin
if Is_Type (Ent) then
if Is_Private_Type (Ent) then
Res := not Has_Discriminants (Ent)
or else Is_Constrained (Ent);
else
if Is_Composite_Type (Underlying_Type (Ent)) then
Res := Is_Constrained (Ent);
else
Res := True;
end if;
end if;
elsif not Is_Variable (Pref)
or else Present (Formal_Ent)
or else Is_Aliased_View (Pref)
then
Res := True;
else
Res := Is_Constrained (Etype (Ent));
end if;
Rewrite (N,
New_Reference_To (Boolean_Literals (Res), Loc));
end;
else
Rewrite (N,
New_Reference_To (
Boolean_Literals (
not Is_Variable (Pref)
or else Nkind (Pref) = N_Explicit_Dereference
or else Is_Constrained (Etype (Pref))),
Loc));
end if;
Analyze_And_Resolve (N, Standard_Boolean);
end Constrained;
when Attribute_Copy_Sign =>
Expand_Fpt_Attribute_RR (N);
when Attribute_Count => Count :
declare
Entnam : Node_Id;
Index : Node_Id;
Name : Node_Id;
Call : Node_Id;
Conctyp : Entity_Id;
begin
if Nkind (Pref) = N_Indexed_Component then
Entnam := Prefix (Pref);
Index := First (Expressions (Pref));
else
Entnam := Pref;
Index := Empty;
end if;
Conctyp := Current_Scope;
while not Is_Concurrent_Type (Conctyp) loop
Conctyp := Scope (Conctyp);
end loop;
if Is_Protected_Type (Conctyp) then
if Abort_Allowed
or else Restriction_Active (No_Entry_Queue) = False
or else Number_Entries (Conctyp) > 1
then
Name := New_Reference_To (RTE (RE_Protected_Count), Loc);
Call :=
Make_Function_Call (Loc,
Name => Name,
Parameter_Associations => New_List (
New_Reference_To (
Object_Ref (
Corresponding_Body (Parent (Conctyp))), Loc),
Entry_Index_Expression (
Loc, Entity (Entnam), Index, Scope (Entity (Entnam)))));
else
Name := New_Reference_To (RTE (RE_Protected_Count_Entry), Loc);
Call := Make_Function_Call (Loc,
Name => Name,
Parameter_Associations => New_List (
New_Reference_To (
Object_Ref (
Corresponding_Body (Parent (Conctyp))), Loc)));
end if;
else
Call :=
Make_Function_Call (Loc,
Name => New_Reference_To (RTE (RE_Task_Count), Loc),
Parameter_Associations => New_List (
Entry_Index_Expression
(Loc, Entity (Entnam), Index, Scope (Entity (Entnam)))));
end if;
if Base_Type (Typ) /= Base_Type (Standard_Integer) then
Rewrite (N, Convert_To (Typ, Call));
else
Rewrite (N, Call);
end if;
Analyze_And_Resolve (N, Typ);
end Count;
when Attribute_Elab_Body |
Attribute_Elab_Spec =>
Elab_Body : declare
Ent : constant Entity_Id :=
Make_Defining_Identifier (Loc,
New_Internal_Name ('E'));
Str : String_Id;
Lang : Node_Id;
procedure Make_Elab_String (Nod : Node_Id);
procedure Make_Elab_String (Nod : Node_Id) is
begin
if Nkind (Nod) = N_Selected_Component then
Make_Elab_String (Prefix (Nod));
if Java_VM then
Store_String_Char ('$');
else
Store_String_Char ('_');
Store_String_Char ('_');
end if;
Get_Name_String (Chars (Selector_Name (Nod)));
else
pragma Assert (Nkind (Nod) = N_Identifier);
Get_Name_String (Chars (Nod));
end if;
Store_String_Chars (Name_Buffer (1 .. Name_Len));
end Make_Elab_String;
begin
Start_String;
Make_Elab_String (Pref);
if Java_VM then
Store_String_Chars ("._elab");
Lang := Make_Identifier (Loc, Name_Ada);
else
Store_String_Chars ("___elab");
Lang := Make_Identifier (Loc, Name_C);
end if;
if Id = Attribute_Elab_Body then
Store_String_Char ('b');
else
Store_String_Char ('s');
end if;
Str := End_String;
Insert_Actions (N, New_List (
Make_Subprogram_Declaration (Loc,
Specification =>
Make_Procedure_Specification (Loc,
Defining_Unit_Name => Ent)),
Make_Pragma (Loc,
Chars => Name_Import,
Pragma_Argument_Associations => New_List (
Make_Pragma_Argument_Association (Loc,
Expression => Lang),
Make_Pragma_Argument_Association (Loc,
Expression =>
Make_Identifier (Loc, Chars (Ent))),
Make_Pragma_Argument_Association (Loc,
Expression =>
Make_String_Literal (Loc, Str))))));
Set_Entity (N, Ent);
Rewrite (N, New_Occurrence_Of (Ent, Loc));
end Elab_Body;
when Attribute_Elaborated => Elaborated : declare
Ent : constant Entity_Id := Entity (Pref);
begin
if Present (Elaboration_Entity (Ent)) then
Rewrite (N,
New_Occurrence_Of (Elaboration_Entity (Ent), Loc));
else
Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
end if;
end Elaborated;
when Attribute_Enum_Rep => Enum_Rep :
begin
if Is_Non_Empty_List (Exprs) then
Rewrite (N,
OK_Convert_To (Typ, Relocate_Node (First (Exprs))));
elsif Ekind (Entity (Pref)) = E_Enumeration_Literal then
Rewrite (N,
Make_Integer_Literal (Loc, Enumeration_Rep (Entity (Pref))));
elsif Ekind (Entity (Pref)) = E_Constant
and then Present (Renamed_Object (Entity (Pref)))
and then
Ekind (Entity (Renamed_Object (Entity (Pref))))
= E_Enumeration_Literal
then
Rewrite (N,
Make_Integer_Literal (Loc,
Enumeration_Rep (Entity (Renamed_Object (Entity (Pref))))));
else
Rewrite (N,
OK_Convert_To (Typ, Relocate_Node (Pref)));
end if;
Set_Etype (N, Typ);
Analyze_And_Resolve (N, Typ);
end Enum_Rep;
when Attribute_Exponent =>
Expand_Fpt_Attribute_R (N);
when Attribute_External_Tag => External_Tag :
begin
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Reference_To (RTE (RE_External_Tag), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Tag,
Prefix => Prefix (N)))));
Analyze_And_Resolve (N, Standard_String);
end External_Tag;
when Attribute_First => declare
Ptyp : constant Entity_Id := Etype (Pref);
begin
if Is_Constrained_Packed_Array (Ptyp) then
Rewrite (N,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_First,
Prefix => New_Reference_To (Get_Index_Subtype (N), Loc)));
Analyze_And_Resolve (N, Typ);
elsif Is_Access_Type (Ptyp) then
Apply_Access_Check (N);
end if;
end;
when Attribute_First_Bit => First_Bit :
declare
CE : constant Entity_Id := Entity (Selector_Name (Pref));
begin
if Known_Static_Component_Bit_Offset (CE) then
Rewrite (N,
Make_Integer_Literal (Loc,
Component_Bit_Offset (CE) mod System_Storage_Unit));
Analyze_And_Resolve (N, Typ);
else
Apply_Universal_Integer_Attribute_Checks (N);
end if;
end First_Bit;
when Attribute_Fixed_Value => Fixed_Value :
begin
Rewrite (N,
Make_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Entity (Pref), Loc),
Expression => Relocate_Node (First (Exprs))));
Set_Etype (N, Entity (Pref));
Set_Analyzed (N);
Apply_Type_Conversion_Checks (N);
end Fixed_Value;
when Attribute_Floor =>
Expand_Fpt_Attribute_R (N);
when Attribute_Fore => Fore :
declare
Ptyp : constant Entity_Id := Etype (Pref);
begin
Rewrite (N,
Convert_To (Typ,
Make_Function_Call (Loc,
Name => New_Reference_To (RTE (RE_Fore), Loc),
Parameter_Associations => New_List (
Convert_To (Standard_Long_Long_Float,
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Ptyp, Loc),
Attribute_Name => Name_First)),
Convert_To (Standard_Long_Long_Float,
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Ptyp, Loc),
Attribute_Name => Name_Last))))));
Analyze_And_Resolve (N, Typ);
end Fore;
when Attribute_Fraction =>
Expand_Fpt_Attribute_R (N);
when Attribute_Identity => Identity : declare
Id_Kind : Entity_Id;
begin
if Etype (Pref) = Standard_Exception_Type then
Id_Kind := RTE (RE_Exception_Id);
if Present (Renamed_Object (Entity (Pref))) then
Set_Entity (Pref, Renamed_Object (Entity (Pref)));
end if;
Rewrite (N,
Unchecked_Convert_To (Id_Kind, Make_Reference (Loc, Pref)));
else
Id_Kind := RTE (RO_AT_Task_Id);
Rewrite (N,
Unchecked_Convert_To (Id_Kind, Concurrent_Ref (Pref)));
end if;
Analyze_And_Resolve (N, Id_Kind);
end Identity;
when Attribute_Image =>
Exp_Imgv.Expand_Image_Attribute (N);
when Attribute_Img => Img :
begin
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Etype (Pref), Loc),
Attribute_Name => Name_Image,
Expressions => New_List (Relocate_Node (Pref))));
Analyze_And_Resolve (N, Standard_String);
end Img;
when Attribute_Input => Input : declare
P_Type : constant Entity_Id := Entity (Pref);
B_Type : constant Entity_Id := Base_Type (P_Type);
U_Type : constant Entity_Id := Underlying_Type (P_Type);
Strm : constant Node_Id := First (Exprs);
Fname : Entity_Id;
Decl : Node_Id;
Call : Node_Id;
Prag : Node_Id;
Arg2 : Node_Id;
Rfunc : Node_Id;
Cntrl : Node_Id := Empty;
procedure Freeze_Stream_Subprogram (F : Entity_Id);
procedure Freeze_Stream_Subprogram (F : Entity_Id) is
Decl : constant Node_Id := Unit_Declaration_Node (F);
Bod : Node_Id;
begin
if Present (Decl)
and then Nkind (Decl) = N_Subprogram_Declaration
and then Present (Corresponding_Body (Decl))
then
Bod := Corresponding_Body (Decl);
if Nkind (Unit_Declaration_Node (Bod)) =
N_Subprogram_Renaming_Declaration
then
Set_Is_Frozen (Entity (Name (Unit_Declaration_Node (Bod))));
end if;
end if;
end Freeze_Stream_Subprogram;
begin
if No (U_Type) then
return;
end if;
Fname := Find_Stream_Subprogram (P_Type, TSS_Stream_Input);
if Present (Fname) then
null;
else
Prag := Get_Stream_Convert_Pragma (P_Type);
if Present (Prag) then
Arg2 := Next (First (Pragma_Argument_Associations (Prag)));
Rfunc := Entity (Expression (Arg2));
Rewrite (N,
Convert_To (B_Type,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Rfunc, Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of
(Etype (First_Formal (Rfunc)), Loc),
Attribute_Name => Name_Input,
Expressions => Exprs)))));
Analyze_And_Resolve (N, B_Type);
return;
elsif Is_Elementary_Type (U_Type) then
if Present (TSS (Base_Type (U_Type), TSS_Stream_Read)) then
Build_Record_Or_Elementary_Input_Function
(Loc, U_Type, Decl, Fname);
Insert_Action (N, Decl);
else
Rewrite (N, Build_Elementary_Input_Call (N));
Analyze_And_Resolve (N, P_Type);
return;
end if;
elsif Is_Array_Type (U_Type) then
Build_Array_Input_Function (Loc, U_Type, Decl, Fname);
Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False);
elsif Is_Class_Wide_Type (P_Type) then
declare
Rtyp : constant Entity_Id := Root_Type (P_Type);
Dnn : Entity_Id;
Decl : Node_Id;
begin
Dnn :=
Make_Defining_Identifier (Loc,
Chars => New_Internal_Name ('D'));
Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Dnn,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Tag), Loc),
Expression =>
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Internal_Tag), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Standard_String, Loc),
Attribute_Name => Name_Input,
Expressions => New_List (
Relocate_Node
(Duplicate_Subexpr (Strm)))))));
Insert_Action (N, Decl);
Fname := Find_Prim_Op (Rtyp, TSS_Stream_Input);
Cntrl := Unchecked_Convert_To (P_Type,
New_Occurrence_Of (Dnn, Loc));
Set_Etype (Cntrl, P_Type);
Set_Parent (Cntrl, N);
end;
elsif Is_Tagged_Type (U_Type) then
Fname := Find_Prim_Op (U_Type, TSS_Stream_Input);
else
pragma Assert
(Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type));
if Is_Unchecked_Union (Base_Type (U_Type))
and then not Present (Discriminant_Constraint (U_Type))
then
Insert_Action (N,
Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction));
return;
end if;
Build_Record_Or_Elementary_Input_Function
(Loc, Base_Type (U_Type), Decl, Fname);
Insert_Action (N, Decl);
if Nkind (Parent (N)) = N_Object_Declaration
and then Is_Record_Type (U_Type)
then
declare
Comp : Entity_Id;
Func : Entity_Id;
begin
Comp := First_Component (U_Type);
while Present (Comp) loop
Func :=
Find_Stream_Subprogram
(Etype (Comp), TSS_Stream_Read);
if Present (Func) then
Freeze_Stream_Subprogram (Func);
end if;
Next_Component (Comp);
end loop;
end;
end if;
end if;
end if;
Call :=
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Fname, Loc),
Parameter_Associations => New_List (
Relocate_Node (Strm)));
Set_Controlling_Argument (Call, Cntrl);
Rewrite (N, Unchecked_Convert_To (P_Type, Call));
Analyze_And_Resolve (N, P_Type);
if Nkind (Parent (N)) = N_Object_Declaration then
Freeze_Stream_Subprogram (Fname);
end if;
end Input;
when Attribute_Integer_Value => Integer_Value :
begin
Rewrite (N,
Make_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Entity (Pref), Loc),
Expression => Relocate_Node (First (Exprs))));
Set_Etype (N, Entity (Pref));
Set_Analyzed (N);
Apply_Type_Conversion_Checks (N);
end Integer_Value;
when Attribute_Last => declare
Ptyp : constant Entity_Id := Etype (Pref);
begin
if Is_Constrained_Packed_Array (Ptyp) then
Rewrite (N,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Last,
Prefix => New_Reference_To (Get_Index_Subtype (N), Loc)));
Analyze_And_Resolve (N, Typ);
elsif Is_Access_Type (Ptyp) then
Apply_Access_Check (N);
end if;
end;
when Attribute_Last_Bit => Last_Bit :
declare
CE : constant Entity_Id := Entity (Selector_Name (Pref));
begin
if Known_Static_Component_Bit_Offset (CE)
and then Known_Static_Esize (CE)
then
Rewrite (N,
Make_Integer_Literal (Loc,
Intval => (Component_Bit_Offset (CE) mod System_Storage_Unit)
+ Esize (CE) - 1));
Analyze_And_Resolve (N, Typ);
else
Apply_Universal_Integer_Attribute_Checks (N);
end if;
end Last_Bit;
when Attribute_Leading_Part =>
Expand_Fpt_Attribute_RI (N);
when Attribute_Length => declare
Ptyp : constant Entity_Id := Etype (Pref);
Ityp : Entity_Id;
Xnum : Uint;
begin
if Is_Array_Type (Ptyp) and then Is_Packed (Ptyp) then
Ityp := Get_Index_Subtype (N);
if Is_Enumeration_Type (Ityp)
and then Present (Enum_Pos_To_Rep (Base_Type (Ityp)))
then
if No (Exprs) then
Xnum := Uint_1;
else
Xnum := Expr_Value (First (Expressions (N)));
end if;
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Max,
Expressions => New_List
(Make_Integer_Literal (Loc, 0),
Make_Op_Add (Loc,
Left_Opnd =>
Make_Op_Subtract (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Ityp, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (Pref),
Attribute_Name => Name_Last,
Expressions => New_List (
Make_Integer_Literal (Loc, Xnum))))),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Ityp, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
Duplicate_Subexpr_No_Checks (Pref),
Attribute_Name => Name_First,
Expressions => New_List (
Make_Integer_Literal (Loc, Xnum)))))),
Right_Opnd => Make_Integer_Literal (Loc, 1)))));
Analyze_And_Resolve (N, Typ, Suppress => All_Checks);
return;
elsif Is_Constrained (Ptyp) then
Rewrite (N,
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Range_Length,
Prefix => New_Reference_To (Ityp, Loc)));
Analyze_And_Resolve (N, Typ);
end if;
elsif Is_Access_Type (Ptyp) then
Apply_Access_Check (N);
declare
Dtyp : constant Entity_Id := Designated_Type (Ptyp);
Xtyp : Entity_Id;
begin
if Is_Array_Type (Dtyp) and then Is_Packed (Dtyp) then
Xtyp := Get_Index_Subtype (N);
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc),
Attribute_Name => Name_Max,
Expressions => New_List (
Make_Integer_Literal (Loc, 0),
Make_Op_Add (Loc,
Make_Integer_Literal (Loc, 1),
Make_Op_Subtract (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Xtyp, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix => Duplicate_Subexpr (Pref),
Attribute_Name => Name_Last,
Expressions =>
New_Copy_List (Exprs)))),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Xtyp, Loc),
Attribute_Name => Name_Pos,
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
Duplicate_Subexpr_No_Checks (Pref),
Attribute_Name => Name_First,
Expressions =>
New_Copy_List (Exprs)))))))));
Analyze_And_Resolve (N, Typ);
end if;
end;
else
Apply_Universal_Integer_Attribute_Checks (N);
end if;
end;
when Attribute_Machine =>
Expand_Fpt_Attribute_R (N);
when Attribute_Machine_Size =>
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => Prefix (N),
Attribute_Name => Name_Object_Size));
Analyze_And_Resolve (N, Typ);
when Attribute_Mantissa => Mantissa : declare
Ptyp : constant Entity_Id := Etype (Pref);
begin
Rewrite (N,
Convert_To (Typ,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (RTE (RE_Mantissa_Value), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Standard_Integer, Loc),
Attribute_Name => Name_Integer_Value,
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Ptyp, Loc),
Attribute_Name => Name_First))),
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Standard_Integer, Loc),
Attribute_Name => Name_Integer_Value,
Expressions => New_List (
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Ptyp, Loc),
Attribute_Name => Name_Last)))))));
Analyze_And_Resolve (N, Typ);
end Mantissa;
when Attribute_Mod => Mod_Case : declare
Arg : constant Node_Id := Relocate_Node (First (Exprs));
Hi : constant Node_Id := Type_High_Bound (Etype (Arg));
Modv : constant Uint := Modulus (Btyp);
begin
if Modv <= Expr_Value (Hi) then
Rewrite (N,
Convert_To (Btyp,
Make_Op_Mod (Loc,
Left_Opnd => Arg,
Right_Opnd => Make_Integer_Literal (Loc, Modv))));
else
Rewrite (N,
Make_Conditional_Expression (Loc,
Expressions => New_List (
Make_Op_Ge (Loc,
Left_Opnd => Duplicate_Subexpr (Arg),
Right_Opnd => Make_Integer_Literal (Loc, 0)),
Convert_To (Btyp,
Duplicate_Subexpr_No_Checks (Arg)),
Make_Op_Subtract (Loc,
Left_Opnd =>
Make_Integer_Literal (Loc,
Intval => Modv - 1),
Right_Opnd =>
Convert_To (Btyp,
Make_Op_Minus (Loc,
Right_Opnd =>
Make_Op_Add (Loc,
Left_Opnd => Duplicate_Subexpr_No_Checks (Arg),
Right_Opnd =>
Make_Integer_Literal (Loc,
Intval => 1))))))));
end if;
Analyze_And_Resolve (N, Btyp);
end Mod_Case;
when Attribute_Model =>
Expand_Fpt_Attribute_R (N);
when Attribute_Output => Output : declare
P_Type : constant Entity_Id := Entity (Pref);
U_Type : constant Entity_Id := Underlying_Type (P_Type);
Pname : Entity_Id;
Decl : Node_Id;
Prag : Node_Id;
Arg3 : Node_Id;
Wfunc : Node_Id;
begin
if No (U_Type) then
return;
end if;
Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Output);
if Present (Pname) then
null;
else
Prag := Get_Stream_Convert_Pragma (P_Type);
if Present (Prag) then
Arg3 :=
Next (Next (First (Pragma_Argument_Associations (Prag))));
Wfunc := Entity (Expression (Arg3));
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Etype (Wfunc), Loc),
Attribute_Name => Name_Output,
Expressions => New_List (
Relocate_Node (First (Exprs)),
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Wfunc, Loc),
Parameter_Associations => New_List (
Convert_To (Etype (First_Formal (Wfunc)),
Relocate_Node (Next (First (Exprs)))))))));
Analyze (N);
return;
elsif Is_Elementary_Type (U_Type) then
if Present (TSS (Base_Type (U_Type), TSS_Stream_Write)) then
Build_Record_Or_Elementary_Output_Procedure
(Loc, U_Type, Decl, Pname);
Insert_Action (N, Decl);
else
Rewrite (N, Build_Elementary_Write_Call (N));
Analyze (N);
return;
end if;
elsif Is_Array_Type (U_Type) then
Build_Array_Output_Procedure (Loc, U_Type, Decl, Pname);
Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False);
elsif Is_Class_Wide_Type (P_Type) then
Tag_Write : declare
Strm : constant Node_Id := First (Exprs);
Item : constant Node_Id := Next (Strm);
begin
Insert_Action (N,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Standard_String, Loc),
Attribute_Name => Name_Output,
Expressions => New_List (
Relocate_Node (Duplicate_Subexpr (Strm)),
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_External_Tag), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
Relocate_Node
(Duplicate_Subexpr (Item, Name_Req => True)),
Attribute_Name => Name_Tag))))));
end Tag_Write;
Pname := Find_Prim_Op (U_Type, TSS_Stream_Output);
elsif Is_Tagged_Type (U_Type) then
Pname := Find_Prim_Op (U_Type, TSS_Stream_Output);
else
pragma Assert
(Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type));
if Is_Unchecked_Union (Base_Type (U_Type))
and then not Present (Discriminant_Constraint (U_Type))
then
Insert_Action (N,
Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction));
return;
end if;
Build_Record_Or_Elementary_Output_Procedure
(Loc, Base_Type (U_Type), Decl, Pname);
Insert_Action (N, Decl);
end if;
end if;
Rewrite_Stream_Proc_Call (Pname);
end Output;
when Attribute_Pos => Pos :
declare
Etyp : Entity_Id := Base_Type (Entity (Pref));
begin
if Is_Boolean_Type (Etyp) then
Adjust_Condition (First (Exprs));
Etyp := Standard_Boolean;
Set_Prefix (N, New_Occurrence_Of (Standard_Boolean, Loc));
end if;
if Is_Enumeration_Type (Etyp) then
if Present (Enum_Pos_To_Rep (Etyp)) then
Append_To (Exprs, Rep_To_Pos_Flag (Etyp, Loc));
Rewrite (N,
Convert_To (Typ,
Make_Function_Call (Loc,
Name =>
New_Reference_To (TSS (Etyp, TSS_Rep_To_Pos), Loc),
Parameter_Associations => Exprs)));
Analyze_And_Resolve (N, Typ);
else
Apply_Universal_Integer_Attribute_Checks (N);
end if;
elsif Is_Integer_Type (Etyp) then
Rewrite (N, Convert_To (Typ, First (Exprs)));
Analyze_And_Resolve (N, Typ);
end if;
end Pos;
when Attribute_Position => Position :
declare
CE : constant Entity_Id := Entity (Selector_Name (Pref));
begin
if Present (Component_Clause (CE)) then
Rewrite (N,
Make_Integer_Literal (Loc,
Intval => Component_Bit_Offset (CE) / System_Storage_Unit));
Analyze_And_Resolve (N, Typ);
else
Apply_Universal_Integer_Attribute_Checks (N);
end if;
end Position;
when Attribute_Pred => Pred :
declare
Ptyp : constant Entity_Id := Base_Type (Etype (Pref));
begin
if Is_Enumeration_Type (Ptyp)
and then Present (Enum_Pos_To_Rep (Ptyp))
then
if Has_Contiguous_Rep (Ptyp) then
Rewrite (N,
Unchecked_Convert_To (Ptyp,
Make_Op_Add (Loc,
Left_Opnd =>
Make_Integer_Literal (Loc,
Enumeration_Rep (First_Literal (Ptyp))),
Right_Opnd =>
Make_Function_Call (Loc,
Name =>
New_Reference_To
(TSS (Ptyp, TSS_Rep_To_Pos), Loc),
Parameter_Associations =>
New_List (
Unchecked_Convert_To (Ptyp,
Make_Op_Subtract (Loc,
Left_Opnd =>
Unchecked_Convert_To (Standard_Integer,
Relocate_Node (First (Exprs))),
Right_Opnd =>
Make_Integer_Literal (Loc, 1))),
Rep_To_Pos_Flag (Ptyp, Loc))))));
else
Append_To (Exprs, Rep_To_Pos_Flag (Ptyp, Loc));
Rewrite (N,
Make_Indexed_Component (Loc,
Prefix => New_Reference_To (Enum_Pos_To_Rep (Ptyp), Loc),
Expressions => New_List (
Make_Op_Subtract (Loc,
Left_Opnd =>
Make_Function_Call (Loc,
Name =>
New_Reference_To (TSS (Ptyp, TSS_Rep_To_Pos), Loc),
Parameter_Associations => Exprs),
Right_Opnd => Make_Integer_Literal (Loc, 1)))));
end if;
Analyze_And_Resolve (N, Typ);
elsif Is_Floating_Point_Type (Ptyp) then
Expand_Fpt_Attribute_R (N);
Analyze_And_Resolve (N, Typ);
elsif Is_Modular_Integer_Type (Ptyp) then
null;
elsif not Overflow_Checks_Suppressed (Ptyp) then
Expand_Pred_Succ (N);
end if;
end Pred;
when Attribute_Range_Length => Range_Length : declare
P_Type : constant Entity_Id := Etype (Pref);
begin
if Is_Enumeration_Type (P_Type)
and then Has_Non_Standard_Rep (P_Type)
then
Rewrite (N,
Make_Op_Add (Loc,
Left_Opnd =>
Make_Op_Subtract (Loc,
Left_Opnd =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Pos,
Prefix => New_Occurrence_Of (P_Type, Loc),
Expressions => New_List (
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Last,
Prefix => New_Occurrence_Of (P_Type, Loc)))),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Attribute_Name => Name_Pos,
Prefix => New_Occurrence_Of (P_Type, Loc),
Expressions => New_List (
Make_Attribute_Reference (Loc,
Attribute_Name => Name_First,
Prefix => New_Occurrence_Of (P_Type, Loc))))),
Right_Opnd =>
Make_Integer_Literal (Loc, 1)));
Analyze_And_Resolve (N, Typ);
else
Apply_Universal_Integer_Attribute_Checks (N);
end if;
end Range_Length;
when Attribute_Read => Read : declare
P_Type : constant Entity_Id := Entity (Pref);
B_Type : constant Entity_Id := Base_Type (P_Type);
U_Type : constant Entity_Id := Underlying_Type (P_Type);
Pname : Entity_Id;
Decl : Node_Id;
Prag : Node_Id;
Arg2 : Node_Id;
Rfunc : Node_Id;
Lhs : Node_Id;
Rhs : Node_Id;
begin
if No (U_Type) then
return;
end if;
Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Read);
if Present (Pname) then
null;
else
Prag := Get_Stream_Convert_Pragma (P_Type);
if Present (Prag) then
Arg2 := Next (First (Pragma_Argument_Associations (Prag)));
Rfunc := Entity (Expression (Arg2));
Lhs := Relocate_Node (Next (First (Exprs)));
Rhs :=
Convert_To (B_Type,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Rfunc, Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of
(Etype (First_Formal (Rfunc)), Loc),
Attribute_Name => Name_Input,
Expressions => New_List (
Relocate_Node (First (Exprs)))))));
if Nkind (Lhs) = N_Type_Conversion then
Lhs := Expression (Lhs);
Rhs := Convert_To (Etype (Lhs), Rhs);
end if;
Rewrite (N,
Make_Assignment_Statement (Loc,
Name => Lhs,
Expression => Rhs));
Set_Assignment_OK (Lhs);
Analyze (N);
return;
elsif Is_Elementary_Type (U_Type) then
declare
Lhs : Node_Id;
Rhs : Node_Id;
begin
Lhs := Relocate_Node (Next (First (Exprs)));
Rhs := Build_Elementary_Input_Call (N);
if Nkind (Lhs) = N_Type_Conversion then
Lhs := Expression (Lhs);
Rhs := Convert_To (Etype (Lhs), Rhs);
end if;
Set_Assignment_OK (Lhs);
Rewrite (N,
Make_Assignment_Statement (Loc,
Name => Lhs,
Expression => Rhs));
Analyze (N);
return;
end;
elsif Is_Array_Type (U_Type) then
Build_Array_Read_Procedure (N, U_Type, Decl, Pname);
Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False);
elsif Is_Tagged_Type (U_Type) then
Pname := Find_Prim_Op (U_Type, TSS_Stream_Read);
else
pragma Assert
(Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type));
if Is_Unchecked_Union (Base_Type (U_Type)) then
Insert_Action (N,
Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction));
end if;
if Has_Discriminants (U_Type)
and then Present
(Discriminant_Default_Value (First_Discriminant (U_Type)))
then
Build_Mutable_Record_Read_Procedure
(Loc, Base_Type (U_Type), Decl, Pname);
else
Build_Record_Read_Procedure
(Loc, Base_Type (U_Type), Decl, Pname);
end if;
Insert_Action (N, Decl, All_Checks);
end if;
end if;
Rewrite_Stream_Proc_Call (Pname);
end Read;
when Attribute_Remainder =>
Expand_Fpt_Attribute_RR (N);
when Attribute_Round =>
Rewrite (N,
Convert_To (Etype (N), Relocate_Node (First (Exprs))));
Analyze_And_Resolve (N);
when Attribute_Rounding =>
Expand_Fpt_Attribute_R (N);
when Attribute_Scaling =>
Expand_Fpt_Attribute_RI (N);
when Attribute_Size |
Attribute_Object_Size |
Attribute_Value_Size |
Attribute_VADS_Size => Size :
declare
Ptyp : constant Entity_Id := Etype (Pref);
Siz : Uint;
New_Node : Node_Id;
begin
if Id = Attribute_VADS_Size
or else (Use_VADS_Size and then Id = Attribute_Size)
then
if (Is_Entity_Name (Pref)
and then Present (Size_Clause (Entity (Pref))))
or else
(Nkind (Pref) = N_Component_Clause
and then (Present (Component_Clause
(Entity (Selector_Name (Pref))))
or else Is_Packed (Etype (Prefix (Pref)))))
or else
(Nkind (Pref) = N_Indexed_Component
and then (Component_Size (Etype (Prefix (Pref))) /= 0
or else Is_Packed (Etype (Prefix (Pref)))))
then
Set_Attribute_Name (N, Name_Size);
else
if (not Is_Entity_Name (Pref)
or else not Is_Type (Entity (Pref)))
and then (Is_Scalar_Type (Etype (Pref))
or else Is_Constrained (Etype (Pref)))
then
Rewrite (Pref, New_Occurrence_Of (Etype (Pref), Loc));
end if;
if Is_Scalar_Type (Etype (Pref))
and then No (Size_Clause (Etype (Pref)))
then
Set_Attribute_Name (N, Name_Object_Size);
else
Set_Attribute_Name (N, Name_Size);
end if;
end if;
end if;
if Is_Entity_Name (Pref)
and then Is_Class_Wide_Type (Entity (Pref))
then
Rewrite (Prefix (N), New_Occurrence_Of (Entity (Pref), Loc));
return;
elsif Is_Class_Wide_Type (Ptyp) then
New_Node :=
Make_Function_Call (Loc,
Name => New_Reference_To
(Find_Prim_Op (Ptyp, Name_uSize), Loc),
Parameter_Associations => New_List (Pref));
if Typ /= Standard_Long_Long_Integer then
New_Node := Convert_To (Typ, New_Node);
end if;
Rewrite (N, New_Node);
Analyze_And_Resolve (N, Typ);
return;
elsif Nkind (Pref) = N_Indexed_Component then
Siz := Component_Size (Etype (Prefix (Pref)));
elsif Nkind (Pref) = N_Selected_Component then
declare
Rec : constant Entity_Id := Etype (Prefix (Pref));
Comp : constant Entity_Id := Entity (Selector_Name (Pref));
begin
if Present (Component_Clause (Comp)) then
Siz := Esize (Comp);
elsif Is_Packed (Rec) then
Siz := RM_Size (Ptyp);
else
Apply_Universal_Integer_Attribute_Checks (N);
return;
end if;
end;
else
Apply_Universal_Integer_Attribute_Checks (N);
if Is_Entity_Name (Pref)
and then Is_Formal (Entity (Pref))
and then Is_Array_Type (Etype (Pref))
and then Is_Packed (Etype (Pref))
then
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix =>
New_Occurrence_Of (Get_Actual_Subtype (Pref), Loc),
Attribute_Name => Name_Size));
Analyze_And_Resolve (N, Typ);
end if;
return;
end if;
if Siz /= 0 then
Rewrite (N, Make_Integer_Literal (Loc, Siz));
Analyze_And_Resolve (N, Typ);
Set_Is_Static_Expression (N, False);
end if;
end Size;
when Attribute_Storage_Pool =>
Rewrite (N,
Make_Type_Conversion (Loc,
Subtype_Mark => New_Reference_To (Etype (N), Loc),
Expression => New_Reference_To (Entity (N), Loc)));
Analyze_And_Resolve (N, Typ);
when Attribute_Storage_Size => Storage_Size :
declare
Ptyp : constant Entity_Id := Etype (Pref);
begin
if Is_Access_Type (Ptyp) then
if Present (Storage_Size_Variable (Root_Type (Ptyp))) then
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => New_Reference_To (Typ, Loc),
Attribute_Name => Name_Max,
Expressions => New_List (
Make_Integer_Literal (Loc, 0),
Convert_To (Typ,
New_Reference_To
(Storage_Size_Variable (Root_Type (Ptyp)), Loc)))));
elsif Present (Associated_Storage_Pool (Root_Type (Ptyp))) then
Rewrite (N,
OK_Convert_To (Typ,
Make_Function_Call (Loc,
Name =>
New_Reference_To
(Find_Prim_Op
(Etype (Associated_Storage_Pool (Root_Type (Ptyp))),
Attribute_Name (N)),
Loc),
Parameter_Associations => New_List (New_Reference_To (
Associated_Storage_Pool (Root_Type (Ptyp)), Loc)))));
else
Rewrite (N, Make_Integer_Literal (Loc, 0));
end if;
Analyze_And_Resolve (N, Typ);
else
if not Present (Storage_Size_Variable (Ptyp)) then
Rewrite (N,
Convert_To (Typ,
Make_Function_Call (Loc,
Name =>
New_Occurrence_Of (RTE (RE_Default_Stack_Size), Loc))));
else
if not (Is_Entity_Name (Pref) and then
Is_Task_Type (Entity (Pref))) and then
Chars (Last_Entity (Corresponding_Record_Type (Ptyp))) =
Name_uSize
then
Rewrite (N,
Convert_To (Typ,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (
RTE (RE_Adjust_Storage_Size), Loc),
Parameter_Associations =>
New_List (
Make_Selected_Component (Loc,
Prefix =>
Unchecked_Convert_To (
Corresponding_Record_Type (Ptyp),
New_Copy_Tree (Pref)),
Selector_Name =>
Make_Identifier (Loc, Name_uSize))))));
else
Rewrite (N,
Convert_To (Typ,
Make_Function_Call (Loc,
Name => New_Occurrence_Of (
RTE (RE_Adjust_Storage_Size), Loc),
Parameter_Associations =>
New_List (
New_Reference_To (
Storage_Size_Variable (Ptyp), Loc)))));
end if;
Analyze_And_Resolve (N, Typ);
end if;
end if;
end Storage_Size;
when Attribute_Stream_Size => Stream_Size : declare
Ptyp : constant Entity_Id := Etype (Pref);
Size : Int;
begin
if Has_Stream_Size_Clause (Ptyp) then
Size := UI_To_Int
(Static_Integer (Expression (Stream_Size_Clause (Ptyp))));
else
Size := UI_To_Int (Esize (Ptyp));
end if;
Rewrite (N, Make_Integer_Literal (Loc, Intval => Size));
Analyze_And_Resolve (N, Typ);
end Stream_Size;
when Attribute_Succ => Succ :
declare
Ptyp : constant Entity_Id := Base_Type (Etype (Pref));
begin
if Is_Enumeration_Type (Ptyp)
and then Present (Enum_Pos_To_Rep (Ptyp))
then
if Has_Contiguous_Rep (Ptyp) then
Rewrite (N,
Unchecked_Convert_To (Ptyp,
Make_Op_Add (Loc,
Left_Opnd =>
Make_Integer_Literal (Loc,
Enumeration_Rep (First_Literal (Ptyp))),
Right_Opnd =>
Make_Function_Call (Loc,
Name =>
New_Reference_To
(TSS (Ptyp, TSS_Rep_To_Pos), Loc),
Parameter_Associations =>
New_List (
Unchecked_Convert_To (Ptyp,
Make_Op_Add (Loc,
Left_Opnd =>
Unchecked_Convert_To (Standard_Integer,
Relocate_Node (First (Exprs))),
Right_Opnd =>
Make_Integer_Literal (Loc, 1))),
Rep_To_Pos_Flag (Ptyp, Loc))))));
else
Append_To (Exprs, Rep_To_Pos_Flag (Ptyp, Loc));
Rewrite (N,
Make_Indexed_Component (Loc,
Prefix => New_Reference_To (Enum_Pos_To_Rep (Ptyp), Loc),
Expressions => New_List (
Make_Op_Add (Loc,
Left_Opnd =>
Make_Function_Call (Loc,
Name =>
New_Reference_To
(TSS (Ptyp, TSS_Rep_To_Pos), Loc),
Parameter_Associations => Exprs),
Right_Opnd => Make_Integer_Literal (Loc, 1)))));
end if;
Analyze_And_Resolve (N, Typ);
elsif Is_Floating_Point_Type (Ptyp) then
Expand_Fpt_Attribute_R (N);
Analyze_And_Resolve (N, Typ);
elsif Is_Modular_Integer_Type (Ptyp) then
null;
elsif not Overflow_Checks_Suppressed (Ptyp) then
Expand_Pred_Succ (N);
end if;
end Succ;
when Attribute_Tag => Tag :
declare
Ttyp : Entity_Id;
Prefix_Is_Type : Boolean;
begin
if Is_Entity_Name (Pref) and then Is_Type (Entity (Pref)) then
Ttyp := Entity (Pref);
Prefix_Is_Type := True;
else
Ttyp := Etype (Pref);
Prefix_Is_Type := False;
end if;
if Is_Class_Wide_Type (Ttyp) then
Ttyp := Root_Type (Ttyp);
end if;
Ttyp := Underlying_Type (Ttyp);
if Prefix_Is_Type then
if not Java_VM then
Rewrite (N,
Unchecked_Convert_To (RTE (RE_Tag),
New_Reference_To (Access_Disp_Table (Ttyp), Loc)));
Analyze_And_Resolve (N, RTE (RE_Tag));
end if;
else
Rewrite (N,
Make_Selected_Component (Loc,
Prefix => Relocate_Node (Pref),
Selector_Name =>
New_Reference_To (Tag_Component (Ttyp), Loc)));
Analyze_And_Resolve (N, RTE (RE_Tag));
end if;
end Tag;
when Attribute_Terminated => Terminated :
begin
if Restricted_Profile then
Rewrite (N,
Build_Call_With_Task (Pref, RTE (RE_Restricted_Terminated)));
else
Rewrite (N,
Build_Call_With_Task (Pref, RTE (RE_Terminated)));
end if;
Analyze_And_Resolve (N, Standard_Boolean);
end Terminated;
when Attribute_To_Address =>
Rewrite (N,
Unchecked_Convert_To (RTE (RE_Address),
Relocate_Node (First (Exprs))));
Analyze_And_Resolve (N, RTE (RE_Address));
when Attribute_Truncation =>
Expand_Fpt_Attribute_R (N);
when Attribute_Unbiased_Rounding =>
Expand_Fpt_Attribute_R (N);
when Attribute_Unchecked_Access =>
Expand_Access_To_Type (N);
when Attribute_UET_Address => UET_Address : declare
Ent : constant Entity_Id :=
Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
begin
Insert_Action (N,
Make_Object_Declaration (Loc,
Defining_Identifier => Ent,
Aliased_Present => True,
Object_Definition =>
New_Occurrence_Of (RTE (RE_Address), Loc)));
Get_External_Unit_Name_String (Get_Unit_Name (Pref));
Name_Buffer (1 + 7 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
Name_Len := Name_Len + 7;
Name_Buffer (1 .. 7) := "__gnat_";
Name_Buffer (Name_Len + 1 .. Name_Len + 5) := "__SDP";
Name_Len := Name_Len + 5;
Set_Is_Imported (Ent);
Set_Interface_Name (Ent,
Make_String_Literal (Loc,
Strval => String_From_Name_Buffer));
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Ent, Loc),
Attribute_Name => Name_Address));
Analyze_And_Resolve (N, Typ);
end UET_Address;
when Attribute_Unrestricted_Access =>
Expand_Access_To_Type (N);
when Attribute_Val => Val :
declare
Etyp : constant Entity_Id := Base_Type (Entity (Pref));
begin
if Is_Enumeration_Type (Etyp)
and then Present (Enum_Pos_To_Rep (Etyp))
then
if Has_Contiguous_Rep (Etyp) then
declare
Rep_Node : constant Node_Id :=
Unchecked_Convert_To (Etyp,
Make_Op_Add (Loc,
Left_Opnd =>
Make_Integer_Literal (Loc,
Enumeration_Rep (First_Literal (Etyp))),
Right_Opnd =>
(Convert_To (Standard_Integer,
Relocate_Node (First (Exprs))))));
begin
Rewrite (N,
Unchecked_Convert_To (Etyp,
Make_Op_Add (Loc,
Left_Opnd =>
Make_Integer_Literal (Loc,
Enumeration_Rep (First_Literal (Etyp))),
Right_Opnd =>
Make_Function_Call (Loc,
Name =>
New_Reference_To
(TSS (Etyp, TSS_Rep_To_Pos), Loc),
Parameter_Associations => New_List (
Rep_Node,
Rep_To_Pos_Flag (Etyp, Loc))))));
end;
else
Rewrite (N,
Make_Indexed_Component (Loc,
Prefix => New_Reference_To (Enum_Pos_To_Rep (Etyp), Loc),
Expressions => New_List (
Convert_To (Standard_Integer,
Relocate_Node (First (Exprs))))));
end if;
Analyze_And_Resolve (N, Typ);
end if;
end Val;
when Attribute_Valid => Valid :
declare
Ptyp : constant Entity_Id := Etype (Pref);
Btyp : Entity_Id := Base_Type (Ptyp);
Tst : Node_Id;
Save_Validity_Checks_On : constant Boolean := Validity_Checks_On;
function Make_Range_Test return Node_Id;
function Make_Range_Test return Node_Id is
begin
return
Make_And_Then (Loc,
Left_Opnd =>
Make_Op_Ge (Loc,
Left_Opnd =>
Unchecked_Convert_To (Btyp, Duplicate_Subexpr (Pref)),
Right_Opnd =>
Unchecked_Convert_To (Btyp,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Ptyp, Loc),
Attribute_Name => Name_First))),
Right_Opnd =>
Make_Op_Le (Loc,
Left_Opnd =>
Unchecked_Convert_To (Btyp,
Duplicate_Subexpr_No_Checks (Pref)),
Right_Opnd =>
Unchecked_Convert_To (Btyp,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Ptyp, Loc),
Attribute_Name => Name_Last))));
end Make_Range_Test;
begin
Validity_Checks_On := False;
if Is_Floating_Point_Type (Ptyp) then
declare
Rtp : constant Entity_Id := Root_Type (Etype (Pref));
begin
if Is_Possibly_Unaligned_Object (Pref) then
Set_Attribute_Name (N, Name_Unaligned_Valid);
Expand_Fpt_Attribute
(N, Rtp, Name_Unaligned_Valid,
New_List (
Make_Attribute_Reference (Loc,
Prefix => Relocate_Node (Pref),
Attribute_Name => Name_Address)));
else
Expand_Fpt_Attribute
(N, Rtp, Name_Valid,
New_List (
Make_Attribute_Reference (Loc,
Prefix => Unchecked_Convert_To (Rtp, Pref),
Attribute_Name => Name_Unrestricted_Access)));
end if;
if not Subtypes_Statically_Match (Ptyp, Btyp) then
Rewrite (N,
Make_And_Then (Loc,
Left_Opnd => Relocate_Node (N),
Right_Opnd =>
Make_In (Loc,
Left_Opnd => Convert_To (Btyp, Pref),
Right_Opnd => New_Occurrence_Of (Ptyp, Loc))));
end if;
end;
elsif Is_Enumeration_Type (Ptyp)
and then Present (Enum_Pos_To_Rep (Base_Type (Ptyp)))
then
Tst :=
Make_Op_Ge (Loc,
Left_Opnd =>
Make_Function_Call (Loc,
Name =>
New_Reference_To
(TSS (Base_Type (Ptyp), TSS_Rep_To_Pos), Loc),
Parameter_Associations => New_List (
Pref,
New_Occurrence_Of (Standard_False, Loc))),
Right_Opnd => Make_Integer_Literal (Loc, 0));
if Ptyp /= Btyp
and then
(Type_Low_Bound (Ptyp) /= Type_Low_Bound (Btyp)
or else
Type_High_Bound (Ptyp) /= Type_High_Bound (Btyp))
then
Set_Parent (Tst, Parent (N));
Tst :=
Make_And_Then (Loc,
Left_Opnd => Make_Range_Test,
Right_Opnd => Tst);
end if;
Rewrite (N, Tst);
elsif Is_Boolean_Type (Ptyp)
and then Convention (Ptyp) = Convention_Fortran
then
Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
elsif Has_Biased_Representation (Ptyp) then
Btyp := RTE (RE_Unsigned_32);
Rewrite (N,
Make_Op_Lt (Loc,
Left_Opnd =>
Unchecked_Convert_To (Btyp, Duplicate_Subexpr (Pref)),
Right_Opnd =>
Unchecked_Convert_To (Btyp,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Ptyp, Loc),
Attribute_Name => Name_Range_Length))));
elsif Is_Unsigned_Type (Ptyp) then
if Esize (Ptyp) <= 32 then
Btyp := RTE (RE_Unsigned_32);
else
Btyp := RTE (RE_Unsigned_64);
end if;
Rewrite (N, Make_Range_Test);
else
if Esize (Ptyp) <= Esize (Standard_Integer) then
Btyp := Standard_Integer;
else
Btyp := Universal_Integer;
end if;
Rewrite (N, Make_Range_Test);
end if;
Analyze_And_Resolve (N, Standard_Boolean);
Validity_Checks_On := Save_Validity_Checks_On;
end Valid;
when Attribute_Value =>
Exp_Imgv.Expand_Value_Attribute (N);
when Attribute_Wide_Image => Wide_Image :
begin
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Reference_To (RTE (RE_String_To_Wide_String), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => Pref,
Attribute_Name => Name_Image,
Expressions => Exprs),
Make_Integer_Literal (Loc,
Intval => Int (Wide_Character_Encoding_Method)))));
Analyze_And_Resolve (N, Standard_Wide_String);
end Wide_Image;
when Attribute_Wide_Wide_Image => Wide_Wide_Image :
begin
Rewrite (N,
Make_Function_Call (Loc,
Name => New_Reference_To
(RTE (RE_String_To_Wide_Wide_String), Loc),
Parameter_Associations => New_List (
Make_Attribute_Reference (Loc,
Prefix => Pref,
Attribute_Name => Name_Image,
Expressions => Exprs),
Make_Integer_Literal (Loc,
Intval => Int (Wide_Character_Encoding_Method)))));
Analyze_And_Resolve (N, Standard_Wide_Wide_String);
end Wide_Wide_Image;
when Attribute_Wide_Value => Wide_Value :
begin
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => Pref,
Attribute_Name => Name_Value,
Expressions => New_List (
Make_Function_Call (Loc,
Name =>
New_Reference_To (RTE (RE_Wide_String_To_String), Loc),
Parameter_Associations => New_List (
Relocate_Node (First (Exprs)),
Make_Integer_Literal (Loc,
Intval => Int (Wide_Character_Encoding_Method)))))));
Analyze_And_Resolve (N, Typ);
end Wide_Value;
when Attribute_Wide_Wide_Value => Wide_Wide_Value :
begin
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => Pref,
Attribute_Name => Name_Value,
Expressions => New_List (
Make_Function_Call (Loc,
Name =>
New_Reference_To (RTE (RE_Wide_Wide_String_To_String), Loc),
Parameter_Associations => New_List (
Relocate_Node (First (Exprs)),
Make_Integer_Literal (Loc,
Intval => Int (Wide_Character_Encoding_Method)))))));
Analyze_And_Resolve (N, Typ);
end Wide_Wide_Value;
when Attribute_Wide_Wide_Width =>
Exp_Imgv.Expand_Width_Attribute (N, Wide_Wide);
when Attribute_Wide_Width =>
Exp_Imgv.Expand_Width_Attribute (N, Wide);
when Attribute_Width =>
Exp_Imgv.Expand_Width_Attribute (N, Normal);
when Attribute_Write => Write : declare
P_Type : constant Entity_Id := Entity (Pref);
U_Type : constant Entity_Id := Underlying_Type (P_Type);
Pname : Entity_Id;
Decl : Node_Id;
Prag : Node_Id;
Arg3 : Node_Id;
Wfunc : Node_Id;
begin
if No (U_Type) then
return;
end if;
Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Write);
if Present (Pname) then
null;
else
Prag := Get_Stream_Convert_Pragma (P_Type);
if Present (Prag) then
Arg3 :=
Next (Next (First (Pragma_Argument_Associations (Prag))));
Wfunc := Entity (Expression (Arg3));
Rewrite (N,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Etype (Wfunc), Loc),
Attribute_Name => Name_Output,
Expressions => New_List (
Relocate_Node (First (Exprs)),
Make_Function_Call (Loc,
Name => New_Occurrence_Of (Wfunc, Loc),
Parameter_Associations => New_List (
Convert_To (Etype (First_Formal (Wfunc)),
Relocate_Node (Next (First (Exprs)))))))));
Analyze (N);
return;
elsif Is_Elementary_Type (U_Type) then
Rewrite (N, Build_Elementary_Write_Call (N));
Analyze (N);
return;
elsif Is_Array_Type (U_Type) then
Build_Array_Write_Procedure (N, U_Type, Decl, Pname);
Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False);
elsif Is_Tagged_Type (U_Type) then
Pname := Find_Prim_Op (U_Type, TSS_Stream_Write);
else
pragma Assert
(Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type));
if Is_Unchecked_Union (Base_Type (U_Type)) then
Insert_Action (N,
Make_Raise_Program_Error (Loc,
Reason => PE_Unchecked_Union_Restriction));
end if;
if Has_Discriminants (U_Type)
and then Present
(Discriminant_Default_Value (First_Discriminant (U_Type)))
then
Build_Mutable_Record_Write_Procedure
(Loc, Base_Type (U_Type), Decl, Pname);
else
Build_Record_Write_Procedure
(Loc, Base_Type (U_Type), Decl, Pname);
end if;
Insert_Action (N, Decl);
end if;
end if;
Rewrite_Stream_Proc_Call (Pname);
end Write;
when Attribute_Component_Size =>
null;
when Attribute_Bit_Order |
Attribute_Code_Address |
Attribute_Definite |
Attribute_Max |
Attribute_Mechanism_Code |
Attribute_Min |
Attribute_Null_Parameter |
Attribute_Passed_By_Reference |
Attribute_Pool_Address =>
null;
when Attribute_Aft |
Attribute_Bit |
Attribute_Max_Size_In_Storage_Elements
=>
Apply_Universal_Integer_Attribute_Checks (N);
when Attribute_Abort_Signal |
Attribute_Address_Size |
Attribute_Base |
Attribute_Class |
Attribute_Default_Bit_Order |
Attribute_Delta |
Attribute_Denorm |
Attribute_Digits |
Attribute_Emax |
Attribute_Epsilon |
Attribute_Has_Access_Values |
Attribute_Has_Discriminants |
Attribute_Large |
Attribute_Machine_Emax |
Attribute_Machine_Emin |
Attribute_Machine_Mantissa |
Attribute_Machine_Overflows |
Attribute_Machine_Radix |
Attribute_Machine_Rounds |
Attribute_Maximum_Alignment |
Attribute_Model_Emin |
Attribute_Model_Epsilon |
Attribute_Model_Mantissa |
Attribute_Model_Small |
Attribute_Modulus |
Attribute_Partition_ID |
Attribute_Range |
Attribute_Safe_Emax |
Attribute_Safe_First |
Attribute_Safe_Large |
Attribute_Safe_Last |
Attribute_Safe_Small |
Attribute_Scale |
Attribute_Signed_Zeros |
Attribute_Small |
Attribute_Storage_Unit |
Attribute_Target_Name |
Attribute_Type_Class |
Attribute_Unconstrained_Array |
Attribute_Universal_Literal_String |
Attribute_Wchar_T_Size |
Attribute_Word_Size =>
raise Program_Error;
when Attribute_Asm_Input |
Attribute_Asm_Output =>
null;
end case;
exception
when RE_Not_Available =>
return;
end Expand_N_Attribute_Reference;
procedure Expand_Pred_Succ (N : Node_Id) is
Loc : constant Source_Ptr := Sloc (N);
Cnam : Name_Id;
begin
if Attribute_Name (N) = Name_Pred then
Cnam := Name_First;
else
Cnam := Name_Last;
end if;
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
Make_Op_Eq (Loc,
Left_Opnd =>
Duplicate_Subexpr_Move_Checks (First (Expressions (N))),
Right_Opnd =>
Make_Attribute_Reference (Loc,
Prefix =>
New_Reference_To (Base_Type (Etype (Prefix (N))), Loc),
Attribute_Name => Cnam)),
Reason => CE_Overflow_Check_Failed));
end Expand_Pred_Succ;
function Find_Inherited_TSS
(Typ : Entity_Id;
Nam : TSS_Name_Type) return Entity_Id
is
Btyp : Entity_Id := Typ;
Proc : Entity_Id;
begin
loop
Btyp := Base_Type (Btyp);
Proc := TSS (Btyp, Nam);
exit when Present (Proc)
or else not Is_Derived_Type (Btyp);
Btyp := Etype (Btyp);
end loop;
if No (Proc) then
Proc := TSS (Base_Type (Underlying_Type (Typ)), Nam);
end if;
return Proc;
end Find_Inherited_TSS;
function Find_Stream_Subprogram
(Typ : Entity_Id;
Nam : TSS_Name_Type) return Entity_Id is
begin
if Is_Tagged_Type (Typ)
and then Is_Derived_Type (Typ)
then
return Find_Prim_Op (Typ, Nam);
else
return Find_Inherited_TSS (Typ, Nam);
end if;
end Find_Stream_Subprogram;
function Get_Index_Subtype (N : Node_Id) return Node_Id is
P_Type : Entity_Id := Etype (Prefix (N));
Indx : Node_Id;
J : Int;
begin
if Is_Access_Type (P_Type) then
P_Type := Designated_Type (P_Type);
end if;
if No (Expressions (N)) then
J := 1;
else
J := UI_To_Int (Expr_Value (First (Expressions (N))));
end if;
Indx := First_Index (P_Type);
while J > 1 loop
Next_Index (Indx);
J := J - 1;
end loop;
return Etype (Indx);
end Get_Index_Subtype;
function Get_Stream_Convert_Pragma (T : Entity_Id) return Node_Id is
Typ : Entity_Id;
N : Node_Id;
begin
N := First_Rep_Item (Implementation_Base_Type (T));
while Present (N) loop
if Nkind (N) = N_Pragma and then Chars (N) = Name_Stream_Convert then
Typ :=
Entity (Expression (First (Pragma_Argument_Associations (N))));
if not Is_Tagged_Type (T)
or else T = Typ
or else (Is_Private_Type (Typ) and then T = Full_View (Typ))
then
return N;
end if;
end if;
Next_Rep_Item (N);
end loop;
return Empty;
end Get_Stream_Convert_Pragma;
function Is_Constrained_Packed_Array (Typ : Entity_Id) return Boolean is
Arr : Entity_Id := Typ;
begin
if Is_Access_Type (Arr) then
Arr := Designated_Type (Arr);
end if;
return Is_Array_Type (Arr)
and then Is_Constrained (Arr)
and then Present (Packed_Array_Type (Arr));
end Is_Constrained_Packed_Array;
end Exp_Attr;