public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-8146] gccrs: Add trait context to ContextualASTVisitor
Date: Tue, 16 Jan 2024 18:17:37 +0000 (GMT)	[thread overview]
Message-ID: <20240116181737.8F1F03857713@sourceware.org> (raw)

https://gcc.gnu.org/g:c1d722aa6f011a1584b1815bfbfb8d2733c1ba34

commit r14-8146-gc1d722aa6f011a1584b1815bfbfb8d2733c1ba34
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Thu Nov 9 19:45:08 2023 +0100

    gccrs: Add trait context to ContextualASTVisitor
    
    Some construct are forbidden in trait context (eg. pub, async...) and
    we'll need to reject those. To do so we need to identify a trait context.
    
    gcc/rust/ChangeLog:
    
            * ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Push the new
            trait context when visiting a trait.
            * ast/rust-ast-visitor.h: Add visit function prototype and TRAIT
            context.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 gcc/rust/ast/rust-ast-visitor.cc | 8 ++++++++
 gcc/rust/ast/rust-ast-visitor.h  | 3 +++
 2 files changed, 11 insertions(+)

diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc
index b9ff2f97280..b4d1011a03e 100644
--- a/gcc/rust/ast/rust-ast-visitor.cc
+++ b/gcc/rust/ast/rust-ast-visitor.cc
@@ -1462,5 +1462,13 @@ ContextualASTVisitor::visit (AST::TraitImpl &impl)
   pop_context ();
 }
 
+void
+ContextualASTVisitor::visit (AST::Trait &trait)
+{
+  push_context (Context::TRAIT);
+  DefaultASTVisitor::visit (trait);
+  pop_context ();
+}
+
 } // namespace AST
 } // namespace Rust
diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h
index 0f66dbe2c31..d6340e745c9 100644
--- a/gcc/rust/ast/rust-ast-visitor.h
+++ b/gcc/rust/ast/rust-ast-visitor.h
@@ -442,6 +442,7 @@ protected:
     FUNCTION,
     INHERENT_IMPL,
     TRAIT_IMPL,
+    TRAIT,
     MODULE,
     CRATE,
   };
@@ -453,6 +454,8 @@ protected:
 
   virtual void visit (AST::TraitImpl &impl) override;
 
+  virtual void visit (AST::Trait &trait) override;
+
   template <typename T> void visit (T &item)
   {
     DefaultASTVisitor::visit (item);

                 reply	other threads:[~2024-01-16 18:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240116181737.8F1F03857713@sourceware.org \
    --to=cohenarthur@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).