public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-224] [Ada] Simplify conversion from Character to Char_Code
@ 2022-05-10 8:20 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2022-05-10 8:20 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:0e38fbfe1415e29d98bcdadc7307d589f496546b
commit r13-224-g0e38fbfe1415e29d98bcdadc7307d589f496546b
Author: Piotr Trojanek <trojanek@adacore.com>
Date: Wed Jan 19 14:05:16 2022 +0100
[Ada] Simplify conversion from Character to Char_Code
Replace "Char_Code (Character'Pos (...))" with "Get_Char_Code (...)".
The Get_Char_Code routine is inlined, so there is no performance penalty
when it is called with static actual parameters.
The N_Character_Literal has field Char_Literal_Value of type Unat, but
we should really only store there values from Char_Code type (e.g. there
are no characters with negative ASCII codes). It seems cleaner to use
UI_From_CC and not a more general UI_From_Int when setting the character
literal values.
Cleanup related to handling of character values in SPARK
counterexamples, which just like the code for names in task arrays
create N_Character_Literal nodes.
gcc/ada/
* exp_prag.adb (Expand_Pragma_Import_Or_Interface): Use
Get_Char_Code.
* exp_util.adb (Build_Task_Array_Image): Simplify conversion to
Char_Code.
(Build_Task_Image_Prefix): Likewise.
(Build_Task_Record_Image): Likewise.
* cstand.adb (Create_Standard): Use UI_From_Int instead of
UI_From_CC.
* exp_ch11.adb (Expand_N_Exception_Declaration): Likewise.
* sem_res.adb (Patch_Up_Value): Likewise.
* stringt.adb (Write_String_Table_Entry): Use Get_Char_Code.
Diff:
---
gcc/ada/cstand.adb | 8 ++++----
gcc/ada/exp_ch11.adb | 2 +-
gcc/ada/exp_prag.adb | 2 +-
gcc/ada/exp_util.adb | 16 ++++++++--------
gcc/ada/sem_res.adb | 4 ++--
gcc/ada/stringt.adb | 2 +-
6 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/gcc/ada/cstand.adb b/gcc/ada/cstand.adb
index b2e6ef9e5de..8ae0e47a96e 100644
--- a/gcc/ada/cstand.adb
+++ b/gcc/ada/cstand.adb
@@ -787,7 +787,7 @@ package body CStand is
B_Node := New_Node (N_Character_Literal, Stloc);
Set_Is_Static_Expression (B_Node);
Set_Chars (B_Node, No_Name);
- Set_Char_Literal_Value (B_Node, UI_From_Int (16#FF#));
+ Set_Char_Literal_Value (B_Node, UI_From_CC (16#FF#));
Set_Entity (B_Node, Empty);
Set_Etype (B_Node, Standard_Character);
Set_High_Bound (R_Node, B_Node);
@@ -833,7 +833,7 @@ package body CStand is
B_Node := New_Node (N_Character_Literal, Stloc);
Set_Is_Static_Expression (B_Node);
Set_Chars (B_Node, No_Name);
- Set_Char_Literal_Value (B_Node, UI_From_Int (16#FFFF#));
+ Set_Char_Literal_Value (B_Node, UI_From_CC (16#FFFF#));
Set_Entity (B_Node, Empty);
Set_Etype (B_Node, Standard_Wide_Character);
Set_High_Bound (R_Node, B_Node);
@@ -882,7 +882,7 @@ package body CStand is
B_Node := New_Node (N_Character_Literal, Stloc);
Set_Is_Static_Expression (B_Node);
Set_Chars (B_Node, No_Name);
- Set_Char_Literal_Value (B_Node, UI_From_Int (16#7FFF_FFFF#));
+ Set_Char_Literal_Value (B_Node, UI_From_CC (16#7FFF_FFFF#));
Set_Entity (B_Node, Empty);
Set_Etype (B_Node, Standard_Wide_Wide_Character);
Set_High_Bound (R_Node, B_Node);
@@ -1088,7 +1088,7 @@ package body CStand is
Set_Is_Static_Expression (Expr_Decl);
Set_Chars (Expr_Decl, No_Name);
Set_Etype (Expr_Decl, Standard_Character);
- Set_Char_Literal_Value (Expr_Decl, UI_From_Int (Int (Ccode)));
+ Set_Char_Literal_Value (Expr_Decl, UI_From_CC (Ccode));
end;
Append (Decl, Decl_A);
diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb
index b2eff312baf..855d3038826 100644
--- a/gcc/ada/exp_ch11.adb
+++ b/gcc/ada/exp_ch11.adb
@@ -1246,7 +1246,7 @@ package body Exp_Ch11 is
Append_To (L,
Make_Character_Literal (Loc,
Chars => Name_uA,
- Char_Literal_Value => UI_From_Int (Character'Pos ('A'))));
+ Char_Literal_Value => UI_From_CC (Get_Char_Code ('A'))));
-- Name_Length component: Nam'Length
diff --git a/gcc/ada/exp_prag.adb b/gcc/ada/exp_prag.adb
index 35ec2508550..0fe8bfffdb2 100644
--- a/gcc/ada/exp_prag.adb
+++ b/gcc/ada/exp_prag.adb
@@ -2010,7 +2010,7 @@ package body Exp_Prag is
Rewrite (Expression (Lang_Char),
Make_Character_Literal (Loc,
Chars => Name_uC,
- Char_Literal_Value => UI_From_Int (Character'Pos ('C'))));
+ Char_Literal_Value => UI_From_CC (Get_Char_Code ('C'))));
Analyze (Expression (Lang_Char));
-- Change the value of Foreign_Data
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 30c293c3465..263b42f7586 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -4183,7 +4183,7 @@ package body Exp_Util is
Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
- Set_Character_Literal_Name (Char_Code (Character'Pos ('(')));
+ Set_Character_Literal_Name (Get_Char_Code ('('));
Append_To (Stats,
Make_Assignment_Statement (Loc,
@@ -4194,7 +4194,7 @@ package body Exp_Util is
Expression =>
Make_Character_Literal (Loc,
Chars => Name_Find,
- Char_Literal_Value => UI_From_Int (Character'Pos ('(')))));
+ Char_Literal_Value => UI_From_CC (Get_Char_Code ('(')))));
Append_To (Stats,
Make_Assignment_Statement (Loc,
@@ -4244,7 +4244,7 @@ package body Exp_Util is
Expressions =>
New_List (Make_Integer_Literal (Loc, 1))))));
- Set_Character_Literal_Name (Char_Code (Character'Pos (',')));
+ Set_Character_Literal_Name (Get_Char_Code (','));
Append_To (Stats,
Make_Assignment_Statement (Loc,
@@ -4254,7 +4254,7 @@ package body Exp_Util is
Expression =>
Make_Character_Literal (Loc,
Chars => Name_Find,
- Char_Literal_Value => UI_From_Int (Character'Pos (',')))));
+ Char_Literal_Value => UI_From_CC (Get_Char_Code (',')))));
Append_To (Stats,
Make_Assignment_Statement (Loc,
@@ -4266,7 +4266,7 @@ package body Exp_Util is
end if;
end loop;
- Set_Character_Literal_Name (Char_Code (Character'Pos (')')));
+ Set_Character_Literal_Name (Get_Char_Code (')'));
Append_To (Stats,
Make_Assignment_Statement (Loc,
@@ -4277,7 +4277,7 @@ package body Exp_Util is
Expression =>
Make_Character_Literal (Loc,
Chars => Name_Find,
- Char_Literal_Value => UI_From_Int (Character'Pos (')')))));
+ Char_Literal_Value => UI_From_CC (Get_Char_Code (')')))));
return Build_Task_Image_Function (Loc, Decls, Stats, Res);
end Build_Task_Array_Image;
@@ -4569,7 +4569,7 @@ package body Exp_Util is
Build_Task_Image_Prefix (Loc, Len, Res, Pos, Pref, Sum, Decls, Stats);
- Set_Character_Literal_Name (Char_Code (Character'Pos ('.')));
+ Set_Character_Literal_Name (Get_Char_Code ('.'));
-- Res (Pos) := '.';
@@ -4582,7 +4582,7 @@ package body Exp_Util is
Make_Character_Literal (Loc,
Chars => Name_Find,
Char_Literal_Value =>
- UI_From_Int (Character'Pos ('.')))));
+ UI_From_CC (Get_Char_Code ('.')))));
Append_To (Stats,
Make_Assignment_Statement (Loc,
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 1c686cd3e06..734e457975b 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -2245,12 +2245,12 @@ package body Sem_Res is
elsif Nkind (N) = N_String_Literal
and then Is_Character_Type (Typ)
then
- Set_Character_Literal_Name (Char_Code (Character'Pos ('A')));
+ Set_Character_Literal_Name (Get_Char_Code ('A'));
Rewrite (N,
Make_Character_Literal (Sloc (N),
Chars => Name_Find,
Char_Literal_Value =>
- UI_From_Int (Character'Pos ('A'))));
+ UI_From_CC (Get_Char_Code ('A'))));
Set_Etype (N, Any_Character);
Set_Is_Static_Expression (N);
diff --git a/gcc/ada/stringt.adb b/gcc/ada/stringt.adb
index e96b96f5586..5bae3cc9ae7 100644
--- a/gcc/ada/stringt.adb
+++ b/gcc/ada/stringt.adb
@@ -441,7 +441,7 @@ package body Stringt is
for J in 1 .. String_Length (Id) loop
C := Get_String_Char (Id, J);
- if C = Character'Pos ('"') then
+ if C = Get_Char_Code ('"') then
Write_Str ("""""");
else
Write_Char_Code (C);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-10 8:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10 8:20 [gcc r13-224] [Ada] Simplify conversion from Character to Char_Code 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).