@@ -546,21 +546,17 @@ class ForeverStackStore
546
546
template <Namespace N> class ForeverStack
547
547
{
548
548
public:
549
- ForeverStack ()
549
+ ForeverStack (ForeverStackStore &base )
550
550
// FIXME: Is that valid? Do we use the root? If yes, we should give the
551
551
// 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
+ {}
558
554
559
555
/* *
560
556
* Add a new Rib to the stack. If the Rib already exists, nothing is pushed
561
557
* and the stack's cursor is simply moved to this existing Rib.
562
558
*
563
- * @param rib The Rib to push
559
+ * @param rib_kind The kind of Rib to push
564
560
* @param id The NodeId of the node for which the Rib was created. For
565
561
* example, if a Rib is created because a lexical scope is entered,
566
562
* then `id` is that `BlockExpr`'s NodeId.
@@ -679,61 +675,8 @@ template <Namespace N> class ForeverStack
679
675
bool is_module_descendant (NodeId parent, NodeId child) const ;
680
676
681
677
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;
737
680
738
681
/* Reverse iterate on `Node`s from the cursor, in an outwards fashion */
739
682
void reverse_iter (std::function<KeepGoing (Node &)> lambda);
@@ -748,7 +691,7 @@ template <Namespace N> class ForeverStack
748
691
const Node &cursor () const ;
749
692
void update_cursor (Node &new_cursor);
750
693
751
- Node root ;
694
+ std::reference_wrapper<ForeverStackStore> base ;
752
695
std::reference_wrapper<Node> cursor_reference;
753
696
754
697
void stream_rib (std::stringstream &stream, const Rib &rib,
@@ -774,16 +717,8 @@ template <Namespace N> class ForeverStack
774
717
SegIterator<S> iterator);
775
718
776
719
/* 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;
787
722
788
723
// FIXME: Documentation
789
724
tl::optional<DfsResult> dfs (Node &starting_point, NodeId to_find);
0 commit comments