From 8c0fd362fa6f9b38c0eb4f814fb2533336f966e5 Mon Sep 17 00:00:00 2001 From: Quentin Ochem Date: Thu, 30 May 2024 15:36:23 -0400 Subject: [PATCH 1/6] isolated file from the oop branch --- considered/rfc-oop-fields.rst | 81 +++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 considered/rfc-oop-fields.rst diff --git a/considered/rfc-oop-fields.rst b/considered/rfc-oop-fields.rst new file mode 100644 index 00000000..bd5ddb7f --- /dev/null +++ b/considered/rfc-oop-fields.rst @@ -0,0 +1,81 @@ +- Feature Name: Standard OOP model +- Start Date: May 5th 2020 +- RFC PR: +- RFC Issue: + +Summary +======= + +Motivation +========== + +Guide-level explanation +======================= + +Components declarations +----------------------- + +A record and tagged record type can now have 3 declarative +region where fields can be declared: + +- the package public view +- the package private view +- the record private view + +A public view that allows for additional fields to be declared is denoted by +`with private` after its declaration. The private view of a record type can +then be split between its own public and private sections: + +For example: + +.. code-block:: ada + + package P is + type R is record + Pub : Integer; + end R + with private; + + type T is tagged record + Pub : Integer; + end T + with private; + + private + + type R is record + Priv : Integer; + private + Hidden : Integer; + end R; + + type T is tagged record + Priv : Integer; + private + Hidden : Integer; + end T; + end P; + +Fields that are private to a type (noted `Hidden` in the above example) can +only be accessed through the primitives, constructors and destructors of that +very type. They are inaccessible to other subprograms, notably non-primitive +or overriden primitives. + +Reference-level explanation +=========================== + +Rationale and alternatives +========================== + +Drawbacks +========= + +Prior art +========= + +Unresolved questions +==================== + +Future possibilities +==================== + From ec40e4459b5ae9f23062f54cee4946e6332e7633 Mon Sep 17 00:00:00 2001 From: Quentin Ochem Date: Thu, 30 May 2024 15:47:57 -0400 Subject: [PATCH 2/6] expanded on the RFC --- considered/rfc-oop-fields.rst | 109 +++++++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 15 deletions(-) diff --git a/considered/rfc-oop-fields.rst b/considered/rfc-oop-fields.rst index bd5ddb7f..8a516068 100644 --- a/considered/rfc-oop-fields.rst +++ b/considered/rfc-oop-fields.rst @@ -15,8 +15,8 @@ Guide-level explanation Components declarations ----------------------- -A record and tagged record type can now have 3 declarative -region where fields can be declared: +A record and tagged record type can now have 3 declarative regions where fields +can be declared: - the package public view - the package private view @@ -33,33 +33,112 @@ For example: package P is type R is record Pub : Integer; - end R - with private; + end record + with private; -- There are more fields in the private view type T is tagged record Pub : Integer; - end T - with private; + end record + with private; -- There are more fields in the private view private type R is record Priv : Integer; - private - Hidden : Integer; - end R; + end record; type T is tagged record Priv : Integer; + end record; + end P; + +Visibilty rules of these fields are following the usual package-visibilty rules. + +In addition to the above, it is possible to add a `private` section within the +record itself: + +.. code-block:: ada + + package P is + type R is record + Pub : Integer; private - Hidden : Integer; - end T; + Pub_Hidden : Integer; + end record + with private; -- There are more fields in the private view + + type T is tagged record + Pub : Integer; + private + Pub_Hidden : Integer; + end record + with private; -- There are more fields in the private view + + private + + type R is record + Priv : Integer; + private + Priv_Hidden : Integer; + end record; + + type T is tagged record + Priv : Integer; + private + Priv_Hidden : Integer; + end record; + end P; + +Fields that are private to a type can only be accessed if: +- The field is visible from the package visibilty rules +- The access in a primitive of that type, or a primitive of a derived type. + +This is similar to the `protected` visibility level of languages such as Java +or C++. + +For example: + +.. code-block:: ada + + package P is + type Root is record + Pub : Integer; + private + Pub_Hidden : Integer; + end record; + + procedure Primitive (Self : Root); + + type Child is new Root with null record; + + procedure Primitive (Self : Child); + + package Other is + procedure Non_Primitive (Self : Root); + end Other; end P; -Fields that are private to a type (noted `Hidden` in the above example) can -only be accessed through the primitives, constructors and destructors of that -very type. They are inaccessible to other subprograms, notably non-primitive -or overriden primitives. + package body P is + procedure Primitive (Self : Root) is + begin + Self.Pub := 1; -- OK + Self.Pub_Hidden := 1; -- OK + end Primivite; + + procedure Primitive (Self : Child) is + begin + Self.Pub := 1; -- OK + Self.Pub_Hidden := 1; -- OK + end Primivite; + + package Other is + procedure Non_Primitive (Self : Root) is + begin + Self.Pub := 1; -- OK + Self.Pub_Hidden := 1; -- Compilation Error + end Non_Primitive; + end Other; + end P; Reference-level explanation =========================== From 52724fbd07484bc08be26c2cfe26c8567d1d468b Mon Sep 17 00:00:00 2001 From: Quentin Ochem Date: Thu, 29 Aug 2024 14:55:55 -0400 Subject: [PATCH 3/6] protected defition is now in a different RFC --- considered/rfc-oop-fields.rst | 86 ----------------------------------- 1 file changed, 86 deletions(-) diff --git a/considered/rfc-oop-fields.rst b/considered/rfc-oop-fields.rst index 8a516068..c14b4636 100644 --- a/considered/rfc-oop-fields.rst +++ b/considered/rfc-oop-fields.rst @@ -54,92 +54,6 @@ For example: Visibilty rules of these fields are following the usual package-visibilty rules. -In addition to the above, it is possible to add a `private` section within the -record itself: - -.. code-block:: ada - - package P is - type R is record - Pub : Integer; - private - Pub_Hidden : Integer; - end record - with private; -- There are more fields in the private view - - type T is tagged record - Pub : Integer; - private - Pub_Hidden : Integer; - end record - with private; -- There are more fields in the private view - - private - - type R is record - Priv : Integer; - private - Priv_Hidden : Integer; - end record; - - type T is tagged record - Priv : Integer; - private - Priv_Hidden : Integer; - end record; - end P; - -Fields that are private to a type can only be accessed if: -- The field is visible from the package visibilty rules -- The access in a primitive of that type, or a primitive of a derived type. - -This is similar to the `protected` visibility level of languages such as Java -or C++. - -For example: - -.. code-block:: ada - - package P is - type Root is record - Pub : Integer; - private - Pub_Hidden : Integer; - end record; - - procedure Primitive (Self : Root); - - type Child is new Root with null record; - - procedure Primitive (Self : Child); - - package Other is - procedure Non_Primitive (Self : Root); - end Other; - end P; - - package body P is - procedure Primitive (Self : Root) is - begin - Self.Pub := 1; -- OK - Self.Pub_Hidden := 1; -- OK - end Primivite; - - procedure Primitive (Self : Child) is - begin - Self.Pub := 1; -- OK - Self.Pub_Hidden := 1; -- OK - end Primivite; - - package Other is - procedure Non_Primitive (Self : Root) is - begin - Self.Pub := 1; -- OK - Self.Pub_Hidden := 1; -- Compilation Error - end Non_Primitive; - end Other; - end P; - Reference-level explanation =========================== From 8c8187e1774edb13416c34ba93cddf6193aece68 Mon Sep 17 00:00:00 2001 From: Quentin Ochem Date: Mon, 16 Sep 2024 11:39:41 -0400 Subject: [PATCH 4/6] fixed number of sections, only two in this proposal --- considered/rfc-oop-fields.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/considered/rfc-oop-fields.rst b/considered/rfc-oop-fields.rst index c14b4636..e2c9325c 100644 --- a/considered/rfc-oop-fields.rst +++ b/considered/rfc-oop-fields.rst @@ -15,12 +15,11 @@ Guide-level explanation Components declarations ----------------------- -A record and tagged record type can now have 3 declarative regions where fields +A record and tagged record type can now have 2 declarative regions where fields can be declared: - the package public view - the package private view -- the record private view A public view that allows for additional fields to be declared is denoted by `with private` after its declaration. The private view of a record type can From cd745e97526c59c06c151ca6239d89c181e6873a Mon Sep 17 00:00:00 2001 From: Elie Richa Date: Thu, 16 Jan 2025 19:07:18 +0100 Subject: [PATCH 5/6] Address empty views in rfc-oop-fields.rst --- considered/rfc-oop-fields.rst | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/considered/rfc-oop-fields.rst b/considered/rfc-oop-fields.rst index e2c9325c..c5dba5ec 100644 --- a/considered/rfc-oop-fields.rst +++ b/considered/rfc-oop-fields.rst @@ -53,6 +53,57 @@ For example: Visibilty rules of these fields are following the usual package-visibilty rules. +It is possible to declare empty public or private views either with an empty `record end record` section, or the shorthands `null record` syntax. + +For example, all of the following type declarations are legal: + +.. code-block:: ada + + package Legal is + type R1 is null record with private; -- This syntax is supported for declaring an empty public view + + type R2 is record + Pub : Integer; + end record + with private; + + type R3 is record + end record with private; -- This record type has both public and private views empty + + -- Same as R1, R2, R3 in tagged type forms + + type T1 is tagged null record with private; + + type T2 is tagged record + Pub : Integer; + end record + with private; + + type T3 is tagged null record with private; + + private + + type R1 is record + Priv : Integer; + end record; + + type R2 is record + end record; + + type R3 is null record; -- This record type has both public and private views empty + + type T1 is tagged record + Priv : Integer; + end record; + + type T2 is tagged null record; + + type T3 is tagged null record; + + end Legal; + +As outlined in the example, it is legal to declare both public and private views as empty. + Reference-level explanation =========================== From 5aa4d3331791049fa2d7bc152c340025454ab3bf Mon Sep 17 00:00:00 2001 From: Elie Richa Date: Thu, 16 Jan 2025 19:15:29 +0100 Subject: [PATCH 6/6] Address feedback in rfc-oop-fields.rst --- considered/rfc-oop-fields.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/considered/rfc-oop-fields.rst b/considered/rfc-oop-fields.rst index c5dba5ec..635fd27a 100644 --- a/considered/rfc-oop-fields.rst +++ b/considered/rfc-oop-fields.rst @@ -68,6 +68,7 @@ For example, all of the following type declarations are legal: with private; type R3 is record + null; end record with private; -- This record type has both public and private views empty -- Same as R1, R2, R3 in tagged type forms @@ -88,6 +89,7 @@ For example, all of the following type declarations are legal: end record; type R2 is record + null; end record; type R3 is null record; -- This record type has both public and private views empty