From: Owen Avery <[email protected]>
ForeverStack::Node doesn't have to be templated, so it can be moved to a
new base class for ForeverStack (ForeverStackBase). This should help
with handling Node objects that come from ForeverStack instances with
different namespaces.
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h (class ForeverStackBase): New.
(class ForeverStack): Use ForeverStackBase as a base class.
(class ForeverStack::Link): Move to...
(class ForeverStackBase::Link): ...here.
(class ForeverStack::LinkCmp): Move to...
(class ForeverStackBase::LinkCmp): ...here.
(class ForeverStack::Node): Move to...
(class ForeverStackBase::Node): ...here.
(ForeverStackBase::Node::is_root): Mark inline.
(ForeverStackBase::Node::is_prelude): Likewise.
(ForeverStackBase::Node::is_leaf): Likewise.
(ForeverStackBase::Node::insert_child): Likewise.
* resolve/rust-forever-stack.hxx (ForeverStack::Node::is_root):
Move to...
(ForeverStackBase::Node::is_root): ...here.
(ForeverStack::Node::is_prelude): Move to...
(ForeverStackBase::Node::is_prelude): ...here.
(ForeverStack::Node::is_leaf): Move to...
(ForeverStackBase::Node::is_leaf): ...here.
(ForeverStack::Node::insert_child): Move to...
(ForeverStackBase::Node::insert_child): ...here.
Signed-off-by: Owen Avery <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/0e19cee2e9b0b004f3ce6aaded424c2d3a072f26
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4653
gcc/rust/resolve/rust-forever-stack.h | 100 ++++++++++++------------
gcc/rust/resolve/rust-forever-stack.hxx | 12 +--
2 files changed, 56 insertions(+), 56 deletions(-)
diff --git a/gcc/rust/resolve/rust-forever-stack.h
b/gcc/rust/resolve/rust-forever-stack.h
index 7e8cf14d9..823868218 100644
--- a/gcc/rust/resolve/rust-forever-stack.h
+++ b/gcc/rust/resolve/rust-forever-stack.h
@@ -484,7 +484,58 @@ enum class LookupFinalizeError
Loop,
};
-template <Namespace N> class ForeverStack
+class ForeverStackBase
+{
+public:
+ /**
+ * A link between two Nodes in our trie data structure. This class represents
+ * the edges of the graph
+ */
+ class Link
+ {
+ public:
+ Link (NodeId id, tl::optional<Identifier> path) : id (id), path (path) {}
+
+ bool compare (const Link &other) const { return id < other.id; }
+
+ NodeId id;
+ tl::optional<Identifier> path;
+ };
+
+ /* Link comparison class, which we use in a Node's `children` map */
+ class LinkCmp
+ {
+ public:
+ bool operator() (const Link &lhs, const Link &rhs) const
+ {
+ return lhs.compare (rhs);
+ }
+ };
+
+ class Node
+ {
+ public:
+ Node (Rib rib, NodeId id) : rib (rib), id (id) {}
+ Node (Rib rib, NodeId id, Node &parent)
+ : rib (rib), id (id), parent (parent)
+ {}
+
+ inline bool is_root () const;
+ inline bool is_prelude () const;
+ inline bool is_leaf () const;
+
+ inline void insert_child (Link link, Node child);
+
+ Rib rib; // this is the "value" of the node - the data it keeps.
+ std::map<Link, Node, LinkCmp> children; // all the other nodes it links to
+
+ NodeId id; // The node id of the Node's scope
+
+ tl::optional<Node &> parent; // `None` only if the node is a root
+ };
+};
+
+template <Namespace N> class ForeverStack : public ForeverStackBase
{
public:
ForeverStack ()
@@ -625,53 +676,6 @@ public:
*/
bool is_module_descendant (NodeId parent, NodeId child) const;
- /**
- * A link between two Nodes in our trie data structure. This class represents
- * the edges of the graph
- */
- class Link
- {
- public:
- Link (NodeId id, tl::optional<Identifier> path) : id (id), path (path) {}
-
- bool compare (const Link &other) const { return id < other.id; }
-
- NodeId id;
- tl::optional<Identifier> path;
- };
-
- /* Link comparison class, which we use in a Node's `children` map */
- class LinkCmp
- {
- public:
- bool operator() (const Link &lhs, const Link &rhs) const
- {
- return lhs.compare (rhs);
- }
- };
-
- class Node
- {
- public:
- Node (Rib rib, NodeId id) : rib (rib), id (id) {}
- Node (Rib rib, NodeId id, Node &parent)
- : rib (rib), id (id), parent (parent)
- {}
-
- bool is_root () const;
- bool is_prelude () const;
- bool is_leaf () const;
-
- void insert_child (Link link, Node child);
-
- Rib rib; // this is the "value" of the node - the data it keeps.
- std::map<Link, Node, LinkCmp> children; // all the other nodes it links to
-
- NodeId id; // The node id of the Node's scope
-
- tl::optional<Node &> parent; // `None` only if the node is a root
- };
-
tl::optional<Rib::Definition> get (Node &start, const Identifier &name);
/* Should we keep going upon seeing a Rib? */
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx
b/gcc/rust/resolve/rust-forever-stack.hxx
index 07290feb4..3ed6692ff 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -28,30 +28,26 @@
namespace Rust {
namespace Resolver2_0 {
-template <Namespace N>
bool
-ForeverStack<N>::Node::is_root () const
+ForeverStackBase::Node::is_root () const
{
return !parent.has_value ();
}
-template <Namespace N>
bool
-ForeverStack<N>::Node::is_prelude () const
+ForeverStackBase::Node::is_prelude () const
{
return rib.kind == Rib::Kind::Prelude;
}
-template <Namespace N>
bool
-ForeverStack<N>::Node::is_leaf () const
+ForeverStackBase::Node::is_leaf () const
{
return children.empty ();
}
-template <Namespace N>
void
-ForeverStack<N>::Node::insert_child (Link link, Node child)
+ForeverStackBase::Node::insert_child (Link link, Node child)
{
children.insert ({link, child});
base-commit: e540b625a9f1c50d30e2d4ebbe17a480a1d1cfb2
--
2.54.0