To: J3 J3/19-231r2 From: Van Snyder & Malcolm Cohen Subject: Formal Specifications for True Enumeration types Date: 2019-October-16 Reference: 18-114r1 18-256r1 19-216r1 19-230r2 0. Changes resulting from straw votes 2019-10-15 11. Are enumerators specifiable whether class (1) or not, always class (1), magic to disambiguate if class (1), never class (1)? 0-0-0-15. 21. Clamp if construction out of range? Yes, no, indifferent: 0, 15, 0. 21. Constructor, function, indifferent? 10-0-5. 21. Constructor incorrect value: undefined, error, indifferent: 6-2-7. 21. Next, prev: Error, undefined, clamp, stat=, indifferent: 0-0-13-2. Requirement B: Deleted from 19-230r1. Requirement D: Default initial value may be provided. MIN, MAX, MINVAL, MAXVAL, MINLOC, MAXLOC, FINDLOC added without objection (this was intended for r1 but overlooked). 1. Introduction This paper contains the proposed formal specifications for enumeration types (proposal US21). These have been extracted from 19-216r1, which mixes together requirements and specifications, and reworded. It is essential to refer to the Formal Requirements document (19-230r2) when reading this paper. This paper does not contain the formal syntax of the feature. Any syntax in this paper is illustrative. Letters in brackets refer to requirements in 19-230r2. 2. Formal specifications 1. [A] An enumeration type name shall be a class (1) name, and shall be treated the same as (other) derived type names. 2. [A] An enumeration type shall have at least one enumerator. (Otherwise it would have no possible value.) 3. [A] An enumeration type is a derived type that is not a structure type. It has no type parameters. COMMENT: Type parameters just don't seem to make sense for enumeration types. 4. [B] The type definition shall have no type-bound-procedure-part. COMMENT: We could permit a type-bound procedure part now, or permit one in the future. The semantics of having type-bound procedures would seem to make sense; however, in the interests of keeping this feature to a manageable size, we should not allow it now. 5. [A] An enumeration type cannot be a SEQUENCE or BIND(C) type; therefore enumeration type definitions in different scoping units will produce different enumeration types, even if the type definitions themselves are textually identical. Furthermore, a SEQUENCE or BIND(C) type shall not contain a component that is of enumeration type. An object of enumeration type cannot appear in a storage association context. 6. [A] An enumeration type definition shall list all the enumerators in order; the ordinal number of an enumerator is its position in the list. 7. Deleted. 8. [A] Extending a structure type cannot produce an enumeration type. 9. [A] The enumerator values of an enumeration shall have an internal representation that is the same as a processor-dependent integer kind, with the value being the same as the ordinal number of the enumerator. COMMENT: This is actually merely implementation advice, so maybe this should be a "should" not a "shall". It is conceivable that a processor might want to put some extra info into an enum type, e.g. it might have its name, or where it was defined, etc. 10. Deleted. 11. [F] Enumerator names are class (2) names. 12. Deleted. 13. [F] An enumerator is a constant expression. 14. [F] Accessing the name of an enumeration type by use association does not make any of its enumerator names available (because enumerator names are not class (1) names). 15. [F] The syntax for denoting an enumerator shall involve the enumeration type name and no other class (1) name. If the enumeration type name is inaccessible, this syntax shall not be available. 16. Deleted because enumerator names are not class (1) names. 17. [H] A variable of enumeration type shall be initialised only by a value of that enumeration type. 18. [H] Default initialisation of components that have enumeration type shall be allowed. If no default initialisation is specified, the component is nonetheless default-initialised to the default value for the enumeration type (if any). 19. [I] In intrinsic assignment involving enumeration type, the type of the variable shall be the same type. 20. [K] The conversion mechanism from enumeration to integer shall be the intrinsic function INT. 21. [K] Definition of a type constructor implicitly defines a type constructor of the same name. The conversion mechanism from integer to enumeration shall be this type constructor; note that this is NOT a structure constructor. As the ordinal value is not a component; it does not have a name. If the integer value is not one of the ordinal values of enumerators of the type, the result is undefined. 22. [L] The mechanisms for enquiring the first/last enumeration values shall use an entity of that enumeration type. The result is a constant expression. 23. [M] The "next" and "previous" values from a data object of enumeration type can be produced by functions defined as a consequence of the type definition. The "next" value after the last one, and and "previous" value of the first one, are errors. These functions have some optional way of returning an error status to the caller, with error termination on error if missing. 24. [N] Formatted output of enumeration values produces the name of the enumerator in upper case (not qualified by the type name). Formatted input shall accept both lower case and upper case as equivalent. Explicit formatting uses the "A" format descriptor. List-directed and namelist output do not enclose the text of the enumerator name within apostrophes or quotes 25. [N] Unformatted files use a processor dependent representation for values of enumeration types. 26. [O] When a SELECT CASE expression is of enumeration type, the CASE values shall be of the same type. CASE ranges shall be available; the ordinal number of the second value shall be greater than or equal to the ordinal number of the first. 27. [C,P] If a DO index variable is of enumeration type, the variable shall have its type explicitly declared on the DO statement, limiting its scope to the DO or DO CONCURRENT construct. The remaining specifications do not refer to any particular requirement. 28. Generic resolution shall treat different enumeration types as different types, and different from any other type. 29. A variable of enumeration type shall not be polymorphic. 30. Argument association shall treat different enumeration types as different. 31. [C] TRANSFER into an enumeration type should be limited to values that resulted from a TRANSFER out of the same enumeration type. 32. Because enumerators are ordered, objects of enumeration type may be arguments to MIN and MAX, the ARRAY argument of MINVAL, MAXVAL, MINLOC, or MAXLOC, and the ARRAY and VALUE arguments to FINDLOC. ===END===