-- Common processing for attributes Definite and Has_Discriminants.
-- Checks that prefix is generic indefinite formal type.
+ procedure Check_Formal_Restriction_On_Attribute;
+ -- Issue an error in formal mode because attribute N is allowed
+
procedure Check_Integer_Type;
-- Verify that prefix of attribute N is an integer type
-- Start of processing for Analyze_Access_Attribute
begin
- -- Access attribute is not allowed in SPARK or ALFA
-
- if Formal_Verification_Mode and then Comes_From_Source (N) then
- Error_Attr_P ("|~~% attribute is not allowed");
- end if;
-
- -- Proceed with analysis
-
+ Check_Formal_Restriction_On_Attribute;
Check_E0;
if Nkind (P) = N_Character_Literal then
Check_E2;
end Check_Floating_Point_Type_2;
+ -------------------------------------------
+ -- Check_Formal_Restriction_On_Attribute --
+ -------------------------------------------
+
+ procedure Check_Formal_Restriction_On_Attribute is
+ begin
+ Error_Msg_Name_1 := Aname;
+ Check_Formal_Restriction ("attribute % is not allowed", P);
+ end Check_Formal_Restriction_On_Attribute;
+
------------------------
-- Check_Integer_Type --
------------------------
("?redundant attribute, & is its own base type", N, Typ);
end if;
+ if Nkind (Parent (N)) /= N_Attribute_Reference then
+ Error_Msg_Name_1 := Aname;
+ Check_Formal_Restriction
+ ("attribute% is only allowed as prefix of another attribute", P);
+ end if;
+
Set_Etype (N, Base_Type (Entity (P)));
Set_Entity (N, Base_Type (Entity (P)));
Rewrite (N, New_Reference_To (Entity (N), Loc));
when Attribute_Image => Image :
begin
- Set_Etype (N, Standard_String);
+ Check_Formal_Restriction_On_Attribute;
Check_Scalar_Type;
+ Set_Etype (N, Standard_String);
if Is_Real_Type (P_Type) then
if Ada_Version = Ada_83 and then Comes_From_Source (N) then
when Attribute_Pos =>
Check_Discrete_Type;
Check_E1;
+
+ if Is_Boolean_Type (P_Type) then
+ Error_Msg_Name_1 := Aname;
+ Error_Msg_Name_2 := Chars (P_Type);
+ Check_Formal_Restriction
+ ("attribute% is not allowed for type%", P);
+ end if;
+
Resolve (E1, P_Base_Type);
Set_Etype (N, Universal_Integer);
when Attribute_Pred =>
Check_Scalar_Type;
Check_E1;
+
+ if Is_Real_Type (P_Type) or else Is_Boolean_Type (P_Type) then
+ Error_Msg_Name_1 := Aname;
+ Error_Msg_Name_2 := Chars (P_Type);
+ Check_Formal_Restriction
+ ("attribute% is not allowed for type%", P);
+ end if;
+
Resolve (E1, P_Base_Type);
Set_Etype (N, P_Base_Type);
when Attribute_Succ =>
Check_Scalar_Type;
Check_E1;
+
+ if Is_Real_Type (P_Type) or else Is_Boolean_Type (P_Type) then
+ Error_Msg_Name_1 := Aname;
+ Error_Msg_Name_2 := Chars (P_Type);
+ Check_Formal_Restriction
+ ("attribute% is not allowed for type%", P);
+ end if;
+
Resolve (E1, P_Base_Type);
Set_Etype (N, P_Base_Type);
begin
Check_E1;
Check_Discrete_Type;
+
+ if Is_Boolean_Type (P_Type) then
+ Error_Msg_Name_1 := Aname;
+ Error_Msg_Name_2 := Chars (P_Type);
+ Check_Formal_Restriction
+ ("attribute% is not allowed for type%", P);
+ end if;
+
Resolve (E1, Any_Integer);
Set_Etype (N, P_Base_Type);
when Attribute_Value => Value :
begin
+ Check_Formal_Restriction_On_Attribute;
Check_E1;
Check_Scalar_Type;
when Attribute_Wide_Image => Wide_Image :
begin
+ Check_Formal_Restriction_On_Attribute;
Check_Scalar_Type;
Set_Etype (N, Standard_Wide_String);
Check_E1;
when Attribute_Wide_Value => Wide_Value :
begin
+ Check_Formal_Restriction_On_Attribute;
Check_E1;
Check_Scalar_Type;
----------------
when Attribute_Wide_Width =>
+ Check_Formal_Restriction_On_Attribute;
Check_E0;
Check_Scalar_Type;
Set_Etype (N, Universal_Integer);
-----------
when Attribute_Width =>
+ Check_Formal_Restriction_On_Attribute;
Check_E0;
Check_Scalar_Type;
Set_Etype (N, Universal_Integer);
-- given kind of type (index constraint to an array type, for example).
procedure Modular_Type_Declaration (T : Entity_Id; Def : Node_Id);
- -- Create new modular type. Verify that modulus is in bounds and is
- -- a power of two (implementation restriction).
+ -- Create new modular type. Verify that modulus is in bounds
+ -- (implementation restriction).
procedure New_Concatenation_Op (Typ : Entity_Id);
-- Create an abbreviated declaration for an operator in order to
-- Non-binary case
elsif M_Val < 2 ** Bits then
+ Check_Formal_Restriction ("modulus should be a power of 2", T);
Set_Non_Binary_Modulus (T);
if Bits > System_Max_Nonbinary_Modulus_Power then
begin
Analyze_And_Resolve (R, Base_Type (T));
+ if not Is_Static_Range (R) then
+ Check_Formal_Restriction ("range should be static", R);
+ end if;
+
if Nkind (R) = N_Range then
Lo := Low_Bound (R);
Hi := High_Bound (R);