]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: ast: Refactor TraitItem to keep Location info
authorArthur Cohen <arthur.cohen@embecosm.com>
Wed, 15 Feb 2023 16:10:54 +0000 (17:10 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 6 Apr 2023 08:47:24 +0000 (10:47 +0200)
gcc/rust/ChangeLog:

* ast/rust-ast.h: Keep location in TraitItem base class
* ast/rust-item.h (class TraitItemFunc): Use base class location instead.
(class TraitItemMethod): Likewise.
(class TraitItemConst): Likewise.
(class TraitItemType): Likewise.
* ast/rust-macro.h: Likewise.

gcc/rust/ast/rust-ast.h
gcc/rust/ast/rust-item.h
gcc/rust/ast/rust-macro.h

index d986fdf9368fbce3cce8107ac1d68283d4fe72bb..585bdb09e68ab9f97117620943619caa16642d0c 100644 (file)
@@ -1358,12 +1358,15 @@ protected:
 class TraitItem
 {
 protected:
-  TraitItem () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) {}
+  TraitItem (Location locus)
+    : node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus)
+  {}
 
   // Clone function implementation as pure virtual method
   virtual TraitItem *clone_trait_item_impl () const = 0;
 
   NodeId node_id;
+  Location locus;
 
 public:
   virtual ~TraitItem () {}
@@ -1382,6 +1385,7 @@ public:
   virtual bool is_marked_for_strip () const = 0;
 
   NodeId get_node_id () const { return node_id; }
+  Location get_locus () const { return locus; }
 };
 
 /* Abstract base class for items used within an inherent impl block (the impl
index 51ed815c700156d6e18fe9318c7a7604e77e5496..16209613881111eb3f87fa7ec390294302959967 100644 (file)
@@ -2908,7 +2908,6 @@ class TraitItemFunc : public TraitItem
   std::vector<Attribute> outer_attrs;
   TraitFunctionDecl decl;
   std::unique_ptr<BlockExpr> block_expr;
-  Location locus;
 
 public:
   // Returns whether function has a definition or is just a declaration.
@@ -2916,14 +2915,14 @@ public:
 
   TraitItemFunc (TraitFunctionDecl decl, std::unique_ptr<BlockExpr> block_expr,
                 std::vector<Attribute> outer_attrs, Location locus)
-    : TraitItem (), outer_attrs (std::move (outer_attrs)),
-      decl (std::move (decl)), block_expr (std::move (block_expr)),
-      locus (locus)
+    : TraitItem (locus), outer_attrs (std::move (outer_attrs)),
+      decl (std::move (decl)), block_expr (std::move (block_expr))
   {}
 
   // Copy constructor with clone
   TraitItemFunc (TraitItemFunc const &other)
-    : outer_attrs (other.outer_attrs), decl (other.decl), locus (other.locus)
+    : TraitItem (other.locus), outer_attrs (other.outer_attrs),
+      decl (other.decl)
   {
     node_id = other.node_id;
 
@@ -2956,8 +2955,6 @@ public:
 
   std::string as_string () const override;
 
-  Location get_locus () const { return locus; }
-
   void accept_vis (ASTVisitor &vis) override;
 
   // Invalid if trait decl is empty, so base stripping on that.
@@ -3128,7 +3125,6 @@ class TraitItemMethod : public TraitItem
   std::vector<Attribute> outer_attrs;
   TraitMethodDecl decl;
   std::unique_ptr<BlockExpr> block_expr;
-  Location locus;
 
 public:
   // Returns whether method has a definition or is just a declaration.
@@ -3136,14 +3132,14 @@ public:
 
   TraitItemMethod (TraitMethodDecl decl, std::unique_ptr<BlockExpr> block_expr,
                   std::vector<Attribute> outer_attrs, Location locus)
-    : TraitItem (), outer_attrs (std::move (outer_attrs)),
-      decl (std::move (decl)), block_expr (std::move (block_expr)),
-      locus (locus)
+    : TraitItem (locus), outer_attrs (std::move (outer_attrs)),
+      decl (std::move (decl)), block_expr (std::move (block_expr))
   {}
 
   // Copy constructor with clone
   TraitItemMethod (TraitItemMethod const &other)
-    : outer_attrs (other.outer_attrs), decl (other.decl), locus (other.locus)
+    : TraitItem (other.locus), outer_attrs (other.outer_attrs),
+      decl (other.decl)
   {
     node_id = other.node_id;
 
@@ -3176,8 +3172,6 @@ public:
 
   std::string as_string () const override;
 
-  Location get_locus () const { return locus; }
-
   void accept_vis (ASTVisitor &vis) override;
 
   // Invalid if trait decl is empty, so base stripping on that.
@@ -3219,8 +3213,6 @@ class TraitItemConst : public TraitItem
   // bool has_expression;
   std::unique_ptr<Expr> expr;
 
-  Location locus;
-
 public:
   // Whether the constant item has an associated expression.
   bool has_expression () const { return expr != nullptr; }
@@ -3228,14 +3220,14 @@ public:
   TraitItemConst (Identifier name, std::unique_ptr<Type> type,
                  std::unique_ptr<Expr> expr,
                  std::vector<Attribute> outer_attrs, Location locus)
-    : TraitItem (), outer_attrs (std::move (outer_attrs)),
-      name (std::move (name)), type (std::move (type)), expr (std::move (expr)),
-      locus (locus)
+    : TraitItem (locus), outer_attrs (std::move (outer_attrs)),
+      name (std::move (name)), type (std::move (type)), expr (std::move (expr))
   {}
 
   // Copy constructor with clones
   TraitItemConst (TraitItemConst const &other)
-    : outer_attrs (other.outer_attrs), name (other.name), locus (other.locus)
+    : TraitItem (other.locus), outer_attrs (other.outer_attrs),
+      name (other.name)
   {
     node_id = other.node_id;
 
@@ -3328,8 +3320,6 @@ class TraitItemType : public TraitItem
   std::vector<std::unique_ptr<TypeParamBound>>
     type_param_bounds; // inlined form
 
-  Location locus;
-
 public:
   // Returns whether trait item type has type param bounds.
   bool has_type_param_bounds () const { return !type_param_bounds.empty (); }
@@ -3337,14 +3327,14 @@ public:
   TraitItemType (Identifier name,
                 std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
                 std::vector<Attribute> outer_attrs, Location locus)
-    : TraitItem (), outer_attrs (std::move (outer_attrs)),
-      name (std::move (name)),
-      type_param_bounds (std::move (type_param_bounds)), locus (locus)
+    : TraitItem (locus), outer_attrs (std::move (outer_attrs)),
+      name (std::move (name)), type_param_bounds (std::move (type_param_bounds))
   {}
 
   // Copy constructor with vector clone
   TraitItemType (TraitItemType const &other)
-    : outer_attrs (other.outer_attrs), name (other.name), locus (other.locus)
+    : TraitItem (other.locus), outer_attrs (other.outer_attrs),
+      name (other.name)
   {
     node_id = other.node_id;
     type_param_bounds.reserve (other.type_param_bounds.size ());
@@ -3374,8 +3364,6 @@ public:
 
   std::string as_string () const override;
 
-  Location get_locus () const { return locus; }
-
   void accept_vis (ASTVisitor &vis) override;
 
   // Invalid if name is empty, so base stripping on that.
index 1a1a32da34cd6ddac126e2b0bac1077e4f7d4f4e..be8ed5609137e06b26ca0b60a27b1a063295b907 100644 (file)
@@ -723,7 +723,7 @@ private:
     MacroInvocData invoc_data, std::vector<Attribute> outer_attrs,
     Location locus, bool is_semi_coloned,
     std::vector<std::unique_ptr<MacroInvocation>> &&pending_eager_invocs)
-    : outer_attrs (std::move (outer_attrs)), locus (locus),
+    : TraitItem (locus), outer_attrs (std::move (outer_attrs)), locus (locus),
       node_id (Analysis::Mappings::get ()->get_next_node_id ()),
       invoc_data (std::move (invoc_data)), is_semi_coloned (is_semi_coloned),
       kind (kind), builtin_kind (builtin_kind),
@@ -731,10 +731,10 @@ private:
   {}
 
   MacroInvocation (const MacroInvocation &other)
-    : outer_attrs (other.outer_attrs), locus (other.locus),
-      node_id (other.node_id), invoc_data (other.invoc_data),
-      is_semi_coloned (other.is_semi_coloned), kind (other.kind),
-      builtin_kind (other.builtin_kind)
+    : TraitItem (other.locus), outer_attrs (other.outer_attrs),
+      locus (other.locus), node_id (other.node_id),
+      invoc_data (other.invoc_data), is_semi_coloned (other.is_semi_coloned),
+      kind (other.kind), builtin_kind (other.builtin_kind)
   {
     if (other.kind == InvocKind::Builtin)
       for (auto &pending : other.pending_eager_invocs)