Skip to content

Commit

Permalink
Merge branch 'topic/is_definite_subt' into 'master'
Browse files Browse the repository at this point in the history
Extend is_definite_subtype to work on type expressions

See merge request eng/libadalang/libadalang!1632
  • Loading branch information
raph-amiard committed Apr 30, 2024
2 parents 4f3c6c9 + 2511512 commit 8ebb438
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ada/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -10484,6 +10484,13 @@ class TypeExpr(AdaNode):
This node has no ARM correspondence.
"""

@langkit_property(public=True)
def is_definite_subtype():
"""
Returns whether this designates a definite subtype.
"""
return Entity.designated_type_decl.is_definite_subtype

array_ndims = Property(
origin.bind(Self.origin_node, Entity.designated_type.array_ndims)
)
Expand Down Expand Up @@ -10643,6 +10650,13 @@ class SubtypeIndication(TypeExpr):
env.bind(Entity.node_env, Entity.name.designated_type_impl)
)

@langkit_property()
def is_definite_subtype():
return (
Not(Entity.constraint.is_null)
| Entity.designated_type_decl.is_definite_subtype
)

@langkit_property(return_type=T.CompletionItem.array)
def complete_items():
"""
Expand Down
12 changes: 12 additions & 0 deletions testsuite/tests/properties/is_definite_subtype/test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ procedure Test is
type C is array (Integer) of Natural;
type CC is array (Integer range <>) of Integer;
type D is new CC (1 .. 12);

type E (A : Boolean) is record
case A is
when True => B : Integer;
when False => null;
end case;
end record;

O1 : CC := (1, 2, 3, 4);
O2 : CC (1 .. 10);
O3 : E (True);
O4 : E := (A => True, others => <>);
begin
null;
end Test;
5 changes: 5 additions & 0 deletions testsuite/tests/properties/is_definite_subtype/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
<ConcreteTypeDecl ["C"] test.adb:6:4-6:41> is a definite subtype
<ConcreteTypeDecl ["CC"] test.adb:7:4-7:51> is not a definite subtype
<ConcreteTypeDecl ["D"] test.adb:8:4-8:31> is a definite subtype
<ConcreteTypeDecl ["E"] test.adb:10:4-15:15> is not a definite subtype
<SubtypeIndication test.adb:17:9-17:11> is not a definite subtype
<SubtypeIndication test.adb:18:9-18:21> is a definite subtype
<SubtypeIndication test.adb:19:9-19:17> is a definite subtype
<SubtypeIndication test.adb:20:9-20:10> is not a definite subtype

Done
7 changes: 7 additions & 0 deletions testsuite/tests/properties/is_definite_subtype/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
else:
print('{} is not a definite subtype'.format(n))

for n in u.root.findall(lal.ObjectDecl):
te = n.f_type_expr
if te.p_is_definite_subtype:
print('{} is a definite subtype'.format(te))
else:
print('{} is not a definite subtype'.format(te))

print('')

print('Done')

0 comments on commit 8ebb438

Please sign in to comment.