Skip to content

Commit 4384876

Browse files
committed
Lkt lowering: handle external properties
TN: RA22-015
1 parent 9100a0b commit 4384876

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

langkit/lkt_lowering.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,15 @@ class StructAnnotations(ParsedAnnotations):
492492
class FunAnnotations(ParsedAnnotations):
493493
abstract: bool
494494
export: bool
495+
external: bool
496+
uses_entity_info: bool
497+
uses_envs: bool
495498
annotations = [
496499
FlagAnnotationSpec('abstract'),
497-
498500
FlagAnnotationSpec('export'),
501+
FlagAnnotationSpec('external'),
502+
FlagAnnotationSpec('uses_entity_info'),
503+
FlagAnnotationSpec('uses_envs'),
499504
]
500505

501506

@@ -1665,12 +1670,25 @@ def lower_property(self, full_decl: L.FullDecl) -> PropertyDef:
16651670
env[a] = arg.var
16661671

16671672
# Lower the expression itself
1668-
if annotations.abstract:
1673+
if annotations.abstract or annotations.external:
16691674
assert decl.f_body is None
16701675
expr = None
16711676
else:
16721677
expr = self.lower_expr(decl.f_body, env)
16731678

1679+
# If @uses_entity_info and @uses_envs are not present for non-external
1680+
# properties, use None instead of False, for the validation machinery
1681+
# in PropertyDef to work properly (we expect False/true for external
1682+
# properties, and None for non-external ones).
1683+
uses_entity_info: Optional[bool]
1684+
uses_envs: Optional[bool]
1685+
if annotations.external:
1686+
uses_entity_info = annotations.uses_entity_info
1687+
uses_envs = annotations.uses_envs
1688+
else:
1689+
uses_entity_info = annotations.uses_entity_info or None
1690+
uses_envs = annotations.uses_envs or None
1691+
16741692
result = PropertyDef(
16751693
expr=expr,
16761694
prefix=AbstractNodeData.PREFIX_PROPERTY,
@@ -1688,9 +1706,9 @@ def lower_property(self, full_decl: L.FullDecl) -> PropertyDef:
16881706
memoized=False,
16891707
call_memoizable=False,
16901708
memoize_in_populate=False,
1691-
external=False,
1692-
uses_entity_info=None,
1693-
uses_envs=None,
1709+
external=annotations.external,
1710+
uses_entity_info=uses_entity_info,
1711+
uses_envs=uses_envs,
16941712
optional_entity_info=False,
16951713
warn_on_unused=True,
16961714
ignore_warn_on_node=None,

testsuite/tests/misc/event_handler/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Example(FooNode):
2828
build_and_run(
2929
lkt_file="expected_concrete_syntax.lkt",
3030
ada_main="main.adb",
31-
lkt_semantic_checks=True
31+
types_from_lkt=True,
3232
)
3333

3434
print("Done")

testsuite/tests/properties/external/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ class Plus(Expression):
3232
result = Property(Self.left.result + Self.right.result)
3333

3434

35-
build_and_run(lkt_file='expected_concrete_syntax.lkt', py_script='main.py')
35+
build_and_run(lkt_file='expected_concrete_syntax.lkt', py_script='main.py',
36+
types_from_lkt=True)
3637
print('Done')

0 commit comments

Comments
 (0)