Skip to content

Commit

Permalink
Merge branch 'topic/1070' into 'master'
Browse files Browse the repository at this point in the history
Fix Depends aspect support

Closes #1070

See merge request eng/libadalang/libadalang!1505
  • Loading branch information
thvnx committed Jan 18, 2024
2 parents ebcdb34 + 347e393 commit 5c1f331
Show file tree
Hide file tree
Showing 4 changed files with 522 additions and 7 deletions.
26 changes: 19 additions & 7 deletions ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -16848,16 +16848,28 @@ def depends_assoc_equation():
# call sub_equation: If it's a name it will resolve the name. If
# it's an aggregate it will return LogicTrue() and the content will
# be resolved separately.
Entity.expr.sub_equation,

If(
# The ``null`` literal is a possible value for ```expr``. Do
# not resolve it.
Or(
Entity.expr.is_a(T.NullLiteral),
Entity.expr.cast(T.UnOp)._.expr._.is_a(T.NullLiteral)
),
LogicTrue(),
Entity.expr.sub_equation
),
# Here, we go fetch the first element of the list of names. Since
# we parse this as an aggregate, the list is elements separated by
# pipes (alternatives_list), which will ever only have one element
# in this case. We make sure to only resolve Identifiers, because
# the ``null`` literal is also possible here and we don't want
# to resolve it.
Entity.names.at(0).cast(Identifier).as_entity.then(
lambda n: n.sub_equation, default_val=LogicTrue()
# in this case. As above, we make sure to not resolve the ``null``
# literal.
Let(
lambda n=Entity.names.at(0):
If(
n.is_null | n.is_a(T.NullLiteral),
LogicTrue(),
n.as_entity.sub_equation
)
)
)

Expand Down
63 changes: 63 additions & 0 deletions testsuite/tests/name_resolution/global_depends_aspects_2/test.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
-- All these tests have been derived from the SPARK documentation

procedure Test is
X, Y, Z, A, B, C, D, G : Integer;

procedure P (X, Y, Z : in Integer; Result : out Boolean)
with Depends => (Result => (X, Y, Z));
pragma Test_Block;

procedure Q (X, Y, Z : in Integer; A, B, C, D, E : out Integer)
with Depends => ((A, B) => (X, Y),
C => (X, Z),
D => null,
E => Y);
pragma Test_Block;

procedure R (X, Y, Z : in Integer; A, B, C, D : in out Integer)
with Depends => ((A, B) =>+ (A, X, Y),
C =>+ Z,
D =>+ null);
pragma Test_Block;

procedure S
with Global => (Input => (X, Y, Z),
In_Out => (A, B, C, D)),
Depends => ((A, B) =>+ (A, X, Y, Z),
C =>+ Y,
D =>+ null);
pragma Test_Block;

function F (X, Y : Integer) return Integer
with Global => G,
Depends => (F'Result => (G, X),
null => Y);
pragma Test_Block;

procedure P (X, Y, Z : in Integer; Result : out Boolean) is
begin
null;
end;

procedure Q (X, Y, Z : in Integer; A, B, C, D, E : out Integer) is
begin
null;
end;

procedure R (X, Y, Z : in Integer; A, B, C, D : in out Integer) is
begin
null;
end;

procedure S is
begin
null;
end;

function F (X, Y : Integer) return Integer is
begin
return 0;
end;
begin
null;
end Test;
Loading

0 comments on commit 5c1f331

Please sign in to comment.