Skip to content

Commit

Permalink
Merge branch 'topic/1128' into 'master'
Browse files Browse the repository at this point in the history
Support Result attribute on access-to-function type

Closes #1128

See merge request eng/libadalang/libadalang!1460
  • Loading branch information
thvnx committed Nov 16, 2023
2 parents 4c974bc + 09e0f60 commit df74463
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 9 deletions.
18 changes: 12 additions & 6 deletions ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -19914,20 +19914,26 @@ def bind_to_prefix_eq():

@langkit_property(return_type=Equation, dynamic_vars=[env, origin])
def result_attr_equation():
# We find the containing subprogram starting the bound env's node
# instead of Self, as this attribute can appear in a pragma Post
# appearing *after* the subprogram.
containing_subp = Var(env.env_node.parents.find(
# We find the containing declaration (a function declaration or an
# access-to-function type) starting the bound env's node instead of
# Self, as this attribute can appear in a pragma Post appearing
# *after* the declaration.
containing_decl = Var(env.env_node.parents.find(
lambda p: p.is_a(BasicSubpDecl, BaseSubpBody)
| p.cast(ConcreteTypeDecl)._.type_def.is_a(AccessToSubpDef)
).as_entity.cast(T.BasicDecl))

returns = Var(containing_subp.subp_spec_or_null.then(
returns = Var(containing_decl.match(
lambda sd=T.ConcreteTypeDecl:
sd.type_def.cast(AccessToSubpDef).subp_spec,
lambda bd=T.BasicDecl: bd.subp_spec_or_null,
).then(
lambda ss: ss.return_type
))

return And(
Bind(Self.type_var, returns),
Bind(Entity.prefix.ref_var, containing_subp)
Bind(Entity.prefix.ref_var, containing_decl)
)

@langkit_property(return_type=Equation, dynamic_vars=[env, origin])
Expand Down
112 changes: 109 additions & 3 deletions testsuite/tests/name_resolution/post_result/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,120 @@ Expr: <Id "Barize" test_result_attr.adb:8:8-8:14>
type: None
expected type: None

Resolving xrefs for node <EndName test_result_attr.adb:10:5-10:21>
Resolving xrefs for node <ConcreteTypeDecl ["T1"] test_result_attr.adb:10:4-11:29>
**********************************************************************************


Resolving xrefs for node <SubpSpec test_result_attr.adb:10:22-10:59>
********************************************************************

Expr: <Id "Boolean" test_result_attr.adb:10:52-10:59>
references: <DefiningName "Boolean" __standard:3:8-3:15>
type: None
expected type: None

Resolving xrefs for node <ParamSpec ["A"] test_result_attr.adb:10:32-10:43>
***************************************************************************

Expr: <Id "Boolean" test_result_attr.adb:10:36-10:43>
references: <DefiningName "Boolean" __standard:3:8-3:15>
type: None
expected type: None

Resolving xrefs for node <AspectAssoc test_result_attr.adb:11:7-11:28>
**********************************************************************

Expr: <Id "Post" test_result_attr.adb:11:7-11:11>
references: None
type: None
expected type: None
Expr: <RelationOp test_result_attr.adb:11:15-11:28>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
Expr: <AttributeRef test_result_attr.adb:11:15-11:24>
references: None
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
Expr: <Id "T1" test_result_attr.adb:11:15-11:17>
references: <DefiningName "T1" test_result_attr.adb:10:9-10:11>
type: None
expected type: None
Expr: <Id "Result" test_result_attr.adb:11:18-11:24>
references: None
type: None
expected type: None
Expr: <OpEq "=" test_result_attr.adb:11:25-11:26>
references: None
type: None
expected type: None
Expr: <Id "A" test_result_attr.adb:11:27-11:28>
references: <DefiningName "A" test_result_attr.adb:10:32-10:33>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>

Resolving xrefs for node <ConcreteTypeDecl ["T2"] test_result_attr.adb:13:4-13:60>
**********************************************************************************


Resolving xrefs for node <SubpSpec test_result_attr.adb:13:22-13:59>
********************************************************************

Expr: <Id "Boolean" test_result_attr.adb:13:52-13:59>
references: <DefiningName "Boolean" __standard:3:8-3:15>
type: None
expected type: None

Resolving xrefs for node <ParamSpec ["A"] test_result_attr.adb:13:32-13:43>
***************************************************************************

Expr: <Id "Boolean" test_result_attr.adb:13:36-13:43>
references: <DefiningName "Boolean" __standard:3:8-3:15>
type: None
expected type: None

Resolving xrefs for node <PragmaNode test_result_attr.adb:15:4-15:35>
*********************************************************************

Expr: <Id "Post" test_result_attr.adb:15:11-15:15>
references: None
type: None
expected type: None
Expr: <RelationOp test_result_attr.adb:15:17-15:33>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
Expr: <AttributeRef test_result_attr.adb:15:17-15:26>
references: None
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
Expr: <Id "T2" test_result_attr.adb:15:17-15:19>
references: <DefiningName "T2" test_result_attr.adb:13:9-13:11>
type: None
expected type: None
Expr: <Id "Result" test_result_attr.adb:15:20-15:26>
references: None
type: None
expected type: None
Expr: <OpEq "=" test_result_attr.adb:15:27-15:28>
references: None
type: None
expected type: None
Expr: <Id "True" test_result_attr.adb:15:29-15:33>
references: <DefiningName "True" __standard:3:27-3:31>
type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>
expected type: <ConcreteTypeDecl ["Boolean"] __standard:3:3-3:33>

Resolving xrefs for node <NullStmt test_result_attr.adb:18:4-18:9>
******************************************************************


Resolving xrefs for node <EndName test_result_attr.adb:19:5-19:21>
******************************************************************

Expr: <EndName test_result_attr.adb:10:5-10:21>
Expr: <EndName test_result_attr.adb:19:5-19:21>
references: <DefiningName "Test_Result_Attr" test_result_attr.adb:1:11-1:27>
type: None
expected type: None
Expr: <Id "Test_Result_Attr" test_result_attr.adb:10:5-10:21>
Expr: <Id "Test_Result_Attr" test_result_attr.adb:19:5-19:21>
references: <DefiningName "Test_Result_Attr" test_result_attr.adb:1:11-1:27>
type: None
expected type: None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ procedure Test_Result_Attr is
begin
return 12;
end Barize;

type T1 is access function (A : Boolean) return Boolean with
Post => T1'Result = A;

type T2 is access function (A : Boolean) return Boolean;

pragma Post (T2'Result = True);

begin
null;
end Test_Result_Attr;
pragma Test_Block;

0 comments on commit df74463

Please sign in to comment.