From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 9701C3858C66; Tue, 7 Feb 2023 17:55:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9701C3858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675792530; bh=S88rhnl3JXFfDOq6C3kAQ/dUhJhp56W3caUylvwBwwk=; h=From:To:Subject:Date:From; b=OVLeBk+zWuJhusaGK+cf3KKd5pqhFjT0X+8xTinlS8t/sx7st1b3I563lIHSSCnws 0oQcrE0Ey//sJVrvTeQ5j21TddstYUvjUAehjE7oy1WKUvYJodTYs1UFAKcEnBBGEl HlrLeKW4PFycCUTslFBnirHxHQIxXrTd8zsDoXj4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] gccrs: Refactor PathProbeType code into CC file X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 3e044eb0d53b5fb66cf683e0a86706ce68eec2f1 X-Git-Newrev: d5d70e3fa6e66798b1f2eca4b9aa3821ae4dc0c5 Message-Id: <20230207175530.9701C3858C66@sourceware.org> Date: Tue, 7 Feb 2023 17:55:30 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d5d70e3fa6e66798b1f2eca4b9aa3821ae4dc0c5 commit d5d70e3fa6e66798b1f2eca4b9aa3821ae4dc0c5 Author: Philip Herron Date: Mon Jan 16 17:54:41 2023 +0000 gccrs: Refactor PathProbeType code into CC file Signed-off-by: Philip Herron 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