Skip to content

Commit

Permalink
Merge branch 'topic/1404' into 'master'
Browse files Browse the repository at this point in the history
Add user-defined indexing support for ClasswideTypeDecl

See merge request eng/libadalang/libadalang!1701
  • Loading branch information
thvnx committed Jul 17, 2024
2 parents 4f2a579 + 8afa234 commit 36479e5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ada/nodes.lkt
Original file line number Diff line number Diff line change
Expand Up @@ -6571,6 +6571,14 @@ class ClasswideTypeDecl: BaseTypeDecl {
@with_dynvars(origin)
fun is_iterable_type(): Bool = self.type_decl().is_iterable_type()

fun has_ud_indexing(): Bool = self.type_decl.has_ud_indexing

fun constant_indexing_fns(): Array[Entity[BasicDecl]] =
self.type_decl.constant_indexing_fns

fun variable_indexing_fns(): Array[Entity[BasicDecl]] =
self.type_decl.variable_indexing_fns

fun is_task_type(): Bool = self.type_decl().is_task_type()

@with_dynvars(origin)
Expand Down
35 changes: 35 additions & 0 deletions testsuite/tests/name_resolution/ud_indexing_7/test.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
procedure Test is
package String_Vector is
type Virtual_String_Vector is tagged private with
Constant_Indexing => Element;

function Element
(Self : Virtual_String_Vector'Class;
Index : Positive) return Character;
private
type Virtual_String_Vector is tagged record
Data : Character;
end record;
end String_Vector;

package body String_Vector is
function Element
(Self : Virtual_String_Vector'Class;
Index : Positive) return Character is
begin
return 'x';
end;
end String_Vector;

use String_Vector;


procedure P (X : Virtual_String_Vector'Class) is
C : Character;
begin
C := X (1);
pragma Test_Statement;
end P;
begin
null;
end;
25 changes: 25 additions & 0 deletions testsuite/tests/name_resolution/ud_indexing_7/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Analyzing test.adb
##################

Resolving xrefs for node <AssignStmt test.adb:30:7-30:18>
*********************************************************

Expr: <Id "C" test.adb:30:7-30:8>
references: <DefiningName "C" test.adb:28:7-28:8>
type: <ConcreteTypeDecl ["Character"] __standard:21:3-21:27>
expected type: None
Expr: <CallExpr test.adb:30:12-30:17>
references: <DefiningName "X" test.adb:27:17-27:18>
type: <ConcreteTypeDecl ["Character"] __standard:21:3-21:27>
expected type: <ConcreteTypeDecl ["Character"] __standard:21:3-21:27>
Expr: <Id "X" test.adb:30:12-30:13>
references: <DefiningName "X" test.adb:27:17-27:18>
type: <ClasswideTypeDecl ["Virtual_String_Vector"] test.adb:3:7-4:39>
expected type: None
Expr: <Int test.adb:30:15-30:16>
references: None
type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
expected type: <SubtypeDecl ["Positive"] __standard:6:3-6:57>


Done.
2 changes: 2 additions & 0 deletions testsuite/tests/name_resolution/ud_indexing_7/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
driver: name-resolution
input_sources: [test.adb]

0 comments on commit 36479e5

Please sign in to comment.