diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-02-06 17:46:07 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-04-06 10:47:23 +0200 |
commit | c627781b8f6c2539ea17a9240458e6a53b00f262 (patch) | |
tree | ef3e19f38b80ec8cc05f4eddc19de72802e5c105 /gcc/rust | |
parent | fd406fc7046f427385b644759265ae06ed741d6b (diff) | |
download | gcc-c627781b8f6c2539ea17a9240458e6a53b00f262.zip gcc-c627781b8f6c2539ea17a9240458e6a53b00f262.tar.gz gcc-c627781b8f6c2539ea17a9240458e6a53b00f262.tar.bz2 |
gccrs: Extract query_type from TypeCheckBase to be a simple extern
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* Make-lang.in: add new dependancy
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::query_type): refactor
* typecheck/rust-hir-type-check-base.h: refactor
* typecheck/rust-hir-type-check.h (RUST_HIR_TYPE_CHECK): refactor
* typecheck/rust-type-util.cc: New file.
* typecheck/rust-type-util.h: New file.
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/Make-lang.in | 1 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-base.cc | 73 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-base.h | 2 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check.h | 1 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-type-util.cc | 108 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-type-util.h | 38 |
6 files changed, 148 insertions, 75 deletions
diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 09bbe45..06f64a0 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -134,6 +134,7 @@ GRS_OBJS = \ rust/rust-hir-type-check-implitem.o \ rust/rust-hir-dot-operator.o \ rust/rust-hir-path-probe.o \ + rust/rust-type-util.o \ rust/rust-coercion.o \ rust/rust-casts.o \ rust/rust-unify.o \ diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index 6e42b7b..e302e27 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc @@ -483,78 +483,5 @@ TypeCheckBase::resolve_generic_params ( } } -bool -TypeCheckBase::query_type (HirId reference, TyTy::BaseType **result) -{ - if (context->query_in_progress (reference)) - return false; - - if (context->lookup_type (reference, result)) - return true; - - context->insert_query (reference); - - HIR::Item *item = mappings->lookup_hir_item (reference); - if (item != nullptr) - { - rust_debug_loc (item->get_locus (), "resolved item {%u} to", reference); - *result = TypeCheckItem::Resolve (*item); - context->query_completed (reference); - return true; - } - - HirId parent_impl_id = UNKNOWN_HIRID; - HIR::ImplItem *impl_item - = mappings->lookup_hir_implitem (reference, &parent_impl_id); - if (impl_item != nullptr) - { - HIR::ImplBlock *impl_block - = mappings->lookup_hir_impl_block (parent_impl_id); - rust_assert (impl_block != nullptr); - - // found an impl item - rust_debug_loc (impl_item->get_locus (), "resolved impl-item {%u} to", - reference); - - *result = TypeCheckItem::ResolveImplItem (*impl_block, *impl_item); - context->query_completed (reference); - return true; - } - - // is it an impl_type? - HIR::ImplBlock *impl_block_by_type = nullptr; - bool found_impl_block_type - = mappings->lookup_impl_block_type (reference, &impl_block_by_type); - if (found_impl_block_type) - { - *result = TypeCheckItem::ResolveImplBlockSelf (*impl_block_by_type); - context->query_completed (reference); - return true; - } - - // is it an extern item? - HirId parent_extern_block_id = UNKNOWN_HIRID; - HIR::ExternalItem *extern_item - = mappings->lookup_hir_extern_item (reference, &parent_extern_block_id); - if (extern_item != nullptr) - { - HIR::ExternBlock *block - = mappings->lookup_hir_extern_block (parent_extern_block_id); - rust_assert (block != nullptr); - - *result = TypeCheckTopLevelExternItem::Resolve (extern_item, *block); - context->query_completed (reference); - return true; - } - - // more? - Location possible_locus = mappings->lookup_location (reference); - rust_debug_loc (possible_locus, "query system failed to resolve: [%u]", - reference); - context->query_completed (reference); - - return false; -} - } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.h b/gcc/rust/typecheck/rust-hir-type-check-base.h index 3350143..b8ff2cf 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.h +++ b/gcc/rust/typecheck/rust-hir-type-check-base.h @@ -69,8 +69,6 @@ protected: const std::vector<std::unique_ptr<HIR::GenericParam>> &generic_params, std::vector<TyTy::SubstitutionParamMapping> &substitutions); - bool query_type (HirId reference, TyTy::BaseType **result); - Analysis::Mappings *mappings; Resolver *resolver; TypeCheckContext *context; diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index 5124539..6d4b9b8 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -19,6 +19,7 @@ #ifndef RUST_HIR_TYPE_CHECK #define RUST_HIR_TYPE_CHECK +#include "rust-type-util.h" #include "rust-hir-full-decls.h" #include "rust-hir-map.h" #include "rust-tyty.h" diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc new file mode 100644 index 0000000..4e38826 --- /dev/null +++ b/gcc/rust/typecheck/rust-type-util.cc @@ -0,0 +1,108 @@ +// Copyright (C) 2020-2022 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include "rust-type-util.h" +#include "rust-diagnostics.h" +#include "rust-hir-type-check.h" +#include "rust-name-resolver.h" +#include "rust-hir-visitor.h" +#include "rust-hir-map.h" +#include "rust-hir-type-check-item.h" +#include "rust-hir-type-check-implitem.h" + +namespace Rust { +namespace Resolver { + +bool +query_type (HirId reference, TyTy::BaseType **result) +{ + Analysis::Mappings *mappings = Analysis::Mappings::get (); + TypeCheckContext *context = TypeCheckContext::get (); + + if (context->query_in_progress (reference)) + return false; + + if (context->lookup_type (reference, result)) + return true; + + context->insert_query (reference); + + HIR::Item *item = mappings->lookup_hir_item (reference); + if (item != nullptr) + { + rust_debug_loc (item->get_locus (), "resolved item {%u} to", reference); + *result = TypeCheckItem::Resolve (*item); + context->query_completed (reference); + return true; + } + + HirId parent_impl_id = UNKNOWN_HIRID; + HIR::ImplItem *impl_item + = mappings->lookup_hir_implitem (reference, &parent_impl_id); + if (impl_item != nullptr) + { + HIR::ImplBlock *impl_block + = mappings->lookup_hir_impl_block (parent_impl_id); + rust_assert (impl_block != nullptr); + + // found an impl item + rust_debug_loc (impl_item->get_locus (), "resolved impl-item {%u} to", + reference); + + *result = TypeCheckItem::ResolveImplItem (*impl_block, *impl_item); + context->query_completed (reference); + return true; + } + + // is it an impl_type? + HIR::ImplBlock *impl_block_by_type = nullptr; + bool found_impl_block_type + = mappings->lookup_impl_block_type (reference, &impl_block_by_type); + if (found_impl_block_type) + { + *result = TypeCheckItem::ResolveImplBlockSelf (*impl_block_by_type); + context->query_completed (reference); + return true; + } + + // is it an extern item? + HirId parent_extern_block_id = UNKNOWN_HIRID; + HIR::ExternalItem *extern_item + = mappings->lookup_hir_extern_item (reference, &parent_extern_block_id); + if (extern_item != nullptr) + { + HIR::ExternBlock *block + = mappings->lookup_hir_extern_block (parent_extern_block_id); + rust_assert (block != nullptr); + + *result = TypeCheckTopLevelExternItem::Resolve (extern_item, *block); + context->query_completed (reference); + return true; + } + + // more? + Location possible_locus = mappings->lookup_location (reference); + rust_debug_loc (possible_locus, "query system failed to resolve: [%u]", + reference); + context->query_completed (reference); + + return false; +} + +} // namespace Resolver +} // namespace Rust diff --git a/gcc/rust/typecheck/rust-type-util.h b/gcc/rust/typecheck/rust-type-util.h new file mode 100644 index 0000000..a3f9efc --- /dev/null +++ b/gcc/rust/typecheck/rust-type-util.h @@ -0,0 +1,38 @@ +// Copyright (C) 2020-2022 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#ifndef RUST_TYPE_UTIL +#define RUST_TYPE_UTIL + +#include "rust-mapping-common.h" + +namespace Rust { + +namespace TyTy { +class BaseType; +} + +namespace Resolver { + +extern bool +query_type (HirId reference, TyTy::BaseType **result); + +} // namespace Resolver +} // namespace Rust + +#endif // RUST_TYPE_UTIL |