Skip to content

Commit

Permalink
Merge branch 'topic/lal_refactor.13.nameres_failures' into 'master'
Browse files Browse the repository at this point in the history
Return Ref_Result_Kind result for a better handling of Error

See merge request eng/ide/libadalang-tools!190
  • Loading branch information
AdrienBoulanger committed Mar 27, 2024
2 parents 54178e0 + e4a3a77 commit 2b65089
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
26 changes: 12 additions & 14 deletions src/laltools-common.adb
Original file line number Diff line number Diff line change
Expand Up @@ -2706,15 +2706,16 @@ package body Laltools.Common is
Trace : GNATCOLL.Traces.Trace_Handle;
Imprecise : in out Boolean) return Boolean
is
Definition : Defining_Name;
This_Imprecise : Boolean := False;
Definition : Defining_Name;
Ref_Kind : Libadalang.Common.Ref_Result_Kind;
begin
if Node.As_Ada_Node /= No_Ada_Node
and then Node.Kind in Ada_Name
then
Definition := Laltools.Common.Resolve_Name
(Node.As_Name, Trace, This_Imprecise);
Imprecise := Imprecise or This_Imprecise;
(Node.As_Name, Trace, Ref_Kind);
Imprecise :=
Ref_Kind in Libadalang.Common.Error | Libadalang.Common.Imprecise;
return Definition /= No_Defining_Name
and then Definition.P_Basic_Decl.Kind =
Ada_Enum_Literal_Decl;
Expand Down Expand Up @@ -2942,13 +2943,12 @@ package body Laltools.Common is
function Resolve_Name
(Name_Node : Name;
Trace : GNATCOLL.Traces.Trace_Handle;
Imprecise : out Boolean) return Defining_Name
Ref_Kind : out Libadalang.Common.Ref_Result_Kind) return Defining_Name
is
Result : Defining_Name;
Result : Defining_Name;
Failsafe_Result : Refd_Def;
begin
Imprecise := False;

Ref_Kind := Precise;
if Name_Node.Is_Null then
return No_Defining_Name;
-- P_Failsafe_Referenced_Def_Name doesn't work on the decl itself
Expand All @@ -2957,14 +2957,12 @@ package body Laltools.Common is
else
Failsafe_Result := Name_Node.P_Failsafe_Referenced_Def_Name
(Imprecise_Fallback => True);
Ref_Kind := Kind (Failsafe_Result);
case Kind (Failsafe_Result) is
when Precise =>
-- Nothing extra to do here
when Precise | Imprecise =>
-- Nothing extra to do here
null;
when Libadalang.Common.Imprecise =>
Imprecise := True;
when Error =>
Imprecise := True;
return No_Defining_Name;
when No_Ref =>
return No_Defining_Name;
Expand All @@ -2982,7 +2980,7 @@ package body Laltools.Common is
exception
when E : Property_Error =>
Log (Trace, E);
Imprecise := True;
Ref_Kind := Error;
return No_Defining_Name;
end Resolve_Name;

Expand Down
4 changes: 1 addition & 3 deletions src/laltools-common.ads
Original file line number Diff line number Diff line change
Expand Up @@ -832,11 +832,9 @@ package Laltools.Common is
function Resolve_Name
(Name_Node : Name;
Trace : GNATCOLL.Traces.Trace_Handle;
Imprecise : out Boolean)
Ref_Kind : out Libadalang.Common.Ref_Result_Kind)
return Defining_Name;
-- Return the definition node (canonical part) of the given name.
-- Imprecise is set to True if LAL has marked the result as imprecise or
-- if an error happened.

function Resolve_Name_Precisely (Name_Node : Name) return Defining_Name;
-- Return the definition node (canonical part) of the given name.
Expand Down

0 comments on commit 2b65089

Please sign in to comment.