pragma Style_Checks (All_Checks);
separate (Par)
package body Ch12 is
function P_Formal_Derived_Type_Definition return Node_Id;
function P_Formal_Discrete_Type_Definition return Node_Id;
function P_Formal_Fixed_Point_Definition return Node_Id;
function P_Formal_Floating_Point_Definition return Node_Id;
function P_Formal_Modular_Type_Definition return Node_Id;
function P_Formal_Package_Declaration return Node_Id;
function P_Formal_Private_Type_Definition return Node_Id;
function P_Formal_Signed_Integer_Type_Definition return Node_Id;
function P_Formal_Subprogram_Declaration return Node_Id;
function P_Formal_Type_Declaration return Node_Id;
function P_Formal_Type_Definition return Node_Id;
function P_Generic_Association return Node_Id;
procedure P_Formal_Object_Declarations (Decls : List_Id);
function P_Generic return Node_Id is
Gen_Sloc : constant Source_Ptr := Token_Ptr;
Gen_Decl : Node_Id;
Decl_Node : Node_Id;
Decls : List_Id;
Def_Unit : Node_Id;
Ren_Token : Token_Type;
Scan_State : Saved_Scan_State;
begin
Scan;
if Token = Tok_Private then
Error_Msg_SC ("PRIVATE goes before GENERIC, not after");
Scan; end if;
Save_Scan_State (Scan_State);
if Token = Tok_Package
or else Token = Tok_Function
or else Token = Tok_Procedure
then
Ren_Token := Token;
Scan;
if Token = Tok_Identifier then
Def_Unit := P_Defining_Program_Unit_Name;
Check_Misspelling_Of (Tok_Renames);
if Token = Tok_Renames then
if Ren_Token = Tok_Package then
Decl_Node := New_Node
(N_Generic_Package_Renaming_Declaration, Gen_Sloc);
elsif Ren_Token = Tok_Procedure then
Decl_Node := New_Node
(N_Generic_Procedure_Renaming_Declaration, Gen_Sloc);
else Decl_Node := New_Node
(N_Generic_Function_Renaming_Declaration, Gen_Sloc);
end if;
Scan; Set_Defining_Unit_Name (Decl_Node, Def_Unit);
Set_Name (Decl_Node, P_Name);
TF_Semicolon;
return Decl_Node;
end if;
end if;
end if;
Restore_Scan_State (Scan_State);
Decls := New_List;
Decl_Loop : loop
P_Pragmas_Opt (Decls);
if Token = Tok_Private then
Error_Msg_S ("generic private child packages not permitted");
Scan; end if;
if Token = Tok_Use then
Append (P_Use_Clause, Decls);
else
if Token = Tok_Identifier then
P_Formal_Object_Declarations (Decls);
elsif Token = Tok_Type then
Append (P_Formal_Type_Declaration, Decls);
elsif Token = Tok_With then
Scan;
if Token = Tok_Package then
Append (P_Formal_Package_Declaration, Decls);
elsif Token = Tok_Procedure or Token = Tok_Function then
Append (P_Formal_Subprogram_Declaration, Decls);
else
Error_Msg_BC
("FUNCTION, PROCEDURE or PACKAGE expected here");
Resync_Past_Semicolon;
end if;
elsif Token = Tok_Subtype then
Error_Msg_SC ("subtype declaration not allowed " &
"as generic parameter declaration!");
Resync_Past_Semicolon;
else
exit Decl_Loop;
end if;
end if;
end loop Decl_Loop;
if Token = Tok_Package then
Gen_Decl := New_Node (N_Generic_Package_Declaration, Gen_Sloc);
Set_Specification (Gen_Decl, P_Package (Pf_Spcn));
else
Gen_Decl := New_Node (N_Generic_Subprogram_Declaration, Gen_Sloc);
Set_Specification (Gen_Decl, P_Subprogram_Specification);
if Nkind (Defining_Unit_Name (Specification (Gen_Decl))) =
N_Defining_Program_Unit_Name
and then Scope.Last > 0
then
Error_Msg_SP ("child unit allowed only at library level");
end if;
TF_Semicolon;
end if;
Set_Generic_Formal_Declarations (Gen_Decl, Decls);
return Gen_Decl;
end P_Generic;
function P_Generic_Actual_Part_Opt return List_Id is
Association_List : List_Id;
begin
if Token = Tok_Semicolon then
return No_List;
elsif Token /= Tok_Left_Paren
and then Token_Is_At_Start_Of_Line
and then Start_Column <= Scope.Table (Scope.Last).Ecol
then
return No_List;
else
Association_List := New_List;
T_Left_Paren;
loop
Append (P_Generic_Association, Association_List);
exit when not Comma_Present;
end loop;
T_Right_Paren;
return Association_List;
end if;
end P_Generic_Actual_Part_Opt;
function P_Generic_Association return Node_Id is
Scan_State : Saved_Scan_State;
Param_Name_Node : Node_Id;
Generic_Assoc_Node : Node_Id;
begin
Generic_Assoc_Node := New_Node (N_Generic_Association, Token_Ptr);
if Token in Token_Class_Desig then
Param_Name_Node := Token_Node;
Save_Scan_State (Scan_State); Scan;
if Token = Tok_Arrow then
Scan; Set_Selector_Name (Generic_Assoc_Node, Param_Name_Node);
else
Restore_Scan_State (Scan_State); end if;
end if;
Set_Explicit_Generic_Actual_Parameter (Generic_Assoc_Node, P_Expression);
return Generic_Assoc_Node;
end P_Generic_Association;
procedure P_Formal_Object_Declarations (Decls : List_Id) is
Decl_Node : Node_Id;
Scan_State : Saved_Scan_State;
Num_Idents : Nat;
Ident : Nat;
Idents : array (Int range 1 .. 4096) of Entity_Id;
begin
Idents (1) := P_Defining_Identifier (C_Comma_Colon);
Num_Idents := 1;
while Comma_Present loop
Num_Idents := Num_Idents + 1;
Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
end loop;
T_Colon;
if Num_Idents > 1 then
Save_Scan_State (Scan_State);
end if;
Ident := 1;
Ident_Loop : loop
Decl_Node := New_Node (N_Formal_Object_Declaration, Token_Ptr);
Set_Defining_Identifier (Decl_Node, Idents (Ident));
P_Mode (Decl_Node);
Set_Subtype_Mark (Decl_Node, P_Subtype_Mark_Resync);
No_Constraint;
Set_Expression (Decl_Node, Init_Expr_Opt);
if Ident > 1 then
Set_Prev_Ids (Decl_Node, True);
end if;
if Ident < Num_Idents then
Set_More_Ids (Decl_Node, True);
end if;
Append (Decl_Node, Decls);
exit Ident_Loop when Ident = Num_Idents;
Ident := Ident + 1;
Restore_Scan_State (Scan_State);
end loop Ident_Loop;
TF_Semicolon;
end P_Formal_Object_Declarations;
function P_Formal_Type_Declaration return Node_Id is
Decl_Node : Node_Id;
Def_Node : Node_Id;
begin
Decl_Node := New_Node (N_Formal_Type_Declaration, Token_Ptr);
Scan; Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
if P_Unknown_Discriminant_Part_Opt then
Set_Unknown_Discriminants_Present (Decl_Node, True);
else
Set_Discriminant_Specifications
(Decl_Node, P_Known_Discriminant_Part_Opt);
end if;
T_Is;
Def_Node := P_Formal_Type_Definition;
if Def_Node /= Error then
Set_Formal_Type_Definition (Decl_Node, Def_Node);
TF_Semicolon;
else
Decl_Node := Error;
if Token = Tok_Semicolon then
Scan;
end if;
end if;
return Decl_Node;
end P_Formal_Type_Declaration;
function P_Formal_Type_Definition return Node_Id is
Scan_State : Saved_Scan_State;
Typedef_Node : Node_Id;
begin
if Token_Name = Name_Abstract then
Check_95_Keyword (Tok_Abstract, Tok_Tagged);
end if;
if Token_Name = Name_Tagged then
Check_95_Keyword (Tok_Tagged, Tok_Private);
Check_95_Keyword (Tok_Tagged, Tok_Limited);
end if;
case Token is
when Tok_Abstract =>
Save_Scan_State (Scan_State);
Scan;
if Token = Tok_New then
Restore_Scan_State (Scan_State); return P_Formal_Derived_Type_Definition;
elsif Token = Tok_Limited then
Scan;
if Token = Tok_New then
Restore_Scan_State (Scan_State); return P_Formal_Derived_Type_Definition;
else
Restore_Scan_State (Scan_State); return P_Formal_Private_Type_Definition;
end if;
else
Restore_Scan_State (Scan_State); return P_Formal_Private_Type_Definition;
end if;
when Tok_Access =>
return P_Access_Type_Definition;
when Tok_Array =>
return P_Array_Type_Definition;
when Tok_Delta =>
return P_Formal_Fixed_Point_Definition;
when Tok_Digits =>
return P_Formal_Floating_Point_Definition;
when Tok_Interface => return P_Interface_Type_Definition (Is_Synchronized => False);
when Tok_Left_Paren =>
return P_Formal_Discrete_Type_Definition;
when Tok_Limited =>
Save_Scan_State (Scan_State);
Scan;
if Token = Tok_Interface then
Typedef_Node := P_Interface_Type_Definition
(Is_Synchronized => False);
Set_Limited_Present (Typedef_Node);
return Typedef_Node;
elsif Token = Tok_New then
Restore_Scan_State (Scan_State); return P_Formal_Derived_Type_Definition;
else
if Token = Tok_Abstract then
Error_Msg_SC ("ABSTRACT must come before LIMITED");
Scan;
if Token = Tok_New then
Restore_Scan_State (Scan_State); return P_Formal_Derived_Type_Definition;
else
Restore_Scan_State (Scan_State);
return P_Formal_Private_Type_Definition;
end if;
end if;
Restore_Scan_State (Scan_State);
return P_Formal_Private_Type_Definition;
end if;
when Tok_Mod =>
return P_Formal_Modular_Type_Definition;
when Tok_New =>
return P_Formal_Derived_Type_Definition;
when Tok_Private |
Tok_Tagged =>
return P_Formal_Private_Type_Definition;
when Tok_Range =>
return P_Formal_Signed_Integer_Type_Definition;
when Tok_Record =>
Error_Msg_SC ("record not allowed in generic type definition!");
Discard_Junk_Node (P_Record_Definition);
return Error;
when Tok_Protected |
Tok_Synchronized |
Tok_Task =>
Scan;
declare
Saved_Token : constant Token_Type := Token;
begin
Typedef_Node := P_Interface_Type_Definition
(Is_Synchronized => True);
case Saved_Token is
when Tok_Task =>
Set_Task_Present (Typedef_Node);
when Tok_Protected =>
Set_Protected_Present (Typedef_Node);
when Tok_Synchronized =>
Set_Synchronized_Present (Typedef_Node);
when others =>
null;
end case;
return Typedef_Node;
end;
when others =>
Error_Msg_BC ("expecting generic type definition here");
Resync_Past_Semicolon;
return Error;
end case;
end P_Formal_Type_Definition;
function P_Formal_Private_Type_Definition return Node_Id is
Def_Node : Node_Id;
begin
Def_Node := New_Node (N_Formal_Private_Type_Definition, Token_Ptr);
if Token = Tok_Abstract then
Scan;
if Token_Name = Name_Tagged then
Check_95_Keyword (Tok_Tagged, Tok_Private);
Check_95_Keyword (Tok_Tagged, Tok_Limited);
end if;
if Token /= Tok_Tagged then
Error_Msg_SP ("ABSTRACT must be followed by TAGGED");
else
Set_Abstract_Present (Def_Node, True);
end if;
end if;
if Token = Tok_Tagged then
Set_Tagged_Present (Def_Node, True);
Scan; end if;
if Token = Tok_Limited then
Set_Limited_Present (Def_Node, True);
Scan; end if;
if Token = Tok_Abstract then
if Prev_Token = Tok_Tagged then
Error_Msg_SC ("ABSTRACT must come before TAGGED");
elsif Prev_Token = Tok_Limited then
Error_Msg_SC ("ABSTRACT must come before LIMITED");
end if;
Resync_Past_Semicolon;
elsif Token = Tok_Tagged then
Error_Msg_SC ("TAGGED must come before LIMITED");
Resync_Past_Semicolon;
end if;
Set_Sloc (Def_Node, Token_Ptr);
T_Private;
return Def_Node;
end P_Formal_Private_Type_Definition;
function P_Formal_Derived_Type_Definition return Node_Id is
Def_Node : Node_Id;
begin
Def_Node := New_Node (N_Formal_Derived_Type_Definition, Token_Ptr);
if Token = Tok_Abstract then
Set_Abstract_Present (Def_Node);
Scan; end if;
if Token = Tok_Limited then
Set_Limited_Present (Def_Node);
Scan;
if Ada_Version < Ada_05 then
Error_Msg_SP
("LIMITED in derived type is an Ada 2005 extension");
Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
end if;
if Token = Tok_Abstract then
Scan; end if;
end if;
Scan; Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
No_Constraint;
if Token = Tok_And then
Scan;
if Ada_Version < Ada_05 then
Error_Msg_SP
("abstract interface is an Ada 2005 extension");
Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
end if;
Set_Interface_List (Def_Node, New_List);
loop
Append (P_Qualified_Simple_Name, Interface_List (Def_Node));
exit when Token /= Tok_And;
Scan; end loop;
end if;
if Token = Tok_With then
Scan; Set_Private_Present (Def_Node, True);
T_Private;
elsif Token = Tok_Tagged then
Scan;
if Token = Tok_Private then
Error_Msg_SC ("TAGGED should be WITH");
Set_Private_Present (Def_Node, True);
T_Private;
else
Ignore (Tok_Tagged);
end if;
end if;
return Def_Node;
end P_Formal_Derived_Type_Definition;
function P_Formal_Discrete_Type_Definition return Node_Id is
Def_Node : Node_Id;
begin
Def_Node := New_Node (N_Formal_Discrete_Type_Definition, Token_Ptr);
Scan; T_Box;
T_Right_Paren;
return Def_Node;
end P_Formal_Discrete_Type_Definition;
function P_Formal_Signed_Integer_Type_Definition return Node_Id is
Def_Node : Node_Id;
begin
Def_Node :=
New_Node (N_Formal_Signed_Integer_Type_Definition, Token_Ptr);
Scan; T_Box;
return Def_Node;
end P_Formal_Signed_Integer_Type_Definition;
function P_Formal_Modular_Type_Definition return Node_Id is
Def_Node : Node_Id;
begin
Def_Node :=
New_Node (N_Formal_Modular_Type_Definition, Token_Ptr);
Scan; T_Box;
return Def_Node;
end P_Formal_Modular_Type_Definition;
function P_Formal_Floating_Point_Definition return Node_Id is
Def_Node : Node_Id;
begin
Def_Node :=
New_Node (N_Formal_Floating_Point_Definition, Token_Ptr);
Scan; T_Box;
return Def_Node;
end P_Formal_Floating_Point_Definition;
function P_Formal_Fixed_Point_Definition return Node_Id is
Def_Node : Node_Id;
Delta_Sloc : Source_Ptr;
begin
Delta_Sloc := Token_Ptr;
Scan; T_Box;
if Token = Tok_Digits then
Def_Node :=
New_Node (N_Formal_Decimal_Fixed_Point_Definition, Delta_Sloc);
Scan; T_Box;
else
Def_Node :=
New_Node (N_Formal_Ordinary_Fixed_Point_Definition, Delta_Sloc);
end if;
return Def_Node;
end P_Formal_Fixed_Point_Definition;
function P_Formal_Subprogram_Declaration return Node_Id is
Prev_Sloc : constant Source_Ptr := Prev_Token_Ptr;
Spec_Node : constant Node_Id := P_Subprogram_Specification;
Def_Node : Node_Id;
begin
if Token = Tok_Is then
T_Is;
if Token = Tok_Abstract then
Def_Node :=
New_Node (N_Formal_Abstract_Subprogram_Declaration, Prev_Sloc);
Scan;
if Ada_Version < Ada_05 then
Error_Msg_SP
("formal abstract subprograms are an Ada 2005 extension");
Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
end if;
else
Def_Node :=
New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
end if;
Set_Specification (Def_Node, Spec_Node);
if Token = Tok_Semicolon then
Scan;
elsif Token = Tok_Box then
Set_Box_Present (Def_Node, True);
Scan; T_Semicolon;
elsif Token = Tok_Null then
if Ada_Version < Ada_05 then
Error_Msg_SP
("null default subprograms are an Ada 2005 extension");
Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
end if;
if Nkind (Spec_Node) = N_Procedure_Specification then
Set_Null_Present (Spec_Node);
else
Error_Msg_SP ("only procedures can be null");
end if;
Scan; T_Semicolon;
else
Set_Default_Name (Def_Node, P_Name);
T_Semicolon;
end if;
else
Def_Node :=
New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
Set_Specification (Def_Node, Spec_Node);
T_Semicolon;
end if;
return Def_Node;
end P_Formal_Subprogram_Declaration;
function P_Formal_Package_Declaration return Node_Id is
Def_Node : Node_Id;
Scan_State : Saved_Scan_State;
begin
Def_Node := New_Node (N_Formal_Package_Declaration, Prev_Token_Ptr);
Scan; Set_Defining_Identifier (Def_Node, P_Defining_Identifier (C_Is));
T_Is;
T_New;
Set_Name (Def_Node, P_Qualified_Simple_Name);
if Token = Tok_Left_Paren then
Save_Scan_State (Scan_State); Scan;
if Token = Tok_Box then
Set_Box_Present (Def_Node, True);
Scan; T_Right_Paren;
else
Restore_Scan_State (Scan_State); Set_Generic_Associations (Def_Node, P_Generic_Actual_Part_Opt);
end if;
end if;
T_Semicolon;
return Def_Node;
end P_Formal_Package_Declaration;
end Ch12;