diff --git a/ada/ast.py b/ada/ast.py index bacb9759c..f5741f1c1 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -9180,11 +9180,15 @@ def index_type(dim=Int): @langkit_property() def xref_equation(): return Entity.types.logic_all( - lambda typ: typ.subtype_indication.sub_equation + lambda typ: + typ.subtype_name.xref_no_overloading + & If(typ.lower_bound.is_null, + LogicTrue(), + typ.lower_bound.sub_equation) ) is_static = Property(Entity.types.all( - lambda t: t.subtype_indication.is_static_subtype + lambda t: t.subtype_name.is_static_subtype )) @@ -23219,11 +23223,12 @@ class UnconstrainedArrayIndex(AdaNode): List of unconstrained array indexes. """ - subtype_indication = Field(type=SubtypeIndication) + subtype_name = Field(type=Name) + lower_bound = Field(type=Expr) @langkit_property(dynamic_vars=[origin]) def designated_type(): - return Entity.subtype_indication.designated_type + return Entity.subtype_name.name_designated_type class AbstractStateDecl(BasicDecl): diff --git a/ada/grammar.py b/ada/grammar.py index 2423f84e4..6a6d8e713 100644 --- a/ada/grammar.py +++ b/ada/grammar.py @@ -175,7 +175,7 @@ def end_named_block(): ), unconstrained_index=UnconstrainedArrayIndex( - A.subtype_indication, "range", "<>" + A.subtype_name, "range", Opt(A.simple_expr, ".."), "<>" ), array_type_def=ArrayTypeDef( @@ -1426,7 +1426,11 @@ def end_named_block(): ), discrete_range=Or( - BinOp(A.simple_expr, Op.alt_double_dot(".."), A.simple_expr), + BinOp( + A.simple_expr, + Op.alt_double_dot(".."), + Or(A.simple_expr, A.box_expr) + ), Predicate(A.name, T.Name.is_range_attribute) ), diff --git a/testsuite/tests/name_resolution/fixed_lower_bound/test.adb b/testsuite/tests/name_resolution/fixed_lower_bound/test.adb new file mode 100644 index 000000000..c3ad3595c --- /dev/null +++ b/testsuite/tests/name_resolution/fixed_lower_bound/test.adb @@ -0,0 +1,40 @@ +-- Check that the following experimental GNAT feature: +-- Fixed lower bounds for array types and subtypes +-- is correctly supported. + +-- https://github.com/AdaCore/ada-spark-rfcs/blob/master/prototyped/rfc-fixed-lower-bound.rst +pragma Extensions_Allowed (On); + +procedure Test is + type A is array (Integer range 1 .. <>) of Integer; + pragma Test_Block; + + type String_1 is array (Positive range 1 .. <>) of Character; + pragma Test_Block; + + subtype Fixed_String is String (1 .. <>); + pragma Test_Statement; + + subtype Fixed_String_2 is String (Integer range 1 .. <>); + pragma Test_Statement; + + type Int_Matrix_1 is array (Positive range 1 .. <>, + Positive range <>) of Integer; + pragma Test_Block; + type Int_Matrix_2 is array (Positive range <>, + Positive range 1 .. <>) of Integer; + pragma Test_Block; + type Int_Matrix_3 is array (Positive range 1 .. <>, + Positive range 1 .. <>) of Integer; + pragma Test_Block; + + type Matrix is array (Positive range <>, Positive range <>) of Integer; + pragma Test_Block; + + subtype SMatrix is Matrix (2 .. <>, 2 .. <>); + pragma Test_Statement; + subtype SMatrix2 is Matrix (Integer range 2 .. <>, Integer range 2 .. <>); + pragma Test_Statement; +begin + null; +end Test; diff --git a/testsuite/tests/name_resolution/fixed_lower_bound/test.out b/testsuite/tests/name_resolution/fixed_lower_bound/test.out new file mode 100644 index 000000000..0c02ad7f1 --- /dev/null +++ b/testsuite/tests/name_resolution/fixed_lower_bound/test.out @@ -0,0 +1,245 @@ +Analyzing test.adb +################## + +Resolving xrefs for node +********************************************************** + +Expr: + references: + type: None + expected type: None +Expr: + references: None + type: + expected type: None +Expr: + references: + type: None + expected type: None + +Resolving xrefs for node +************************************************************ + +Expr: + references: + type: None + expected type: None +Expr: + references: None + type: + expected type: None +Expr: + references: + type: None + expected type: None + +Resolving xrefs for node +*************************************************************************** + +Expr: + references: + type: None + expected type: None +Expr: + type: + expected type: +Expr: + references: None + type: + expected type: +Expr: + references: None + type: None + expected type: None +Expr: + type: + expected type: + +Resolving xrefs for node +***************************************************************************** + +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + type: + expected type: +Expr: + references: None + type: + expected type: +Expr: + references: None + type: None + expected type: None +Expr: + type: + expected type: + +Resolving xrefs for node +************************************************************ + +Expr: + references: + type: None + expected type: None +Expr: + references: None + type: + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None + +Resolving xrefs for node +************************************************************ + +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: None + type: + expected type: None +Expr: + references: + type: None + expected type: None + +Resolving xrefs for node +************************************************************ + +Expr: + references: + type: None + expected type: None +Expr: + references: None + type: + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: None + type: + expected type: None +Expr: + references: + type: None + expected type: None + +Resolving xrefs for node +************************************************************ + +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None + +Resolving xrefs for node +********************************************************************** + +Expr: + references: + type: None + expected type: None +Expr: + type: + expected type: +Expr: + references: None + type: + expected type: +Expr: + references: None + type: None + expected type: None +Expr: + type: + expected type: +Expr: + type: + expected type: +Expr: + references: None + type: + expected type: +Expr: + references: None + type: None + expected type: None +Expr: + type: + expected type: + +Resolving xrefs for node +*********************************************************************** + +Expr: + references: + type: None + expected type: None +Expr: + references: + type: None + expected type: None +Expr: + type: + expected type: +Expr: + references: None + type: + expected type: +Expr: + references: None + type: None + expected type: None +Expr: + type: + expected type: +Expr: + references: + type: None + expected type: None +Expr: + type: + expected type: +Expr: + references: None + type: + expected type: +Expr: + references: None + type: None + expected type: None +Expr: + type: + expected type: + + +Done. diff --git a/testsuite/tests/name_resolution/fixed_lower_bound/test.yaml b/testsuite/tests/name_resolution/fixed_lower_bound/test.yaml new file mode 100644 index 000000000..173e325ff --- /dev/null +++ b/testsuite/tests/name_resolution/fixed_lower_bound/test.yaml @@ -0,0 +1,2 @@ +driver: name-resolution +input_sources: [test.adb] diff --git a/testsuite/tests/parser/full_type_decl_16/test.out b/testsuite/tests/parser/full_type_decl_16/test.out index c125e78de..a3f4f935b 100644 --- a/testsuite/tests/parser/full_type_decl_16/test.out +++ b/testsuite/tests/parser/full_type_decl_16/test.out @@ -11,13 +11,9 @@ ConcreteTypeDecl[1:1-1:49] | | |f_types: | | | UnconstrainedArrayIndexList[1:20-1:36] | | | | UnconstrainedArrayIndex[1:20-1:36] -| | | | |f_subtype_indication: -| | | | | SubtypeIndication[1:20-1:27] -| | | | | |f_has_not_null: -| | | | | | NotNullAbsent[1:20-1:20] -| | | | | |f_name: -| | | | | | Id[1:20-1:27]: Integer -| | | | | |f_constraint: +| | | | |f_subtype_name: +| | | | | Id[1:20-1:27]: Integer +| | | | |f_lower_bound: | |f_component_type: | | ComponentDef[1:41-1:48] | | |f_has_aliased: diff --git a/user_manual/changes/libadalang/1034.yaml b/user_manual/changes/libadalang/1034.yaml new file mode 100644 index 000000000..8b4bb150f --- /dev/null +++ b/user_manual/changes/libadalang/1034.yaml @@ -0,0 +1,6 @@ +type: new-feature +title: Fixed lower bounds for array types and subtypes +description: | + This change adds support for the GNAT experimental feature allowing fixed + lower bounds for array types and subtypes. +date: 2023-11-07