Annotated King Reference Manual/Declarations
This page is work in progress.
Declarations
editSyntax
editdeclarative_part ::= declarative_item {declarative_item} declarative_item ::= basic_declarative_item | body basic_declarative_item ::= basic_declaration | aspect_clause basic_declaration ::= null_declaration | type_declaration | subtype_declaration | object_declaration | named_value_declaration | subprogram_declaration | statement_procedure_declaration | expression_function_declaration | module_declaration | renaming_declaration | macro_declaration | macro_expansion defining_program_unit_name ::= [parent_unit_name.] defining_identifier
Rationale
editInside basic_declaration, defining_program_unit_name shall be only an identifier.
The mention of parent_unit_name may appear only at library level. It is provided here as some declarations apply at library level.
Discussion
edit-
Null Declarations
editExamples
editnull;
Syntax
editnull_declaration ::= null;
Rationale
edit-
Discussion
edit-
Type Declarations
editSee section Types.
Subtype Declarations
editExamples
editsubtype Month_Number is Integer range 1 .. 12;
Syntax
editsubtype_declaration ::= subtype defining_identifier is subtype_indication [aspect_specification]; subtype_indication ::= subtype_mark [constraint] subtype_mark ::= subtype_name
constraint ::= scalar_constraint | composite_constraint scalar_constraint ::= range_constraint range_constraint ::= range range_specification range_specification ::= range_attribute_reference | simple_expression .. simple_expression range_attribute_reference ::= prefix'range_attribute_designator range_attribute_designator ::= range composite_constraint ::= discriminant_constraint discriminant_constraint ::= (discriminant_association {, discriminant_association}) discriminant_association ::= discriminant_selector_name => expression
Rationale
edit-
Discussion
edit-
Object Declarations
editExamples
editOwner : State_Map is State_Map'(others => False);
Syntax
editobject_declaration ::= defining_identifier : [constant] subtype_indication [is expression] [aspect_specification];
Rationale
edit-
Discussion
edit-
Named Value Declarations
editExamples
editThinking = 10.0;
Message = "Hello, World!";
Syntax
editnamed_value_declaration ::= defining_identifier = static_expression;
Rationale
edit-
Discussion
edit-
Subprogram Declarations
editExamples
editSet_Seed : procedure (State : out State; Seed : in Result <- Result'Last);
Random : function (State : in out State) return Result;
Syntax
editsubprogram_declaration ::= subprogram_specification [aspect_specification]; subprogram_specification ::= procedure_specification | function_specification procedure_specification ::= defining_program_unit_name : procedure parameter_profile function_specification ::= defining_designator : function parameter_and_result_profile defining_designator ::= defining_program_unit_name | defining_operator_symbol operator_symbol ::= string_literal parameter_profile ::= [formal_part] parameter_and_result_profile ::= [formal_part] return subtype_mark formal_part ::= (parameter_specification {; parameter_specification}) parameter_specification ::= defining_identifier : parameter_mode subtype_mark [<- default_expression] parameter_mode ::= in | in out | out
Rationale
edit-
Discussion
edit-
Statement Procedure Declarations
editExamples
editSet_Seed : procedure (Seed : in Result <- 0) is (State <- Seed);
Nothing : procedure is (null);
Syntax
editstatement_procedure_declaration ::= simple_statement_procedure | declare_statement_procedure simple_statement_procedure ::= procedure_specification [aspect_specification] is (simple_statement); declare_statement_procedure ::= procedure_specification [aspect_specification] is (declare declare_declaration {declare_declaration} begin simple_statement); declare_declaration ::= subtype_declaration | object_declaration | named_value_declaration
Rationale
editInner declared objects can only be constant declarations.
Discussion
edit-
Expression Function Declarations
editExamples
editHas_Sticks : function (ID : in Philosopher_ID) return Boolean is (Owner (ID) );
Syntax
editexpression_function_declaration ::= function_specification [aspect_specification] is (expression);
Rationale
edit-
Discussion
edit-
Module Declarations
editExamples
editBad_Random : module is
type State is hidden;
type Result is range 0 .. 2 ^ 16 - 1;
Set_Seed : procedure (State : out State; Seed : in Result <- Result'Last);
Random : function (State : in out State) return Result;
Bad_Random : end module;
Syntax
editmodule_declaration ::= module_specification; module_specification ::= defining_program_unit_name : module [aspect_specification] is {basic_declarative_item} [parent_unit_name.]identifier : end module
Rationale
edit-
Discussion
edit-
Renaming Declarations
editExamples
editMain_Window : constant Window_ID renames King.GUI.Main_Window;
Syntax
editrenaming_declaration ::= object_renaming_declaration | module_renaming_declaration | subprogram_renaming_declaration | macro_renaming_declaration object_renaming_declaration ::= defining_identifier : [constant] subtype_mark renames object_name [aspect_specification]; module_renaming_declaration ::= defining_program_unit_name : module renames module_name [aspect_specification]; subprogram_renaming_declaration ::= subprogram_specification renames callable_entity_name [aspect_specification]; macro_renaming_declaration ::= defining_program_unit_name : macro module renames macro_module_name [aspect_specification];
Rationale
editThe subtype of renaming object must be the same as for the renamed object.
Renaming a constant object shall include the reserved word constant, on the contrary variable object shall not.
Use a new name value for renaming a named value. Use a new subtype name for renaming a subtype.
Discussion
edit-
Macro Declarations
editExamples
editBounded_Lists : macro
type Element is hidden with <-;
"=" : function (Left : in Element; Right : in Element) return Boolean is <>;
Bounded_Lists : module is
type List (Max_Length : Position_Value) is hidden with Default_Initial_Condition => List.Is_Empty;
Length : function (List : in List) return Count_Value;
Is_Empty : function (List : in List) return Boolean is (List.Length = 0);
Is_Full : function (List : in List) return Boolean is (List.Length = List.Max_Length);
-- ...
Bounded_Lists : end module;
Syntax
editmacro_declaration ::= macro_module_declaration macro_module_declaration ::= defining_program_unit_name : macro_formal_part module_specification; macro_formal_part ::= macro macro_formal_parameter_declaration {macro_formal_parameter_declaration} macro_formal_parameter_declaration ::= formal_object_declaration | formal_type_declaration | formal_subprogram_declaration formal_object_declaration ::= defining_identifier : constant subtype_mark [<- default_expression] [aspect_specification]; formal_type_declaration ::= formal_complete_type_declaration formal_complete_type_declaration ::= type defining_identifier[discriminant_part] is formal_type_definition [or use default_subtype_mark] [aspect_specification]; formal_type_definition ::= formal_hidden_type_definition | formal_map_type_definition | formal_sequence_type_definition | formal_set_type_definition | formal_discrete_type_definition | formal_signed_integer_type_definition | formal_floating_point_definition | formal_ordinary_fixed_point_definition | formal_any_numeric_definition formal_hidden_type_definition ::= hidden [(<>)] [with <-] formal_map_type_definition ::= map_type_definition formal_sequence_type_definition ::= sequence_type_definition formal_set_type_definition ::= set_type_definition formal_discrete_type_definition ::= [range] (<>) formal_signed_integer_type_definition ::= range <> formal_floating_point_definition ::= digits <> formal_ordinary_fixed_point_definition ::= delta <> formal_any_numeric_definition ::= delta digits [range] <> formal_subprogram_declaration ::= formal_concrete_subprogram_declaration formal_concrete_subprogram_declaration ::= subprogram_specification [is subprogram_default][aspect_specification]; | statement_procedure_declaration | expression_function_declaration subprogram_default ::= default_name | <>
Rationale
edit-
Discussion
edit-
Macro Expansions
editExamples
editWrap : module is new King.Algorithms.Wrapping (Element => Philosopher_ID);
Syntax
editmacro_expansion ::= defining_program_unit_name : module is new macro_module_name [macro_actual_part] [aspect_specification]; macro_actual_part ::= (macro_association {, macro_association}) macro_association ::= macro_formal_parameter_selector_name => explicit_macro_actual_parameter explicit_macro_actual_parameter ::= expression | subprogram_name | subtype_mark
Rationale
edit-
Discussion
edit-