mirror of
https://github.com/AdaCore/langkit.git
synced 2026-02-12 12:28:12 -08:00
Generic API: bind the Lookup function for nodes
This commit is contained in:
@@ -1149,6 +1149,22 @@ package body Langkit_Support.Generic_API.Analysis is
|
||||
return Self.Desc.Node_Sloc_Range (Self.Internal.Node);
|
||||
end Sloc_Range;
|
||||
|
||||
------------
|
||||
-- Lookup --
|
||||
------------
|
||||
|
||||
function Lookup
|
||||
(Self : Lk_Node'Class; Sloc : Source_Location) return Lk_Node is
|
||||
begin
|
||||
Check_Safety_Net (Self);
|
||||
if Self.Is_Null then
|
||||
return No_Lk_Node;
|
||||
end if;
|
||||
|
||||
return Wrap_Node
|
||||
(Self.Desc.Node_Lookup (Self.Internal.Node, Sloc), Self);
|
||||
end Lookup;
|
||||
|
||||
-------------------
|
||||
-- Is_Incomplete --
|
||||
-------------------
|
||||
|
||||
@@ -333,6 +333,12 @@ package Langkit_Support.Generic_API.Analysis is
|
||||
--
|
||||
-- Note that this returns the sloc of the parent for synthetic nodes.
|
||||
|
||||
function Lookup
|
||||
(Self : Lk_Node'Class; Sloc : Source_Location) return Lk_Node;
|
||||
-- Look for the bottom-most node in the ``Self`` subtree whose sloc range
|
||||
-- contains ``Sloc``. Return it, or ``No_Lk_Node`` if no such node was
|
||||
-- found.
|
||||
|
||||
-- TODO??? Bind all other node primitives
|
||||
|
||||
function Is_Incomplete (Self : Lk_Node) return Boolean;
|
||||
|
||||
@@ -109,6 +109,9 @@ package Langkit_Support.Internal.Descriptor is
|
||||
(Node : Analysis.Internal_Node) return Text_Type;
|
||||
type Node_Sloc_Range_Type is access function
|
||||
(Node : Analysis.Internal_Node) return Source_Location_Range;
|
||||
type Node_Lookup_Type is access function
|
||||
(Node : Analysis.Internal_Node;
|
||||
Sloc : Source_Location) return Analysis.Internal_Node;
|
||||
type Node_Last_Attempted_Child_Type is access function
|
||||
(Node : Analysis.Internal_Node) return Integer;
|
||||
|
||||
@@ -217,6 +220,7 @@ package Langkit_Support.Internal.Descriptor is
|
||||
Node_Token_End : Node_Token_Getter_Type;
|
||||
Node_Text : Node_Text_Type;
|
||||
Node_Sloc_Range : Node_Sloc_Range_Type;
|
||||
Node_Lookup : Node_Lookup_Type;
|
||||
Node_Last_Attempted_Child : Node_Last_Attempted_Child_Type;
|
||||
|
||||
Entity_Image : Entity_Image_Type;
|
||||
|
||||
@@ -465,6 +465,17 @@ package body ${ada_lib_name}.Generic_Impl is
|
||||
return Implementation.Sloc_Range (+Node);
|
||||
end Node_Sloc_Range;
|
||||
|
||||
-----------------
|
||||
-- Node_Lookup --
|
||||
-----------------
|
||||
|
||||
function Node_Lookup
|
||||
(Node : Analysis.Internal_Node;
|
||||
Sloc : Source_Location) return Analysis.Internal_Node is
|
||||
begin
|
||||
return +Implementation.Lookup (+Node, Sloc);
|
||||
end Node_Lookup;
|
||||
|
||||
-------------------------------
|
||||
-- Node_Last_Attempted_Child --
|
||||
-------------------------------
|
||||
|
||||
@@ -180,6 +180,9 @@ private package ${ada_lib_name}.Generic_Impl is
|
||||
function Node_Text (Node : Internal_Node) return Text_Type;
|
||||
function Node_Sloc_Range
|
||||
(Node : Internal_Node) return Source_Location_Range;
|
||||
function Node_Lookup
|
||||
(Node : Analysis.Internal_Node;
|
||||
Sloc : Source_Location) return Analysis.Internal_Node;
|
||||
function Node_Last_Attempted_Child (Node : Internal_Node) return Integer;
|
||||
|
||||
function Entity_Image (Entity : Internal_Entity) return String;
|
||||
@@ -267,6 +270,7 @@ private package ${ada_lib_name}.Generic_Impl is
|
||||
Node_Token_End => Node_Token_End'Access,
|
||||
Node_Text => Node_Text'Access,
|
||||
Node_Sloc_Range => Node_Sloc_Range'Access,
|
||||
Node_Lookup => Node_Lookup'Access,
|
||||
Node_Last_Attempted_Child => Node_Last_Attempted_Child'Access,
|
||||
|
||||
Entity_Image => Entity_Image'Access,
|
||||
|
||||
@@ -330,6 +330,11 @@ begin
|
||||
end;
|
||||
New_Line;
|
||||
|
||||
Put_Line
|
||||
("No_Lk_Node.Lookup (1, 1) -> " & Image (No_Lk_Node.Lookup ((1, 1))));
|
||||
Put_Line ("Root.Lookup (2, 7) -> " & Image (U.Root.Lookup ((2, 7))));
|
||||
New_Line;
|
||||
|
||||
Put_Line ("Root.Is_Incomplete -> " & U.Root.Is_Incomplete'Image);
|
||||
Put ("No_Lk_Node.Is_Incomplete -> ");
|
||||
declare
|
||||
|
||||
@@ -151,6 +151,9 @@ No_Lk_Node.Text -> Got a Precondition_Failure exception: null node
|
||||
Root.Sloc_Range -> 1:1-3:15
|
||||
No_Lk_Node.Sloc_Range -> Got a Precondition_Failure exception: null node
|
||||
|
||||
No_Lk_Node.Lookup (1, 1) -> None
|
||||
Root.Lookup (2, 7) -> <VarDecl example.txt:2:1-2:11>
|
||||
|
||||
Root.Is_Incomplete -> FALSE
|
||||
No_Lk_Node.Is_Incomplete -> Got a Precondition_Failure exception: null node
|
||||
|
||||
|
||||
Reference in New Issue
Block a user