@@ -91,12 +91,6 @@ Bvariable::error_variable ()
9191
9292// A helper function to create a GCC identifier from a C++ string.
9393
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-
10094namespace Backend {
10195
10296// 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,
609603 tree *pp = &field_trees;
610604 for (const auto &p : fields)
611605 {
612- tree name_tree = get_identifier_from_string ( p.name );
606+ tree name_tree = p.name . as_tree ( );
613607 tree type_tree = p.type ;
614608 if (error_operand_p (type_tree))
615609 return error_mark_node;
@@ -675,7 +669,7 @@ fill_in_array (tree fill, tree element_type, tree length_tree)
675669// Return a named version of a type.
676670
677671tree
678- named_type (const std::string & name, tree type, location_t location)
672+ named_type (GGC ::Ident name, tree type, location_t location)
679673{
680674 if (error_operand_p (type))
681675 return error_mark_node;
@@ -688,15 +682,14 @@ named_type (const std::string &name, tree type, location_t location)
688682 || TREE_CODE (type) == COMPLEX_TYPE
689683 || TREE_CODE (type) == BOOLEAN_TYPE ))
690684 {
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);
693687 TYPE_NAME (type) = decl;
694688 return type;
695689 }
696690
697691 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);
700693 DECL_ORIGINAL_TYPE (decl) = type;
701694 TYPE_NAME (copy) = decl;
702695 return copy;
@@ -1924,9 +1917,9 @@ convert_tree (tree type_tree, tree expr_tree, location_t location)
19241917// Make a global variable.
19251918
19261919Bvariable *
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)
19301923{
19311924 if (error_operand_p (type_tree))
19321925 return Bvariable::error_variable ();
@@ -1936,20 +1929,19 @@ global_variable (const std::string &var_name, const std::string &asm_name,
19361929 if ((is_external || !is_hidden) && int_size_in_bytes (type_tree) == 0 )
19371930 type_tree = non_zero_size_type (type_tree);
19381931
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);
19411933 if (is_external)
19421934 DECL_EXTERNAL (decl) = 1 ;
19431935 else
19441936 TREE_STATIC (decl) = 1 ;
19451937 if (!is_hidden)
19461938 {
19471939 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 ( ));
19491941 }
19501942 else
19511943 {
1952- SET_DECL_ASSEMBLER_NAME (decl, get_identifier_from_string (asm_name ));
1944+ SET_DECL_ASSEMBLER_NAME (decl, asm_name. as_tree ( ));
19531945 }
19541946
19551947 TREE_USED (decl) = 1 ;
@@ -1989,13 +1981,12 @@ global_variable_set_init (Bvariable *var, tree expr_tree)
19891981// Make a local variable.
19901982
19911983Bvariable *
1992- local_variable (tree function, const std::string & name, tree type_tree,
1984+ local_variable (tree function, GGC ::Ident name, tree type_tree,
19931985 Bvariable *decl_var, location_t location)
19941986{
19951987 if (error_operand_p (type_tree))
19961988 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);
19991990 DECL_CONTEXT (decl) = function;
20001991
20011992 if (decl_var != NULL )
@@ -2010,13 +2001,12 @@ local_variable (tree function, const std::string &name, tree type_tree,
20102001// Make a function parameter variable.
20112002
20122003Bvariable *
2013- parameter_variable (tree function, const std::string & name, tree type_tree,
2004+ parameter_variable (tree function, GGC ::Ident name, tree type_tree,
20142005 location_t location)
20152006{
20162007 if (error_operand_p (type_tree))
20172008 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);
20202010 DECL_CONTEXT (decl) = function;
20212011 DECL_ARG_TYPE (decl) = type_tree;
20222012
@@ -2027,13 +2017,12 @@ parameter_variable (tree function, const std::string &name, tree type_tree,
20272017// Make a static chain variable.
20282018
20292019Bvariable *
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,
20312021 location_t location)
20322022{
20332023 if (error_operand_p (type_tree))
20342024 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);
20372026 DECL_CONTEXT (decl) = fndecl;
20382027 DECL_ARG_TYPE (decl) = type_tree;
20392028 TREE_USED (decl) = 1 ;
@@ -2124,10 +2113,10 @@ temporary_variable (tree fndecl, tree bind_tree, tree type_tree, tree init_tree,
21242113// Make a label.
21252114
21262115tree
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)
21282117{
21292118 tree decl;
2130- if (name.empty ())
2119+ if (! name.has_value ())
21312120 {
21322121 if (DECL_STRUCT_FUNCTION (func_tree) == NULL )
21332122 push_struct_function (func_tree);
@@ -2140,7 +2129,7 @@ label (tree func_tree, const std::string &name, location_t location)
21402129 }
21412130 else
21422131 {
2143- tree id = get_identifier_from_string (name );
2132+ tree id = name-> as_tree ( );
21442133 decl = build_decl (location, LABEL_DECL , id, void_type_node);
21452134 DECL_CONTEXT (decl) = func_tree;
21462135 }
@@ -2179,21 +2168,21 @@ label_address (tree label, location_t location)
21792168// Declare or define a new function.
21802169
21812170tree
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,
21832172 unsigned int flags, location_t location)
21842173{
21852174 if (error_operand_p (functype))
21862175 return error_mark_node;
21872176
21882177 gcc_assert (FUNCTION_POINTER_TYPE_P (functype));
21892178 functype = TREE_TYPE (functype);
2190- tree id = get_identifier_from_string (name );
2179+ tree id = name. as_tree ( );
21912180 if (error_operand_p (id))
21922181 return error_mark_node;
21932182
21942183 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 ( ));
21972186
21982187 if ((flags & function_is_declaration) != 0 )
21992188 DECL_EXTERNAL (decl) = 1 ;
@@ -2236,7 +2225,7 @@ function_defer_statement (tree function, tree undefer_tree, tree defer_tree,
22362225 push_cfun (DECL_STRUCT_FUNCTION (function));
22372226
22382227 tree stmt_list = NULL ;
2239- tree label = Backend::label (function, " " , location);
2228+ tree label = Backend::label (function, tl:: nullopt , location);
22402229 tree label_def = label_definition_statement (label);
22412230 append_to_statement_list (label_def, &stmt_list);
22422231
0 commit comments