-- references to parameters of the inherited subprogram to point to the
-- corresponding parameters of the current subprogram.
- procedure Insert_Before_First_Source_Declaration (Nod : Node_Id);
- -- Insert node Nod before the first source declaration of the context
+ procedure Insert_After_Last_Declaration (Nod : Node_Id);
+ -- Insert node Nod after the last declaration of the context
function Invariants_Or_Predicates_Present return Boolean;
-- Determines if any invariants or predicates are present for any OUT
return CP;
end Grab_PPC;
- --------------------------------------------
- -- Insert_Before_First_Source_Declaration --
- --------------------------------------------
+ -----------------------------------
+ -- Insert_After_Last_Declaration --
+ -----------------------------------
- procedure Insert_Before_First_Source_Declaration (Nod : Node_Id) is
+ procedure Insert_After_Last_Declaration (Nod : Node_Id) is
Decls : constant List_Id := Declarations (N);
- Decl : Node_Id;
begin
if No (Decls) then
Set_Declarations (N, New_List (Nod));
else
- Decl := First (Decls);
-
- while Present (Decl) loop
- if Comes_From_Source (Decl) then
- exit;
- end if;
-
- Next (Decl);
- end loop;
-
- if No (Decl) then
- Append_To (Decls, Nod);
- else
- Insert_Before (Decl, Nod);
- end if;
+ Append_To (Decls, Nod);
end if;
- end Insert_Before_First_Source_Declaration;
+ end Insert_After_Last_Declaration;
--------------------------------------
-- Invariants_Or_Predicates_Present --
-- The entity for the _Postconditions procedure
begin
- -- Insert the corresponding body of a post condition pragma before
- -- the first source declaration of the context. This ensures that
- -- any [sub]types generated in relation to the formals of the
- -- subprogram are still visible in the _postcondition body.
-
- Insert_Before_First_Source_Declaration (
+ -- Insert the corresponding body of a post condition pragma after
+ -- the last declaration of the context. This ensures that the body
+ -- will not cause any premature freezing as it may mention types:
+
+ -- procedure Proc (Obj : Array_Typ) is
+ -- procedure _postconditions is
+ -- begin
+ -- ... Obj ...
+ -- end _postconditions;
+
+ -- subtype T is Array_Typ (Obj'First (1) .. Obj'Last (1));
+ -- begin
+
+ -- In the example above, Obj is of type T but the incorrect
+ -- placement of _postconditions will cause a crash in gigi due to
+ -- an out of order reference. The body of _postconditions must be
+ -- placed after the declaration of Temp to preserve correct
+ -- visibility.
+
+ Insert_After_Last_Declaration (
Make_Subprogram_Body (Loc,
Specification =>
Make_Procedure_Specification (Loc,
-- Aspect is an Ada 2012 feature. Note that there is no need to check
-- dimensions for nodes that don't come from source.
- if Ada_Version < Ada_2012
- or else not Comes_From_Source (N)
- then
+ if Ada_Version < Ada_2012 or else not Comes_From_Source (N) then
return;
end if;
end if;
while Present (Comp) loop
+
-- Get the expression from the component
if Nkind (Comp) = N_Component_Association then
Error_Detected := True;
end if;
- Error_Msg_N ("\expected dimension " &
- Dimensions_Msg_Of (Comp_Typ) & ", found " &
- Dimensions_Msg_Of (Expr),
- Expr);
+ Error_Msg_N
+ ("\expected dimension "
+ & Dimensions_Msg_Of (Comp_Typ)
+ & ", found "
+ & Dimensions_Msg_Of (Expr),
+ Expr);
end if;
-- Look at the named components right after the positional components
is
begin
Error_Msg_N ("dimensions mismatch in assignment", N);
- Error_Msg_N ("\left-hand side " & Dimensions_Msg_Of (Lhs, True), N);
+ Error_Msg_N ("\left-hand side " & Dimensions_Msg_Of (Lhs, True), N);
Error_Msg_N ("\right-hand side " & Dimensions_Msg_Of (Rhs, True), N);
end Error_Dim_Msg_For_Assignment_Statement;
"dimensions",
N,
Entity (N));
- Error_Msg_N ("\left operand " & Dimensions_Msg_Of (L, True), N);
+ Error_Msg_N ("\left operand " & Dimensions_Msg_Of (L, True), N);
Error_Msg_N ("\right operand " & Dimensions_Msg_Of (R, True), N);
end Error_Dim_Msg_For_Binary_Op;
Ada_Numerics_Generic_Elementary_Functions);
end Is_Elementary_Function_Entity;
+ -- Start of processing for Elementary_Function_Calls
+
begin
-- Get the original subprogram entity following the renaming chain
-- Check the call is an Elementary function call
if Is_Elementary_Function_Entity (Ent) then
+
-- Sqrt function call case
if Chars (Ent) = Name_Sqrt then
else
Actual := First_Actual (N);
-
while Present (Actual) loop
if Exists (Dimensions_Of (Actual)) then
- -- Check if an error has already been encountered so
- -- far.
+
+ -- Check if error has already been encountered so far
if not Error_Detected then
Error_Msg_NE ("dimensions mismatch in call of&",
Expr : Node_Id) is
begin
Error_Msg_N ("dimensions mismatch in component declaration", N);
- Error_Msg_N ("\expected dimension " &
- Dimensions_Msg_Of (Etyp) & ", found " &
- Dimensions_Msg_Of (Expr),
+ Error_Msg_N ("\expected dimension "
+ & Dimensions_Msg_Of (Etyp)
+ & ", found "
+ & Dimensions_Msg_Of (Expr),
Expr);
end Error_Dim_Msg_For_Component_Declaration;
-- dimensionless to indicate the literal is treated as if its
-- dimension matches the type dimension.
- if Nkind_In (Original_Node (Expr),
- N_Real_Literal,
- N_Integer_Literal)
+ if Nkind_In (Original_Node (Expr), N_Real_Literal,
+ N_Integer_Literal)
then
Dim_Warning_For_Numeric_Literal (Expr, Etyp);
procedure Analyze_Dimension_Extended_Return_Statement (N : Node_Id) is
Return_Ent : constant Entity_Id := Return_Statement_Entity (N);
Return_Etyp : constant Entity_Id :=
- Etype (Return_Applies_To (Return_Ent));
+ Etype (Return_Applies_To (Return_Ent));
Return_Obj_Decls : constant List_Id := Return_Object_Declarations (N);
Return_Obj_Decl : Node_Id;
Return_Obj_Id : Entity_Id;
is
begin
Error_Msg_N ("dimensions mismatch in extended return statement", N);
- Error_Msg_N ("\expected dimension " &
- Dimensions_Msg_Of (Return_Etyp) & ", found " &
- Dimensions_Msg_Of (Return_Obj_Typ),
+ Error_Msg_N ("\expected dimension "
+ & Dimensions_Msg_Of (Return_Etyp)
+ & ", found "
+ & Dimensions_Msg_Of (Return_Obj_Typ),
N);
end Error_Dim_Msg_For_Extended_Return_Statement;
begin
if Present (Return_Obj_Decls) then
Return_Obj_Decl := First (Return_Obj_Decls);
-
while Present (Return_Obj_Decl) loop
if Nkind (Return_Obj_Decl) = N_Object_Declaration then
- Return_Obj_Id := Defining_Identifier (Return_Obj_Decl);
+ Return_Obj_Id := Defining_Identifier (Return_Obj_Decl);
if Is_Return_Object (Return_Obj_Id) then
Return_Obj_Typ := Etype (Return_Obj_Id);
-----------------------------------------------------
procedure Analyze_Dimension_Extension_Or_Record_Aggregate (N : Node_Id) is
- Comp : Node_Id := First (Component_Associations (N));
+ Comp : Node_Id;
Comp_Id : Entity_Id;
Comp_Typ : Entity_Id;
Expr : Node_Id;
-- Aspect is an Ada 2012 feature. Note that there is no need to check
-- dimensions for aggregates that don't come from source.
- if Ada_Version < Ada_2012
- or else not Comes_From_Source (N)
- then
+ if Ada_Version < Ada_2012 or else not Comes_From_Source (N) then
return;
end if;
+ Comp := First (Component_Associations (N));
while Present (Comp) loop
Comp_Id := Entity (First (Choices (Comp)));
Comp_Typ := Etype (Comp_Id);
-- dimensions of the component mismatch.
if Dimensions_Of (Expr) /= Dimensions_Of (Comp_Typ) then
+
-- Check if an error has already been encountered so far
if not Error_Detected then
+
-- Extension aggregate case
if Nkind (N) = N_Extension_Aggregate then
- Error_Msg_N ("dimensions mismatch in extension aggregate",
- N);
+ Error_Msg_N
+ ("dimensions mismatch in extension aggregate", N);
-- Record aggregate case
else
- Error_Msg_N ("dimensions mismatch in record aggregate",
- N);
+ Error_Msg_N
+ ("dimensions mismatch in record aggregate", N);
end if;
Error_Detected := True;
end if;
- Error_Msg_N ("\expected dimension " &
- Dimensions_Msg_Of (Comp_Typ) & ", found " &
- Dimensions_Msg_Of (Expr),
- Comp);
+ Error_Msg_N
+ ("\expected dimension "
+ & Dimensions_Msg_Of (Comp_Typ)
+ & ", found "
+ & Dimensions_Msg_Of (Expr),
+ Comp);
end if;
end if;
-- Aspect is an Ada 2012 feature. Note that there is no need to check
-- dimensions for sub specs that don't come from source.
- if Ada_Version < Ada_2012
- or else not Comes_From_Source (N)
- then
+ if Ada_Version < Ada_2012 or else not Comes_From_Source (N) then
return;
end if;
Formal := First (Formals);
-
while Present (Formal) loop
Typ := Parameter_Type (Formal);
Dims_Of_Typ := Dimensions_Of (Typ);
if Present (Expr)
and then Dims_Of_Typ /= Dimensions_Of (Expr)
- and then Nkind_In (Original_Node (Expr),
- N_Real_Literal,
- N_Integer_Literal)
+ and then Nkind_In (Original_Node (Expr), N_Real_Literal,
+ N_Integer_Literal)
then
Dim_Warning_For_Numeric_Literal (Expr, Etype (Typ));
end if;
Expr : Node_Id) is
begin
Error_Msg_N ("dimensions mismatch in object declaration", N);
- Error_Msg_N ("\expected dimension " &
- Dimensions_Msg_Of (Etyp) & ", found " &
- Dimensions_Msg_Of (Expr),
- Expr);
+ Error_Msg_N
+ ("\expected dimension "
+ & Dimensions_Msg_Of (Etyp)
+ & ", found "
+ & Dimensions_Msg_Of (Expr),
+ Expr);
end Error_Dim_Msg_For_Object_Declaration;
-- Start of processing for Analyze_Dimension_Object_Declaration
-- Check dimensions match
if Dim_Of_Expr /= Dim_Of_Etyp then
+
-- Numeric literal case. Issue a warning if the object type is not
-- dimensionless to indicate the literal is treated as if its
-- dimension matches the type dimension.
- if Nkind_In (Original_Node (Expr),
- N_Real_Literal,
- N_Integer_Literal)
+ if Nkind_In (Original_Node (Expr), N_Real_Literal,
+ N_Integer_Literal)
then
Dim_Warning_For_Numeric_Literal (Expr, Etyp);
- -- Case where the object is a constant whose type is a dimensioned
- -- type.
+ -- Case of object is a constant whose type is a dimensioned type
elsif Constant_Present (N) and then not Exists (Dim_Of_Etyp) then
- -- Propagate the dimension from the expression to the object
- -- entity
+
+ -- Propagate dimension from expression to object entity
Set_Dimensions (Id, Dim_Of_Expr);
Renamed_Name : Node_Id) is
begin
Error_Msg_N ("dimensions mismatch in object renaming declaration", N);
- Error_Msg_N ("\expected dimension " &
- Dimensions_Msg_Of (Sub_Mark) & ", found " &
- Dimensions_Msg_Of (Renamed_Name),
- Renamed_Name);
+ Error_Msg_N
+ ("\expected dimension "
+ & Dimensions_Msg_Of (Sub_Mark)
+ & ", found "
+ & Dimensions_Msg_Of (Renamed_Name),
+ Renamed_Name);
end Error_Dim_Msg_For_Object_Renaming_Declaration;
-- Start of processing for Analyze_Dimension_Object_Renaming_Declaration
is
begin
Error_Msg_N ("dimensions mismatch in return statement", N);
- Error_Msg_N ("\expected dimension " &
- Dimensions_Msg_Of (Return_Etyp) & ", found " &
- Dimensions_Msg_Of (Expr),
- Expr);
+ Error_Msg_N
+ ("\expected dimension "
+ & Dimensions_Msg_Of (Return_Etyp)
+ & ", found "
+ & Dimensions_Msg_Of (Expr),
+ Expr);
end Error_Dim_Msg_For_Simple_Return_Statement;
-- Start of processing for Analyze_Dimension_Simple_Return_Statement
-- it cannot inherit a dimension from its subtype.
if Exists (Dims_Of_Id) then
- Error_Msg_N ("subtype& already" & Dimensions_Msg_Of (Id, True),
- N);
+ Error_Msg_N
+ ("subtype& already" & Dimensions_Msg_Of (Id, True), N);
+
else
Set_Dimensions (Id, Dims_Of_Etyp);
Set_Symbol (Id, Symbol_Of (Etyp));
if Exists (Symbol_Of (Etyp)) then
Symbols := Symbol_Of (Etyp);
-
else
Symbols := From_Dim_To_Str_Of_Unit_Symbols
(Dims_Of_Actual, System_Of (Base_Type (Etyp)));
begin
Start_String;
-
while Belong_To_Numeric_Literal (C) loop
Store_String_Char (C);
Src_Ptr := Src_Ptr + 1;
function Symbol_Of (E : Entity_Id) return String_Id is
Subtype_Symbol : constant String_Id := Symbol_Table.Get (E);
-
begin
if Subtype_Symbol /= No_String then
return Subtype_Symbol;
-
else
return From_Dim_To_Str_Of_Unit_Symbols
(Dimensions_Of (E), System_Of (Base_Type (E)));
return Null_System;
end System_Of;
+
end Sem_Dim;