Skip to content

Commit ebd3f59

Browse files
committed
Merge branch 'topic/845' into 'master'
Fix uninitialized memory when using %domain construct. Closes #845 See merge request eng/libadalang/langkit!1211
2 parents 0fe6e6c + ee8b0a8 commit ebd3f59

File tree

6 files changed

+77
-1
lines changed

6 files changed

+77
-1
lines changed

langkit/templates/properties/domain_ada.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ begin
1515
if element_type.is_entity_type else
1616
element_type)
1717
node_expr = 'Item.Node' if element_type.is_entity_type else 'Item'
18-
info_expr = 'Item.Info' if element_type.is_entity_type else '<>'
18+
info_expr = ('Item.Info'
19+
if element_type.is_entity_type else
20+
'No_Entity_Info')
1921
%>
2022
Item : constant ${element_type.name} := Get (Self, Dom, J);
2123
begin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import lexer_example
2+
3+
@with_lexer(foo_lexer)
4+
grammar foo_grammar {
5+
@main_rule main_rule <- Example("example")
6+
}
7+
8+
@abstract
9+
class FooNode implements Node[FooNode] {
10+
v: LogicVar
11+
}
12+
13+
class Example: FooNode {
14+
fun identity(): Entity[Example] = self
15+
16+
@exported
17+
fun test(): Bool = (
18+
%domain(node.v, [node]) and %eq(node.v, node.v, conv_prop=Example.identity)
19+
).solve()
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
with Ada.Text_IO; use Ada.Text_IO;
2+
3+
with Libfoolang.Analysis; use Libfoolang.Analysis;
4+
5+
procedure Main is
6+
Ctx : constant Analysis_Context := Create_Context;
7+
U : constant Analysis_Unit := Ctx.Get_From_Buffer
8+
(Filename => "main.txt", Buffer => "example");
9+
10+
Node : constant Example := U.Root.As_Example;
11+
Dummy : Boolean;
12+
begin
13+
if U.Has_Diagnostics then
14+
Put_Line ("Parsing errors...");
15+
return;
16+
end if;
17+
Dummy := Node.P_Test;
18+
Put_Line ("main.adb: Done.");
19+
end Main;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
main.adb: Done.
2+
Done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Test that using the ``domain`` DSL construct with bare nodes does not set
3+
uninitialized data into the corresponding logic variable.
4+
"""
5+
6+
from langkit.dsl import ASTNode, T, UserField
7+
from langkit.expressions import Bind, Entity, Self, langkit_property
8+
9+
from utils import build_and_run
10+
11+
12+
class FooNode(ASTNode):
13+
v = UserField(type=T.LogicVar, public=False)
14+
15+
16+
class Example(FooNode):
17+
@langkit_property(return_type=T.Example.entity)
18+
def identity():
19+
return Entity
20+
21+
@langkit_property(public=True)
22+
def test():
23+
return (Self.v.domain([Self]) &
24+
Bind(Self.v, Self.v, conv_prop=Example.identity)).solve
25+
26+
27+
build_and_run(
28+
lkt_file='expected_concrete_syntax.lkt',
29+
gpr_mains=['main.adb'],
30+
types_from_lkt=True,
31+
)
32+
print('Done')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
driver: python

0 commit comments

Comments
 (0)