Skip to content

Commit

Permalink
Add support for Deref attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
thvnx committed Jul 15, 2024
1 parent 065dba8 commit 732d5f4
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ada/nodes.lkt
Original file line number Diff line number Diff line change
Expand Up @@ -12676,6 +12676,7 @@ class AttributeRef: Name {
elif rel_name == s"Index" then self.index_equation()
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()
else raise[Equation] PropertyError("Unhandled attribute")
}

Expand Down Expand Up @@ -12942,6 +12943,18 @@ class AttributeRef: Name {
self.prefix.sub_equation() and %eq(node.type_var(), typ)
}

|" Return the xref equation for the ``Deref`` attribute.
@with_dynvars(env, origin, entry_point)
fun deref_equation(): Equation =
self.prefix.xref_type_equation
and %eq(node.type_var, node.prefix.ref_var)
and self.args?[0].do(
(arg) => arg.expr.sub_equation
and %eq(arg.expr.expected_type_var, node.system_address_type)
and arg.expr.matches_expected_type,
default_val=%false
)

|" Return the xref equation for the ``Has_Same_Storage`` and
|" ``Overlaps_Storage`` attributes.
@with_dynvars(env, origin, entry_point)
Expand Down Expand Up @@ -14862,7 +14875,8 @@ class Identifier: BaseId implements TokenNode {
# For other args, we deactivate this parsing, so that they're correctly
# parsed as ``CallExpr (AttrRef (pfx, attr), args)``.
fun is_attr_with_args(): Bool =
node.symbol in s"First" | s"Last" | s"Range" | s"Length" | s"Has_Same_Storage" | s"Overlaps_Storage"
node.symbol in s"First" | s"Last" | s"Range" | s"Length"
| s"Has_Same_Storage" | s"Overlaps_Storage" | s"Deref"

@with_dynvars(origin)
fun complete_items(): Array[CompletionItem] = self.parent.complete_items()
Expand Down
11 changes: 11 additions & 0 deletions testsuite/tests/name_resolution/deref_attribute/test.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
with System;

procedure Test (A : System.Address) is
I : Integer := Integer'Deref(A);
pragma Test_Statement;

B : Boolean := Integer'Deref(A) = 2;
pragma Test_Statement;
begin
null;
end;
64 changes: 64 additions & 0 deletions testsuite/tests/name_resolution/deref_attribute/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Analyzing test.adb
##################

Resolving xrefs for node <ObjectDecl ["I"] test.adb:4:4-4:36>
*************************************************************

Expr: <Id "Integer" test.adb:4:8-4:15>
references: <DefiningName "Integer" __standard:4:8-4:15>
type: None
expected type: None
Expr: <AttributeRef test.adb:4:19-4:35>
references: None
type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
expected type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
Expr: <Id "Integer" test.adb:4:19-4:26>
references: <DefiningName "Integer" __standard:4:8-4:15>
type: None
expected type: None
Expr: <Id "Deref" test.adb:4:27-4:32>
references: None
type: None
expected type: None
Expr: <Id "A" test.adb:4:33-4:34>
references: <DefiningName "A" test.adb:3:17-3:18>
type: <ConcreteTypeDecl ["Address"] system.ads:67:4-67:28>
expected type: <ConcreteTypeDecl ["Address"] system.ads:67:4-67:28>

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

Expr: <Id "Boolean" test.adb:7:8-7:15>
references: <DefiningName "Boolean" __standard:3:8-3:15>
type: None
expected type: None
Expr: <RelationOp test.adb:7:19-7:39>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
Expr: <AttributeRef test.adb:7:19-7:35>
references: None
type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
expected type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>
Expr: <Id "Integer" test.adb:7:19-7:26>
references: <DefiningName "Integer" __standard:4:8-4:15>
type: None
expected type: None
Expr: <Id "Deref" test.adb:7:27-7:32>
references: None
type: None
expected type: None
Expr: <Id "A" test.adb:7:33-7:34>
references: <DefiningName "A" test.adb:3:17-3:18>
type: <ConcreteTypeDecl ["Address"] system.ads:67:4-67:28>
expected type: <ConcreteTypeDecl ["Address"] system.ads:67:4-67:28>
Expr: <OpEq "=" test.adb:7:36-7:37>
references: None
type: None
expected type: None
Expr: <Int test.adb:7:38-7:39>
references: None
type: <ConcreteTypeDecl ["Universal_Int_Type_"] __standard:116:3-116:45>
expected type: <ConcreteTypeDecl ["Integer"] __standard:4:3-4:54>


Done.
2 changes: 2 additions & 0 deletions testsuite/tests/name_resolution/deref_attribute/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 732d5f4

Please sign in to comment.