[gcc r12-3814] [Ada] More flexibility in preprocessor

Pierre-Marie de Rodat pmderodat@gcc.gnu.org
Wed Sep 22 15:11:30 GMT 2021


https://gcc.gnu.org/g:3d2226f1730e027808b8f9c17d4f6b7ac1eb7c44

commit r12-3814-g3d2226f1730e027808b8f9c17d4f6b7ac1eb7c44
Author: Arnaud Charlet <charlet@adacore.com>
Date:   Mon Jul 26 04:16:06 2021 -0400

    [Ada] More flexibility in preprocessor
    
    gcc/ada/
    
            * prep.adb (Preprocess): Allow for more flexibility when
            Relaxed_RM_Semantics is set.

Diff:
---
 gcc/ada/prep.adb | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/prep.adb b/gcc/ada/prep.adb
index 37556d55e91..e01161c7289 100644
--- a/gcc/ada/prep.adb
+++ b/gcc/ada/prep.adb
@@ -1410,7 +1410,12 @@ package body Prep is
 
                      Scan.all;
 
-                     if Token /= Tok_If then
+                     --  Ignore all recoverable errors if Relaxed_RM_Semantics
+
+                     if Relaxed_RM_Semantics then
+                        null;
+
+                     elsif Token /= Tok_If then
                         Error_Msg -- CODEFIX
                           ("IF expected", Token_Ptr);
                         No_Error_Found := False;
@@ -1453,21 +1458,31 @@ package body Prep is
                   --  Illegal preprocessor line
 
                   when others =>
-                     No_Error_Found := False;
-
                      if Pp_States.Last = 0 then
                         Error_Msg -- CODEFIX
                           ("IF expected", Token_Ptr);
+                        No_Error_Found := False;
 
-                     elsif
-                       Pp_States.Table (Pp_States.Last).Else_Ptr = 0
+                     elsif Relaxed_RM_Semantics
+                       and then Get_Name_String (Token_Name) = "endif"
                      then
+                        --  In relaxed mode, accept "endif" instead of
+                        --  "end if".
+
+                        --  Decrement the depth of the #if stack
+
+                        if Pp_States.Last > 0 then
+                           Pp_States.Decrement_Last;
+                        end if;
+                     elsif Pp_States.Table (Pp_States.Last).Else_Ptr = 0 then
                         Error_Msg
                           ("IF, ELSIF, ELSE, or `END IF` expected",
                            Token_Ptr);
+                        No_Error_Found := False;
 
                      else
                         Error_Msg ("IF or `END IF` expected", Token_Ptr);
+                        No_Error_Found := False;
                      end if;
 
                      --  Skip to the end of this illegal line


More information about the Gcc-cvs mailing list