{
internal_vector.emplace_back (std::forward<Args> (args)...);
}
- std::vector<T> &get_vector () { return internal_vector; }
+
size_t size () const { return internal_vector.size (); }
+
+ std::vector<T> &get_vector () { return internal_vector; }
};
using Scopes = IndexVec<ScopeId, Scope>;
using Loans = IndexVec<LoanId, Loan>;
+using Places = IndexVec<PlaceId, Place>;
/** Allocated places and keeps track of paths. */
class PlaceDB
{
private:
// Possible optimizations: separate variables to speedup lookup.
- std::vector<Place> places;
+ Places places;
std::unordered_map<TyTy::BaseType *, PlaceId> constants_lookup;
Scopes scopes;
ScopeId current_scope = ROOT_SCOPE;
scopes.emplace_back (); // Root scope.
}
- Place &operator[] (PlaceId id) { return places.at (id.value); }
- const Place &operator[] (PlaceId id) const { return places.at (id.value); }
-
- decltype (places)::const_iterator begin () const { return places.begin (); }
- decltype (places)::const_iterator end () const { return places.end (); }
+ Place &operator[] (PlaceId id) { return places.at (id); }
+ const Place &operator[] (PlaceId id) const { return places.at (id); }
size_t size () const { return places.size (); }
{
places.emplace_back (std::forward<Place &&> (place));
PlaceId new_place = {places.size () - 1};
- Place &new_place_ref = places[new_place.value]; // Intentional shadowing.
+ Place &new_place_ref = places[new_place]; // Intentional shadowing.
if (last_sibling == INVALID_PLACE)
- places[new_place_ref.path.parent.value].path.first_child = new_place;
+ places[new_place_ref.path.parent].path.first_child = new_place;
else
- places[last_sibling.value].path.next_sibling = new_place;
+ places[last_sibling].path.next_sibling = new_place;
if (new_place_ref.kind == Place::VARIABLE
|| new_place_ref.kind == Place::TEMPORARY)
PlaceId current = INVALID_PLACE;
if (parent.value < places.size ())
{
- current = places[parent.value].path.first_child;
+ current = places[parent].path.first_child;
while (current != INVALID_PLACE)
{
- if (places[current.value].kind == kind
- && places[current.value].variable_or_field_index == id)
+ if (places[current].kind == kind
+ && places[current].variable_or_field_index == id)
{
- rust_assert (places[current.value].tyty->is_equal (*tyty));
+ rust_assert (places[current].tyty->is_equal (*tyty));
return current;
}
- current = places[current.value].path.next_sibling;
+ current = places[current].path.next_sibling;
}
}
return add_place ({kind, (uint32_t) id,
while (current.value != places.size ())
{
- if (places[current.value].kind == Place::VARIABLE
- && places[current.value].variable_or_field_index == id)
+ if (places[current].kind == Place::VARIABLE
+ && places[current].variable_or_field_index == id)
return current;
++current.value;
}
LoanId id = {loans.size ()};
loans.push_back (std::forward<Loan &&> (loan));
PlaceId borrowed_place = loans.get_vector ().rbegin ()->place;
- places[loans.get_vector ().rbegin ()->place.value].borrowed_by.push_back (
- id);
- if (places[borrowed_place.value].kind == Place::DEREF)
+ places[loans.get_vector ().rbegin ()->place].borrowed_by.push_back (id);
+ if (places[borrowed_place].kind == Place::DEREF)
{
- places[places[borrowed_place.value].path.parent.value]
- .borrowed_by.push_back (id);
+ places[places[borrowed_place].path.parent].borrowed_by.push_back (id);
}
return id;
}
PlaceId get_var (PlaceId id) const
{
- if (places[id.value].is_var ())
+ if (places[id].is_var ())
return id;
- rust_assert (places[id.value].is_path ());
+ rust_assert (places[id].is_path ());
PlaceId current = id;
- while (!places[current.value].is_var ())
+ while (!places[current].is_var ())
{
- current = places[current.value].path.parent;
+ current = places[current].path.parent;
}
return current;
}
template <typename FN> void for_each_path_from_root (PlaceId var, FN fn) const
{
PlaceId current = var;
- current = places[current.value].path.first_child;
+ current = places[current].path.first_child;
while (current != INVALID_PLACE)
{
fn (current);
for_each_path_from_root (current, fn);
- current = places[current.value].path.next_sibling;
+ current = places[current].path.next_sibling;
}
}
while (current != INVALID_PLACE)
{
fn (current);
- current = places[current.value].path.parent;
+ current = places[current].path.parent;
}
}