[Ada] Implementation of Inox feature of fixed lower bounds on array types/subtypes
authorGary Dismukes <dismukes@adacore.com>
Fri, 5 Mar 2021 07:20:09 +0000 (02:20 -0500)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 17 Jun 2021 14:32:16 +0000 (10:32 -0400)
commitd32db3a763249a8b94c2e2e285fc6f400eadea4e
tree834f149ad26966000533a1dcefd502b5c07fa11e
parent4892e31daceb8ab230768a15eb0a01b814e8bbfd
[Ada] Implementation of Inox feature of fixed lower bounds on array types/subtypes

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.
13 files changed:
gcc/ada/checks.adb
gcc/ada/einfo.ads
gcc/ada/exp_ch4.adb
gcc/ada/exp_ch6.adb
gcc/ada/exp_util.adb
gcc/ada/exp_util.ads
gcc/ada/gen_il-fields.ads
gcc/ada/gen_il-gen-gen_entities.adb
gcc/ada/par-ch3.adb
gcc/ada/sem_ch3.adb
gcc/ada/sem_res.adb
gcc/ada/sem_util.adb
gcc/ada/sprint.adb