public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Refactor TypeBoundPredicate to be below the definition for SubstitutionRef
@ 2022-06-08 12:19 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:19 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:9411c061aaeae0be39c678e0885472c37b112141

commit 9411c061aaeae0be39c678e0885472c37b112141
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Mon Mar 14 17:35:57 2022 +0000

    Refactor TypeBoundPredicate to be below the definition for SubstitutionRef
    
    This means TypeBoundPredicate will now be able to inherit all behaviours
    of normal generics so we do not duplicate the work in handling generics
    it will also allow us to more easily check for unconstrained type
    parameters on traits.

Diff:
---
 gcc/rust/typecheck/rust-tyty-bounds.cc |  54 ++++++++++++++
 gcc/rust/typecheck/rust-tyty.h         | 124 +++++++++++++--------------------
 2 files changed, 103 insertions(+), 75 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc
index 1d1c481ce73..bc1e76ef69f 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -67,6 +67,10 @@ TypeCheckBase::resolve_trait_path (HIR::TypePath &path)
 
 namespace TyTy {
 
+TypeBoundPredicate::TypeBoundPredicate (DefId reference, Location locus)
+  : reference (reference), locus (locus), args (nullptr)
+{}
+
 std::string
 TypeBoundPredicate::as_string () const
 {
@@ -192,5 +196,55 @@ TypeBoundPredicateItem::needs_implementation () const
   return !get_raw_item ()->is_optional ();
 }
 
+// TypeBoundsMappings
+
+TypeBoundsMappings::TypeBoundsMappings (
+  std::vector<TypeBoundPredicate> specified_bounds)
+  : specified_bounds (specified_bounds)
+{}
+
+std::vector<TypeBoundPredicate> &
+TypeBoundsMappings::get_specified_bounds ()
+{
+  return specified_bounds;
+}
+
+const std::vector<TypeBoundPredicate> &
+TypeBoundsMappings::get_specified_bounds () const
+{
+  return specified_bounds;
+}
+
+size_t
+TypeBoundsMappings::num_specified_bounds () const
+{
+  return specified_bounds.size ();
+}
+
+std::string
+TypeBoundsMappings::raw_bounds_as_string () const
+{
+  std::string buf;
+  for (size_t i = 0; i < specified_bounds.size (); i++)
+    {
+      const TypeBoundPredicate &b = specified_bounds.at (i);
+      bool has_next = (i + 1) < specified_bounds.size ();
+      buf += b.get_name () + (has_next ? " + " : "");
+    }
+  return buf;
+}
+
+std::string
+TypeBoundsMappings::bounds_as_string () const
+{
+  return "bounds:[" + raw_bounds_as_string () + "]";
+}
+
+void
+TypeBoundsMappings::add_bound (TypeBoundPredicate predicate)
+{
+  specified_bounds.push_back (predicate);
+}
+
 } // namespace TyTy
 } // namespace Rust
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 82262abab09..d1c2170ba34 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -108,92 +108,24 @@ private:
   const Resolver::TraitItemReference *trait_item_ref;
 };
 
-class TypeBoundPredicate
-{
-public:
-  TypeBoundPredicate (DefId reference, Location locus)
-    : reference (reference), locus (locus), args (nullptr)
-  {}
-
-  std::string as_string () const;
-
-  const Resolver::TraitReference *get () const;
-
-  Location get_locus () const { return locus; }
-
-  std::string get_name () const;
-
-  // check that this predicate is object-safe see:
-  // https://doc.rust-lang.org/reference/items/traits.html#object-safety
-  bool is_object_safe (bool emit_error, Location locus) const;
-
-  void apply_generic_arguments (HIR::GenericArgs *generic_args);
-
-  bool contains_item (const std::string &search) const;
-
-  TypeBoundPredicateItem
-  lookup_associated_item (const std::string &search) const;
-
-  HIR::GenericArgs *get_generic_args () { return args; }
-
-  const HIR::GenericArgs *get_generic_args () const { return args; }
-
-  bool has_generic_args () const
-  {
-    if (args == nullptr)
-      return false;
-
-    return args->has_generic_args ();
-  }
-
-private:
-  DefId reference;
-  Location locus;
-  HIR::GenericArgs *args;
-};
-
 class TypeBoundsMappings
 {
 protected:
-  TypeBoundsMappings (std::vector<TypeBoundPredicate> specified_bounds)
-    : specified_bounds (specified_bounds)
-  {}
+  TypeBoundsMappings (std::vector<TypeBoundPredicate> specified_bounds);
 
 public:
-  std::vector<TypeBoundPredicate> &get_specified_bounds ()
-  {
-    return specified_bounds;
-  }
+  std::vector<TypeBoundPredicate> &get_specified_bounds ();
 
-  const std::vector<TypeBoundPredicate> &get_specified_bounds () const
-  {
-    return specified_bounds;
-  }
+  const std::vector<TypeBoundPredicate> &get_specified_bounds () const;
 
-  size_t num_specified_bounds () const { return specified_bounds.size (); }
+  size_t num_specified_bounds () const;
 
-  std::string raw_bounds_as_string () const
-  {
-    std::string buf;
-    for (size_t i = 0; i < specified_bounds.size (); i++)
-      {
-	const TypeBoundPredicate &b = specified_bounds.at (i);
-	bool has_next = (i + 1) < specified_bounds.size ();
-	buf += b.get_name () + (has_next ? " + " : "");
-      }
-    return buf;
-  }
+  std::string raw_bounds_as_string () const;
 
-  std::string bounds_as_string () const
-  {
-    return "bounds:[" + raw_bounds_as_string () + "]";
-  }
+  std::string bounds_as_string () const;
 
 protected:
-  void add_bound (TypeBoundPredicate predicate)
-  {
-    specified_bounds.push_back (predicate);
-  }
+  void add_bound (TypeBoundPredicate predicate);
 
   std::vector<TypeBoundPredicate> specified_bounds;
 };
@@ -1007,6 +939,48 @@ protected:
   SubstitutionArgumentMappings used_arguments;
 };
 
+class TypeBoundPredicate
+{
+public:
+  TypeBoundPredicate (DefId reference, Location locus);
+
+  std::string as_string () const;
+
+  const Resolver::TraitReference *get () const;
+
+  Location get_locus () const { return locus; }
+
+  std::string get_name () const;
+
+  // check that this predicate is object-safe see:
+  // https://doc.rust-lang.org/reference/items/traits.html#object-safety
+  bool is_object_safe (bool emit_error, Location locus) const;
+
+  void apply_generic_arguments (HIR::GenericArgs *generic_args);
+
+  bool contains_item (const std::string &search) const;
+
+  TypeBoundPredicateItem
+  lookup_associated_item (const std::string &search) const;
+
+  HIR::GenericArgs *get_generic_args () { return args; }
+
+  const HIR::GenericArgs *get_generic_args () const { return args; }
+
+  bool has_generic_args () const
+  {
+    if (args == nullptr)
+      return false;
+
+    return args->has_generic_args ();
+  }
+
+private:
+  DefId reference;
+  Location locus;
+  HIR::GenericArgs *args;
+};
+
 // https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.VariantDef.html
 class VariantDef
 {


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

only message in thread, other threads:[~2022-06-08 12:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:19 [gcc/devel/rust/master] Refactor TypeBoundPredicate to be below the definition for SubstitutionRef Thomas Schwinge

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