mirror of
https://gcc.gnu.org/git/gcc.git
synced 2026-02-22 12:00:03 -05:00
gccrs: ast: transform helper methods to visits and add methods to simplify repeated patterns
gcc/rust/ChangeLog: * ast/rust-ast-dump.cc (Dump::go): Use new API. (Dump::format_function_param): Refactor. (Dump::visit_items_joined_by_separator): New function. (Dump::emit_attrib): Refactor. (Dump::visit_as_line): New function. (Dump::visit_items_as_lines): Likewise. (Dump::visit_items_as_block): Likewise. (Dump::visit): Use new API. (Dump::emit_visibility): Likewise. (Dump::emit_indented_string): Likewise. (Dump::emit_generic_params): Likewise. (Dump::format_tuple_field): Likewise. (Dump::format_struct_field): Likewise. (Dump::format_function_common): Likewise. (Dump::visit_function_common): Likewise. * ast/rust-ast-dump.h: Declare new functions and add documentation. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
This commit is contained in:
committed by
Arthur Cohen
parent
aedd97a537
commit
3b5fb3f89b
File diff suppressed because it is too large
Load Diff
@@ -81,46 +81,55 @@ private:
|
||||
template <typename T> void visit (std::unique_ptr<T> &node);
|
||||
|
||||
/**
|
||||
* Format together common items of functions: Parameters, return type, block
|
||||
* Visit all items in given collection, placing the separator in between but
|
||||
* not at the end.
|
||||
* Start and end offset allow to visit only a "slice" from the collection.
|
||||
*/
|
||||
void format_function_common (std::unique_ptr<Type> &return_type,
|
||||
std::unique_ptr<BlockExpr> &block);
|
||||
template <typename T>
|
||||
void visit_items_joined_by_separator (T &collection,
|
||||
const std::string &separator = "",
|
||||
size_t start_offset = 0,
|
||||
size_t end_offset = 0);
|
||||
|
||||
/**
|
||||
* Format a function's definition parameter
|
||||
* Visit item placing indentation before and trailing string + end of line
|
||||
* after.
|
||||
*/
|
||||
void format_function_param (FunctionParam ¶m);
|
||||
template <typename T>
|
||||
void visit_as_line (T &item, const std::string &trailing = "");
|
||||
|
||||
/**
|
||||
* Emit an attribute
|
||||
* Visit each item in a collection "as line".
|
||||
*
|
||||
* @see visit_as_line
|
||||
*/
|
||||
void emit_attrib (const Attribute &attrib);
|
||||
template <typename T>
|
||||
void visit_items_as_lines (T &collection, const std::string &trailing = "");
|
||||
|
||||
/**
|
||||
* Emit an item's visibility
|
||||
* Visit each item in collection as lines inside a block delimited by braces
|
||||
* with increased indentation. Also includes special handling for empty
|
||||
* collection to print only the delimiters with no new line inside.
|
||||
*/
|
||||
void emit_visibility (const Visibility &vis);
|
||||
template <typename T>
|
||||
void visit_items_as_block (T &collection, const std::string &line_trailing,
|
||||
char left_brace = '{', char right_brace = '}');
|
||||
|
||||
/**
|
||||
* Emit an indented string with an optional extra comment
|
||||
* Visit common items of functions: Parameters, return type, block
|
||||
*/
|
||||
std::ostream &emit_indented_string (const std::string &value,
|
||||
const std::string &comment = "");
|
||||
void visit_function_common (std::unique_ptr<Type> &return_type,
|
||||
std::unique_ptr<BlockExpr> &block);
|
||||
|
||||
/**
|
||||
* Emit formatted string for generic parameters
|
||||
*/
|
||||
void emit_generic_params (std::vector<std::unique_ptr<GenericParam>> ¶ms);
|
||||
|
||||
/**
|
||||
* Format a single field of a tuple
|
||||
*/
|
||||
void format_tuple_field (TupleField &field);
|
||||
|
||||
/**
|
||||
* Format a single field of a struct
|
||||
*/
|
||||
void format_struct_field (StructField &field);
|
||||
void visit (FunctionParam ¶m);
|
||||
void visit (const Attribute &attrib);
|
||||
void visit (const 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 (NamedFunctionParam ¶m);
|
||||
void visit (MacroRule &rule);
|
||||
|
||||
// rust-ast.h
|
||||
void visit (Token &tok);
|
||||
|
||||
Reference in New Issue
Block a user