diff options
Diffstat (limited to 'gcc/ada/pprint.adb')
-rw-r--r-- | gcc/ada/pprint.adb | 104 |
1 files changed, 44 insertions, 60 deletions
diff --git a/gcc/ada/pprint.adb b/gcc/ada/pprint.adb index c00962d..f7717bf 100644 --- a/gcc/ada/pprint.adb +++ b/gcc/ada/pprint.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2008-2020, Free Software Foundation, Inc. -- +-- Copyright (C) 2008-2021, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -23,20 +23,25 @@ -- -- ------------------------------------------------------------------------------ -with Atree; use Atree; -with Csets; use Csets; -with Einfo; use Einfo; -with Namet; use Namet; -with Nlists; use Nlists; -with Opt; use Opt; -with Sinfo; use Sinfo; -with Sinput; use Sinput; -with Snames; use Snames; -with Uintp; use Uintp; +with Atree; use Atree; +with Einfo; use Einfo; +with Einfo.Entities; use Einfo.Entities; +with Einfo.Utils; use Einfo.Utils; +with Namet; use Namet; +with Nlists; use Nlists; +with Opt; use Opt; +with Sinfo; use Sinfo; +with Sinfo.Nodes; use Sinfo.Nodes; +with Sinfo.Utils; use Sinfo.Utils; +with Sinput; use Sinput; +with Snames; use Snames; +with Uintp; use Uintp; + +with System.Case_Util; package body Pprint is - List_Name_Count : Integer := 0; + List_Name_Count : Natural := 0; -- Counter used to prevent infinite recursion while computing name of -- complex expressions. @@ -225,8 +230,7 @@ package body Pprint is end; when N_Integer_Literal => - UI_Image (Intval (Expr)); - return UI_Image_Buffer (1 .. UI_Image_Length); + return UI_Image (Intval (Expr)); when N_Real_Literal => return Real_Image (Realval (Expr)); @@ -238,10 +242,10 @@ package body Pprint is return "new " & Expr_Name (Expression (Expr)); when N_Aggregate => - if Present (Sinfo.Expressions (Expr)) then + if Present (Expressions (Expr)) then return List_Name - (List => First (Sinfo.Expressions (Expr)), + (List => First (Expressions (Expr)), Add_Space => False); -- Do not return empty string for (others => <>) aggregate @@ -265,39 +269,13 @@ package body Pprint is when N_Extension_Aggregate => return "(" & Expr_Name (Ancestor_Part (Expr)) & " with " & List_Name - (List => First (Sinfo.Expressions (Expr)), + (List => First (Expressions (Expr)), Add_Space => False, Add_Paren => False) & ")"; when N_Attribute_Reference => if Take_Prefix then declare - function To_Mixed_Case (S : String) return String; - -- Transform given string into the corresponding one in - -- mixed case form. - - ------------------- - -- To_Mixed_Case -- - ------------------- - - function To_Mixed_Case (S : String) return String is - Result : String (S'Range); - Ucase : Boolean := True; - - begin - for J in S'Range loop - if Ucase then - Result (J) := Fold_Upper (S (J)); - else - Result (J) := Fold_Lower (S (J)); - end if; - - Ucase := (S (J) = '_'); - end loop; - - return Result; - end To_Mixed_Case; - Id : constant Attribute_Id := Get_Attribute_Id (Attribute_Name (Expr)); @@ -306,7 +284,7 @@ package body Pprint is Str : constant String := Expr_Name (Prefix (Expr)) & "'" - & To_Mixed_Case + & System.Case_Util.To_Mixed (Get_Name_String (Attribute_Name (Expr))); N : Node_Id; @@ -382,9 +360,8 @@ package body Pprint is and then Nkind (Decl) = N_Object_Declaration and then not Comes_From_Source (Decl) and then Constant_Present (Decl) - and then Present (Sinfo.Expression (Decl)) - and then Nkind (Sinfo.Expression (Decl)) = - N_Reference + and then Present (Expression (Decl)) + and then Nkind (Expression (Decl)) = N_Reference then return ""; end if; @@ -437,12 +414,14 @@ package body Pprint is when N_If_Expression => declare - N : constant Node_Id := First (Sinfo.Expressions (Expr)); + Cond_Expr : constant Node_Id := First (Expressions (Expr)); + Then_Expr : constant Node_Id := Next (Cond_Expr); + Else_Expr : constant Node_Id := Next (Then_Expr); begin return - "if " & Expr_Name (N) & " then " - & Expr_Name (Next (N)) & " else " - & Expr_Name (Next (Next (N))); + "if " & Expr_Name (Cond_Expr) & " then " + & Expr_Name (Then_Expr) & " else " + & Expr_Name (Else_Expr); end; when N_Qualified_Expression => @@ -648,9 +627,9 @@ package body Pprint is if Take_Prefix then return Expr_Name (Prefix (Expr)) - & List_Name (First (Sinfo.Expressions (Expr))); + & List_Name (First (Expressions (Expr))); else - return List_Name (First (Sinfo.Expressions (Expr))); + return List_Name (First (Expressions (Expr))); end if; when N_Function_Call => @@ -662,13 +641,12 @@ package body Pprint is if Default = "" then return '(' & Expr_Name (Name (Expr)) - & List_Name (First (Sinfo.Parameter_Associations (Expr))) + & List_Name (First (Parameter_Associations (Expr))) & ')'; else return Expr_Name (Name (Expr)) - & List_Name - (First (Sinfo.Parameter_Associations (Expr))); + & List_Name (First (Parameter_Associations (Expr))); end if; when N_Null => @@ -682,7 +660,7 @@ package body Pprint is end case; end Expr_Name; - -- Start of processing for Expression_Name + -- Start of processing for Expression_Image begin if not From_Source then @@ -697,6 +675,12 @@ package body Pprint is end; end if; + -- Reach to the underlying expression for an expression-with-actions + + if Nkind (Expr) = N_Expression_With_Actions then + return Expression_Image (Expression (Expr), Default); + end if; + -- Compute left (start) and right (end) slocs for the expression -- Consider using Sinput.Sloc_Range instead, except that it does not -- work properly currently??? @@ -788,11 +772,11 @@ package body Pprint is end if; when N_Indexed_Component => - Right := Original_Node (Last (Sinfo.Expressions (Right))); + Right := Original_Node (Last (Expressions (Right))); Append_Paren := Append_Paren + 1; when N_Function_Call => - if Present (Sinfo.Parameter_Associations (Right)) then + if Present (Parameter_Associations (Right)) then declare Rover : Node_Id; Found : Boolean; @@ -801,7 +785,7 @@ package body Pprint is -- Avoid source position confusion associated with -- parameters for which Comes_From_Source is False. - Rover := First (Sinfo.Parameter_Associations (Right)); + Rover := First (Parameter_Associations (Right)); Found := False; while Present (Rover) loop if Comes_From_Source (Original_Node (Rover)) then |