Skip to content

Commit 36e8ab8

Browse files
committed
[skip ci] use ForeverStackStore
1 parent ceb13c1 commit 36e8ab8

File tree

4 files changed

+125
-334
lines changed

4 files changed

+125
-334
lines changed

gcc/rust/resolve/rust-forever-stack.h

+9-74
Original file line numberDiff line numberDiff line change
@@ -546,21 +546,17 @@ class ForeverStackStore
546546
template <Namespace N> class ForeverStack
547547
{
548548
public:
549-
ForeverStack ()
549+
ForeverStack (ForeverStackStore &base)
550550
// FIXME: Is that valid? Do we use the root? If yes, we should give the
551551
// crate's node id to ForeverStack's constructor
552-
: root (Node (Rib (Rib::Kind::Normal), UNKNOWN_NODEID)),
553-
cursor_reference (root)
554-
{
555-
rust_assert (root.is_root ());
556-
rust_assert (root.is_leaf ());
557-
}
552+
: base (base), cursor_reference (base.get_root ())
553+
{}
558554

559555
/**
560556
* Add a new Rib to the stack. If the Rib already exists, nothing is pushed
561557
* and the stack's cursor is simply moved to this existing Rib.
562558
*
563-
* @param rib The Rib to push
559+
* @param rib_kind The kind of Rib to push
564560
* @param id The NodeId of the node for which the Rib was created. For
565561
* example, if a Rib is created because a lexical scope is entered,
566562
* then `id` is that `BlockExpr`'s NodeId.
@@ -679,61 +675,8 @@ template <Namespace N> class ForeverStack
679675
bool is_module_descendant (NodeId parent, NodeId child) const;
680676

681677
private:
682-
/**
683-
* A link between two Nodes in our trie data structure. This class represents
684-
* the edges of the graph
685-
*/
686-
class Link
687-
{
688-
public:
689-
Link (NodeId id, tl::optional<Identifier> path) : id (id), path (path) {}
690-
691-
bool compare (const Link &other) const { return id < other.id; }
692-
693-
NodeId id;
694-
tl::optional<Identifier> path;
695-
};
696-
697-
/* Link comparison class, which we use in a Node's `children` map */
698-
class LinkCmp
699-
{
700-
public:
701-
bool operator() (const Link &lhs, const Link &rhs) const
702-
{
703-
return lhs.compare (rhs);
704-
}
705-
};
706-
707-
class Node
708-
{
709-
public:
710-
Node (Rib rib, NodeId id) : rib (rib), id (id) {}
711-
Node (Rib rib, NodeId id, Node &parent)
712-
: rib (rib), id (id), parent (parent)
713-
{}
714-
715-
bool is_root () const;
716-
bool is_leaf () const;
717-
718-
void insert_child (Link link, Node child);
719-
720-
Rib rib; // this is the "value" of the node - the data it keeps.
721-
std::map<Link, Node, LinkCmp> children; // all the other nodes it links to
722-
723-
NodeId id; // The node id of the Node's scope
724-
725-
tl::optional<Node &> parent; // `None` only if the node is a root
726-
};
727-
728-
/* Should we keep going upon seeing a Rib? */
729-
enum class KeepGoing
730-
{
731-
Yes,
732-
No,
733-
};
734-
735-
/* Add a new Rib to the stack. This is an internal method */
736-
void push_inner (Rib rib, Link link);
678+
using Node = ForeverStackStore::Node;
679+
using KeepGoing = ForeverStackStore::KeepGoing;
737680

738681
/* Reverse iterate on `Node`s from the cursor, in an outwards fashion */
739682
void reverse_iter (std::function<KeepGoing (Node &)> lambda);
@@ -748,7 +691,7 @@ template <Namespace N> class ForeverStack
748691
const Node &cursor () const;
749692
void update_cursor (Node &new_cursor);
750693

751-
Node root;
694+
std::reference_wrapper<ForeverStackStore> base;
752695
std::reference_wrapper<Node> cursor_reference;
753696

754697
void stream_rib (std::stringstream &stream, const Rib &rib,
@@ -774,16 +717,8 @@ template <Namespace N> class ForeverStack
774717
SegIterator<S> iterator);
775718

776719
/* Helper functions for forward resolution (to_canonical_path, to_rib...) */
777-
struct DfsResult
778-
{
779-
Node &first;
780-
std::string second;
781-
};
782-
struct ConstDfsResult
783-
{
784-
const Node &first;
785-
std::string second;
786-
};
720+
using DfsResult = ForeverStackStore::DfsResult;
721+
using ConstDfsResult = ForeverStackStore::ConstDfsResult;
787722

788723
// FIXME: Documentation
789724
tl::optional<DfsResult> dfs (Node &starting_point, NodeId to_find);

0 commit comments

Comments
 (0)