public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Simplify unit loading with membership tests
@ 2021-07-06 14:48 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2021-07-06 14:48 UTC (permalink / raw)
  To: gcc-patches; +Cc: Piotr Trojanek

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

Cleanup excessive whitespace and use membership tests in code related to
loading of compilation units; semantics is unaffected.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* lib-load.adb (Load_Unit): Remove excessive whitespace.
	* lib.adb (Is_Internal_Unit, Is_Predefined_Unit): Likewise.
	* par-ch10.adb (P_Compilation_Unit): Simplify with membership
	test.
	* par-load.adb (Load): Likewise.
	* uname.adb (Get_Unit_Name): Likewise.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 5571 bytes --]

diff --git a/gcc/ada/lib-load.adb b/gcc/ada/lib-load.adb
--- a/gcc/ada/lib-load.adb
+++ b/gcc/ada/lib-load.adb
@@ -396,14 +396,14 @@ package body Lib.Load is
    ---------------
 
    function Load_Unit
-     (Load_Name         : Unit_Name_Type;
-      Required          : Boolean;
-      Error_Node        : Node_Id;
-      Subunit           : Boolean;
-      Corr_Body         : Unit_Number_Type := No_Unit;
-      Renamings         : Boolean          := False;
-      With_Node         : Node_Id          := Empty;
-      PMES              : Boolean          := False) return Unit_Number_Type
+     (Load_Name  : Unit_Name_Type;
+      Required   : Boolean;
+      Error_Node : Node_Id;
+      Subunit    : Boolean;
+      Corr_Body  : Unit_Number_Type := No_Unit;
+      Renamings  : Boolean          := False;
+      With_Node  : Node_Id          := Empty;
+      PMES       : Boolean          := False) return Unit_Number_Type
    is
       Calling_Unit : Unit_Number_Type;
       Uname_Actual : Unit_Name_Type;


diff --git a/gcc/ada/lib.adb b/gcc/ada/lib.adb
--- a/gcc/ada/lib.adb
+++ b/gcc/ada/lib.adb
@@ -128,12 +128,12 @@ package body Lib is
       return Units.Table (U).Is_Predefined_Renaming;
    end Is_Predefined_Renaming;
 
-   function Is_Internal_Unit       (U : Unit_Number_Type) return Boolean is
+   function Is_Internal_Unit (U : Unit_Number_Type) return Boolean is
    begin
       return Units.Table (U).Is_Internal_Unit;
    end Is_Internal_Unit;
 
-   function Is_Predefined_Unit     (U : Unit_Number_Type) return Boolean is
+   function Is_Predefined_Unit (U : Unit_Number_Type) return Boolean is
    begin
       return Units.Table (U).Is_Predefined_Unit;
    end Is_Predefined_Unit;
@@ -482,18 +482,12 @@ package body Lib is
          --  body of the same unit. The location in the spec is considered
          --  earlier.
 
-         if Nkind (Unit1) = N_Subprogram_Body
-              or else
-            Nkind (Unit1) = N_Package_Body
-         then
+         if Nkind (Unit1) in N_Subprogram_Body | N_Package_Body then
             if Library_Unit (Cunit (Unum1)) = Cunit (Unum2) then
                return Yes_After;
             end if;
 
-         elsif Nkind (Unit2) = N_Subprogram_Body
-                 or else
-               Nkind (Unit2) = N_Package_Body
-         then
+         elsif Nkind (Unit2) in N_Subprogram_Body | N_Package_Body then
             if Library_Unit (Cunit (Unum2)) = Cunit (Unum1) then
                return Yes_Before;
             end if;


diff --git a/gcc/ada/par-ch10.adb b/gcc/ada/par-ch10.adb
--- a/gcc/ada/par-ch10.adb
+++ b/gcc/ada/par-ch10.adb
@@ -555,7 +555,7 @@ package body Ch10 is
                                   | N_Generic_Function_Renaming_Declaration
                                   | N_Generic_Package_Renaming_Declaration
                                   | N_Generic_Procedure_Renaming_Declaration
-          or else Nkind (Unit_Node) in N_Package_Body
+                                  | N_Package_Body
                                   | N_Package_Instantiation
                                   | N_Package_Renaming_Declaration
                                   | N_Package_Specification


diff --git a/gcc/ada/par-load.adb b/gcc/ada/par-load.adb
--- a/gcc/ada/par-load.adb
+++ b/gcc/ada/par-load.adb
@@ -182,14 +182,8 @@ begin
       --  Check for predefined file case
 
       if Name_Len > 1
+        and then Name_Buffer (1) in 'a' | 's' | 'i' | 'g'
         and then Name_Buffer (2) = '-'
-        and then (Name_Buffer (1) = 'a'
-                    or else
-                  Name_Buffer (1) = 's'
-                    or else
-                  Name_Buffer (1) = 'i'
-                    or else
-                  Name_Buffer (1) = 'g')
       then
          declare
             Expect_Name : constant Unit_Name_Type := Expected_Unit (Cur_Unum);
@@ -248,9 +242,7 @@ begin
 
    --  If current unit is a body, load its corresponding spec
 
-   if Nkind (Unit (Curunit)) = N_Package_Body
-     or else Nkind (Unit (Curunit)) = N_Subprogram_Body
-   then
+   if Nkind (Unit (Curunit)) in N_Package_Body | N_Subprogram_Body then
       Spec_Name := Get_Spec_Name (Unit_Name (Cur_Unum));
       Unum :=
         Load_Unit
@@ -304,11 +296,11 @@ begin
    --  If current unit is a child unit spec, load its parent. If the child unit
    --  is loaded through a limited with, the parent must be as well.
 
-   elsif     Nkind (Unit (Curunit)) =  N_Package_Declaration
-     or else Nkind (Unit (Curunit)) =  N_Subprogram_Declaration
-     or else Nkind (Unit (Curunit)) in N_Generic_Declaration
-     or else Nkind (Unit (Curunit)) in N_Generic_Instantiation
-     or else Nkind (Unit (Curunit)) in N_Renaming_Declaration
+   elsif Nkind (Unit (Curunit)) in N_Package_Declaration
+                                 | N_Subprogram_Declaration
+                                 | N_Generic_Declaration
+                                 | N_Generic_Instantiation
+                                 | N_Renaming_Declaration
    then
       --  Turn style checks off for parent unit
 


diff --git a/gcc/ada/uname.adb b/gcc/ada/uname.adb
--- a/gcc/ada/uname.adb
+++ b/gcc/ada/uname.adb
@@ -367,8 +367,8 @@ package body Uname is
          Node := Declaration_Node (Entity (Node));
       end if;
 
-      if Nkind (Node) = N_Package_Specification
-        or else Nkind (Node) in N_Subprogram_Specification
+      if Nkind (Node) in N_Package_Specification
+                       | N_Subprogram_Specification
       then
          Node := Parent (Node);
       end if;



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-06 14:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 14:48 [Ada] Simplify unit loading with membership tests Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).