From patchwork Wed Apr 5 14:03:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 79685 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp353789vqo; Wed, 5 Apr 2023 07:33:41 -0700 (PDT) X-Google-Smtp-Source: AKy350YLIWzxzsEdkXsXnDq9Pl0SSSrIorBqhf0Y+QUsOY9bhAgxizcgbLjCJcYvHFEbRFbB8XID X-Received: by 2002:a17:906:9bd1:b0:8b1:bab0:aa3d with SMTP id de17-20020a1709069bd100b008b1bab0aa3dmr3090043ejc.8.1680705221476; Wed, 05 Apr 2023 07:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705221; cv=none; d=google.com; s=arc-20160816; b=GOHyixJKd8gnaR1wMRL0gqDelBdPeeSbn7u3cFUumKGcXXhFAE8K/yy9nqEbzkY+UQ ZzgUF8I5Ianza3uGZ7pWqV112IuUIqTyGkwKhbpGOZuDlL6o6hZx+E3clGRZOgK0InxG cOrfnfL73izsgyTD7589x2j+nZhP28fiE0ZFsp8RVzY25z7K5ToEo/tTYaUAHp2t3cDk Ct8oPryFji012/SxhUQevgAz6yUdrSFqc4ZDCzwnfYuWIljDZ0iaWiZzAFW4TNAW7G7d 0kaeUCyXSgMs20kxkO9uTlqr9O4f9gMNXfBF7EmsyFwFCZfhTFT79L/GbVRPXr7kqCZr 3M9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=PnkP2UgVFA7Tq7DGt8tHOjPew0CkHxnAWM1bV1pNAwE=; b=Xjbucmgo/2tvFov8QCtLKrVYk50ZcP9jgteDbO4omUfqkvwkwQgnZHpdlknVEd0g5O v30qjB3n2lmINsTSKk/eJpaSpd4KcwHj6m7Dtf2b7a9xPf0ebTik3vjndtK6OlsHHFsF 5nRx3o0mhj895pz6LJwnOiINOb0DKGELFHpVyQDmZ8P1BRQTozyy93rymqpLzf3xJtIb aqCnwsXUxOsU2WK5q23+utQf9peXmcySH0R77aNXycmAcJAi1A84SyrZh8VcvQg0+Mcc tyA5xmkKbzfeHh+qarmh+o/EMOjBgu2Qv87vguRTRTIkOTFSak6HwyWQX8kRyY6/gvUQ xLYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=dicAOXYU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id lz11-20020a170906fb0b00b00933a8c2308dsi2794291ejb.255.2023.04.05.07.33.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:33:41 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=dicAOXYU; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C7AFD388C5D5 for ; Wed, 5 Apr 2023 14:13:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 05D5E385020E for ; Wed, 5 Apr 2023 14:05:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 05D5E385020E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wm1-x331.google.com with SMTP id i5-20020a05600c354500b003edd24054e0so23810219wmq.4 for ; Wed, 05 Apr 2023 07:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703558; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=PnkP2UgVFA7Tq7DGt8tHOjPew0CkHxnAWM1bV1pNAwE=; b=dicAOXYU2+9EM19EQxFpb7wKQ2UnHY3+rMjPIH3JyR5rk9HQnUC4tNyM2cXliz8il6 iRrgNk01iIOOsrPjDeDKpQxg6lQ7JHeCDIo5+99WCLFq9ZqSyWt3aejKXhHElIHKAKcn rpIlHpflbiQLErxPcsPC0+gguMCcOt+DDrWU3l5aD8THediSeLKwoTSug2fwwt4Aqfa8 Nf1lEOOROs270xbwzq0UWrEGmShDwwgHkfx79rrzMjGzLsP7cKZQSouaYdnplUwhRsYd kPzOJR16rW+5rCMBlus349Yn8O1lLz5BiP/1EQ2Ywxk1Y7qrHcd9HC7WFhIoneL/coZ/ TCjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703558; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PnkP2UgVFA7Tq7DGt8tHOjPew0CkHxnAWM1bV1pNAwE=; b=nuUFt1NTbVqpH68DawQrTUZVNK184fkrpRV3xBlgADitnOVrtzY7yHT4ticGikV8R+ 1MPd7OuN9TEYd9nJ4LU0ClcTHfC8ETFLBqtqetXYAuiER5ysoLb9nEsaenCBNpuwokE0 5O545JBgb7ghpAgPmXocLQ+7hiNRnyMQhWOrSqA5pj49tIG+fdUy4E3BBenPcFabiOIj wZLFRr/DENb5Gj5YsGfDNNLZmehyR0Ipe2dUVffWGdt7iUH0l3TOHKqz6Ab0X9Fgcrc1 yBqNuEbGFCkXzAEGOye5Bz+zAHP816lUl4f8Jg8A5koVLtK0V9R6y1iyeqMeD7Sk6KWF CMCw== X-Gm-Message-State: AAQBX9c3wvOvZBATK+Xuv513i1+/B2pP2PA4IwZaMlmMkQvEIQFb1ZMI xs1N3N7wLLSy2XHhhxMMyFfCrX6CPtki4Q14lg== X-Received: by 2002:a1c:7406:0:b0:3ed:ff92:dd2a with SMTP id p6-20020a1c7406000000b003edff92dd2amr4937490wmc.12.1680703558306; Wed, 05 Apr 2023 07:05:58 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:05:58 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 42/88] gccrs: Refactor PathProbeType code into CC file Date: Wed, 5 Apr 2023 16:03:26 +0200 Message-Id: <20230405140411.3016563-43-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405140411.3016563-1-arthur.cohen@embecosm.com> References: <20230405140411.3016563-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762347158125780756?= X-GMAIL-MSGID: =?utf-8?q?1762347158125780756?= From: Philip Herron 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 --- 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 783282a0dc9..dd511ac4184 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