Annotated King Reference Manual/Declarations

From Wikibooks, open books for an open world
Jump to navigation Jump to search

This page is work in progress.

Declarations[edit | edit source]

Syntax[edit | edit source]

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
          | exception_declaration
          | macro_declaration
          | macro_expansion

defining_program_unit_name ::= [parent_unit_name.] defining_identifier

Rationale[edit | edit source]

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 | edit source]

-

Null Declarations[edit | edit source]

Examples[edit | edit source]

null;

Syntax[edit | edit source]

null_declaration ::= null;

Rationale[edit | edit source]

-

Discussion[edit | edit source]

-

Type Declarations[edit | edit source]

See section Types.

Subtype Declarations[edit | edit source]

Examples[edit | edit source]

subtype Month_Number is Integer range 1 .. 12;

Syntax[edit | edit source]

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 | edit source]

-

Discussion[edit | edit source]

-

Object Declarations[edit | edit source]

Examples[edit | edit source]

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

Syntax[edit | edit source]

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

Rationale[edit | edit source]

-

Discussion[edit | edit source]

-

Named Value Declarations[edit | edit source]

Examples[edit | edit source]

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

Syntax[edit | edit source]

named_value_declaration ::= defining_identifier = static_expression;

Rationale[edit | edit source]

-

Discussion[edit | edit source]

-

Subprogram Declarations[edit | edit source]

Examples[edit | edit source]

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

Syntax[edit | edit source]

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 | edit source]

-

Discussion[edit | edit source]

-

Statement Procedure Declarations[edit | edit source]

Examples[edit | edit source]

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

Syntax[edit | edit source]

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 | edit source]

Inner declared objects can only be constant declarations.

Discussion[edit | edit source]

-

Expression Function Declarations[edit | edit source]

Examples[edit | edit source]

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

Syntax[edit | edit source]

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

Rationale[edit | edit source]

-

Discussion[edit | edit source]

-

Module Declarations[edit | edit source]

Examples[edit | edit source]

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 | edit source]

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 | edit source]

-

Discussion[edit | edit source]

-

Renaming Declarations[edit | edit source]

Examples[edit | edit source]

Main_Window : constant Window_ID renames King.GUI.Main_Window;

Syntax[edit | edit source]

renaming_declaration ::=
            object_renaming_declaration
          | exception_renaming_declaration
          | module_renaming_declaration
          | subprogram_renaming_declaration
          | macro_renaming_declaration

object_renaming_declaration ::= 
          defining_identifier : [constant] subtype_mark renames object_name [aspect_specification];

exception_renaming_declaration ::=
          defining_identifier : exception renames exception_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 | edit source]

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 | edit source]

-

Exception Declarations[edit | edit source]

Examples[edit | edit source]

Invalid_File : exception;

Syntax[edit | edit source]

exception_declaration ::= defining_identifier : exception [aspect_specification];

Rationale[edit | edit source]

-

Discussion[edit | edit source]

-

Macro Declarations[edit | edit source]

Examples[edit | edit source]

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 | edit source]

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 | edit source]

-

Discussion[edit | edit source]

-

Macro Expansions[edit | edit source]

Examples[edit | edit source]

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

Syntax[edit | edit source]

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 | edit source]

-

Discussion[edit | edit source]

-