diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-07-31 12:31:58 +0200 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2023-09-05 14:05:36 +0000 |
commit | 7cfad27662370008db7fa1dd1e2635d02ca312a9 (patch) | |
tree | 7a38427c61fee07dcfe47ef686ef58a5dad88b4f /gcc | |
parent | 133d96c3756c4b4d13533d28845baedbd633f8f0 (diff) | |
download | gcc-7cfad27662370008db7fa1dd1e2635d02ca312a9.zip gcc-7cfad27662370008db7fa1dd1e2635d02ca312a9.tar.gz gcc-7cfad27662370008db7fa1dd1e2635d02ca312a9.tar.bz2 |
Change trait getter to return references
Having copy and any other constructor stuff might lead to a breakage in
the future where the node id differs due to a newly constructed
SimplePath node. This change will allow us to assert the NodeId is from
the ast and not any copy made in between.
gcc/rust/ChangeLog:
* ast/rust-ast.cc (Attribute::get_traits_to_derive): Change
return type to a vector of references.
* ast/rust-ast.h: Update constructor.
* expand/rust-expand-visitor.cc (ExpandVisitor::expand_inner_stmts):
Update function call.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-ast.cc | 6 | ||||
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 2 | ||||
-rw-r--r-- | gcc/rust/expand/rust-expand-visitor.cc | 4 |
3 files changed, 6 insertions, 6 deletions
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index e7b3db0..5534590 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -95,15 +95,15 @@ Attribute::is_derive () const * * @param attrs The attributes on the item to derive */ -std::vector<AST::SimplePath> +std::vector<std::reference_wrapper<AST::SimplePath>> Attribute::get_traits_to_derive () { - std::vector<AST::SimplePath> result; + std::vector<std::reference_wrapper<AST::SimplePath>> result; auto &input = get_attr_input (); switch (input.get_attr_input_type ()) { case AST::AttrInput::META_ITEM: { - auto meta = static_cast<AST::AttrInputMetaItemContainer &> (input); + auto &meta = static_cast<AST::AttrInputMetaItemContainer &> (input); for (auto ¤t : meta.get_items ()) { // HACK: Find a better way to achieve the downcast. diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 3fb0cd1..db55f01 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -519,7 +519,7 @@ public: bool is_derive () const; - std::vector<AST::SimplePath> get_traits_to_derive (); + std::vector<std::reference_wrapper<AST::SimplePath>> get_traits_to_derive (); // default destructor ~Attribute () = default; diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index f75069b..55d5de0 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -185,7 +185,7 @@ ExpandVisitor::expand_inner_items ( for (auto &to_derive : traits_to_derive) { auto maybe_builtin = MacroBuiltin::builtins.lookup ( - to_derive.as_string ()); + to_derive.get ().as_string ()); if (MacroBuiltin::builtins.is_iter_ok (maybe_builtin)) { auto new_item @@ -271,7 +271,7 @@ ExpandVisitor::expand_inner_stmts (AST::BlockExpr &expr) for (auto &to_derive : traits_to_derive) { auto maybe_builtin = MacroBuiltin::builtins.lookup ( - to_derive.as_string ()); + to_derive.get ().as_string ()); if (MacroBuiltin::builtins.is_iter_ok (maybe_builtin)) { auto new_item |