public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7690] gccrs: expand: Change names and document behavior
@ 2024-01-16 17:54 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 17:54 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:1891acf2bdd0cdce74e53c7c90ddedae47742624
commit r14-7690-g1891acf2bdd0cdce74e53c7c90ddedae47742624
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Wed Jun 21 15:56:26 2023 +0200
gccrs: expand: Change names and document behavior
Change some argument name, as well as some documentation.
gcc/rust/ChangeLog:
* ast/rust-ast.cc (BlockExpr::normalize_tail_expr): Refactor
code and warn about dangling reference.
* expand/rust-expand-visitor.cc (expand_stmt_attribute):
Document function and change argument names to make those
clearer.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diff:
---
gcc/rust/ast/rust-ast.cc | 4 +++-
gcc/rust/expand/rust-expand-visitor.cc | 10 ++++++++--
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 2eac09ba5d3..14ad3a05620 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -4228,8 +4228,10 @@ BlockExpr::normalize_tail_expr ()
if (!expr)
{
// HACK: try to turn the last statement into a tail expression
- if (statements.size () && statements.back ()->is_expr ())
+ if (!statements.empty () && statements.back ()->is_expr ())
{
+ // Watch out: This reference become invalid when the vector is
+ // modified.
auto &stmt = static_cast<ExprStmt &> (*statements.back ());
if (!stmt.is_semicolon_followed ())
diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc
index 28ff3df3148..055f723fc75 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -149,12 +149,18 @@ expand_item_attribute (AST::Item &item, AST::SimplePath &name,
return result;
}
+/* Helper function to expand a given attribute on a statement and collect back
+ * statements.
+ * T should be anything that can be used as a statement accepting outer
+ * attributes.
+ */
template <typename T>
static std::vector<std::unique_ptr<AST::Stmt>>
-expand_stmt_attribute (T &item, AST::SimplePath &name, MacroExpander &expander)
+expand_stmt_attribute (T &statement, AST::SimplePath &attribute,
+ MacroExpander &expander)
{
std::vector<std::unique_ptr<AST::Stmt>> result;
- auto frag = expander.expand_attribute_proc_macro (item, name);
+ auto frag = expander.expand_attribute_proc_macro (statement, attribute);
if (!frag.is_error ())
{
for (auto &node : frag.get_nodes ())
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-16 17:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 17:54 [gcc r14-7690] gccrs: expand: Change names and document behavior Arthur Cohen
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).