----------------------------------------
procedure Check_Expr_Is_OK_Static_Expression
- (Expr : Node_Id;
- Typ : Entity_Id := Empty)
- is
+ (Expr : Node_Id; Typ : Entity_Id := Empty) is
begin
- if Present (Typ) then
- Analyze_And_Resolve (Expr, Typ);
- else
- Analyze_And_Resolve (Expr);
- end if;
-
- -- An expression cannot be considered static if its resolution
- -- failed or if it's erroneous. Stop the analysis of the
- -- related aspect.
-
- if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
- raise Aspect_Exit;
-
- elsif Is_OK_Static_Expression (Expr) then
- return;
+ case Is_OK_Static_Expression_Of_Type (Expr, Typ) is
+ when Static =>
+ null;
- -- Finally, we have a real error
+ when Not_Static =>
+ Error_Msg_Name_1 := Nam;
+ Flag_Non_Static_Expr
+ ("entity for aspect% must be a static expression!",
+ Expr);
+ raise Aspect_Exit;
- else
- Error_Msg_Name_1 := Nam;
- Flag_Non_Static_Expr
- ("entity for aspect% must be a static expression!",
- Expr);
- raise Aspect_Exit;
- end if;
+ when Invalid =>
+ raise Aspect_Exit;
+ end case;
end Check_Expr_Is_OK_Static_Expression;
------------------------
Set_Expression (N, Error);
E := Error;
- if Nkind (Def) /= N_String_Literal then
- Error_Msg_N
- ("External_Initialization aspect expects a string literal value",
- Specification);
- return;
- end if;
+ case Is_OK_Static_Expression_Of_Type (Def, Standard_String) is
+ when Static =>
+ null;
+
+ when Not_Static =>
+ Error_Msg_N
+ ("External_Initialization aspect expects a static string",
+ Specification);
+ return;
+
+ when Invalid =>
+ return;
+ end case;
if not (Is_String_Type (T)
- or else Is_RTE (Base_Type (T), RE_Stream_Element_Array))
+ or else Is_RTE (Base_Type (T), RE_Stream_Element_Array))
then
Error_Msg_N
("External_Initialization aspect can only be applied to objects "
end if;
declare
- S : constant String := Stringt.To_String (Strval (Def));
+ S : constant String :=
+ Stringt.To_String (Strval (Expr_Value_S (Def)));
begin
if System.OS_Lib.Is_Absolute_Path (S) then
Data_Path := Name_Find (S);
return Is_Static_Expression (N) and then not Raises_Constraint_Error (N);
end Is_OK_Static_Expression;
+ -------------------------------------
+ -- Is_OK_Static_Expression_Of_Type --
+ -------------------------------------
+
+ function Is_OK_Static_Expression_Of_Type
+ (Expr : Node_Id; Typ : Entity_Id := Empty) return Staticity is
+ begin
+ if Present (Typ) then
+ Analyze_And_Resolve (Expr, Typ);
+ else
+ Analyze_And_Resolve (Expr);
+ end if;
+
+ -- An expression cannot be considered static if its resolution
+ -- failed or if an error was flagged.
+
+ if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
+ return Invalid;
+ end if;
+
+ if Is_OK_Static_Expression (Expr) then
+ return Static;
+ end if;
+
+ -- An interesting special case, if we have a string literal and we
+ -- are in Ada 83 mode, then we allow it even though it will not be
+ -- flagged as static. This allows the use of Ada 95 pragmas like
+ -- Import in Ada 83 mode. They will of course be flagged with
+ -- warnings as usual, but will not cause errors.
+
+ if Ada_Version = Ada_83
+ and then Nkind (Expr) = N_String_Literal
+ then
+ return Static;
+ end if;
+
+ return Not_Static;
+ end Is_OK_Static_Expression_Of_Type;
+
------------------------
-- Is_OK_Static_Range --
------------------------
-- for compile time evaluation purposes. Use Compile_Time_Known_Value
-- instead (see section on "Compile-Time Known Values" above).
+ type Staticity is (Static, Not_Static, Invalid);
+
+ function Is_OK_Static_Expression_Of_Type
+ (Expr : Node_Id; Typ : Entity_Id := Empty) return Staticity;
+ -- Return whether Expr is a static expression of the given type (i.e. it
+ -- will be analyzed and resolved using this type, which can be any valid
+ -- argument to Resolve, e.g. Any_Integer is OK). Includes checking that the
+ -- expression does not raise Constraint_Error.
+
function Is_OK_Static_Range (N : Node_Id) return Boolean;
-- Determines if range is static, as defined in RM 4.9(26), and also checks
-- that neither bound of the range raises constraint error, thus ensuring
----------------------------------------
procedure Check_Expr_Is_OK_Static_Expression
- (Expr : Node_Id;
- Typ : Entity_Id := Empty)
- is
+ (Expr : Node_Id; Typ : Entity_Id := Empty) is
begin
- if Present (Typ) then
- Analyze_And_Resolve (Expr, Typ);
- else
- Analyze_And_Resolve (Expr);
- end if;
-
- -- An expression cannot be considered static if its resolution failed
- -- or if it's erroneous. Stop the analysis of the related pragma.
-
- if Etype (Expr) = Any_Type or else Error_Posted (Expr) then
- raise Pragma_Exit;
-
- elsif Is_OK_Static_Expression (Expr) then
- return;
-
- -- An interesting special case, if we have a string literal and we
- -- are in Ada 83 mode, then we allow it even though it will not be
- -- flagged as static. This allows the use of Ada 95 pragmas like
- -- Import in Ada 83 mode. They will of course be flagged with
- -- warnings as usual, but will not cause errors.
-
- elsif Ada_Version = Ada_83
- and then Nkind (Expr) = N_String_Literal
- then
- return;
+ case Is_OK_Static_Expression_Of_Type (Expr, Typ) is
+ when Static =>
+ null;
- -- Finally, we have a real error
+ when Not_Static =>
+ Error_Msg_Name_1 := Pname;
+ Flag_Non_Static_Expr
+ (Fix_Error
+ ("argument for pragma% must be a static expression!"),
+ Expr);
+ raise Pragma_Exit;
- else
- Error_Msg_Name_1 := Pname;
- Flag_Non_Static_Expr
- (Fix_Error ("argument for pragma% must be a static expression!"),
- Expr);
- raise Pragma_Exit;
- end if;
+ when Invalid =>
+ raise Pragma_Exit;
+ end case;
end Check_Expr_Is_OK_Static_Expression;
-------------------------