Skip to content

Commit

Permalink
Add some reference getter
Browse files Browse the repository at this point in the history
Visitor pattern requires a getter to children using a mutable reference.

gcc/rust/ChangeLog:

	* ast/rust-ast.h: Add some missing mutable reference getters.
	* ast/rust-expr.h: Likewise.
	* ast/rust-item.h: Likewise.
	* ast/rust-path.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
  • Loading branch information
P-E-P authored and CohenArthur committed Nov 6, 2023
1 parent e7caf68 commit ebe2f98
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions gcc/rust/ast/rust-ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,10 @@ class LifetimeParam : public GenericParam
public:
Lifetime get_lifetime () const { return lifetime; }

Lifetime &get_lifetime () { return lifetime; }

Attribute &get_outer_attribute () { return outer_attr; }

// Returns whether the lifetime param has any lifetime bounds.
bool has_lifetime_bounds () const { return !lifetime_bounds.empty (); }

Expand Down
6 changes: 6 additions & 0 deletions gcc/rust/ast/rust-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ class MetaItemLitExpr : public MetaItemInner

LiteralExpr get_literal () const { return lit_expr; }

LiteralExpr &get_literal () { return lit_expr; }

void accept_vis (ASTVisitor &vis) override;

bool check_cfg_predicate (const Session &session) const override;
Expand Down Expand Up @@ -256,8 +258,12 @@ class MetaItemPathLit : public MetaItem

SimplePath get_path () const { return path; }

SimplePath &get_path () { return path; }

LiteralExpr get_literal () const { return lit; }

LiteralExpr &get_literal () { return lit; }

std::string as_string () const override
{
return path.as_string () + " = " + lit.as_string ();
Expand Down
22 changes: 19 additions & 3 deletions gcc/rust/ast/rust-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class TypeParam : public GenericParam
// Returns whether the type param has an outer attribute.
bool has_outer_attribute () const { return !outer_attr.is_empty (); }

Attribute &get_outer_attribute () { return outer_attr; }

TypeParam (Identifier type_representation, location_t locus = UNDEF_LOCATION,
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds
= std::vector<std::unique_ptr<TypeParamBound>> (),
Expand Down Expand Up @@ -472,6 +474,7 @@ class SelfParam
bool get_is_mut () const { return is_mut; }

Lifetime get_lifetime () const { return lifetime; }
Lifetime &get_lifetime () { return lifetime; }

NodeId get_node_id () const { return node_id; }

Expand Down Expand Up @@ -915,7 +918,9 @@ class Method : public InherentImplItem, public TraitImplItem

location_t get_locus () const override final { return locus; }

FunctionQualifiers get_qualifiers () { return qualifiers; }
FunctionQualifiers get_qualifiers () const { return qualifiers; }

FunctionQualifiers &get_qualifiers () { return qualifiers; }

Visibility &get_visibility () { return vis; }
const Visibility &get_visibility () const { return vis; }
Expand Down Expand Up @@ -1299,6 +1304,8 @@ class UseTreeGlob : public UseTree
return path;
}

SimplePath &get_path () { return path; }

/* TODO: find way to ensure only PATH_PREFIXED glob_type has path - factory
* methods? */
protected:
Expand Down Expand Up @@ -1389,6 +1396,8 @@ class UseTreeList : public UseTree
return path;
}

SimplePath &get_path () { return path; }

std::vector<std::unique_ptr<UseTree>> &get_trees () { return trees; }

const std::vector<std::unique_ptr<UseTree>> &get_trees () const
Expand Down Expand Up @@ -1451,6 +1460,8 @@ class UseTreeRebind : public UseTree
return path;
}

SimplePath &get_path () { return path; }

const Identifier &get_identifier () const
{
rust_assert (has_identifier ());
Expand Down Expand Up @@ -1677,6 +1688,8 @@ class Function : public VisItem, public InherentImplItem, public TraitImplItem

const FunctionQualifiers &get_qualifiers () const { return qualifiers; }

FunctionQualifiers &get_qualifiers () { return qualifiers; }

Identifier get_function_name () const { return function_name; }

// TODO: is this better? Or is a "vis_block" better?
Expand Down Expand Up @@ -2921,7 +2934,8 @@ class TraitFunctionDecl
// TODO: is this better? Or is a "vis_block" better?
WhereClause &get_where_clause () { return where_clause; }

FunctionQualifiers get_qualifiers () { return qualifiers; }
FunctionQualifiers get_qualifiers () const { return qualifiers; }
FunctionQualifiers &get_qualifiers () { return qualifiers; }
};

// Actual trait item function declaration within traits
Expand Down Expand Up @@ -3137,7 +3151,9 @@ class TraitMethodDecl
SelfParam &get_self_param () { return self_param; }
const SelfParam &get_self_param () const { return self_param; }

FunctionQualifiers get_qualifiers () { return qualifiers; }
FunctionQualifiers get_qualifiers () const { return qualifiers; }

FunctionQualifiers &get_qualifiers () { return qualifiers; }
};

// Actual trait item method declaration within traits
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/ast/rust-path.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ class ConstGenericParam : public GenericParam

const Identifier &get_name () const { return name; }

Attribute &get_outer_attribute () { return outer_attr; }

std::unique_ptr<AST::Type> &get_type ()
{
rust_assert (has_type ());
Expand Down

0 comments on commit ebe2f98

Please sign in to comment.