diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-06-27 11:22:00 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:46:30 +0100 |
commit | fcb228d1232820a1fbf63f9f366630067a13a432 (patch) | |
tree | e169e00d029e728824b723fc7873ff1750c2fba2 /gcc/rust/ast | |
parent | 0ee16a42074486d6514379d7faa6aee54100f0a4 (diff) | |
download | gcc-fcb228d1232820a1fbf63f9f366630067a13a432.zip gcc-fcb228d1232820a1fbf63f9f366630067a13a432.tar.gz gcc-fcb228d1232820a1fbf63f9f366630067a13a432.tar.bz2 |
gccrs: ast: Change Identifier definition
Change Identifier type definition from a simple typedef to a whole class
with it's own node id.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Change with
call to getter.
* ast/rust-ast.cc (Module::as_string): Likewise.
(StaticItem::as_string): Likewise.
(TupleStruct::as_string): Likewise.
(Method::as_string): Likewise.
(StructStruct::as_string): Likewise.
(UseTreeRebind::as_string): Likewise.
(Enum::as_string): Likewise.
(Trait::as_string): Likewise.
(Union::as_string): Likewise.
(Function::as_string): Likewise.
(TypeAlias::as_string): Likewise.
(MacroRulesDefinition::as_string): Likewise.
(FieldAccessExpr::as_string): Likewise.
(MacroMatchFragment::as_string): Likewise.
(TypeParam::as_string): Likewise.
(StructExprFieldIdentifierValue::as_string): Likewise.
(EnumItem::as_string): Likewise.
(StructField::as_string): Likewise.
(ExternalTypeItem::as_string): Likewise.
(ExternalStaticItem::as_string): Likewise.
(ExternalFunctionItem::as_string): Likewise.
(TraitFunctionDecl::as_string): Likewise.
(TraitMethodDecl::as_string): Likewise.
(TraitItemConst::as_string): Likewise.
(TraitItemType::as_string): Likewise.
(MaybeNamedParam::as_string): Likewise.
(MetaListPaths::as_string): Likewise.
(MetaListNameValueStr::as_string): Likewise.
(Module::process_file_path): Likewise.
(MetaListNameValueStr::check_cfg_predicate): Likewise.
(MetaListPaths::check_cfg_predicate): Likewise.
(MetaWord::check_cfg_predicate): Likewise.
(MetaNameValueStr::check_cfg_predicate): Likewise.
(MetaNameValueStr::to_attribute): Likewise.
(MetaWord::to_attribute): Likewise.
(MetaListPaths::to_attribute): Likewise.
(MetaListNameValueStr::to_attribute): Likewise.
(operator<<): Change Identifier class <<
operator overload for standard output stream.
* ast/rust-ast.h (class Identifier): Change typedef to proper
class definition.
(operator<<): Add prototype for operator overload.
(class Token): Change getter identifier.
(class MetaListNameValueStr): Likewise.
(class PathExpr): Likewise.
* ast/rust-expr.h: Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-macro.h: Likewise.
* ast/rust-path.cc (GenericArg::disambiguate_to_type): Likewise.
(GenericArgsBinding::as_string): Likewise.
(ConstGenericParam::as_string): Likewise.
* ast/rust-path.h: Likewise.
* ast/rust-pattern.cc (IdentifierPattern::as_string): Likewise.
(StructPatternFieldIdentPat::as_string): Likewise.
(StructPatternFieldIdent::as_string): Likewise.
* ast/rust-type.h: Likewise.
* backend/rust-compile-base.cc: Likewise.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-extern.h: Likewise.
* backend/rust-compile-fnparam.cc (CompileFnParam::visit):
Likewise.
* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
Likewise.
* backend/rust-compile-item.cc (CompileItem::visit): Likewise.
* backend/rust-compile-pattern.cc (CompilePatternBindings::visit): Likewise.
* backend/rust-compile-struct-field-expr.cc (CompileStructExprField::visit):
Likewise.
* backend/rust-compile-var-decl.h: Likewise.
* backend/rust-compile.cc: Likewise.
* checks/errors/rust-unsafe-checker.cc (check_extern_call):
Likewise.
* checks/lints/rust-lint-marklive.cc (MarkLive::visit):
Likewise.
* checks/lints/rust-lint-scan-deadcode.h: Likewise.
* expand/rust-derive-clone.cc (DeriveClone::clone_fn): Likewise.
(DeriveClone::visit_tuple): Likewise.
(DeriveClone::visit_struct): Likewise.
(DeriveClone::visit_union): Likewise.
* expand/rust-derive-copy.cc (DeriveCopy::visit_struct):
Likewise.
(DeriveCopy::visit_tuple): Likewise.
(DeriveCopy::visit_enum): Likewise.
(DeriveCopy::visit_union): Likewise.
* expand/rust-macro-expand.cc (MacroExpander::match_matcher):
Likewise.
(MacroExpander::match_n_matches): Likewise.
(MacroExpander::match_repetition): Likewise.
(MacroExpander::match_repetition_skipped_metavars): Likewise.
* hir/rust-ast-lower-base.cc (struct_field_name_exists):
Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit):
Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* hir/tree/rust-hir-item.h: Likewise.
* hir/tree/rust-hir-path.h: Likewise.
* hir/tree/rust-hir-type.h: Likewise.
* hir/tree/rust-hir.cc (Module::as_string): Likewise.
(StaticItem::as_string): Likewise.
(TupleStruct::as_string): Likewise.
(ConstantItem::as_string): Likewise.
(StructStruct::as_string): Likewise.
(UseTreeRebind::as_string): Likewise.
(Enum::as_string): Likewise.
(Trait::as_string): Likewise.
(Union::as_string): Likewise.
(Function::as_string): Likewise.
(TypeAlias::as_string): Likewise.
(FieldAccessExpr::as_string): Likewise.
(TypeParam::as_string): Likewise.
(GenericArgsBinding::as_string): Likewise.
(StructPatternFieldIdent::as_string): Likewise.
(StructPatternFieldIdentPat::as_string): Likewise.
(IdentifierPattern::as_string): Likewise.
(StructExprFieldIdentifierValue::as_string): Likewise.
(EnumItem::as_string): Likewise.
(StructField::as_string): Likewise.
(ExternalStaticItem::as_string): Likewise.
(ExternalFunctionItem::as_string): Likewise.
(NamedFunctionParam::as_string): Likewise.
(TraitFunctionDecl::as_string): Likewise.
(TraitItemConst::as_string): Likewise.
(TraitItemType::as_string): Likewise.
(MaybeNamedParam::as_string): Likewise.
* hir/tree/rust-hir.h: Likewise.
* parse/rust-parse-impl.h (Parser::parse_macro_match_fragment):
Likewise.
(Parser::parse_module): Likewise.
(Parser::parse_use_tree): Likewise.
(Parser::parse_maybe_named_param): Likewise.
* resolve/rust-ast-resolve-implitem.h: Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit):
Likewise.
(ResolveItem::visit): Likewise.
(flatten_rebind): Likewise.
(ResolveExternItem::visit): Likewise.
(rust_flatten_rebind): Likewise.
(rust_flatten_rebind_nested): Likewise.
* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go):
Likewise.
(PatternDeclaration::visit): Likewise.
(PatternDeclaration::add_new_binding): Likewise.
* resolve/rust-ast-resolve-stmt.h: Likewise.
* resolve/rust-ast-resolve-toplevel.h: Likewise.
* resolve/rust-ast-resolve-type.h: Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise.
* typecheck/rust-autoderef.cc: Likewise.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::select):
Likewise.
* typecheck/rust-hir-path-probe.cc (PathProbeType::visit):
Likewise.
* typecheck/rust-hir-trait-reference.cc (TraitReference::get_name): Likewise.
* typecheck/rust-hir-trait-resolve.cc (ResolveTraitItemToRef::visit): Likewise.
(TraitResolver::resolve_trait): Likewise.
(TraitItemReference::resolve_item): Likewise.
(AssociatedImplTrait::setup_raw_associated_types): Likewise.
* typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): Likewise.
(TypeCheckImplItem::visit): Likewise.
(TypeCheckImplItemWithTrait::visit): Likewise.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise.
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::visit): Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::visit): Likewise.
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise.
* typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args): Likewise.
* util/rust-attributes.cc (check_doc_attribute): Likewise.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r-- | gcc/rust/ast/rust-ast-collector.cc | 78 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast.cc | 114 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 115 | ||||
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 4 | ||||
-rw-r--r-- | gcc/rust/ast/rust-item.h | 22 | ||||
-rw-r--r-- | gcc/rust/ast/rust-macro.h | 6 | ||||
-rw-r--r-- | gcc/rust/ast/rust-path.cc | 6 | ||||
-rw-r--r-- | gcc/rust/ast/rust-path.h | 13 | ||||
-rw-r--r-- | gcc/rust/ast/rust-pattern.cc | 6 | ||||
-rw-r--r-- | gcc/rust/ast/rust-type.h | 2 |
10 files changed, 207 insertions, 159 deletions
diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index e261849..d851066 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -296,7 +296,7 @@ TokenCollector::visit (StructField &field) visit (attr); } visit (field.get_visibility ()); - auto name = field.get_field_name (); + auto name = field.get_field_name ().as_string (); tokens.push_back ( Rust::Token::make_identifier (field.get_locus (), std::move (name))); tokens.push_back (Rust::Token::make (COLON, Location ())); @@ -358,7 +358,7 @@ TokenCollector::visit (MaybeNamedParam ¶m) { visit (attr); } - auto param_name = param.get_name (); + auto param_name = param.get_name ().as_string (); switch (param.get_param_kind ()) { case MaybeNamedParam::UNNAMED: @@ -458,7 +458,7 @@ TokenCollector::visit (AttrInputMetaItemContainer &container) void TokenCollector::visit (IdentifierExpr &ident_expr) { - auto ident = ident_expr.get_ident (); + auto ident = ident_expr.get_ident ().as_string (); tokens.push_back ( Rust::Token::make_identifier (ident_expr.get_locus (), std::move (ident))); } @@ -520,7 +520,7 @@ TokenCollector::visit (ConstGenericParam ¶m) // const IDENTIFIER : Type ( = Block | IDENTIFIER | -?LITERAL )? tokens.push_back (Rust::Token::make (CONST, param.get_locus ())); - auto id = param.get_name (); + auto id = param.get_name ().as_string (); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); tokens.push_back (Rust::Token::make (COLON, Location ())); visit (param.get_type ()); @@ -632,7 +632,7 @@ TokenCollector::visit (GenericArgsBinding &binding) { // Syntax: // IDENTIFIER `=` Type - auto identifier = binding.get_identifier (); + auto identifier = binding.get_identifier ().as_string (); tokens.push_back (Rust::Token::make_identifier (binding.get_locus (), std::move (identifier))); @@ -1128,7 +1128,7 @@ TokenCollector::visit (StructExprFieldIdentifier &expr) { // TODO: Add attributes // visit_items_as_lines (expr.get_attrs ()); - auto id = expr.get_field_name (); + auto id = expr.get_field_name ().as_string (); tokens.push_back ( Rust::Token::make_identifier (expr.get_locus (), std::move (id))); } @@ -1217,7 +1217,7 @@ TokenCollector::visit (FieldAccessExpr &expr) { visit (expr.get_receiver_expr ()); tokens.push_back (Rust::Token::make (DOT, expr.get_locus ())); - auto field_name = expr.get_field_name (); + auto field_name = expr.get_field_name ().as_string (); tokens.push_back ( Rust::Token::make_identifier (Location (), std::move (field_name))); } @@ -1524,7 +1524,7 @@ TokenCollector::visit (TypeParam ¶m) // TypeParamBounds : // TypeParamBound ( + TypeParamBound )* +? - auto id = param.get_type_representation (); + auto id = param.get_type_representation ().as_string (); tokens.push_back ( Rust::Token::make_identifier (param.get_locus (), std::move (id))); if (param.has_type_param_bounds ()) @@ -1591,7 +1591,7 @@ void TokenCollector::visit (Method &method) { visit (method.get_visibility ()); - auto method_name = method.get_method_name (); + auto method_name = method.get_method_name ().as_string (); tokens.push_back (Rust::Token::make (FN_TOK, method.get_locus ())); tokens.push_back ( Rust::Token::make_identifier (Location (), std::move (method_name))); @@ -1632,7 +1632,7 @@ TokenCollector::visit (Module &module) visit_items_as_lines (module.get_outer_attrs ()); visit (module.get_visibility ()); - auto name = module.get_name (); + auto name = module.get_name ().as_string (); tokens.push_back (Rust::Token::make (MOD, module.get_locus ())); tokens.push_back ( Rust::Token::make_identifier (Location (), std::move (name))); @@ -1733,7 +1733,7 @@ TokenCollector::visit (UseTreeRebind &use_tree) { case UseTreeRebind::NewBindType::IDENTIFIER: { tokens.push_back (Rust::Token::make (AS, Location ())); - auto id = use_tree.get_identifier (); + auto id = use_tree.get_identifier ().as_string (); tokens.push_back ( Rust::Token::make_identifier (use_tree.get_locus (), std::move (id))); } @@ -1770,7 +1770,7 @@ TokenCollector::visit (Function &function) visit (function.get_visibility ()); tokens.push_back (Rust::Token::make (FN_TOK, function.get_locus ())); - auto name = function.get_function_name (); + auto name = function.get_function_name ().as_string (); tokens.push_back ( Rust::Token::make_identifier (Location (), std::move (name))); if (function.has_generics ()) @@ -1808,7 +1808,7 @@ TokenCollector::visit (TypeAlias &type_alias) visit_items_as_lines (type_alias.get_outer_attrs ()); if (type_alias.has_visibility ()) visit (type_alias.get_visibility ()); - auto alias_name = type_alias.get_new_type_name (); + auto alias_name = type_alias.get_new_type_name ().as_string (); tokens.push_back (Rust::Token::make (TYPE, type_alias.get_locus ())); tokens.push_back ( Rust::Token::make_identifier (Location (), std::move (alias_name))); @@ -1827,7 +1827,7 @@ TokenCollector::visit (StructStruct &struct_item) visit_items_as_lines (struct_item.get_outer_attrs ()); if (struct_item.has_visibility ()) visit (struct_item.get_visibility ()); - auto struct_name = struct_item.get_identifier (); + auto struct_name = struct_item.get_identifier ().as_string (); tokens.push_back (Rust::Token::make (STRUCT_TOK, struct_item.get_locus ())); tokens.push_back ( Rust::Token::make_identifier (Location (), std::move (struct_name))); @@ -1850,7 +1850,7 @@ void TokenCollector::visit (TupleStruct &tuple_struct) { visit_items_as_lines (tuple_struct.get_outer_attrs ()); - auto struct_name = tuple_struct.get_identifier (); + auto struct_name = tuple_struct.get_identifier ().as_string (); tokens.push_back (Rust::Token::make (STRUCT_TOK, tuple_struct.get_locus ())); tokens.push_back ( Rust::Token::make_identifier (Location (), std::move (struct_name))); @@ -1870,7 +1870,7 @@ void TokenCollector::visit (EnumItem &item) { visit_items_as_lines (item.get_outer_attrs ()); - auto id = item.get_identifier (); + auto id = item.get_identifier ().as_string (); tokens.push_back ( Rust::Token::make_identifier (item.get_locus (), std::move (id))); } @@ -1878,7 +1878,7 @@ TokenCollector::visit (EnumItem &item) void TokenCollector::visit (EnumItemTuple &item) { - auto id = item.get_identifier (); + auto id = item.get_identifier ().as_string (); tokens.push_back ( Rust::Token::make_identifier (item.get_locus (), std::move (id))); tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ())); @@ -1889,7 +1889,7 @@ TokenCollector::visit (EnumItemTuple &item) void TokenCollector::visit (EnumItemStruct &item) { - auto id = item.get_identifier (); + auto id = item.get_identifier ().as_string (); tokens.push_back ( Rust::Token::make_identifier (item.get_locus (), std::move (id))); visit_items_as_block (item.get_struct_fields (), @@ -1899,7 +1899,7 @@ TokenCollector::visit (EnumItemStruct &item) void TokenCollector::visit (EnumItemDiscriminant &item) { - auto id = item.get_identifier (); + auto id = item.get_identifier ().as_string (); tokens.push_back ( Rust::Token::make_identifier (item.get_locus (), std::move (id))); tokens.push_back (Rust::Token::make (EQUAL, Location ())); @@ -1913,7 +1913,7 @@ TokenCollector::visit (Enum &enumeration) if (enumeration.has_visibility ()) visit (enumeration.get_visibility ()); tokens.push_back (Rust::Token::make (ENUM_TOK, enumeration.get_locus ())); - auto id = enumeration.get_identifier (); + auto id = enumeration.get_identifier ().as_string (); tokens.push_back ( Rust::Token::make_identifier (enumeration.get_locus (), std::move (id))); if (enumeration.has_generics ()) @@ -1929,7 +1929,7 @@ void TokenCollector::visit (Union &union_item) { visit_items_as_lines (union_item.get_outer_attrs ()); - auto id = union_item.get_identifier (); + auto id = union_item.get_identifier ().as_string (); tokens.push_back ( Rust::Token::make_identifier (union_item.get_locus (), "union")); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); @@ -1974,7 +1974,7 @@ TokenCollector::visit (StaticItem &item) tokens.push_back (Rust::Token::make (STATIC_TOK, item.get_locus ())); if (item.is_mutable ()) tokens.push_back (Rust::Token::make (MUT, Location ())); - auto id = item.get_identifier (); + auto id = item.get_identifier ().as_string (); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); tokens.push_back (Rust::Token::make (COLON, Location ())); visit (item.get_type ()); @@ -2012,7 +2012,7 @@ void TokenCollector::visit (TraitItemFunc &item) { auto func = item.get_trait_function_decl (); - auto id = func.get_identifier (); + auto id = func.get_identifier ().as_string (); tokens.push_back (Rust::Token::make (FN_TOK, item.get_locus ())); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ())); @@ -2049,7 +2049,7 @@ void TokenCollector::visit (TraitItemMethod &item) { auto method = item.get_trait_method_decl (); - auto id = method.get_identifier (); + auto id = method.get_identifier ().as_string (); tokens.push_back (Rust::Token::make (FN_TOK, item.get_locus ())); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); @@ -2071,7 +2071,7 @@ TokenCollector::visit (TraitItemMethod &item) void TokenCollector::visit (TraitItemConst &item) { - auto id = item.get_identifier (); + auto id = item.get_identifier ().as_string (); indentation (); tokens.push_back (Rust::Token::make (CONST, item.get_locus ())); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); @@ -2084,7 +2084,7 @@ TokenCollector::visit (TraitItemConst &item) void TokenCollector::visit (TraitItemType &item) { - auto id = item.get_identifier (); + auto id = item.get_identifier ().as_string (); indentation (); tokens.push_back (Rust::Token::make (TYPE, item.get_locus ())); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); @@ -2104,7 +2104,7 @@ TokenCollector::visit (Trait &trait) visit (trait.get_visibility ()); - auto id = trait.get_identifier (); + auto id = trait.get_identifier ().as_string (); tokens.push_back (Rust::Token::make (TRAIT, trait.get_locus ())); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); @@ -2168,7 +2168,7 @@ TokenCollector::visit (ExternalTypeItem &type) { visit (type.get_visibility ()); - auto id = type.get_identifier (); + auto id = type.get_identifier ().as_string (); tokens.push_back (Rust::Token::make (TYPE, Location ())); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); tokens.push_back (Rust::Token::make (SEMICOLON, Location ())); @@ -2177,7 +2177,7 @@ TokenCollector::visit (ExternalTypeItem &type) void TokenCollector::visit (ExternalStaticItem &item) { - auto id = item.get_identifier (); + auto id = item.get_identifier ().as_string (); visit_items_as_lines (item.get_outer_attrs ()); if (item.has_visibility ()) visit (item.get_visibility ()); @@ -2197,7 +2197,7 @@ TokenCollector::visit (ExternalFunctionItem &function) { visit (function.get_visibility ()); - auto id = function.get_identifier (); + auto id = function.get_identifier ().as_string (); tokens.push_back (Rust::Token::make (FN_TOK, function.get_locus ())); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ())); @@ -2247,7 +2247,7 @@ get_delimiters (DelimType delim) void TokenCollector::visit (MacroMatchFragment &match) { - auto id = match.get_ident (); + auto id = match.get_ident ().as_string (); auto frag_spec = match.get_frag_spec ().as_string (); tokens.push_back (Rust::Token::make (DOLLAR_SIGN, Location ())); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); @@ -2318,7 +2318,7 @@ TokenCollector::visit (MacroRulesDefinition &rules_def) for (auto &outer_attr : rules_def.get_outer_attrs ()) visit (outer_attr); - auto rule_name = rules_def.get_rule_name (); + auto rule_name = rules_def.get_rule_name ().as_string (); tokens.push_back ( Rust::Token::make_identifier (rules_def.get_locus (), "macro_rules")); tokens.push_back (Rust::Token::make (EXCLAM, Location ())); @@ -2361,7 +2361,7 @@ TokenCollector::visit (MetaItemSeq &item) void TokenCollector::visit (MetaWord &word) { - auto id = word.get_ident (); + auto id = word.get_ident ().as_string (); tokens.push_back ( Rust::Token::make_identifier (word.get_locus (), std::move (id))); } @@ -2370,7 +2370,7 @@ void TokenCollector::visit (MetaNameValueStr &name) { auto pair = name.get_name_value_pair (); - auto id = std::get<0> (pair); + auto id = std::get<0> (pair).as_string (); auto value = std::get<1> (pair); tokens.push_back ( Rust::Token::make_identifier (name.get_locus (), std::move (id))); @@ -2384,7 +2384,7 @@ TokenCollector::visit (MetaNameValueStr &name) void TokenCollector::visit (MetaListPaths &list) { - auto id = list.get_ident (); + auto id = list.get_ident ().as_string (); tokens.push_back ( Rust::Token::make_identifier (list.get_locus (), std::move (id))); tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ())); @@ -2395,7 +2395,7 @@ TokenCollector::visit (MetaListPaths &list) void TokenCollector::visit (MetaListNameValueStr &list) { - auto id = list.get_ident (); + auto id = list.get_ident ().as_string (); tokens.push_back ( Rust::Token::make_identifier (list.get_locus (), std::move (id))); tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ())); @@ -2421,7 +2421,7 @@ TokenCollector::visit (IdentifierPattern &pattern) { tokens.push_back (Rust::Token::make (MUT, Location ())); } - auto id = pattern.get_ident (); + auto id = pattern.get_ident ().as_string (); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); if (pattern.has_pattern_to_bind ()) { @@ -2528,7 +2528,7 @@ void TokenCollector::visit (StructPatternFieldIdentPat &pattern) { visit_items_as_lines (pattern.get_outer_attrs ()); - auto id = pattern.get_identifier (); + auto id = pattern.get_identifier ().as_string (); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); tokens.push_back (Rust::Token::make (COLON, pattern.get_locus ())); visit (pattern.get_ident_pattern ()); @@ -2543,7 +2543,7 @@ TokenCollector::visit (StructPatternFieldIdent &pattern) if (pattern.is_mut ()) tokens.push_back (Rust::Token::make (MUT, Location ())); - auto id = pattern.get_identifier (); + auto id = pattern.get_identifier ().as_string (); tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id))); } diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 14ad3a0..24e719c 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -251,7 +251,7 @@ VisItem::as_string () const std::string Module::as_string () const { - std::string str = VisItem::as_string () + "mod " + module_name; + std::string str = VisItem::as_string () + "mod " + module_name.as_string (); // Return early if we're dealing with an unloaded module as their body resides // in a different file @@ -298,7 +298,7 @@ StaticItem::as_string () const if (has_mut) str += " mut"; - str += " " + name; + str += " " + name.as_string (); // DEBUG: null pointer check if (type == nullptr) @@ -339,7 +339,7 @@ TupleStruct::as_string () const { std::string str = VisItem::as_string (); - str += "struct " + struct_name; + str += "struct " + struct_name.as_string (); // generic params str += "\n Generic params: "; @@ -476,7 +476,7 @@ Method::as_string () const str += vis.as_string () + " " + qualifiers.as_string (); - str += " fn " + method_name; + str += " fn " + method_name.as_string (); // generic params str += "\n Generic params: "; @@ -537,7 +537,7 @@ StructStruct::as_string () const { std::string str = VisItem::as_string (); - str += "struct " + struct_name; + str += "struct " + struct_name.as_string (); // generic params str += "\n Generic params: "; @@ -686,7 +686,7 @@ UseTreeRebind::as_string () const // nothing to add, just path break; case IDENTIFIER: - path_str += " as " + identifier; + path_str += " as " + identifier.as_string (); break; case WILDCARD: path_str += " as _"; @@ -703,7 +703,7 @@ std::string Enum::as_string () const { std::string str = VisItem::as_string (); - str += enum_name; + str += enum_name.as_string (); // generic params str += "\n Generic params: "; @@ -768,7 +768,7 @@ Trait::as_string () const if (has_unsafe) str += "unsafe "; - str += "trait " + name; + str += "trait " + name.as_string (); // generic params str += "\n Generic params: "; @@ -851,7 +851,7 @@ Union::as_string () const { std::string str = VisItem::as_string (); - str += "union " + union_name; + str += "union " + union_name.as_string (); // generic params str += "\n Generic params: "; @@ -923,7 +923,7 @@ Function::as_string () const str += "void "; } - str += function_name; + str += function_name.as_string (); if (has_generics ()) { @@ -1110,7 +1110,7 @@ TypeAlias::as_string () const { std::string str = VisItem::as_string (); - str += " " + new_type_name; + str += " " + new_type_name.as_string (); // generic params str += "\n Generic params: "; @@ -1192,7 +1192,7 @@ MacroRulesDefinition::as_string () const // TODO: deal with macro_2_0 str += "macro_rules!"; - str += rule_name; + str += rule_name.as_string (); str += "\n Macro rules: "; if (rules.empty ()) @@ -1559,7 +1559,7 @@ std::string FieldAccessExpr::as_string () const { // TODO: rewrite dump to better reflect non-literal exprs - return receiver->as_string () + "." + field; + return receiver->as_string () + "." + field.as_string (); } std::string @@ -2179,7 +2179,7 @@ LifetimeParam::as_string () const std::string MacroMatchFragment::as_string () const { - return "$" + ident + ": " + frag_spec.as_string (); + return "$" + ident.as_string () + ": " + frag_spec.as_string (); } std::string @@ -2256,7 +2256,7 @@ TypeParam::as_string () const else str += outer_attr.as_string (); - str += "\n Identifier: " + type_representation; + str += "\n Identifier: " + type_representation.as_string (); str += "\n Type param bounds: "; if (!has_type_param_bounds ()) @@ -2565,7 +2565,7 @@ std::string StructExprFieldIdentifierValue::as_string () const { // TODO: rewrite to work with non-linearisable exprs - return field_name + " : " + StructExprFieldWithVal::as_string (); + return field_name.as_string () + " : " + StructExprFieldWithVal::as_string (); } std::string @@ -2604,7 +2604,7 @@ std::string EnumItem::as_string () const { std::string str = VisItem::as_string (); - str += variant_name; + str += variant_name.as_string (); return str; } @@ -2691,7 +2691,7 @@ StructField::as_string () const if (has_visibility ()) str += "\n" + visibility.as_string (); - str += " " + field_name + " : " + field_type->as_string (); + str += " " + field_name.as_string () + " : " + field_type->as_string (); return str; } @@ -2713,7 +2713,7 @@ ExternalTypeItem::as_string () const { auto str = append_attributes (outer_attrs, OUTER); - str += "type " + item_name + ";"; + str += "type " + item_name.as_string () + ";"; return str; } @@ -2733,7 +2733,7 @@ ExternalStaticItem::as_string () const str += "mut "; // add name - str += item_name; + str += item_name.as_string (); // add type on new line str += "\n Type: " + item_type->as_string (); @@ -2753,7 +2753,7 @@ ExternalFunctionItem::as_string () const str += "fn "; // add name - str += item_name; + str += item_name.as_string (); // generic params str += "\n Generic params: "; @@ -2850,7 +2850,8 @@ TraitItemFunc::as_string () const std::string TraitFunctionDecl::as_string () const { - std::string str = qualifiers.as_string () + "fn " + function_name; + std::string str + = qualifiers.as_string () + "fn " + function_name.as_string (); // generic params str += "\n Generic params: "; @@ -2920,7 +2921,8 @@ TraitItemMethod::as_string () const std::string TraitMethodDecl::as_string () const { - std::string str = qualifiers.as_string () + "fn " + function_name; + std::string str + = qualifiers.as_string () + "fn " + function_name.as_string (); // generic params str += "\n Generic params: "; @@ -2979,7 +2981,7 @@ TraitItemConst::as_string () const // TODO: rewrite to work with non-linearisable exprs std::string str = append_attributes (outer_attrs, OUTER); - str += "\nconst " + name + " : " + type->as_string (); + str += "\nconst " + name.as_string () + " : " + type->as_string (); if (has_expression ()) str += " = " + expr->as_string (); @@ -2992,7 +2994,7 @@ TraitItemType::as_string () const { std::string str = append_attributes (outer_attrs, OUTER); - str += "\ntype " + name; + str += "\ntype " + name.as_string (); str += "\n Type param bounds: "; if (!has_type_param_bounds ()) @@ -3167,7 +3169,7 @@ MaybeNamedParam::as_string () const case UNNAMED: break; case IDENTIFIER: - str = name + " : "; + str = name.as_string () + " : "; break; case WILDCARD: str = "_ : "; @@ -3216,7 +3218,7 @@ MetaItemSeq::as_string () const std::string MetaListPaths::as_string () const { - std::string str = ident + "("; + std::string str = ident.as_string () + "("; auto i = paths.begin (); auto e = paths.end (); @@ -3234,7 +3236,7 @@ MetaListPaths::as_string () const std::string MetaListNameValueStr::as_string () const { - std::string str = ident + "("; + std::string str = ident.as_string () + "("; auto i = strs.begin (); auto e = strs.end (); @@ -3313,7 +3315,7 @@ Module::process_file_path () // file that contains the 'mod <file>;' directive std::string including_fpath (outer_filename); - std::string expected_file_path = module_name + ".rs"; + std::string expected_file_path = module_name.as_string () + ".rs"; std::string expected_dir_path = "mod.rs"; auto dir_slash_pos = including_fpath.rfind (file_separator); @@ -3366,8 +3368,8 @@ Module::process_file_path () bool file_mod_found = file_exists (file_mod_path); // Then, search for <directory>/<module_name>/mod.rs - std::string dir_mod_path - = current_directory_name + module_name + file_separator + expected_dir_path; + std::string dir_mod_path = current_directory_name + module_name.as_string () + + file_separator + expected_dir_path; bool dir_mod_found = file_exists (dir_mod_path); bool multiple_candidates_found = file_mod_found && dir_mod_found; @@ -3376,12 +3378,13 @@ Module::process_file_path () if (multiple_candidates_found) rust_error_at (locus, "two candidates found for module %s: %s.rs and %s%smod.rs", - module_name.c_str (), module_name.c_str (), - module_name.c_str (), file_separator); + module_name.as_string ().c_str (), + module_name.as_string ().c_str (), + module_name.as_string ().c_str (), file_separator); if (no_candidates_found) rust_error_at (locus, "no candidate found for module %s", - module_name.c_str ()); + module_name.as_string ().c_str ()); if (no_candidates_found || multiple_candidates_found) return; @@ -3878,7 +3881,7 @@ MetaItemLitExpr::check_cfg_predicate (const Session &) const bool MetaListNameValueStr::check_cfg_predicate (const Session &session) const { - if (ident == "all") + if (ident.as_string () == "all") { for (const auto &str : strs) { @@ -3887,7 +3890,7 @@ MetaListNameValueStr::check_cfg_predicate (const Session &session) const } return true; } - else if (ident == "any") + else if (ident.as_string () == "any") { for (const auto &str : strs) { @@ -3896,7 +3899,7 @@ MetaListNameValueStr::check_cfg_predicate (const Session &session) const } return false; } - else if (ident == "not") + else if (ident.as_string () == "not") { if (strs.size () != 1) { @@ -3918,7 +3921,7 @@ MetaListNameValueStr::check_cfg_predicate (const Session &session) const "cfg predicate could not be checked for " "MetaListNameValueStr with ident of " "'%s' - ident must be 'all' or 'any'", - ident.c_str ()); + ident.as_string ().c_str ()); return false; } } @@ -3926,7 +3929,7 @@ MetaListNameValueStr::check_cfg_predicate (const Session &session) const bool MetaListPaths::check_cfg_predicate (const Session &session) const { - if (ident == "all") + if (ident.as_string () == "all") { for (const auto &path : paths) { @@ -3935,7 +3938,7 @@ MetaListPaths::check_cfg_predicate (const Session &session) const } return true; } - else if (ident == "any") + else if (ident.as_string () == "any") { for (const auto &path : paths) { @@ -3944,7 +3947,7 @@ MetaListPaths::check_cfg_predicate (const Session &session) const } return false; } - else if (ident == "not") + else if (ident.as_string () == "not") { if (paths.size () != 1) { @@ -3966,7 +3969,7 @@ MetaListPaths::check_cfg_predicate (const Session &session) const "cfg predicate could not be checked for " "MetaListNameValueStr with ident of " "'%s' - ident must be 'all' or 'any'", - ident.c_str ()); + ident.as_string ().c_str ()); return false; } } @@ -4029,7 +4032,7 @@ MetaItemSeq::check_cfg_predicate (const Session &session) const bool MetaWord::check_cfg_predicate (const Session &session) const { - return session.options.target_data.has_key (ident); + return session.options.target_data.has_key (ident.as_string ()); } bool @@ -4048,10 +4051,13 @@ MetaNameValueStr::check_cfg_predicate (const Session &session) const // DEBUG rust_debug ( "checked key-value pair for cfg: '%s', '%s' - is%s in target data", - ident.c_str (), str.c_str (), - session.options.target_data.has_key_value_pair (ident, str) ? "" : " not"); + ident.as_string ().c_str (), str.c_str (), + session.options.target_data.has_key_value_pair (ident.as_string (), str) + ? "" + : " not"); - return session.options.target_data.has_key_value_pair (ident, str); + return session.options.target_data.has_key_value_pair (ident.as_string (), + str); } bool @@ -4080,7 +4086,7 @@ MetaNameValueStr::to_attribute () const // FIXME: What location do we put here? Is the literal above supposed to have // an empty location as well? // Should MetaNameValueStr keep a location? - return Attribute (SimplePath::from_str (ident, ident_locus), + return Attribute (SimplePath::from_str (ident.as_string (), ident_locus), std::unique_ptr<AttrInputLiteral> ( new AttrInputLiteral (std::move (lit_expr)))); } @@ -4107,7 +4113,8 @@ MetaItemSeq::to_attribute () const Attribute MetaWord::to_attribute () const { - return Attribute (SimplePath::from_str (ident, ident_locus), nullptr); + return Attribute (SimplePath::from_str (ident.as_string (), ident_locus), + nullptr); } Attribute @@ -4125,7 +4132,7 @@ MetaListPaths::to_attribute () const std::unique_ptr<AttrInputMetaItemContainer> new_seq_container ( new AttrInputMetaItemContainer (std::move (new_seq))); - return Attribute (SimplePath::from_str (ident, ident_locus), + return Attribute (SimplePath::from_str (ident.as_string (), ident_locus), std::move (new_seq_container)); } @@ -4140,7 +4147,7 @@ MetaListNameValueStr::to_attribute () const std::unique_ptr<AttrInputMetaItemContainer> new_seq_container ( new AttrInputMetaItemContainer (std::move (new_seq))); - return Attribute (SimplePath::from_str (ident, ident_locus), + return Attribute (SimplePath::from_str (ident.as_string (), ident_locus), std::move (new_seq_container)); } @@ -4986,4 +4993,11 @@ MetaWord::accept_vis (ASTVisitor &vis) } } // namespace AST + +std::ostream & +operator<< (std::ostream &os, Identifier const &i) +{ + return os << i.as_string (); +} + } // namespace Rust diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 893b4bb..a4caee7 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -28,11 +28,30 @@ namespace Rust { // TODO: remove typedefs and make actual types for these -typedef std::string Identifier; typedef int TupleIndex; struct Session; struct MacroExpander; +class Identifier +{ +public: + Identifier (std::string ident = "") + : ident (ident), node_id (Analysis::Mappings::get ()->get_next_node_id ()) + {} + + NodeId get_node_id () const { return node_id; } + const std::string &as_string () const { return ident; } + + bool empty () const { return ident.empty (); } + +private: + std::string ident; + NodeId node_id; +}; + +std::ostream & +operator<< (std::ostream &os, Identifier const &i); + namespace AST { // foward decl: ast visitor class ASTVisitor; @@ -60,11 +79,11 @@ class Node : public Visitable public: /** * Get the kind of Node this is. This is used to differentiate various AST - * elements with very little overhead when extracting the derived type through - * static casting is not necessary. + * elements with very little overhead when extracting the derived type + * through static casting is not necessary. */ - // FIXME: Mark this as `= 0` in the future to make sure every node implements - // it + // FIXME: Mark this as `= 0` in the future to make sure every node + // implements it virtual Kind get_ast_kind () const { return Kind::UNKNOWN; } }; @@ -93,8 +112,8 @@ public: virtual std::string as_string () const = 0; - /* Converts token tree to a flat token stream. Tokens must be pointer to avoid - * mutual dependency with Token. */ + /* Converts token tree to a flat token stream. Tokens must be pointer to + * avoid mutual dependency with Token. */ virtual std::vector<std::unique_ptr<Token>> to_token_stream () const = 0; protected: @@ -151,9 +170,9 @@ class Token : public TokenTree, public MacroMatch const_TokenPtr tok_ref; - /* new idea: wrapper around const_TokenPtr used for heterogeneuous storage in - * token trees. rather than convert back and forth when parsing macros, just - * wrap it. */ + /* new idea: wrapper around const_TokenPtr used for heterogeneuous storage + * in token trees. rather than convert back and forth when parsing macros, + * just wrap it. */ public: // Unique pointer custom clone function @@ -250,15 +269,15 @@ protected: // No virtual for now as not polymorphic but can be in future /*virtual*/ Token *clone_token_impl () const { return new Token (*this); } - /* Use covariance to implement clone function as returning this object rather - * than base */ + /* Use covariance to implement clone function as returning this object + * rather than base */ Token *clone_token_tree_impl () const final override { return clone_token_impl (); } - /* Use covariance to implement clone function as returning this object rather - * than base */ + /* Use covariance to implement clone function as returning this object + * rather than base */ Token *clone_macro_match_impl () const final override { return clone_token_impl (); @@ -282,8 +301,8 @@ public: }; private: - /* TODO: maybe make subclasses of each type of literal with their typed values - * (or generics) */ + /* TODO: maybe make subclasses of each type of literal with their typed + * values (or generics) */ std::string value_as_string; LitType type; PrimitiveCoreType type_hint; @@ -310,8 +329,8 @@ public: bool is_error () const { return type == ERROR; } }; -/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to - * be defined */ +/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr + * to be defined */ class AttrInputLiteral; /* TODO: move applicable stuff into here or just don't include it because @@ -571,8 +590,8 @@ public: // Call to parse attribute body to meta item syntax. void parse_attr_to_meta_item (); - /* Determines whether cfg predicate is true and item with attribute should not - * be stripped. Attribute body must already be parsed to meta item. */ + /* Determines whether cfg predicate is true and item with attribute should + * not be stripped. Attribute body must already be parsed to meta item. */ bool check_cfg_predicate (const Session &session) const; // Returns whether body has been parsed to meta item form or not. @@ -583,7 +602,8 @@ public: std::vector<Attribute> separate_cfg_attrs () const; protected: - // not virtual as currently no subclasses of Attribute, but could be in future + // not virtual as currently no subclasses of Attribute, but could be in + // future /*virtual*/ Attribute *clone_attribute_impl () const { return new Attribute (*this); @@ -849,8 +869,8 @@ public: DelimType get_delim_type () const { return delim_type; } }; -/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to - * be defined */ +/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr + * to be defined */ class AttrInputLiteral; // abstract base meta item class @@ -879,8 +899,9 @@ class MetaListPaths; // Forward decl - defined in rust-macro.h class MetaListNameValueStr; -/* Base statement abstract class. Note that most "statements" are not allowed in - * top-level module scope - only a subclass of statements called "items" are. */ +/* Base statement abstract class. Note that most "statements" are not allowed + * in top-level module scope - only a subclass of statements called "items" + * are. */ class Stmt : public Node { public: @@ -1022,9 +1043,9 @@ protected: // pure virtual clone implementation virtual ExprWithoutBlock *clone_expr_without_block_impl () const = 0; - /* Save having to specify two clone methods in derived classes by making expr - * clone return exprwithoutblock clone. Hopefully won't affect performance too - * much. */ + /* Save having to specify two clone methods in derived classes by making + * expr clone return exprwithoutblock clone. Hopefully won't affect + * performance too much. */ ExprWithoutBlock *clone_expr_impl () const final override { return clone_expr_without_block_impl (); @@ -1042,7 +1063,8 @@ public: /* HACK: IdentifierExpr, delete when figure out identifier vs expr problem in * Pratt parser */ -/* Alternatively, identifiers could just be represented as single-segment paths +/* Alternatively, identifiers could just be represented as single-segment + * paths */ class IdentifierExpr : public ExprWithoutBlock { @@ -1057,7 +1079,7 @@ public: locus (locus) {} - std::string as_string () const override { return ident; } + std::string as_string () const override { return ident.as_string (); } Location get_locus () const override final { return locus; } @@ -1181,9 +1203,9 @@ protected: // Clone function implementation as pure virtual method virtual TypeNoBounds *clone_type_no_bounds_impl () const = 0; - /* Save having to specify two clone methods in derived classes by making type - * clone return typenobounds clone. Hopefully won't affect performance too - * much. */ + /* Save having to specify two clone methods in derived classes by making + * type clone return typenobounds clone. Hopefully won't affect performance + * too much. */ TypeNoBounds *clone_type_impl () const final override { return clone_type_no_bounds_impl (); @@ -1192,8 +1214,8 @@ protected: TypeNoBounds () : Type () {} }; -/* Abstract base class representing a type param bound - Lifetime and TraitBound - * extends it */ +/* Abstract base class representing a type param bound - Lifetime and + * TraitBound extends it */ class TypeParamBound : public Visitable { public: @@ -1271,16 +1293,16 @@ public: std::string get_lifetime_name () const { return lifetime_name; } protected: - /* Use covariance to implement clone function as returning this object rather - * than base */ + /* Use covariance to implement clone function as returning this object + * rather than base */ Lifetime *clone_type_param_bound_impl () const override { return new Lifetime (node_id, lifetime_type, lifetime_name, locus); } }; -/* Base generic parameter in AST. Abstract - can be represented by a Lifetime or - * Type param */ +/* Base generic parameter in AST. Abstract - can be represented by a Lifetime + * or Type param */ class GenericParam : public Visitable { public: @@ -1363,8 +1385,8 @@ public: Kind get_kind () const override final { return Kind::Lifetime; } protected: - /* Use covariance to implement clone function as returning this object rather - * than base */ + /* Use covariance to implement clone function as returning this object + * rather than base */ LifetimeParam *clone_generic_param_impl () const override { return new LifetimeParam (*this); @@ -1957,4 +1979,15 @@ class PathExpr : public ExprWithoutBlock } // namespace AST } // namespace Rust +namespace std { +template <> struct less<Rust::Identifier> +{ + bool operator() (const Rust::Identifier &lhs, + const Rust::Identifier &rhs) const + { + return lhs.as_string () < rhs.as_string (); + } +}; +} // namespace std + #endif diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 8ea2c8c..9a1da7a 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -1667,7 +1667,7 @@ public: locus (locus) {} - std::string as_string () const override { return field_name; } + std::string as_string () const override { return field_name.as_string (); } Location get_locus () const override final { return locus; } @@ -1741,7 +1741,7 @@ public: void accept_vis (ASTVisitor &vis) override; - std::string get_field_name () const { return field_name; } + std::string get_field_name () const { return field_name.as_string (); } Location get_locus () const override final { return locus; } diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 4563f61..5b3529b 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -752,7 +752,7 @@ public: // Creates an error state method. static Method create_error () { - return Method ("", FunctionQualifiers (Location (), NONE, true), + return Method ({""}, FunctionQualifiers (Location (), NONE, true), std::vector<std::unique_ptr<GenericParam>> (), SelfParam::create_error (), std::vector<FunctionParam> (), nullptr, WhereClause::create_empty (), nullptr, @@ -1136,7 +1136,7 @@ public: Location get_locus () const override final { return locus; } // Invalid if name is empty, so base stripping on that. - void mark_for_strip () override { module_name = ""; } + void mark_for_strip () override { module_name = {""}; } bool is_marked_for_strip () const override { return module_name.empty (); } protected: @@ -1865,7 +1865,7 @@ public: Location get_locus () const override final { return locus; } // Invalid if name is empty, so base stripping on that. - void mark_for_strip () override { struct_name = ""; } + void mark_for_strip () override { struct_name = {""}; } bool is_marked_for_strip () const override { return struct_name.empty (); } Identifier get_struct_name () const { return struct_name; } @@ -2240,7 +2240,7 @@ public: Identifier get_identifier () const { return variant_name; } // Based on idea that name is never empty. - void mark_for_strip () override { variant_name = ""; } + void mark_for_strip () override { variant_name = {""}; } bool is_marked_for_strip () const override { return variant_name.empty (); } protected: @@ -2461,7 +2461,7 @@ public: Identifier get_identifier () const { return enum_name; } // Invalid if name is empty, so base stripping on that. - void mark_for_strip () override { enum_name = ""; } + void mark_for_strip () override { enum_name = {""}; } bool is_marked_for_strip () const override { return enum_name.empty (); } // TODO: this mutable getter seems really dodgy. Think up better way. @@ -2561,7 +2561,7 @@ public: void accept_vis (ASTVisitor &vis) override; // Invalid if name is empty, so base stripping on that. - void mark_for_strip () override { union_name = ""; } + void mark_for_strip () override { union_name = {""}; } bool is_marked_for_strip () const override { return union_name.empty (); } // TODO: this mutable getter seems really dodgy. Think up better way. @@ -2907,7 +2907,7 @@ public: std::string as_string () const; // Invalid if function name is empty, so base stripping on that. - void mark_for_strip () { function_name = ""; } + void mark_for_strip () { function_name = {""}; } bool is_marked_for_strip () const { return function_name.empty (); } // TODO: this mutable getter seems really dodgy. Think up better way. @@ -3120,7 +3120,7 @@ public: std::string as_string () const; // Invalid if method name is empty, so base stripping on that. - void mark_for_strip () { function_name = ""; } + void mark_for_strip () { function_name = {""}; } bool is_marked_for_strip () const { return function_name.empty (); } // TODO: this mutable getter seems really dodgy. Think up better way. @@ -3399,7 +3399,7 @@ public: void accept_vis (ASTVisitor &vis) override; // Invalid if name is empty, so base stripping on that. - void mark_for_strip () override { name = ""; } + void mark_for_strip () override { name = {""}; } bool is_marked_for_strip () const override { return name.empty (); } // TODO: this mutable getter seems really dodgy. Think up better way. @@ -3534,7 +3534,7 @@ public: void accept_vis (ASTVisitor &vis) override; // Invalid if trait name is empty, so base stripping on that. - void mark_for_strip () override { name = ""; } + void mark_for_strip () override { name = {""}; } bool is_marked_for_strip () const override { return name.empty (); } // TODO: think of better way to do this @@ -4346,7 +4346,7 @@ public: void accept_vis (ASTVisitor &vis) override; // Based on idea that nane should never be empty. - void mark_for_strip () override { item_name = ""; }; + void mark_for_strip () override { item_name = {""}; }; bool is_marked_for_strip () const override { return item_name.empty (); }; // TODO: this mutable getter seems really dodgy. Think up better way. diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 77c9b84..877df2a 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -537,7 +537,7 @@ public: void accept_vis (ASTVisitor &vis) override; // Invalid if rule name is empty, so base stripping on that. - void mark_for_strip () override { rule_name = ""; } + void mark_for_strip () override { rule_name = {""}; } bool is_marked_for_strip () const override { return rule_name.empty (); } // TODO: this mutable getter seems really dodgy. Think up better way. @@ -921,7 +921,7 @@ public: : ident (std::move (ident)), ident_locus (ident_locus) {} - std::string as_string () const override { return ident; } + std::string as_string () const override { return ident.as_string (); } void accept_vis (ASTVisitor &vis) override; @@ -960,7 +960,7 @@ public: std::string as_string () const override { - return ident + " = \"" + str + "\""; + return ident.as_string () + " = \"" + str + "\""; } void accept_vis (ASTVisitor &vis) override; diff --git a/gcc/rust/ast/rust-path.cc b/gcc/rust/ast/rust-path.cc index 9a3489b..ee6a6fb 100644 --- a/gcc/rust/ast/rust-path.cc +++ b/gcc/rust/ast/rust-path.cc @@ -96,7 +96,7 @@ GenericArg::disambiguate_to_type () const rust_assert (get_kind () == Kind::Either); auto segment = std::unique_ptr<TypePathSegment> ( - new TypePathSegment (path, false, locus)); + new TypePathSegment (path.as_string (), false, locus)); auto segments = std::vector<std::unique_ptr<TypePathSegment>> (); segments.emplace_back (std::move (segment)); @@ -108,14 +108,14 @@ std::string GenericArgsBinding::as_string () const { // TODO: rewrite to work with non-literalisable types - return identifier + " = " + type->as_string (); + return identifier.as_string () + " = " + type->as_string (); } std::string ConstGenericParam::as_string () const { std::string str ("ConstGenericParam: "); - str += "const " + name + ": " + type->as_string (); + str += "const " + name.as_string () + ": " + type->as_string (); if (has_default_value ()) str += " = " + get_default_value ().as_string (); diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h index 8e4eb19..cad9d5d 100644 --- a/gcc/rust/ast/rust-path.h +++ b/gcc/rust/ast/rust-path.h @@ -77,7 +77,7 @@ public: // Creates an error state generic args binding. static GenericArgsBinding create_error () { - return GenericArgsBinding ("", nullptr); + return GenericArgsBinding ({""}, nullptr); } // Pointer type for type in constructor to enable polymorphism @@ -159,19 +159,20 @@ public: static GenericArg create_error () { - return GenericArg (nullptr, nullptr, "", Kind::Error, Location ()); + return GenericArg (nullptr, nullptr, {""}, Kind::Error, Location ()); } static GenericArg create_const (std::unique_ptr<Expr> expression) { auto locus = expression->get_locus (); - return GenericArg (std::move (expression), nullptr, "", Kind::Const, locus); + return GenericArg (std::move (expression), nullptr, {""}, Kind::Const, + locus); } static GenericArg create_type (std::unique_ptr<Type> type) { auto locus = type->get_locus (); - return GenericArg (nullptr, std::move (type), "", Kind::Type, locus); + return GenericArg (nullptr, std::move (type), {""}, Kind::Type, locus); } static GenericArg create_ambiguous (Identifier path, Location locus) @@ -245,7 +246,7 @@ public: { rust_assert (kind == Kind::Either); - return path; + return path.as_string (); } std::string as_string () const @@ -255,7 +256,7 @@ public: case Kind::Error: gcc_unreachable (); case Kind::Either: - return "Ambiguous: " + path; + return "Ambiguous: " + path.as_string (); case Kind::Const: return "Const: { " + expression->as_string () + " }"; case Kind::Type: diff --git a/gcc/rust/ast/rust-pattern.cc b/gcc/rust/ast/rust-pattern.cc index 14179ca..e4712c3 100644 --- a/gcc/rust/ast/rust-pattern.cc +++ b/gcc/rust/ast/rust-pattern.cc @@ -48,7 +48,7 @@ IdentifierPattern::as_string () const if (is_mut) str += "mut "; - str += variable_ident; + str += variable_ident.as_string (); if (has_pattern_to_bind ()) str += " @ " + to_bind->as_string (); @@ -126,7 +126,7 @@ StructPatternFieldIdentPat::as_string () const str += "\n"; - str += ident + " : " + ident_pattern->as_string (); + str += ident.as_string () + " : " + ident_pattern->as_string (); return str; } @@ -144,7 +144,7 @@ StructPatternFieldIdent::as_string () const if (has_mut) str += "mut "; - str += ident; + str += ident.as_string (); return str; } diff --git a/gcc/rust/ast/rust-type.h b/gcc/rust/ast/rust-type.h index 7fa1bc6..7b679d5 100644 --- a/gcc/rust/ast/rust-type.h +++ b/gcc/rust/ast/rust-type.h @@ -813,7 +813,7 @@ public: // Creates an error state param. static MaybeNamedParam create_error () { - return MaybeNamedParam ("", UNNAMED, nullptr, {}, Location ()); + return MaybeNamedParam ({""}, UNNAMED, nullptr, {}, Location ()); } Location get_locus () const { return locus; } |