Skip to content

Commit

Permalink
Lkt: use lkt_toolbox instead of lkt_resolve driver
Browse files Browse the repository at this point in the history
For convenience, get rid of the lkt_resolve driver and use lkt_toolbox
to run Lkt's tests.

TN: UA29-022
  • Loading branch information
thvnx committed Nov 9, 2021
1 parent c68098d commit 9d665ee
Show file tree
Hide file tree
Showing 29 changed files with 196 additions and 252 deletions.
29 changes: 25 additions & 4 deletions contrib/lkt/extensions/mains/lkt_toolbox.adb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
with Ada.Directories; use Ada.Directories;
with Ada.Exceptions;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;

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

with Langkit_Support.Text; use Langkit_Support.Text;

with Liblktlang.Analysis;
with Liblktlang.Analysis; use Liblktlang.Analysis;
with Liblktlang.Common;

procedure Lkt_Toolbox is
Expand Down Expand Up @@ -45,6 +46,20 @@ procedure Lkt_Toolbox is
(S : Analysis.Semantic_Result; Unit : Analysis.Analysis_Unit);
-- Print a semantic result

function Format_Node (Decl_Node : Decl'Class) return String;
-- Format node for semantic result printing

-----------------
-- Format_Node --
-----------------

function Format_Node (Decl_Node : Decl'Class) return String is
begin
-- Remove rebindings information as there is no easy way to filter
-- out/format rebindings information involving prelude declarations.
return Decl_Node.P_As_Bare_Decl.Image;
end Format_Node;

---------------------------
-- Print_Semantic_Result --
---------------------------
Expand Down Expand Up @@ -75,7 +90,7 @@ procedure Lkt_Toolbox is
and then not Analysis.Result_Ref (S).Is_Null
then
Put_Line ("Id " & Analysis.Node (S).Image);
Put_Line (" references " & Analysis.Result_Ref (S).Image);
Put_Line (" references " & Format_Node (Analysis.Result_Ref (S)));
New_Line;
end if;
end Print_Semantic_Result;
Expand All @@ -87,9 +102,15 @@ begin
if Arg.Parser.Parse then
for File_Name of Arg.Files.Get loop
declare
Unit : constant Analysis.Analysis_Unit
:= Ctx.Get_From_File (To_String (File_Name));
File_Name_Str : constant String := To_String (File_Name);
Unit : constant Analysis.Analysis_Unit :=
Ctx.Get_From_File (File_Name_Str);
begin
if not Arg.Check_Only.Get then
Put_Line ("Resolving " & File_Name_Str);
Put_Line ((File_Name_Str'Length + 10) * "=");
end if;

if Unit.Diagnostics'Length > 0 then
for Diagnostic of Unit.Diagnostics loop
Print_Diagnostic
Expand Down
26 changes: 16 additions & 10 deletions contrib/lkt/extensions/src/liblktlang-implementation-extensions.adb
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,24 @@ package body Liblktlang.Implementation.Extensions is
function Decl_Short_Image (Node : Bare_Decl) return Text_Type is
Full_Name_Acc : String_Type := Dispatcher_Decl_P_Full_Name (Node);
Full_Name : constant Text_Type := Full_Name_Acc.Content;
File_Name : constant Text_Type :=
To_Text (Ada.Directories.Simple_Name (Get_Filename (Unit (Node))));
begin
Dec_Ref (Full_Name_Acc);
return
"<" & To_Text (Kind_Name (Node)) & " """ & Full_Name & """ "
& To_Text (Ada.Directories.Simple_Name (Get_Filename (Unit (Node))))

-- Don't show the sloc for function types, because it will be the root
-- node's sloc, and thus will always change when we add stuff to the
-- file, which is not helpful nor practical for tests.
& (if Node.Kind = Lkt_Function_Type
then ""
else ":" & To_Text (Image (Sloc_Range (Node)))) & ">";
if File_Name = "__prelude" then
return "<" & To_Text (Kind_Name (Node))
& " prelude: """ & Full_Name & """>";
else
return "<" & To_Text (Kind_Name (Node)) & " """ & Full_Name & """ "
& File_Name

-- Don't show the sloc for function types, because it will be the
-- root node's sloc, and thus will always change when we add stuff
-- to the file, which is not helpful nor practical for tests.
& (if Node.Kind = Lkt_Function_Type
then ""
else ":" & To_Text (Image (Sloc_Range (Node)))) & ">";
end if;
end Decl_Short_Image;

--------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions contrib/lkt/language/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,17 @@ def assert_bare():
PropertyError(T.Decl, "Type decl has rebindings but shouldn't")
)

@langkit_property(public=True)
def as_bare_decl():
"""
Get this declaration without rebindings information.
"""
# This is used by lkt_toolbox as a simple solution to filter out
# rebindings information for the prelude declarations. TODO: improve it
# in order to properly show rebindings information for prelude
# declarations (i.e. do not show sloc nor unit name).
return Entity.node.as_bare_entity

@langkit_property()
def call_scope():
"""
Expand Down
87 changes: 0 additions & 87 deletions contrib/lkt/lkt_resolve.py

This file was deleted.

4 changes: 2 additions & 2 deletions support/langkit_support-diagnostics-output.adb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ package body Langkit_Support.Diagnostics.Output is

Line_Nb : constant Positive := Positive (Sloc_Range.Start_Line);
Start_Offset : constant Positive := Positive (Sloc_Range.Start_Column);
End_Offset : constant Positive := Positive (Sloc_Range.End_Column);
End_Offset : constant Positive := Positive (Sloc_Range.End_Column) - 1;

Line_Nb_Width : constant Positive :=
Positive'Image (Line_Nb + Lines_After)'Length - 1;
Expand Down Expand Up @@ -96,7 +96,7 @@ package body Langkit_Support.Diagnostics.Output is
declare
Caret_Line : Text_Type (1 .. End_Offset) := (others => ' ');
begin
Caret_Line (Start_Offset .. End_Offset - 1) := (others => '^');
Caret_Line (Start_Offset .. End_Offset) := (others => '^');
Put_Line (Output_File, Caret_Line);
end;
Reset_Colors;
Expand Down
19 changes: 0 additions & 19 deletions testsuite/drivers/lkt_resolve_driver.py

This file was deleted.

12 changes: 12 additions & 0 deletions testsuite/drivers/lkt_toolbox_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from drivers.base_driver import BaseDriver


class LktToolboxDriver(BaseDriver):
"""
Custom driver that will automatically run the "lkt_toolbox" utility
on the testcase's "test.lkt" file.
"""

def run(self):
self.run_and_check(['lkt_toolbox', 'test.lkt'],
memcheck=True, for_coverage=True)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Resolving test.lkt
==================
test.lkt:4:9: error: ambiguous type for expression
3 | val a = "hello"
4 | val a = "hello"
| ^^^^^^^

Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ Id <RefId "String" test.lkt:13:57-13:63>
references <StructDecl prelude: "String">

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

32 changes: 16 additions & 16 deletions testsuite/tests/contrib/lkt_semantic/array_type_concrete/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ Expr <RefId "bar" test.lkt:17:27-17:30>
has type <FunctionType prelude: "() -> String">

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

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

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

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

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

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

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

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

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

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

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

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

Loading

0 comments on commit 9d665ee

Please sign in to comment.