Skip to content

Commit

Permalink
Merge branch 'topic/1424' into 'master'
Browse files Browse the repository at this point in the history
Various fixes for DeepBlue codebase name resolution

Closes #1424

See merge request eng/libadalang/libadalang!1719
  • Loading branch information
thvnx committed Aug 2, 2024
2 parents 320e3c3 + e7ad519 commit 6983f44
Show file tree
Hide file tree
Showing 17 changed files with 440 additions and 60 deletions.
44 changes: 39 additions & 5 deletions ada/nodes.lkt
Original file line number Diff line number Diff line change
Expand Up @@ -5590,7 +5590,7 @@ class BaseTypeDecl: BasicDecl {
# is defined by the `Cursor` type declaration.
self.children_env().get_first(s"Cursor").as![BaseTypeDecl]
# Check out cursor type for types with `Iterable` aspect
or? self.as[TypeDecl].iterable_cursor_type()
or? self.iterable_cursor_type()

fun is_not_root_int_type(): Bool =
not node.is_null and self != node.root_int_type()
Expand Down Expand Up @@ -6446,6 +6446,10 @@ class BaseTypeDecl: BasicDecl {
fun iterable_comp_type(): Entity[BaseTypeDecl] =
null[Entity[BaseTypeDecl]]

@with_dynvars(origin)
fun iterable_cursor_type(): Entity[BaseTypeDecl] =
null[Entity[BaseTypeDecl]]

|" Return the canonical type declaration for this type declaration. For
|" subtypes, it will return the base type declaration.
@exported
Expand Down Expand Up @@ -6566,6 +6570,10 @@ class BaseSubtypeDecl: BaseTypeDecl {
fun iterable_comp_type(): Entity[BaseTypeDecl] =
self.get_type().iterable_comp_type()

@with_dynvars(origin)
fun iterable_cursor_type(): Entity[BaseTypeDecl] =
self.get_type().iterable_cursor_type()

@with_dynvars(origin=null[AdaNode])
fun is_record_type(): Bool = self.get_type().is_record_type()

Expand Down Expand Up @@ -6613,6 +6621,9 @@ class SubtypeDecl: BaseSubtypeDecl {
case t => t
}

fun get_imp_deref(): Entity[Expr] =
self.get_type().get_imp_deref()

fun discrete_range(): DiscreteRange = self.subtype.discrete_range()

@with_dynvars(env, origin, entry_point)
Expand Down Expand Up @@ -12749,8 +12760,13 @@ class AttributeRef: Name {

@with_dynvars(env, origin, no_visibility=false)
fun designated_env(): LexicalEnv =
if self.is_access_attr() or self.attribute.name_is(s"Old") then self.prefix.designated_env()
elif self.attribute.name_is(s"Result") then node.parents().find((p) => p is BasicSubpDecl | SubpBody).as_entity.as[BasicDecl].subp_spec_or_null().return_type().defining_env()
if self.is_access_attr() or self.attribute.name_is(s"Old") then
self.prefix.designated_env()
elif self.attribute.name_is(s"Result") then
node.parents().find(
(p) => p is BasicSubpDecl | BaseSubpBody
).as_entity.as[BasicDecl].subp_spec_or_null().return_type()
.defining_env()
else null[LexicalEnv]

|" Return the subprogram declaration referred by this attribute name,
Expand All @@ -12767,15 +12783,19 @@ class AttributeRef: Name {
# Attributes that simply return subprograms
elif rel_name in s"Succ" | s"Pred" | s"Min" | s"Max" | s"Ceiling" | s"Floor" | s"Rounding" | s"Unbiased_Rounding" | s"Leading_Part" | s"Truncation" | s"Exponent" | s"Fraction" | s"Copy_Sign" | s"Remainder" | s"Adjacent" | s"Machine" | s"Machine_Rounding" | s"Scaling" | s"Compose" | s"Mod" | s"Value" | s"Wide_Value" | s"Wide_Wide_Value" | s"Fixed_Value" | s"Integer_Value" | s"Pos" | s"Val" | s"Enum_Val" | s"Write" | s"Read" | s"Output" | s"Input" | s"Put_Image" | s"Asm_Input" | s"Asm_Output" | s"Model" | s"Round" then self.attribute_subprogram_equation()
elif rel_name in s"Size" | s"VADS_Size" then self.size_equation()
elif rel_name in s"Max_Size_In_Storage_Elements" | s"Aft" | s"Object_Size" | s"Value_Size" | s"Storage_Size" then self.subtype_attr_equation()
elif rel_name in s"Max_Size_In_Storage_Elements" | s"Max_Alignment_For_Allocation"
| s"Aft" | s"Object_Size" | s"Value_Size" | s"Storage_Size"
| s"Scale"
then self.subtype_attr_equation()
elif rel_name in s"Access" | s"Unchecked_Access" | s"Unrestricted_Access" then self.access_equation()
elif rel_name == s"Image" then self.image_equation(node.std_string_type())
elif rel_name == s"Wide_Image" then self.image_equation(node.std_wide_string_type())
elif rel_name == s"Wide_Wide_Image" then self.image_equation(node.std_wide_wide_string_type())
elif rel_name == s"Enum_Rep" then self.enum_rep_equation()
elif rel_name in s"Invalid_Value" | s"First_Valid" | s"Last_Valid" then self.self_type_equation()
elif rel_name == s"Identity" then self.identity_equation()
elif rel_name == s"Address" then self.address_equation()
elif rel_name in s"Address" | s"Code_Address" then
self.address_equation()
elif rel_name in s"Small" | s"Model_Small" | s"Safe_Small" | s"Epsilon" | s"Model_Epsilon" | s"Large" | s"Safe_Large" | s"Delta" | s"Safe_First" | s"Safe_Last" then self.universal_real_equation()
elif rel_name == s"Img" then self.img_equation(node.std_string_type())
elif rel_name == s"Tag" then self.tag_attr_equation()
Expand Down Expand Up @@ -12818,6 +12838,7 @@ class AttributeRef: Name {
elif rel_name == s"Abort_Signal" then %eq(node.ref_var(), node.std_entity(s"abort_signal_")) and %eq(node.type_var(), null[Entity[BaseTypeDecl]])
elif rel_name in s"Has_Same_Storage" | s"Overlaps_Storage" then self.storage_equation()
elif rel_name == s"Deref" then self.deref_equation()
elif rel_name == s"Mechanism_Code" then self.mechanism_code_equation()
else raise[Equation] PropertyError("Unhandled attribute")
}

Expand Down Expand Up @@ -13096,6 +13117,18 @@ class AttributeRef: Name {
default_val=%false
)

|" Return the xref equation for the ``Mechanism_Code`` attribute.
@with_dynvars(env, origin, entry_point)
fun mechanism_code_equation(): Equation =
self.prefix.xref_no_overloading()
and self.universal_int_bind(node.type_var())
and self.args?[0].do(
(arg) => arg.expr().sub_equation()
and self.universal_int_bind(arg.expr().expected_type_var())
and arg.expr().matches_expected_type(),
default_val=%true
)

|" Return the xref equation for the ``Has_Same_Storage`` and
|" ``Overlaps_Storage`` attributes.
@with_dynvars(env, origin, entry_point)
Expand Down Expand Up @@ -15108,6 +15141,7 @@ class Identifier: BaseId implements TokenNode {
fun is_attr_with_args(): Bool =
node.symbol in s"First" | s"Last" | s"Range" | s"Length"
| s"Has_Same_Storage" | s"Overlaps_Storage" | s"Deref"
| s"Mechanism_Code"

@with_dynvars(origin)
fun complete_items(): Array[CompletionItem] = self.parent.complete_items()
Expand Down
5 changes: 4 additions & 1 deletion testsuite/tests/name_resolution/address_clause/subp.adb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ procedure Subp is
for C'Address use X.A;
pragma Test_Statement;
begin
null;
if C'Code_Address /= C'Address then
raise;
end if;
pragma Test_Statement;
end;
end P;
begin
Expand Down
35 changes: 35 additions & 0 deletions testsuite/tests/name_resolution/address_clause/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,40 @@ Expr: <Id "A" subp.adb:16:30-16:31>
type: <ConcreteTypeDecl ["Address"] system.ads:67:4-67:28>
expected type: <ConcreteTypeDecl ["Address"] system.ads:67:4-67:28>

Resolving xrefs for node <IfStmt subp.adb:19:10-21:17>
******************************************************

Expr: <RelationOp subp.adb:19:13-19:40>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
Expr: <AttributeRef subp.adb:19:13-19:27>
references: None
type: <ConcreteTypeDecl ["Address"] system.ads:67:4-67:28>
expected type: <ConcreteTypeDecl ["Address"] system.ads:67:4-67:28>
Expr: <Id "C" subp.adb:19:13-19:14>
references: <DefiningName "C" subp.adb:13:20-13:21>
type: None
expected type: None
Expr: <Id "Code_Address" subp.adb:19:15-19:27>
references: None
type: None
expected type: None
Expr: <OpNeq "/=" subp.adb:19:28-19:30>
references: None
type: None
expected type: None
Expr: <AttributeRef subp.adb:19:31-19:40>
references: None
type: <ConcreteTypeDecl ["Address"] system.ads:67:4-67:28>
expected type: <ConcreteTypeDecl ["Address"] system.ads:67:4-67:28>
Expr: <Id "C" subp.adb:19:31-19:32>
references: <DefiningName "C" subp.adb:13:20-13:21>
type: None
expected type: None
Expr: <Id "Address" subp.adb:19:33-19:40>
references: None
type: None
expected type: None


Done.
19 changes: 19 additions & 0 deletions testsuite/tests/name_resolution/implicit_deref_4/test.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
procedure Test is
type Database is tagged null record;

type Connection (D : access Database) is tagged null record
with Implicit_Dereference => D;

subtype Sub_Connection is Connection;

function Get (DB : Database'Class) return Boolean is (True);

procedure P (DB : Sub_Connection) is
B : Boolean := Get (DB);
pragma Test_Statement;
begin
null;
end P;
begin
null;
end;
25 changes: 25 additions & 0 deletions testsuite/tests/name_resolution/implicit_deref_4/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Analyzing test.adb
##################

Resolving xrefs for node <ObjectDecl ["B"] test.adb:12:7-12:31>
***************************************************************

Expr: <Id "Boolean" test.adb:12:11-12:18>
references: <DefiningName "Boolean" __standard:3:8-3:15>
type: None
expected type: None
Expr: <CallExpr test.adb:12:22-12:30>
references: <DefiningName "Get" test.adb:9:13-9:16>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
Expr: <Id "Get" test.adb:12:22-12:25>
references: <DefiningName "Get" test.adb:9:13-9:16>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: None
Expr: <Id "DB" test.adb:12:27-12:29>
references: <DefiningName "DB" test.adb:11:17-11:19>
type: <SubtypeDecl ["Sub_Connection"] test.adb:7:4-7:41>
expected type: <ClasswideTypeDecl ["Database"] test.adb:2:4-2:40>


Done.
2 changes: 2 additions & 0 deletions testsuite/tests/name_resolution/implicit_deref_4/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
driver: name-resolution
input_sources: [test.adb]
9 changes: 9 additions & 0 deletions testsuite/tests/name_resolution/iterable_aspect/test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ procedure Test is

procedure My_Put_Line (S : String) is null;

subtype Sub_List is List;

My_Sub_List : Sub_List := (S => "Subwou");

begin

for E of My_List loop
Expand All @@ -77,4 +81,9 @@ begin
end loop;
pragma Test_Block;

for E in My_Sub_List loop
My_Put_Line (Get_Element (My_Sub_List, E)'Image);
end loop;
pragma Test_Block;

end Test;
Loading

0 comments on commit 6983f44

Please sign in to comment.