From 1f8bdccd00c15f1fdc316e3595e6825f60fc55d5 Mon Sep 17 00:00:00 2001 From: Romain Beguet Date: Fri, 31 May 2024 10:28:55 +0200 Subject: [PATCH] Make DefiningName's basic_decl property bypass internal nodes. --- ada/ast.py | 35 ++++++++-------- .../tests/properties/basic_decl/test.adb | 33 +++++++++++++++ .../tests/properties/basic_decl/test.out | 41 +++++++++++++++++++ .../tests/properties/basic_decl/test.yaml | 2 + 4 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 testsuite/tests/properties/basic_decl/test.adb create mode 100644 testsuite/tests/properties/basic_decl/test.out create mode 100644 testsuite/tests/properties/basic_decl/test.yaml diff --git a/ada/ast.py b/ada/ast.py index d542683d8..72c3998f4 100644 --- a/ada/ast.py +++ b/ada/ast.py @@ -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( @@ -18267,14 +18267,7 @@ 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), @@ -18282,8 +18275,18 @@ def all_env_els_impl( 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, @@ -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( @@ -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) ) @@ -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, @@ -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: @@ -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(), diff --git a/testsuite/tests/properties/basic_decl/test.adb b/testsuite/tests/properties/basic_decl/test.adb new file mode 100644 index 000000000..fa2f75d51 --- /dev/null +++ b/testsuite/tests/properties/basic_decl/test.adb @@ -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; diff --git a/testsuite/tests/properties/basic_decl/test.out b/testsuite/tests/properties/basic_decl/test.out new file mode 100644 index 000000000..834cc8ac3 --- /dev/null +++ b/testsuite/tests/properties/basic_decl/test.out @@ -0,0 +1,41 @@ +Working on node +============================================================== + +Eval 'node.find(lal.DefiningName).p_basic_decl' +Result: + +Working on node +======================================================== + +Eval 'node.find(lal.DefiningName).p_basic_decl' +Result: + +Working on node +=================================================================== + +Eval 'node.find(lal.DefiningName).p_basic_decl' +Result: + +Working on node +=============================================================== + +Eval 'node.find(lal.DefiningName).p_basic_decl' +Result: + +Working on node +==================================================================== + +Eval 'node.find(lal.DefiningName).p_basic_decl' +Result: + +Working on node +============================================================= + +Eval 'node.find(lal.DefiningName).p_basic_decl' +Result: + +Working on node +========================================================== + +Eval 'node.find(lal.DefiningName).p_basic_decl' +Result: diff --git a/testsuite/tests/properties/basic_decl/test.yaml b/testsuite/tests/properties/basic_decl/test.yaml new file mode 100644 index 000000000..35ad4d5c4 --- /dev/null +++ b/testsuite/tests/properties/basic_decl/test.yaml @@ -0,0 +1,2 @@ +driver: inline-playground +input_sources: [test.adb]