This is a prototype implementation of the feature for defining array
types and subtypes with fixed lower bounds for index ranges as proposed
as part of the "Inox" language design effort. This feature is currently
supported under control of the -gnatX (language extensions) switch, and
allows unconstrained array types as well as unconstrained subtypes to be
declared with indexes that use the special syntax "expression .. <>", to
indicate that the lower bound of the array type or subtype is fixed at a
value given by an expression. In contexts such as actual parameters,
object declarations, return statements, and type conversions, if the
context is such an unconstrained array subtype with a fixed lower bound,
bounds sliding is performed. Also, in certain contexts, such as index
constraints, consistency of the range imposed by the constraint with the
fixed lower bound of the array type being constrained is enforced.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

        * checks.adb (Discrete_Range_Cond): For an index subtype that
        has a fixed lower bound, require that the range's lower bound
        match that of the subtype.
        (Selected_Range_Checks): Warn about the case where a static
        lower bound does not equal an index subtype's fixed lower bound.
        * einfo.ads (Is_Fixed_Lower_Bound_Array_Subtype,
        Is_Fixed_Lower_Bound_Index_Subtype): Document new entity flag.
        * exp_ch4.adb (Expand_N_Type_Conversion): If the operand is of
        an unconstrained array subtype with fixed lower bound, then
        Expand_Sliding_Conversion is applied to the operand.
        * exp_ch6.adb (Expand_Simple_Function_Return): If the result
        subtype is an unconstrained array subtype with fixed lower
        bound, then Expand_Sliding_Conversion is applied to the return
        object.
        * exp_util.ads (Expand_Sliding_Conversion): New procedure for
        applying a sliding subtype conversion to an array object of a
        fixed-lower-bound subtype when needed.
        * exp_util.adb: Add with_clause for Freeze.
        (Expand_Sliding_Conversion): New procedure for applying a
        sliding subtype conversion to an array object of a
        fixed-lower-bound subtype when needed.  It traverses the indexes
        of the unconstrained array type/subtype to create a target
        constrained subtype and rewrites the array object to be a
        conversion to that subtype, when there's at least one index
        whose lower bound does not statically match the fixed-lower
        bound of the target subtype.
        * gen_il-fields.ads (type Opt_Field_Enum): Add literals
        Is_Fixed_Lower_Bound_Array_Subtype and
        Is_Fixed_Lower_Bound_Index_Subtype for new flags on type
        entities.
        * gen_il-gen-gen_entities.adb: Add calls to
        Create_Semantic_Field for the new fixed-lower-bound flags on
        type entities.
        * par-ch3.adb (P_Array_Type_Definition): Add handling for
        parsing of fixed-lower-bound index ranges in unconstrained array
        types. Report an error if such an index is encountered and GNAT
        language extensions are not enabled.
        (P_Index_Subtype_Def_With_Fixed_Lower_Bound): Support procedure
        for parsing unconstrained index ranges.
        (P_Index_Or_Discriminant_Constraint): Add handling for parsing
        of index constraints that specify ranges with fixed lower
        bounds. Report an error if such an index is encountered and GNAT
        language extensions are not enabled.
        * sem_ch3.adb (Analyze_Object_Declaration): If the object's
        nominal subtype is an array subtype with fixed lower bound, then
        Expand_Sliding_Conversion is applied to the object.
        (Array_Type_Declaration): Mark the array type and the subtypes
        of any indexes that specify a fixed lower bound as being
        fixed-lower-bound subtypes, and set the High_bound of the range
        of such an index to the upper bound of the named subtype.
        (Constrain_Array): For an array subtype with one or more index
        ranges specifying a fixed lower bound, set Is_Constrained to
        False and set the array subtype's
        Is_Fixed_Lower_Bound_Array_Subtype flag to True.
        (Constrain_Index): Mark the subtypes of an index that specifies
        a fixed lower bound as being a fixed-lower-bound index subtype,
        and set the High_bound of the range of such an index to the
        upper bound of the base type of the array type's corresponding
        index.
        * sem_res.adb (Resolve_Actuals): If a formal is of an
        unconstrained array subtype with fixed lower bound, then
        Expand_Sliding_Conversion is applied to the actual.
        * sem_util.adb (Build_Actual_Subtype): If the actual subtype
        corresponds to an unconstrained array subtype having any indexes
        with fixed lower bounds, then set the lower bounds of any such
        indexes of the actual subtype to the appropriate fixed lower
        bound of the formal subtype (rather than taking it from the
        formal itself).
        * sprint.adb (Sprint_Node_Actual, case N_Range): If a range's
        Etype has a fixed lower bound, then print "<>" rather than the
        High_Bound of the range.

Attachment: patch.diff.gz
Description: application/gzip

Reply via email to