Skip to content

Commit 9d665ee

Browse files
committed
Lkt: use lkt_toolbox instead of lkt_resolve driver
For convenience, get rid of the lkt_resolve driver and use lkt_toolbox to run Lkt's tests. TN: UA29-022
1 parent c68098d commit 9d665ee

File tree

29 files changed

+196
-252
lines changed

29 files changed

+196
-252
lines changed

contrib/lkt/extensions/mains/lkt_toolbox.adb

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
with Ada.Directories; use Ada.Directories;
22
with Ada.Exceptions;
3+
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
34
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
45
with Ada.Text_IO; use Ada.Text_IO;
56

@@ -14,7 +15,7 @@ use Langkit_Support.Diagnostics.Output;
1415

1516
with Langkit_Support.Text; use Langkit_Support.Text;
1617

17-
with Liblktlang.Analysis;
18+
with Liblktlang.Analysis; use Liblktlang.Analysis;
1819
with Liblktlang.Common;
1920

2021
procedure Lkt_Toolbox is
@@ -45,6 +46,20 @@ procedure Lkt_Toolbox is
4546
(S : Analysis.Semantic_Result; Unit : Analysis.Analysis_Unit);
4647
-- Print a semantic result
4748

49+
function Format_Node (Decl_Node : Decl'Class) return String;
50+
-- Format node for semantic result printing
51+
52+
-----------------
53+
-- Format_Node --
54+
-----------------
55+
56+
function Format_Node (Decl_Node : Decl'Class) return String is
57+
begin
58+
-- Remove rebindings information as there is no easy way to filter
59+
-- out/format rebindings information involving prelude declarations.
60+
return Decl_Node.P_As_Bare_Decl.Image;
61+
end Format_Node;
62+
4863
---------------------------
4964
-- Print_Semantic_Result --
5065
---------------------------
@@ -75,7 +90,7 @@ procedure Lkt_Toolbox is
7590
and then not Analysis.Result_Ref (S).Is_Null
7691
then
7792
Put_Line ("Id " & Analysis.Node (S).Image);
78-
Put_Line (" references " & Analysis.Result_Ref (S).Image);
93+
Put_Line (" references " & Format_Node (Analysis.Result_Ref (S)));
7994
New_Line;
8095
end if;
8196
end Print_Semantic_Result;
@@ -87,9 +102,15 @@ begin
87102
if Arg.Parser.Parse then
88103
for File_Name of Arg.Files.Get loop
89104
declare
90-
Unit : constant Analysis.Analysis_Unit
91-
:= Ctx.Get_From_File (To_String (File_Name));
105+
File_Name_Str : constant String := To_String (File_Name);
106+
Unit : constant Analysis.Analysis_Unit :=
107+
Ctx.Get_From_File (File_Name_Str);
92108
begin
109+
if not Arg.Check_Only.Get then
110+
Put_Line ("Resolving " & File_Name_Str);
111+
Put_Line ((File_Name_Str'Length + 10) * "=");
112+
end if;
113+
93114
if Unit.Diagnostics'Length > 0 then
94115
for Diagnostic of Unit.Diagnostics loop
95116
Print_Diagnostic

contrib/lkt/extensions/src/liblktlang-implementation-extensions.adb

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,24 @@ package body Liblktlang.Implementation.Extensions is
7474
function Decl_Short_Image (Node : Bare_Decl) return Text_Type is
7575
Full_Name_Acc : String_Type := Dispatcher_Decl_P_Full_Name (Node);
7676
Full_Name : constant Text_Type := Full_Name_Acc.Content;
77+
File_Name : constant Text_Type :=
78+
To_Text (Ada.Directories.Simple_Name (Get_Filename (Unit (Node))));
7779
begin
7880
Dec_Ref (Full_Name_Acc);
79-
return
80-
"<" & To_Text (Kind_Name (Node)) & " """ & Full_Name & """ "
81-
& To_Text (Ada.Directories.Simple_Name (Get_Filename (Unit (Node))))
82-
83-
-- Don't show the sloc for function types, because it will be the root
84-
-- node's sloc, and thus will always change when we add stuff to the
85-
-- file, which is not helpful nor practical for tests.
86-
& (if Node.Kind = Lkt_Function_Type
87-
then ""
88-
else ":" & To_Text (Image (Sloc_Range (Node)))) & ">";
81+
if File_Name = "__prelude" then
82+
return "<" & To_Text (Kind_Name (Node))
83+
& " prelude: """ & Full_Name & """>";
84+
else
85+
return "<" & To_Text (Kind_Name (Node)) & " """ & Full_Name & """ "
86+
& File_Name
87+
88+
-- Don't show the sloc for function types, because it will be the
89+
-- root node's sloc, and thus will always change when we add stuff
90+
-- to the file, which is not helpful nor practical for tests.
91+
& (if Node.Kind = Lkt_Function_Type
92+
then ""
93+
else ":" & To_Text (Image (Sloc_Range (Node)))) & ">";
94+
end if;
8995
end Decl_Short_Image;
9096

9197
--------------------------------------

contrib/lkt/language/parser.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,17 @@ def assert_bare():
620620
PropertyError(T.Decl, "Type decl has rebindings but shouldn't")
621621
)
622622

623+
@langkit_property(public=True)
624+
def as_bare_decl():
625+
"""
626+
Get this declaration without rebindings information.
627+
"""
628+
# This is used by lkt_toolbox as a simple solution to filter out
629+
# rebindings information for the prelude declarations. TODO: improve it
630+
# in order to properly show rebindings information for prelude
631+
# declarations (i.e. do not show sloc nor unit name).
632+
return Entity.node.as_bare_entity
633+
623634
@langkit_property()
624635
def call_scope():
625636
"""

contrib/lkt/lkt_resolve.py

Lines changed: 0 additions & 87 deletions
This file was deleted.

support/langkit_support-diagnostics-output.adb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ package body Langkit_Support.Diagnostics.Output is
6666

6767
Line_Nb : constant Positive := Positive (Sloc_Range.Start_Line);
6868
Start_Offset : constant Positive := Positive (Sloc_Range.Start_Column);
69-
End_Offset : constant Positive := Positive (Sloc_Range.End_Column);
69+
End_Offset : constant Positive := Positive (Sloc_Range.End_Column) - 1;
7070

7171
Line_Nb_Width : constant Positive :=
7272
Positive'Image (Line_Nb + Lines_After)'Length - 1;
@@ -96,7 +96,7 @@ package body Langkit_Support.Diagnostics.Output is
9696
declare
9797
Caret_Line : Text_Type (1 .. End_Offset) := (others => ' ');
9898
begin
99-
Caret_Line (Start_Offset .. End_Offset - 1) := (others => '^');
99+
Caret_Line (Start_Offset .. End_Offset) := (others => '^');
100100
Put_Line (Output_File, Caret_Line);
101101
end;
102102
Reset_Colors;

testsuite/drivers/lkt_resolve_driver.py

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from drivers.base_driver import BaseDriver
2+
3+
4+
class LktToolboxDriver(BaseDriver):
5+
"""
6+
Custom driver that will automatically run the "lkt_toolbox" utility
7+
on the testcase's "test.lkt" file.
8+
"""
9+
10+
def run(self):
11+
self.run_and_check(['lkt_toolbox', 'test.lkt'],
12+
memcheck=True, for_coverage=True)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Resolving test.lkt
22
==================
33
test.lkt:4:9: error: ambiguous type for expression
4-
3 | val a = "hello"
4+
4 | val a = "hello"
55
| ^^^^^^^
66

testsuite/tests/contrib/lkt_semantic/array_list_methods/test.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ Id <RefId "String" test.lkt:13:57-13:63>
8585
references <StructDecl prelude: "String">
8686

8787
test.lkt:13:66: error: Cannot find entity `self` in this scope
88-
12 | @invalid fun test_astlist_indexing(a: ASTList[String]): String = self(12)
89-
| ^^^^
88+
13 | @invalid fun test_astlist_indexing(a: ASTList[String]): String = self(12)
89+
| ^^^^
9090

testsuite/tests/contrib/lkt_semantic/array_type_concrete/test.out

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ Expr <RefId "bar" test.lkt:17:27-17:30>
154154
has type <FunctionType prelude: "() -> String">
155155

156156
test.lkt:17:27: error: Mismatched types: expected `Int`, got `String`
157-
16 | @invalid val a5 = [foo(), bar()]
158-
| ^^^^^
157+
17 | @invalid val a5 = [foo(), bar()]
158+
| ^^^^^
159159

160160
Expr <ArrayLiteral test.lkt:17:19-17:33>
161161
has type <InstantiatedGenericType prelude: "Array[Int]">
@@ -164,12 +164,12 @@ Expr <NumLit test.lkt:18:20-18:21>
164164
has type <StructDecl prelude: "Int">
165165

166166
test.lkt:18:23: error: Mismatched types: expected `Int`, got a character literal
167-
17 | @invalid val a6 = [1, '2', "3", foo(), bar()]
168-
| ^^^
167+
18 | @invalid val a6 = [1, '2', "3", foo(), bar()]
168+
| ^^^
169169

170170
test.lkt:18:28: error: Mismatched types: expected `Int`, got a string literal
171-
17 | @invalid val a6 = [1, '2', "3", foo(), bar()]
172-
| ^^^
171+
18 | @invalid val a6 = [1, '2', "3", foo(), bar()]
172+
| ^^^
173173

174174
Id <RefId "foo" test.lkt:18:33-18:36>
175175
references <FunDecl "foo" test.lkt:8:1-8:19>
@@ -187,11 +187,11 @@ Expr <RefId "bar" test.lkt:18:40-18:43>
187187
has type <FunctionType prelude: "() -> String">
188188

189189
test.lkt:18:40: error: Mismatched types: expected `Int`, got `String`
190-
17 | @invalid val a6 = [1, '2', "3", foo(), bar()]
191-
| ^^^^^
190+
18 | @invalid val a6 = [1, '2', "3", foo(), bar()]
191+
| ^^^^^
192192

193193
test.lkt:18:19: error: ambiguous type for expression
194-
17 | @invalid val a6 = [1, '2', "3", foo(), bar()]
194+
18 | @invalid val a6 = [1, '2', "3", foo(), bar()]
195195
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
196196

197197
Id <RefId "foo" test.lkt:20:12-20:15>
@@ -408,18 +408,18 @@ Expr <ArrayLiteral test.lkt:31:21-31:33>
408408
has type <InstantiatedGenericType prelude: "Array[String]">
409409

410410
test.lkt:31:36: error: Mismatched types: expected `String`, got a number literal
411-
30 | @invalid val a11 = [[bar(), "2"], [1, 2]]
412-
| ^
411+
31 | @invalid val a11 = [[bar(), "2"], [1, 2]]
412+
| ^
413413

414414
test.lkt:31:39: error: Mismatched types: expected `String`, got a number literal
415-
30 | @invalid val a11 = [[bar(), "2"], [1, 2]]
416-
| ^
415+
31 | @invalid val a11 = [[bar(), "2"], [1, 2]]
416+
| ^
417417

418418
test.lkt:31:35: error: Mismatched types: expected `Array[String]`, got an array
419-
30 | @invalid val a11 = [[bar(), "2"], [1, 2]]
420-
| ^^^^^^
419+
31 | @invalid val a11 = [[bar(), "2"], [1, 2]]
420+
| ^^^^^^
421421

422422
test.lkt:31:20: error: ambiguous type for expression
423-
30 | @invalid val a11 = [[bar(), "2"], [1, 2]]
423+
31 | @invalid val a11 = [[bar(), "2"], [1, 2]]
424424
| ^^^^^^^^^^^^^^^^^^^^^^
425425

0 commit comments

Comments
 (0)