From: Jakub Dupak <dev@jakubdupak.com>
This is currently needed for lifetimes to use the existing infrastructure.
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): Add new reference visitor wrapper.
* ast/rust-ast-dump.h: Declare it.
* ast/rust-item.h: Add mutable visibility getters.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
---
gcc/rust/ast/rust-ast-dump.cc | 15 +++++++++++----
gcc/rust/ast/rust-ast-dump.h | 11 ++++++++---
gcc/rust/ast/rust-item.h | 4 ++++
3 files changed, 23 insertions(+), 7 deletions(-)
@@ -64,6 +64,13 @@ Dump::visit (std::unique_ptr<T> &node)
node->accept_vis (*this);
}
+template <typename T>
+void
+Dump::visit (T &node)
+{
+ node.accept_vis (*this);
+}
+
template <typename T>
void
Dump::visit_items_joined_by_separator (T &collection,
@@ -129,7 +136,7 @@ Dump::visit (FunctionParam ¶m)
}
void
-Dump::visit (const Attribute &attrib)
+Dump::visit (Attribute &attrib)
{
stream << "#[";
visit_items_joined_by_separator (attrib.get_path ().get_segments (), "::");
@@ -158,13 +165,13 @@ Dump::visit (const Attribute &attrib)
}
void
-Dump::visit (const SimplePathSegment &segment)
+Dump::visit (SimplePathSegment &segment)
{
stream << segment.get_segment_name ();
}
void
-Dump::visit (const Visibility &vis)
+Dump::visit (Visibility &vis)
{
switch (vis.get_vis_type ())
{
@@ -1099,7 +1106,7 @@ Dump::visit (TraitItemType &item)
void
Dump::visit (Trait &trait)
{
- for (const auto &attr : trait.get_outer_attrs ())
+ for (auto &attr : trait.get_outer_attrs ())
{
visit (attr);
stream << "\n" << indentation;
@@ -80,6 +80,11 @@ private:
*/
template <typename T> void visit (std::unique_ptr<T> &node);
+ /**
+ * @see visit<std::unique_ptr<T>>
+ */
+ template <typename T> void visit (T &node);
+
/**
* Visit all items in given @collection, placing the separator in between but
* not at the end.
@@ -122,12 +127,12 @@ private:
std::unique_ptr<BlockExpr> &block);
void visit (FunctionParam ¶m);
- void visit (const Attribute &attrib);
- void visit (const Visibility &vis);
+ void visit (Attribute &attrib);
+ void visit (Visibility &vis);
void visit (std::vector<std::unique_ptr<GenericParam>> ¶ms);
void visit (TupleField &field);
void visit (StructField &field);
- void visit (const SimplePathSegment &segment);
+ void visit (SimplePathSegment &segment);
void visit (NamedFunctionParam ¶m);
void visit (MacroRule &rule);
@@ -908,6 +908,7 @@ public:
FunctionQualifiers get_qualifiers () { return qualifiers; }
+ Visibility &get_visibility () { return vis; }
const Visibility &get_visibility () const { return vis; }
protected:
@@ -1982,6 +1983,7 @@ public:
return field_type;
}
+ Visibility &get_visibility () { return visibility; }
const Visibility &get_visibility () const { return visibility; }
NodeId get_node_id () const { return node_id; }
@@ -2116,6 +2118,7 @@ public:
NodeId get_node_id () const { return node_id; }
+ Visibility &get_visibility () { return visibility; }
const Visibility &get_visibility () const { return visibility; }
Location get_locus () const { return locus; }
@@ -4157,6 +4160,7 @@ public:
Location get_locus () const { return locus; }
+ Visibility &get_visibility () { return visibility; }
const Visibility &get_visibility () const { return visibility; }
ExternalFunctionItem (