gccrs: rework the HIR dump pass
Nearly complete rewrite of the HIR dump pass. fixes #693 gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (convert_param_kind_to_str): New. (convert_new_bind_type_to_str): New. (convert_mut_to_str): New. (Dump::go): New. (Dump::put): New. (Dump::begin): New. (Dump::end): New. (Dump::begin_field): New. (Dump::end_field): New. (Dump::put_field): New. (Dump::visit_field): New. (Dump::visit): Refactor. (Dump::visit_collection): New. (Dump::do_traititem): New. (Dump::do_vis_item): New. (Dump::do_functionparam): New. (Dump::do_pathpattern): New. (Dump::do_structexprstruct): New. (Dump::do_expr): New. (Dump::do_pathexpr): New. (Dump::do_typepathsegment): New. (Dump::do_typepathfunction): New. (Dump::do_qualifiedpathtype): New. (Dump::do_operatorexpr): New. (Dump::do_mappings): New. (Dump::do_inner_attrs): New. (Dump::do_outer_attrs): New. (Dump::do_baseloopexpr): New. (Dump::do_ifletexpr): New. (Dump::do_struct): New. (Dump::do_enumitem): New. (Dump::do_traitfunctiondecl): New. (Dump::do_externalitem): New. (Dump::do_namefunctionparam): New. (Dump::do_stmt): New. (Dump::do_type): New. (Dump::do_item): New. (Dump::do_tuplefield): New. (Dump::do_structfield): New. (Dump::do_genericargs): New. (Dump::do_maybenamedparam): New. * hir/rust-hir-dump.h: Refactor. * hir/tree/rust-hir-item.h (enum_to_str): New. * hir/tree/rust-hir-type.h (enum_to_str): New. * hir/tree/rust-hir.cc (enum_to_str): New. * util/rust-common.h (enum_to_str): New. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
This commit is contained in:
parent
8288dc0fed
commit
bcd76dbcaa
6 changed files with 2406 additions and 560 deletions
File diff suppressed because it is too large
Load diff
|
@ -19,6 +19,8 @@
|
|||
#ifndef RUST_HIR_DUMP_H
|
||||
#define RUST_HIR_DUMP_H
|
||||
|
||||
#include "rust-hir-expr.h"
|
||||
#include "rust-hir-item.h"
|
||||
#include "rust-hir-visitor.h"
|
||||
#include "rust-hir.h"
|
||||
#include "rust-hir-full.h"
|
||||
|
@ -34,9 +36,68 @@ public:
|
|||
void go (HIR::Crate &crate);
|
||||
|
||||
private:
|
||||
bool beg_of_line;
|
||||
Indent indentation;
|
||||
std::ostream &stream;
|
||||
|
||||
void put (std::string name, bool newline = true);
|
||||
|
||||
enum delim
|
||||
{
|
||||
CURLY = 0,
|
||||
SQUARE = 1,
|
||||
};
|
||||
|
||||
static std::string delims[2][2];
|
||||
|
||||
void begin (std::string name, enum delim = SQUARE);
|
||||
void end (std::string name, enum delim = SQUARE);
|
||||
void begin_field (std::string name);
|
||||
void end_field (std::string name);
|
||||
|
||||
template <class T>
|
||||
void visit_collection (std::string name,
|
||||
std::vector<std::unique_ptr<T>> &vec);
|
||||
|
||||
template <class T>
|
||||
void visit_collection (std::string name, std::vector<T> &vec);
|
||||
|
||||
void visit_field (std::string field_name, FullVisitable &v);
|
||||
|
||||
template <class T>
|
||||
void visit_field (std::string field_name, std::unique_ptr<T> &);
|
||||
|
||||
void put_field (std::string field_name, std::string text);
|
||||
void do_vis_item (VisItem &);
|
||||
void do_mappings (const Analysis::NodeMapping &mappings);
|
||||
void do_inner_attrs (WithInnerAttrs &);
|
||||
void do_outer_attrs (std::vector<AST::Attribute> &attrs);
|
||||
|
||||
void do_stmt (Stmt &);
|
||||
void do_item (Item &);
|
||||
void do_type (Type &);
|
||||
void do_expr (Expr &);
|
||||
void do_ifletexpr (IfLetExpr &);
|
||||
void do_pathexpr (PathExpr &);
|
||||
void do_pathpattern (PathPattern &);
|
||||
void do_genericargs (GenericArgs &);
|
||||
void do_typepathsegment (TypePathSegment &);
|
||||
void do_typepathfunction (TypePathFunction &);
|
||||
void do_externalitem (ExternalItem &);
|
||||
void do_operatorexpr (OperatorExpr &);
|
||||
void do_structexprstruct (StructExprStruct &);
|
||||
void do_functionparam (FunctionParam &);
|
||||
void do_qualifiedpathtype (QualifiedPathType &);
|
||||
void do_baseloopexpr (BaseLoopExpr &);
|
||||
void do_traititem (TraitItem &);
|
||||
void do_traitfunctiondecl (TraitFunctionDecl &);
|
||||
void do_namefunctionparam (NamedFunctionParam &);
|
||||
void do_enumitem (EnumItem &);
|
||||
void do_tuplefield (TupleField &);
|
||||
void do_structfield (StructField &);
|
||||
void do_maybenamedparam (MaybeNamedParam &);
|
||||
void do_struct (Struct &);
|
||||
|
||||
void visit (AST::Attribute &attribute);
|
||||
virtual void visit (Lifetime &) override;
|
||||
virtual void visit (LifetimeParam &) override;
|
||||
|
@ -120,10 +181,12 @@ private:
|
|||
virtual void visit (TypeAlias &) override;
|
||||
virtual void visit (StructStruct &) override;
|
||||
virtual void visit (TupleStruct &) override;
|
||||
|
||||
virtual void visit (EnumItem &) override;
|
||||
virtual void visit (EnumItemTuple &) override;
|
||||
virtual void visit (EnumItemStruct &) override;
|
||||
virtual void visit (EnumItemDiscriminant &) override;
|
||||
|
||||
virtual void visit (Enum &) override;
|
||||
virtual void visit (Union &) override;
|
||||
virtual void visit (ConstantItem &) override;
|
||||
|
|
|
@ -1009,6 +1009,8 @@ protected:
|
|||
}
|
||||
};
|
||||
|
||||
std::string enum_to_str (UseTreeRebind::NewBindType);
|
||||
|
||||
// Rust use declaration (i.e. for modules) HIR node
|
||||
class UseDeclaration : public VisItem
|
||||
{
|
||||
|
|
|
@ -750,6 +750,8 @@ public:
|
|||
Identifier get_name () const { return name; }
|
||||
};
|
||||
|
||||
std::string enum_to_str (MaybeNamedParam::ParamKind);
|
||||
|
||||
/* A function pointer type - can be created via coercion from function items and
|
||||
* non- capturing closures. */
|
||||
class BareFunctionType : public TypeNoBounds
|
||||
|
|
|
@ -3670,6 +3670,36 @@ MaybeNamedParam::as_string () const
|
|||
return str;
|
||||
}
|
||||
|
||||
std::string
|
||||
enum_to_str (MaybeNamedParam::ParamKind pk)
|
||||
{
|
||||
switch (pk)
|
||||
{
|
||||
case MaybeNamedParam::ParamKind::UNNAMED:
|
||||
return "UNNAMED";
|
||||
case MaybeNamedParam::ParamKind::IDENTIFIER:
|
||||
return "IDENTIFIER";
|
||||
case MaybeNamedParam::ParamKind::WILDCARD:
|
||||
return "WILDCARD";
|
||||
}
|
||||
gcc_unreachable ();
|
||||
}
|
||||
|
||||
std::string
|
||||
enum_to_str (UseTreeRebind::NewBindType nbt)
|
||||
{
|
||||
switch (nbt)
|
||||
{
|
||||
case UseTreeRebind::NewBindType::NONE:
|
||||
return "NONE";
|
||||
case UseTreeRebind::NewBindType::IDENTIFIER:
|
||||
return "IDENTIFIER";
|
||||
case UseTreeRebind::NewBindType::WILDCARD:
|
||||
return "WILDCARD";
|
||||
}
|
||||
gcc_unreachable ();
|
||||
}
|
||||
|
||||
/* Override that calls the function recursively on all items contained within
|
||||
* the module. */
|
||||
void
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#ifndef RUST_COMMON
|
||||
#define RUST_COMMON
|
||||
#include "rust-system.h"
|
||||
#include <string>
|
||||
|
||||
namespace Rust {
|
||||
|
||||
|
@ -48,6 +50,20 @@ enum AsyncConstStatus
|
|||
ASYNC_FN
|
||||
};
|
||||
|
||||
inline std::string
|
||||
enum_to_str (Mutability mut)
|
||||
{
|
||||
std::string str;
|
||||
switch (mut)
|
||||
{
|
||||
case Mutability::Imm:
|
||||
return "Imm";
|
||||
case Mutability::Mut:
|
||||
return "Mut";
|
||||
}
|
||||
gcc_unreachable ();
|
||||
};
|
||||
|
||||
} // namespace Rust
|
||||
|
||||
#endif // RUST_COMMON
|
||||
|
|
Loading…
Add table
Reference in a new issue