Annotated King Reference Manual/Declarations

This page is work in progress.

Declarations

edit

Syntax

edit
declarative_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

edit

Inside 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

edit

Examples

edit
null;

Syntax

edit
null_declaration ::= null;

Rationale

edit

-

Discussion

edit

-

Type Declarations

edit

See section Types.

Subtype Declarations

edit

Examples

edit
subtype Month_Number is Integer range 1 .. 12;

Syntax

edit
subtype_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

edit

Examples

edit
Owner : State_Map is State_Map'(others => False);

Syntax

edit
object_declaration ::= defining_identifier : [constant] subtype_indication [is expression]
                          [aspect_specification];

Rationale

edit

-

Discussion

edit

-

Named Value Declarations

edit

Examples

edit
Thinking = 10.0;
Message = "Hello, World!";

Syntax

edit
named_value_declaration ::= defining_identifier = static_expression;

Rationale

edit

-

Discussion

edit

-

Subprogram Declarations

edit

Examples

edit
Set_Seed : procedure (State : out State; Seed : in Result <- Result'Last);
Random : function (State : in out State) return Result;

Syntax

edit
subprogram_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

edit

Examples

edit
Set_Seed : procedure (Seed : in Result <- 0) is (State <- Seed);
Nothing : procedure is (null);

Syntax

edit
statement_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

edit

Inner declared objects can only be constant declarations.

Discussion

edit

-

Expression Function Declarations

edit

Examples

edit
Has_Sticks : function (ID : in Philosopher_ID) return Boolean is (Owner (ID) );

Syntax

edit
expression_function_declaration ::=
           function_specification [aspect_specification] is (expression);

Rationale

edit

-

Discussion

edit

-

Module Declarations

edit

Examples

edit
Bad_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

edit
module_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

edit

Examples

edit
Main_Window : constant Window_ID renames King.GUI.Main_Window;

Syntax

edit
renaming_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

edit

The 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

edit

Examples

edit
Bounded_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

edit
macro_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

edit

Examples

edit
Wrap : module is new King.Algorithms.Wrapping (Element => Philosopher_ID);

Syntax

edit
macro_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

-