From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 4036D3857713; Tue, 2 May 2023 07:10:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4036D3857713 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683011418; bh=TzXcu3LP2hw5iUiUkjGqZfT8cMmOmRIHLLut/y/OXvY=; h=From:To:Subject:Date:From; b=BuaHpkaRAS6IW2cds0iaSUc2NHYHTwSGuToff39bWOboQPL0PtsBRb5Rp7sEmqB6O 6IsmwGJcUv15LmCRoSKHII5LDKDSo7lFtut/kSBgCspB4X183WYfkVxa8KUPs/++ER YXNCHdKvxcs7w3w5aKgNanz9QCGvsyq+lWMkhLMI= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] gccrs: add helper to check for a const or static context X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: aa67a856e7ed69d595f7cd8dc7a747ec69db6712 X-Git-Newrev: c630493edcd2ccbef51a5893796f5deecd9d8a0b Message-Id: <20230502071018.4036D3857713@sourceware.org> Date: Tue, 2 May 2023 07:10:18 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c630493edcd2ccbef51a5893796f5deecd9d8a0b commit c630493edcd2ccbef51a5893796f5deecd9d8a0b Author: Philip Herron Date: Mon Apr 17 22:04:11 2023 +0100 gccrs: add helper to check for a const or static context gcc/rust/ChangeLog: * typecheck/rust-hir-type-check.h: new helper * typecheck/rust-typecheck-context.cc (TypeCheckContext::have_function_context): implementation Signed-off-by: Philip Herron Diff: --- gcc/rust/typecheck/rust-hir-type-check.h | 1 + gcc/rust/typecheck/rust-typecheck-context.cc | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index 538dcaefc12..74ab6c3cacf 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -91,6 +91,7 @@ public: void insert_type_by_node_id (NodeId ref, HirId id); bool lookup_type_by_node_id (NodeId ref, HirId *id); + bool have_function_context () const; TyTy::BaseType *peek_return_type (); TypeCheckContextItem peek_context (); void push_return_type (TypeCheckContextItem item, diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc b/gcc/rust/typecheck/rust-typecheck-context.cc index c041b153b4e..ffa49dc195b 100644 --- a/gcc/rust/typecheck/rust-typecheck-context.cc +++ b/gcc/rust/typecheck/rust-typecheck-context.cc @@ -136,6 +136,12 @@ TypeCheckContext::lookup_type_by_node_id (NodeId ref, HirId *id) return true; } +bool +TypeCheckContext::have_function_context () const +{ + return !return_type_stack.empty (); +} + TyTy::BaseType * TypeCheckContext::peek_return_type () {