public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8146] gccrs: Add trait context to ContextualASTVisitor
@ 2024-01-16 18:17 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 18:17 UTC (permalink / raw)
  To: gcc-cvs

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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-16 18:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 18:17 [gcc r14-8146] gccrs: Add trait context to ContextualASTVisitor 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).