aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorKushal Pal <kushalpal109@gmail.com>2024-08-19 09:28:25 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-19 15:32:09 +0100
commitd91f1148d85ae0801387975364a5338237ac6efc (patch)
treeac108b213aed118d1124fc1a3a3fab0c6ba8b9c5 /gcc/rust
parent11b808ba788834072539a4aca6d64144243e5d46 (diff)
downloadgcc-d91f1148d85ae0801387975364a5338237ac6efc.zip
gcc-d91f1148d85ae0801387975364a5338237ac6efc.tar.gz
gcc-d91f1148d85ae0801387975364a5338237ac6efc.tar.bz2
gccrs: Introduce `IndexVec`
gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-place.h (struct Loan): Introduce new class `IndexVec` inspired from IndexVec of rust. It acts as a wrapper around `std::vector` and lets user specify a strong type to use as index. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/checks/errors/borrowck/rust-bir-place.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index f7018d3..2356460 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -199,6 +199,25 @@ struct Loan
location_t location;
};
+// I is the index type, T is the contained type
+template <typename I, typename T> class IndexVec
+{
+ std::vector<T> internal_vector;
+
+public:
+ T &at (I pid) { return internal_vector[pid.value]; }
+ const T &at (I pid) const { return internal_vector[pid.value]; }
+ T &operator[] (I pid) { return internal_vector[pid.value]; }
+ const T &operator[] (I pid) const { return internal_vector[pid.value]; }
+
+ void push_back (T &&param) { internal_vector.push_back (std::move (param)); }
+ template <typename... Args> void emplace_back (Args &&... args)
+ {
+ internal_vector.emplace_back (std::forward<Args> (args)...);
+ }
+ size_t size () const { return internal_vector.size (); }
+};
+
/** Allocated places and keeps track of paths. */
class PlaceDB
{