Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefer if expressions #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions gpr/src/gpr-ali.adb
Original file line number Diff line number Diff line change
Expand Up @@ -1288,11 +1288,9 @@ package body GPR.ALI is

Get_Name_String (Units.Table (Units.Last).Uname);

if Name_Buffer (Name_Len) = 'b' then
Units.Table (Units.Last).Utype := Is_Body_Only;
else
Units.Table (Units.Last).Utype := Is_Spec_Only;
end if;
Units.Table (Units.Last).Utype :=
(if Name_Buffer (Name_Len) = 'b' then Is_Body_Only
else Is_Spec_Only);
end if;

-- Ignore external version lines
Expand Down Expand Up @@ -1434,13 +1432,12 @@ package body GPR.ALI is
if C = EOF then
-- Check that gnatprove generated .ali files ended with right marker

if Opt.GnatProve_Mode
and then T (First_P .. Last_P) /= Spark_End_Marker
then
return No_ALI_Id;
end if;

return Id;
return
(if
Opt.GnatProve_Mode
and then T (First_P .. Last_P) /= Spark_End_Marker
then No_ALI_Id
else Id);
end if;

Check_Unknown_Line;
Expand Down
104 changes: 40 additions & 64 deletions gpr/src/gpr-attr.adb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ package body GPR.Attr is
(Attribute : Attribute_Node_Id) return Attribute_Default_Value
is
begin
if Attribute = Empty_Attribute then
return Empty_Value;
else
return Attrs.Table (Attribute.Value).Default;
end if;
return
(if Attribute = Empty_Attribute then Empty_Value
else Attrs.Table (Attribute.Value).Default);
end Attribute_Default_Of;

-----------------------
Expand All @@ -90,11 +88,9 @@ package body GPR.Attr is
(Attribute : Attribute_Node_Id) return Attribute_Kind
is
begin
if Attribute = Empty_Attribute then
return Unknown;
else
return Attrs.Table (Attribute.Value).Attr_Kind;
end if;
return
(if Attribute = Empty_Attribute then Unknown
else Attrs.Table (Attribute.Value).Attr_Kind);
end Attribute_Kind_Of;

-----------------------
Expand All @@ -103,11 +99,9 @@ package body GPR.Attr is

function Attribute_Name_Of (Attribute : Attribute_Node_Id) return Name_Id is
begin
if Attribute = Empty_Attribute then
return No_Name;
else
return Attrs.Table (Attribute.Value).Name;
end if;
return
(if Attribute = Empty_Attribute then No_Name
else Attrs.Table (Attribute.Value).Name);
end Attribute_Name_Of;

--------------------------
Expand Down Expand Up @@ -213,14 +207,12 @@ package body GPR.Attr is

function Attribute_Location return String is
begin
if Current_Package = Empty_Pkg then
return "project level attributes";

else
return "attribute of package """
& Get_Name_String
(Package_Attributes.Table (Current_Package).Name) & '"';
end if;
return
(if Current_Package = Empty_Pkg then "project level attributes"
else "attribute of package """ &
Get_Name_String
(Package_Attributes.Table (Current_Package).Name) &
'"');
end Attribute_Location;

-----------------
Expand Down Expand Up @@ -1427,11 +1419,9 @@ package body GPR.Attr is
return Boolean
is
begin
if Attribute = Empty_Attribute then
return False;
else
return Attrs.Table (Attribute.Value).Config_Concat;
end if;
return
(Attribute /= Empty_Attribute)
and then Attrs.Table (Attribute.Value).Config_Concat;
end Is_Config_Concatenable;

------------------
Expand All @@ -1451,11 +1441,9 @@ package body GPR.Attr is
(After : Attribute_Node_Id) return Attribute_Node_Id
is
begin
if After = Empty_Attribute then
return Empty_Attribute;
else
return (Value => Attrs.Table (After.Value).Next);
end if;
return
(if After = Empty_Attribute then Empty_Attribute
else (Value => Attrs.Table (After.Value).Next));
end Next_Attribute;

-----------------------
Expand All @@ -1464,22 +1452,18 @@ package body GPR.Attr is

function Optional_Index_Of (Attribute : Attribute_Node_Id) return Boolean is
begin
if Attribute = Empty_Attribute then
return False;
else
return Attrs.Table (Attribute.Value).Optional_Index;
end if;
return
(Attribute /= Empty_Attribute)
and then Attrs.Table (Attribute.Value).Optional_Index;
end Optional_Index_Of;

function Others_Allowed_For
(Attribute : Attribute_Node_Id) return Boolean
is
begin
if Attribute = Empty_Attribute then
return False;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example where if expression is even simplified away!

else
return Attrs.Table (Attribute.Value).Others_Allowed;
end if;
return
(Attribute /= Empty_Attribute)
and then Attrs.Table (Attribute.Value).Others_Allowed;
end Others_Allowed_For;

-----------------------
Expand All @@ -1499,11 +1483,9 @@ package body GPR.Attr is
begin
for Index in Package_Attributes.First .. Package_Attributes.Last loop
if Package_Attributes.Table (Index).Name = Name then
if Package_Attributes.Table (Index).Known then
return (Value => Index);
else
return Unknown_Package;
end if;
return
(if Package_Attributes.Table (Index).Known then (Value => Index)
else Unknown_Package);
end if;
end loop;

Expand Down Expand Up @@ -1810,11 +1792,9 @@ package body GPR.Attr is
(Attribute : Attribute_Node_Id) return Variable_Kind
is
begin
if Attribute = Empty_Attribute then
return Undefined;
else
return Attrs.Table (Attribute.Value).Var_Kind;
end if;
return
(if Attribute = Empty_Attribute then Undefined
else Attrs.Table (Attribute.Value).Var_Kind);
end Variable_Kind_Of;

------------------------
Expand All @@ -1825,12 +1805,10 @@ package body GPR.Attr is
(Pkg : Package_Node_Id) return Attribute_Node_Id
is
begin
if Pkg = Empty_Package or else Pkg = Unknown_Package then
return Empty_Attribute;
else
return
(Value => Package_Attributes.Table (Pkg.Value).First_Attribute);
end if;
return
(if Pkg = Empty_Package or else Pkg = Unknown_Package then
Empty_Attribute
else (Value => Package_Attributes.Table (Pkg.Value).First_Attribute));
end First_Attribute_Of;

----------------------
Expand All @@ -1839,11 +1817,9 @@ package body GPR.Attr is

function Is_Package_Known (Pkg : Package_Node_Id) return Boolean is
begin
if Pkg = Empty_Package or else Pkg = Unknown_Package then
return False;
else
return Package_Attributes.Table (Pkg.Value).Known;
end if;
return
not (Pkg = Empty_Package or else Pkg = Unknown_Package)
and then Package_Attributes.Table (Pkg.Value).Known;
end Is_Package_Known;

end GPR.Attr;
24 changes: 8 additions & 16 deletions gpr/src/gpr-compilation-process.adb
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,7 @@ package body GPR.Compilation.Process is

function Get_Slave_For (Pid : Id) return String is
begin
if Pid.Kind = Local then
return "";

else
return Results.Get_Slave_For (Pid);
end if;
return (if Pid.Kind = Local then "" else Results.Get_Slave_For (Pid));
end Get_Slave_For;

----------
Expand All @@ -165,11 +160,10 @@ package body GPR.Compilation.Process is
function Hash (Process : Id) return Header_Num is
Modulo : constant Integer := Integer (Header_Num'Last) + 1;
begin
if Process.Kind = Local then
return Header_Num (Pid_To_Integer (Process.Pid) mod Modulo);
else
return Header_Num (Process.R_Pid mod Remote_Id (Modulo));
end if;
return
(if Process.Kind = Local then
Header_Num (Pid_To_Integer (Process.Pid) mod Modulo)
else Header_Num (Process.R_Pid mod Remote_Id (Modulo)));
end Hash;

------------------------
Expand Down Expand Up @@ -234,11 +228,9 @@ package body GPR.Compilation.Process is
use type Failures_Slave_Set.Cursor;
Pos : constant Failures_Slave_Set.Cursor := Failed_Proc.Find (Pid);
begin
if Pos = Failures_Slave_Set.No_Element then
return "";
else
return Failures_Slave_Set.Element (Pos);
end if;
return
(if Pos = Failures_Slave_Set.No_Element then ""
else Failures_Slave_Set.Element (Pos));
end Get_Slave_For;

---------------------------
Expand Down
43 changes: 17 additions & 26 deletions gpr/src/gpr-compilation-protocol.adb
Original file line number Diff line number Diff line change
Expand Up @@ -467,18 +467,15 @@ package body GPR.Compilation.Protocol is
Timestamp := Time_Stamp_Type (Line.Args (5).all);
Version := To_Unbounded_String (Line.Args (6).all);

if Line.Args'Length > 6 then
Hash := To_Unbounded_String (Line.Args (7).all);
else
Hash := Null_Unbounded_String;
end if;
Hash :=
(if Line.Args'Length > 6 then
To_Unbounded_String (Line.Args (7).all)
else Null_Unbounded_String);

if Line.Args'Length > 7 then
Included_Artifact_Patterns :=
To_Unbounded_String (Line.Args (8).all);
else
Included_Artifact_Patterns := Null_Unbounded_String;
end if;
Included_Artifact_Patterns :=
(if Line.Args'Length > 7 then
To_Unbounded_String (Line.Args (8).all)
else Null_Unbounded_String);

elsif Line.Cmd = PG then
Is_Ping := True;
Expand Down Expand Up @@ -1244,15 +1241,11 @@ package body GPR.Compilation.Protocol is
is
P : constant Natural := Index (Str, To_String (Channel.WD_To));
begin
if P = 0 then
return Str;

else
-- Make sure we translate the filename to native directory seprator
return To_Native_Directory_Separator
(To_String (Channel.WD_From)
& Str (P + Length (Channel.WD_To) .. Str'Last));
end if;
return
(if P = 0 then Str
else To_Native_Directory_Separator
(To_String (Channel.WD_From) &
Str (P + Length (Channel.WD_To) .. Str'Last)));
end Translate_Receive;

--------------------
Expand All @@ -1264,12 +1257,10 @@ package body GPR.Compilation.Protocol is
is
P : constant Natural := Index (Str, To_String (Channel.WD_From));
begin
if P = 0 then
return Str;
else
return To_String (Channel.WD_To)
& Str (P + Length (Channel.WD_From) .. Str'Last);
end if;
return
(if P = 0 then Str
else To_String (Channel.WD_To) &
Str (P + Length (Channel.WD_From) .. Str'Last));
end Translate_Send;

end GPR.Compilation.Protocol;
29 changes: 11 additions & 18 deletions gpr/src/gpr-compilation-slave.adb
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,7 @@ package body GPR.Compilation.Slave is
function Channel (Host : String) return Protocol.Communication_Channel is
S : constant Slave := Slaves.Find (Host);
begin
if S = No_Slave then
return No_Channel;
else
return S.Channel;
end if;
return (if S = No_Slave then No_Channel else S.Channel);
end Channel;

----------------------------
Expand Down Expand Up @@ -538,14 +534,13 @@ package body GPR.Compilation.Slave is
RD : constant String :=
Get_Name_String (V.Value.Value);
begin
if Is_Absolute_Path (RD) then
Root_Dir := To_Unbounded_String (RD);
else
Root_Dir := To_Unbounded_String
(Normalize_Pathname
(To_String (Root_Dir)
& Directory_Separator & RD));
end if;
Root_Dir :=
(if Is_Absolute_Path (RD) then
To_Unbounded_String (RD)
else To_Unbounded_String
(Normalize_Pathname
(To_String (Root_Dir) &
Directory_Separator & RD)));

if not Exists (To_String (Root_Dir))
or else not Is_Directory (To_String (Root_Dir))
Expand Down Expand Up @@ -835,11 +830,9 @@ package body GPR.Compilation.Slave is
S : constant Slave := (Sock => Socket, others => <>);
Position : constant Slave_S.Cursor := Pool.Find (S);
begin
if Slave_S.Has_Element (Position) then
return Slave_S.Element (Position);
else
return No_Slave;
end if;
return
(if Slave_S.Has_Element (Position) then Slave_S.Element (Position)
else No_Slave);
end Find;

function Find (Host : String) return Slave is
Expand Down
Loading