[Ada] Simplify detection of static membership choices

Message ID 20200610133540.GA80625@adacore.com
State New
Headers show
Series
  • [Ada] Simplify detection of static membership choices
Related show

Commit Message

Pierre-Marie de Rodat June 10, 2020, 1:35 p.m.
Membership test operators (i.e. "in" and "not in") have either the right
operand present (when there is just one choice) or the list of
alternatives present (when there are many choices), as documented in
sinfo.ads.

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

2020-06-10  Piotr Trojanek  <trojanek@adacore.com>

gcc/ada/

	* sem_ch13.adb (All_Membership_Choices_Static): Assert an AST
	property documented in sinfo.ads and simplify an excessive
	condition.

Patch

--- gcc/ada/sem_ch13.adb
+++ gcc/ada/sem_ch13.adb
@@ -844,11 +844,16 @@  package body Sem_Ch13 is
    function All_Membership_Choices_Static (Expr : Node_Id) return Boolean is
       pragma Assert (Nkind (Expr) in N_Membership_Test);
    begin
-      return ((Present (Right_Opnd (Expr))
-              and then Is_Static_Choice (Right_Opnd (Expr)))
-            or else
-              (Present (Alternatives (Expr))
-              and then All_Static_Choices (Alternatives (Expr))));
+      pragma Assert
+        (Present (Right_Opnd (Expr))
+           xor
+         Present (Alternatives (Expr)));
+
+      if Present (Right_Opnd (Expr)) then
+         return Is_Static_Choice (Right_Opnd (Expr));
+      else
+         return All_Static_Choices (Alternatives (Expr));
+      end if;
    end All_Membership_Choices_Static;
 
    ------------------------