Skip to content

Commit

Permalink
Merge branch 'topic/1390' into 'master'
Browse files Browse the repository at this point in the history
Make DefiningName's basic_decl property bypass internal nodes.

Closes #1390

See merge request eng/libadalang/libadalang!1656
  • Loading branch information
Roldak committed Jun 3, 2024
2 parents ed884a1 + 1f8bdcc commit 4cc7e4e
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 16 deletions.
35 changes: 19 additions & 16 deletions ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -18147,7 +18147,7 @@ def fully_qualified_name_impl(
lambda scel=T.SyntheticDefiningName: [scel.name_symbol.image],
lambda n: n.as_single_tok_node_array.map(lambda t: t.text)
))
bd = Var(Entity.basic_decl_no_internal)
bd = Var(Entity.basic_decl)

self_name = Var(def_name_array.map(
lambda i, t: t.concat(
Expand Down Expand Up @@ -18267,23 +18267,26 @@ def all_env_els_impl(
return Entity.name.all_env_els_impl(seq, seq_from, categories)

basic_decl = Property(
Self.parents.find(lambda p: p.is_a(T.BasicDecl))
.cast_or_raise(T.BasicDecl).as_entity,
public=True, memoized=True,
doc="Returns this DefiningName's basic declaration"
)

basic_decl_no_internal = Property(
Entity.basic_decl.then(
Entity.basic_decl_internal.then(
lambda bd: If(
bd.is_a(GenericPackageInternal, GenericSubpInternal,
SingleTaskTypeDecl),
bd.parent.cast_or_raise(BasicDecl),
bd
)
),
doc="Returns this DefiningName's basic declaration but discard "
"intermediate internal nodes."
public=True,
doc="Return this DefiningName's basic declaration, discarding internal"
" nodes such as Generic*Internal wrappers"
)

basic_decl_internal = Property(
Entity.parents.find(
lambda p: p.is_a(T.BasicDecl)
).cast_or_raise(T.BasicDecl),
memoized=True,
doc="Return this DefiningName's basic declaration, but do not bypass"
" internal nodes (such as Generic*Internal wrappers)"
)

@langkit_property(public=True, return_type=T.RefResult.array,
Expand Down Expand Up @@ -18583,7 +18586,7 @@ def get_aspect_impl(name=Symbol, inherited=Bool):
"""
return Entity.get_pragma(name).then(
lambda p: p.as_aspect(inherited)
)._or(Entity.basic_decl.get_aspect_assoc(name).then(
)._or(Entity.basic_decl_internal.get_aspect_assoc(name).then(
lambda aa: Aspect.new(exists=True, node=aa,
value=aa.expr, inherited=inherited)
))._or(Entity.get_representation_clause(name).then(
Expand Down Expand Up @@ -18639,7 +18642,7 @@ def get_aspect_on_parts(name=Symbol, inherited=Bool,
),

parts_to_check.map(
lambda p: p.basic_decl.get_aspect_assoc(name).then(
lambda p: p.basic_decl_internal.get_aspect_assoc(name).then(
lambda aa: Aspect.new(exists=True, node=aa,
value=aa.expr, inherited=inherited)
)
Expand All @@ -18653,7 +18656,7 @@ def get_aspect_on_parts(name=Symbol, inherited=Bool,
return self_aspects.find(lambda a: a.exists)._or(
# If nothing has been found so far for entity, check out for any
# inherited aspect.
Entity.basic_decl_no_internal.cast(BaseTypeDecl).then(
Entity.basic_decl.cast(BaseTypeDecl).then(
lambda bd: Let(
lambda typ=If(bd.is_a(T.BaseSubtypeDecl),
bd.cast(T.BaseSubtypeDecl).get_type,
Expand Down Expand Up @@ -18759,7 +18762,7 @@ def get_pragma(name=Symbol):
in aspects, i.e. information that can be represented by either aspect
specification nodes, pragma nodes or attribute definition nodes.
"""
bd = Var(Entity.basic_decl_no_internal.match(
bd = Var(Entity.basic_decl.match(
# If Entity is an EnumLiteralDecl, search the pragma from the enum
# type declaration node.
lambda eld=T.EnumLiteralDecl:
Expand Down Expand Up @@ -18843,7 +18846,7 @@ def is_ghost_code():
Return whether the entity defined by this name is ghost or not.
See SPARK RM 6.9.
"""
bd = Var(Entity.basic_decl_no_internal)
bd = Var(Entity.basic_decl)
return Or(
Entity.has_aspect('Ghost'),
bd.parent_basic_decl._.is_ghost_code(),
Expand Down
33 changes: 33 additions & 0 deletions testsuite/tests/properties/basic_decl/test.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
procedure Test is
task My_Task;
--% node.find(lal.DefiningName).p_basic_decl

task body My_Task is
begin
null;
end My_Task;
--% node.find(lal.DefiningName).p_basic_decl

task type My_Task_Type;
--% node.find(lal.DefiningName).p_basic_decl

task body My_Task_Type is
begin
null;
end My_Task_Type;
--% node.find(lal.DefiningName).p_basic_decl

generic
package Pkg is
end Pkg;
--% node.find(lal.DefiningName).p_basic_decl

generic
procedure Foo;
--% node.find(lal.DefiningName).p_basic_decl

procedure Foo is null;
--% node.find(lal.DefiningName).p_basic_decl
begin
null;
end Test;
41 changes: 41 additions & 0 deletions testsuite/tests/properties/basic_decl/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Working on node <SingleTaskDecl ["My_Task"] test.adb:2:4-2:17>
==============================================================

Eval 'node.find(lal.DefiningName).p_basic_decl'
Result: <SingleTaskDecl ["My_Task"] test.adb:2:4-2:17>

Working on node <TaskBody ["My_Task"] test.adb:5:4-8:16>
========================================================

Eval 'node.find(lal.DefiningName).p_basic_decl'
Result: <TaskBody ["My_Task"] test.adb:5:4-8:16>

Working on node <TaskTypeDecl ["My_Task_Type"] test.adb:11:4-11:27>
===================================================================

Eval 'node.find(lal.DefiningName).p_basic_decl'
Result: <TaskTypeDecl ["My_Task_Type"] test.adb:11:4-11:27>

Working on node <TaskBody ["My_Task_Type"] test.adb:14:4-17:21>
===============================================================

Eval 'node.find(lal.DefiningName).p_basic_decl'
Result: <TaskBody ["My_Task_Type"] test.adb:14:4-17:21>

Working on node <GenericPackageInternal ["Pkg"] test.adb:21:4-22:12>
====================================================================

Eval 'node.find(lal.DefiningName).p_basic_decl'
Result: <GenericPackageDecl ["Pkg"] test.adb:20:4-22:12>

Working on node <GenericSubpDecl ["Foo"] test.adb:25:4-26:18>
=============================================================

Eval 'node.find(lal.DefiningName).p_basic_decl'
Result: <GenericSubpDecl ["Foo"] test.adb:25:4-26:18>

Working on node <NullSubpDecl ["Foo"] test.adb:29:4-29:26>
==========================================================

Eval 'node.find(lal.DefiningName).p_basic_decl'
Result: <NullSubpDecl ["Foo"] test.adb:29:4-29:26>
2 changes: 2 additions & 0 deletions testsuite/tests/properties/basic_decl/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
driver: inline-playground
input_sources: [test.adb]

0 comments on commit 4cc7e4e

Please sign in to comment.