diff options
author | Piotr Trojanek <trojanek@adacore.com> | 2022-05-20 09:41:30 +0200 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2022-06-02 09:06:45 +0000 |
commit | b05a31e579ec2e46c46c4b3f36fffdf0e959bd1f (patch) | |
tree | fccac0415278884fdcc26f23e557960b669f4d79 /gcc/ada/exp_ch5.adb | |
parent | 89e037d0e36654e84823c47980ef19dc0f77b8ce (diff) | |
download | gcc-b05a31e579ec2e46c46c4b3f36fffdf0e959bd1f.zip gcc-b05a31e579ec2e46c46c4b3f36fffdf0e959bd1f.tar.gz gcc-b05a31e579ec2e46c46c4b3f36fffdf0e959bd1f.tar.bz2 |
[Ada] Remove redundant checks for missing lists
When iterating over list elements with First/Next there is no need to
check if the list is present, because First intentionally returns Empty
if list is not present and the condition of subsequent loop will not be
satisfied.
Code cleanup; semantics is unaffected.
Occurrences of the redundant pattern were found with:
$ grep First -B 3 | less
and examining the output for the calls to Present.
gcc/ada/
* exp_ch13.adb, exp_ch5.adb, exp_ch9.adb, exp_strm.adb,
sem_ch10.adb, sem_ch13.adb, sem_ch5.adb, sem_ch6.adb,
sem_ch8.adb, sem_elab.adb, sem_eval.adb, sem_prag.adb,
sem_util.adb: Remove checks for the missing list before
iterating with First/Next; reindent code and refill comments.
Diffstat (limited to 'gcc/ada/exp_ch5.adb')
-rw-r--r-- | gcc/ada/exp_ch5.adb | 105 |
1 files changed, 51 insertions, 54 deletions
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb index b995577..2072935 100644 --- a/gcc/ada/exp_ch5.adb +++ b/gcc/ada/exp_ch5.adb @@ -4530,75 +4530,72 @@ package body Exp_Ch5 is -- Loop through elsif parts, dealing with constant conditions and -- possible condition actions that are present. - if Present (Elsif_Parts (N)) then - E := First (Elsif_Parts (N)); - while Present (E) loop + E := First (Elsif_Parts (N)); + while Present (E) loop - -- Do not consider controlled objects found in an if statement - -- which actually models an if expression because their early - -- finalization will affect the result of the expression. + -- Do not consider controlled objects found in an if statement which + -- actually models an if expression because their early finalization + -- will affect the result of the expression. - if not From_Conditional_Expression (N) then - Process_Statements_For_Controlled_Objects (E); - end if; + if not From_Conditional_Expression (N) then + Process_Statements_For_Controlled_Objects (E); + end if; - Adjust_Condition (Condition (E)); + Adjust_Condition (Condition (E)); - -- If there are condition actions, then rewrite the if statement - -- as indicated above. We also do the same rewrite for a True or - -- False condition. The further processing of this constant - -- condition is then done by the recursive call to expand the - -- newly created if statement + -- If there are condition actions, then rewrite the if statement as + -- indicated above. We also do the same rewrite for a True or False + -- condition. The further processing of this constant condition is + -- then done by the recursive call to expand the newly created if + -- statement - if Present (Condition_Actions (E)) - or else Compile_Time_Known_Value (Condition (E)) - then - New_If := - Make_If_Statement (Sloc (E), - Condition => Condition (E), - Then_Statements => Then_Statements (E), - Elsif_Parts => No_List, - Else_Statements => Else_Statements (N)); - - -- Elsif parts for new if come from remaining elsif's of parent - - while Present (Next (E)) loop - if No (Elsif_Parts (New_If)) then - Set_Elsif_Parts (New_If, New_List); - end if; + if Present (Condition_Actions (E)) + or else Compile_Time_Known_Value (Condition (E)) + then + New_If := + Make_If_Statement (Sloc (E), + Condition => Condition (E), + Then_Statements => Then_Statements (E), + Elsif_Parts => No_List, + Else_Statements => Else_Statements (N)); + + -- Elsif parts for new if come from remaining elsif's of parent + + while Present (Next (E)) loop + if No (Elsif_Parts (New_If)) then + Set_Elsif_Parts (New_If, New_List); + end if; - Append (Remove_Next (E), Elsif_Parts (New_If)); - end loop; + Append (Remove_Next (E), Elsif_Parts (New_If)); + end loop; - Set_Else_Statements (N, New_List (New_If)); + Set_Else_Statements (N, New_List (New_If)); - Insert_List_Before (New_If, Condition_Actions (E)); + Insert_List_Before (New_If, Condition_Actions (E)); - Remove (E); + Remove (E); - if Is_Empty_List (Elsif_Parts (N)) then - Set_Elsif_Parts (N, No_List); - end if; + if Is_Empty_List (Elsif_Parts (N)) then + Set_Elsif_Parts (N, No_List); + end if; - Analyze (New_If); + Analyze (New_If); - -- Note this is not an implicit if statement, since it is part - -- of an explicit if statement in the source (or of an implicit - -- if statement that has already been tested). We set the flag - -- after calling Analyze to avoid generating extra warnings - -- specific to pure if statements, however (see - -- Sem_Ch5.Analyze_If_Statement). + -- Note this is not an implicit if statement, since it is part of + -- an explicit if statement in the source (or of an implicit if + -- statement that has already been tested). We set the flag after + -- calling Analyze to avoid generating extra warnings specific to + -- pure if statements, however (see Sem_Ch5.Analyze_If_Statement). - Preserve_Comes_From_Source (New_If, N); - return; + Preserve_Comes_From_Source (New_If, N); + return; - -- No special processing for that elsif part, move to next + -- No special processing for that elsif part, move to next - else - Next (E); - end if; - end loop; - end if; + else + Next (E); + end if; + end loop; -- Some more optimizations applicable if we still have an IF statement |