public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: Refactor PathProbeType code into CC file
@ 2023-02-07 17:55 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-02-07 17:55 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:d5d70e3fa6e66798b1f2eca4b9aa3821ae4dc0c5
commit d5d70e3fa6e66798b1f2eca4b9aa3821ae4dc0c5
Author: Philip Herron <herron.philip@googlemail.com>
Date: Mon Jan 16 17:54:41 2023 +0000
gccrs: Refactor PathProbeType code into CC file
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-path-probe.cc (PathProbeCandidate::Candidate::Candidate): refactor
(PathProbeCandidate::PathProbeCandidate): likewise
(PathProbeCandidate::as_string): likewise
(PathProbeCandidate::is_enum_candidate): likewise
(PathProbeCandidate::is_impl_candidate): likewise
(PathProbeCandidate::is_trait_candidate): likewise
(PathProbeCandidate::is_full_trait_item_candidate): likewise
(PathProbeCandidate::get_error): likewise
(PathProbeCandidate::is_error): likewise
(PathProbeCandidate::get_defid): likewise
(PathProbeCandidate::operator<): likewise
* typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): likewise
Diff:
---
gcc/rust/typecheck/rust-hir-path-probe.cc | 109 ++++++++++++++++++++++++++++++
gcc/rust/typecheck/rust-hir-path-probe.h | 82 ++++------------------
2 files changed, 124 insertions(+), 67 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc b/gcc/rust/typecheck/rust-hir-path-probe.cc
index 06d8920d2eb..be89ceb8645 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.cc
+++ b/gcc/rust/typecheck/rust-hir-path-probe.cc
@@ -23,6 +23,115 @@
namespace Rust {
namespace Resolver {
+// PathProbeCandidate
+
+PathProbeCandidate::Candidate::Candidate (EnumItemCandidate enum_field)
+ : enum_field (enum_field)
+{}
+
+PathProbeCandidate::Candidate::Candidate (ImplItemCandidate impl) : impl (impl)
+{}
+
+PathProbeCandidate::Candidate::Candidate (TraitItemCandidate trait)
+ : trait (trait)
+{}
+
+PathProbeCandidate::PathProbeCandidate (CandidateType type, TyTy::BaseType *ty,
+ Location locus,
+ EnumItemCandidate enum_field)
+ : type (type), ty (ty), locus (locus), item (enum_field)
+{}
+
+PathProbeCandidate::PathProbeCandidate (CandidateType type, TyTy::BaseType *ty,
+ Location locus, ImplItemCandidate impl)
+ : type (type), ty (ty), locus (locus), item (impl)
+{}
+
+PathProbeCandidate::PathProbeCandidate (CandidateType type, TyTy::BaseType *ty,
+ Location locus,
+ TraitItemCandidate trait)
+ : type (type), ty (ty), locus (locus), item (trait)
+{}
+
+std::string
+PathProbeCandidate::as_string () const
+{
+ return "PathProbe candidate TODO - as_string";
+}
+
+bool
+PathProbeCandidate::is_enum_candidate () const
+{
+ return type == ENUM_VARIANT;
+}
+
+bool
+PathProbeCandidate::is_impl_candidate () const
+{
+ return type == IMPL_CONST || type == IMPL_TYPE_ALIAS || type == IMPL_FUNC;
+}
+
+bool
+PathProbeCandidate::is_trait_candidate () const
+{
+ return type == TRAIT_ITEM_CONST || type == TRAIT_TYPE_ALIAS
+ || type == TRAIT_FUNC;
+}
+
+bool
+PathProbeCandidate::is_full_trait_item_candidate () const
+{
+ return is_trait_candidate () && item.trait.impl == nullptr;
+}
+
+PathProbeCandidate
+PathProbeCandidate::get_error ()
+{
+ return PathProbeCandidate (ERROR, nullptr, Location (),
+ ImplItemCandidate{nullptr, nullptr});
+}
+
+bool
+PathProbeCandidate::is_error () const
+{
+ return type == ERROR;
+}
+
+DefId
+PathProbeCandidate::get_defid () const
+{
+ switch (type)
+ {
+ case ENUM_VARIANT:
+ return item.enum_field.variant->get_defid ();
+ break;
+
+ case IMPL_CONST:
+ case IMPL_TYPE_ALIAS:
+ case IMPL_FUNC:
+ return item.impl.impl_item->get_impl_mappings ().get_defid ();
+ break;
+
+ case TRAIT_ITEM_CONST:
+ case TRAIT_TYPE_ALIAS:
+ case TRAIT_FUNC:
+ return item.trait.item_ref->get_mappings ().get_defid ();
+ break;
+
+ case ERROR:
+ default:
+ return UNKNOWN_DEFID;
+ }
+
+ return UNKNOWN_DEFID;
+}
+
+bool
+PathProbeCandidate::operator< (const PathProbeCandidate &c) const
+{
+ return get_defid () < c.get_defid ();
+}
+
// PathProbeType
PathProbeType::PathProbeType (const TyTy::BaseType *receiver,
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h
index d46d797ca4c..0bb3b994957 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.h
+++ b/gcc/rust/typecheck/rust-hir-path-probe.h
@@ -73,89 +73,37 @@ struct PathProbeCandidate
ImplItemCandidate impl;
TraitItemCandidate trait;
- Candidate (EnumItemCandidate enum_field) : enum_field (enum_field) {}
- Candidate (ImplItemCandidate impl) : impl (impl) {}
- Candidate (TraitItemCandidate trait) : trait (trait) {}
+ Candidate (EnumItemCandidate enum_field);
+ Candidate (ImplItemCandidate impl);
+ Candidate (TraitItemCandidate trait);
} item;
PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, Location locus,
- EnumItemCandidate enum_field)
- : type (type), ty (ty), locus (locus), item (enum_field)
- {}
+ EnumItemCandidate enum_field);
PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, Location locus,
- ImplItemCandidate impl)
- : type (type), ty (ty), locus (locus), item (impl)
- {}
+ ImplItemCandidate impl);
PathProbeCandidate (CandidateType type, TyTy::BaseType *ty, Location locus,
- TraitItemCandidate trait)
- : type (type), ty (ty), locus (locus), item (trait)
- {}
+ TraitItemCandidate trait);
- std::string as_string () const
- {
- return "PathProbe candidate TODO - as_string";
- }
+ std::string as_string () const;
- bool is_enum_candidate () const { return type == ENUM_VARIANT; }
+ bool is_enum_candidate () const;
- bool is_impl_candidate () const
- {
- return type == IMPL_CONST || type == IMPL_TYPE_ALIAS || type == IMPL_FUNC;
- }
+ bool is_impl_candidate () const;
- bool is_trait_candidate () const
- {
- return type == TRAIT_ITEM_CONST || type == TRAIT_TYPE_ALIAS
- || type == TRAIT_FUNC;
- }
+ bool is_trait_candidate () const;
- bool is_full_trait_item_candidate () const
- {
- return is_trait_candidate () && item.trait.impl == nullptr;
- }
+ bool is_full_trait_item_candidate () const;
- static PathProbeCandidate get_error ()
- {
- return PathProbeCandidate (ERROR, nullptr, Location (),
- ImplItemCandidate{nullptr, nullptr});
- }
+ static PathProbeCandidate get_error ();
- bool is_error () const { return type == ERROR; }
+ bool is_error () const;
- DefId get_defid () const
- {
- switch (type)
- {
- case ENUM_VARIANT:
- return item.enum_field.variant->get_defid ();
- break;
-
- case IMPL_CONST:
- case IMPL_TYPE_ALIAS:
- case IMPL_FUNC:
- return item.impl.impl_item->get_impl_mappings ().get_defid ();
- break;
-
- case TRAIT_ITEM_CONST:
- case TRAIT_TYPE_ALIAS:
- case TRAIT_FUNC:
- return item.trait.item_ref->get_mappings ().get_defid ();
- break;
-
- case ERROR:
- default:
- return UNKNOWN_DEFID;
- }
-
- return UNKNOWN_DEFID;
- }
+ DefId get_defid () const;
- bool operator<(const PathProbeCandidate &c) const
- {
- return get_defid () < c.get_defid ();
- }
+ bool operator< (const PathProbeCandidate &c) const;
};
class PathProbeType : public TypeCheckBase, public HIR::HIRImplVisitor
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-02-07 17:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-07 17:55 [gcc/devel/rust/master] gccrs: Refactor PathProbeType code into CC file 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).