注释国王参考手册/类型
此页面正在建设中。
一些一般原则
- 所有标量子类型都有一个默认值。对于有界数值和枚举子类型,这是子类型的“第一个”,除非在 Default_Value 方面指定了不同的值。对于无界数值子类型,必须指定 Default_Value 方面。请注意,无界数值类型可以有有界子类型。
- 可以为所有子类型指定 Predicate 方面。
- 所有标量类型都具有属性 'Image、'Value、'Min、'Max、'Previous 和 'Next。
- 整数和枚举类型具有属性 'Position、'Value (integer)、'Representation 和 'From_Representation。对于整数类型,'Position 和 'Representation 都给出参数的值,'Value (integer) 和 'From_Representation 给出具有参数值的类型的值(如果存在);这类似于 Ada 中整数类型的 'Pos 和 "Val。
- 'Image <=>、'Value (string) 互为反函数,'Position <=> 'Value (integer) 也是如此。
type_declaration ::= full_type_declaration | hidden_type_declaration full_type_declaration ::= type defining_identifier [known_discriminant_part] is type_definition [aspect_specification]; hidden_type_declaration ::= type defining_identifier [discriminant_part] is hidden [aspect_specification]; discriminant_part ::= unknown_discriminant_part | known_discriminant_part unknown_discriminant_part ::= (<>) known_discriminant_part ::= (discriminant_specification {; discriminant_specification}) discriminant_specification ::= defining_identifier : subtype_mark [<- default_expression] type_definition ::= enumeration_type_definition | integer_type_definition | real_type_definition | map_type_definition | sequence_type_definition | set_type_definition | record_type_definition | derived_type_definition | module_type_definition | task_type_definition
-
-
type Suit is (Spade, Club, Heart, Diamond);
type Philosopher_ID is (Archimedes, Descartes, Hegel, Kant, Socrates);
enumeration_type_definition ::= (enumeration_literal_specification {, enumeration_literal_specification}) enumeration_literal_specification ::= defining_identifier | defining_character_literal
= /= < <= > >=
First, Last, Position, From_Representation, Representation, Image, Value, Min, Max, Previous, Next
Bit_Size, Byte_Size
My_Card : Suit;
-
-
type Day is range 1 .. 31;
type Factorial is range <> with Default_Value => 0;
integer_type_definition ::= bounded_integer_type_definition | unbounded_integer_type_definition bounded_integer_type_definition ::= range static_simple_expression .. static_simple_expression unbounded_integer_type_definition ::= range <>
+ - * / rem mod ^ = /= < <= > >= and or xor not
First, Last, Bit_Wise_Operators, Image, Value, Min, Max, Previous, Next, Valid
具有 Bit_Wise_Operators = True 的附加属性
Shift_Left, Shift_Right, Rotate_Left, Rotate_Right, Mod
Default_Value, Predicate, Signed_Representation, Overflow_Checking
N : Factorial;
所有适合单个硬件整数的有界整数类型都可用它的基本类型的位运算。
-
real_type_definition ::= floating_point_definition | fixed_point_definition
type Risk is digits 7 range 0 .. 1;
type Rational is digits <> with Default_Value => 0;
floating_point_definition ::= bounded_floating_point_definition | unbounded_floating_point_definition bounded_floating_point_definition ::= digits static_expression [real_range_specification] real_range_specification ::= range static_simple_expression .. static_simple_expression unbounded_floating_point_definition ::= digits <>
+ - * / ^ = /= < <= > >=
Image, Value, Min, Max, Previous, Next, Valid, digits
Default_Value, Predicate
Speed : Rational;
-
-
type Angle is delta 0.01 range -3.14 .. 3.14;
type Duration is delta 10.0 ^ -9 range <> with Default_Value => 0;
fixed_point_definition ::= bounded_fixed_point_definition | unbounded_fixed_point_definition bounded_fixed_point_definition ::= delta static_expression real_range_specification unbounded_fixed_point_definition ::= delta static_expression range <>
+ - * / ^ = /= < <= > >=
图像、值、最小值、最大值、前一个、下一个、有效、增量
Default_Value, Predicate
Bearing : Angle;
不应该提供小数类型,以涵盖 Ada 中相应的可用类型吗?
增量为 10 的幂的 King 定点类型等效于 Ada 小数定点类型。
type Money is delta 0.01 digits 14;
上面的代码等效于
type Money is delta 0.01 range -999_999_999_999.99 .. 999_999_999_999.99;
-
type Store is map Part_Key => Stock_Info;
map_type_definition := map key_subtype_mark => value_subtype_mark
= /=
"=" 只有在为值子类型定义时才定义。
-
删除、清除、定义、大小
-
My_Store : Store;
My_Store (K99)
Store'(K1 => SI1, KE => SIE)
Store'(null) -- Empty map
for K in My_Store'range
for E of My_Store
映射也可以通过函数实现,因此 King 对两者使用相同的符号。
-
type Stack is sequence of Message;
sequence_type_definition := sequence of element_subtype_mark
= /= &
"=" 只有在为值子类型定义时才定义。
-
删除、清除、长度
-
My_Stack : Stack;
My_Stack [Curent]
My_Stack'[MC, ML, MZ]
My_Stack'[null] -- Empty sequence
for P in [reverse] My_Stack'range
for E of [reverse] My_Stack
-
-
type File_Mask is set of File_Mode;
set_type_definition := set of element_subtype_mark
+ - * / = /= < <= > >= [not] in
-
大小
-
My_Mask : File_Mask:
-
My_Mask'{Read, Exec}
My_Mask'{null} -- Empty set
My_Mask'{all} -- Full set
for M of My_Mask
-
-
type Complex is record
Re : Float;
Im : Float;
end record Complex;
record_type_definition ::= record_definition record_definition ::= record component_list end record record_identifier component_list ::= component_item {component_item} | {component_item} variant_part | null; component_item ::= component_declaration component_declaration ::= defining_identifier : component_definition [<- default_expression] [aspect_specification]; component_definition ::= subtype_indication variant_part ::= case discriminant_direct_name is variant {variant} end case; variant ::= when discrete_choice_list => component_list discrete_choice_list ::= discrete_choice {| discrete_choice} discrete_choice ::= choice_expression | discrete_subtype_indication | range_specification | others
= /=
-
-
Z : Complex;
Z.Re
-
-
type Boxes (Length : Position_Value) is record
Box_A : Receive_Box (Max_Length => Length);
Box_B : Receive_Box (Max_Length => Length);
end record;
type Boxes_4 is new Boxes (Length => 4);
derived_type_definition ::= new parent_subtype_indication
-
-
-
操作、属性等基于父类型。
-
type Strings is module
Set : procedure (S : String);
Index : function (Pattern : String; Going : Direction <- Forward) return Position_Value;
Head : function (Count : Natural; Pad : Unicode <- Space) return String;
-- ...
end module Strings;
module_type_definition ::= module subprogram_declaration {subprogram_declaration} end module module_identifier
-
-
-
-
-
type Philosopher (ID : Philosopher_ID <- Archimedes) is task;
task_type_definition ::= task
= /=
-
-
T1 : Philosopher;
-
-
type Semaphore is task
Secure : procedure;
Release : procedure;
end task Semaphore;
task_type_definition ::= task subprogram_declaration {subprogram_declaration} end task task_identifier
= /=
-
-
S1 : Semaphore;
被动任务是主动任务之间唯一可以进行通信的方式。
-