diff mbox series

[116/125] gccrs: borrowck: BIR: make BIR visitor const

Message ID 20240801145809.366388-118-arthur.cohen@embecosm.com
State New
Headers show
Series [001/125] Rust: Make 'tree'-level 'MAIN_NAME_P' work | expand

Commit Message

Arthur Cohen Aug. 1, 2024, 2:57 p.m. UTC
From: Jakub Dupak <dev@jakubdupak.com>

gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): const
	visitor
	* checks/errors/borrowck/rust-bir-dump.h: const visitor
	* checks/errors/borrowck/rust-bir-visitor.h: const visitor
	* checks/errors/borrowck/rust-bir.h: const getter

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
---
 gcc/rust/checks/errors/borrowck/rust-bir-dump.cc   | 14 +++++++-------
 gcc/rust/checks/errors/borrowck/rust-bir-dump.h    | 14 +++++++-------
 gcc/rust/checks/errors/borrowck/rust-bir-visitor.h | 14 +++++++-------
 gcc/rust/checks/errors/borrowck/rust-bir.h         |  6 +++++-
 4 files changed, 26 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index 320b653f830..6f1579df1d9 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -155,7 +155,7 @@  Dump::go (bool enable_simplify_cfg)
   stream << "}\n";
 }
 void
-Dump::visit (Statement &stmt)
+Dump::visit (const Statement &stmt)
 {
   statement_place = stmt.get_place ();
   switch (stmt.get_kind ())
@@ -247,7 +247,7 @@  Dump::visit_move_place (PlaceId place_id)
 }
 
 void
-Dump::visit (BorrowExpr &expr)
+Dump::visit (const BorrowExpr &expr)
 {
   stream << "&";
   visit_lifetime (statement_place);
@@ -268,7 +268,7 @@  Dump::visit_lifetime (PlaceId place_id)
 }
 
 void
-Dump::visit (InitializerExpr &expr)
+Dump::visit (const InitializerExpr &expr)
 {
   stream << "{";
   print_comma_separated (stream, expr.get_values (), [this] (PlaceId place_id) {
@@ -278,7 +278,7 @@  Dump::visit (InitializerExpr &expr)
 }
 
 void
-Dump::visit (CallExpr &expr)
+Dump::visit (const CallExpr &expr)
 {
   stream << "Call(";
   if (auto fn_type
@@ -305,7 +305,7 @@  Dump::visit (CallExpr &expr)
 }
 
 void
-Dump::visit (Operator<1> &expr)
+Dump::visit (const Operator<1> &expr)
 {
   stream << "Operator(";
   visit_move_place (expr.get_operand<0> ());
@@ -313,7 +313,7 @@  Dump::visit (Operator<1> &expr)
 }
 
 void
-Dump::visit (Operator<2> &expr)
+Dump::visit (const Operator<2> &expr)
 {
   stream << "Operator(";
   visit_move_place (expr.get_operand<0> ());
@@ -323,7 +323,7 @@  Dump::visit (Operator<2> &expr)
 }
 
 void
-Dump::visit (Assignment &expr)
+Dump::visit (const Assignment &expr)
 {
   if (func.place_db[expr.get_rhs ()].is_rvalue ())
     {
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.h b/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
index cc3f9cdc738..9d6babd0053 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
@@ -49,16 +49,16 @@  public:
   void go (bool enable_simplify_cfg = false);
 
 protected:
-  void visit (Statement &stmt) override;
+  void visit (const Statement &stmt) override;
   void visit_place (PlaceId place_id);
   void visit_move_place (PlaceId place_id);
-  void visit (BorrowExpr &expr) override;
+  void visit (const BorrowExpr &expr) override;
   void visit_lifetime (PlaceId place_id);
-  void visit (InitializerExpr &expr) override;
-  void visit (CallExpr &expr) override;
-  void visit (Operator<1> &expr) override;
-  void visit (Operator<2> &expr) override;
-  void visit (Assignment &expr) override;
+  void visit (const InitializerExpr &expr) override;
+  void visit (const CallExpr &expr) override;
+  void visit (const Operator<1> &expr) override;
+  void visit (const Operator<2> &expr) override;
+  void visit (const Assignment &expr) override;
   void visit_scope (ScopeId id, size_t depth = 1);
 
   std::ostream &indent (size_t depth);
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h b/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h
index 7ad62f700db..2371b8bb5ce 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-visitor.h
@@ -32,13 +32,13 @@  class CallExpr;
 class Visitor
 {
 public:
-  virtual void visit (Statement &stmt) = 0;
-  virtual void visit (InitializerExpr &expr) = 0;
-  virtual void visit (Operator<1> &expr) = 0;
-  virtual void visit (Operator<2> &expr) = 0;
-  virtual void visit (BorrowExpr &expr) = 0;
-  virtual void visit (Assignment &expr) = 0;
-  virtual void visit (CallExpr &expr) = 0;
+  virtual void visit (const Statement &stmt) = 0;
+  virtual void visit (const InitializerExpr &expr) = 0;
+  virtual void visit (const Operator<1> &expr) = 0;
+  virtual void visit (const Operator<2> &expr) = 0;
+  virtual void visit (const BorrowExpr &expr) = 0;
+  virtual void visit (const Assignment &expr) = 0;
+  virtual void visit (const CallExpr &expr) = 0;
 };
 
 class Visitable
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir.h b/gcc/rust/checks/errors/borrowck/rust-bir.h
index f8a2151aaf8..d21cb90abf5 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir.h
@@ -137,6 +137,10 @@  public:
 
 public:
   std::vector<PlaceId> &get_values () { return values; }
+  WARN_UNUSED_RESULT const std::vector<PlaceId> &get_values () const
+  {
+    return values;
+  }
 };
 
 template <unsigned ARITY>
@@ -199,7 +203,7 @@  public:
   {}
 
 public:
-  const std::vector<PlaceId> &get_arguments () { return arguments; }
+  const std::vector<PlaceId> &get_arguments () const { return arguments; }
   WARN_UNUSED_RESULT PlaceId get_callable () const { return callable; }
 };