@@ -91,12 +91,6 @@ Bvariable::error_variable ()
91
91
92
92
// A helper function to create a GCC identifier from a C++ string.
93
93
94
- static inline tree
95
- get_identifier_from_string (const std::string &str)
96
- {
97
- return get_identifier_with_length (str.data (), str.length ());
98
- }
99
-
100
94
namespace Backend {
101
95
102
96
// Define the built-in functions that are exposed to GCCRust.
@@ -609,7 +603,7 @@ fill_in_fields (tree fill, const std::vector<typed_identifier> &fields,
609
603
tree *pp = &field_trees;
610
604
for (const auto &p : fields)
611
605
{
612
- tree name_tree = get_identifier_from_string ( p.name );
606
+ tree name_tree = p.name . as_tree ( );
613
607
tree type_tree = p.type ;
614
608
if (error_operand_p (type_tree))
615
609
return error_mark_node;
@@ -675,7 +669,7 @@ fill_in_array (tree fill, tree element_type, tree length_tree)
675
669
// Return a named version of a type.
676
670
677
671
tree
678
- named_type (const std::string & name, tree type, location_t location)
672
+ named_type (GGC::Ident name, tree type, location_t location)
679
673
{
680
674
if (error_operand_p (type))
681
675
return error_mark_node;
@@ -688,15 +682,14 @@ named_type (const std::string &name, tree type, location_t location)
688
682
|| TREE_CODE (type) == COMPLEX_TYPE
689
683
|| TREE_CODE (type) == BOOLEAN_TYPE))
690
684
{
691
- tree decl = build_decl (BUILTINS_LOCATION, TYPE_DECL,
692
- get_identifier_from_string (name ), type);
685
+ tree decl
686
+ = build_decl (BUILTINS_LOCATION, TYPE_DECL, name. as_tree ( ), type);
693
687
TYPE_NAME (type) = decl;
694
688
return type;
695
689
}
696
690
697
691
tree copy = build_variant_type_copy (type);
698
- tree decl
699
- = build_decl (location, TYPE_DECL, get_identifier_from_string (name), copy);
692
+ tree decl = build_decl (location, TYPE_DECL, name.as_tree (), copy);
700
693
DECL_ORIGINAL_TYPE (decl) = type;
701
694
TYPE_NAME (copy) = decl;
702
695
return copy;
@@ -1924,9 +1917,9 @@ convert_tree (tree type_tree, tree expr_tree, location_t location)
1924
1917
// Make a global variable.
1925
1918
1926
1919
Bvariable *
1927
- global_variable (const std::string & var_name, const std::string & asm_name,
1928
- tree type_tree , bool is_external , bool is_hidden ,
1929
- bool in_unique_section, location_t location)
1920
+ global_variable (GGC::Ident var_name, GGC::Ident asm_name, tree type_tree ,
1921
+ bool is_external , bool is_hidden , bool in_unique_section ,
1922
+ location_t location)
1930
1923
{
1931
1924
if (error_operand_p (type_tree))
1932
1925
return Bvariable::error_variable ();
@@ -1936,20 +1929,19 @@ global_variable (const std::string &var_name, const std::string &asm_name,
1936
1929
if ((is_external || !is_hidden) && int_size_in_bytes (type_tree) == 0 )
1937
1930
type_tree = non_zero_size_type (type_tree);
1938
1931
1939
- tree decl = build_decl (location, VAR_DECL,
1940
- get_identifier_from_string (var_name), type_tree);
1932
+ tree decl = build_decl (location, VAR_DECL, var_name.as_tree (), type_tree);
1941
1933
if (is_external)
1942
1934
DECL_EXTERNAL (decl) = 1 ;
1943
1935
else
1944
1936
TREE_STATIC (decl) = 1 ;
1945
1937
if (!is_hidden)
1946
1938
{
1947
1939
TREE_PUBLIC (decl) = 1 ;
1948
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier_from_string (asm_name ));
1940
+ SET_DECL_ASSEMBLER_NAME (decl, asm_name. as_tree ( ));
1949
1941
}
1950
1942
else
1951
1943
{
1952
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier_from_string (asm_name ));
1944
+ SET_DECL_ASSEMBLER_NAME (decl, asm_name. as_tree ( ));
1953
1945
}
1954
1946
1955
1947
TREE_USED (decl) = 1 ;
@@ -1989,13 +1981,12 @@ global_variable_set_init (Bvariable *var, tree expr_tree)
1989
1981
// Make a local variable.
1990
1982
1991
1983
Bvariable *
1992
- local_variable (tree function, const std::string & name, tree type_tree,
1984
+ local_variable (tree function, GGC::Ident name, tree type_tree,
1993
1985
Bvariable *decl_var, location_t location)
1994
1986
{
1995
1987
if (error_operand_p (type_tree))
1996
1988
return Bvariable::error_variable ();
1997
- tree decl = build_decl (location, VAR_DECL, get_identifier_from_string (name),
1998
- type_tree);
1989
+ tree decl = build_decl (location, VAR_DECL, name.as_tree (), type_tree);
1999
1990
DECL_CONTEXT (decl) = function;
2000
1991
2001
1992
if (decl_var != NULL )
@@ -2010,13 +2001,12 @@ local_variable (tree function, const std::string &name, tree type_tree,
2010
2001
// Make a function parameter variable.
2011
2002
2012
2003
Bvariable *
2013
- parameter_variable (tree function, const std::string & name, tree type_tree,
2004
+ parameter_variable (tree function, GGC::Ident name, tree type_tree,
2014
2005
location_t location)
2015
2006
{
2016
2007
if (error_operand_p (type_tree))
2017
2008
return Bvariable::error_variable ();
2018
- tree decl = build_decl (location, PARM_DECL,
2019
- get_identifier_from_string (name), type_tree);
2009
+ tree decl = build_decl (location, PARM_DECL, name.as_tree (), type_tree);
2020
2010
DECL_CONTEXT (decl) = function;
2021
2011
DECL_ARG_TYPE (decl) = type_tree;
2022
2012
@@ -2027,13 +2017,12 @@ parameter_variable (tree function, const std::string &name, tree type_tree,
2027
2017
// Make a static chain variable.
2028
2018
2029
2019
Bvariable *
2030
- static_chain_variable (tree fndecl, const std::string & name, tree type_tree,
2020
+ static_chain_variable (tree fndecl, GGC::Ident name, tree type_tree,
2031
2021
location_t location)
2032
2022
{
2033
2023
if (error_operand_p (type_tree))
2034
2024
return Bvariable::error_variable ();
2035
- tree decl = build_decl (location, PARM_DECL,
2036
- get_identifier_from_string (name), type_tree);
2025
+ tree decl = build_decl (location, PARM_DECL, name.as_tree (), type_tree);
2037
2026
DECL_CONTEXT (decl) = fndecl;
2038
2027
DECL_ARG_TYPE (decl) = type_tree;
2039
2028
TREE_USED (decl) = 1 ;
@@ -2124,10 +2113,10 @@ temporary_variable (tree fndecl, tree bind_tree, tree type_tree, tree init_tree,
2124
2113
// Make a label.
2125
2114
2126
2115
tree
2127
- label (tree func_tree, const std::string & name, location_t location)
2116
+ label (tree func_tree, tl::optional<GGC::Ident> name, location_t location)
2128
2117
{
2129
2118
tree decl;
2130
- if (name.empty ())
2119
+ if (! name.has_value ())
2131
2120
{
2132
2121
if (DECL_STRUCT_FUNCTION (func_tree) == NULL )
2133
2122
push_struct_function (func_tree);
@@ -2140,7 +2129,7 @@ label (tree func_tree, const std::string &name, location_t location)
2140
2129
}
2141
2130
else
2142
2131
{
2143
- tree id = get_identifier_from_string (name );
2132
+ tree id = name-> as_tree ( );
2144
2133
decl = build_decl (location, LABEL_DECL, id, void_type_node);
2145
2134
DECL_CONTEXT (decl) = func_tree;
2146
2135
}
@@ -2179,21 +2168,21 @@ label_address (tree label, location_t location)
2179
2168
// Declare or define a new function.
2180
2169
2181
2170
tree
2182
- function (tree functype, const std::string & name, const std::string & asm_name,
2171
+ function (tree functype, GGC::Ident name, tl::optional<GGC::Ident> asm_name,
2183
2172
unsigned int flags, location_t location)
2184
2173
{
2185
2174
if (error_operand_p (functype))
2186
2175
return error_mark_node;
2187
2176
2188
2177
gcc_assert (FUNCTION_POINTER_TYPE_P (functype));
2189
2178
functype = TREE_TYPE (functype);
2190
- tree id = get_identifier_from_string (name );
2179
+ tree id = name. as_tree ( );
2191
2180
if (error_operand_p (id))
2192
2181
return error_mark_node;
2193
2182
2194
2183
tree decl = build_decl (location, FUNCTION_DECL, id, functype);
2195
- if (! asm_name.empty ())
2196
- SET_DECL_ASSEMBLER_NAME (decl, get_identifier_from_string (asm_name ));
2184
+ if (asm_name.has_value ())
2185
+ SET_DECL_ASSEMBLER_NAME (decl, asm_name-> as_tree ( ));
2197
2186
2198
2187
if ((flags & function_is_declaration) != 0 )
2199
2188
DECL_EXTERNAL (decl) = 1 ;
@@ -2236,7 +2225,7 @@ function_defer_statement (tree function, tree undefer_tree, tree defer_tree,
2236
2225
push_cfun (DECL_STRUCT_FUNCTION (function));
2237
2226
2238
2227
tree stmt_list = NULL ;
2239
- tree label = Backend::label (function, " " , location);
2228
+ tree label = Backend::label (function, tl:: nullopt , location);
2240
2229
tree label_def = label_definition_statement (label);
2241
2230
append_to_statement_list (label_def, &stmt_list);
2242
2231
0 commit comments