From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by sourceware.org (Postfix) with ESMTPS id AE2A3385DDFA for ; Thu, 1 Aug 2024 14:59:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE2A3385DDFA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AE2A3385DDFA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::533 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524384; cv=none; b=kyBKlHDaotv1rUFLDH/DBOT7FlgL7+H5NnUnC9IttZ+DEw355Um5WJSoQASce4mEC/t8KjpfsX3WfqGzWZH1NiUBLWss7EviG5IJfjbIky3dcRLzqoCMCZL2KugLJduCQ5u/rZc3pdsOYFuwLRvCsYEOystq04P257lNp4vSRdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524384; c=relaxed/simple; bh=u1MG1HkHiunq3lHvG1x9OtE358CmlnJEnWK47jr9E2k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BiACKTf0KClHpLWoaHhM+xra6X81JgbPBefcs/88OPgyHFbUgJUcQL463XLsvmvNMDbxkmNs/eRNGJUM5E9INEhJEpiQK4F/3U82QVGH3APPaCHTUGUyb+/1Cowis/qQTDjys7uT5CZ1Lz+JwJwfNcuZ+RMzFSM4JQx2nNj8nDU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5a2a90243c9so8479312a12.0 for ; Thu, 01 Aug 2024 07:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524348; x=1723129148; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bd73Tcp9//FIlM4hCPVvxWSj56uo0j8XPdtMtuG6sgQ=; b=bI3EkEZaEDa/p6ADGCiMchuB9uNwrbd6ytve1g/LginsS7GpJEgpzjCwG5zitaT/F3 58h/6BJ70erZF7YJNULry1U75pdsz0xsEFya5gaEkJvkwzhHkAbtT/IHRebxx85FCB5V kbRbqismCSU+2e9Blkb+niewh9fgwz7jfIWA59dvBQtsoMhWRbKGcqdIRXBNpfBZRZuM rZghl+zb39KK/qapVOFUSi7tu/HjjubTF9lhOIhfCxIam+yDAJFtiidleFgrMBVEgkwD 1AEn6r62qJ0LaMadgql2Myiip8+SlU7VdX4mg/M+aAKyWJVwzMuuU84wICPR+sMfPAeh XNJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524348; x=1723129148; h=content-transfer-encoding:mime-version: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=bd73Tcp9//FIlM4hCPVvxWSj56uo0j8XPdtMtuG6sgQ=; b=i4Rj05Hiahy2HV2t8fTByzNzdnTBGI9wIsXd21vjAgxYC9PJ7LkD5pHWL7LtMGoVny E8j2ujS4nhGYYw2okxkvlKS3wLXdXqZfn0sos13CEHbiyz2P4BZpynTi+r+ds2lrJzJ+ n2Pa8RG0BPUXbWIrD41Qyt1fs3EhTjyGiRhBkpGiNmiqZmLXdbL14pe6UhFu23c6amxU gWr+C0Djlc9tME1x8LAFx1vJtCtvxvTin50w13BbAL2/zSl4sRsLHcu0Lif09X+zjZFQ oMuH4rpqJDgIz0h2QJDpKK5Z1r9UaFcqueRTY+q3P3hag72uCWS+W0twtY9EI+3KENUn KU5Q== X-Gm-Message-State: AOJu0Ywes0RbhO0kKR8zmvIgG7Hpc11cKQp4E+i50VB3clcvGbfJLQex RVrwkuaf7CEV0AOW1jBzNSYW6JjHlgcz3gH5nKpt8cfO9Hs9aZKoma1fyul5zzame/LQ/6B3cQY P9q4B X-Google-Smtp-Source: AGHT+IHvcUI50u7cdcO/aLUybfoqAP1qwjWQfM1l7sXlNUgjkAM4BKWzDFngXj8i5pWJDwnDk33rpQ== X-Received: by 2002:a05:6402:2d5:b0:5af:7b5a:81a0 with SMTP id 4fb4d7f45d1cf-5b7f37ed775mr432301a12.6.1722524346782; Thu, 01 Aug 2024 07:59:06 -0700 (PDT) Received: from platypus.lan ([2a04:cec2:9:dc84:3622:6733:ff49:ee91]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590592sm10252456a12.25.2024.08.01.07.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:59:06 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [PATCH 045/125] gccrs: Replace unique_ptr references with references Date: Thu, 1 Aug 2024 16:56:41 +0200 Message-ID: <20240801145809.366388-47-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240801145809.366388-2-arthur.cohen@embecosm.com> References: <20240801145809.366388-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.1 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 List-Id: From: Pierre-Emmanuel Patry This kind of double indirection is pointless and prone to error. This commit change the api of all getters from the AST to use references directly instead of references to unique pointers. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove reference to unique pointer and replace it with a direct reference to the wrapped data. * ast/rust-ast.cc (VariadicParam::as_string): Likewise. (BlockExpr::normalize_tail_expr): Likewise. * ast/rust-expr.h: Likewise and add pointer getter in order to allow pointer reseat. * ast/rust-item.h: Likewise and add pointer getter for reseat. * ast/rust-path.h: Likewise. * ast/rust-pattern.h: Likewise. * ast/rust-stmt.h: Likewise. * ast/rust-type.h: Likewise. * expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_struct_fields): Remove references to unique pointers and replace it with direct references to the wrapped object. (CfgStrip::maybe_strip_tuple_fields): Likewise. (CfgStrip::maybe_strip_generic_args): Likewise. (CfgStrip::maybe_strip_qualified_path_type): Likewise. (CfgStrip::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::maybe_expand_expr): Likewise. (ExpandVisitor::maybe_expand_type): Likewise. (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_binding): Likewise. (ASTLoweringBase::lower_generic_args): Likewise. (ASTLoweringBase::lower_self): Likewise. (ASTLoweringBase::lower_type_no_bounds): Likewise. (ASTLoweringBase::lower_bound): Likewise. (ASTLoweringBase::lower_range_pattern_bound): Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-block.h: Likewise. * hir/rust-ast-lower-enumitem.h: Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::translate): Likewise. (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-expr.h: Likewise. * hir/rust-ast-lower-extern.h: Likewise. * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::translate): Likewise. (ASTLowerImplItem::visit): Likewise. (ASTLowerTraitItem::translate): Likewise. (ASTLowerTraitItem::visit): Likewise. * hir/rust-ast-lower-implitem.h: Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::translate): Likewise. (ASTLoweringItem::visit): Likewise. * hir/rust-ast-lower-item.h: Likewise. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::translate): Likewise. (ASTLoweringPattern::visit): Likewise. * hir/rust-ast-lower-pattern.h: Likewise. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Likewise. * hir/rust-ast-lower-struct-field-expr.h: Likewise. * hir/rust-ast-lower-type.cc (ASTLowerTypePath::visit): Likewise. (ASTLowerQualifiedPathInType::visit): Likewise. (ASTLoweringType::translate): Likewise. (ASTLoweringType::visit): Likewise. (ASTLowerGenericParam::translate): Likewise. (ASTLowerGenericParam::visit): Likewise. (ASTLoweringTypeBounds::translate): Likewise. (ASTLoweringTypeBounds::visit): Likewise. (ASTLowerWhereClauseItem::visit): Likewise. * hir/rust-ast-lower-type.h: Likewise. * hir/rust-ast-lower.cc (ASTLowering::go): Likewise. (ASTLoweringBlock::visit): Likewise. (ASTLoweringIfBlock::visit): Likewise. (ASTLoweringIfLetBlock::visit): Likewise. (ASTLowerStructExprField::visit): Likewise. (ASTLoweringExprWithBlock::visit): Likewise. (ASTLoweringBase::lower_qual_path_type): Likewise. (ASTLoweringBase::lower_closure_param): Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::resolve_visibility): Likewise. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::go): Likewise. (ResolveExpr::visit): Likewise. (ResolveExpr::resolve_closure_param): Likewise. * resolve/rust-ast-resolve-expr.h: Likewise. * resolve/rust-ast-resolve-implitem.h: Likewise. * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise. (ResolveItem::go): Likewise. (ResolveItem::visit): Likewise. (ResolveItem::resolve_impl_item): Likewise. (ResolveItem::resolve_extern_item): Likewise. (ResolveImplItems::go): Likewise. (ResolveExternItem::go): Likewise. (ResolveExternItem::visit): Likewise. * resolve/rust-ast-resolve-item.h: Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::go): Likewise. (ResolvePath::resolve_path): Likewise. * resolve/rust-ast-resolve-path.h: Likewise. * resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go): Likewise. (PatternDeclaration::visit): Likewise. (resolve_range_pattern_bound): Likewise. * resolve/rust-ast-resolve-pattern.h: Likewise. * resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): Likewise. * resolve/rust-ast-resolve-stmt.h: Likewise. * resolve/rust-ast-resolve-struct-expr-field.cc (ResolveStructExprField::go): Likewise. (ResolveStructExprField::visit): Likewise. * resolve/rust-ast-resolve-struct-expr-field.h: Likewise. * resolve/rust-ast-resolve-toplevel.h: Likewise. * resolve/rust-ast-resolve-type.cc (ResolveType::visit): Likewise. (ResolveRelativeTypePath::go): Likewise. (ResolveRelativeQualTypePath::resolve_qual_seg): Likewise. (ResolveTypeToCanonicalPath::go): Likewise. (ResolveTypeToCanonicalPath::visit): Likewise. (ResolveGenericArgs::resolve_disambiguated_generic): Likewise. (ResolveGenericArgs::go): Likewise. * resolve/rust-ast-resolve-type.h: Likewise. * resolve/rust-ast-resolve.cc (NameResolution::go): Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::resolve_qualified_path_type): Likewise. (EarlyNameResolver::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Likewise. * checks/errors/rust-ast-validation.cc: Likewise. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/ast/rust-ast-collector.cc | 3 +- gcc/rust/ast/rust-ast.cc | 4 +- gcc/rust/ast/rust-expr.h | 302 ++++++++---- gcc/rust/ast/rust-item.h | 160 +++++- gcc/rust/ast/rust-path.h | 50 +- gcc/rust/ast/rust-pattern.h | 36 +- gcc/rust/ast/rust-stmt.h | 35 +- gcc/rust/ast/rust-type.h | 34 +- gcc/rust/checks/errors/rust-ast-validation.cc | 4 +- gcc/rust/expand/rust-cfg-strip.cc | 456 +++++++++--------- gcc/rust/expand/rust-expand-visitor.cc | 92 ++-- gcc/rust/expand/rust-expand-visitor.h | 10 +- gcc/rust/hir/rust-ast-lower-base.cc | 39 +- gcc/rust/hir/rust-ast-lower-base.h | 6 +- gcc/rust/hir/rust-ast-lower-block.h | 42 +- gcc/rust/hir/rust-ast-lower-enumitem.h | 8 +- gcc/rust/hir/rust-ast-lower-expr.cc | 130 +++-- gcc/rust/hir/rust-ast-lower-expr.h | 10 +- gcc/rust/hir/rust-ast-lower-extern.h | 22 +- gcc/rust/hir/rust-ast-lower-implitem.cc | 47 +- gcc/rust/hir/rust-ast-lower-implitem.h | 4 +- gcc/rust/hir/rust-ast-lower-item.cc | 68 ++- gcc/rust/hir/rust-ast-lower-item.h | 2 +- gcc/rust/hir/rust-ast-lower-pattern.cc | 54 +-- gcc/rust/hir/rust-ast-lower-pattern.h | 2 +- gcc/rust/hir/rust-ast-lower-stmt.cc | 30 +- .../hir/rust-ast-lower-struct-field-expr.h | 6 +- gcc/rust/hir/rust-ast-lower-type.cc | 67 ++- gcc/rust/hir/rust-ast-lower-type.h | 6 +- gcc/rust/hir/rust-ast-lower.cc | 70 ++- gcc/rust/resolve/rust-ast-resolve-base.cc | 2 +- gcc/rust/resolve/rust-ast-resolve-expr.cc | 160 +++--- gcc/rust/resolve/rust-ast-resolve-expr.h | 2 +- gcc/rust/resolve/rust-ast-resolve-implitem.h | 10 +- gcc/rust/resolve/rust-ast-resolve-item.cc | 203 ++++---- gcc/rust/resolve/rust-ast-resolve-item.h | 10 +- gcc/rust/resolve/rust-ast-resolve-path.cc | 38 +- gcc/rust/resolve/rust-ast-resolve-path.h | 12 +- gcc/rust/resolve/rust-ast-resolve-pattern.cc | 65 ++- gcc/rust/resolve/rust-ast-resolve-pattern.h | 4 +- gcc/rust/resolve/rust-ast-resolve-stmt.cc | 17 +- gcc/rust/resolve/rust-ast-resolve-stmt.h | 71 ++- .../rust-ast-resolve-struct-expr-field.cc | 10 +- .../rust-ast-resolve-struct-expr-field.h | 2 +- gcc/rust/resolve/rust-ast-resolve-toplevel.h | 26 +- gcc/rust/resolve/rust-ast-resolve-type.cc | 47 +- gcc/rust/resolve/rust-ast-resolve-type.h | 36 +- gcc/rust/resolve/rust-ast-resolve.cc | 9 +- gcc/rust/resolve/rust-default-resolver.cc | 68 +-- gcc/rust/resolve/rust-early-name-resolver.cc | 28 +- .../rust-toplevel-name-resolver-2.0.cc | 6 +- 51 files changed, 1418 insertions(+), 1207 deletions(-) diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index eb03dccaf84..a2cb506805b 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -2546,8 +2546,7 @@ TokenCollector::visit (LetStmt &stmt) { push (Rust::Token::make (LET, stmt.get_locus ())); auto &pattern = stmt.get_pattern (); - if (pattern) - visit (pattern); + visit (pattern); if (stmt.has_type ()) { diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 6eb3394c146..326379cf40c 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -2291,7 +2291,7 @@ std::string VariadicParam::as_string () const { if (has_pattern ()) - return get_pattern ()->as_string () + " : ..."; + return get_pattern ().as_string () + " : ..."; else return "..."; } @@ -4258,7 +4258,7 @@ BlockExpr::normalize_tail_expr () if (!stmt.is_semicolon_followed ()) { - expr = std::move (stmt.get_expr ()); + expr = std::move (stmt.take_expr ()); statements.pop_back (); } } diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 4830ae0d2d3..d3dc197ea55 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -387,10 +387,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_borrowed_expr () + Expr &get_borrowed_expr () { rust_assert (main_or_left_expr != nullptr); - return main_or_left_expr; + return *main_or_left_expr; } bool get_is_mut () const { return is_mut; } @@ -421,10 +421,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_dereferenced_expr () + Expr &get_dereferenced_expr () { rust_assert (main_or_left_expr != nullptr); - return main_or_left_expr; + return *main_or_left_expr; } protected: @@ -452,10 +452,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_propagating_expr () + Expr &get_propagating_expr () { rust_assert (main_or_left_expr != nullptr); - return main_or_left_expr; + return *main_or_left_expr; } protected: @@ -495,10 +495,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_negated_expr () + Expr &get_negated_expr () { rust_assert (main_or_left_expr != nullptr); - return main_or_left_expr; + return *main_or_left_expr; } protected: @@ -561,14 +561,26 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_left_expr () + Expr &get_left_expr () + { + rust_assert (main_or_left_expr != nullptr); + return *main_or_left_expr; + } + + std::unique_ptr &get_left_expr_ptr () { rust_assert (main_or_left_expr != nullptr); return main_or_left_expr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_right_expr () + Expr &get_right_expr () + { + rust_assert (right_expr != nullptr); + return *right_expr; + } + + std::unique_ptr &get_right_expr_ptr () { rust_assert (right_expr != nullptr); return right_expr; @@ -637,14 +649,26 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_left_expr () + Expr &get_left_expr () + { + rust_assert (main_or_left_expr != nullptr); + return *main_or_left_expr; + } + + std::unique_ptr &get_left_expr_ptr () { rust_assert (main_or_left_expr != nullptr); return main_or_left_expr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_right_expr () + Expr &get_right_expr () + { + rust_assert (right_expr != nullptr); + return *right_expr; + } + + std::unique_ptr &get_right_expr_ptr () { rust_assert (right_expr != nullptr); return right_expr; @@ -713,14 +737,26 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_left_expr () + Expr &get_left_expr () + { + rust_assert (main_or_left_expr != nullptr); + return *main_or_left_expr; + } + + std::unique_ptr &get_left_expr_ptr () { rust_assert (main_or_left_expr != nullptr); return main_or_left_expr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_right_expr () + Expr &get_right_expr () + { + rust_assert (right_expr != nullptr); + return *right_expr; + } + + std::unique_ptr &get_right_expr_ptr () { rust_assert (right_expr != nullptr); return right_expr; @@ -777,17 +813,17 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_casted_expr () + Expr &get_casted_expr () { rust_assert (main_or_left_expr != nullptr); - return main_or_left_expr; + return *main_or_left_expr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_type_to_cast_to () + TypeNoBounds &get_type_to_cast_to () { rust_assert (type_to_convert_to != nullptr); - return type_to_convert_to; + return *type_to_convert_to; } protected: @@ -843,19 +879,31 @@ public: void visit_rhs (ASTVisitor &vis) { right_expr->accept_vis (vis); } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_left_expr () + Expr &get_left_expr () + { + rust_assert (main_or_left_expr != nullptr); + return *main_or_left_expr; + } + + std::unique_ptr &get_left_expr_ptr () { rust_assert (main_or_left_expr != nullptr); return main_or_left_expr; } - // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_right_expr () + std::unique_ptr &get_right_expr_ptr () { rust_assert (right_expr != nullptr); return right_expr; } + // TODO: is this better? Or is a "vis_block" better? + Expr &get_right_expr () + { + rust_assert (right_expr != nullptr); + return *right_expr; + } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -917,14 +965,26 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_left_expr () + Expr &get_left_expr () + { + rust_assert (main_or_left_expr != nullptr); + return *main_or_left_expr; + } + + std::unique_ptr &get_left_expr_ptr () { rust_assert (main_or_left_expr != nullptr); return main_or_left_expr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_right_expr () + Expr &get_right_expr () + { + rust_assert (right_expr != nullptr); + return *right_expr; + } + + std::unique_ptr &get_right_expr_ptr () { rust_assert (right_expr != nullptr); return right_expr; @@ -1012,7 +1072,13 @@ public: } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_expr_in_parens () + Expr &get_expr_in_parens () + { + rust_assert (expr_in_parens != nullptr); + return *expr_in_parens; + } + + std::unique_ptr &get_expr_in_parens_ptr () { rust_assert (expr_in_parens != nullptr); return expr_in_parens; @@ -1147,17 +1213,17 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_elem_to_copy () + Expr &get_elem_to_copy () { rust_assert (elem_to_copy != nullptr); - return elem_to_copy; + return *elem_to_copy; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_num_copies () + Expr &get_num_copies () { rust_assert (num_copies != nullptr); - return num_copies; + return *num_copies; } protected: @@ -1331,17 +1397,17 @@ public: } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_array_expr () + Expr &get_array_expr () { rust_assert (array_expr != nullptr); - return array_expr; + return *array_expr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_index_expr () + Expr &get_index_expr () { rust_assert (index_expr != nullptr); - return index_expr; + return *index_expr; } const std::vector &get_outer_attrs () const { return outer_attrs; } @@ -1521,10 +1587,10 @@ public: bool is_marked_for_strip () const override { return tuple_expr == nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_tuple_expr () + Expr &get_tuple_expr () { rust_assert (tuple_expr != nullptr); - return tuple_expr; + return *tuple_expr; } const std::vector &get_outer_attrs () const { return outer_attrs; } @@ -1664,10 +1730,10 @@ public: std::string as_string () const; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_base_struct () + Expr &get_base_struct () { rust_assert (base_struct != nullptr); - return base_struct; + return *base_struct; } }; @@ -1763,10 +1829,10 @@ public: std::string as_string () const override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_value () + Expr &get_value () { rust_assert (value != nullptr); - return value; + return *value; } }; @@ -2021,10 +2087,10 @@ public: std::vector > &get_params () { return params; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_function_expr () + Expr &get_function_expr () { rust_assert (function != nullptr); - return function; + return *function; } const std::vector &get_outer_attrs () const { return outer_attrs; } @@ -2121,10 +2187,10 @@ public: std::vector > &get_params () { return params; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_receiver_expr () + Expr &get_receiver_expr () { rust_assert (receiver != nullptr); - return receiver; + return *receiver; } const PathExprSegment &get_method_name () const { return method_name; } @@ -2207,10 +2273,10 @@ public: bool is_marked_for_strip () const override { return receiver == nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_receiver_expr () + Expr &get_receiver_expr () { rust_assert (receiver != nullptr); - return receiver; + return *receiver; } Identifier get_field_name () const { return field; } @@ -2304,13 +2370,19 @@ public: const std::vector &get_outer_attrs () const { return outer_attrs; } std::vector &get_outer_attrs () { return outer_attrs; } - std::unique_ptr &get_pattern () + Pattern &get_pattern () { rust_assert (pattern != nullptr); - return pattern; + return *pattern; } - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (has_type_given ()); + return *type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (has_type_given ()); return type; @@ -2411,10 +2483,10 @@ public: return closure_inner == nullptr; } - std::unique_ptr &get_definition_expr () + Expr &get_definition_expr () { rust_assert (closure_inner != nullptr); - return closure_inner; + return *closure_inner; } protected: @@ -2532,7 +2604,13 @@ public: std::vector > &get_statements () { return statements; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_tail_expr () + Expr &get_tail_expr () + { + rust_assert (has_tail_expr ()); + return *expr; + } + + std::unique_ptr &get_tail_expr_ptr () { rust_assert (has_tail_expr ()); return expr; @@ -2651,14 +2729,20 @@ public: bool is_marked_for_strip () const override { return expr == nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_definition_block () + BlockExpr &get_definition_block () { rust_assert (expr != nullptr); - return expr; + return *expr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_return_type () + Type &get_return_type () + { + rust_assert (return_type != nullptr); + return *return_type; + } + + std::unique_ptr &get_return_type_ptr () { rust_assert (return_type != nullptr); return return_type; @@ -2794,10 +2878,10 @@ public: bool is_marked_for_strip () const override { return marked_for_strip; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_break_expr () + Expr &get_break_expr () { rust_assert (has_break_expr ()); - return break_expr; + return *break_expr; } const std::vector &get_outer_attrs () const { return outer_attrs; } @@ -2906,17 +2990,17 @@ public: } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_from_expr () + Expr &get_from_expr () { rust_assert (from != nullptr); - return from; + return *from; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_to_expr () + Expr &get_to_expr () { rust_assert (to != nullptr); - return to; + return *to; } protected: @@ -2974,10 +3058,10 @@ public: bool is_marked_for_strip () const override { return from == nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_from_expr () + Expr &get_from_expr () { rust_assert (from != nullptr); - return from; + return *from; } protected: @@ -3036,10 +3120,10 @@ public: bool is_marked_for_strip () const override { return to == nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_to_expr () + Expr &get_to_expr () { rust_assert (to != nullptr); - return to; + return *to; } protected: @@ -3142,17 +3226,17 @@ public: } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_from_expr () + Expr &get_from_expr () { rust_assert (from != nullptr); - return from; + return *from; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_to_expr () + Expr &get_to_expr () { rust_assert (to != nullptr); - return to; + return *to; } protected: @@ -3211,10 +3295,10 @@ public: bool is_marked_for_strip () const override { return to == nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_to_expr () + Expr &get_to_expr () { rust_assert (to != nullptr); - return to; + return *to; } protected: @@ -3290,10 +3374,10 @@ public: bool is_marked_for_strip () const override { return marked_for_strip; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_returned_expr () + Expr &get_returned_expr () { rust_assert (return_expr != nullptr); - return return_expr; + return *return_expr; } const std::vector &get_outer_attrs () const { return outer_attrs; } @@ -3372,10 +3456,10 @@ public: bool is_marked_for_strip () const override { return expr == nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_block_expr () + BlockExpr &get_block_expr () { rust_assert (expr != nullptr); - return expr; + return *expr; } const std::vector &get_outer_attrs () const { return outer_attrs; } @@ -3461,10 +3545,10 @@ public: bool is_marked_for_strip () const override { return loop_block == nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_loop_block () + BlockExpr &get_loop_block () { rust_assert (loop_block != nullptr); - return loop_block; + return *loop_block; } const std::vector &get_outer_attrs () const { return outer_attrs; } @@ -3544,10 +3628,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_predicate_expr () + Expr &get_predicate_expr () { rust_assert (condition != nullptr); - return condition; + return *condition; } protected: @@ -3617,10 +3701,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_scrutinee_expr () + Expr &get_scrutinee_expr () { rust_assert (scrutinee != nullptr); - return scrutinee; + return *scrutinee; } // TODO: this mutable getter seems really dodgy. Think up better way. @@ -3689,17 +3773,17 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_iterator_expr () + Expr &get_iterator_expr () { rust_assert (iterator_expr != nullptr); - return iterator_expr; + return *iterator_expr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_pattern () + Pattern &get_pattern () { rust_assert (pattern != nullptr); - return pattern; + return *pattern; } protected: @@ -3786,17 +3870,23 @@ public: void vis_if_block (ASTVisitor &vis) { if_block->accept_vis (vis); } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_condition_expr () + Expr &get_condition_expr () + { + rust_assert (condition != nullptr); + return *condition; + } + + std::unique_ptr &get_condition_expr_ptr () { rust_assert (condition != nullptr); return condition; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_if_block () + BlockExpr &get_if_block () { rust_assert (if_block != nullptr); - return if_block; + return *if_block; } // Invalid if if block or condition is null, so base stripping on that. @@ -3874,10 +3964,10 @@ public: void vis_else_block (ASTVisitor &vis) { else_block->accept_vis (vis); } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_else_block () + ExprWithBlock &get_else_block () { rust_assert (else_block != nullptr); - return else_block; + return *else_block; } protected: @@ -3975,17 +4065,23 @@ public: } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_value_expr () + Expr &get_value_expr () + { + rust_assert (value != nullptr); + return *value; + } + + std::unique_ptr &get_value_expr_ptr () { rust_assert (value != nullptr); return value; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_if_block () + BlockExpr &get_if_block () { rust_assert (if_block != nullptr); - return if_block; + return *if_block; } // TODO: this mutable getter seems really dodgy. Think up better way. @@ -4067,10 +4163,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_else_block () + ExprWithBlock &get_else_block () { rust_assert (else_block != nullptr); - return else_block; + return *else_block; } protected: @@ -4159,7 +4255,13 @@ public: std::string as_string () const; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_guard_expr () + Expr &get_guard_expr () + { + rust_assert (has_match_arm_guard ()); + return *guard_expr; + } + + std::unique_ptr &get_guard_expr_ptr () { rust_assert (has_match_arm_guard ()); return guard_expr; @@ -4220,7 +4322,13 @@ public: std::string as_string () const; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_expr () + Expr &get_expr () + { + rust_assert (expr != nullptr); + return *expr; + } + + std::unique_ptr &get_expr_ptr () { rust_assert (expr != nullptr); return expr; @@ -4315,10 +4423,10 @@ public: } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_scrutinee_expr () + Expr &get_scrutinee_expr () { rust_assert (branch_value != nullptr); - return branch_value; + return *branch_value; } const std::vector &get_match_cases () const { return match_arms; } diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index d09f4550062..c03de9b1a92 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -141,7 +141,13 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (type != nullptr); + return *type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (type != nullptr); return type; @@ -288,7 +294,13 @@ public: void accept_vis (ASTVisitor &vis) override; - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (bound_type != nullptr); + return *bound_type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (bound_type != nullptr); return bound_type; @@ -516,7 +528,13 @@ public: NodeId get_node_id () const { return node_id; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (has_type ()); + return *type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (has_type ()); return type; @@ -611,16 +629,16 @@ public: return new VariadicParam (*this); } - std::unique_ptr &get_pattern () + Pattern &get_pattern () { rust_assert (param_name != nullptr); - return param_name; + return *param_name; } - const std::unique_ptr &get_pattern () const + const Pattern &get_pattern () const { rust_assert (param_name != nullptr); - return param_name; + return *param_name; } bool has_pattern () const { return param_name != nullptr; } @@ -694,16 +712,22 @@ public: const std::vector &get_outer_attrs () const { return outer_attrs; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_pattern () + Pattern &get_pattern () { rust_assert (param_name != nullptr); - return param_name; + return *param_name; } bool has_name () const { return param_name != nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (type != nullptr); + return *type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (type != nullptr); return type; @@ -1409,7 +1433,13 @@ public: WhereClause &get_where_clause () { return where_clause; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_return_type () + Type &get_return_type () + { + rust_assert (has_return_type ()); + return *return_type; + } + + std::unique_ptr &get_return_type_ptr () { rust_assert (has_return_type ()); return return_type; @@ -1552,10 +1582,10 @@ public: WhereClause &get_where_clause () { return where_clause; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_type_aliased () + Type &get_type_aliased () { rust_assert (existing_type != nullptr); - return existing_type; + return *existing_type; } Identifier get_new_type_name () const { return new_type_name; } @@ -1750,7 +1780,13 @@ public: location_t get_locus () const { return locus; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_field_type () + Type &get_field_type () + { + rust_assert (field_type != nullptr); + return *field_type; + } + + std::unique_ptr &get_field_type_ptr () { rust_assert (field_type != nullptr); return field_type; @@ -1901,7 +1937,13 @@ public: const std::vector &get_outer_attrs () const { return outer_attrs; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_field_type () + Type &get_field_type () + { + rust_assert (field_type != nullptr); + return *field_type; + } + + std::unique_ptr &get_field_type_ptr () { rust_assert (field_type != nullptr); return field_type; @@ -2098,7 +2140,13 @@ public: bool has_expr () { return expression != nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_expr () + Expr &get_expr () + { + rust_assert (expression != nullptr); + return *expression; + } + + std::unique_ptr &get_expr_ptr () { rust_assert (expression != nullptr); return expression; @@ -2414,14 +2462,26 @@ public: bool has_expr () { return const_expr != nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_expr () + Expr &get_expr () + { + rust_assert (const_expr != nullptr); + return *const_expr; + } + + std::unique_ptr &get_expr_ptr () { rust_assert (const_expr != nullptr); return const_expr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (type != nullptr); + return *type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (type != nullptr); return type; @@ -2521,14 +2581,26 @@ public: bool has_expr () { return expr != nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_expr () + Expr &get_expr () + { + rust_assert (expr != nullptr); + return *expr; + } + + std::unique_ptr &get_expr_ptr () { rust_assert (expr != nullptr); return expr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (type != nullptr); + return *type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (type != nullptr); return type; @@ -2629,14 +2701,26 @@ public: bool has_expr () const { return expr != nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_expr () + Expr &get_expr () + { + rust_assert (has_expr ()); + return *expr; + } + + std::unique_ptr &get_expr_ptr () { rust_assert (has_expr ()); return expr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (type != nullptr); + return *type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (type != nullptr); return type; @@ -2958,7 +3042,13 @@ public: WhereClause &get_where_clause () { return where_clause; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (trait_type != nullptr); + return *trait_type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (trait_type != nullptr); return trait_type; @@ -3409,7 +3499,13 @@ public: const std::vector &get_outer_attrs () const { return outer_attrs; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (item_type != nullptr); + return *item_type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (item_type != nullptr); return item_type; @@ -3542,7 +3638,13 @@ public: const std::vector &get_outer_attrs () const { return outer_attrs; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (param_type != nullptr); + return *param_type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (param_type != nullptr); return param_type; @@ -3700,7 +3802,13 @@ public: WhereClause &get_where_clause () { return where_clause; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_return_type () + Type &get_return_type () + { + rust_assert (has_return_type ()); + return *return_type; + } + + std::unique_ptr &get_return_type_ptr () { rust_assert (has_return_type ()); return return_type; diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h index bd3012b1bed..83412ebea8c 100644 --- a/gcc/rust/ast/rust-path.h +++ b/gcc/rust/ast/rust-path.h @@ -120,7 +120,13 @@ public: std::string as_string () const; // TODO: is this better? Or is a "vis_pattern" better? - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (type != nullptr); + return *type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (type != nullptr); return type; @@ -216,10 +222,10 @@ public: switch (get_kind ()) { case Kind::Const: - get_expression ()->accept_vis (visitor); + get_expression ().accept_vis (visitor); break; case Kind::Type: - get_type ()->accept_vis (visitor); + get_type ().accept_vis (visitor); break; case Kind::Either: break; @@ -228,14 +234,28 @@ public: } } - std::unique_ptr &get_expression () + Expr &get_expression () + { + rust_assert (kind == Kind::Const); + + return *expression; + } + + std::unique_ptr &get_expression_ptr () { rust_assert (kind == Kind::Const); return expression; } - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (kind == Kind::Type); + + return *type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (kind == Kind::Type); @@ -352,11 +372,11 @@ public: Attribute &get_outer_attribute () { return outer_attr; } - std::unique_ptr &get_type () + AST::Type &get_type () { rust_assert (has_type ()); - return type; + return *type; } GenericArg &get_default_value () @@ -957,7 +977,13 @@ public: std::vector > &get_params () { return inputs; } // TODO: is this better? Or is a "vis_pattern" better? - std::unique_ptr &get_return_type () + Type &get_return_type () + { + rust_assert (has_return_type ()); + return *return_type; + } + + std::unique_ptr &get_return_type_ptr () { rust_assert (has_return_type ()); return return_type; @@ -1176,7 +1202,13 @@ public: location_t get_locus () const { return locus; } // TODO: is this better? Or is a "vis_pattern" better? - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (type_to_invoke_on != nullptr); + return *type_to_invoke_on; + } + + std::unique_ptr &get_type_ptr () { rust_assert (type_to_invoke_on != nullptr); return type_to_invoke_on; diff --git a/gcc/rust/ast/rust-pattern.h b/gcc/rust/ast/rust-pattern.h index 365f3b7f69d..abf6de6a043 100644 --- a/gcc/rust/ast/rust-pattern.h +++ b/gcc/rust/ast/rust-pattern.h @@ -138,10 +138,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_pattern" better? - std::unique_ptr &get_pattern_to_bind () + Pattern &get_pattern_to_bind () { rust_assert (has_pattern_to_bind ()); - return to_bind; + return *to_bind; } Identifier get_ident () const { return variable_ident; } @@ -428,16 +428,16 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? or is a "vis_bound" better? - std::unique_ptr &get_lower_bound () + RangePatternBound &get_lower_bound () { rust_assert (lower != nullptr); - return lower; + return *lower; } - std::unique_ptr &get_upper_bound () + RangePatternBound &get_upper_bound () { rust_assert (upper != nullptr); - return upper; + return *upper; } NodeId get_node_id () const override { return node_id; } @@ -500,10 +500,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: is this better? Or is a "vis_pattern" better? - std::unique_ptr &get_referenced_pattern () + Pattern &get_referenced_pattern () { rust_assert (pattern != nullptr); - return pattern; + return *pattern; } bool is_double_reference () const { return has_two_amps; } @@ -663,10 +663,10 @@ public: TupleIndex get_index () { return index; } // TODO: is this better? Or is a "vis_pattern" better? - std::unique_ptr &get_index_pattern () + Pattern &get_index_pattern () { rust_assert (tuple_pattern != nullptr); - return tuple_pattern; + return *tuple_pattern; } ItemType get_item_type () const override final { return ItemType::TUPLE_PAT; } @@ -743,10 +743,10 @@ public: const Identifier &get_identifier () const { return ident; } // TODO: is this better? Or is a "vis_pattern" better? - std::unique_ptr &get_ident_pattern () + Pattern &get_ident_pattern () { rust_assert (ident_pattern != nullptr); - return ident_pattern; + return *ident_pattern; } ItemType get_item_type () const override final { return ItemType::IDENT_PAT; } @@ -1183,10 +1183,10 @@ public: void accept_vis (ASTVisitor &vis) override; - std::unique_ptr &get_items () + TupleStructItems &get_items () { rust_assert (items != nullptr); - return items; + return *items; } PathInExpression &get_path () { return path; } @@ -1428,10 +1428,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: seems kinda dodgy. Think of better way. - std::unique_ptr &get_items () + TuplePatternItems &get_items () { rust_assert (items != nullptr); - return items; + return *items; } NodeId get_node_id () const override { return node_id; } @@ -1490,10 +1490,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: seems kinda dodgy. Think of better way. - std::unique_ptr &get_pattern_in_parens () + Pattern &get_pattern_in_parens () { rust_assert (pattern_in_parens != nullptr); - return pattern_in_parens; + return *pattern_in_parens; } NodeId get_node_id () const override { return node_id; } diff --git a/gcc/rust/ast/rust-stmt.h b/gcc/rust/ast/rust-stmt.h index b332425316c..51c59182ba6 100644 --- a/gcc/rust/ast/rust-stmt.h +++ b/gcc/rust/ast/rust-stmt.h @@ -22,6 +22,7 @@ #include "rust-ast.h" #include "rust-path.h" #include "rust-expr.h" +#include namespace Rust { namespace AST { @@ -155,19 +156,31 @@ public: const std::vector &get_outer_attrs () const { return outer_attrs; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_init_expr () + Expr &get_init_expr () + { + rust_assert (has_init_expr ()); + return *init_expr; + } + + std::unique_ptr &get_init_expr_ptr () { rust_assert (has_init_expr ()); return init_expr; } - std::unique_ptr &get_pattern () + Pattern &get_pattern () { rust_assert (variables_pattern != nullptr); - return variables_pattern; + return *variables_pattern; + } + + Type &get_type () + { + rust_assert (has_type ()); + return *type; } - std::unique_ptr &get_type () + std::unique_ptr &get_type_ptr () { rust_assert (has_type ()); return type; @@ -249,12 +262,24 @@ public: bool is_marked_for_strip () const override { return expr == nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_expr () + Expr &get_expr () + { + rust_assert (expr != nullptr); + return *expr; + } + + std::unique_ptr &get_expr_ptr () { rust_assert (expr != nullptr); return expr; } + std::unique_ptr take_expr () + { + rust_assert (expr != nullptr); + return std::move (expr); + } + bool is_semicolon_followed () const { return semicolon_followed; } protected: diff --git a/gcc/rust/ast/rust-type.h b/gcc/rust/ast/rust-type.h index 91a9d2f5999..23572a29a45 100644 --- a/gcc/rust/ast/rust-type.h +++ b/gcc/rust/ast/rust-type.h @@ -513,10 +513,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: would a "vis_type" be better? - std::unique_ptr &get_type_pointed_to () + TypeNoBounds &get_type_pointed_to () { rust_assert (type != nullptr); - return type; + return *type; } protected: @@ -580,17 +580,17 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: would a "vis_type" be better? - std::unique_ptr &get_type_referenced () + TypeNoBounds &get_type_referenced () { rust_assert (type != nullptr); - return type; + return *type; } bool get_has_mut () const { return has_mut; } Lifetime &get_lifetime () { return lifetime; } - std::unique_ptr &get_base_type () { return type; } + TypeNoBounds &get_base_type () { return *type; } protected: /* Use covariance to implement clone function as returning this object rather @@ -641,17 +641,17 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: would a "vis_type" be better? - std::unique_ptr &get_elem_type () + Type &get_elem_type () { rust_assert (elem_type != nullptr); - return elem_type; + return *elem_type; } // TODO: would a "vis_expr" be better? - std::unique_ptr &get_size_expr () + Expr &get_size_expr () { rust_assert (size != nullptr); - return size; + return *size; } protected: @@ -701,10 +701,10 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: would a "vis_type" be better? - std::unique_ptr &get_elem_type () + Type &get_elem_type () { rust_assert (elem_type != nullptr); - return elem_type; + return *elem_type; } protected: @@ -824,7 +824,13 @@ public: const std::vector &get_outer_attrs () const { return outer_attrs; } // TODO: would a "vis_type" be better? - std::unique_ptr &get_type () + Type &get_type () + { + rust_assert (param_type != nullptr); + return *param_type; + } + + std::unique_ptr &get_type_ptr () { rust_assert (param_type != nullptr); return param_type; @@ -935,10 +941,10 @@ public: } // TODO: would a "vis_type" be better? - std::unique_ptr &get_return_type () + TypeNoBounds &get_return_type () { rust_assert (has_return_type ()); - return return_type; + return *return_type; } FunctionQualifiers &get_function_qualifiers () { return function_qualifiers; } diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index d5892087889..e219fba5ce8 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -125,8 +125,8 @@ ASTValidation::visit (AST::Function &function) // if functional parameter if (!it->get ()->is_self () && !it->get ()->is_variadic ()) { - auto param = static_cast (it->get ()); - auto kind = param->get_pattern ()->get_pattern_kind (); + auto ¶m = static_cast (**it); + auto kind = param.get_pattern ().get_pattern_kind (); if (kind != AST::Pattern::Kind::Identifier && kind != AST::Pattern::Kind::Wildcard) diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index 923015fa05e..19f377ea75a 100644 --- a/gcc/rust/expand/rust-cfg-strip.cc +++ b/gcc/rust/expand/rust-cfg-strip.cc @@ -184,11 +184,10 @@ CfgStrip::maybe_strip_struct_fields (std::vector &fields) // expand sub-types of type, but can't strip type itself auto &type = field.get_field_type (); - type->accept_vis (*this); + type.accept_vis (*this); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), - "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); // if nothing else happens, increment ++it; @@ -212,10 +211,9 @@ CfgStrip::maybe_strip_tuple_fields (std::vector &fields) // expand sub-types of type, but can't strip type itself auto &type = field.get_field_type (); - type->accept_vis (*this); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), - "cannot strip type in this position"); + type.accept_vis (*this); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); // if nothing else happens, increment ++it; @@ -242,16 +240,16 @@ CfgStrip::maybe_strip_function_params ( // TODO: should an unwanted strip lead to break out of loop? auto &pattern = param->get_pattern (); - pattern->accept_vis (*this); - if (pattern->is_marked_for_strip ()) - rust_error_at (pattern->get_locus (), + pattern.accept_vis (*this); + if (pattern.is_marked_for_strip ()) + rust_error_at (pattern.get_locus (), "cannot strip pattern in this position"); auto &type = param->get_type (); - type->accept_vis (*this); + type.accept_vis (*this); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); } // increment @@ -272,19 +270,19 @@ CfgStrip::maybe_strip_generic_args (AST::GenericArgs &args) { case AST::GenericArg::Kind::Type: { auto &type = arg.get_type (); - type->accept_vis (*this); + type.accept_vis (*this); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); break; } case AST::GenericArg::Kind::Const: { auto &expr = arg.get_expression (); - expr->accept_vis (*this); + expr.accept_vis (*this); - if (expr->is_marked_for_strip ()) - rust_error_at (expr->get_locus (), + if (expr.is_marked_for_strip ()) + rust_error_at (expr.get_locus (), "cannot strip expression in this position"); break; } @@ -303,11 +301,10 @@ CfgStrip::maybe_strip_generic_args (AST::GenericArgs &args) for (auto &binding : args.get_binding_args ()) { auto &type = binding.get_type (); - type->accept_vis (*this); + type.accept_vis (*this); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), - "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); } } @@ -315,10 +312,10 @@ void CfgStrip::maybe_strip_qualified_path_type (AST::QualifiedPathType &path_type) { auto &type = path_type.get_type (); - type->accept_vis (*this); + type.accept_vis (*this); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); if (path_type.has_as_clause ()) { @@ -347,18 +344,18 @@ CfgStrip::CfgStrip::maybe_strip_closure_params ( } auto &pattern = param.get_pattern (); - pattern->accept_vis (*this); - if (pattern->is_marked_for_strip ()) - rust_error_at (pattern->get_locus (), + pattern.accept_vis (*this); + if (pattern.is_marked_for_strip ()) + rust_error_at (pattern.get_locus (), "cannot strip pattern in this position"); if (param.has_type_given ()) { auto &type = param.get_type (); - type->accept_vis (*this); + type.accept_vis (*this); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); } @@ -451,8 +448,8 @@ CfgStrip::visit (AST::TypePathSegmentFunction &segment) { auto &return_type = type_path_function.get_return_type (); - if (return_type->is_marked_for_strip ()) - rust_error_at (return_type->get_locus (), + if (return_type.is_marked_for_strip ()) + rust_error_at (return_type.get_locus (), "cannot strip type in this position"); } } @@ -516,8 +513,8 @@ CfgStrip::visit (AST::BorrowExpr &expr) * allowed to have external attributes in this position so can't be * stripped. */ auto &borrowed_expr = expr.get_borrowed_expr (); - if (borrowed_expr->is_marked_for_strip ()) - rust_error_at (borrowed_expr->get_locus (), + if (borrowed_expr.is_marked_for_strip ()) + rust_error_at (borrowed_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -536,9 +533,9 @@ CfgStrip::visit (AST::DereferenceExpr &expr) * allowed to have external attributes in this position so can't be * stripped. */ auto &dereferenced_expr = expr.get_dereferenced_expr (); - dereferenced_expr->accept_vis (*this); - if (dereferenced_expr->is_marked_for_strip ()) - rust_error_at (dereferenced_expr->get_locus (), + dereferenced_expr.accept_vis (*this); + if (dereferenced_expr.is_marked_for_strip ()) + rust_error_at (dereferenced_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -559,8 +556,8 @@ CfgStrip::visit (AST::ErrorPropagationExpr &expr) * allowed to have external attributes in this position so can't be * stripped. */ auto &propagating_expr = expr.get_propagating_expr (); - if (propagating_expr->is_marked_for_strip ()) - rust_error_at (propagating_expr->get_locus (), + if (propagating_expr.is_marked_for_strip ()) + rust_error_at (propagating_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -580,8 +577,8 @@ CfgStrip::visit (AST::NegationExpr &expr) * allowed to have external attributes in this position so can't be * stripped. */ auto &negated_expr = expr.get_negated_expr (); - if (negated_expr->is_marked_for_strip ()) - rust_error_at (negated_expr->get_locus (), + if (negated_expr.is_marked_for_strip ()) + rust_error_at (negated_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -593,13 +590,13 @@ CfgStrip::visit (AST::ArithmeticOrLogicalExpr &expr) * two direct descendant expressions, can strip ones below that */ // ensure that they are not marked for strip - if (expr.get_left_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_left_expr ()->get_locus (), + if (expr.get_left_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_left_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes are never allowed " "before binary op exprs"); - if (expr.get_right_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_right_expr ()->get_locus (), + if (expr.get_right_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_right_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -612,13 +609,13 @@ CfgStrip::visit (AST::ComparisonExpr &expr) AST::DefaultASTVisitor::visit (expr); // ensure that they are not marked for strip - if (expr.get_left_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_left_expr ()->get_locus (), + if (expr.get_left_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_left_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes are never allowed " "before binary op exprs"); - if (expr.get_right_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_right_expr ()->get_locus (), + if (expr.get_right_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_right_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -631,13 +628,13 @@ CfgStrip::visit (AST::LazyBooleanExpr &expr) AST::DefaultASTVisitor::visit (expr); // ensure that they are not marked for strip - if (expr.get_left_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_left_expr ()->get_locus (), + if (expr.get_left_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_left_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes are never allowed " "before binary op exprs"); - if (expr.get_right_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_right_expr ()->get_locus (), + if (expr.get_right_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_right_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -651,15 +648,15 @@ CfgStrip::visit (AST::TypeCastExpr &expr) auto &casted_expr = expr.get_casted_expr (); // ensure that they are not marked for strip - if (casted_expr->is_marked_for_strip ()) - rust_error_at (casted_expr->get_locus (), + if (casted_expr.is_marked_for_strip ()) + rust_error_at (casted_expr.get_locus (), "cannot strip expression in this position - outer " "attributes are never allowed before cast exprs"); // TODO: strip sub-types of type auto &type = expr.get_type_to_cast_to (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); } void CfgStrip::visit (AST::AssignmentExpr &expr) @@ -673,13 +670,13 @@ CfgStrip::visit (AST::AssignmentExpr &expr) AST::DefaultASTVisitor::visit (expr); // ensure that they are not marked for strip - if (expr.get_left_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_left_expr ()->get_locus (), + if (expr.get_left_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_left_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes are never allowed " "before binary op exprs"); - if (expr.get_right_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_right_expr ()->get_locus (), + if (expr.get_right_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_right_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -691,13 +688,13 @@ CfgStrip::visit (AST::CompoundAssignmentExpr &expr) AST::DefaultASTVisitor::visit (expr); // ensure that they are not marked for strip - if (expr.get_left_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_left_expr ()->get_locus (), + if (expr.get_left_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_left_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes are never allowed " "before binary op exprs"); - if (expr.get_right_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_right_expr ()->get_locus (), + if (expr.get_right_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_right_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -727,8 +724,8 @@ CfgStrip::visit (AST::GroupedExpr &expr) AST::DefaultASTVisitor::visit (expr); auto &inner_expr = expr.get_expr_in_parens (); - if (inner_expr->is_marked_for_strip ()) - rust_error_at (inner_expr->get_locus (), + if (inner_expr.is_marked_for_strip ()) + rust_error_at (inner_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -750,15 +747,15 @@ CfgStrip::visit (AST::ArrayElemsCopied &elems) // only intend stripping for internal sub-expressions auto &copied_expr = elems.get_elem_to_copy (); - if (copied_expr->is_marked_for_strip ()) - rust_error_at (copied_expr->get_locus (), + if (copied_expr.is_marked_for_strip ()) + rust_error_at (copied_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); auto ©_count = elems.get_num_copies (); - copy_count->accept_vis (*this); - if (copy_count->is_marked_for_strip ()) - rust_error_at (copy_count->get_locus (), + copy_count.accept_vis (*this); + if (copy_count.is_marked_for_strip ()) + rust_error_at (copy_count.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -807,14 +804,14 @@ CfgStrip::visit (AST::ArrayIndexExpr &expr) AST::DefaultASTVisitor::visit (expr); const auto &array_expr = expr.get_array_expr (); - if (array_expr->is_marked_for_strip ()) - rust_error_at (array_expr->get_locus (), + if (array_expr.is_marked_for_strip ()) + rust_error_at (array_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); const auto &index_expr = expr.get_index_expr (); - if (index_expr->is_marked_for_strip ()) - rust_error_at (index_expr->get_locus (), + if (index_expr.is_marked_for_strip ()) + rust_error_at (index_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -861,8 +858,8 @@ CfgStrip::visit (AST::TupleIndexExpr &expr) * associated with this level), but any sub-expressions would be * stripped. Thus, no need to erase when strip check called. */ auto &tuple_expr = expr.get_tuple_expr (); - if (tuple_expr->is_marked_for_strip ()) - rust_error_at (tuple_expr->get_locus (), + if (tuple_expr.is_marked_for_strip ()) + rust_error_at (tuple_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -903,8 +900,8 @@ CfgStrip::visit (AST::StructExprFieldIdentifierValue &field) AST::DefaultASTVisitor::visit (field); auto &value = field.get_value (); - if (value->is_marked_for_strip ()) - rust_error_at (value->get_locus (), + if (value.is_marked_for_strip ()) + rust_error_at (value.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -916,8 +913,8 @@ CfgStrip::visit (AST::StructExprFieldIndexValue &field) AST::DefaultASTVisitor::visit (field); auto &value = field.get_value (); - if (value->is_marked_for_strip ()) - rust_error_at (value->get_locus (), + if (value.is_marked_for_strip ()) + rust_error_at (value.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -959,9 +956,9 @@ CfgStrip::visit (AST::StructExprStructFields &expr) if (expr.has_struct_base ()) { auto &base_struct_expr = expr.get_struct_base ().get_base_struct (); - base_struct_expr->accept_vis (*this); - if (base_struct_expr->is_marked_for_strip ()) - rust_error_at (base_struct_expr->get_locus (), + base_struct_expr.accept_vis (*this); + if (base_struct_expr.is_marked_for_strip ()) + rust_error_at (base_struct_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -998,9 +995,9 @@ CfgStrip::visit (AST::StructExprStructBase &expr) * the expression. as such, can only strip sub-expressions. */ rust_assert (!expr.get_struct_base ().is_invalid ()); auto &base_struct_expr = expr.get_struct_base ().get_base_struct (); - base_struct_expr->accept_vis (*this); - if (base_struct_expr->is_marked_for_strip ()) - rust_error_at (base_struct_expr->get_locus (), + base_struct_expr.accept_vis (*this); + if (base_struct_expr.is_marked_for_strip ()) + rust_error_at (base_struct_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -1021,8 +1018,8 @@ CfgStrip::visit (AST::CallExpr &expr) AST::DefaultASTVisitor::visit (expr); auto &function = expr.get_function_expr (); - if (function->is_marked_for_strip ()) - rust_error_at (function->get_locus (), + if (function.is_marked_for_strip ()) + rust_error_at (function.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); @@ -1049,8 +1046,8 @@ CfgStrip::visit (AST::MethodCallExpr &expr) AST::DefaultASTVisitor::visit (expr); auto &receiver = expr.get_receiver_expr (); - if (receiver->is_marked_for_strip ()) - rust_error_at (receiver->get_locus (), + if (receiver.is_marked_for_strip ()) + rust_error_at (receiver.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); @@ -1079,8 +1076,8 @@ CfgStrip::visit (AST::FieldAccessExpr &expr) AST::DefaultASTVisitor::visit (expr); auto &receiver = expr.get_receiver_expr (); - if (receiver->is_marked_for_strip ()) - rust_error_at (receiver->get_locus (), + if (receiver.is_marked_for_strip ()) + rust_error_at (receiver.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -1103,8 +1100,8 @@ CfgStrip::visit (AST::ClosureExprInner &expr) // can't strip expression itself, but can strip sub-expressions auto &definition_expr = expr.get_definition_expr (); - if (definition_expr->is_marked_for_strip ()) - rust_error_at (definition_expr->get_locus (), + if (definition_expr.is_marked_for_strip ()) + rust_error_at (definition_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -1138,7 +1135,7 @@ CfgStrip::visit (AST::BlockExpr &expr) { auto &tail_expr = expr.get_tail_expr (); - if (tail_expr->is_marked_for_strip ()) + if (tail_expr.is_marked_for_strip ()) expr.strip_tail_expr (); } } @@ -1163,14 +1160,14 @@ CfgStrip::visit (AST::ClosureExprInnerTyped &expr) // can't strip return type, but can strip sub-types auto &type = expr.get_return_type (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); // can't strip expression itself, but can strip sub-expressions auto &definition_block = expr.get_definition_block (); - definition_block->accept_vis (*this); - if (definition_block->is_marked_for_strip ()) - rust_error_at (definition_block->get_locus (), + definition_block.accept_vis (*this); + if (definition_block.is_marked_for_strip ()) + rust_error_at (definition_block.get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } @@ -1204,8 +1201,8 @@ CfgStrip::visit (AST::BreakExpr &expr) { auto &break_expr = expr.get_break_expr (); - if (break_expr->is_marked_for_strip ()) - rust_error_at (break_expr->get_locus (), + if (break_expr.is_marked_for_strip ()) + rust_error_at (break_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -1218,13 +1215,13 @@ CfgStrip::visit (AST::RangeFromToExpr &expr) AST::DefaultASTVisitor::visit (expr); // ensure that they are not marked for strip - if (expr.get_from_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_from_expr ()->get_locus (), + if (expr.get_from_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_from_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes are never allowed " "before range exprs"); - if (expr.get_to_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_to_expr ()->get_locus (), + if (expr.get_to_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_to_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -1238,8 +1235,8 @@ CfgStrip::visit (AST::RangeFromExpr &expr) /* should have no possibility for outer attrs as would be parsed * with outer expr */ auto &from_expr = expr.get_from_expr (); - if (from_expr->is_marked_for_strip ()) - rust_error_at (from_expr->get_locus (), + if (from_expr.is_marked_for_strip ()) + rust_error_at (from_expr.get_locus (), "cannot strip expression in this position - outer " "attributes are never allowed before range exprs"); } @@ -1253,8 +1250,8 @@ CfgStrip::visit (AST::RangeToExpr &expr) /* should syntactically not have outer attributes, though this may * not have worked in practice */ auto &to_expr = expr.get_to_expr (); - if (to_expr->is_marked_for_strip ()) - rust_error_at (to_expr->get_locus (), + if (to_expr.is_marked_for_strip ()) + rust_error_at (to_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -1268,13 +1265,13 @@ CfgStrip::visit (AST::RangeFromToInclExpr &expr) AST::DefaultASTVisitor::visit (expr); // ensure that they are not marked for strip - if (expr.get_from_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_from_expr ()->get_locus (), + if (expr.get_from_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_from_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes are never allowed " "before range exprs"); - if (expr.get_to_expr ()->is_marked_for_strip ()) - rust_error_at (expr.get_to_expr ()->get_locus (), + if (expr.get_to_expr ().is_marked_for_strip ()) + rust_error_at (expr.get_to_expr ().get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -1288,8 +1285,8 @@ CfgStrip::visit (AST::RangeToInclExpr &expr) /* should syntactically not have outer attributes, though this may * not have worked in practice */ auto &to_expr = expr.get_to_expr (); - if (to_expr->is_marked_for_strip ()) - rust_error_at (to_expr->get_locus (), + if (to_expr.is_marked_for_strip ()) + rust_error_at (to_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -1312,8 +1309,8 @@ CfgStrip::visit (AST::ReturnExpr &expr) if (expr.has_returned_expr ()) { auto &returned_expr = expr.get_returned_expr (); - if (returned_expr->is_marked_for_strip ()) - rust_error_at (returned_expr->get_locus (), + if (returned_expr.is_marked_for_strip ()) + rust_error_at (returned_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -1338,8 +1335,8 @@ CfgStrip::visit (AST::UnsafeBlockExpr &expr) // can't strip block itself, but can strip sub-expressions auto &block_expr = expr.get_block_expr (); - if (block_expr->is_marked_for_strip ()) - rust_error_at (block_expr->get_locus (), + if (block_expr.is_marked_for_strip ()) + rust_error_at (block_expr.get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } @@ -1358,8 +1355,8 @@ CfgStrip::visit (AST::LoopExpr &expr) // can't strip block itself, but can strip sub-expressions auto &loop_block = expr.get_loop_block (); - if (loop_block->is_marked_for_strip ()) - rust_error_at (loop_block->get_locus (), + if (loop_block.is_marked_for_strip ()) + rust_error_at (loop_block.get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } @@ -1377,15 +1374,15 @@ CfgStrip::visit (AST::WhileLoopExpr &expr) AST::DefaultASTVisitor::visit (expr); // can't strip predicate expr itself, but can strip sub-expressions auto &predicate_expr = expr.get_predicate_expr (); - if (predicate_expr->is_marked_for_strip ()) - rust_error_at (predicate_expr->get_locus (), + if (predicate_expr.is_marked_for_strip ()) + rust_error_at (predicate_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); // can't strip block itself, but can strip sub-expressions auto &loop_block = expr.get_loop_block (); - if (loop_block->is_marked_for_strip ()) - rust_error_at (loop_block->get_locus (), + if (loop_block.is_marked_for_strip ()) + rust_error_at (loop_block.get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } @@ -1409,15 +1406,15 @@ CfgStrip::visit (AST::WhileLetLoopExpr &expr) // can't strip scrutinee expr itself, but can strip sub-expressions auto &scrutinee_expr = expr.get_scrutinee_expr (); - if (scrutinee_expr->is_marked_for_strip ()) - rust_error_at (scrutinee_expr->get_locus (), + if (scrutinee_expr.is_marked_for_strip ()) + rust_error_at (scrutinee_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); // can't strip block itself, but can strip sub-expressions auto &loop_block = expr.get_loop_block (); - if (loop_block->is_marked_for_strip ()) - rust_error_at (loop_block->get_locus (), + if (loop_block.is_marked_for_strip ()) + rust_error_at (loop_block.get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } @@ -1435,21 +1432,21 @@ CfgStrip::visit (AST::ForLoopExpr &expr) AST::DefaultASTVisitor::visit (expr); // strip sub-patterns of pattern auto &pattern = expr.get_pattern (); - if (pattern->is_marked_for_strip ()) - rust_error_at (pattern->get_locus (), + if (pattern.is_marked_for_strip ()) + rust_error_at (pattern.get_locus (), "cannot strip pattern in this position"); // can't strip scrutinee expr itself, but can strip sub-expressions auto &iterator_expr = expr.get_iterator_expr (); - if (iterator_expr->is_marked_for_strip ()) - rust_error_at (iterator_expr->get_locus (), + if (iterator_expr.is_marked_for_strip ()) + rust_error_at (iterator_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); // can't strip block itself, but can strip sub-expressions auto &loop_block = expr.get_loop_block (); - if (loop_block->is_marked_for_strip ()) - rust_error_at (loop_block->get_locus (), + if (loop_block.is_marked_for_strip ()) + rust_error_at (loop_block.get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } @@ -1471,15 +1468,15 @@ CfgStrip::visit (AST::IfExpr &expr) // can't strip condition expr itself, but can strip sub-expressions auto &condition_expr = expr.get_condition_expr (); - if (condition_expr->is_marked_for_strip ()) - rust_error_at (condition_expr->get_locus (), + if (condition_expr.is_marked_for_strip ()) + rust_error_at (condition_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); // can't strip if block itself, but can strip sub-expressions auto &if_block = expr.get_if_block (); - if (if_block->is_marked_for_strip ()) - rust_error_at (if_block->get_locus (), + if (if_block.is_marked_for_strip ()) + rust_error_at (if_block.get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } @@ -1499,22 +1496,22 @@ CfgStrip::visit (AST::IfExprConseqElse &expr) // can't strip condition expr itself, but can strip sub-expressions auto &condition_expr = expr.get_condition_expr (); - if (condition_expr->is_marked_for_strip ()) - rust_error_at (condition_expr->get_locus (), + if (condition_expr.is_marked_for_strip ()) + rust_error_at (condition_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); // can't strip if block itself, but can strip sub-expressions auto &if_block = expr.get_if_block (); - if (if_block->is_marked_for_strip ()) - rust_error_at (if_block->get_locus (), + if (if_block.is_marked_for_strip ()) + rust_error_at (if_block.get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); // can't strip else block itself, but can strip sub-expressions auto &else_block = expr.get_else_block (); - if (else_block->is_marked_for_strip ()) - rust_error_at (else_block->get_locus (), + if (else_block.is_marked_for_strip ()) + rust_error_at (else_block.get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } @@ -1539,15 +1536,15 @@ CfgStrip::visit (AST::IfLetExpr &expr) // can't strip value expr itself, but can strip sub-expressions auto &value_expr = expr.get_value_expr (); - if (value_expr->is_marked_for_strip ()) - rust_error_at (value_expr->get_locus (), + if (value_expr.is_marked_for_strip ()) + rust_error_at (value_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); // can't strip if block itself, but can strip sub-expressions auto &if_block = expr.get_if_block (); - if (if_block->is_marked_for_strip ()) - rust_error_at (if_block->get_locus (), + if (if_block.is_marked_for_strip ()) + rust_error_at (if_block.get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } @@ -1571,22 +1568,22 @@ CfgStrip::visit (AST::IfLetExprConseqElse &expr) // can't strip value expr itself, but can strip sub-expressions auto &value_expr = expr.get_value_expr (); - if (value_expr->is_marked_for_strip ()) - rust_error_at (value_expr->get_locus (), + if (value_expr.is_marked_for_strip ()) + rust_error_at (value_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); // can't strip if block itself, but can strip sub-expressions auto &if_block = expr.get_if_block (); - if (if_block->is_marked_for_strip ()) - rust_error_at (if_block->get_locus (), + if (if_block.is_marked_for_strip ()) + rust_error_at (if_block.get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); // can't strip else block itself, but can strip sub-expressions auto &else_block = expr.get_else_block (); - if (else_block->is_marked_for_strip ()) - rust_error_at (else_block->get_locus (), + if (else_block.is_marked_for_strip ()) + rust_error_at (else_block.get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } @@ -1613,8 +1610,8 @@ CfgStrip::visit (AST::MatchExpr &expr) // can't strip scrutinee expr itself, but can strip sub-expressions auto &scrutinee_expr = expr.get_scrutinee_expr (); - if (scrutinee_expr->is_marked_for_strip ()) - rust_error_at (scrutinee_expr->get_locus (), + if (scrutinee_expr.is_marked_for_strip ()) + rust_error_at (scrutinee_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); @@ -1646,16 +1643,16 @@ CfgStrip::visit (AST::MatchExpr &expr) if (match_arm.has_match_arm_guard ()) { auto &guard_expr = match_arm.get_guard_expr (); - if (guard_expr->is_marked_for_strip ()) - rust_error_at (guard_expr->get_locus (), + if (guard_expr.is_marked_for_strip ()) + rust_error_at (guard_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } // strip sub-expressions from match cases auto &case_expr = match_case.get_expr (); - if (case_expr->is_marked_for_strip ()) - rust_error_at (case_expr->get_locus (), + if (case_expr.is_marked_for_strip ()) + rust_error_at (case_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); @@ -1713,8 +1710,8 @@ CfgStrip::visit (AST::TypeParam ¶m) AST::DefaultASTVisitor::visit (param); - if (param.has_type () && param.get_type ()->is_marked_for_strip ()) - rust_error_at (param.get_type ()->get_locus (), + if (param.has_type () && param.get_type ().is_marked_for_strip ()) + rust_error_at (param.get_type ().get_locus (), "cannot strip type in this position"); } @@ -1725,8 +1722,8 @@ CfgStrip::visit (AST::TypeBoundWhereClauseItem &item) AST::DefaultASTVisitor::visit (item); auto &type = item.get_type (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); } void @@ -1807,8 +1804,8 @@ CfgStrip::visit (AST::Function &function) if (function.has_return_type ()) { auto &return_type = function.get_return_type (); - if (return_type->is_marked_for_strip ()) - rust_error_at (return_type->get_locus (), + if (return_type.is_marked_for_strip ()) + rust_error_at (return_type.get_locus (), "cannot strip type in this position"); } @@ -1839,8 +1836,8 @@ CfgStrip::visit (AST::TypeAlias &type_alias) AST::DefaultASTVisitor::visit (type_alias); auto &type = type_alias.get_type_aliased (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); } void @@ -1933,8 +1930,8 @@ CfgStrip::visit (AST::EnumItemDiscriminant &item) * allowed to have external attributes in this position so can't be * stripped. */ auto &expr = item.get_expr (); - if (expr->is_marked_for_strip ()) - rust_error_at (expr->get_locus (), + if (expr.is_marked_for_strip ()) + rust_error_at (expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -1987,8 +1984,8 @@ CfgStrip::visit (AST::ConstantItem &const_item) // strip any sub-types auto &type = const_item.get_type (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); /* strip any internal sub-expressions - expression itself isn't * allowed to have external attributes in this position so can't be @@ -1996,8 +1993,8 @@ CfgStrip::visit (AST::ConstantItem &const_item) if (const_item.has_expr ()) { auto &expr = const_item.get_expr (); - if (expr->is_marked_for_strip ()) - rust_error_at (expr->get_locus (), + if (expr.is_marked_for_strip ()) + rust_error_at (expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -2018,15 +2015,15 @@ CfgStrip::visit (AST::StaticItem &static_item) // strip any sub-types auto &type = static_item.get_type (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); /* strip any internal sub-expressions - expression itself isn't * allowed to have external attributes in this position so can't be * stripped. */ auto &expr = static_item.get_expr (); - if (expr->is_marked_for_strip ()) - rust_error_at (expr->get_locus (), + if (expr.is_marked_for_strip ()) + rust_error_at (expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -2047,8 +2044,8 @@ CfgStrip::visit (AST::TraitItemConst &item) // strip any sub-types auto &type = item.get_type (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); /* strip any internal sub-expressions - expression itself isn't * allowed to have external attributes in this position so can't be @@ -2056,8 +2053,8 @@ CfgStrip::visit (AST::TraitItemConst &item) if (item.has_expression ()) { auto &expr = item.get_expr (); - if (expr->is_marked_for_strip ()) - rust_error_at (expr->get_locus (), + if (expr.is_marked_for_strip ()) + rust_error_at (expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -2124,8 +2121,8 @@ CfgStrip::visit (AST::InherentImpl &impl) auto &type = impl.get_type (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); maybe_strip_pointer_allow_strip (impl.get_impl_items ()); } @@ -2152,8 +2149,8 @@ CfgStrip::visit (AST::TraitImpl &impl) AST::DefaultASTVisitor::visit (impl); auto &type = impl.get_type (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); auto &trait_path = impl.get_trait_path (); visit (trait_path); @@ -2191,8 +2188,8 @@ CfgStrip::visit (AST::ExternalStaticItem &item) AST::DefaultASTVisitor::visit (item); auto &type = item.get_type (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); } void @@ -2239,8 +2236,8 @@ CfgStrip::visit (AST::IdentifierPattern &pattern) AST::DefaultASTVisitor::visit (pattern); auto &sub_pattern = pattern.get_pattern_to_bind (); - if (sub_pattern->is_marked_for_strip ()) - rust_error_at (sub_pattern->get_locus (), + if (sub_pattern.is_marked_for_strip ()) + rust_error_at (sub_pattern.get_locus (), "cannot strip pattern in this position"); } @@ -2270,8 +2267,8 @@ CfgStrip::visit (AST::ReferencePattern &pattern) AST::DefaultASTVisitor::visit (pattern); auto &sub_pattern = pattern.get_referenced_pattern (); - if (sub_pattern->is_marked_for_strip ()) - rust_error_at (sub_pattern->get_locus (), + if (sub_pattern.is_marked_for_strip ()) + rust_error_at (sub_pattern.get_locus (), "cannot strip pattern in this position"); } void @@ -2289,8 +2286,8 @@ CfgStrip::visit (AST::StructPatternFieldTuplePat &field) // strip sub-patterns (can't strip top-level pattern) auto &sub_pattern = field.get_index_pattern (); - if (sub_pattern->is_marked_for_strip ()) - rust_error_at (sub_pattern->get_locus (), + if (sub_pattern.is_marked_for_strip ()) + rust_error_at (sub_pattern.get_locus (), "cannot strip pattern in this position"); } @@ -2308,8 +2305,8 @@ CfgStrip::visit (AST::StructPatternFieldIdentPat &field) AST::DefaultASTVisitor::visit (field); // strip sub-patterns (can't strip top-level pattern) auto &sub_pattern = field.get_ident_pattern (); - if (sub_pattern->is_marked_for_strip ()) - rust_error_at (sub_pattern->get_locus (), + if (sub_pattern.is_marked_for_strip ()) + rust_error_at (sub_pattern.get_locus (), "cannot strip pattern in this position"); } void @@ -2442,8 +2439,8 @@ CfgStrip::visit (AST::GroupedPattern &pattern) // can't strip inner pattern, only sub-patterns auto &pattern_in_parens = pattern.get_pattern_in_parens (); - if (pattern_in_parens->is_marked_for_strip ()) - rust_error_at (pattern_in_parens->get_locus (), + if (pattern_in_parens.is_marked_for_strip ()) + rust_error_at (pattern_in_parens.get_locus (), "cannot strip pattern in this position"); } @@ -2489,8 +2486,8 @@ CfgStrip::visit (AST::LetStmt &stmt) AST::DefaultASTVisitor::visit (stmt); // can't strip pattern, but call for sub-patterns auto &pattern = stmt.get_pattern (); - if (pattern->is_marked_for_strip ()) - rust_error_at (pattern->get_locus (), + if (pattern.is_marked_for_strip ()) + rust_error_at (pattern.get_locus (), "cannot strip pattern in this position"); // similar for type @@ -2498,9 +2495,8 @@ CfgStrip::visit (AST::LetStmt &stmt) { auto &type = stmt.get_type (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), - "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); } /* strip any internal sub-expressions - expression itself isn't @@ -2510,8 +2506,8 @@ CfgStrip::visit (AST::LetStmt &stmt) { auto &init_expr = stmt.get_init_expr (); - if (init_expr->is_marked_for_strip ()) - rust_error_at (init_expr->get_locus (), + if (init_expr.is_marked_for_strip ()) + rust_error_at (init_expr.get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } @@ -2529,7 +2525,7 @@ CfgStrip::visit (AST::ExprStmt &stmt) AST::DefaultASTVisitor::visit (stmt); // strip if expr is to be stripped auto &expr = stmt.get_expr (); - if (expr->is_marked_for_strip ()) + if (expr.is_marked_for_strip ()) { stmt.mark_for_strip (); return; @@ -2580,8 +2576,8 @@ CfgStrip::visit (AST::RawPointerType &type) AST::DefaultASTVisitor::visit (type); // expand but don't strip type pointed to auto &pointed_type = type.get_type_pointed_to (); - if (pointed_type->is_marked_for_strip ()) - rust_error_at (pointed_type->get_locus (), + if (pointed_type.is_marked_for_strip ()) + rust_error_at (pointed_type.get_locus (), "cannot strip type in this position"); } @@ -2591,8 +2587,8 @@ CfgStrip::visit (AST::ReferenceType &type) AST::DefaultASTVisitor::visit (type); // expand but don't strip type referenced auto &referenced_type = type.get_type_referenced (); - if (referenced_type->is_marked_for_strip ()) - rust_error_at (referenced_type->get_locus (), + if (referenced_type.is_marked_for_strip ()) + rust_error_at (referenced_type.get_locus (), "cannot strip type in this position"); } @@ -2602,14 +2598,14 @@ CfgStrip::visit (AST::ArrayType &type) AST::DefaultASTVisitor::visit (type); // expand but don't strip type referenced auto &base_type = type.get_elem_type (); - if (base_type->is_marked_for_strip ()) - rust_error_at (base_type->get_locus (), + if (base_type.is_marked_for_strip ()) + rust_error_at (base_type.get_locus (), "cannot strip type in this position"); // same for expression auto &size_expr = type.get_size_expr (); - if (size_expr->is_marked_for_strip ()) - rust_error_at (size_expr->get_locus (), + if (size_expr.is_marked_for_strip ()) + rust_error_at (size_expr.get_locus (), "cannot strip expression in this position"); } void @@ -2618,8 +2614,8 @@ CfgStrip::visit (AST::SliceType &type) AST::DefaultASTVisitor::visit (type); // expand but don't strip elem type auto &elem_type = type.get_elem_type (); - if (elem_type->is_marked_for_strip ()) - rust_error_at (elem_type->get_locus (), + if (elem_type.is_marked_for_strip ()) + rust_error_at (elem_type.get_locus (), "cannot strip type in this position"); } @@ -2644,9 +2640,8 @@ CfgStrip::visit (AST::BareFunctionType &type) } auto &type = param.get_type (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), - "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); // increment if nothing else happens ++it; @@ -2661,8 +2656,8 @@ CfgStrip::visit (AST::BareFunctionType &type) // In that case, we need to handle AST::TypeNoBounds on top of just // AST::Types auto &return_type = type.get_return_type (); - if (return_type->is_marked_for_strip ()) - rust_error_at (return_type->get_locus (), + if (return_type.is_marked_for_strip ()) + rust_error_at (return_type.get_locus (), "cannot strip type in this position"); } @@ -2677,9 +2672,8 @@ CfgStrip::visit (AST::SelfParam ¶m) if (param.has_type ()) { auto &type = param.get_type (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), - "cannot strip type in this position"); + if (type.is_marked_for_strip ()) + rust_error_at (type.get_locus (), "cannot strip type in this position"); } /* TODO: maybe check for invariants being violated - e.g. both type and * lifetime? */ diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index 6c1efb1d2e0..c840c25994e 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -360,7 +360,7 @@ ExpandVisitor::expand_struct_fields (std::vector &fields) { for (auto &field : fields) { - maybe_expand_type (field.get_field_type ()); + maybe_expand_type (field.get_field_type_ptr ()); } } @@ -368,7 +368,7 @@ void ExpandVisitor::expand_tuple_fields (std::vector &fields) { for (auto &field : fields) - maybe_expand_type (field.get_field_type ()); + maybe_expand_type (field.get_field_type_ptr ()); } // FIXME: This can definitely be refactored with the method above @@ -388,10 +388,10 @@ ExpandVisitor::expand_generic_args (AST::GenericArgs &args) switch (arg.get_kind ()) { case AST::GenericArg::Kind::Type: - maybe_expand_type (arg.get_type ()); + maybe_expand_type (arg.get_type_ptr ()); break; case AST::GenericArg::Kind::Const: - maybe_expand_expr (arg.get_expression ()); + maybe_expand_expr (arg.get_expression_ptr ()); break; default: break; @@ -407,13 +407,13 @@ ExpandVisitor::expand_generic_args (AST::GenericArgs &args) // expand binding args - strip sub-types only // FIXME: ARTHUR: This needs a test! Foo for (auto &binding : args.get_binding_args ()) - maybe_expand_type (binding.get_type ()); + maybe_expand_type (binding.get_type_ptr ()); } void ExpandVisitor::expand_qualified_path_type (AST::QualifiedPathType &path_type) { - maybe_expand_type (path_type.get_type ()); + maybe_expand_type (path_type.get_type_ptr ()); // FIXME: ARTHUR: Can we do macro expansion in there? Needs a test! if (path_type.has_as_clause ()) @@ -426,7 +426,7 @@ ExpandVisitor::expand_closure_params (std::vector ¶ms) for (auto ¶m : params) { if (param.has_type_given ()) - maybe_expand_type (param.get_type ()); + maybe_expand_type (param.get_type_ptr ()); } } @@ -491,7 +491,7 @@ ExpandVisitor::visit (AST::TypePathSegmentFunction &segment) visit (type); if (type_path_function.has_return_type ()) - maybe_expand_type (type_path_function.get_return_type ()); + maybe_expand_type (type_path_function.get_return_type_ptr ()); } void @@ -545,42 +545,42 @@ ExpandVisitor::visit (AST::ErrorPropagationExpr &expr) void ExpandVisitor::visit (AST::ArithmeticOrLogicalExpr &expr) { - maybe_expand_expr (expr.get_left_expr ()); - maybe_expand_expr (expr.get_right_expr ()); + maybe_expand_expr (expr.get_left_expr_ptr ()); + maybe_expand_expr (expr.get_right_expr_ptr ()); } void ExpandVisitor::visit (AST::ComparisonExpr &expr) { - maybe_expand_expr (expr.get_left_expr ()); - maybe_expand_expr (expr.get_right_expr ()); + maybe_expand_expr (expr.get_left_expr_ptr ()); + maybe_expand_expr (expr.get_right_expr_ptr ()); } void ExpandVisitor::visit (AST::LazyBooleanExpr &expr) { - maybe_expand_expr (expr.get_left_expr ()); - maybe_expand_expr (expr.get_right_expr ()); + maybe_expand_expr (expr.get_left_expr_ptr ()); + maybe_expand_expr (expr.get_right_expr_ptr ()); } void ExpandVisitor::visit (AST::AssignmentExpr &expr) { - maybe_expand_expr (expr.get_left_expr ()); - maybe_expand_expr (expr.get_right_expr ()); + maybe_expand_expr (expr.get_left_expr_ptr ()); + maybe_expand_expr (expr.get_right_expr_ptr ()); } void ExpandVisitor::visit (AST::CompoundAssignmentExpr &expr) { - maybe_expand_expr (expr.get_left_expr ()); - maybe_expand_expr (expr.get_right_expr ()); + maybe_expand_expr (expr.get_left_expr_ptr ()); + maybe_expand_expr (expr.get_right_expr_ptr ()); } void ExpandVisitor::visit (AST::GroupedExpr &expr) { - maybe_expand_expr (expr.get_expr_in_parens ()); + maybe_expand_expr (expr.get_expr_in_parens_ptr ()); } void @@ -620,7 +620,7 @@ ExpandVisitor::visit (AST::BlockExpr &expr) expand_tail_expr (expr, expander); if (expr.has_tail_expr ()) - maybe_expand_expr (expr.get_tail_expr ()); + maybe_expand_expr (expr.get_tail_expr_ptr ()); } void @@ -628,7 +628,7 @@ ExpandVisitor::visit (AST::ClosureExprInnerTyped &expr) { expand_closure_params (expr.get_params ()); - maybe_expand_type (expr.get_return_type ()); + maybe_expand_type (expr.get_return_type_ptr ()); visit (expr.get_definition_block ()); } @@ -640,7 +640,7 @@ ExpandVisitor::visit (AST::ContinueExpr &expr) void ExpandVisitor::visit (AST::IfExpr &expr) { - maybe_expand_expr (expr.get_condition_expr ()); + maybe_expand_expr (expr.get_condition_expr_ptr ()); visit (expr.get_if_block ()); } @@ -648,7 +648,7 @@ ExpandVisitor::visit (AST::IfExpr &expr) void ExpandVisitor::visit (AST::IfExprConseqElse &expr) { - maybe_expand_expr (expr.get_condition_expr ()); + maybe_expand_expr (expr.get_condition_expr_ptr ()); visit (expr.get_if_block ()); visit (expr.get_else_block ()); @@ -657,7 +657,7 @@ ExpandVisitor::visit (AST::IfExprConseqElse &expr) void ExpandVisitor::visit (AST::IfLetExpr &expr) { - maybe_expand_expr (expr.get_value_expr ()); + maybe_expand_expr (expr.get_value_expr_ptr ()); visit (expr.get_if_block ()); } @@ -665,7 +665,7 @@ ExpandVisitor::visit (AST::IfLetExpr &expr) void ExpandVisitor::visit (AST::IfLetExprConseqElse &expr) { - maybe_expand_expr (expr.get_value_expr ()); + maybe_expand_expr (expr.get_value_expr_ptr ()); visit (expr.get_if_block ()); visit (expr.get_else_block ()); @@ -684,9 +684,9 @@ ExpandVisitor::visit (AST::MatchExpr &expr) visit (pattern); if (arm.has_match_arm_guard ()) - maybe_expand_expr (arm.get_guard_expr ()); + maybe_expand_expr (arm.get_guard_expr_ptr ()); - maybe_expand_expr (match_case.get_expr ()); + maybe_expand_expr (match_case.get_expr_ptr ()); } } @@ -697,7 +697,7 @@ ExpandVisitor::visit (AST::TypeParam ¶m) visit (bound); if (param.has_type ()) - maybe_expand_type (param.get_type ()); + maybe_expand_type (param.get_type_ptr ()); } void @@ -707,7 +707,7 @@ ExpandVisitor::visit (AST::LifetimeWhereClauseItem &) void ExpandVisitor::visit (AST::TypeBoundWhereClauseItem &item) { - maybe_expand_type (item.get_type ()); + maybe_expand_type (item.get_type_ptr ()); for (auto &bound : item.get_type_param_bounds ()) visit (bound); @@ -745,7 +745,7 @@ ExpandVisitor::visit (AST::Function &function) expand_function_params (function.get_function_params ()); if (function.has_return_type ()) - maybe_expand_type (function.get_return_type ()); + maybe_expand_type (function.get_return_type_ptr ()); if (function.has_where_clause ()) expand_where_clause (function.get_where_clause ()); @@ -797,7 +797,7 @@ ExpandVisitor::visit (AST::EnumItemStruct &item) void ExpandVisitor::visit (AST::EnumItemDiscriminant &item) { - maybe_expand_expr (item.get_expr ()); + maybe_expand_expr (item.get_expr_ptr ()); } void @@ -812,27 +812,27 @@ ExpandVisitor::visit (AST::Union &union_item) void ExpandVisitor::visit (AST::ConstantItem &const_item) { - maybe_expand_type (const_item.get_type ()); + maybe_expand_type (const_item.get_type_ptr ()); if (const_item.has_expr ()) - maybe_expand_expr (const_item.get_expr ()); + maybe_expand_expr (const_item.get_expr_ptr ()); } void ExpandVisitor::visit (AST::StaticItem &static_item) { - maybe_expand_type (static_item.get_type ()); + maybe_expand_type (static_item.get_type_ptr ()); - maybe_expand_expr (static_item.get_expr ()); + maybe_expand_expr (static_item.get_expr_ptr ()); } void ExpandVisitor::visit (AST::TraitItemConst &const_item) { - maybe_expand_type (const_item.get_type ()); + maybe_expand_type (const_item.get_type_ptr ()); if (const_item.has_expr ()) - maybe_expand_expr (const_item.get_expr ()); + maybe_expand_expr (const_item.get_expr_ptr ()); } void @@ -870,7 +870,7 @@ ExpandVisitor::visit (AST::InherentImpl &impl) // FIXME: Is that correct? How do we test that? expander.push_context (MacroExpander::ContextType::ITEM); - maybe_expand_type (impl.get_type ()); + maybe_expand_type (impl.get_type_ptr ()); expander.pop_context (); @@ -895,7 +895,7 @@ ExpandVisitor::visit (AST::TraitImpl &impl) // FIXME: Is that correct? How do we test that? expander.push_context (MacroExpander::ContextType::ITEM); - maybe_expand_type (impl.get_type ()); + maybe_expand_type (impl.get_type_ptr ()); expander.pop_context (); @@ -919,7 +919,7 @@ ExpandVisitor::visit (AST::ExternalTypeItem &item) void ExpandVisitor::visit (AST::ExternalStaticItem &static_item) { - maybe_expand_type (static_item.get_type ()); + maybe_expand_type (static_item.get_type_ptr ()); } void @@ -978,16 +978,16 @@ ExpandVisitor::visit (AST::LetStmt &stmt) visit (stmt.get_pattern ()); if (stmt.has_type ()) - maybe_expand_type (stmt.get_type ()); + maybe_expand_type (stmt.get_type_ptr ()); if (stmt.has_init_expr ()) - maybe_expand_expr (stmt.get_init_expr ()); + maybe_expand_expr (stmt.get_init_expr_ptr ()); } void ExpandVisitor::visit (AST::ExprStmt &stmt) { - maybe_expand_expr (stmt.get_expr ()); + maybe_expand_expr (stmt.get_expr_ptr ()); } void @@ -995,7 +995,7 @@ ExpandVisitor::visit (AST::BareFunctionType &type) { for (auto ¶m : type.get_function_params ()) { - maybe_expand_type (param.get_type ()); + maybe_expand_type (param.get_type_ptr ()); } if (type.has_return_type ()) @@ -1005,7 +1005,7 @@ ExpandVisitor::visit (AST::BareFunctionType &type) void ExpandVisitor::visit (AST::FunctionParam ¶m) { - maybe_expand_type (param.get_type ()); + maybe_expand_type (param.get_type_ptr ()); } void @@ -1014,7 +1014,7 @@ ExpandVisitor::visit (AST::SelfParam ¶m) /* TODO: maybe check for invariants being violated - e.g. both type and * lifetime? */ if (param.has_type ()) - maybe_expand_type (param.get_type ()); + maybe_expand_type (param.get_type_ptr ()); } template diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h index 034aeede2f4..8885b3876f2 100644 --- a/gcc/rust/expand/rust-expand-visitor.h +++ b/gcc/rust/expand/rust-expand-visitor.h @@ -47,10 +47,16 @@ public: using AST::DefaultASTVisitor::visit; - /* Maybe expand a macro invocation in lieu of an expression */ + /* + Maybe expand a macro invocation in lieu of an expression + expr : Core guidelines R33, this function reseat the pointer. + */ void maybe_expand_expr (std::unique_ptr &expr); - /* Maybe expand a macro invocation in lieu of a type */ + /* + Maybe expand a macro invocation in lieu of a type + type : Core guidelines R33, this function reseat the pointer. + */ void maybe_expand_type (std::unique_ptr &type); /** diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index 652530ae7a5..bd26e7019c3 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -568,7 +568,7 @@ ASTLoweringBase::lower_generic_params ( std::vector> lowered; for (auto &ast_param : params) { - auto hir_param = ASTLowerGenericParam::translate (ast_param.get ()); + auto hir_param = ASTLowerGenericParam::translate (*ast_param); lowered.push_back (std::unique_ptr (hir_param)); } @@ -593,8 +593,7 @@ ASTLoweringBase::lower_path_expr_seg (AST::PathExprSegment &s) HIR::GenericArgsBinding ASTLoweringBase::lower_binding (AST::GenericArgsBinding &binding) { - HIR::Type *lowered_type - = ASTLoweringType::translate (binding.get_type ().get ()); + HIR::Type *lowered_type = ASTLoweringType::translate (binding.get_type ()); return HIR::GenericArgsBinding (binding.get_identifier (), std::unique_ptr (lowered_type), binding.get_locus ()); @@ -625,13 +624,12 @@ ASTLoweringBase::lower_generic_args (AST::GenericArgs &args) switch (arg.get_kind ()) { case AST::GenericArg::Kind::Type: { - auto type = ASTLoweringType::translate (arg.get_type ().get ()); + auto type = ASTLoweringType::translate (arg.get_type ()); type_args.emplace_back (std::unique_ptr (type)); break; } case AST::GenericArg::Kind::Const: { - auto expr - = ASTLoweringExpr::translate (arg.get_expression ().get ()); + auto expr = ASTLoweringExpr::translate (arg.get_expression ()); const_args.emplace_back ( HIR::ConstGenericArg (std::unique_ptr (expr), expr->get_locus ())); @@ -660,7 +658,7 @@ ASTLoweringBase::lower_self (AST::Param ¶m) if (self.has_type ()) { - HIR::Type *type = ASTLoweringType::translate (self.get_type ().get ()); + HIR::Type *type = ASTLoweringType::translate (self.get_type ()); return HIR::SelfParam (mapping, std::unique_ptr (type), self.get_is_mut (), self.get_locus ()); } @@ -676,13 +674,13 @@ ASTLoweringBase::lower_self (AST::Param ¶m) } HIR::Type * -ASTLoweringBase::lower_type_no_bounds (AST::TypeNoBounds *type) +ASTLoweringBase::lower_type_no_bounds (AST::TypeNoBounds &type) { return ASTLoweringType::translate (type); } HIR::TypeParamBound * -ASTLoweringBase::lower_bound (AST::TypeParamBound *bound) +ASTLoweringBase::lower_bound (AST::TypeParamBound &bound) { return ASTLoweringTypeBounds::translate (bound); } @@ -828,7 +826,7 @@ ASTLoweringBase::lower_tuple_pattern_multiple ( std::vector> patterns; for (auto &p : pattern.get_patterns ()) { - HIR::Pattern *translated = ASTLoweringPattern::translate (p.get ()); + HIR::Pattern *translated = ASTLoweringPattern::translate (*p); patterns.push_back (std::unique_ptr (translated)); } @@ -845,13 +843,13 @@ ASTLoweringBase::lower_tuple_pattern_ranged ( for (auto &p : pattern.get_lower_patterns ()) { - HIR::Pattern *translated = ASTLoweringPattern::translate (p.get ()); + HIR::Pattern *translated = ASTLoweringPattern::translate (*p); lower_patterns.push_back (std::unique_ptr (translated)); } for (auto &p : pattern.get_upper_patterns ()) { - HIR::Pattern *translated = ASTLoweringPattern::translate (p.get ()); + HIR::Pattern *translated = ASTLoweringPattern::translate (*p); upper_patterns.push_back (std::unique_ptr (translated)); } @@ -861,14 +859,14 @@ ASTLoweringBase::lower_tuple_pattern_ranged ( } std::unique_ptr -ASTLoweringBase::lower_range_pattern_bound (AST::RangePatternBound *bound) +ASTLoweringBase::lower_range_pattern_bound (AST::RangePatternBound &bound) { std::unique_ptr hir_bound = nullptr; - switch (bound->get_bound_type ()) + switch (bound.get_bound_type ()) { case AST::RangePatternBound::RangePatternBoundType::LITERAL: { AST::RangePatternBoundLiteral &ref - = *static_cast (bound); + = static_cast (bound); HIR::Literal literal = lower_literal (ref.get_literal ()); @@ -878,23 +876,20 @@ ASTLoweringBase::lower_range_pattern_bound (AST::RangePatternBound *bound) } break; case AST::RangePatternBound::RangePatternBoundType::PATH: { - AST::RangePatternBoundPath &ref - = *static_cast (bound); + auto &ref = static_cast (bound); HIR::PathInExpression *path - = ASTLowerPathInExpression::translate (&ref.get_path ()); + = ASTLowerPathInExpression::translate (ref.get_path ()); hir_bound = std::unique_ptr ( new HIR::RangePatternBoundPath (*path)); } break; case AST::RangePatternBound::RangePatternBoundType::QUALPATH: { - AST::RangePatternBoundQualPath &ref - = *static_cast (bound); + auto &ref = static_cast (bound); HIR::QualifiedPathInExpression *qualpath - = ASTLowerQualPathInExpression::translate ( - &ref.get_qualified_path ()); + = ASTLowerQualPathInExpression::translate (ref.get_qualified_path ()); hir_bound = std::unique_ptr ( new HIR::RangePatternBoundQualPath (*qualpath)); diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index c01c7c85767..59cb244419f 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -280,9 +280,9 @@ protected: HIR::SelfParam lower_self (AST::Param &self); - HIR::Type *lower_type_no_bounds (AST::TypeNoBounds *type); + HIR::Type *lower_type_no_bounds (AST::TypeNoBounds &type); - HIR::TypeParamBound *lower_bound (AST::TypeParamBound *bound); + HIR::TypeParamBound *lower_bound (AST::TypeParamBound &bound); HIR::QualifiedPathType lower_qual_path_type (AST::QualifiedPathType &qual_path_type); @@ -310,7 +310,7 @@ protected: lower_tuple_pattern_ranged (AST::TuplePatternItemsRanged &pattern); std::unique_ptr - lower_range_pattern_bound (AST::RangePatternBound *bound); + lower_range_pattern_bound (AST::RangePatternBound &bound); HIR::Literal lower_literal (const AST::Literal &literal); diff --git a/gcc/rust/hir/rust-ast-lower-block.h b/gcc/rust/hir/rust-ast-lower-block.h index 300c24e0ab6..e15776a733f 100644 --- a/gcc/rust/hir/rust-ast-lower-block.h +++ b/gcc/rust/hir/rust-ast-lower-block.h @@ -30,11 +30,11 @@ class ASTLoweringBlock : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::BlockExpr *translate (AST::BlockExpr *expr, bool *terminated) + static HIR::BlockExpr *translate (AST::BlockExpr &expr, bool *terminated) { ASTLoweringBlock resolver; - expr->normalize_tail_expr (); - expr->accept_vis (resolver); + expr.normalize_tail_expr (); + expr.accept_vis (resolver); if (resolver.translated != nullptr) { resolver.mappings->insert_hir_expr (resolver.translated); @@ -44,16 +44,15 @@ public: return resolver.translated; } - static HIR::UnsafeBlockExpr *translate (AST::UnsafeBlockExpr *expr, + static HIR::UnsafeBlockExpr *translate (AST::UnsafeBlockExpr &expr, bool *terminated) { ASTLoweringBlock resolver; HIR::BlockExpr *block - = ASTLoweringBlock::translate (expr->get_block_expr ().get (), - terminated); + = ASTLoweringBlock::translate (expr.get_block_expr (), terminated); auto crate_num = resolver.mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, expr->get_node_id (), + Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), resolver.mappings->get_next_hir_id ( crate_num), UNKNOWN_LOCAL_DEFID); @@ -61,7 +60,7 @@ public: HIR::UnsafeBlockExpr *translated = new HIR::UnsafeBlockExpr (mapping, std::unique_ptr (block), - expr->get_outer_attrs (), expr->get_locus ()); + expr.get_outer_attrs (), expr.get_locus ()); resolver.mappings->insert_hir_expr (translated); @@ -84,10 +83,10 @@ class ASTLoweringIfBlock : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::IfExpr *translate (AST::IfExpr *expr, bool *terminated) + static HIR::IfExpr *translate (AST::IfExpr &expr, bool *terminated) { ASTLoweringIfBlock resolver; - expr->accept_vis (resolver); + expr.accept_vis (resolver); if (resolver.translated != nullptr) { resolver.mappings->insert_hir_expr (resolver.translated); @@ -116,10 +115,10 @@ class ASTLoweringIfLetBlock : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::IfLetExpr *translate (AST::IfLetExpr *expr) + static HIR::IfLetExpr *translate (AST::IfLetExpr &expr) { ASTLoweringIfLetBlock resolver; - expr->accept_vis (resolver); + expr.accept_vis (resolver); if (resolver.translated != nullptr) { resolver.mappings->insert_hir_expr (resolver.translated); @@ -144,11 +143,11 @@ class ASTLoweringExprWithBlock : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::ExprWithBlock *translate (AST::ExprWithBlock *expr, + static HIR::ExprWithBlock *translate (AST::ExprWithBlock &expr, bool *terminated) { ASTLoweringExprWithBlock resolver; - expr->accept_vis (resolver); + expr.accept_vis (resolver); if (resolver.translated != nullptr) { resolver.mappings->insert_hir_expr (resolver.translated); @@ -162,39 +161,38 @@ public: void visit (AST::IfExpr &expr) override { - translated = ASTLoweringIfBlock::translate (&expr, &terminated); + translated = ASTLoweringIfBlock::translate (expr, &terminated); } void visit (AST::IfExprConseqElse &expr) override { - translated = ASTLoweringIfBlock::translate (&expr, &terminated); + translated = ASTLoweringIfBlock::translate (expr, &terminated); } void visit (AST::IfLetExpr &expr) override { - translated = ASTLoweringIfLetBlock::translate (&expr); + translated = ASTLoweringIfLetBlock::translate (expr); } void visit (AST::IfLetExprConseqElse &expr) override { - translated = ASTLoweringIfLetBlock::translate (&expr); + translated = ASTLoweringIfLetBlock::translate (expr); } void visit (AST::BlockExpr &expr) override { - translated = ASTLoweringBlock::translate (&expr, &terminated); + translated = ASTLoweringBlock::translate (expr, &terminated); } void visit (AST::UnsafeBlockExpr &expr) override { - translated = ASTLoweringBlock::translate (&expr, &terminated); + translated = ASTLoweringBlock::translate (expr, &terminated); } void visit (AST::LoopExpr &expr) override { HIR::BlockExpr *loop_block - = ASTLoweringBlock::translate (expr.get_loop_block ().get (), - &terminated); + = ASTLoweringBlock::translate (expr.get_loop_block (), &terminated); HIR::LoopLabel loop_label = lower_loop_label (expr.get_loop_label ()); diff --git a/gcc/rust/hir/rust-ast-lower-enumitem.h b/gcc/rust/hir/rust-ast-lower-enumitem.h index d78d8b17a61..3cbf6e88661 100644 --- a/gcc/rust/hir/rust-ast-lower-enumitem.h +++ b/gcc/rust/hir/rust-ast-lower-enumitem.h @@ -83,8 +83,7 @@ public: for (auto &field : item.get_tuple_fields ()) { HIR::Visibility vis = translate_visibility (field.get_visibility ()); - HIR::Type *type - = ASTLoweringType::translate (field.get_field_type ().get ()); + HIR::Type *type = ASTLoweringType::translate (field.get_field_type ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping field_mapping ( @@ -121,8 +120,7 @@ public: for (auto &field : item.get_struct_fields ()) { HIR::Visibility vis = translate_visibility (field.get_visibility ()); - HIR::Type *type - = ASTLoweringType::translate (field.get_field_type ().get ()); + HIR::Type *type = ASTLoweringType::translate (field.get_field_type ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping field_mapping ( @@ -160,7 +158,7 @@ public: "visibility qualifier %qs not allowed on enum item", item.get_visibility ().as_string ().c_str ()); - HIR::Expr *expr = ASTLoweringExpr::translate (item.get_expr ().get ()); + HIR::Expr *expr = ASTLoweringExpr::translate (item.get_expr ()); translated = new HIR::EnumItemDiscriminant (mapping, item.get_identifier (), std::unique_ptr (expr), diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc index ece15529b5f..6944db9b9cc 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.cc +++ b/gcc/rust/hir/rust-ast-lower-expr.cc @@ -35,20 +35,20 @@ ASTLoweringExpr::ASTLoweringExpr () {} HIR::Expr * -ASTLoweringExpr::translate (AST::Expr *expr, bool *terminated) +ASTLoweringExpr::translate (AST::Expr &expr, bool *terminated) { ASTLoweringExpr resolver; - expr->accept_vis (resolver); + expr.accept_vis (resolver); if (resolver.translated == nullptr) { - rust_fatal_error (expr->get_locus (), "Failed to lower expr: [%s]", - expr->as_string ().c_str ()); + rust_fatal_error (expr.get_locus (), "Failed to lower expr: [%s]", + expr.as_string ().c_str ()); return nullptr; } resolver.mappings->insert_hir_expr (resolver.translated); resolver.mappings->insert_location ( - resolver.translated->get_mappings ().get_hirid (), expr->get_locus ()); + resolver.translated->get_mappings ().get_hirid (), expr.get_locus ()); if (terminated != nullptr) *terminated = resolver.terminated; @@ -60,7 +60,7 @@ void ASTLoweringExpr::visit (AST::TupleIndexExpr &expr) { HIR::Expr *tuple_expr - = ASTLoweringExpr::translate (expr.get_tuple_expr ().get (), &terminated); + = ASTLoweringExpr::translate (expr.get_tuple_expr (), &terminated); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -79,7 +79,7 @@ ASTLoweringExpr::visit (AST::TupleExpr &expr) std::vector > tuple_elements; for (auto &e : expr.get_tuple_elems ()) { - HIR::Expr *t = ASTLoweringExpr::translate (e.get ()); + HIR::Expr *t = ASTLoweringExpr::translate (*e); tuple_elements.push_back (std::unique_ptr (t)); } @@ -97,49 +97,49 @@ ASTLoweringExpr::visit (AST::TupleExpr &expr) void ASTLoweringExpr::visit (AST::IfExpr &expr) { - translated = ASTLoweringIfBlock::translate (&expr, &terminated); + translated = ASTLoweringIfBlock::translate (expr, &terminated); } void ASTLoweringExpr::visit (AST::IfExprConseqElse &expr) { - translated = ASTLoweringIfBlock::translate (&expr, &terminated); + translated = ASTLoweringIfBlock::translate (expr, &terminated); } void ASTLoweringExpr::visit (AST::IfLetExpr &expr) { - translated = ASTLoweringIfLetBlock::translate (&expr); + translated = ASTLoweringIfLetBlock::translate (expr); } void ASTLoweringExpr::visit (AST::IfLetExprConseqElse &expr) { - translated = ASTLoweringIfLetBlock::translate (&expr); + translated = ASTLoweringIfLetBlock::translate (expr); } void ASTLoweringExpr::visit (AST::BlockExpr &expr) { - translated = ASTLoweringBlock::translate (&expr, &terminated); + translated = ASTLoweringBlock::translate (expr, &terminated); } void ASTLoweringExpr::visit (AST::UnsafeBlockExpr &expr) { - translated = ASTLoweringBlock::translate (&expr, &terminated); + translated = ASTLoweringBlock::translate (expr, &terminated); } void ASTLoweringExpr::visit (AST::PathInExpression &expr) { - translated = ASTLowerPathInExpression::translate (&expr); + translated = ASTLowerPathInExpression::translate (expr); } void ASTLoweringExpr::visit (AST::QualifiedPathInExpression &expr) { - translated = ASTLowerQualPathInExpression::translate (&expr); + translated = ASTLowerQualPathInExpression::translate (expr); } void @@ -148,7 +148,7 @@ ASTLoweringExpr::visit (AST::ReturnExpr &expr) terminated = true; HIR::Expr *return_expr = expr.has_returned_expr () - ? ASTLoweringExpr::translate (expr.get_returned_expr ().get ()) + ? ASTLoweringExpr::translate (expr.get_returned_expr ()) : nullptr; auto crate_num = mappings->get_current_crate (); @@ -163,14 +163,13 @@ ASTLoweringExpr::visit (AST::ReturnExpr &expr) void ASTLoweringExpr::visit (AST::CallExpr &expr) { - HIR::Expr *func - = ASTLoweringExpr::translate (expr.get_function_expr ().get ()); + HIR::Expr *func = ASTLoweringExpr::translate (expr.get_function_expr ()); auto const &in_params = expr.get_params (); std::vector > params; for (auto ¶m : in_params) { - auto trans = ASTLoweringExpr::translate (param.get ()); + auto trans = ASTLoweringExpr::translate (*param); params.push_back (std::unique_ptr (trans)); } @@ -190,14 +189,13 @@ ASTLoweringExpr::visit (AST::MethodCallExpr &expr) HIR::PathExprSegment method_path = lower_path_expr_seg (expr.get_method_name ()); - HIR::Expr *receiver - = ASTLoweringExpr::translate (expr.get_receiver_expr ().get ()); + HIR::Expr *receiver = ASTLoweringExpr::translate (expr.get_receiver_expr ()); auto const &in_params = expr.get_params (); std::vector > params; for (auto ¶m : in_params) { - auto trans = ASTLoweringExpr::translate (param.get ()); + auto trans = ASTLoweringExpr::translate (*param); params.push_back (std::unique_ptr (trans)); } @@ -215,8 +213,8 @@ ASTLoweringExpr::visit (AST::MethodCallExpr &expr) void ASTLoweringExpr::visit (AST::AssignmentExpr &expr) { - HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); - HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); + HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ()); + HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -266,10 +264,9 @@ ASTLoweringExpr::visit (AST::ArrayExpr &expr) void ASTLoweringExpr::visit (AST::ArrayIndexExpr &expr) { - HIR::Expr *array_expr - = ASTLoweringExpr::translate (expr.get_array_expr ().get ()); + HIR::Expr *array_expr = ASTLoweringExpr::translate (expr.get_array_expr ()); HIR::Expr *array_index_expr - = ASTLoweringExpr::translate (expr.get_index_expr ().get ()); + = ASTLoweringExpr::translate (expr.get_index_expr ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -288,7 +285,7 @@ ASTLoweringExpr::visit (AST::ArrayElemsValues &elems) std::vector > elements; for (auto &elem : elems.get_values ()) { - HIR::Expr *translated_elem = ASTLoweringExpr::translate (elem.get ()); + HIR::Expr *translated_elem = ASTLoweringExpr::translate (*elem); elements.push_back (std::unique_ptr (translated_elem)); } @@ -305,10 +302,8 @@ ASTLoweringExpr::visit (AST::ArrayElemsValues &elems) void ASTLoweringExpr::visit (AST::ArrayElemsCopied &elems) { - HIR::Expr *element - = ASTLoweringExpr::translate (elems.get_elem_to_copy ().get ()); - HIR::Expr *num_copies - = ASTLoweringExpr::translate (elems.get_num_copies ().get ()); + HIR::Expr *element = ASTLoweringExpr::translate (elems.get_elem_to_copy ()); + HIR::Expr *num_copies = ASTLoweringExpr::translate (elems.get_num_copies ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (mappings->get_current_crate (), @@ -337,9 +332,9 @@ ASTLoweringExpr::visit (AST::LiteralExpr &expr) void ASTLoweringExpr::visit (AST::ArithmeticOrLogicalExpr &expr) { - HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); + HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ()); rust_assert (lhs != nullptr); - HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); + HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ()); rust_assert (rhs != nullptr); auto crate_num = mappings->get_current_crate (); @@ -355,9 +350,9 @@ ASTLoweringExpr::visit (AST::ArithmeticOrLogicalExpr &expr) void ASTLoweringExpr::visit (AST::ComparisonExpr &expr) { - HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); + HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ()); rust_assert (lhs != nullptr); - HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); + HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ()); rust_assert (rhs != nullptr); auto crate_num = mappings->get_current_crate (); @@ -374,9 +369,9 @@ ASTLoweringExpr::visit (AST::ComparisonExpr &expr) void ASTLoweringExpr::visit (AST::LazyBooleanExpr &expr) { - HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); + HIR::Expr *lhs = ASTLoweringExpr::translate (expr.get_left_expr ()); rust_assert (lhs != nullptr); - HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); + HIR::Expr *rhs = ASTLoweringExpr::translate (expr.get_right_expr ()); rust_assert (rhs != nullptr); auto crate_num = mappings->get_current_crate (); @@ -394,7 +389,7 @@ void ASTLoweringExpr::visit (AST::NegationExpr &expr) { HIR::Expr *negated_value - = ASTLoweringExpr::translate (expr.get_negated_expr ().get ()); + = ASTLoweringExpr::translate (expr.get_negated_expr ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -411,9 +406,9 @@ void ASTLoweringExpr::visit (AST::TypeCastExpr &expr) { HIR::Expr *expr_to_cast_to - = ASTLoweringExpr::translate (expr.get_casted_expr ().get ()); + = ASTLoweringExpr::translate (expr.get_casted_expr ()); HIR::Type *type_to_cast_to - = lower_type_no_bounds (expr.get_type_to_cast_to ().get ()); + = lower_type_no_bounds (expr.get_type_to_cast_to ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -467,9 +462,8 @@ ASTLoweringExpr::visit (AST::CompoundAssignmentExpr &expr) rust_unreachable (); } - HIR::Expr *asignee_expr - = ASTLoweringExpr::translate (expr.get_left_expr ().get ()); - HIR::Expr *value = ASTLoweringExpr::translate (expr.get_right_expr ().get ()); + HIR::Expr *asignee_expr = ASTLoweringExpr::translate (expr.get_left_expr ()); + HIR::Expr *value = ASTLoweringExpr::translate (expr.get_right_expr ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -485,7 +479,7 @@ void ASTLoweringExpr::visit (AST::StructExprStruct &struct_expr) { HIR::PathInExpression *path - = ASTLowerPathInExpression::translate (&struct_expr.get_struct_name ()); + = ASTLowerPathInExpression::translate (struct_expr.get_struct_name ()); HIR::PathInExpression copied_path (*path); delete path; @@ -505,7 +499,7 @@ ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr) { // bit of a hack for now HIR::PathInExpression *path - = ASTLowerPathInExpression::translate (&struct_expr.get_struct_name ()); + = ASTLowerPathInExpression::translate (struct_expr.get_struct_name ()); HIR::PathInExpression copied_path (*path); delete path; @@ -513,7 +507,7 @@ ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr) if (struct_expr.has_struct_base ()) { HIR::Expr *translated_base = ASTLoweringExpr::translate ( - struct_expr.get_struct_base ().get_base_struct ().get ()); + struct_expr.get_struct_base ().get_base_struct ()); base = new HIR::StructBase (std::unique_ptr (translated_base)); } @@ -522,7 +516,7 @@ ASTLoweringExpr::visit (AST::StructExprStructFields &struct_expr) for (auto &field : in_fields) { HIR::StructExprField *translated - = ASTLowerStructExprField::translate (field.get ()); + = ASTLowerStructExprField::translate (*field); fields.push_back (std::unique_ptr (translated)); } @@ -542,7 +536,7 @@ void ASTLoweringExpr::visit (AST::GroupedExpr &expr) { HIR::Expr *paren_expr - = ASTLoweringExpr::translate (expr.get_expr_in_parens ().get ()); + = ASTLoweringExpr::translate (expr.get_expr_in_parens ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -558,8 +552,7 @@ ASTLoweringExpr::visit (AST::GroupedExpr &expr) void ASTLoweringExpr::visit (AST::FieldAccessExpr &expr) { - HIR::Expr *receiver - = ASTLoweringExpr::translate (expr.get_receiver_expr ().get ()); + HIR::Expr *receiver = ASTLoweringExpr::translate (expr.get_receiver_expr ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -574,19 +567,19 @@ ASTLoweringExpr::visit (AST::FieldAccessExpr &expr) void ASTLoweringExpr::visit (AST::LoopExpr &expr) { - translated = ASTLoweringExprWithBlock::translate (&expr, &terminated); + translated = ASTLoweringExprWithBlock::translate (expr, &terminated); } void ASTLoweringExpr::visit (AST::WhileLoopExpr &expr) { - translated = ASTLoweringExprWithBlock::translate (&expr, &terminated); + translated = ASTLoweringExprWithBlock::translate (expr, &terminated); } void ASTLoweringExpr::visit (AST::ForLoopExpr &expr) { - translated = ASTLoweringExprWithBlock::translate (&expr, &terminated); + translated = ASTLoweringExprWithBlock::translate (expr, &terminated); } void @@ -596,7 +589,7 @@ ASTLoweringExpr::visit (AST::BreakExpr &expr) = lower_lifetime (expr.get_label ().get_lifetime ()); HIR::Expr *break_expr = expr.has_break_expr () - ? ASTLoweringExpr::translate (expr.get_break_expr ().get ()) + ? ASTLoweringExpr::translate (expr.get_break_expr ()) : nullptr; auto crate_num = mappings->get_current_crate (); @@ -629,7 +622,7 @@ void ASTLoweringExpr::visit (AST::BorrowExpr &expr) { HIR::Expr *borrow_lvalue - = ASTLoweringExpr::translate (expr.get_borrowed_expr ().get ()); + = ASTLoweringExpr::translate (expr.get_borrowed_expr ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -664,7 +657,7 @@ void ASTLoweringExpr::visit (AST::DereferenceExpr &expr) { HIR::Expr *dref_lvalue - = ASTLoweringExpr::translate (expr.get_dereferenced_expr ().get ()); + = ASTLoweringExpr::translate (expr.get_dereferenced_expr ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -681,7 +674,7 @@ void ASTLoweringExpr::visit (AST::ErrorPropagationExpr &expr) { HIR::Expr *propagating_expr - = ASTLoweringExpr::translate (expr.get_propagating_expr ().get ()); + = ASTLoweringExpr::translate (expr.get_propagating_expr ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -695,7 +688,7 @@ ASTLoweringExpr::visit (AST::ErrorPropagationExpr &expr) void ASTLoweringExpr::visit (AST::MatchExpr &expr) { - translated = ASTLoweringExprWithBlock::translate (&expr, &terminated); + translated = ASTLoweringExprWithBlock::translate (expr, &terminated); } void @@ -706,9 +699,8 @@ ASTLoweringExpr::visit (AST::RangeFromToExpr &expr) mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); - HIR::Expr *range_from - = ASTLoweringExpr::translate (expr.get_from_expr ().get ()); - HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ().get ()); + HIR::Expr *range_from = ASTLoweringExpr::translate (expr.get_from_expr ()); + HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ()); translated = new HIR::RangeFromToExpr (mapping, @@ -725,8 +717,7 @@ ASTLoweringExpr::visit (AST::RangeFromExpr &expr) mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); - HIR::Expr *range_from - = ASTLoweringExpr::translate (expr.get_from_expr ().get ()); + HIR::Expr *range_from = ASTLoweringExpr::translate (expr.get_from_expr ()); translated = new HIR::RangeFromExpr (mapping, std::unique_ptr (range_from), @@ -741,7 +732,7 @@ ASTLoweringExpr::visit (AST::RangeToExpr &expr) mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); - HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ().get ()); + HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ()); translated = new HIR::RangeToExpr (mapping, std::unique_ptr (range_to), @@ -767,9 +758,8 @@ ASTLoweringExpr::visit (AST::RangeFromToInclExpr &expr) mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); - HIR::Expr *range_from - = ASTLoweringExpr::translate (expr.get_from_expr ().get ()); - HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ().get ()); + HIR::Expr *range_from = ASTLoweringExpr::translate (expr.get_from_expr ()); + HIR::Expr *range_to = ASTLoweringExpr::translate (expr.get_to_expr ()); translated = new HIR::RangeFromToInclExpr (mapping, @@ -782,7 +772,7 @@ void ASTLoweringExpr::visit (AST::ClosureExprInner &expr) { HIR::Expr *closure_expr - = ASTLoweringExpr::translate (expr.get_definition_expr ().get ()); + = ASTLoweringExpr::translate (expr.get_definition_expr ()); std::vector closure_params; for (auto ¶m : expr.get_params ()) @@ -809,7 +799,7 @@ ASTLoweringExpr::visit (AST::ClosureExprInnerTyped &expr) { HIR::Type *closure_return_type = nullptr; HIR::Expr *closure_expr - = ASTLoweringExpr::translate (expr.get_definition_block ().get ()); + = ASTLoweringExpr::translate (expr.get_definition_block ()); std::vector closure_params; for (auto ¶m : expr.get_params ()) diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h index 168dd014002..ab3ae0a8b5f 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.h +++ b/gcc/rust/hir/rust-ast-lower-expr.h @@ -30,10 +30,10 @@ class ASTLowerPathInExpression : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::PathInExpression *translate (AST::PathInExpression *expr) + static HIR::PathInExpression *translate (AST::PathInExpression &expr) { ASTLowerPathInExpression compiler; - expr->accept_vis (compiler); + expr.accept_vis (compiler); rust_assert (compiler.translated); return compiler.translated; } @@ -52,10 +52,10 @@ class ASTLowerQualPathInExpression : public ASTLoweringBase public: static HIR::QualifiedPathInExpression * - translate (AST::QualifiedPathInExpression *expr) + translate (AST::QualifiedPathInExpression &expr) { ASTLowerQualPathInExpression compiler; - expr->accept_vis (compiler); + expr.accept_vis (compiler); rust_assert (compiler.translated); return compiler.translated; } @@ -73,7 +73,7 @@ class ASTLoweringExpr : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::Expr *translate (AST::Expr *expr, bool *terminated = nullptr); + static HIR::Expr *translate (AST::Expr &expr, bool *terminated = nullptr); void visit (AST::TupleIndexExpr &expr) override; void visit (AST::TupleExpr &expr) override; diff --git a/gcc/rust/hir/rust-ast-lower-extern.h b/gcc/rust/hir/rust-ast-lower-extern.h index ad7d75422d6..e92acdc44a1 100644 --- a/gcc/rust/hir/rust-ast-lower-extern.h +++ b/gcc/rust/hir/rust-ast-lower-extern.h @@ -51,8 +51,7 @@ public: void visit (AST::ExternalStaticItem &item) override { HIR::Visibility vis = translate_visibility (item.get_visibility ()); - HIR::Type *static_type - = ASTLoweringType::translate (item.get_type ().get ()); + HIR::Type *static_type = ASTLoweringType::translate (item.get_type ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, item.get_node_id (), @@ -77,7 +76,7 @@ public: HIR::Type *return_type = function.has_return_type () - ? ASTLoweringType::translate (function.get_return_type ().get ()) + ? ASTLoweringType::translate (function.get_return_type ()) : nullptr; bool is_variadic = function.is_variadic (); @@ -88,25 +87,24 @@ public: std::vector function_params; for (auto it = begin; it != end; it++) { - auto param = static_cast (it->get ()); + auto ¶m = static_cast (**it); - if (param->is_variadic () || param->is_self ()) + if (param.is_variadic () || param.is_self ()) continue; - auto param_kind = param->get_pattern ()->get_pattern_kind (); + auto param_kind = param.get_pattern ().get_pattern_kind (); rust_assert (param_kind == AST::Pattern::Kind::Identifier || param_kind == AST::Pattern::Kind::Wildcard); - auto param_ident = static_cast ( - param->get_pattern ().get ()); + auto ¶m_ident + = static_cast (param.get_pattern ()); Identifier param_name = param_kind == AST::Pattern::Kind::Identifier - ? param_ident->get_ident () + ? param_ident.get_ident () : std::string ("_"); - HIR::Type *param_type - = ASTLoweringType::translate (param->get_type ().get ()); + HIR::Type *param_type = ASTLoweringType::translate (param.get_type ()); auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, param->get_node_id (), + Analysis::NodeMapping mapping (crate_num, param.get_node_id (), mappings->get_next_hir_id (crate_num), mappings->get_next_localdef_id ( crate_num)); diff --git a/gcc/rust/hir/rust-ast-lower-implitem.cc b/gcc/rust/hir/rust-ast-lower-implitem.cc index 38bac5de703..41761bbce32 100644 --- a/gcc/rust/hir/rust-ast-lower-implitem.cc +++ b/gcc/rust/hir/rust-ast-lower-implitem.cc @@ -28,10 +28,10 @@ namespace Rust { namespace HIR { HIR::ImplItem * -ASTLowerImplItem::translate (AST::AssociatedItem *item, HirId parent_impl_id) +ASTLowerImplItem::translate (AST::AssociatedItem &item, HirId parent_impl_id) { ASTLowerImplItem resolver; - item->accept_vis (resolver); + item.accept_vis (resolver); if (resolver.translated != nullptr) { @@ -63,7 +63,7 @@ ASTLowerImplItem::visit (AST::TypeAlias &alias) generic_params = lower_generic_params (alias.get_generic_params ()); HIR::Type *existing_type - = ASTLoweringType::translate (alias.get_type_aliased ().get ()); + = ASTLoweringType::translate (alias.get_type_aliased ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, alias.get_node_id (), @@ -86,9 +86,8 @@ ASTLowerImplItem::visit (AST::ConstantItem &constant) { HIR::Visibility vis = translate_visibility (constant.get_visibility ()); - HIR::Type *type - = ASTLoweringType::translate (constant.get_type ().get (), true); - HIR::Expr *expr = ASTLoweringExpr::translate (constant.get_expr ().get ()); + HIR::Type *type = ASTLoweringType::translate (constant.get_type (), true); + HIR::Expr *expr = ASTLoweringExpr::translate (constant.get_expr ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, constant.get_node_id (), @@ -138,7 +137,7 @@ ASTLowerImplItem::visit (AST::Function &function) std::unique_ptr return_type = function.has_return_type () ? std::unique_ptr ( - ASTLoweringType::translate (function.get_return_type ().get ())) + ASTLoweringType::translate (function.get_return_type ())) : nullptr; std::vector function_params; @@ -146,28 +145,28 @@ ASTLowerImplItem::visit (AST::Function &function) { if (p->is_self () || p->is_variadic ()) continue; - auto param = static_cast (p.get ()); + auto param = static_cast (*p); auto translated_pattern = std::unique_ptr ( - ASTLoweringPattern::translate (param->get_pattern ().get ())); + ASTLoweringPattern::translate (param.get_pattern ())); auto translated_type = std::unique_ptr ( - ASTLoweringType::translate (param->get_type ().get ())); + ASTLoweringType::translate (param.get_type ())); auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, param->get_node_id (), + Analysis::NodeMapping mapping (crate_num, param.get_node_id (), mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); auto hir_param = HIR::FunctionParam (mapping, std::move (translated_pattern), - std::move (translated_type), param->get_locus ()); + std::move (translated_type), param.get_locus ()); function_params.push_back (std::move (hir_param)); } bool terminated = false; std::unique_ptr function_body = std::unique_ptr ( - ASTLoweringBlock::translate (function.get_definition ()->get (), + ASTLoweringBlock::translate (*function.get_definition ().value (), &terminated)); auto crate_num = mappings->get_current_crate (); @@ -207,10 +206,10 @@ ASTLowerImplItem::visit (AST::Function &function) } HIR::TraitItem * -ASTLowerTraitItem::translate (AST::AssociatedItem *item) +ASTLowerTraitItem::translate (AST::AssociatedItem &item) { ASTLowerTraitItem resolver; - item->accept_vis (resolver); + item.accept_vis (resolver); if (resolver.translated != nullptr) { @@ -241,7 +240,7 @@ ASTLowerTraitItem::visit (AST::Function &func) std::unique_ptr return_type = func.has_return_type () ? std::unique_ptr ( - ASTLoweringType::translate (func.get_return_type ().get ())) + ASTLoweringType::translate (func.get_return_type ())) : nullptr; // set self parameter to error if this is a method @@ -256,21 +255,21 @@ ASTLowerTraitItem::visit (AST::Function &func) if (p->is_variadic () || p->is_self ()) continue; - auto param = static_cast (p.get ()); + auto param = static_cast (*p); auto translated_pattern = std::unique_ptr ( - ASTLoweringPattern::translate (param->get_pattern ().get ())); + ASTLoweringPattern::translate (param.get_pattern ())); auto translated_type = std::unique_ptr ( - ASTLoweringType::translate (param->get_type ().get ())); + ASTLoweringType::translate (param.get_type ())); auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, param->get_node_id (), + Analysis::NodeMapping mapping (crate_num, param.get_node_id (), mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); auto hir_param = HIR::FunctionParam (mapping, std::move (translated_pattern), - std::move (translated_type), param->get_locus ()); + std::move (translated_type), param.get_locus ()); function_params.push_back (hir_param); } @@ -284,7 +283,7 @@ ASTLowerTraitItem::visit (AST::Function &func) bool terminated = false; std::unique_ptr block_expr = func.has_body () ? std::unique_ptr ( - ASTLoweringBlock::translate (func.get_definition ()->get (), + ASTLoweringBlock::translate (*func.get_definition ().value (), &terminated)) : nullptr; @@ -316,9 +315,9 @@ ASTLowerTraitItem::visit (AST::Function &func) void ASTLowerTraitItem::visit (AST::TraitItemConst &constant) { - HIR::Type *type = ASTLoweringType::translate (constant.get_type ().get ()); + HIR::Type *type = ASTLoweringType::translate (constant.get_type ()); HIR::Expr *expr = constant.has_expression () - ? ASTLoweringExpr::translate (constant.get_expr ().get ()) + ? ASTLoweringExpr::translate (constant.get_expr ()) : nullptr; auto crate_num = mappings->get_current_crate (); diff --git a/gcc/rust/hir/rust-ast-lower-implitem.h b/gcc/rust/hir/rust-ast-lower-implitem.h index bbde9f6878c..bd511b7d1d5 100644 --- a/gcc/rust/hir/rust-ast-lower-implitem.h +++ b/gcc/rust/hir/rust-ast-lower-implitem.h @@ -29,7 +29,7 @@ class ASTLowerImplItem : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::ImplItem *translate (AST::AssociatedItem *item, + static HIR::ImplItem *translate (AST::AssociatedItem &item, HirId parent_impl_id); void visit (AST::TypeAlias &alias) override; void visit (AST::ConstantItem &constant) override; @@ -47,7 +47,7 @@ class ASTLowerTraitItem : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::TraitItem *translate (AST::AssociatedItem *item); + static HIR::TraitItem *translate (AST::AssociatedItem &item); void visit (AST::Function &func) override; void visit (AST::TraitItemConst &constant) override; void visit (AST::TraitItemType &type) override; diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc index 7ef556fee0d..bfcdb986527 100644 --- a/gcc/rust/hir/rust-ast-lower-item.cc +++ b/gcc/rust/hir/rust-ast-lower-item.cc @@ -32,10 +32,10 @@ namespace Rust { namespace HIR { HIR::Item * -ASTLoweringItem::translate (AST::Item *item) +ASTLoweringItem::translate (AST::Item &item) { ASTLoweringItem resolver; - item->accept_vis (resolver); + item.accept_vis (resolver); if (resolver.translated != nullptr) { @@ -44,7 +44,7 @@ ASTLoweringItem::translate (AST::Item *item) auto locus = resolver.translated->get_locus (); resolver.handle_outer_attributes (*resolver.translated); - resolver.mappings->insert_ast_item (item); + resolver.mappings->insert_ast_item (&item); resolver.mappings->insert_hir_item (resolver.translated); resolver.mappings->insert_location (id, locus); resolver.mappings->insert_defid_mapping (defid, resolver.translated); @@ -68,7 +68,7 @@ ASTLoweringItem::visit (AST::Module &module) for (auto &item : module.get_items ()) { - auto transitem = translate (item.get ()); + auto transitem = translate (*item); // The item may be null if it doesn't need to live in the HIR - for // example, macro rules definitions if (transitem) @@ -105,7 +105,7 @@ ASTLoweringItem::visit (AST::TypeAlias &alias) generic_params = lower_generic_params (alias.get_generic_params ()); HIR::Type *existing_type - = ASTLoweringType::translate (alias.get_type_aliased ().get ()); + = ASTLoweringType::translate (alias.get_type_aliased ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, alias.get_node_id (), @@ -143,13 +143,12 @@ ASTLoweringItem::visit (AST::TupleStruct &struct_decl) std::vector fields; for (AST::TupleField &field : struct_decl.get_fields ()) { - if (field.get_field_type ()->is_marked_for_strip ()) + if (field.get_field_type ().is_marked_for_strip ()) continue; // FIXME: How do we get the visibility from here? HIR::Visibility vis = translate_visibility (field.get_visibility ()); - HIR::Type *type - = ASTLoweringType::translate (field.get_field_type ().get ()); + HIR::Type *type = ASTLoweringType::translate (field.get_field_type ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, field.get_node_id (), @@ -202,12 +201,11 @@ ASTLoweringItem::visit (AST::StructStruct &struct_decl) std::vector fields; for (AST::StructField &field : struct_decl.get_fields ()) { - if (field.get_field_type ()->is_marked_for_strip ()) + if (field.get_field_type ().is_marked_for_strip ()) continue; HIR::Visibility vis = translate_visibility (field.get_visibility ()); - HIR::Type *type - = ASTLoweringType::translate (field.get_field_type ().get ()); + HIR::Type *type = ASTLoweringType::translate (field.get_field_type ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, field.get_node_id (), @@ -309,13 +307,12 @@ ASTLoweringItem::visit (AST::Union &union_decl) std::vector variants; for (AST::StructField &variant : union_decl.get_variants ()) { - if (variant.get_field_type ()->is_marked_for_strip ()) + if (variant.get_field_type ().is_marked_for_strip ()) continue; // FIXME: Does visibility apply here? HIR::Visibility vis = translate_visibility (variant.get_visibility ()); - HIR::Type *type - = ASTLoweringType::translate (variant.get_field_type ().get ()); + HIR::Type *type = ASTLoweringType::translate (variant.get_field_type ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, variant.get_node_id (), @@ -351,8 +348,8 @@ ASTLoweringItem::visit (AST::StaticItem &var) { HIR::Visibility vis = translate_visibility (var.get_visibility ()); - HIR::Type *type = ASTLoweringType::translate (var.get_type ().get (), true); - HIR::Expr *expr = ASTLoweringExpr::translate (var.get_expr ().get ()); + HIR::Type *type = ASTLoweringType::translate (var.get_type (), true); + HIR::Expr *expr = ASTLoweringExpr::translate (var.get_expr ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, var.get_node_id (), @@ -372,9 +369,8 @@ ASTLoweringItem::visit (AST::ConstantItem &constant) { HIR::Visibility vis = translate_visibility (constant.get_visibility ()); - HIR::Type *type - = ASTLoweringType::translate (constant.get_type ().get (), true); - HIR::Expr *expr = ASTLoweringExpr::translate (constant.get_expr ().get ()); + HIR::Type *type = ASTLoweringType::translate (constant.get_type (), true); + HIR::Expr *expr = ASTLoweringExpr::translate (constant.get_expr ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, constant.get_node_id (), @@ -418,7 +414,7 @@ ASTLoweringItem::visit (AST::Function &function) std::unique_ptr return_type = function.has_return_type () ? std::unique_ptr ( - ASTLoweringType::translate (function.get_return_type ().get ())) + ASTLoweringType::translate (function.get_return_type ())) : nullptr; std::vector function_params; @@ -426,28 +422,28 @@ ASTLoweringItem::visit (AST::Function &function) { if (p->is_variadic () || p->is_self ()) continue; - auto param = static_cast (p.get ()); + auto param = static_cast (*p); auto translated_pattern = std::unique_ptr ( - ASTLoweringPattern::translate (param->get_pattern ().get ())); + ASTLoweringPattern::translate (param.get_pattern ())); auto translated_type = std::unique_ptr ( - ASTLoweringType::translate (param->get_type ().get ())); + ASTLoweringType::translate (param.get_type ())); auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, param->get_node_id (), + Analysis::NodeMapping mapping (crate_num, param.get_node_id (), mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); auto hir_param = HIR::FunctionParam (mapping, std::move (translated_pattern), - std::move (translated_type), param->get_locus ()); + std::move (translated_type), param.get_locus ()); function_params.push_back (std::move (hir_param)); } bool terminated = false; std::unique_ptr function_body = std::unique_ptr ( - ASTLoweringBlock::translate (function.get_definition ()->get (), + ASTLoweringBlock::translate (*function.get_definition ().value (), &terminated)); auto crate_num = mappings->get_current_crate (); @@ -482,8 +478,7 @@ ASTLoweringItem::visit (AST::InherentImpl &impl_block) std::vector> where_clause_items; for (auto &item : impl_block.get_where_clause ().get_items ()) { - HIR::WhereClauseItem *i - = ASTLowerWhereClauseItem::translate (*item.get ()); + HIR::WhereClauseItem *i = ASTLowerWhereClauseItem::translate (*item); where_clause_items.push_back (std::unique_ptr (i)); } @@ -524,8 +519,7 @@ ASTLoweringItem::visit (AST::InherentImpl &impl_block) } } - HIR::Type *impl_type - = ASTLoweringType::translate (impl_block.get_type ().get ()); + HIR::Type *impl_type = ASTLoweringType::translate (impl_block.get_type ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, impl_block.get_node_id (), @@ -540,7 +534,7 @@ ASTLoweringItem::visit (AST::InherentImpl &impl_block) continue; HIR::ImplItem *lowered - = ASTLowerImplItem::translate (impl_item.get (), mapping.get_hirid ()); + = ASTLowerImplItem::translate (*impl_item, mapping.get_hirid ()); rust_assert (lowered != nullptr); impl_items.push_back (std::unique_ptr (lowered)); impl_item_ids.push_back (lowered->get_impl_mappings ().get_hirid ()); @@ -586,7 +580,7 @@ ASTLoweringItem::visit (AST::Trait &trait) { for (auto &bound : trait.get_type_param_bounds ()) { - HIR::TypeParamBound *b = lower_bound (bound.get ()); + HIR::TypeParamBound *b = lower_bound (*bound); type_param_bounds.push_back ( std::unique_ptr (b)); } @@ -599,7 +593,7 @@ ASTLoweringItem::visit (AST::Trait &trait) if (item->is_marked_for_strip ()) continue; - HIR::TraitItem *lowered = ASTLowerTraitItem::translate (item.get ()); + HIR::TraitItem *lowered = ASTLowerTraitItem::translate (*item); trait_items.push_back (std::unique_ptr (lowered)); trait_item_ids.push_back (lowered->get_mappings ().get_hirid ()); } @@ -634,8 +628,7 @@ ASTLoweringItem::visit (AST::TraitImpl &impl_block) std::vector> where_clause_items; for (auto &item : impl_block.get_where_clause ().get_items ()) { - HIR::WhereClauseItem *i - = ASTLowerWhereClauseItem::translate (*item.get ()); + HIR::WhereClauseItem *i = ASTLowerWhereClauseItem::translate (*item); where_clause_items.push_back (std::unique_ptr (i)); } HIR::WhereClause where_clause (std::move (where_clause_items)); @@ -675,8 +668,7 @@ ASTLoweringItem::visit (AST::TraitImpl &impl_block) } } - HIR::Type *impl_type - = ASTLoweringType::translate (impl_block.get_type ().get ()); + HIR::Type *impl_type = ASTLoweringType::translate (impl_block.get_type ()); HIR::TypePath *trait_ref = ASTLowerTypePath::translate (impl_block.get_trait_path ()); @@ -693,7 +685,7 @@ ASTLoweringItem::visit (AST::TraitImpl &impl_block) continue; HIR::ImplItem *lowered - = ASTLowerImplItem::translate (impl_item.get (), mapping.get_hirid ()); + = ASTLowerImplItem::translate (*impl_item, mapping.get_hirid ()); rust_assert (lowered != nullptr); impl_items.push_back (std::unique_ptr (lowered)); impl_item_ids.push_back (lowered->get_impl_mappings ().get_hirid ()); diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h index 0b66084cf4d..522d38f2f2e 100644 --- a/gcc/rust/hir/rust-ast-lower-item.h +++ b/gcc/rust/hir/rust-ast-lower-item.h @@ -29,7 +29,7 @@ class ASTLoweringItem : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::Item *translate (AST::Item *item); + static HIR::Item *translate (AST::Item &item); void visit (AST::Module &module) override; void visit (AST::TypeAlias &alias) override; diff --git a/gcc/rust/hir/rust-ast-lower-pattern.cc b/gcc/rust/hir/rust-ast-lower-pattern.cc index d534b829517..96266dc0c60 100644 --- a/gcc/rust/hir/rust-ast-lower-pattern.cc +++ b/gcc/rust/hir/rust-ast-lower-pattern.cc @@ -25,17 +25,17 @@ namespace HIR { ASTLoweringPattern::ASTLoweringPattern () : translated (nullptr) {} HIR::Pattern * -ASTLoweringPattern::translate (AST::Pattern *pattern, bool is_let_top_level) +ASTLoweringPattern::translate (AST::Pattern &pattern, bool is_let_top_level) { ASTLoweringPattern resolver; resolver.is_let_top_level = is_let_top_level; - pattern->accept_vis (resolver); + pattern.accept_vis (resolver); rust_assert (resolver.translated != nullptr); resolver.mappings->insert_hir_pattern (resolver.translated); resolver.mappings->insert_location ( - resolver.translated->get_mappings ().get_hirid (), pattern->get_locus ()); + resolver.translated->get_mappings ().get_hirid (), pattern.get_locus ()); return resolver.translated; } @@ -60,18 +60,18 @@ ASTLoweringPattern::visit (AST::IdentifierPattern &pattern) void ASTLoweringPattern::visit (AST::PathInExpression &pattern) { - translated = ASTLowerPathInExpression::translate (&pattern); + translated = ASTLowerPathInExpression::translate (pattern); } void ASTLoweringPattern::visit (AST::TupleStructPattern &pattern) { HIR::PathInExpression *path - = ASTLowerPathInExpression::translate (&pattern.get_path ()); + = ASTLowerPathInExpression::translate (pattern.get_path ()); TupleStructItems *lowered = nullptr; auto &items = pattern.get_items (); - switch (items->get_item_type ()) + switch (items.get_item_type ()) { case AST::TupleStructItems::RANGE: { // TODO @@ -81,13 +81,12 @@ ASTLoweringPattern::visit (AST::TupleStructPattern &pattern) case AST::TupleStructItems::NO_RANGE: { AST::TupleStructItemsNoRange &items_no_range - = static_cast (*items.get ()); + = static_cast (items); std::vector> patterns; for (auto &inner_pattern : items_no_range.get_patterns ()) { - HIR::Pattern *p - = ASTLoweringPattern::translate (inner_pattern.get ()); + HIR::Pattern *p = ASTLoweringPattern::translate (*inner_pattern); patterns.push_back (std::unique_ptr (p)); } @@ -109,7 +108,7 @@ void ASTLoweringPattern::visit (AST::StructPattern &pattern) { HIR::PathInExpression *path - = ASTLowerPathInExpression::translate (&pattern.get_path ()); + = ASTLowerPathInExpression::translate (pattern.get_path ()); auto &raw_elems = pattern.get_struct_pattern_elems (); rust_assert (!raw_elems.has_etc ()); @@ -121,7 +120,7 @@ ASTLoweringPattern::visit (AST::StructPattern &pattern) switch (field->get_item_type ()) { case AST::StructPatternField::ItemType::TUPLE_PAT: { - AST::StructPatternFieldTuplePat &tuple + auto &tuple = static_cast (*field); auto crate_num = mappings->get_current_crate (); @@ -130,8 +129,8 @@ ASTLoweringPattern::visit (AST::StructPattern &pattern) crate_num), UNKNOWN_LOCAL_DEFID); - std::unique_ptr pat (ASTLoweringPattern::translate ( - tuple.get_index_pattern ().get ())); + std::unique_ptr pat ( + ASTLoweringPattern::translate (tuple.get_index_pattern ())); f = new HIR::StructPatternFieldTuplePat (mapping, tuple.get_index (), @@ -151,8 +150,8 @@ ASTLoweringPattern::visit (AST::StructPattern &pattern) crate_num), UNKNOWN_LOCAL_DEFID); - std::unique_ptr pat (ASTLoweringPattern::translate ( - ident.get_ident_pattern ().get ())); + std::unique_ptr pat ( + ASTLoweringPattern::translate (ident.get_ident_pattern ())); f = new HIR::StructPatternFieldIdentPat (mapping, ident.get_identifier (), @@ -214,20 +213,19 @@ void ASTLoweringPattern::visit (AST::TuplePattern &pattern) { std::unique_ptr items; - switch (pattern.get_items ()->get_pattern_type ()) + switch (pattern.get_items ().get_pattern_type ()) { case AST::TuplePatternItems::TuplePatternItemType::MULTIPLE: { AST::TuplePatternItemsMultiple &ref - = *static_cast ( - pattern.get_items ().get ()); + = static_cast ( + pattern.get_items ()); items = lower_tuple_pattern_multiple (ref); } break; case AST::TuplePatternItems::TuplePatternItemType::RANGED: { AST::TuplePatternItemsRanged &ref - = *static_cast ( - pattern.get_items ().get ()); + = static_cast (pattern.get_items ()); items = lower_tuple_pattern_ranged (ref); } break; @@ -258,10 +256,8 @@ ASTLoweringPattern::visit (AST::LiteralPattern &pattern) void ASTLoweringPattern::visit (AST::RangePattern &pattern) { - auto upper_bound - = lower_range_pattern_bound (pattern.get_upper_bound ().get ()); - auto lower_bound - = lower_range_pattern_bound (pattern.get_lower_bound ().get ()); + auto upper_bound = lower_range_pattern_bound (pattern.get_upper_bound ()); + auto lower_bound = lower_range_pattern_bound (pattern.get_lower_bound ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, pattern.get_node_id (), @@ -277,7 +273,7 @@ void ASTLoweringPattern::visit (AST::GroupedPattern &pattern) { is_let_top_level = false; - pattern.get_pattern_in_parens ()->accept_vis (*this); + pattern.get_pattern_in_parens ().accept_vis (*this); } void @@ -289,7 +285,7 @@ ASTLoweringPattern::visit (AST::ReferencePattern &pattern) UNKNOWN_LOCAL_DEFID); HIR::Pattern *inner - = ASTLoweringPattern::translate (pattern.get_referenced_pattern ().get ()); + = ASTLoweringPattern::translate (pattern.get_referenced_pattern ()); translated = new HIR::ReferencePattern (mapping, std::unique_ptr (inner), @@ -315,7 +311,7 @@ ASTLoweringPattern::visit (AST::SlicePattern &pattern) std::vector> items; for (auto &p : pattern.get_items ()) { - HIR::Pattern *item = ASTLoweringPattern::translate (p.get ()); + HIR::Pattern *item = ASTLoweringPattern::translate (*p); items.push_back (std::unique_ptr (item)); } @@ -340,8 +336,8 @@ ASTLoweringPattern::visit (AST::AltPattern &pattern) for (auto &alt : pattern.get_alts ()) { - alts.push_back (std::unique_ptr ( - ASTLoweringPattern::translate (alt.get ()))); + alts.push_back ( + std::unique_ptr (ASTLoweringPattern::translate (*alt))); } translated diff --git a/gcc/rust/hir/rust-ast-lower-pattern.h b/gcc/rust/hir/rust-ast-lower-pattern.h index 155308ef385..f750108894e 100644 --- a/gcc/rust/hir/rust-ast-lower-pattern.h +++ b/gcc/rust/hir/rust-ast-lower-pattern.h @@ -29,7 +29,7 @@ class ASTLoweringPattern : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::Pattern *translate (AST::Pattern *pattern, + static HIR::Pattern *translate (AST::Pattern &pattern, bool is_let_top_level = false); void visit (AST::IdentifierPattern &pattern) override; diff --git a/gcc/rust/hir/rust-ast-lower-stmt.cc b/gcc/rust/hir/rust-ast-lower-stmt.cc index 6bd1a241b6d..8c68e5678ad 100644 --- a/gcc/rust/hir/rust-ast-lower-stmt.cc +++ b/gcc/rust/hir/rust-ast-lower-stmt.cc @@ -46,8 +46,7 @@ ASTLoweringStmt::translate (AST::Stmt *stmt, bool *terminated) void ASTLoweringStmt::visit (AST::ExprStmt &stmt) { - HIR::Expr *expr - = ASTLoweringExpr::translate (stmt.get_expr ().get (), &terminated); + HIR::Expr *expr = ASTLoweringExpr::translate (stmt.get_expr (), &terminated); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (), @@ -61,21 +60,20 @@ ASTLoweringStmt::visit (AST::ExprStmt &stmt) void ASTLoweringStmt::visit (AST::ConstantItem &constant) { - translated = ASTLoweringItem::translate (&constant); + translated = ASTLoweringItem::translate (constant); } void ASTLoweringStmt::visit (AST::LetStmt &stmt) { HIR::Pattern *variables - = ASTLoweringPattern::translate (stmt.get_pattern ().get (), true); + = ASTLoweringPattern::translate (stmt.get_pattern (), true); HIR::Type *type = stmt.has_type () - ? ASTLoweringType::translate (stmt.get_type ().get ()) + ? ASTLoweringType::translate (stmt.get_type ()) : nullptr; HIR::Expr *init_expression - = stmt.has_init_expr () - ? ASTLoweringExpr::translate (stmt.get_init_expr ().get ()) - : nullptr; + = stmt.has_init_expr () ? ASTLoweringExpr::translate (stmt.get_init_expr ()) + : nullptr; auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, stmt.get_node_id (), @@ -91,25 +89,25 @@ ASTLoweringStmt::visit (AST::LetStmt &stmt) void ASTLoweringStmt::visit (AST::TupleStruct &struct_decl) { - translated = ASTLoweringItem::translate (&struct_decl); + translated = ASTLoweringItem::translate (struct_decl); } void ASTLoweringStmt::visit (AST::StructStruct &struct_decl) { - translated = ASTLoweringItem::translate (&struct_decl); + translated = ASTLoweringItem::translate (struct_decl); } void ASTLoweringStmt::visit (AST::Union &union_decl) { - translated = ASTLoweringItem::translate (&union_decl); + translated = ASTLoweringItem::translate (union_decl); } void ASTLoweringStmt::visit (AST::Enum &enum_decl) { - translated = ASTLoweringItem::translate (&enum_decl); + translated = ASTLoweringItem::translate (enum_decl); } void @@ -126,7 +124,7 @@ ASTLoweringStmt::visit (AST::EmptyStmt &empty) void ASTLoweringStmt::visit (AST::Function &function) { - translated = ASTLoweringItem::translate (&function); + translated = ASTLoweringItem::translate (function); } void @@ -144,19 +142,19 @@ ASTLoweringStmt::visit (AST::MacroRulesDefinition &def) void ASTLoweringStmt::visit (AST::Trait &trait) { - translated = ASTLoweringItem::translate (&trait); + translated = ASTLoweringItem::translate (trait); } void ASTLoweringStmt::visit (AST::InherentImpl &impl_block) { - translated = ASTLoweringItem::translate (&impl_block); + translated = ASTLoweringItem::translate (impl_block); } void ASTLoweringStmt::visit (AST::TraitImpl &impl_block) { - translated = ASTLoweringItem::translate (&impl_block); + translated = ASTLoweringItem::translate (impl_block); } } // namespace HIR diff --git a/gcc/rust/hir/rust-ast-lower-struct-field-expr.h b/gcc/rust/hir/rust-ast-lower-struct-field-expr.h index 933347affb7..2beba05b2ea 100644 --- a/gcc/rust/hir/rust-ast-lower-struct-field-expr.h +++ b/gcc/rust/hir/rust-ast-lower-struct-field-expr.h @@ -30,15 +30,15 @@ class ASTLowerStructExprField : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::StructExprField *translate (AST::StructExprField *field) + static HIR::StructExprField *translate (AST::StructExprField &field) { ASTLowerStructExprField compiler; - field->accept_vis (compiler); + field.accept_vis (compiler); rust_assert (compiler.translated != nullptr); compiler.mappings->insert_hir_struct_field (compiler.translated); compiler.mappings->insert_location ( - compiler.translated->get_mappings ().get_hirid (), field->get_locus ()); + compiler.translated->get_mappings ().get_hirid (), field.get_locus ()); return compiler.translated; } diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc index 504ca051f59..50ec3f905b0 100644 --- a/gcc/rust/hir/rust-ast-lower-type.cc +++ b/gcc/rust/hir/rust-ast-lower-type.cc @@ -44,14 +44,13 @@ ASTLowerTypePath::visit (AST::TypePathSegmentFunction &segment) std::vector> inputs; for (auto ¶m : fn.get_params ()) { - HIR::Type *hir_type = ASTLoweringType::translate (param.get ()); + HIR::Type *hir_type = ASTLoweringType::translate (*param); inputs.push_back (std::unique_ptr (hir_type)); } HIR::Type *result_type - = fn.has_return_type () - ? ASTLoweringType::translate (fn.get_return_type ().get ()) - : nullptr; + = fn.has_return_type () ? ASTLoweringType::translate (fn.get_return_type ()) + : nullptr; HIR::TypePathFunction function_path (std::move (inputs), std::unique_ptr ( @@ -143,8 +142,8 @@ ASTLowerQualifiedPathInType::visit (AST::QualifiedPathInType &path) crate_num, path.get_qualified_path_type ().get_node_id (), hirid, UNKNOWN_LOCAL_DEFID); - HIR::Type *qual_type = ASTLoweringType::translate ( - path.get_qualified_path_type ().get_type ().get ()); + HIR::Type *qual_type + = ASTLoweringType::translate (path.get_qualified_path_type ().get_type ()); HIR::TypePath *qual_trait = ASTLowerTypePath::translate ( path.get_qualified_path_type ().get_as_type_path ()); @@ -180,10 +179,10 @@ ASTLowerQualifiedPathInType::visit (AST::QualifiedPathInType &path) } HIR::Type * -ASTLoweringType::translate (AST::Type *type, bool default_to_static_lifetime) +ASTLoweringType::translate (AST::Type &type, bool default_to_static_lifetime) { ASTLoweringType resolver (default_to_static_lifetime); - type->accept_vis (resolver); + type.accept_vis (resolver); rust_assert (resolver.translated != nullptr); resolver.mappings->insert_hir_type (resolver.translated); @@ -201,7 +200,7 @@ ASTLoweringType::visit (AST::BareFunctionType &fntype) std::vector lifetime_params; for (auto &lifetime_param : fntype.get_for_lifetimes ()) { - auto generic_param = ASTLowerGenericParam::translate (&lifetime_param); + auto generic_param = ASTLowerGenericParam::translate (lifetime_param); lifetime_params.push_back ( *static_cast (generic_param)); } @@ -229,7 +228,7 @@ ASTLoweringType::visit (AST::BareFunctionType &fntype) } HIR::Type *param_type - = ASTLoweringType::translate (param.get_type ().get (), + = ASTLoweringType::translate (param.get_type (), default_to_static_lifetime); HIR::MaybeNamedParam p (param.get_name (), kind, @@ -241,9 +240,8 @@ ASTLoweringType::visit (AST::BareFunctionType &fntype) HIR::Type *return_type = nullptr; if (fntype.has_return_type ()) { - return_type - = ASTLoweringType::translate (fntype.get_return_type ().get (), - default_to_static_lifetime); + return_type = ASTLoweringType::translate (fntype.get_return_type (), + default_to_static_lifetime); } auto crate_num = mappings->get_current_crate (); @@ -264,7 +262,7 @@ ASTLoweringType::visit (AST::TupleType &tuple) for (auto &e : tuple.get_elems ()) { HIR::Type *t - = ASTLoweringType::translate (e.get (), default_to_static_lifetime); + = ASTLoweringType::translate (*e, default_to_static_lifetime); elems.push_back (std::unique_ptr (t)); } @@ -293,10 +291,9 @@ void ASTLoweringType::visit (AST::ArrayType &type) { HIR::Type *translated_type - = ASTLoweringType::translate (type.get_elem_type ().get (), + = ASTLoweringType::translate (type.get_elem_type (), default_to_static_lifetime); - HIR::Expr *array_size - = ASTLoweringExpr::translate (type.get_size_expr ().get ()); + HIR::Expr *array_size = ASTLoweringExpr::translate (type.get_size_expr ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, type.get_node_id (), @@ -316,7 +313,7 @@ ASTLoweringType::visit (AST::ReferenceType &type) = lower_lifetime (type.get_lifetime (), default_to_static_lifetime); HIR::Type *base_type - = ASTLoweringType::translate (type.get_base_type ().get (), + = ASTLoweringType::translate (type.get_base_type (), default_to_static_lifetime); auto crate_num = mappings->get_current_crate (); @@ -335,7 +332,7 @@ void ASTLoweringType::visit (AST::RawPointerType &type) { HIR::Type *base_type - = ASTLoweringType::translate (type.get_type_pointed_to ().get (), + = ASTLoweringType::translate (type.get_type_pointed_to (), default_to_static_lifetime); auto crate_num = mappings->get_current_crate (); @@ -357,7 +354,7 @@ void ASTLoweringType::visit (AST::SliceType &type) { HIR::Type *base_type - = ASTLoweringType::translate (type.get_elem_type ().get (), + = ASTLoweringType::translate (type.get_elem_type (), default_to_static_lifetime); auto crate_num = mappings->get_current_crate (); @@ -397,7 +394,7 @@ ASTLoweringType::visit (AST::TraitObjectTypeOneBound &type) { std::vector> bounds; HIR::TypeParamBound *translated_bound - = ASTLoweringTypeBounds::translate (&type.get_trait_bound ()); + = ASTLoweringTypeBounds::translate (type.get_trait_bound ()); bounds.push_back (std::unique_ptr (translated_bound)); auto crate_num = mappings->get_current_crate (); @@ -417,7 +414,7 @@ ASTLoweringType::visit (AST::TraitObjectType &type) for (auto &bound : type.get_type_param_bounds ()) { HIR::TypeParamBound *translated_bound - = ASTLoweringTypeBounds::translate (bound.get ()); + = ASTLoweringTypeBounds::translate (*bound); bounds.push_back ( std::unique_ptr (translated_bound)); } @@ -432,14 +429,14 @@ ASTLoweringType::visit (AST::TraitObjectType &type) } HIR::GenericParam * -ASTLowerGenericParam::translate (AST::GenericParam *param) +ASTLowerGenericParam::translate (AST::GenericParam ¶m) { ASTLowerGenericParam resolver; - param->accept_vis (resolver); + param.accept_vis (resolver); rust_assert (resolver.translated != nullptr); resolver.mappings->insert_location ( - resolver.translated->get_mappings ().get_hirid (), param->get_locus ()); + resolver.translated->get_mappings ().get_hirid (), param.get_locus ()); resolver.mappings->insert_hir_generic_param (resolver.translated); return resolver.translated; @@ -469,12 +466,12 @@ ASTLowerGenericParam::visit (AST::ConstGenericParam ¶m) mappings->get_next_hir_id (crate_num), mappings->get_next_localdef_id (crate_num)); - auto type = ASTLoweringType::translate (param.get_type ().get ()); + auto type = ASTLoweringType::translate (param.get_type ()); HIR::Expr *default_expr = nullptr; if (param.has_default_value ()) default_expr = ASTLoweringExpr::translate ( - param.get_default_value ().get_expression ().get ()); + param.get_default_value ().get_expression ()); translated = new HIR::ConstGenericParam (param.get_name ().as_string (), std::unique_ptr (type), @@ -491,14 +488,14 @@ ASTLowerGenericParam::visit (AST::TypeParam ¶m) { for (auto &bound : param.get_type_param_bounds ()) { - HIR::TypeParamBound *lowered_bound = lower_bound (bound.get ()); + HIR::TypeParamBound *lowered_bound = lower_bound (*bound); type_param_bounds.push_back ( std::unique_ptr (lowered_bound)); } } HIR::Type *type = param.has_type () - ? ASTLoweringType::translate (param.get_type ().get ()) + ? ASTLoweringType::translate (param.get_type ()) : nullptr; auto crate_num = mappings->get_current_crate (); @@ -513,10 +510,10 @@ ASTLowerGenericParam::visit (AST::TypeParam ¶m) } HIR::TypeParamBound * -ASTLoweringTypeBounds::translate (AST::TypeParamBound *type) +ASTLoweringTypeBounds::translate (AST::TypeParamBound &type) { ASTLoweringTypeBounds resolver; - type->accept_vis (resolver); + type.accept_vis (resolver); rust_assert (resolver.translated != nullptr); resolver.mappings->insert_location ( @@ -532,7 +529,7 @@ ASTLoweringTypeBounds::visit (AST::TraitBound &bound) std::vector for_lifetimes; for (auto &lifetime_param : bound.get_for_lifetimes ()) { - auto generic_param = ASTLowerGenericParam::translate (&lifetime_param); + auto generic_param = ASTLowerGenericParam::translate (lifetime_param); for_lifetimes.push_back ( *static_cast (generic_param)); } @@ -604,18 +601,18 @@ ASTLowerWhereClauseItem::visit (AST::TypeBoundWhereClauseItem &item) for (auto &lifetime_param : item.get_for_lifetimes ()) { - auto generic_param = ASTLowerGenericParam::translate (&lifetime_param); + auto generic_param = ASTLowerGenericParam::translate (lifetime_param); for_lifetimes.push_back ( *static_cast (generic_param)); } std::unique_ptr bound_type = std::unique_ptr ( - ASTLoweringType::translate (item.get_type ().get ())); + ASTLoweringType::translate (item.get_type ())); std::vector> type_param_bounds; for (auto &bound : item.get_type_param_bounds ()) { - HIR::TypeParamBound *b = ASTLoweringTypeBounds::translate (bound.get ()); + HIR::TypeParamBound *b = ASTLoweringTypeBounds::translate (*bound); type_param_bounds.push_back (std::unique_ptr (b)); } diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h index ed90c17bb0f..5207ce27b55 100644 --- a/gcc/rust/hir/rust-ast-lower-type.h +++ b/gcc/rust/hir/rust-ast-lower-type.h @@ -63,7 +63,7 @@ class ASTLoweringType : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::Type *translate (AST::Type *type, + static HIR::Type *translate (AST::Type &type, bool default_to_static_lifetime = false); void visit (AST::BareFunctionType &fntype) override; @@ -97,7 +97,7 @@ class ASTLowerGenericParam : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::GenericParam *translate (AST::GenericParam *param); + static HIR::GenericParam *translate (AST::GenericParam ¶m); void visit (AST::LifetimeParam ¶m) override; void visit (AST::ConstGenericParam ¶m) override; @@ -114,7 +114,7 @@ class ASTLoweringTypeBounds : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::TypeParamBound *translate (AST::TypeParamBound *type); + static HIR::TypeParamBound *translate (AST::TypeParamBound &type); void visit (AST::TraitBound &bound) override; void visit (AST::Lifetime &bound) override; diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index d730f29b13a..1c2db3b8134 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -74,9 +74,9 @@ ASTLowering::go () { std::vector> items; - for (auto it = astCrate.items.begin (); it != astCrate.items.end (); it++) + for (auto &item : astCrate.items) { - auto translated = ASTLoweringItem::translate (it->get ()); + auto translated = ASTLoweringItem::translate (*item); if (translated != nullptr) items.push_back (std::unique_ptr (translated)); } @@ -123,7 +123,7 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr) if (expr.has_tail_expr () && block_did_terminate) { // warning unreachable tail expressions - rust_warning_at (expr.get_tail_expr ()->get_locus (), 0, + rust_warning_at (expr.get_tail_expr ().get_locus (), 0, "unreachable expression"); } @@ -132,7 +132,7 @@ ASTLoweringBlock::visit (AST::BlockExpr &expr) { bool terminated = false; tail_expr = (HIR::ExprWithoutBlock *) - ASTLoweringExpr::translate (expr.get_tail_expr ().get (), &terminated); + ASTLoweringExpr::translate (expr.get_tail_expr (), &terminated); block_did_terminate |= terminated; } @@ -155,12 +155,10 @@ void ASTLoweringIfBlock::visit (AST::IfExpr &expr) { bool ignored_terminated = false; - HIR::Expr *condition - = ASTLoweringExpr::translate (expr.get_condition_expr ().get (), - &ignored_terminated); + HIR::Expr *condition = ASTLoweringExpr::translate (expr.get_condition_expr (), + &ignored_terminated); HIR::BlockExpr *block - = ASTLoweringBlock::translate (expr.get_if_block ().get (), - &ignored_terminated); + = ASTLoweringBlock::translate (expr.get_if_block (), &ignored_terminated); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -176,16 +174,15 @@ void ASTLoweringIfBlock::visit (AST::IfExprConseqElse &expr) { HIR::Expr *condition - = ASTLoweringExpr::translate (expr.get_condition_expr ().get ()); + = ASTLoweringExpr::translate (expr.get_condition_expr ()); bool if_block_terminated = false; bool else_block_termianted = false; HIR::BlockExpr *if_block - = ASTLoweringBlock::translate (expr.get_if_block ().get (), - &if_block_terminated); + = ASTLoweringBlock::translate (expr.get_if_block (), &if_block_terminated); HIR::ExprWithBlock *else_block - = ASTLoweringExprWithBlock::translate (expr.get_else_block ().get (), + = ASTLoweringExprWithBlock::translate (expr.get_else_block (), &else_block_termianted); terminated = if_block_terminated && else_block_termianted; @@ -207,16 +204,14 @@ ASTLoweringIfLetBlock::visit (AST::IfLetExpr &expr) std::vector> patterns; for (auto &pattern : expr.get_patterns ()) { - HIR::Pattern *ptrn = ASTLoweringPattern::translate (pattern.get ()); + HIR::Pattern *ptrn = ASTLoweringPattern::translate (*pattern); patterns.push_back (std::unique_ptr (ptrn)); } - HIR::Expr *value_ptr - = ASTLoweringExpr::translate (expr.get_value_expr ().get ()); + HIR::Expr *value_ptr = ASTLoweringExpr::translate (expr.get_value_expr ()); bool ignored_terminated = false; HIR::BlockExpr *block - = ASTLoweringBlock::translate (expr.get_if_block ().get (), - &ignored_terminated); + = ASTLoweringBlock::translate (expr.get_if_block (), &ignored_terminated); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -235,19 +230,17 @@ ASTLoweringIfLetBlock::visit (AST::IfLetExprConseqElse &expr) std::vector> patterns; for (auto &pattern : expr.get_patterns ()) { - HIR::Pattern *ptrn = ASTLoweringPattern::translate (pattern.get ()); + HIR::Pattern *ptrn = ASTLoweringPattern::translate (*pattern); patterns.push_back (std::unique_ptr (ptrn)); } - HIR::Expr *value_ptr - = ASTLoweringExpr::translate (expr.get_value_expr ().get ()); + HIR::Expr *value_ptr = ASTLoweringExpr::translate (expr.get_value_expr ()); bool ignored_terminated = false; HIR::BlockExpr *block - = ASTLoweringBlock::translate (expr.get_if_block ().get (), - &ignored_terminated); + = ASTLoweringBlock::translate (expr.get_if_block (), &ignored_terminated); HIR::ExprWithBlock *else_block - = ASTLoweringExprWithBlock::translate (expr.get_else_block ().get (), + = ASTLoweringExprWithBlock::translate (expr.get_else_block (), &ignored_terminated); rust_assert (else_block); @@ -268,7 +261,7 @@ ASTLoweringIfLetBlock::visit (AST::IfLetExprConseqElse &expr) void ASTLowerStructExprField::visit (AST::StructExprFieldIdentifierValue &field) { - HIR::Expr *value = ASTLoweringExpr::translate (field.get_value ().get ()); + HIR::Expr *value = ASTLoweringExpr::translate (field.get_value ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, field.get_node_id (), @@ -283,7 +276,7 @@ ASTLowerStructExprField::visit (AST::StructExprFieldIdentifierValue &field) void ASTLowerStructExprField::visit (AST::StructExprFieldIndexValue &field) { - HIR::Expr *value = ASTLoweringExpr::translate (field.get_value ().get ()); + HIR::Expr *value = ASTLoweringExpr::translate (field.get_value ()); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, field.get_node_id (), @@ -315,12 +308,11 @@ void ASTLoweringExprWithBlock::visit (AST::WhileLoopExpr &expr) { HIR::BlockExpr *loop_block - = ASTLoweringBlock::translate (expr.get_loop_block ().get (), &terminated); + = ASTLoweringBlock::translate (expr.get_loop_block (), &terminated); HIR::LoopLabel loop_label = lower_loop_label (expr.get_loop_label ()); HIR::Expr *loop_condition - = ASTLoweringExpr::translate (expr.get_predicate_expr ().get (), - &terminated); + = ASTLoweringExpr::translate (expr.get_predicate_expr (), &terminated); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, expr.get_node_id (), @@ -362,25 +354,25 @@ void ASTLoweringExprWithBlock::visit (AST::MatchExpr &expr) { HIR::Expr *branch_value - = ASTLoweringExpr::translate (expr.get_scrutinee_expr ().get ()); + = ASTLoweringExpr::translate (expr.get_scrutinee_expr ()); std::vector match_arms; for (auto &match_case : expr.get_match_cases ()) { HIR::Expr *kase_expr - = ASTLoweringExpr::translate (match_case.get_expr ().get ()); + = ASTLoweringExpr::translate (match_case.get_expr ()); HIR::Expr *kase_guard_expr = nullptr; if (match_case.get_arm ().has_match_arm_guard ()) { kase_guard_expr = ASTLoweringExpr::translate ( - match_case.get_arm ().get_guard_expr ().get ()); + match_case.get_arm ().get_guard_expr ()); } std::vector> match_arm_patterns; for (auto &pattern : match_case.get_arm ().get_patterns ()) { - HIR::Pattern *ptrn = ASTLoweringPattern::translate (pattern.get ()); + HIR::Pattern *ptrn = ASTLoweringPattern::translate (*pattern); match_arm_patterns.push_back (std::unique_ptr (ptrn)); } @@ -437,8 +429,7 @@ ASTLowerPathInExpression::visit (AST::PathInExpression &expr) HIR::QualifiedPathType ASTLoweringBase::lower_qual_path_type (AST::QualifiedPathType &qualified_type) { - HIR::Type *type - = ASTLoweringType::translate (qualified_type.get_type ().get ()); + HIR::Type *type = ASTLoweringType::translate (qualified_type.get_type ()); HIR::TypePath *trait = qualified_type.has_as_clause () ? ASTLowerTypePath::translate (qualified_type.get_as_type_path ()) @@ -486,12 +477,11 @@ ClosureParam ASTLoweringBase::lower_closure_param (AST::ClosureParam ¶m) { HIR::Pattern *param_pattern - = ASTLoweringPattern::translate (param.get_pattern ().get ()); + = ASTLoweringPattern::translate (param.get_pattern ()); - HIR::Type *param_type - = param.has_type_given () - ? ASTLoweringType::translate (param.get_type ().get ()) - : nullptr; + HIR::Type *param_type = param.has_type_given () + ? ASTLoweringType::translate (param.get_type ()) + : nullptr; return HIR::ClosureParam (std::unique_ptr (param_pattern), param.get_locus (), diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc index 1ef162d37e0..1939a2056e4 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.cc +++ b/gcc/rust/resolve/rust-ast-resolve-base.cc @@ -30,7 +30,7 @@ ResolverBase::resolve_visibility (const AST::Visibility &vis) if (vis.has_path ()) { auto path = vis.get_path (); - ResolvePath::go (&path); + ResolvePath::go (path); // Do we need to lookup something here? // Is it just about resolving the names correctly so we can look them up diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc index 741d900460c..1bb3fc60153 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.cc +++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc @@ -28,17 +28,17 @@ namespace Rust { namespace Resolver { void -ResolveExpr::go (AST::Expr *expr, const CanonicalPath &prefix, +ResolveExpr::go (AST::Expr &expr, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix, bool funny_error) { ResolveExpr resolver (prefix, canonical_prefix, funny_error); - expr->accept_vis (resolver); + expr.accept_vis (resolver); } void ResolveExpr::visit (AST::TupleIndexExpr &expr) { - ResolveExpr::go (expr.get_tuple_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_tuple_expr (), prefix, canonical_prefix); } void @@ -48,41 +48,40 @@ ResolveExpr::visit (AST::TupleExpr &expr) return; for (auto &elem : expr.get_tuple_elems ()) - ResolveExpr::go (elem.get (), prefix, canonical_prefix); + ResolveExpr::go (*elem, prefix, canonical_prefix); } void ResolveExpr::visit (AST::PathInExpression &expr) { - ResolvePath::go (&expr); + ResolvePath::go (expr); } void ResolveExpr::visit (AST::QualifiedPathInExpression &expr) { - ResolvePath::go (&expr); + ResolvePath::go (expr); } void ResolveExpr::visit (AST::ReturnExpr &expr) { if (expr.has_returned_expr ()) - ResolveExpr::go (expr.get_returned_expr ().get (), prefix, - canonical_prefix); + ResolveExpr::go (expr.get_returned_expr (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::CallExpr &expr) { - ResolveExpr::go (expr.get_function_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_function_expr (), prefix, canonical_prefix); for (auto ¶m : expr.get_params ()) - ResolveExpr::go (param.get (), prefix, canonical_prefix); + ResolveExpr::go (*param, prefix, canonical_prefix); } void ResolveExpr::visit (AST::MethodCallExpr &expr) { - ResolveExpr::go (expr.get_receiver_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_receiver_expr (), prefix, canonical_prefix); if (expr.get_method_name ().has_generic_args ()) { @@ -92,14 +91,14 @@ ResolveExpr::visit (AST::MethodCallExpr &expr) auto const &in_params = expr.get_params (); for (auto ¶m : in_params) - ResolveExpr::go (param.get (), prefix, canonical_prefix); + ResolveExpr::go (*param, prefix, canonical_prefix); } void ResolveExpr::visit (AST::AssignmentExpr &expr) { - ResolveExpr::go (expr.get_left_expr ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_right_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_left_expr (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_right_expr (), prefix, canonical_prefix); } /* The "break rust" Easter egg. @@ -178,63 +177,63 @@ ResolveExpr::visit (AST::IdentifierExpr &expr) void ResolveExpr::visit (AST::ArithmeticOrLogicalExpr &expr) { - ResolveExpr::go (expr.get_left_expr ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_right_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_left_expr (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_right_expr (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::CompoundAssignmentExpr &expr) { - ResolveExpr::go (expr.get_left_expr ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_right_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_left_expr (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_right_expr (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::ComparisonExpr &expr) { - ResolveExpr::go (expr.get_left_expr ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_right_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_left_expr (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_right_expr (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::LazyBooleanExpr &expr) { - ResolveExpr::go (expr.get_left_expr ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_right_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_left_expr (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_right_expr (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::NegationExpr &expr) { - ResolveExpr::go (expr.get_negated_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_negated_expr (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::TypeCastExpr &expr) { - ResolveType::go (expr.get_type_to_cast_to ().get ()); - ResolveExpr::go (expr.get_casted_expr ().get (), prefix, canonical_prefix); + ResolveType::go (expr.get_type_to_cast_to ()); + ResolveExpr::go (expr.get_casted_expr (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::IfExpr &expr) { - ResolveExpr::go (expr.get_condition_expr ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_if_block ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_condition_expr (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_if_block (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::IfExprConseqElse &expr) { - ResolveExpr::go (expr.get_condition_expr ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_if_block ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_else_block ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_condition_expr (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_if_block (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_else_block (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::IfLetExpr &expr) { - ResolveExpr::go (expr.get_value_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_value_expr (), prefix, canonical_prefix); NodeId scope_node_id = expr.get_node_id (); resolver->get_name_scope ().push (scope_node_id); @@ -251,10 +250,10 @@ ResolveExpr::visit (AST::IfLetExpr &expr) for (auto &pattern : expr.get_patterns ()) { - PatternDeclaration::go (pattern.get (), Rib::ItemType::Var, bindings); + PatternDeclaration::go (*pattern, Rib::ItemType::Var, bindings); } - ResolveExpr::go (expr.get_if_block ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_if_block (), prefix, canonical_prefix); resolver->get_name_scope ().pop (); resolver->get_type_scope ().pop (); @@ -264,7 +263,7 @@ ResolveExpr::visit (AST::IfLetExpr &expr) void ResolveExpr::visit (AST::IfLetExprConseqElse &expr) { - ResolveExpr::go (expr.get_value_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_value_expr (), prefix, canonical_prefix); NodeId scope_node_id = expr.get_node_id (); resolver->get_name_scope ().push (scope_node_id); @@ -281,11 +280,11 @@ ResolveExpr::visit (AST::IfLetExprConseqElse &expr) for (auto &pattern : expr.get_patterns ()) { - PatternDeclaration::go (pattern.get (), Rib::ItemType::Var, bindings); + PatternDeclaration::go (*pattern, Rib::ItemType::Var, bindings); } - ResolveExpr::go (expr.get_if_block ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_else_block ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_if_block (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_else_block (), prefix, canonical_prefix); resolver->get_name_scope ().pop (); resolver->get_type_scope ().pop (); @@ -328,19 +327,19 @@ ResolveExpr::visit (AST::BlockExpr &expr) for (auto &s : expr.get_statements ()) { if (s->is_item ()) - ResolveStmt::go (s.get (), prefix, canonical_prefix, + ResolveStmt::go (*s, prefix, canonical_prefix, CanonicalPath::create_empty ()); } for (auto &s : expr.get_statements ()) { if (!s->is_item ()) - ResolveStmt::go (s.get (), prefix, canonical_prefix, + ResolveStmt::go (*s, prefix, canonical_prefix, CanonicalPath::create_empty ()); } if (expr.has_tail_expr ()) - ResolveExpr::go (expr.get_tail_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_tail_expr (), prefix, canonical_prefix); resolver->get_name_scope ().pop (); resolver->get_type_scope ().pop (); @@ -350,14 +349,14 @@ ResolveExpr::visit (AST::BlockExpr &expr) void ResolveExpr::visit (AST::UnsafeBlockExpr &expr) { - expr.get_block_expr ()->accept_vis (*this); + expr.get_block_expr ().accept_vis (*this); } void ResolveExpr::visit (AST::ArrayElemsValues &elems) { for (auto &elem : elems.get_values ()) - ResolveExpr::go (elem.get (), prefix, canonical_prefix); + ResolveExpr::go (*elem, prefix, canonical_prefix); } void @@ -369,55 +368,53 @@ ResolveExpr::visit (AST::ArrayExpr &expr) void ResolveExpr::visit (AST::ArrayIndexExpr &expr) { - ResolveExpr::go (expr.get_array_expr ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_index_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_array_expr (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_index_expr (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::ArrayElemsCopied &expr) { - ResolveExpr::go (expr.get_num_copies ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_elem_to_copy ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_num_copies (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_elem_to_copy (), prefix, canonical_prefix); } // this this an empty struct constructor like 'S {}' void ResolveExpr::visit (AST::StructExprStruct &struct_expr) { - ResolveExpr::go (&struct_expr.get_struct_name (), prefix, canonical_prefix); + ResolveExpr::go (struct_expr.get_struct_name (), prefix, canonical_prefix); } // this this a struct constructor with fields void ResolveExpr::visit (AST::StructExprStructFields &struct_expr) { - ResolveExpr::go (&struct_expr.get_struct_name (), prefix, canonical_prefix); + ResolveExpr::go (struct_expr.get_struct_name (), prefix, canonical_prefix); if (struct_expr.has_struct_base ()) { AST::StructBase &base = struct_expr.get_struct_base (); - ResolveExpr::go (base.get_base_struct ().get (), prefix, - canonical_prefix); + ResolveExpr::go (base.get_base_struct (), prefix, canonical_prefix); } auto const &struct_fields = struct_expr.get_fields (); for (auto &struct_field : struct_fields) { - ResolveStructExprField::go (struct_field.get (), prefix, - canonical_prefix); + ResolveStructExprField::go (*struct_field, prefix, canonical_prefix); } } void ResolveExpr::visit (AST::GroupedExpr &expr) { - ResolveExpr::go (expr.get_expr_in_parens ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_expr_in_parens (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::FieldAccessExpr &expr) { - ResolveExpr::go (expr.get_receiver_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_receiver_expr (), prefix, canonical_prefix); } void @@ -444,7 +441,7 @@ ResolveExpr::visit (AST::LoopExpr &expr) rust_error_at (locus, "was defined here"); }); } - ResolveExpr::go (expr.get_loop_block ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_loop_block (), prefix, canonical_prefix); } void @@ -477,7 +474,7 @@ ResolveExpr::visit (AST::BreakExpr &expr) if (expr.has_break_expr ()) { bool funny_error = false; - AST::Expr &break_expr = *expr.get_break_expr ().get (); + auto &break_expr = expr.get_break_expr (); if (break_expr.get_ast_kind () == AST::Kind::IDENTIFIER) { /* This is a break with an expression, and the expression is just a @@ -491,7 +488,7 @@ ResolveExpr::visit (AST::BreakExpr &expr) if (ident == "rust" || ident == "gcc") funny_error = true; } - ResolveExpr::go (&break_expr, prefix, canonical_prefix, funny_error); + ResolveExpr::go (break_expr, prefix, canonical_prefix, funny_error); } } @@ -520,8 +517,8 @@ ResolveExpr::visit (AST::WhileLoopExpr &expr) }); } - ResolveExpr::go (expr.get_predicate_expr ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_loop_block ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_predicate_expr (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_loop_block (), prefix, canonical_prefix); } void @@ -559,9 +556,9 @@ ResolveExpr::visit (AST::ForLoopExpr &expr) resolver->push_new_label_rib (resolver->get_type_scope ().peek ()); // resolve the expression - PatternDeclaration::go (expr.get_pattern ().get (), Rib::ItemType::Var); - ResolveExpr::go (expr.get_iterator_expr ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_loop_block ().get (), prefix, canonical_prefix); + PatternDeclaration::go (expr.get_pattern (), Rib::ItemType::Var); + ResolveExpr::go (expr.get_iterator_expr (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_loop_block (), prefix, canonical_prefix); // done resolver->get_name_scope ().pop (); @@ -600,20 +597,19 @@ ResolveExpr::visit (AST::ContinueExpr &expr) void ResolveExpr::visit (AST::BorrowExpr &expr) { - ResolveExpr::go (expr.get_borrowed_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_borrowed_expr (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::DereferenceExpr &expr) { - ResolveExpr::go (expr.get_dereferenced_expr ().get (), prefix, - canonical_prefix); + ResolveExpr::go (expr.get_dereferenced_expr (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::MatchExpr &expr) { - ResolveExpr::go (expr.get_scrutinee_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_scrutinee_expr (), prefix, canonical_prefix); for (auto &match_case : expr.get_match_cases ()) { // each arm is in its own scope @@ -628,8 +624,7 @@ ResolveExpr::visit (AST::MatchExpr &expr) // resolve AST::MatchArm &arm = match_case.get_arm (); if (arm.has_match_arm_guard ()) - ResolveExpr::go (arm.get_guard_expr ().get (), prefix, - canonical_prefix); + ResolveExpr::go (arm.get_guard_expr (), prefix, canonical_prefix); // We know expr.get_patterns () has one pattern at most // so there's no reason to handle it like an AltPattern. @@ -639,11 +634,11 @@ ResolveExpr::visit (AST::MatchExpr &expr) // insert any possible new patterns for (auto &pattern : arm.get_patterns ()) { - PatternDeclaration::go (pattern.get (), Rib::ItemType::Var, bindings); + PatternDeclaration::go (*pattern, Rib::ItemType::Var, bindings); } // resolve the body - ResolveExpr::go (match_case.get_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (match_case.get_expr (), prefix, canonical_prefix); // done resolver->get_name_scope ().pop (); @@ -655,20 +650,20 @@ ResolveExpr::visit (AST::MatchExpr &expr) void ResolveExpr::visit (AST::RangeFromToExpr &expr) { - ResolveExpr::go (expr.get_from_expr ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_to_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_from_expr (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_to_expr (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::RangeFromExpr &expr) { - ResolveExpr::go (expr.get_from_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_from_expr (), prefix, canonical_prefix); } void ResolveExpr::visit (AST::RangeToExpr &expr) { - ResolveExpr::go (expr.get_to_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_to_expr (), prefix, canonical_prefix); } void @@ -680,8 +675,8 @@ ResolveExpr::visit (AST::RangeFullExpr &) void ResolveExpr::visit (AST::RangeFromToInclExpr &expr) { - ResolveExpr::go (expr.get_from_expr ().get (), prefix, canonical_prefix); - ResolveExpr::go (expr.get_to_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_from_expr (), prefix, canonical_prefix); + ResolveExpr::go (expr.get_to_expr (), prefix, canonical_prefix); } void @@ -705,8 +700,7 @@ ResolveExpr::visit (AST::ClosureExprInner &expr) resolver->push_closure_context (expr.get_node_id ()); - ResolveExpr::go (expr.get_definition_expr ().get (), prefix, - canonical_prefix); + ResolveExpr::go (expr.get_definition_expr (), prefix, canonical_prefix); resolver->pop_closure_context (); @@ -734,12 +728,11 @@ ResolveExpr::visit (AST::ClosureExprInnerTyped &expr) resolve_closure_param (p, bindings); } - ResolveType::go (expr.get_return_type ().get ()); + ResolveType::go (expr.get_return_type ()); resolver->push_closure_context (expr.get_node_id ()); - ResolveExpr::go (expr.get_definition_block ().get (), prefix, - canonical_prefix); + ResolveExpr::go (expr.get_definition_block (), prefix, canonical_prefix); resolver->pop_closure_context (); @@ -752,11 +745,10 @@ void ResolveExpr::resolve_closure_param (AST::ClosureParam ¶m, std::vector &bindings) { - PatternDeclaration::go (param.get_pattern ().get (), Rib::ItemType::Param, - bindings); + PatternDeclaration::go (param.get_pattern (), Rib::ItemType::Param, bindings); if (param.has_type_given ()) - ResolveType::go (param.get_type ().get ()); + ResolveType::go (param.get_type ()); } ResolveExpr::ResolveExpr (const CanonicalPath &prefix, diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.h b/gcc/rust/resolve/rust-ast-resolve-expr.h index 86ae70ffbd8..4897650396d 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.h +++ b/gcc/rust/resolve/rust-ast-resolve-expr.h @@ -30,7 +30,7 @@ class ResolveExpr : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static void go (AST::Expr *expr, const CanonicalPath &prefix, + static void go (AST::Expr &expr, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix, bool funny_error = false); diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h index fa344effe67..641a6cfa754 100644 --- a/gcc/rust/resolve/rust-ast-resolve-implitem.h +++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h @@ -31,13 +31,13 @@ class ResolveToplevelImplItem : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static void go (AST::AssociatedItem *item, const CanonicalPath &prefix) + static void go (AST::AssociatedItem &item, const CanonicalPath &prefix) { - if (item->is_marked_for_strip ()) + if (item.is_marked_for_strip ()) return; ResolveToplevelImplItem resolver (prefix); - item->accept_vis (resolver); + item.accept_vis (resolver); } void visit (AST::TypeAlias &type) override @@ -183,10 +183,10 @@ class ResolveToplevelExternItem : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static void go (AST::ExternalItem *item, const CanonicalPath &prefix) + static void go (AST::ExternalItem &item, const CanonicalPath &prefix) { ResolveToplevelExternItem resolver (prefix); - item->accept_vis (resolver); + item.accept_vis (resolver); }; void visit (AST::Function &function) override diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index c65f112ea3b..d11a78859ef 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -65,10 +65,10 @@ ResolveTraitItems::visit (AST::Function &function) if (function.has_generics ()) for (auto &generic : function.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); if (function.has_return_type ()) - ResolveType::go (function.get_return_type ().get ()); + ResolveType::go (function.get_return_type ()); // self turns into (self: Self) as a function param std::vector bindings @@ -80,45 +80,45 @@ ResolveTraitItems::visit (AST::Function &function) { if (p->is_variadic ()) { - auto param = static_cast (p.get ()); - PatternDeclaration::go (param->get_pattern ().get (), - Rib::ItemType::Param, bindings); + auto param = static_cast (*p); + PatternDeclaration::go (param.get_pattern (), Rib::ItemType::Param, + bindings); } else if (p->is_self ()) { - auto param = static_cast (p.get ()); + auto ¶m = static_cast (*p); // FIXME: which location should be used for Rust::Identifier `self`? AST::IdentifierPattern self_pattern ( - param->get_node_id (), {"self"}, param->get_locus (), - param->get_has_ref (), param->get_is_mut (), + param.get_node_id (), {"self"}, param.get_locus (), + param.get_has_ref (), param.get_is_mut (), std::unique_ptr (nullptr)); - PatternDeclaration::go (&self_pattern, Rib::ItemType::Param); + PatternDeclaration::go (self_pattern, Rib::ItemType::Param); - if (param->has_type ()) + if (param.has_type ()) { // This shouldn't happen the parser should already error for this - rust_assert (!param->get_has_ref ()); - ResolveType::go (param->get_type ().get ()); + rust_assert (!param.get_has_ref ()); + ResolveType::go (param.get_type ()); } else { // here we implicitly make self have a type path of Self std::vector> segments; segments.push_back (std::unique_ptr ( - new AST::TypePathSegment ("Self", false, param->get_locus ()))); + new AST::TypePathSegment ("Self", false, param.get_locus ()))); AST::TypePath self_type_path (std::move (segments), - param->get_locus ()); - ResolveType::go (&self_type_path); + param.get_locus ()); + ResolveType::go (self_type_path); } } else { - auto param = static_cast (p.get ()); - ResolveType::go (param->get_type ().get ()); - PatternDeclaration::go (param->get_pattern ().get (), - Rib::ItemType::Param, bindings); + auto ¶m = static_cast (*p); + ResolveType::go (param.get_type ()); + PatternDeclaration::go (param.get_pattern (), Rib::ItemType::Param, + bindings); } } @@ -127,7 +127,7 @@ ResolveTraitItems::visit (AST::Function &function) // trait items have an optional body if (function.has_body ()) - ResolveExpr::go (function.get_definition ()->get (), path, cpath); + ResolveExpr::go (*function.get_definition ().value (), path, cpath); resolver->get_name_scope ().pop (); resolver->get_type_scope ().pop (); @@ -143,7 +143,7 @@ ResolveTraitItems::visit (AST::TraitItemType &type) mappings->insert_canonical_path (type.get_node_id (), cpath); for (auto &bound : type.get_type_param_bounds ()) - ResolveTypeBound::go (bound.get ()); + ResolveTypeBound::go (*bound); } void @@ -155,10 +155,10 @@ ResolveTraitItems::visit (AST::TraitItemConst &constant) auto cpath = canonical_prefix.append (decl); mappings->insert_canonical_path (constant.get_node_id (), cpath); - ResolveType::go (constant.get_type ().get ()); + ResolveType::go (constant.get_type ()); if (constant.has_expr ()) - ResolveExpr::go (constant.get_expr ().get (), path, cpath); + ResolveExpr::go (constant.get_expr (), path, cpath); } ResolveItem::ResolveItem (const CanonicalPath &prefix, @@ -167,11 +167,11 @@ ResolveItem::ResolveItem (const CanonicalPath &prefix, {} void -ResolveItem::go (AST::Item *item, const CanonicalPath &prefix, +ResolveItem::go (AST::Item &item, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix) { ResolveItem resolver (prefix, canonical_prefix); - item->accept_vis (resolver); + item.accept_vis (resolver); } void @@ -189,12 +189,12 @@ ResolveItem::visit (AST::TypeAlias &alias) if (alias.has_generics ()) for (auto &generic : alias.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); if (alias.has_where_clause ()) ResolveWhereClause::Resolve (alias.get_where_clause ()); - ResolveType::go (alias.get_type_aliased ().get ()); + ResolveType::go (alias.get_type_aliased ()); resolver->get_type_scope ().pop (); } @@ -221,11 +221,11 @@ ResolveItem::visit (AST::Module &module) // FIXME: Should we reinsert a child here? Any reason we ResolveTopLevel::go // in ResolveTopLevel::visit (AST::Module) as well as here? for (auto &item : module.get_items ()) - ResolveTopLevel::go (item.get (), CanonicalPath::create_empty (), cpath); + ResolveTopLevel::go (*item, CanonicalPath::create_empty (), cpath); resolver->push_new_module_scope (module.get_node_id ()); for (auto &item : module.get_items ()) - ResolveItem::go (item.get (), path, cpath); + ResolveItem::go (*item, path, cpath); resolver->pop_module_scope (); @@ -251,19 +251,19 @@ ResolveItem::visit (AST::TupleStruct &struct_decl) if (struct_decl.has_generics ()) for (auto &generic : struct_decl.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); if (struct_decl.has_where_clause ()) ResolveWhereClause::Resolve (struct_decl.get_where_clause ()); for (AST::TupleField &field : struct_decl.get_fields ()) { - if (field.get_field_type ()->is_marked_for_strip ()) + if (field.get_field_type ().is_marked_for_strip ()) continue; resolve_visibility (field.get_visibility ()); - ResolveType::go (field.get_field_type ().get ()); + ResolveType::go (field.get_field_type ()); } resolver->get_type_scope ().pop (); @@ -285,14 +285,14 @@ ResolveItem::visit (AST::Enum &enum_decl) if (enum_decl.has_generics ()) for (auto &generic : enum_decl.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, cpath); + ResolveGenericParam::go (*generic, prefix, cpath); if (enum_decl.has_where_clause ()) ResolveWhereClause::Resolve (enum_decl.get_where_clause ()); /* The actual fields are inside the variants. */ for (auto &variant : enum_decl.get_variants ()) - ResolveItem::go (variant.get (), path, cpath); + ResolveItem::go (*variant, path, cpath); resolver->get_type_scope ().pop (); } @@ -322,10 +322,10 @@ ResolveItem::visit (AST::EnumItemTuple &item) for (auto &field : item.get_tuple_fields ()) { - if (field.get_field_type ()->is_marked_for_strip ()) + if (field.get_field_type ().is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get ()); + ResolveType::go (field.get_field_type ()); } } @@ -340,10 +340,10 @@ ResolveItem::visit (AST::EnumItemStruct &item) for (auto &field : item.get_struct_fields ()) { - if (field.get_field_type ()->is_marked_for_strip ()) + if (field.get_field_type ().is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get ()); + ResolveType::go (field.get_field_type ()); } } @@ -375,19 +375,19 @@ ResolveItem::visit (AST::StructStruct &struct_decl) if (struct_decl.has_generics ()) for (auto &generic : struct_decl.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); if (struct_decl.has_where_clause ()) ResolveWhereClause::Resolve (struct_decl.get_where_clause ()); for (AST::StructField &field : struct_decl.get_fields ()) { - if (field.get_field_type ()->is_marked_for_strip ()) + if (field.get_field_type ().is_marked_for_strip ()) continue; resolve_visibility (field.get_visibility ()); - ResolveType::go (field.get_field_type ().get ()); + ResolveType::go (field.get_field_type ()); } resolver->get_type_scope ().pop (); @@ -410,17 +410,17 @@ ResolveItem::visit (AST::Union &union_decl) if (union_decl.has_generics ()) for (auto &generic : union_decl.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); if (union_decl.has_where_clause ()) ResolveWhereClause::Resolve (union_decl.get_where_clause ()); for (AST::StructField &field : union_decl.get_variants ()) { - if (field.get_field_type ()->is_marked_for_strip ()) + if (field.get_field_type ().is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get ()); + ResolveType::go (field.get_field_type ()); } resolver->get_type_scope ().pop (); @@ -435,8 +435,8 @@ ResolveItem::visit (AST::StaticItem &var) auto cpath = canonical_prefix.append (decl); mappings->insert_canonical_path (var.get_node_id (), cpath); - ResolveType::go (var.get_type ().get ()); - ResolveExpr::go (var.get_expr ().get (), path, cpath); + ResolveType::go (var.get_type ()); + ResolveExpr::go (var.get_expr (), path, cpath); } void @@ -450,8 +450,8 @@ ResolveItem::visit (AST::ConstantItem &constant) resolve_visibility (constant.get_visibility ()); - ResolveType::go (constant.get_type ().get ()); - ResolveExpr::go (constant.get_expr ().get (), path, cpath); + ResolveType::go (constant.get_type ()); + ResolveExpr::go (constant.get_expr (), path, cpath); } void @@ -477,14 +477,14 @@ ResolveItem::visit (AST::Function &function) if (function.has_generics ()) for (auto &generic : function.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); // resolve any where clause items if (function.has_where_clause ()) ResolveWhereClause::Resolve (function.get_where_clause ()); if (function.has_return_type ()) - ResolveType::go (function.get_return_type ().get ()); + ResolveType::go (function.get_return_type ()); if (function.has_self_param ()) { @@ -497,13 +497,13 @@ ResolveItem::visit (AST::Function &function) self_param.get_node_id (), {"self"}, self_param.get_locus (), self_param.get_has_ref (), self_param.get_is_mut (), std::unique_ptr (nullptr)); - PatternDeclaration::go (&self_pattern, Rib::ItemType::Param); + PatternDeclaration::go (self_pattern, Rib::ItemType::Param); if (self_param.has_type ()) { // This shouldn't happen the parser should already error for this rust_assert (!self_param.get_has_ref ()); - ResolveType::go (self_param.get_type ().get ()); + ResolveType::go (self_param.get_type ()); } else { @@ -514,7 +514,7 @@ ResolveItem::visit (AST::Function &function) AST::TypePath self_type_path (std::move (segments), self_param.get_locus ()); - ResolveType::go (&self_type_path); + ResolveType::go (self_type_path); } } @@ -527,28 +527,28 @@ ResolveItem::visit (AST::Function &function) { if (p->is_variadic ()) { - auto param = static_cast (p.get ()); - if (param->has_pattern ()) - PatternDeclaration::go (param->get_pattern ().get (), - Rib::ItemType::Param, bindings); + auto ¶m = static_cast (*p); + if (param.has_pattern ()) + PatternDeclaration::go (param.get_pattern (), Rib::ItemType::Param, + bindings); } else if (p->is_self ()) { - auto param = static_cast (p.get ()); - if (param->has_type ()) - ResolveType::go (param->get_type ().get ()); + auto ¶m = static_cast (*p); + if (param.has_type ()) + ResolveType::go (param.get_type ()); } else { - auto param = static_cast (p.get ()); - ResolveType::go (param->get_type ().get ()); - PatternDeclaration::go (param->get_pattern ().get (), - Rib::ItemType::Param, bindings); + auto ¶m = static_cast (*p); + ResolveType::go (param.get_type ()); + PatternDeclaration::go (param.get_pattern (), Rib::ItemType::Param, + bindings); } } // resolve the function body - ResolveExpr::go (function.get_definition ()->get (), path, cpath); + ResolveExpr::go (*function.get_definition ().value (), path, cpath); resolver->get_name_scope ().pop (); resolver->get_type_scope ().pop (); @@ -568,7 +568,7 @@ ResolveItem::visit (AST::InherentImpl &impl_block) if (impl_block.has_generics ()) for (auto &generic : impl_block.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); // resolve any where clause items if (impl_block.has_where_clause ()) @@ -577,12 +577,11 @@ ResolveItem::visit (AST::InherentImpl &impl_block) // FIXME this needs to be protected behind nominal type-checks see: // rustc --explain E0118 // issue #2634 - ResolveType::go (impl_block.get_type ().get ()); + ResolveType::go (impl_block.get_type ()); // Setup paths CanonicalPath self_cpath = CanonicalPath::create_empty (); - bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_type ().get (), - self_cpath); + bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_type (), self_cpath); rust_assert (ok); rust_debug ("AST::InherentImpl resolve Self: {%s}", self_cpath.get ().c_str ()); @@ -609,22 +608,22 @@ ResolveItem::visit (AST::InherentImpl &impl_block) // done setup paths auto Self - = CanonicalPath::get_big_self (impl_block.get_type ()->get_node_id ()); + = CanonicalPath::get_big_self (impl_block.get_type ().get_node_id ()); resolver->get_type_scope ().insert (Self, - impl_block.get_type ()->get_node_id (), - impl_block.get_type ()->get_locus ()); + impl_block.get_type ().get_node_id (), + impl_block.get_type ().get_locus ()); for (auto &impl_item : impl_block.get_impl_items ()) { rust_debug ( "AST::InherentImpl resolve_impl_item: impl_prefix={%s} cpath={%s}", impl_prefix.get ().c_str (), cpath.get ().c_str ()); - resolve_impl_item (impl_item.get (), impl_prefix, cpath); + resolve_impl_item (*impl_item, impl_prefix, cpath); } resolver->get_type_scope ().peek ()->clear_name ( - Self, impl_block.get_type ()->get_node_id ()); + Self, impl_block.get_type ().get_node_id ()); resolver->get_type_scope ().pop (); resolver->get_name_scope ().pop (); @@ -646,14 +645,14 @@ ResolveItem::visit (AST::TraitImpl &impl_block) if (impl_block.has_generics ()) for (auto &generic : impl_block.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); // resolve any where clause items if (impl_block.has_where_clause ()) ResolveWhereClause::Resolve (impl_block.get_where_clause ()); // CanonicalPath canonical_trait_type = CanonicalPath::create_empty (); - NodeId trait_resolved_node = ResolveType::go (&impl_block.get_trait_path ()); + NodeId trait_resolved_node = ResolveType::go (impl_block.get_trait_path ()); if (trait_resolved_node == UNKNOWN_NODEID) { resolver->get_name_scope ().pop (); @@ -663,7 +662,7 @@ ResolveItem::visit (AST::TraitImpl &impl_block) } // CanonicalPath canonical_impl_type = CanonicalPath::create_empty (); - NodeId type_resolved_node = ResolveType::go (impl_block.get_type ().get ()); + NodeId type_resolved_node = ResolveType::go (impl_block.get_type ()); if (type_resolved_node == UNKNOWN_NODEID) { resolver->get_name_scope ().pop (); @@ -675,7 +674,7 @@ ResolveItem::visit (AST::TraitImpl &impl_block) bool ok; // setup paths CanonicalPath canonical_trait_type = CanonicalPath::create_empty (); - ok = ResolveTypeToCanonicalPath::go (&impl_block.get_trait_path (), + ok = ResolveTypeToCanonicalPath::go (impl_block.get_trait_path (), canonical_trait_type); rust_assert (ok); @@ -683,7 +682,7 @@ ResolveItem::visit (AST::TraitImpl &impl_block) canonical_trait_type.get ().c_str ()); CanonicalPath canonical_impl_type = CanonicalPath::create_empty (); - ok = ResolveTypeToCanonicalPath::go (impl_block.get_type ().get (), + ok = ResolveTypeToCanonicalPath::go (impl_block.get_type (), canonical_impl_type); rust_assert (ok); @@ -722,22 +721,22 @@ ResolveItem::visit (AST::TraitImpl &impl_block) // DONE setup canonical-path auto Self - = CanonicalPath::get_big_self (impl_block.get_type ()->get_node_id ()); + = CanonicalPath::get_big_self (impl_block.get_type ().get_node_id ()); resolver->get_type_scope ().insert (Self, - impl_block.get_type ()->get_node_id (), - impl_block.get_type ()->get_locus ()); + impl_block.get_type ().get_node_id (), + impl_block.get_type ().get_locus ()); for (auto &impl_item : impl_block.get_impl_items ()) { rust_debug ( "AST::TraitImpl resolve_impl_item: impl_prefix={%s} cpath={%s}", impl_prefix.get ().c_str (), cpath.get ().c_str ()); - resolve_impl_item (impl_item.get (), impl_prefix, cpath); + resolve_impl_item (*impl_item, impl_prefix, cpath); } Rib *r = resolver->get_type_scope ().peek (); - r->clear_name (Self, impl_block.get_type ()->get_node_id ()); + r->clear_name (Self, impl_block.get_type ().get_node_id ()); resolver->get_name_scope ().pop (); resolver->get_type_scope ().pop (); @@ -765,7 +764,7 @@ ResolveItem::visit (AST::Trait &trait) CanonicalPath Self = CanonicalPath::get_big_self (trait.get_node_id ()); for (auto &generic : trait.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); // Self is an implicit TypeParam so lets mark it as such resolver->get_type_scope ().append_reference_for_def ( @@ -775,7 +774,7 @@ ResolveItem::visit (AST::Trait &trait) { for (auto &bound : trait.get_type_param_bounds ()) { - ResolveTypeBound::go (bound.get ()); + ResolveTypeBound::go (*bound); } } @@ -804,12 +803,12 @@ ResolveItem::visit (AST::ExternBlock &extern_block) for (auto &item : extern_block.get_extern_items ()) { - resolve_extern_item (item.get ()); + resolve_extern_item (*item); } } void -ResolveItem::resolve_impl_item (AST::AssociatedItem *item, +ResolveItem::resolve_impl_item (AST::AssociatedItem &item, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix) { @@ -817,7 +816,7 @@ ResolveItem::resolve_impl_item (AST::AssociatedItem *item, } void -ResolveItem::resolve_extern_item (AST::ExternalItem *item) +ResolveItem::resolve_extern_item (AST::ExternalItem &item) { ResolveExternItem::go (item, prefix, canonical_prefix); } @@ -953,7 +952,7 @@ ResolveItem::visit (AST::UseDeclaration &use_item) auto &path = import.get_path (); rust_debug ("resolving use-decl path: [%s]", path.as_string ().c_str ()); - NodeId resolved_node_id = ResolvePath::go (&path); + NodeId resolved_node_id = ResolvePath::go (path); bool ok = resolved_node_id != UNKNOWN_NODEID; if (!ok) continue; @@ -977,14 +976,14 @@ ResolveImplItems::ResolveImplItems (const CanonicalPath &prefix, {} void -ResolveImplItems::go (AST::AssociatedItem *item, const CanonicalPath &prefix, +ResolveImplItems::go (AST::AssociatedItem &item, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix) { - if (item->is_marked_for_strip ()) + if (item.is_marked_for_strip ()) return; ResolveImplItems resolver (prefix, canonical_prefix); - item->accept_vis (resolver); + item.accept_vis (resolver); } void @@ -1000,11 +999,11 @@ ResolveImplItems::visit (AST::TypeAlias &alias) } void -ResolveExternItem::go (AST::ExternalItem *item, const CanonicalPath &prefix, +ResolveExternItem::go (AST::ExternalItem &item, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix) { ResolveExternItem resolver (prefix, canonical_prefix); - item->accept_vis (resolver); + item.accept_vis (resolver); } void @@ -1031,18 +1030,18 @@ ResolveExternItem::visit (AST::Function &function) // resolve the generics if (function.has_generics ()) for (auto &generic : function.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); if (function.has_return_type ()) - ResolveType::go (function.get_return_type ().get ()); + ResolveType::go (function.get_return_type ()); // we make a new scope so the names of parameters are resolved and shadowed // correctly - for (auto &it : function.get_function_params ()) - if (!it->is_variadic ()) + for (auto ¶m : function.get_function_params ()) + if (!param->is_variadic ()) { - auto param = static_cast (it.get ()); - ResolveType::go (param->get_type ().get ()); + auto &p = static_cast (*param); + ResolveType::go (p.get_type ()); } // done @@ -1056,7 +1055,7 @@ ResolveExternItem::visit (AST::ExternalStaticItem &item) { resolve_visibility (item.get_visibility ()); - ResolveType::go (item.get_type ().get ()); + ResolveType::go (item.get_type ()); } } // namespace Resolver diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h index 0133d2ca27f..1fd2647b0e3 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.h +++ b/gcc/rust/resolve/rust-ast-resolve-item.h @@ -52,7 +52,7 @@ class ResolveItem : public ResolverBase public: using Rust::Resolver::ResolverBase::visit; - static void go (AST::Item *item, const CanonicalPath &prefix, + static void go (AST::Item &item, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix); void visit (AST::TypeAlias &alias) override; @@ -76,10 +76,10 @@ public: void visit (AST::UseDeclaration &) override; protected: - void resolve_impl_item (AST::AssociatedItem *item, + void resolve_impl_item (AST::AssociatedItem &item, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix); - void resolve_extern_item (AST::ExternalItem *item); + void resolve_extern_item (AST::ExternalItem &item); ResolveItem (const CanonicalPath &prefix, const CanonicalPath &canonical_prefix); @@ -93,7 +93,7 @@ class ResolveImplItems : public ResolveItem using Rust::Resolver::ResolveItem::visit; public: - static void go (AST::AssociatedItem *item, const CanonicalPath &prefix, + static void go (AST::AssociatedItem &item, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix); void visit (AST::TypeAlias &alias) override; @@ -108,7 +108,7 @@ class ResolveExternItem : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static void go (AST::ExternalItem *item, const CanonicalPath &prefix, + static void go (AST::ExternalItem &item, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix); void visit (AST::Function &function) override; diff --git a/gcc/rust/resolve/rust-ast-resolve-path.cc b/gcc/rust/resolve/rust-ast-resolve-path.cc index 56c352e13ea..ec590302367 100644 --- a/gcc/rust/resolve/rust-ast-resolve-path.cc +++ b/gcc/rust/resolve/rust-ast-resolve-path.cc @@ -26,35 +26,35 @@ namespace Resolver { ResolvePath::ResolvePath () : ResolverBase () {} NodeId -ResolvePath::go (AST::PathInExpression *expr) +ResolvePath::go (AST::PathInExpression &expr) { ResolvePath resolver; return resolver.resolve_path (expr); } NodeId -ResolvePath::go (AST::QualifiedPathInExpression *expr) +ResolvePath::go (AST::QualifiedPathInExpression &expr) { ResolvePath resolver; return resolver.resolve_path (expr); } NodeId -ResolvePath::go (AST::SimplePath *expr) +ResolvePath::go (AST::SimplePath &expr) { ResolvePath resolver; return resolver.resolve_path (expr); } NodeId -ResolvePath::resolve_path (AST::PathInExpression *expr) +ResolvePath::resolve_path (AST::PathInExpression &expr) { NodeId resolved_node_id = UNKNOWN_NODEID; NodeId module_scope_id = resolver->peek_current_module_scope (); NodeId previous_resolved_node_id = module_scope_id; - for (size_t i = 0; i < expr->get_segments ().size (); i++) + for (size_t i = 0; i < expr.get_segments ().size (); i++) { - auto &segment = expr->get_segments ().at (i); + auto &segment = expr.get_segments ().at (i); const AST::PathIdentSegment &ident_seg = segment.get_ident_segment (); bool is_first_segment = i == 0; resolved_node_id = UNKNOWN_NODEID; @@ -219,14 +219,14 @@ ResolvePath::resolve_path (AST::PathInExpression *expr) // name scope first if (resolver->get_name_scope ().decl_was_declared_here (resolved_node_id)) { - resolver->insert_resolved_name (expr->get_node_id (), + resolver->insert_resolved_name (expr.get_node_id (), resolved_node_id); } // check the type scope else if (resolver->get_type_scope ().decl_was_declared_here ( resolved_node_id)) { - resolver->insert_resolved_type (expr->get_node_id (), + resolver->insert_resolved_type (expr.get_node_id (), resolved_node_id); } else @@ -238,14 +238,14 @@ ResolvePath::resolve_path (AST::PathInExpression *expr) } NodeId -ResolvePath::resolve_path (AST::QualifiedPathInExpression *expr) +ResolvePath::resolve_path (AST::QualifiedPathInExpression &expr) { - AST::QualifiedPathType &root_segment = expr->get_qualified_path_type (); - ResolveType::go (root_segment.get_type ().get ()); + auto &root_segment = expr.get_qualified_path_type (); + ResolveType::go (root_segment.get_type ()); if (root_segment.has_as_clause ()) - ResolveType::go (&root_segment.get_as_type_path ()); + ResolveType::go (root_segment.get_as_type_path ()); - for (auto &segment : expr->get_segments ()) + for (auto &segment : expr.get_segments ()) { // we cant actually do anything with the segment itself since this is all // the job of the type system to figure it out but we can resolve any @@ -260,18 +260,18 @@ ResolvePath::resolve_path (AST::QualifiedPathInExpression *expr) } NodeId -ResolvePath::resolve_path (AST::SimplePath *expr) +ResolvePath::resolve_path (AST::SimplePath &expr) { NodeId crate_scope_id = resolver->peek_crate_module_scope (); NodeId module_scope_id = resolver->peek_current_module_scope (); NodeId previous_resolved_node_id = UNKNOWN_NODEID; NodeId resolved_node_id = UNKNOWN_NODEID; - for (size_t i = 0; i < expr->get_segments ().size (); i++) + for (size_t i = 0; i < expr.get_segments ().size (); i++) { - AST::SimplePathSegment &segment = expr->get_segments ().at (i); + AST::SimplePathSegment &segment = expr.get_segments ().at (i); bool is_first_segment = i == 0; - bool is_final_segment = i >= (expr->get_segments ().size () - 1); + bool is_final_segment = i >= (expr.get_segments ().size () - 1); resolved_node_id = UNKNOWN_NODEID; if (segment.is_crate_path_seg ()) @@ -393,14 +393,14 @@ ResolvePath::resolve_path (AST::SimplePath *expr) // name scope first if (resolver->get_name_scope ().decl_was_declared_here (resolved_node_id)) { - resolver->insert_resolved_name (expr->get_node_id (), + resolver->insert_resolved_name (expr.get_node_id (), resolved_node_id); } // check the type scope else if (resolver->get_type_scope ().decl_was_declared_here ( resolved_node_id)) { - resolver->insert_resolved_type (expr->get_node_id (), + resolver->insert_resolved_type (expr.get_node_id (), resolved_node_id); } else diff --git a/gcc/rust/resolve/rust-ast-resolve-path.h b/gcc/rust/resolve/rust-ast-resolve-path.h index 7aae19b5eac..08ce750c111 100644 --- a/gcc/rust/resolve/rust-ast-resolve-path.h +++ b/gcc/rust/resolve/rust-ast-resolve-path.h @@ -29,16 +29,16 @@ class ResolvePath : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static NodeId go (AST::PathInExpression *expr); - static NodeId go (AST::QualifiedPathInExpression *expr); - static NodeId go (AST::SimplePath *expr); + static NodeId go (AST::PathInExpression &expr); + static NodeId go (AST::QualifiedPathInExpression &expr); + static NodeId go (AST::SimplePath &expr); private: ResolvePath (); - NodeId resolve_path (AST::PathInExpression *expr); - NodeId resolve_path (AST::QualifiedPathInExpression *expr); - NodeId resolve_path (AST::SimplePath *expr); + NodeId resolve_path (AST::PathInExpression &expr); + NodeId resolve_path (AST::QualifiedPathInExpression &expr); + NodeId resolve_path (AST::SimplePath &expr); void resolve_simple_path_segments (CanonicalPath prefix, size_t offs, diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.cc b/gcc/rust/resolve/rust-ast-resolve-pattern.cc index 545fcf82d44..bfa6e3c4dfe 100644 --- a/gcc/rust/resolve/rust-ast-resolve-pattern.cc +++ b/gcc/rust/resolve/rust-ast-resolve-pattern.cc @@ -23,7 +23,7 @@ namespace Rust { namespace Resolver { void -PatternDeclaration::go (AST::Pattern *pattern, Rib::ItemType type) +PatternDeclaration::go (AST::Pattern &pattern, Rib::ItemType type) { std::vector bindings = {PatternBinding (PatternBoundCtx::Product, std::set ())}; @@ -31,11 +31,11 @@ PatternDeclaration::go (AST::Pattern *pattern, Rib::ItemType type) } void -PatternDeclaration::go (AST::Pattern *pattern, Rib::ItemType type, +PatternDeclaration::go (AST::Pattern &pattern, Rib::ItemType type, std::vector &bindings) { PatternDeclaration resolver (bindings, type); - pattern->accept_vis (resolver); + pattern.accept_vis (resolver); for (auto &map_entry : resolver.missing_bindings) { @@ -71,28 +71,28 @@ PatternDeclaration::visit (AST::IdentifierPattern &pattern) void PatternDeclaration::visit (AST::GroupedPattern &pattern) { - pattern.get_pattern_in_parens ()->accept_vis (*this); + pattern.get_pattern_in_parens ().accept_vis (*this); } void PatternDeclaration::visit (AST::ReferencePattern &pattern) { - pattern.get_referenced_pattern ()->accept_vis (*this); + pattern.get_referenced_pattern ().accept_vis (*this); } void PatternDeclaration::visit (AST::PathInExpression &pattern) { - ResolvePath::go (&pattern); + ResolvePath::go (pattern); } void PatternDeclaration::visit (AST::TupleStructPattern &pattern) { - ResolvePath::go (&pattern.get_path ()); + ResolvePath::go (pattern.get_path ()); - std::unique_ptr &items = pattern.get_items (); - switch (items->get_item_type ()) + AST::TupleStructItems &items = pattern.get_items (); + switch (items.get_item_type ()) { case AST::TupleStructItems::RANGE: { // TODO @@ -101,12 +101,12 @@ PatternDeclaration::visit (AST::TupleStructPattern &pattern) break; case AST::TupleStructItems::NO_RANGE: { - AST::TupleStructItemsNoRange &items_no_range - = static_cast (*items.get ()); + auto &items_no_range + = static_cast (items); for (auto &inner_pattern : items_no_range.get_patterns ()) { - inner_pattern.get ()->accept_vis (*this); + inner_pattern->accept_vis (*this); } } break; @@ -116,7 +116,7 @@ PatternDeclaration::visit (AST::TupleStructPattern &pattern) void PatternDeclaration::visit (AST::StructPattern &pattern) { - ResolvePath::go (&pattern.get_path ()); + ResolvePath::go (pattern.get_path ()); auto &struct_pattern_elems = pattern.get_struct_pattern_elems (); for (auto &field : struct_pattern_elems.get_struct_pattern_fields ()) @@ -127,7 +127,7 @@ PatternDeclaration::visit (AST::StructPattern &pattern) AST::StructPatternFieldTuplePat &tuple = static_cast (*field); - tuple.get_index_pattern ()->accept_vis (*this); + tuple.get_index_pattern ().accept_vis (*this); } break; @@ -135,13 +135,12 @@ PatternDeclaration::visit (AST::StructPattern &pattern) AST::StructPatternFieldIdentPat &ident = static_cast (*field); - ident.get_ident_pattern ()->accept_vis (*this); + ident.get_ident_pattern ().accept_vis (*this); } break; case AST::StructPatternField::ItemType::IDENT: { - AST::StructPatternFieldIdent &ident - = static_cast (*field.get ()); + auto &ident = static_cast (*field); Mutability mut = ident.is_mut () ? Mutability::Mut : Mutability::Imm; @@ -158,13 +157,12 @@ PatternDeclaration::visit (AST::StructPattern &pattern) void PatternDeclaration::visit (AST::TuplePattern &pattern) { - std::unique_ptr &items = pattern.get_items (); - switch (items->get_pattern_type ()) + auto &items = pattern.get_items (); + switch (items.get_pattern_type ()) { case AST::TuplePatternItems::TuplePatternItemType::MULTIPLE: { - AST::TuplePatternItemsMultiple &ref - = *static_cast ( - pattern.get_items ().get ()); + auto &ref = static_cast ( + pattern.get_items ()); for (auto &p : ref.get_patterns ()) p->accept_vis (*this); @@ -172,9 +170,8 @@ PatternDeclaration::visit (AST::TuplePattern &pattern) break; case AST::TuplePatternItems::TuplePatternItemType::RANGED: { - AST::TuplePatternItemsRanged &ref - = *static_cast ( - pattern.get_items ().get ()); + auto &ref + = static_cast (pattern.get_items ()); for (auto &p : ref.get_lower_patterns ()) p->accept_vis (*this); @@ -342,27 +339,25 @@ PatternDeclaration::check_bindings_consistency ( } static void -resolve_range_pattern_bound (AST::RangePatternBound *bound) +resolve_range_pattern_bound (AST::RangePatternBound &bound) { - switch (bound->get_bound_type ()) + switch (bound.get_bound_type ()) { case AST::RangePatternBound::RangePatternBoundType::LITERAL: // Nothing to resolve for a literal. break; case AST::RangePatternBound::RangePatternBoundType::PATH: { - AST::RangePatternBoundPath &ref - = *static_cast (bound); + auto &ref = static_cast (bound); - ResolvePath::go (&ref.get_path ()); + ResolvePath::go (ref.get_path ()); } break; case AST::RangePatternBound::RangePatternBoundType::QUALPATH: { - AST::RangePatternBoundQualPath &ref - = *static_cast (bound); + auto &ref = static_cast (bound); - ResolvePath::go (&ref.get_qualified_path ()); + ResolvePath::go (ref.get_qualified_path ()); } break; } @@ -371,8 +366,8 @@ resolve_range_pattern_bound (AST::RangePatternBound *bound) void PatternDeclaration::visit (AST::RangePattern &pattern) { - resolve_range_pattern_bound (pattern.get_upper_bound ().get ()); - resolve_range_pattern_bound (pattern.get_lower_bound ().get ()); + resolve_range_pattern_bound (pattern.get_upper_bound ()); + resolve_range_pattern_bound (pattern.get_lower_bound ()); } void diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.h b/gcc/rust/resolve/rust-ast-resolve-pattern.h index 5974b503d6a..83607e5409a 100644 --- a/gcc/rust/resolve/rust-ast-resolve-pattern.h +++ b/gcc/rust/resolve/rust-ast-resolve-pattern.h @@ -95,8 +95,8 @@ class PatternDeclaration : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static void go (AST::Pattern *pattern, Rib::ItemType type); - static void go (AST::Pattern *pattern, Rib::ItemType type, + static void go (AST::Pattern &pattern, Rib::ItemType type); + static void go (AST::Pattern &pattern, Rib::ItemType type, std::vector &bindings); void visit (AST::IdentifierPattern &pattern) override; diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.cc b/gcc/rust/resolve/rust-ast-resolve-stmt.cc index 04dfdfed0ff..7b62d1f7f78 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.cc +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.cc @@ -30,31 +30,30 @@ ResolveStmt::visit (AST::ExternBlock &extern_block) resolve_visibility (extern_block.get_visibility ()); for (auto &item : extern_block.get_extern_items ()) { - ResolveToplevelExternItem::go (item.get (), - CanonicalPath::create_empty ()); - ResolveExternItem::go (item.get (), prefix, canonical_prefix); + ResolveToplevelExternItem::go (*item, CanonicalPath::create_empty ()); + ResolveExternItem::go (*item, prefix, canonical_prefix); } } void ResolveStmt::visit (AST::Trait &trait) { - ResolveTopLevel::go (&trait, prefix, canonical_prefix); - ResolveItem::go (&trait, prefix, canonical_prefix); + ResolveTopLevel::go (trait, prefix, canonical_prefix); + ResolveItem::go (trait, prefix, canonical_prefix); } void ResolveStmt::visit (AST::InherentImpl &impl_block) { - ResolveTopLevel::go (&impl_block, prefix, canonical_prefix); - ResolveItem::go (&impl_block, prefix, canonical_prefix); + ResolveTopLevel::go (impl_block, prefix, canonical_prefix); + ResolveItem::go (impl_block, prefix, canonical_prefix); } void ResolveStmt::visit (AST::TraitImpl &impl_block) { - ResolveTopLevel::go (&impl_block, prefix, canonical_prefix); - ResolveItem::go (&impl_block, prefix, canonical_prefix); + ResolveTopLevel::go (impl_block, prefix, canonical_prefix); + ResolveItem::go (impl_block, prefix, canonical_prefix); } } // namespace Resolver diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h index f9aa93ba7c4..d699bdec557 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -33,20 +33,20 @@ class ResolveStmt : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static void go (AST::Stmt *stmt, const CanonicalPath &prefix, + static void go (AST::Stmt &stmt, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix, const CanonicalPath &enum_prefix) { - if (stmt->is_marked_for_strip ()) + if (stmt.is_marked_for_strip ()) return; ResolveStmt resolver (prefix, canonical_prefix, enum_prefix); - stmt->accept_vis (resolver); + stmt.accept_vis (resolver); } void visit (AST::ExprStmt &stmt) override { - ResolveExpr::go (stmt.get_expr ().get (), prefix, canonical_prefix); + ResolveExpr::go (stmt.get_expr (), prefix, canonical_prefix); } void visit (AST::ConstantItem &constant) override @@ -66,21 +66,20 @@ public: rust_error_at (r, "redefined multiple times"); }); - ResolveType::go (constant.get_type ().get ()); - ResolveExpr::go (constant.get_expr ().get (), prefix, canonical_prefix); + ResolveType::go (constant.get_type ()); + ResolveExpr::go (constant.get_expr (), prefix, canonical_prefix); } void visit (AST::LetStmt &stmt) override { if (stmt.has_init_expr ()) { - ResolveExpr::go (stmt.get_init_expr ().get (), prefix, - canonical_prefix); + ResolveExpr::go (stmt.get_init_expr (), prefix, canonical_prefix); } - PatternDeclaration::go (stmt.get_pattern ().get (), Rib::ItemType::Var); + PatternDeclaration::go (stmt.get_pattern (), Rib::ItemType::Var); if (stmt.has_type ()) - ResolveType::go (stmt.get_type ().get ()); + ResolveType::go (stmt.get_type ()); } void visit (AST::TupleStruct &struct_decl) override @@ -107,11 +106,11 @@ public: if (struct_decl.has_generics ()) { for (auto &generic : struct_decl.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); } for (AST::TupleField &field : struct_decl.get_fields ()) - ResolveType::go (field.get_field_type ().get ()); + ResolveType::go (field.get_field_type ()); resolver->get_type_scope ().pop (); } @@ -140,11 +139,11 @@ public: if (enum_decl.has_generics ()) { for (auto &generic : enum_decl.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); } for (auto &variant : enum_decl.get_variants ()) - ResolveStmt::go (variant.get (), path, canonical_prefix, path); + ResolveStmt::go (*variant, path, canonical_prefix, path); resolver->get_type_scope ().pop (); } @@ -188,10 +187,10 @@ public: for (auto &field : item.get_tuple_fields ()) { - if (field.get_field_type ()->is_marked_for_strip ()) + if (field.get_field_type ().is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get ()); + ResolveType::go (field.get_field_type ()); } } @@ -214,10 +213,10 @@ public: for (auto &field : item.get_struct_fields ()) { - if (field.get_field_type ()->is_marked_for_strip ()) + if (field.get_field_type ().is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get ()); + ResolveType::go (field.get_field_type ()); } } @@ -265,15 +264,15 @@ public: if (struct_decl.has_generics ()) { for (auto &generic : struct_decl.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); } for (AST::StructField &field : struct_decl.get_fields ()) { - if (field.get_field_type ()->is_marked_for_strip ()) + if (field.get_field_type ().is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get ()); + ResolveType::go (field.get_field_type ()); } resolver->get_type_scope ().pop (); @@ -302,14 +301,14 @@ public: if (union_decl.has_generics ()) for (auto &generic : union_decl.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); for (AST::StructField &field : union_decl.get_variants ()) { - if (field.get_field_type ()->is_marked_for_strip ()) + if (field.get_field_type ().is_marked_for_strip ()) continue; - ResolveType::go (field.get_field_type ().get ()); + ResolveType::go (field.get_field_type ()); } resolver->get_type_scope ().pop (); @@ -343,10 +342,10 @@ public: if (function.has_generics ()) for (auto &generic : function.get_generic_params ()) - ResolveGenericParam::go (generic.get (), prefix, canonical_prefix); + ResolveGenericParam::go (*generic, prefix, canonical_prefix); if (function.has_return_type ()) - ResolveType::go (function.get_return_type ().get ()); + ResolveType::go (function.get_return_type ()); std::vector bindings = {PatternBinding (PatternBoundCtx::Product, std::set ())}; @@ -357,28 +356,28 @@ public: { if (p->is_variadic ()) { - auto param = static_cast (p.get ()); - PatternDeclaration::go (param->get_pattern ().get (), - Rib::ItemType::Param, bindings); + auto ¶m = static_cast (*p); + PatternDeclaration::go (param.get_pattern (), Rib::ItemType::Param, + bindings); } else if (p->is_self ()) { - auto param = static_cast (p.get ()); - ResolveType::go (param->get_type ().get ()); + auto ¶m = static_cast (*p); + ResolveType::go (param.get_type ()); } else { - auto param = static_cast (p.get ()); + auto ¶m = static_cast (*p); - ResolveType::go (param->get_type ().get ()); - PatternDeclaration::go (param->get_pattern ().get (), - Rib::ItemType::Param, bindings); + ResolveType::go (param.get_type ()); + PatternDeclaration::go (param.get_pattern (), Rib::ItemType::Param, + bindings); } } // resolve the function body - ResolveExpr::go (function.get_definition ()->get (), path, cpath); + ResolveExpr::go (*function.get_definition ().value (), path, cpath); resolver->get_name_scope ().pop (); resolver->get_type_scope ().pop (); diff --git a/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.cc b/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.cc index b707343d3a2..c63da2368ee 100644 --- a/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.cc +++ b/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.cc @@ -23,12 +23,12 @@ namespace Rust { namespace Resolver { void -ResolveStructExprField::go (AST::StructExprField *field, +ResolveStructExprField::go (AST::StructExprField &field, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix) { ResolveStructExprField resolver (prefix, canonical_prefix); - field->accept_vis (resolver); + field.accept_vis (resolver); } ResolveStructExprField::ResolveStructExprField ( @@ -39,13 +39,13 @@ ResolveStructExprField::ResolveStructExprField ( void ResolveStructExprField::visit (AST::StructExprFieldIdentifierValue &field) { - ResolveExpr::go (field.get_value ().get (), prefix, canonical_prefix); + ResolveExpr::go (field.get_value (), prefix, canonical_prefix); } void ResolveStructExprField::visit (AST::StructExprFieldIndexValue &field) { - ResolveExpr::go (field.get_value ().get (), prefix, canonical_prefix); + ResolveExpr::go (field.get_value (), prefix, canonical_prefix); } void @@ -54,7 +54,7 @@ ResolveStructExprField::visit (AST::StructExprFieldIdentifier &field) AST::IdentifierExpr expr (field.get_field_name (), {}, field.get_locus ()); expr.set_node_id (field.get_node_id ()); - ResolveExpr::go (&expr, prefix, canonical_prefix); + ResolveExpr::go (expr, prefix, canonical_prefix); } } // namespace Resolver diff --git a/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.h b/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.h index 67bb9559372..3291c56671b 100644 --- a/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.h +++ b/gcc/rust/resolve/rust-ast-resolve-struct-expr-field.h @@ -31,7 +31,7 @@ class ResolveStructExprField : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static void go (AST::StructExprField *field, const CanonicalPath &prefix, + static void go (AST::StructExprField &field, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix); void visit (AST::StructExprFieldIdentifierValue &field) override; diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index 73b4d29f19c..75769281ca9 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -31,18 +31,18 @@ class ResolveTopLevel : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static void go (AST::Item *item, const CanonicalPath &prefix, + static void go (AST::Item &item, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix) { - if (item->is_marked_for_strip ()) + if (item.is_marked_for_strip ()) return; ResolveTopLevel resolver (prefix, canonical_prefix); - item->accept_vis (resolver); + item.accept_vis (resolver); NodeId current_module = resolver.resolver->peek_current_module_scope (); resolver.mappings->insert_child_item_to_parent_module_mapping ( - item->get_node_id (), current_module); + item.get_node_id (), current_module); } void visit (AST::Module &module) override @@ -67,7 +67,7 @@ public: resolver->push_new_module_scope (module.get_node_id ()); for (auto &item : module.get_items ()) - ResolveTopLevel::go (item.get (), path, cpath); + ResolveTopLevel::go (*item, path, cpath); resolver->pop_module_scope (); @@ -137,7 +137,7 @@ public: resolver->push_new_module_scope (enum_decl.get_node_id ()); for (auto &variant : enum_decl.get_variants ()) - ResolveTopLevel::go (variant.get (), path, cpath); + ResolveTopLevel::go (*variant, path, cpath); resolver->pop_module_scope (); @@ -343,9 +343,9 @@ public: void visit (AST::InherentImpl &impl_block) override { - std::string raw_impl_type_path = impl_block.get_type ()->as_string (); + std::string raw_impl_type_path = impl_block.get_type ().as_string (); CanonicalPath impl_type_seg - = CanonicalPath::new_seg (impl_block.get_type ()->get_node_id (), + = CanonicalPath::new_seg (impl_block.get_type ().get_node_id (), raw_impl_type_path); CanonicalPath impl_type @@ -354,14 +354,14 @@ public: CanonicalPath impl_prefix = prefix.append (impl_type_seg); for (auto &impl_item : impl_block.get_impl_items ()) - ResolveToplevelImplItem::go (impl_item.get (), impl_prefix); + ResolveToplevelImplItem::go (*impl_item, impl_prefix); } void visit (AST::TraitImpl &impl_block) override { - std::string raw_impl_type_path = impl_block.get_type ()->as_string (); + std::string raw_impl_type_path = impl_block.get_type ().as_string (); CanonicalPath impl_type_seg - = CanonicalPath::new_seg (impl_block.get_type ()->get_node_id (), + = CanonicalPath::new_seg (impl_block.get_type ().get_node_id (), raw_impl_type_path); std::string raw_trait_type_path = impl_block.get_trait_path ().as_string (); @@ -385,7 +385,7 @@ public: }); for (auto &impl_item : impl_block.get_impl_items ()) - ResolveToplevelImplItem::go (impl_item.get (), impl_prefix); + ResolveToplevelImplItem::go (*impl_item, impl_prefix); } void visit (AST::Trait &trait) override @@ -416,7 +416,7 @@ public: { for (auto &item : extern_block.get_extern_items ()) { - ResolveToplevelExternItem::go (item.get (), prefix); + ResolveToplevelExternItem::go (*item, prefix); } } diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index bbb05380d2a..df1e7ee1a45 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -27,15 +27,15 @@ namespace Resolver { void ResolveType::visit (AST::ArrayType &type) { - type.get_elem_type ()->accept_vis (*this); - ResolveExpr::go (type.get_size_expr ().get (), CanonicalPath::create_empty (), + type.get_elem_type ().accept_vis (*this); + ResolveExpr::go (type.get_size_expr (), CanonicalPath::create_empty (), CanonicalPath::create_empty ()); } void ResolveType::visit (AST::TraitObjectTypeOneBound &type) { - ResolveTypeBound::go (&type.get_trait_bound ()); + ResolveTypeBound::go (type.get_trait_bound ()); } void @@ -44,20 +44,20 @@ ResolveType::visit (AST::TraitObjectType &type) for (auto &bound : type.get_type_param_bounds ()) { /* NodeId bound_resolved_id = */ - ResolveTypeBound::go (bound.get ()); + ResolveTypeBound::go (*bound); } } void ResolveType::visit (AST::ReferenceType &type) { - resolved_node = ResolveType::go (type.get_type_referenced ().get ()); + resolved_node = ResolveType::go (type.get_type_referenced ()); } void ResolveType::visit (AST::RawPointerType &type) { - resolved_node = ResolveType::go (type.get_type_pointed_to ().get ()); + resolved_node = ResolveType::go (type.get_type_pointed_to ()); } void @@ -75,7 +75,7 @@ ResolveType::visit (AST::NeverType &) void ResolveType::visit (AST::SliceType &type) { - resolved_node = ResolveType::go (type.get_elem_type ().get ()); + resolved_node = ResolveType::go (type.get_elem_type ()); } // resolve relative type-paths @@ -153,12 +153,12 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id) AST::TypePathFunction &fn = fnseg->get_type_path_function (); for (auto ¶m : fn.get_params ()) { - ResolveType::go (param.get ()); + ResolveType::go (*param); } if (fn.has_return_type ()) { - ResolveType::go (fn.get_return_type ().get ()); + ResolveType::go (fn.get_return_type ()); } break; @@ -318,11 +318,11 @@ ResolveRelativeQualTypePath::resolve_qual_seg (AST::QualifiedPathType &seg) return false; } - auto type = seg.get_type ().get (); + auto &type = seg.get_type (); ResolveType::go (type); if (seg.has_as_clause ()) - ResolveType::go (&seg.get_as_type_path ()); + ResolveType::go (seg.get_as_type_path ()); return true; } @@ -356,10 +356,10 @@ ResolveRelativeQualTypePath::visit (AST::TypePathSegment &seg) // resolve to canonical path bool -ResolveTypeToCanonicalPath::go (AST::Type *type, CanonicalPath &result) +ResolveTypeToCanonicalPath::go (AST::Type &type, CanonicalPath &result) { ResolveTypeToCanonicalPath resolver; - type->accept_vis (resolver); + type.accept_vis (resolver); result = resolver.result; return !resolver.result.is_empty (); } @@ -402,8 +402,9 @@ ResolveTypeToCanonicalPath::visit (AST::TypePath &path) if (generic.get_kind () == AST::GenericArg::Kind::Type) { CanonicalPath arg = CanonicalPath::create_empty (); - bool ok = ResolveTypeToCanonicalPath::go ( - generic.get_type ().get (), arg); + bool ok + = ResolveTypeToCanonicalPath::go (generic.get_type (), + arg); if (ok) args.push_back (std::move (arg)); } @@ -444,8 +445,7 @@ void ResolveTypeToCanonicalPath::visit (AST::ReferenceType &type) { CanonicalPath path = CanonicalPath::create_empty (); - bool ok - = ResolveTypeToCanonicalPath::go (type.get_type_referenced ().get (), path); + bool ok = ResolveTypeToCanonicalPath::go (type.get_type_referenced (), path); if (ok) { std::string ref_type_str = type.is_mut () ? "mut" : ""; @@ -458,8 +458,7 @@ void ResolveTypeToCanonicalPath::visit (AST::RawPointerType &type) { CanonicalPath path = CanonicalPath::create_empty (); - bool ok - = ResolveTypeToCanonicalPath::go (type.get_type_pointed_to ().get (), path); + bool ok = ResolveTypeToCanonicalPath::go (type.get_type_pointed_to (), path); if (ok) { std::string ptr_type_str @@ -474,7 +473,7 @@ void ResolveTypeToCanonicalPath::visit (AST::SliceType &type) { CanonicalPath path = CanonicalPath::create_empty (); - bool ok = ResolveTypeToCanonicalPath::go (type.get_elem_type ().get (), path); + bool ok = ResolveTypeToCanonicalPath::go (type.get_elem_type (), path); if (ok) { std::string slice_path = "[" + path.get () + "]"; @@ -487,7 +486,7 @@ ResolveTypeToCanonicalPath::visit (AST::TraitObjectTypeOneBound &type) { CanonicalPath path = CanonicalPath::create_empty (); bool ok - = ResolveTypeToCanonicalPath::go (&type.get_trait_bound ().get_type_path (), + = ResolveTypeToCanonicalPath::go (type.get_trait_bound ().get_type_path (), path); if (ok) { @@ -550,10 +549,10 @@ ResolveGenericArgs::resolve_disambiguated_generic (AST::GenericArg &arg) switch (arg.get_kind ()) { case AST::GenericArg::Kind::Const: - ResolveExpr::go (arg.get_expression ().get (), prefix, canonical_prefix); + ResolveExpr::go (arg.get_expression (), prefix, canonical_prefix); break; case AST::GenericArg::Kind::Type: - ResolveType::go (arg.get_type ().get ()); + ResolveType::go (arg.get_type ()); break; default: rust_unreachable (); @@ -584,7 +583,7 @@ ResolveGenericArgs::go (AST::GenericArgs &generic_args, for (auto &binding : generic_args.get_binding_args ()) { - ResolveType::go (binding.get_type ().get ()); + ResolveType::go (binding.get_type ()); } } diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h index c69a8287de2..f1031e9b1ed 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.h +++ b/gcc/rust/resolve/rust-ast-resolve-type.h @@ -56,20 +56,20 @@ class ResolveType : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static NodeId go (AST::Type *type) + static NodeId go (AST::Type &type) { ResolveType resolver; - type->accept_vis (resolver); + type.accept_vis (resolver); return resolver.resolved_node; } void visit (AST::BareFunctionType &fntype) override { for (auto ¶m : fntype.get_function_params ()) - ResolveType::go (param.get_type ().get ()); + ResolveType::go (param.get_type ()); if (fntype.has_return_type ()) - ResolveType::go (fntype.get_return_type ().get ()); + ResolveType::go (fntype.get_return_type ()); } void visit (AST::TupleType &tuple) override @@ -81,7 +81,7 @@ public: } for (auto &elem : tuple.get_elems ()) - ResolveType::go (elem.get ()); + ResolveType::go (*elem); } void visit (AST::TypePath &path) override @@ -119,16 +119,16 @@ class ResolveTypeBound : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static NodeId go (AST::TypeParamBound *type) + static NodeId go (AST::TypeParamBound &type) { ResolveTypeBound resolver; - type->accept_vis (resolver); + type.accept_vis (resolver); return resolver.resolved_node; }; void visit (AST::TraitBound &bound) override { - resolved_node = ResolveType::go (&bound.get_type_path ()); + resolved_node = ResolveType::go (bound.get_type_path ()); } private: @@ -140,21 +140,21 @@ class ResolveGenericParam : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static NodeId go (AST::GenericParam *param, const CanonicalPath &prefix, + static NodeId go (AST::GenericParam ¶m, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix) { ResolveGenericParam resolver (prefix, canonical_prefix); - param->accept_vis (resolver); + param.accept_vis (resolver); return resolver.resolved_node; } void visit (AST::ConstGenericParam ¶m) override { - ResolveType::go (param.get_type ().get ()); + ResolveType::go (param.get_type ()); if (param.has_default_value ()) - ResolveExpr::go (param.get_default_value ().get_expression ().get (), - prefix, canonical_prefix); + ResolveExpr::go (param.get_default_value ().get_expression (), prefix, + canonical_prefix); ok = true; } @@ -163,13 +163,13 @@ public: { // if it has a type lets resolve it if (param.has_type ()) - ResolveType::go (param.get_type ().get ()); + ResolveType::go (param.get_type ()); if (param.has_type_param_bounds ()) { for (auto &bound : param.get_type_param_bounds ()) { - ResolveTypeBound::go (bound.get ()); + ResolveTypeBound::go (*bound); } } @@ -213,12 +213,12 @@ public: void visit (AST::TypeBoundWhereClauseItem &item) override { - ResolveType::go (item.get_type ().get ()); + ResolveType::go (item.get_type ()); if (item.has_type_param_bounds ()) { for (auto &bound : item.get_type_param_bounds ()) { - ResolveTypeBound::go (bound.get ()); + ResolveTypeBound::go (*bound); } } } @@ -232,7 +232,7 @@ class ResolveTypeToCanonicalPath : public ResolverBase using Rust::Resolver::ResolverBase::visit; public: - static bool go (AST::Type *type, CanonicalPath &result); + static bool go (AST::Type &type, CanonicalPath &result); void visit (AST::TypePath &path) override; diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc index 401434cb667..4273ae34055 100644 --- a/gcc/rust/resolve/rust-ast-resolve.cc +++ b/gcc/rust/resolve/rust-ast-resolve.cc @@ -92,9 +92,8 @@ NameResolution::go (AST::Crate &crate) // first gather the top-level namespace names then we drill down so this // allows for resolving forward declarations since an impl block might have // a Self type Foo which is defined after the impl block for example. - for (auto it = crate.items.begin (); it != crate.items.end (); it++) - ResolveTopLevel::go (it->get (), CanonicalPath::create_empty (), - crate_prefix); + for (auto &item : crate.items) + ResolveTopLevel::go (*item, CanonicalPath::create_empty (), crate_prefix); // FIXME remove this if (saw_errors ()) @@ -104,8 +103,8 @@ NameResolution::go (AST::Crate &crate) } // next we can drill down into the items and their scopes - for (auto it = crate.items.begin (); it != crate.items.end (); it++) - ResolveItem::go (it->get (), CanonicalPath::create_empty (), crate_prefix); + for (auto &item : crate.items) + ResolveItem::go (*item, CanonicalPath::create_empty (), crate_prefix); // done resolver->pop_module_scope (); diff --git a/gcc/rust/resolve/rust-default-resolver.cc b/gcc/rust/resolve/rust-default-resolver.cc index 789cc4eef42..e2609d13c9a 100644 --- a/gcc/rust/resolve/rust-default-resolver.cc +++ b/gcc/rust/resolve/rust-default-resolver.cc @@ -35,7 +35,7 @@ DefaultResolver::visit (AST::BlockExpr &expr) stmt->accept_vis (*this); if (expr.has_tail_expr ()) - expr.get_tail_expr ()->accept_vis (*this); + expr.get_tail_expr ().accept_vis (*this); }; ctx.scoped (Rib::Kind::Normal, expr.get_node_id (), inner_fn); @@ -61,21 +61,21 @@ DefaultResolver::visit (AST::Function &function) { if (p->is_variadic ()) { - auto param = static_cast (p.get ()); - if (param->has_pattern ()) - param->get_pattern ()->accept_vis (*this); + auto ¶m = static_cast (*p); + if (param.has_pattern ()) + param.get_pattern ().accept_vis (*this); } else if (p->is_self ()) { - auto param = static_cast (p.get ()); - param->get_type ()->accept_vis (*this); - param->get_lifetime ().accept_vis (*this); + auto ¶m = static_cast (*p); + param.get_type ().accept_vis (*this); + param.get_lifetime ().accept_vis (*this); } else { - auto param = static_cast (p.get ()); - param->get_pattern ()->accept_vis (*this); - param->get_type ()->accept_vis (*this); + auto ¶m = static_cast (*p); + param.get_pattern ().accept_vis (*this); + param.get_type ().accept_vis (*this); } } @@ -90,9 +90,9 @@ void DefaultResolver::visit (AST::ForLoopExpr &expr) { ctx.scoped (Rib::Kind::Normal, expr.get_node_id (), [this, &expr] () { - expr.get_pattern ()->accept_vis (*this); - expr.get_iterator_expr ()->accept_vis (*this); - expr.get_loop_block ()->accept_vis (*this); + expr.get_pattern ().accept_vis (*this); + expr.get_iterator_expr ().accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); }); } @@ -188,12 +188,12 @@ DefaultResolver::visit (AST::ClosureExprInner &expr) if (param.is_error ()) continue; - param.get_pattern ()->accept_vis (*this); + param.get_pattern ().accept_vis (*this); if (param.has_type_given ()) - param.get_type ()->accept_vis (*this); + param.get_type ().accept_vis (*this); } - expr.get_definition_expr ()->accept_vis (*this); + expr.get_definition_expr ().accept_vis (*this); } void @@ -207,13 +207,13 @@ DefaultResolver::visit (AST::ClosureExprInnerTyped &expr) if (param.is_error ()) continue; - param.get_pattern ()->accept_vis (*this); + param.get_pattern ().accept_vis (*this); if (param.has_type_given ()) - param.get_type ()->accept_vis (*this); + param.get_type ().accept_vis (*this); } - expr.get_definition_block ()->accept_vis (*this); - expr.get_return_type ()->accept_vis (*this); + expr.get_definition_block ().accept_vis (*this); + expr.get_return_type ().accept_vis (*this); } void @@ -263,16 +263,16 @@ DefaultResolver::visit (AST::WhileLetLoopExpr &expr) void DefaultResolver::visit (AST::IfExpr &expr) { - expr.get_condition_expr ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); + expr.get_condition_expr ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); } void DefaultResolver::visit (AST::IfExprConseqElse &expr) { - expr.get_condition_expr ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); - expr.get_else_block ()->accept_vis (*this); + expr.get_condition_expr ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); + expr.get_else_block ().accept_vis (*this); } void @@ -289,14 +289,14 @@ DefaultResolver::visit (AST::MatchExpr &expr) if (expr.is_marked_for_strip ()) return; - expr.get_scrutinee_expr ()->accept_vis (*this); + expr.get_scrutinee_expr ().accept_vis (*this); for (auto &arm : expr.get_match_cases ()) { - arm.get_expr ()->accept_vis (*this); + arm.get_expr ().accept_vis (*this); for (auto &pat : arm.get_arm ().get_patterns ()) pat->accept_vis (*this); if (arm.get_arm ().has_match_arm_guard ()) - arm.get_arm ().get_guard_expr ()->accept_vis (*this); + arm.get_arm ().get_guard_expr ().accept_vis (*this); } } @@ -339,7 +339,7 @@ DefaultResolver::visit (AST::PathInExpression &expr) arg.accept_vis (*this); for (auto &arg : args.get_binding_args ()) if (!arg.is_error ()) - arg.get_type ()->accept_vis (*this); + arg.get_type ().accept_vis (*this); for (auto &arg : args.get_lifetime_args ()) arg.accept_vis (*this); } @@ -441,27 +441,27 @@ void DefaultResolver::visit (AST::EnumItemTuple &item) { for (auto &field : item.get_tuple_fields ()) - field.get_field_type ()->accept_vis (*this); + field.get_field_type ().accept_vis (*this); } void DefaultResolver::visit (AST::EnumItemStruct &item) { for (auto &field : item.get_struct_fields ()) - field.get_field_type ()->accept_vis (*this); + field.get_field_type ().accept_vis (*this); } void DefaultResolver::visit (AST::EnumItemDiscriminant &item) { if (item.has_expr ()) - item.get_expr ()->accept_vis (*this); + item.get_expr ().accept_vis (*this); } void DefaultResolver::visit (AST::ConstantItem &item) { - auto expr_vis = [this, &item] () { item.get_expr ()->accept_vis (*this); }; + auto expr_vis = [this, &item] () { item.get_expr ().accept_vis (*this); }; // FIXME: Why do we need a Rib here? ctx.scoped (Rib::Kind::Item, item.get_node_id (), expr_vis); @@ -470,7 +470,7 @@ DefaultResolver::visit (AST::ConstantItem &item) void DefaultResolver::visit (AST::StaticItem &item) { - auto expr_vis = [this, &item] () { item.get_expr ()->accept_vis (*this); }; + auto expr_vis = [this, &item] () { item.get_expr ().accept_vis (*this); }; // FIXME: Why do we need a Rib here? ctx.scoped (Rib::Kind::ConstantItem, item.get_node_id (), expr_vis); diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc index 5447084cfdd..af44439cdab 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.cc +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -90,13 +90,13 @@ EarlyNameResolver::resolve_generic_args (AST::GenericArgs &generic_args) arg.accept_vis (*this); for (auto &arg : generic_args.get_binding_args ()) - arg.get_type ()->accept_vis (*this); + arg.get_type ().accept_vis (*this); } void EarlyNameResolver::resolve_qualified_path_type (AST::QualifiedPathType &path) { - path.get_type ()->accept_vis (*this); + path.get_type ().accept_vis (*this); if (path.has_as_clause ()) path.get_as_type_path ().accept_vis (*this); @@ -227,7 +227,7 @@ EarlyNameResolver::visit (AST::BlockExpr &expr) stmt->accept_vis (*this); if (expr.has_tail_expr ()) - expr.get_tail_expr ()->accept_vis (*this); + expr.get_tail_expr ().accept_vis (*this); }); } @@ -243,37 +243,37 @@ void EarlyNameResolver::visit (AST::ForLoopExpr &expr) { scoped (expr.get_node_id (), [&expr, this] () { - expr.get_pattern ()->accept_vis (*this); - expr.get_iterator_expr ()->accept_vis (*this); - expr.get_loop_block ()->accept_vis (*this); + expr.get_pattern ().accept_vis (*this); + expr.get_iterator_expr ().accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); }); } void EarlyNameResolver::visit (AST::IfLetExpr &expr) { - expr.get_value_expr ()->accept_vis (*this); + expr.get_value_expr ().accept_vis (*this); scoped (expr.get_node_id (), - [&expr, this] () { expr.get_if_block ()->accept_vis (*this); }); + [&expr, this] () { expr.get_if_block ().accept_vis (*this); }); } void EarlyNameResolver::visit (AST::MatchExpr &expr) { - expr.get_scrutinee_expr ()->accept_vis (*this); + expr.get_scrutinee_expr ().accept_vis (*this); scoped (expr.get_node_id (), [&expr, this] () { for (auto &arm : expr.get_match_cases ()) { scoped (arm.get_node_id (), [&arm, this] () { if (arm.get_arm ().has_match_arm_guard ()) - arm.get_arm ().get_guard_expr ()->accept_vis (*this); + arm.get_arm ().get_guard_expr ().accept_vis (*this); for (auto &pattern : arm.get_arm ().get_patterns ()) pattern->accept_vis (*this); - arm.get_expr ()->accept_vis (*this); + arm.get_expr ().accept_vis (*this); }); } }); @@ -365,7 +365,7 @@ EarlyNameResolver::visit (AST::Trait &trait) void EarlyNameResolver::visit (AST::InherentImpl &impl) { - impl.get_type ()->accept_vis (*this); + impl.get_type ().accept_vis (*this); for (auto &generic : impl.get_generic_params ()) generic->accept_vis (*this); @@ -379,7 +379,7 @@ EarlyNameResolver::visit (AST::InherentImpl &impl) void EarlyNameResolver::visit (AST::TraitImpl &impl) { - impl.get_type ()->accept_vis (*this); + impl.get_type ().accept_vis (*this); for (auto &generic : impl.get_generic_params ()) generic->accept_vis (*this); @@ -558,7 +558,7 @@ EarlyNameResolver::visit (AST::StructPattern &) void EarlyNameResolver::visit (AST::TupleStructPattern &pattern) { - pattern.get_items ()->accept_vis (*this); + pattern.get_items ().accept_vis (*this); } void diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index 6470a63c9ad..446a1c6a41b 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -213,7 +213,7 @@ TopLevel::visit (AST::BlockExpr &expr) stmt->accept_vis (*this); if (expr.has_tail_expr ()) - expr.get_tail_expr ()->accept_vis (*this); + expr.get_tail_expr ().accept_vis (*this); }; ctx.scoped (Rib::Kind::Normal, expr.get_node_id (), sub_vis); @@ -223,7 +223,7 @@ void TopLevel::visit (AST::StaticItem &static_item) { auto sub_vis - = [this, &static_item] () { static_item.get_expr ()->accept_vis (*this); }; + = [this, &static_item] () { static_item.get_expr ().accept_vis (*this); }; ctx.scoped (Rib::Kind::Item, static_item.get_node_id (), sub_vis); } @@ -299,7 +299,7 @@ void TopLevel::visit (AST::ConstantItem &const_item) { auto expr_vis - = [this, &const_item] () { const_item.get_expr ()->accept_vis (*this); }; + = [this, &const_item] () { const_item.get_expr ().accept_vis (*this); }; ctx.scoped (Rib::Kind::ConstantItem, const_item.get_node_id (), expr_vis); } -- 2.45.2