diff options
author | Kushal Pal <kushalpal109@gmail.com> | 2024-07-25 11:57:35 +0000 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2024-08-16 12:31:02 +0000 |
commit | ddda47c4fe5a9f5ed7e16820f6f45079af5bfa3b (patch) | |
tree | 344ed6b79f0d04332e4ae68e26efb2b633e63ce5 /gcc | |
parent | 44664e3875976d8770c830eb468ac6524a2a8aa8 (diff) | |
download | gcc-ddda47c4fe5a9f5ed7e16820f6f45079af5bfa3b.zip gcc-ddda47c4fe5a9f5ed7e16820f6f45079af5bfa3b.tar.gz gcc-ddda47c4fe5a9f5ed7e16820f6f45079af5bfa3b.tar.bz2 |
Map locations to placeholder regions
Mapped placeholder regions to their respective HIR nodes so we can fetch
locations during error reporting.
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-builder.h: Map regions to
their respective HIR nodes.
* checks/errors/borrowck/rust-bir.h (struct Function):
Add unordered_map to maintain the mapping.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/checks/errors/borrowck/rust-bir-builder.h | 23 | ||||
-rw-r--r-- | gcc/rust/checks/errors/borrowck/rust-bir.h | 1 |
2 files changed, 24 insertions, 0 deletions
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h index 183e330..3a92872 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h @@ -50,6 +50,8 @@ public: handle_param (param); handle_body (*function.get_definition ()); + auto region_hir_map + = map_region_to_hir (function.get_generic_params (), ctx.fn_free_regions); return Function{ std::move (ctx.place_db), @@ -57,6 +59,7 @@ public: std::move (ctx.basic_blocks), std::move (ctx.fn_free_regions), std::move (universal_region_bounds), + std::move (region_hir_map), function.get_locus (), }; } @@ -161,6 +164,26 @@ private: push_return (return_location); } } + + // Maps named lifetime parameters to their respective HIR node + const std::unordered_map<Polonius::Origin, HIR::LifetimeParam *> + map_region_to_hir ( + const std::vector<std::unique_ptr<HIR::GenericParam>> &generic_params, + const FreeRegions ®ions) + { + std::unordered_map<Polonius::Origin, HIR::LifetimeParam *> result; + size_t region_index = 0; + for (auto &generic_param : generic_params) + { + if (generic_param->get_kind () + == HIR::GenericParam::GenericKind::LIFETIME) + { + result[regions[region_index++]] + = static_cast<HIR::LifetimeParam *> (generic_param.get ()); + } + } + return result; + } }; } // namespace BIR diff --git a/gcc/rust/checks/errors/borrowck/rust-bir.h b/gcc/rust/checks/errors/borrowck/rust-bir.h index 8a0b964..3e4ea9a 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir.h @@ -47,6 +47,7 @@ struct Function std::vector<BasicBlock> basic_blocks; FreeRegions universal_regions; std::vector<std::pair<FreeRegion, FreeRegion>> universal_region_bounds; + std::unordered_map<Polonius::Origin, HIR::LifetimeParam *> region_hir_map; location_t location; }; |