Skip to content

Commit

Permalink
Merge branch 'topic/fix_dot_notation' into 'master'
Browse files Browse the repository at this point in the history
Add support for calls with prefixed-view notation on access, array and scalar types.

Closes eng/ide/ada_language_server#1274

See merge request eng/libadalang/libadalang!1502
  • Loading branch information
Roldak committed Jan 9, 2024
2 parents 109c243 + ac15612 commit 81e3331
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 6 deletions.
18 changes: 13 additions & 5 deletions ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -5052,15 +5052,23 @@ def defining_env():
Entity.base_types.map(lambda bt: bt._.defining_env)
)).concat(Entity.previous_part_env.singleton).env_group(),

Entity.match(
lambda ar=T.ArrayTypeDef: ar.comp_type.defining_env,
Self.is_a(T.ArrayTypeDef),
Array([
Entity.cast(T.ArrayTypeDef).comp_type.defining_env,
Entity.dottable_subps_env
]).env_group(),

Self.is_a(T.AccessDef),
Array([
# An access to procedure will have a null accessed_type, hence
# the use of the underscore.
lambda ac=T.AccessDef: ac.accessed_type._.defining_env,
Entity.cast(T.AccessDef).accessed_type._.defining_env,
Entity.dottable_subps_env
]).env_group(),

lambda _: EmptyEnv
)
# In any case, include the type's `dottable_subps_env` so as to
# fully support the universal dot notation feature.
Entity.dottable_subps_env
)

containing_type = Property(
Expand Down
124 changes: 124 additions & 0 deletions testsuite/tests/name_resolution/prefixed_untagged/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,128 @@ Expr: <Id "P" test.adb:28:12-28:13>
expected type: None


Analyzing test_access.adb
#########################

Resolving xrefs for node <CallStmt test_access.adb:13:4-13:10>
**************************************************************

Expr: <DottedName test_access.adb:13:4-13:9>
references: <DefiningName "Foo" test_access.adb:6:17-6:20>
type: None
expected type: None
Expr: <Id "X" test_access.adb:13:4-13:5>
references: <DefiningName "X" test_access.adb:11:4-11:5>
type: <ConcreteTypeDecl ["T_Access"] test_access.adb:4:7-4:37>
expected type: <ConcreteTypeDecl ["T_Access"] test_access.adb:4:7-4:37>
Expr: <Id "Foo" test_access.adb:13:6-13:9>
references: <DefiningName "Foo" test_access.adb:6:17-6:20>
type: None
expected type: None


Analyzing test_array.adb
########################

Resolving xrefs for node <CallStmt test_array.adb:13:4-13:10>
*************************************************************

Expr: <DottedName test_array.adb:13:4-13:9>
references: <DefiningName "Foo" test_array.adb:6:17-6:20>
type: None
expected type: None
Expr: <Id "X" test_array.adb:13:4-13:5>
references: <DefiningName "X" test_array.adb:11:4-11:5>
type: <ConcreteTypeDecl ["T_Array"] test_array.adb:4:7-4:54>
expected type: <ConcreteTypeDecl ["T_Array"] test_array.adb:4:7-4:54>
Expr: <Id "Foo" test_array.adb:13:6-13:9>
references: <DefiningName "Foo" test_array.adb:6:17-6:20>
type: None
expected type: None


Analyzing test_scalar.adb
#########################

Resolving xrefs for node <CallStmt test_scalar.adb:24:4-24:12>
**************************************************************

Expr: <DottedName test_scalar.adb:24:4-24:11>
references: <DefiningName "Foo" test_scalar.adb:9:17-9:20>
type: None
expected type: None
Expr: <Id "X_1" test_scalar.adb:24:4-24:7>
references: <DefiningName "X_1" test_scalar.adb:18:4-18:7>
type: <ConcreteTypeDecl ["Enum_T"] test_scalar.adb:3:7-3:32>
expected type: <ConcreteTypeDecl ["Enum_T"] test_scalar.adb:3:7-3:32>
Expr: <Id "Foo" test_scalar.adb:24:8-24:11>
references: <DefiningName "Foo" test_scalar.adb:9:17-9:20>
type: None
expected type: None

Resolving xrefs for node <CallStmt test_scalar.adb:26:4-26:12>
**************************************************************

Expr: <DottedName test_scalar.adb:26:4-26:11>
references: <DefiningName "Foo" test_scalar.adb:10:17-10:20>
type: None
expected type: None
Expr: <Id "X_2" test_scalar.adb:26:4-26:7>
references: <DefiningName "X_2" test_scalar.adb:19:4-19:7>
type: <ConcreteTypeDecl ["Int_T"] test_scalar.adb:4:7-4:35>
expected type: <ConcreteTypeDecl ["Int_T"] test_scalar.adb:4:7-4:35>
Expr: <Id "Foo" test_scalar.adb:26:8-26:11>
references: <DefiningName "Foo" test_scalar.adb:10:17-10:20>
type: None
expected type: None

Resolving xrefs for node <CallStmt test_scalar.adb:28:4-28:12>
**************************************************************

Expr: <DottedName test_scalar.adb:28:4-28:11>
references: <DefiningName "Foo" test_scalar.adb:11:17-11:20>
type: None
expected type: None
Expr: <Id "X_3" test_scalar.adb:28:4-28:7>
references: <DefiningName "X_3" test_scalar.adb:20:4-20:7>
type: <ConcreteTypeDecl ["Mod_T"] test_scalar.adb:5:7-5:27>
expected type: <ConcreteTypeDecl ["Mod_T"] test_scalar.adb:5:7-5:27>
Expr: <Id "Foo" test_scalar.adb:28:8-28:11>
references: <DefiningName "Foo" test_scalar.adb:11:17-11:20>
type: None
expected type: None

Resolving xrefs for node <CallStmt test_scalar.adb:30:4-30:12>
**************************************************************

Expr: <DottedName test_scalar.adb:30:4-30:11>
references: <DefiningName "Foo" test_scalar.adb:12:17-12:20>
type: None
expected type: None
Expr: <Id "X_4" test_scalar.adb:30:4-30:7>
references: <DefiningName "X_4" test_scalar.adb:21:4-21:7>
type: <ConcreteTypeDecl ["Fixed_T"] test_scalar.adb:6:7-6:51>
expected type: <ConcreteTypeDecl ["Fixed_T"] test_scalar.adb:6:7-6:51>
Expr: <Id "Foo" test_scalar.adb:30:8-30:11>
references: <DefiningName "Foo" test_scalar.adb:12:17-12:20>
type: None
expected type: None

Resolving xrefs for node <CallStmt test_scalar.adb:32:4-32:12>
**************************************************************

Expr: <DottedName test_scalar.adb:32:4-32:11>
references: <DefiningName "Foo" test_scalar.adb:13:17-13:20>
type: None
expected type: None
Expr: <Id "X_5" test_scalar.adb:32:4-32:7>
references: <DefiningName "X_5" test_scalar.adb:22:4-22:7>
type: <ConcreteTypeDecl ["Float_T"] test_scalar.adb:7:7-7:32>
expected type: <ConcreteTypeDecl ["Float_T"] test_scalar.adb:7:7-7:32>
Expr: <Id "Foo" test_scalar.adb:32:8-32:11>
references: <DefiningName "Foo" test_scalar.adb:13:17-13:20>
type: None
expected type: None


Done.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
driver: name-resolution
input_sources: [test.adb]
input_sources: [test.adb, test_access.adb, test_array.adb, test_scalar.adb]
15 changes: 15 additions & 0 deletions testsuite/tests/name_resolution/prefixed_untagged/test_access.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
procedure Test_Access is
package Pkg is
type T is null record;
type T_Access is access all T;

procedure Foo (Self : T_Access) is null;
end Pkg;

use Pkg;

X : T_Access;
begin
X.Foo;
pragma Test_Statement;
end Test_Access;
16 changes: 16 additions & 0 deletions testsuite/tests/name_resolution/prefixed_untagged/test_array.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
procedure Test_Array is
package Pkg is
type T is null record;
type T_Array is array (Positive range <>) of T;

procedure Foo (Self : T_Array) is null;
end Pkg;

use Pkg;

X : T_Array (1 .. 10);
begin
X.Foo;
pragma Test_Statement;
end Test_Array;

35 changes: 35 additions & 0 deletions testsuite/tests/name_resolution/prefixed_untagged/test_scalar.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
procedure Test_Scalar is
package Pkg is
type Enum_T is (A, B, C);
type Int_T is range 1 .. 10;
type Mod_T is mod 3;
type Fixed_T is delta 0.1 range 0.0 .. 10.0;
type Float_T is digits 8;

procedure Foo (Self : Enum_T) is null;
procedure Foo (Self : Int_T) is null;
procedure Foo (Self : Mod_T) is null;
procedure Foo (Self : Fixed_T) is null;
procedure Foo (Self : Float_T) is null;
end Pkg;

use Pkg;

X_1 : Enum_T;
X_2 : Int_T;
X_3 : Mod_T;
X_4 : Fixed_T;
X_5 : Float_T;
begin
X_1.Foo;
pragma Test_Statement;
X_2.Foo;
pragma Test_Statement;
X_3.Foo;
pragma Test_Statement;
X_4.Foo;
pragma Test_Statement;
X_5.Foo;
pragma Test_Statement;
end Test_Scalar;

0 comments on commit 81e3331

Please sign in to comment.