Skip to content

Commit

Permalink
Eat your own dog food - rewrites for if expression + additional simpl…
Browse files Browse the repository at this point in the history
…ification
  • Loading branch information
pjljvandelaar committed Jan 10, 2023
1 parent 458c581 commit d504c06
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 63 deletions.
19 changes: 9 additions & 10 deletions src/rejuvenation-factory.adb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ package body Rejuvenation.Factory is
(Context : Project_Context; Recursive : Boolean := True)
return Analysis_Unit_Vectors.Vector
is
Files : File_Array renames
Files :
File_Array renames
Context.Project_Tree.Root_Project.Source_Files
(Recursive => Recursive).all;
Results : Analysis_Unit_Vectors.Vector;
Expand All @@ -67,15 +68,13 @@ package body Rejuvenation.Factory is
Info : constant File_Info :=
Context.Project_Tree.Info (Create (+Filename));
begin
if Recursive then
return
Info.Language = "ada" and then Info.Project /= No_Project
and then not Info.Project.Externally_Built;
else
return
Info.Language = "ada"
and then Info.Project = Context.Project_Tree.Root_Project;
end if;
return
Info.Language = "ada"
and then
(if Recursive then
Info.Project /= No_Project
and then not Info.Project.Externally_Built
else Info.Project = Context.Project_Tree.Root_Project);
end Is_Ada_File_Built_By_Project;

function Is_Project_Main_Program
Expand Down
10 changes: 4 additions & 6 deletions src/rejuvenation-indentation.adb
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ package body Rejuvenation.Indentation is
Pos : constant Natural :=
Index (Token_Text, (1 => ASCII.LF), Going => Backward);
begin
if Pos = 0 then
return
return
(if Pos = 0 then
Indentatation_Of_Token
(Previous (Token), Nr + Token_Text'Length);
else
return Nr + Token_Text'Last - Pos;
end if;
(Previous (Token), Nr + Token_Text'Length)
else Nr + Token_Text'Last - Pos);
end;
else
return No_Indentation;
Expand Down
18 changes: 8 additions & 10 deletions src/rejuvenation-match_patterns.adb
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,10 @@ package body Rejuvenation.Match_Patterns is
-- we select a unique [shallow] representation
function Disambiguate_Node (Node : Ada_Node) return Ada_Node is
begin
if Node.Is_Null or else Node.Kind not in Ada_Defining_Name then
return Node;
else
return Node.First_Child;
end if;
return
(if Node.Is_Null or else Node.Kind not in Ada_Defining_Name then
Node
else Node.First_Child);
end Disambiguate_Node;

Placeholder_Name : constant String := Get_Placeholder_Name (Pattern);
Expand All @@ -524,11 +523,10 @@ package body Rejuvenation.Match_Patterns is
function filter (Node : Ada_Node) return Ada_Node_Array;
function filter (Node : Ada_Node) return Ada_Node_Array is
begin
if Node.Kind = Ada_Composite_Constraint then
return Node.As_Composite_Constraint.F_Constraints.Children;
else
return (1 => Node);
end if;
return
(if Node.Kind = Ada_Composite_Constraint then
Node.As_Composite_Constraint.F_Constraints.Children
else (1 => Node));
end filter;

function Match_Specific
Expand Down
52 changes: 22 additions & 30 deletions src/rejuvenation-node_locations.adb
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ package body Rejuvenation.Node_Locations is
Pos : constant Natural :=
Index (Token_Text, (1 => ASCII.LF), Going => Backward);
begin
if Pos = 0 then
return
return
(if Pos = 0 then
Line_Start_Offset
(Previous (Token), Offset - Token_Text'Length);
else
return
Raw_Data (Token).Source_First + Pos + 1 - Token_Text'First;
end if;
(Previous (Token), Offset - Token_Text'Length)
else Raw_Data (Token).Source_First + Pos + 1 -
Token_Text'First);
end;
else
return Offset;
Expand All @@ -67,15 +65,14 @@ package body Rejuvenation.Node_Locations is
(Token : Token_Reference; Nr : Integer) return Integer
is
begin
if Token /= No_Token
and then Kind (Data (Token)) in Ada_Whitespace | Ada_Comment
then
return
return
(if
Token /= No_Token
and then Kind (Data (Token)) in Ada_Whitespace | Ada_Comment
then
Trivia_Start_Offset
(Previous (Token), Raw_Data (Token).Source_First);
else
return Nr;
end if;
(Previous (Token), Raw_Data (Token).Source_First)
else Nr);
end Trivia_Start_Offset;

begin
Expand Down Expand Up @@ -130,13 +127,10 @@ package body Rejuvenation.Node_Locations is
Encode (Text (Token), Node.Unit.Get_Charset);
Pos : constant Natural := Index (Token_Text, (1 => ASCII.LF));
begin
if Pos = 0 then
return
Line_End_Offset (Next (Token), Offset + Token_Text'Length);
else
return
Raw_Data (Token).Source_First + Pos - Token_Text'First;
end if;
return
(if Pos = 0 then
Line_End_Offset (Next (Token), Offset + Token_Text'Length)
else Raw_Data (Token).Source_First + Pos - Token_Text'First);
end;
else
return Offset;
Expand All @@ -157,14 +151,12 @@ package body Rejuvenation.Node_Locations is
(Token : Token_Reference; Nr : Natural) return Natural
is
begin
if Token /= No_Token
and then Kind (Data (Token)) in Ada_Whitespace | Ada_Comment
then
return
Trivia_End_Offset (Next (Token), Raw_Data (Token).Source_Last);
else
return Nr;
end if;
return
(if
Token /= No_Token
and then Kind (Data (Token)) in Ada_Whitespace | Ada_Comment
then Trivia_End_Offset (Next (Token), Raw_Data (Token).Source_Last)
else Nr);
end Trivia_End_Offset;

begin
Expand Down
11 changes: 4 additions & 7 deletions src/rejuvenation-string_utils.adb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ is
Location : constant Natural :=
Index (Source => Source, Pattern => Pattern);
begin
if Location = 0 then
return Source;
else
return
Source (Source'First .. Location - 1) & Replacement &
return
(if Location = 0 then Source
else Source (Source'First .. Location - 1) & Replacement &
Replace_All
(Source (Location + Pattern'Length .. Source'Last), Pattern,
Replacement);
end if;
Replacement));
end Replace_All;

end Rejuvenation.String_Utils;

0 comments on commit d504c06

Please sign in to comment.