function Is_Relaxed_Initialization_State (Id : E) return B is
begin
-- To qualify, the abstract state must appear with simple option
- -- "Relaxed_Initialization" (??? add reference to SPARK RM once the
- -- Relaxed_Initialization aspect is described there).
+ -- "Relaxed_Initialization" (SPARK RM 6.10).
return
Ekind (Id) = E_Abstract_State
null;
-- Attribute 'Result is allowed to appear in aspect
- -- Relaxed_Initialization (??? add reference to SPARK RM once this
- -- attribute is described there).
+ -- Relaxed_Initialization (SPARK RM 6.10).
elsif Prag_Nam = Name_Relaxed_Initialization
and then Aname = Name_Result
-- Will be set to True if we need to restore the scope table
-- after analyzing the aspect expression.
+ Prev_Id : Entity_Id;
+
-- Start of processing for Analyze_Aspect_Relaxed_Initialization
begin
-- Set name of the aspect for error messages
Error_Msg_Name_1 := Nam;
- -- Annotation of a type; no aspect expression is allowed
+ -- Annotation of a type; no aspect expression is allowed.
+ -- For a private type, the aspect must be attached to the
+ -- partial view.
+ --
-- ??? Once the exact rule for this aspect is ready, we will
-- likely reject concurrent types, etc., so let's keep the code
-- for types and variable separate.
if Is_First_Subtype (E) then
- if Present (Expr) then
+ Prev_Id := Incomplete_Or_Partial_View (E);
+ if Present (Prev_Id) then
+
+ -- Aspect may appear on the full view of an incomplete
+ -- type because the incomplete declaration cannot have
+ -- any aspects.
+
+ if Ekind (Prev_Id) = E_Incomplete_Type then
+ null;
+ else
+ Error_Msg_N ("aspect % must apply to partial view", N);
+ end if;
+
+ elsif Present (Expr) then
Error_Msg_N ("illegal aspect % expression", Expr);
end if;
Error_Msg_N ("illegal aspect % expression", Expr);
end if;
+ -- Annotation of a constant; no aspect expression is allowed.
+ -- For a deferred constant, the aspect must be attached to the
+ -- partial view.
+
+ elsif Ekind (E) = E_Constant then
+ if Present (Incomplete_Or_Partial_View (E)) then
+ Error_Msg_N
+ ("aspect % must apply to deferred constant", N);
+
+ elsif Present (Expr) then
+ Error_Msg_N ("illegal aspect % expression", Expr);
+ end if;
+
-- Annotation of a subprogram; aspect expression is required
elsif Is_Subprogram (E) then
when E_Abstract_State =>
return Is_Relaxed_Initialization_State (E);
+ -- Constants have this aspect attached directly; for deferred
+ -- constants, the aspect is attached to the partial view.
+
+ when E_Constant =>
+ return Has_Aspect (E, Aspect_Relaxed_Initialization);
+
-- Variables have this aspect attached directly
when E_Variable =>
return Has_Aspect (E, Aspect_Relaxed_Initialization);
-- Types have this aspect attached directly (though we only allow it
- -- to be specified for the first subtype).
+ -- to be specified for the first subtype). For private types, the
+ -- aspect is attached to the partial view.
when Type_Kind =>
pragma Assert (Is_First_Subtype (E));
-- yet received a full declaration.
function Has_Relaxed_Initialization (E : Entity_Id) return Boolean;
- -- Returns True iff entity E, which can be either a type, a variable, an
- -- abstract state or a function, is subject to the Relaxed_Initialization
- -- aspect.
+ -- Returns True iff entity E is subject to the Relaxed_Initialization
+ -- aspect. Entity E can be either type, variable, constant, function,
+ -- or abstract state. For private types and deferred constants E should
+ -- be the private view, because aspect can only be attached there.
function Has_Signed_Zeros (E : Entity_Id) return Boolean;
-- Determines if the floating-point type E supports signed zeros.