if (is_query_mode && compiler.reference == error_mark_node)
rust_internal_error_at (ref_locus, "failed to compile trait item: %s",
- item->as_string ().c_str ());
+ item->to_string ().c_str ());
return compiler.reference;
}
auto compiled_param_type
= TyTyResolveCompile::compile (ctx, param_tyty, trait_object_mode);
- parameters.emplace_back (param_pair.get_pattern ().as_string (),
+ parameters.emplace_back (param_pair.get_pattern ().to_string (),
compiled_param_type,
ctx->get_mappings ().lookup_location (
param_tyty->get_ref ()));
auto hir_id = pattern->get_mappings ().get_hirid ();
if (already_assigned_variables.count (hir_id) > 0)
rust_error_at (assigned_loc, "assignment of read-only variable '%s'",
- pattern->as_string ().c_str ());
+ pattern->to_string ().c_str ());
already_assigned_variables.insert (hir_id);
}
do_item (e);
std::string str = "none";
if (e.has_visibility ())
- str = e.get_visibility ().as_string ();
+ str = e.get_visibility ().to_string ();
put_field ("visibility", str);
}
std::string str = "";
for (const auto &segment : e.get_segments ())
- str += segment.as_string () + ", ";
+ str += segment.to_string () + ", ";
put_field ("segments", str);
}
if (e.is_lang_item ())
put_field ("ident_segment", LangItem::PrettyString (e.get_lang_item ()));
else
- put_field ("ident_segment", e.get_ident_segment ().as_string ());
+ put_field ("ident_segment", e.get_ident_segment ().to_string ());
}
void
if (!e.has_loop_label ())
put_field ("label", "none");
else
- put_field ("label", e.get_loop_label ().as_string ());
+ put_field ("label", e.get_loop_label ().to_string ());
visit_field ("loop_block", e.get_loop_block ());
}
if (!e.has_where_clause ())
put_field ("where_clause", "none");
else
- put_field ("where clause", e.get_where_clause ().as_string ());
+ put_field ("where clause", e.get_where_clause ().to_string ());
}
void
Dump::do_traitfunctiondecl (TraitFunctionDecl &e)
{
begin ("TraitFunctionDecl");
- put_field ("qualifiers", e.get_qualifiers ().as_string ());
+ put_field ("qualifiers", e.get_qualifiers ().to_string ());
put_field ("function_name", e.get_function_name ().as_string ());
visit_collection ("generic_params", e.get_generic_params ());
put_field ("return_type", "none");
if (e.has_where_clause ())
- put_field ("where_clause", e.get_where_clause ().as_string ());
+ put_field ("where_clause", e.get_where_clause ().to_string ());
else
put_field ("where_clause", "none");
if (e.is_method ())
- put_field ("self", e.get_self_unchecked ().as_string ());
+ put_field ("self", e.get_self_unchecked ().to_string ());
end ("TraitFunctionDecl");
}
std::string str = "none";
if (e.has_visibility ())
- str = e.get_visibility ().as_string ();
+ str = e.get_visibility ().to_string ();
put_field ("visibility", str);
put_field ("item_name", e.get_item_name ().as_string ());
}
std::string str = "none";
if (e.has_visibility ())
- str = e.get_visibility ().as_string ();
+ str = e.get_visibility ().to_string ();
put_field ("visibility", str);
visit_field ("field_type", e.get_field_type ());
std::string str = "none";
if (e.has_visibility ())
- str = e.get_visibility ().as_string ();
+ str = e.get_visibility ().to_string ();
put_field ("visibility", str);
put_field ("field_name", e.get_field_name ().as_string ());
visit_field ("field_type", e.get_field_type ());
Dump::visit (LifetimeParam &lifetimeparam)
{
begin ("Lifetimeparam");
- put (lifetimeparam.as_string ());
+ put (lifetimeparam.to_debug_string ());
end ("Lifetimeparam");
}
if (!e.has_struct_base ())
put_field ("struct_base", "none");
else
- put_field ("struct_base", e.get_struct_base ().as_string ());
+ put_field ("struct_base", e.get_struct_base ().to_string ());
end ("StructExprStructFields");
}
begin ("StructExprStructBase");
do_structexprstruct (e);
- put_field ("struct_base", e.get_struct_base ().as_string ());
+ put_field ("struct_base", e.get_struct_base ().to_string ());
end ("StructExprStructBase");
}
do_expr (e);
visit_field ("receiver", e.get_receiver ());
- put_field ("method_name", e.get_method_name ().as_string ());
+ put_field ("method_name", e.get_method_name ().to_string ());
visit_collection ("params", e.get_arguments ());
end ("MethodCallExpr");
put_field ("tail_reachable", std::to_string (e.is_tail_reachable ()));
if (e.has_label ())
- put_field ("label", e.get_label ().as_string ());
+ put_field ("label", e.get_label ().to_string ());
visit_collection ("statements", e.get_statements ());
begin ("ContinueExpr");
if (e.has_label ())
- put_field ("label", e.get_label ().as_string ());
+ put_field ("label", e.get_label ().to_string ());
else
put_field ("label", "none");
std::string str ("break ");
if (e.has_label ())
- put_field ("label", e.get_label ().as_string ());
+ put_field ("label", e.get_label ().to_string ());
else
put_field ("label", "none");
{
begin ("OffsetOf");
- put_field ("type", e.get_type ().as_string ());
+ put_field ("type", e.get_type ().to_debug_string ());
put_field ("field", e.get_field ());
end ("OffsetOf");
begin ("Function");
do_vis_item (e);
- put_field ("function_qualifiers", e.get_qualifiers ().as_string ());
+ put_field ("function_qualifiers", e.get_qualifiers ().to_string ());
visit_collection ("generic_params", e.get_generic_params ());
if (!e.has_where_clause ())
put_field ("where_clause", "none");
else
- put_field ("where clause", e.get_where_clause ().as_string ());
+ put_field ("where clause", e.get_where_clause ().to_string ());
visit_field ("function_body", e.get_definition ());
if (e.is_method ())
- put_field ("self", e.get_self_param_unchecked ().as_string ());
+ put_field ("self", e.get_self_param_unchecked ().to_string ());
end ("Function");
}
if (!e.has_where_clause ())
put_field ("where_clause", "none");
else
- put_field ("where clause", e.get_where_clause ().as_string ());
+ put_field ("where clause", e.get_where_clause ().to_string ());
- put_field ("type", e.get_type_aliased ().as_string ());
+ put_field ("type", e.get_type_aliased ().to_debug_string ());
end ("TypeAlias");
}
std::string str = "none";
if (e.has_where_clause ())
- str = e.get_where_clause ().as_string ();
+ str = e.get_where_clause ().to_string ();
put_field ("where clause", str);
visit_collection ("items", e.get_variants ());
std::string str;
if (e.has_where_clause ())
- str = e.get_where_clause ().as_string ();
+ str = e.get_where_clause ().to_string ();
else
str = "none";
put_field ("where clause", str);
std::string str = "none";
if (elt.has_visibility ())
- str = elt.get_visibility ().as_string ();
+ str = elt.get_visibility ().to_string ();
put_field ("visibility", str);
put_field ("field_name", elt.get_field_name ().as_string ());
visit_field ("field_type", elt.get_field_type ());
std::string str;
if (e.has_where_clause ())
- str = e.get_where_clause ().as_string ();
+ str = e.get_where_clause ().to_string ();
else
str = "none";
put_field ("where clause", str);
std::string str;
if (e.has_where_clause ())
- str = e.get_where_clause ().as_string ();
+ str = e.get_where_clause ().to_string ();
else
str = "none";
put_field ("where clause", str);
std::string str = "none";
if (e.has_visibility ())
- str = e.get_visibility ().as_string ();
+ str = e.get_visibility ().to_string ();
put_field ("visibility", str);
//
Dump::visit (RangePatternBoundPath &e)
{
begin ("RangePatternBoundPath");
- put_field ("path", e.get_path ().as_string ());
+ put_field ("path", e.get_path ().to_string ());
end ("RangePatternBoundPath");
}
{
begin ("RangePattern");
do_mappings (e.get_mappings ());
- put_field ("lower", e.get_lower_bound ().as_string ());
- put_field ("upper", e.get_upper_bound ().as_string ());
+ put_field ("lower", e.get_lower_bound ().to_string ());
+ put_field ("upper", e.get_upper_bound ().to_string ());
put_field ("has_ellipsis_syntax",
std::to_string (e.get_has_ellipsis_syntax ()));
end ("RangePattern");
begin ("ReferencePattern");
do_mappings (e.get_mappings ());
put_field ("mut", std::to_string (e.is_mut ()));
- put_field ("pattern", e.get_referenced_pattern ().as_string ());
+ put_field ("pattern", e.get_referenced_pattern ().to_debug_string ());
end ("ReferencePattern");
}
auto oa = e.get_outer_attrs ();
do_outer_attrs (oa);
put_field ("index", std::to_string (e.get_index ()));
- put_field ("tuple_pattern", e.get_tuple_pattern ().as_string ());
+ put_field ("tuple_pattern", e.get_tuple_pattern ().to_string ());
end ("StructPatternFieldTuplePat");
}
begin ("StructPattern");
visit_field ("path", e.get_path ());
- put_field ("elems", e.get_struct_pattern_elems ().as_string ());
+ put_field ("elems", e.get_struct_pattern_elems ().to_string ());
end ("StructPattern");
}
begin ("TupleStructPattern");
do_mappings (e.get_mappings ());
- put_field ("path", e.get_path ().as_string ());
+ put_field ("path", e.get_path ().to_string ());
visit_field ("items", e.get_items ());
{
begin ("ParenthesisedType");
do_type (e);
- put_field ("type_in_parens", e.get_type_in_parens ().as_string ());
+ put_field ("type_in_parens", e.get_type_in_parens ().to_debug_string ());
end ("ParenthesisedType");
}
begin ("RawPointerType");
do_type (e);
put_field ("mut", Rust::enum_to_str (e.get_mut ()));
- put_field ("type", e.get_type ().as_string ());
+ put_field ("type", e.get_type ().to_debug_string ());
end ("RawPointerType");
}
{
begin ("ReferenceType");
do_type (e);
- put_field ("lifetime", e.get_lifetime ().as_string ());
+ put_field ("lifetime", e.get_lifetime ().to_string ());
put_field ("mut", enum_to_str (e.get_mut ()));
- put_field ("type", e.get_base_type ().as_string ());
+ put_field ("type", e.get_base_type ().to_debug_string ());
end ("ReferenceType");
}
visit_collection ("for_lifetimes", e.get_for_lifetimes ());
- put_field ("function_qualifiers", e.get_function_qualifiers ().as_string ());
+ put_field ("function_qualifiers", e.get_function_qualifiers ().to_string ());
if (e.get_function_params ().empty ())
{
return std::unique_ptr<TypeParamBound> (clone_type_param_bound_impl ());
}
- virtual std::string as_string () const = 0;
+ virtual std::string to_string () const = 0;
virtual Analysis::NodeMapping get_mappings () const = 0;
{}
// Returns true if the lifetime is in an error state.
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
}
// TODO: make pure virtual if move out outer attributes to derived classes
- virtual std::string as_string () const;
+ virtual std::string to_string () const;
+
+ std::string to_debug_string () const
+ {
+ return to_string () + mappings.as_string ();
+ }
virtual ~Expr () {}
}
std::string
-OffsetOf::as_string () const
+OffsetOf::to_string () const
{
- return "OffsetOf(" + type->as_string () + ", " + field.as_string () + ")";
+ return "OffsetOf(" + type->to_string () + ", " + field.as_string () + ")";
}
void
Analysis::NodeMapping mappings;
public:
- std::string as_string () const;
+ std::string to_string () const;
LoopLabel (Analysis::NodeMapping mapping, Lifetime loop_label,
location_t locus);
bool negative_number = false;
public:
- std::string as_string () const override
- {
- return "( " + literal.as_string () + " (" + get_mappings ().as_string ()
- + "))";
- }
+ std::string to_string () const override { return literal.as_string (); }
Literal::LitType get_lit_type () const { return literal.get_lit_type (); }
bool raw;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
BorrowExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> borrow_lvalue, Mutability mut, bool raw,
class DereferenceExpr : public OperatorExpr
{
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Constructor calls OperatorExpr's protected constructor
DereferenceExpr (Analysis::NodeMapping mappings,
class ErrorPropagationExpr : public OperatorExpr
{
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Constructor calls OperatorExpr's protected constructor
ErrorPropagationExpr (Analysis::NodeMapping mappings,
ExprType expr_type;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
ExprType get_expr_type () const { return expr_type; }
std::unique_ptr<Expr> right_expr;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
ExprType get_expr_type () const { return expr_type; }
std::unique_ptr<Expr> right_expr;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
ExprType get_expr_type () const { return expr_type; }
LazyBooleanExpr (LazyBooleanExpr &&other) = default;
LazyBooleanExpr &operator= (LazyBooleanExpr &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
ExprType get_expr_type () const { return expr_type; }
// Note: only certain type casts allowed, outlined in reference
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Constructor requires calling protected constructor of OperatorExpr
TypeCastExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> right_expr;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Call OperatorExpr constructor to initialise left_expr
AssignmentExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> right_expr;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
ExprType get_expr_type () const { return expr_type; }
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
GroupedExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> parenthesised_expr,
return std::unique_ptr<ArrayElems> (clone_array_elems_impl ());
}
- virtual std::string as_string () const = 0;
+ virtual std::string to_string () const = 0;
virtual void accept_vis (HIRFullVisitor &vis) = 0;
ArrayElemsValues (ArrayElemsValues &&other) = default;
ArrayElemsValues &operator= (ArrayElemsValues &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
ArrayElemsCopied (ArrayElemsCopied &&other) = default;
ArrayElemsCopied &operator= (ArrayElemsCopied &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns whether array expr has array elems or if it is just empty.
bool has_array_elems () const { return internal_elements != nullptr; }
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
ArrayIndexExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> array_expr,
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
TupleExpr (Analysis::NodeMapping mappings,
std::vector<std::unique_ptr<Expr>> tuple_elements,
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
TupleIndex get_tuple_index () const { return tuple_index; }
public:
PathInExpression &get_struct_name () { return struct_name; }
- std::string as_string () const override;
+ std::string to_string () const override;
ExprType get_expression_type () const override final
{
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Constructor has to call protected constructor of base class
StructExprStruct (Analysis::NodeMapping mappings,
// Returns whether StructBase is in error state
bool is_invalid () const { return base_struct == nullptr; }
- std::string as_string () const;
+ std::string to_string () const;
Expr &get_base () { return *base_struct; }
};
return std::unique_ptr<StructExprField> (clone_struct_expr_field_impl ());
}
- virtual std::string as_string () const = 0;
+ virtual std::string to_string () const = 0;
virtual void accept_vis (HIRFullVisitor &vis) = 0;
virtual void accept_vis (HIRExpressionVisitor &vis) = 0;
StructExprFieldIdentifier (Analysis::NodeMapping mapping,
Identifier field_identifier, location_t locus);
- std::string as_string () const override { return field_name.as_string (); }
+ std::string to_string () const override { return field_name.as_string (); }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
StructExprFieldWithVal &operator= (StructExprFieldWithVal &&other) = default;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
Expr &get_value () { return *value; }
};
std::unique_ptr<Expr> field_value,
location_t locus);
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
std::unique_ptr<Expr> field_value,
location_t locus);
- std::string as_string () const override;
+ std::string to_string () const override;
TupleIndex get_tuple_index () const { return index; };
// is set when type checking
int union_index = -1;
- std::string as_string () const override;
+ std::string to_string () const override;
bool has_struct_base () const { return struct_base.has_value (); }
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
CallExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> function_expr,
std::vector<std::unique_ptr<Expr>> function_params,
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
MethodCallExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> call_receiver,
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
FieldAccessExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> field_access_receiver,
ClosureParam (ClosureParam &&other) = default;
ClosureParam &operator= (ClosureParam &&other) = default;
- std::string as_string () const;
+ std::string to_string () const;
const std::vector<AST::Attribute> &get_outer_attrs () const
{
ClosureExpr (ClosureExpr &&other) = default;
ClosureExpr &operator= (ClosureExpr &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
location_t get_locus () const override final { return locus; }
location_t start_locus;
location_t end_locus;
- std::string as_string () const override;
+ std::string to_string () const override;
AST::AttrVec get_inner_attrs () const { return inner_attrs; }
AnonConst (const AnonConst &other);
AnonConst operator= (const AnonConst &other);
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExpressionVisitor &vis) override;
- std::string as_string () const override;
+ std::string to_string () const override;
ExprType get_expression_type () const final override
{
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns true if the continue expr has a label.
bool has_label () const { return label.has_value (); }
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns whether the break expression has a label or not.
bool has_label () const { return label.has_value (); }
std::unique_ptr<Expr> to;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
RangeFromToExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> range_from,
std::unique_ptr<Expr> from;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
RangeFromExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> range_from, location_t locus);
std::unique_ptr<Expr> to;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// outer attributes not allowed
RangeToExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> range_to,
class RangeFullExpr : public RangeExpr
{
public:
- std::string as_string () const override;
+ std::string to_string () const override;
RangeFullExpr (Analysis::NodeMapping mappings, location_t locus);
// outer attributes not allowed
std::unique_ptr<Expr> to;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
RangeFromToInclExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> range_from,
std::unique_ptr<Expr> to;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
RangeToInclExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> range_to, location_t locus);
location_t locus;
- std::string as_string () const override;
+ std::string to_string () const override;
/* Returns whether the object has an expression returned (i.e. not void return
* type). */
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
UnsafeBlockExpr (Analysis::NodeMapping mappings,
std::unique_ptr<BlockExpr> block_expr,
class LoopExpr : public BaseLoopExpr
{
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Constructor for LoopExpr
LoopExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> condition;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Constructor for while loop with loop label
WhileLoopExpr (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> condition;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Constructor with a loop label
WhileLetLoopExpr (Analysis::NodeMapping mappings,
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
IfExpr (Analysis::NodeMapping mappings, std::unique_ptr<Expr> condition,
std::unique_ptr<BlockExpr> if_block, location_t locus);
std::unique_ptr<ExprWithBlock> else_block;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
IfExprConseqElse (Analysis::NodeMapping mappings,
std::unique_ptr<Expr> condition,
return MatchArm (std::vector<std::unique_ptr<Pattern>> (), locus);
}
- std::string as_string () const;
+ std::string to_string () const;
std::vector<std::unique_ptr<Pattern>> &get_patterns ()
{
~MatchCase () = default;
- std::string as_string () const;
+ std::string to_string () const;
+ std::string to_debug_string () const;
Analysis::NodeMapping get_mappings () const { return mappings; }
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
bool has_match_arms () const { return !match_arms.empty (); }
AwaitExpr (AwaitExpr &&other) = default;
AwaitExpr &operator= (AwaitExpr &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
location_t get_locus () const override final { return locus; }
AsyncBlockExpr (AsyncBlockExpr &&other) = default;
AsyncBlockExpr &operator= (AsyncBlockExpr &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
location_t get_locus () const override final { return locus; }
void accept_vis (HIRFullVisitor &vis) override;
- std::string as_string () const override { return "InlineAsm HIR Node"; }
+ std::string to_string () const override { return "InlineAsm HIR Node"; }
location_t get_locus () const override { return locus; }
OffsetOf &operator= (const OffsetOf &other);
ExprWithoutBlock *clone_expr_without_block_impl () const override;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRExpressionVisitor &vis) override;
void accept_vis (HIRFullVisitor &vis) override;
return *this;
}
+std::string
+LifetimeParam::to_debug_string () const
+{
+ std::string result = "LifetimeParam";
+ result += "\nOuter attributes: ";
+ if (outer_attrs.empty ())
+ {
+ result += "\nnone";
+ }
+ else
+ {
+ for (const auto &attr : outer_attrs)
+ {
+ result += "\n" + attr.as_string ();
+ }
+ }
+ result += lifetime.to_string ();
+ if (!lifetime_bounds.empty ())
+ {
+ result += ": ";
+ for (size_t i = 0; i < lifetime_bounds.size (); ++i)
+ {
+ if (i > 0)
+ result += " + ";
+ result += lifetime_bounds[i].to_string ();
+ }
+ }
+ return result;
+}
+
+std::string
+LifetimeParam::to_string () const
+{
+ std::string result;
+ if (!outer_attrs.empty ())
+ {
+ for (const auto &attr : outer_attrs)
+ {
+ result += attr.as_string () + "\n";
+ }
+ }
+ result += lifetime.to_string ();
+ if (!lifetime_bounds.empty ())
+ {
+ result += ": ";
+ for (size_t i = 0; i < lifetime_bounds.size (); ++i)
+ {
+ if (i > 0)
+ result += " + ";
+ result += lifetime_bounds[i].to_string ();
+ }
+ }
+ return result;
+}
+
ConstGenericParam::ConstGenericParam (std::string name,
std::unique_ptr<Type> type,
std::unique_ptr<Expr> default_expression,
}
std::string
-ConstGenericParam::as_string () const
+ConstGenericParam::to_debug_string () const
+{
+ std::string result = "ConstGenericParam:\n";
+ result += "Outer attributes: ";
+ if (outer_attrs.empty ())
+ {
+ result += "\nnone";
+ }
+ else
+ {
+ for (const auto &attr : outer_attrs)
+ {
+ result += "\n" + attr.as_string ();
+ }
+ }
+ result += "\nconst " + name + ": " + type->to_string ();
+
+ if (default_expression)
+ result += " = " + default_expression->to_string ();
+
+ return result;
+}
+
+std::string
+ConstGenericParam::to_string () const
{
- auto result = "ConstGenericParam: " + name + " : " + type->as_string ();
+ std::string result;
+ if (!outer_attrs.empty ())
+ for (const auto &attr : outer_attrs)
+ result += attr.as_string () + "\n";
+ result = "const " + name + ": " + type->to_string ();
if (default_expression)
- result += " = " + default_expression->as_string ();
+ result += " = " + default_expression->to_string ();
return result;
}
return std::unique_ptr<GenericParam> (clone_generic_param_impl ());
}
- virtual std::string as_string () const = 0;
+ virtual std::string to_debug_string () const = 0;
+
+ virtual std::string to_string () const = 0;
virtual location_t get_locus () const = 0;
LifetimeParam (LifetimeParam &&other) = default;
LifetimeParam &operator= (LifetimeParam &&other) = default;
- std::string as_string () const override;
+ std::string to_debug_string () const override;
+
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
AST::AttrVec &get_outer_attrs () override { return outer_attrs; }
- std::string as_string () const override final;
+ std::string to_debug_string () const override final;
+
+ std::string to_string () const override final;
void accept_vis (HIRFullVisitor &vis) override final;
BaseKind get_hir_kind () override { return Node::BaseKind::ITEM; }
- std::string as_string () const override;
+ std::string to_string () const override;
/* Adds crate names to the vector passed by reference, if it can
* (polymorphism). */
TypeParam &operator= (TypeParam &&other) = default;
- std::string as_string () const override;
+ std::string to_debug_string () const override;
+
+ std::string to_string () const override;
location_t get_locus () const override final { return locus; }
return std::unique_ptr<WhereClauseItem> (clone_where_clause_item_impl ());
}
- virtual std::string as_string () const = 0;
+ virtual std::string to_string () const = 0;
virtual void accept_vis (HIRFullVisitor &vis) = 0;
mappings (std::move (mappings))
{}
- std::string as_string () const override;
+ std::string to_string () const override;
location_t get_locus () const { return locus; }
location_t get_locus () const { return locus; }
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
// Returns whether the WhereClause has no items.
bool is_empty () const { return where_clause_items.empty (); }
- std::string as_string () const;
+ std::string to_string () const;
std::vector<std::unique_ptr<WhereClauseItem>> &get_items ()
{
Lifetime &get_lifetime () { return lifetime.value (); }
- std::string as_string () const;
+ std::string to_string () const;
location_t get_locus () const { return locus; }
unsafety (unsafety), has_extern (has_extern), abi (abi)
{}
- std::string as_string () const;
+ std::string to_string () const;
Const get_const_status () const { return const_status; }
FunctionParam (FunctionParam &&other) = default;
FunctionParam &operator= (FunctionParam &&other) = default;
- std::string as_string () const;
+ std::string to_string () const;
location_t get_locus () const { return locus; }
Visibility &get_visibility () { return visibility; }
const Visibility &get_visibility () const { return visibility; }
- std::string as_string () const override;
+ std::string to_string () const override;
};
// Rust module item - abstract base class
std::vector<std::unique_ptr<Item>> items;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns whether the module has items in its body.
bool has_items () const { return !items.empty (); }
"extern crate foo"
"extern crate std as cool_std" */
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns whether extern crate declaration has an as clause.
bool has_as_clause () const { return !as_clause_name.empty (); }
return std::unique_ptr<UseTree> (clone_use_tree_impl ());
}
- virtual std::string as_string () const = 0;
+ virtual std::string to_string () const = 0;
location_t get_locus () const { return locus; }
PathType get_glob_type () { return glob_type; }
AST::SimplePath get_path () { return path; };
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
// Returns whether has inner tree elements.
bool has_trees () const { return !trees.empty (); }
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
// Returns whether has identifier (or, rather, is allowed to).
bool has_identifier () const { return bind_type == IDENTIFIER; }
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
UseDeclaration (Analysis::NodeMapping mappings,
std::unique_ptr<UseTree> use_tree, Visibility visibility,
Defaultness defaultness;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns whether function has generic parameters.
bool has_generics () const { return !generic_params.empty (); }
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns whether type alias has generic parameters.
bool has_generics () const { return !generic_params.empty (); }
class Struct : public VisItem
{
protected:
- // protected to enable access by derived classes - allows better as_string
+ // protected to enable access by derived classes - allows better to_string
Identifier struct_name;
// bool has_generics;
StructField (StructField &&other) = default;
StructField &operator= (StructField &&other) = default;
- std::string as_string () const;
+ std::string to_string () const;
Identifier get_field_name () const { return field_name; }
std::vector<StructField> fields;
bool is_unit;
- std::string as_string () const override;
+ std::string to_string () const override;
// Mega-constructor with all possible fields
StructStruct (Analysis::NodeMapping mappings, std::vector<StructField> fields,
// Returns whether tuple field is in an error state.
bool is_error () const { return field_type == nullptr; }
- std::string as_string () const;
+ std::string to_string () const;
Analysis::NodeMapping get_mappings () const { return mappings; }
std::vector<TupleField> fields;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Mega-constructor with all possible fields
TupleStruct (Analysis::NodeMapping mappings, std::vector<TupleField> fields,
return std::unique_ptr<EnumItem> (clone_item_impl ());
}
- virtual std::string as_string () const override;
+ virtual std::string to_string () const override;
virtual EnumItemKind get_enum_item_kind () const { return Named; };
// not pure virtual as not abstract
std::vector<TupleField> tuple_fields, AST::AttrVec outer_attrs,
location_t locus);
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRStmtVisitor &vis) override;
std::vector<StructField> struct_fields,
AST::AttrVec outer_attrs, location_t locus);
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRStmtVisitor &vis) override;
return EnumItemKind::Discriminant;
}
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRStmtVisitor &vis) override;
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns whether "enum" has generic parameters.
bool has_generics () const { return !generic_params.empty (); }
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns whether union has generic params.
bool has_generics () const { return !generic_params.empty (); }
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
ConstantItem (Analysis::NodeMapping mappings, Identifier ident,
Visibility vis, std::unique_ptr<Type> type,
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
StaticItem (Analysis::NodeMapping mappings, Identifier name, Mutability mut,
std::unique_ptr<Type> type, std::unique_ptr<Expr> expr,
TraitFunctionDecl (TraitFunctionDecl &&other) = default;
TraitFunctionDecl &operator= (TraitFunctionDecl &&other) = default;
- std::string as_string () const;
+ std::string to_string () const;
// Returns whether function decl has generic parameters.
bool has_generics () const { return !generic_params.empty (); }
TraitItemFunc (TraitItemFunc &&other) = default;
TraitItemFunc &operator= (TraitItemFunc &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
location_t get_locus () const { return locus; }
TraitItemConst (TraitItemConst &&other) = default;
TraitItemConst &operator= (TraitItemConst &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
location_t get_locus () const { return locus; }
TraitItemType (TraitItemType &&other) = default;
TraitItemType &operator= (TraitItemType &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
location_t get_locus () const { return locus; }
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns whether trait has generic parameters.
bool has_generics () const { return !generic_params.empty (); }
ImplBlock (ImplBlock &&other) = default;
ImplBlock &operator= (ImplBlock &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns whether inherent impl block has inherent impl items.
bool has_impl_items () const { return !impl_items.empty (); }
return std::unique_ptr<ExternalItem> (clone_external_item_impl ());
}
- virtual std::string as_string () const;
+ virtual std::string to_string () const;
+
+ std::string to_debug_string () const
+ {
+ return to_string () + mappings.as_string ();
+ }
location_t get_locus () const { return locus; }
ExternalStaticItem (ExternalStaticItem &&other) = default;
ExternalStaticItem &operator= (ExternalStaticItem &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExternalItemVisitor &vis) override;
NamedFunctionParam (NamedFunctionParam &&other) = default;
NamedFunctionParam &operator= (NamedFunctionParam &&other) = default;
- std::string as_string () const;
+ std::string to_string () const;
Identifier get_param_name () const { return name; }
ExternalFunctionItem (ExternalFunctionItem &&other) = default;
ExternalFunctionItem &operator= (ExternalFunctionItem &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExternalItemVisitor &vis) override;
ExternalTypeItem &operator= (ExternalTypeItem &&other) = default;
ExternalTypeItem &operator= (ExternalTypeItem const &other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRExternalItemVisitor &vis) override;
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns whether extern block has extern items.
bool has_extern_items () const { return !extern_items.empty (); }
if (!is_single_segment ())
return false;
- return get_final_segment ().get_segment ().as_string ().compare ("self") == 0;
+ return get_final_segment ().get_segment ().to_string ().compare (
+ Rust::Values::Keywords::SELF)
+ == 0;
}
TypePathSegment::TypePathSegment (Analysis::NodeMapping mappings,
// Returns whether PathIdentSegment is in an error state.
bool is_error () const { return segment_name.empty (); }
- std::string as_string () const { return segment_name; }
+ std::string to_string () const { return segment_name; }
};
// A binding of an identifier to a type used in generic arguments in paths
GenericArgsBinding (GenericArgsBinding &&other) = default;
GenericArgsBinding &operator= (GenericArgsBinding &&other) = default;
- std::string as_string () const;
+ std::string to_string () const;
Identifier &get_identifier () { return identifier; }
const Identifier &get_identifier () const { return identifier; }
bool is_empty () const;
- std::string as_string () const;
+ std::string to_string () const;
std::vector<Lifetime> &get_lifetime_args () { return lifetime_args; }
const std::vector<Lifetime> &get_lifetime_args () const
PathExprSegment (PathExprSegment &&other) = default;
PathExprSegment &operator= (PathExprSegment &&other) = default;
- std::string as_string () const;
+ std::string to_string () const;
location_t get_locus () const { return locus; }
return segments.size () == 1;
}
- std::string as_string () const override;
+ std::string to_string () const override;
void iterate_path_segments (std::function<bool (PathExprSegment &)> cb);
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Constructor
PathInExpression (Analysis::NodeMapping mappings,
TypePathSegment (Analysis::NodeMapping mappings, std::string segment_name,
bool has_separating_scope_resolution, location_t locus);
- virtual std::string as_string () const
+ virtual std::string to_string () const
{
if (ident_segment)
- return ident_segment->as_string ();
+ return ident_segment->to_string ();
return LangItem::PrettyString (*lang_item);
}
std::vector<ConstGenericArg> const_args,
location_t locus);
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
TypePathFunction (TypePathFunction &&other) = default;
TypePathFunction &operator= (TypePathFunction &&other) = default;
- std::string as_string () const;
+ std::string to_string () const;
const std::vector<std::unique_ptr<Type> > &get_params () const
{
bool has_separating_scope_resolution,
TypePathFunction function_path, location_t locus);
- std::string as_string () const override;
+ std::string to_string () const override;
bool is_ident_only () const override { return false; }
TypePath (TypePath &&other) = default;
TypePath &operator= (TypePath &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
/* Converts TypePath to SimplePath if possible (i.e. no generic or function
* arguments). Otherwise returns an empty SimplePath. */
// Returns whether the qualified path type has a rebind as clause.
bool has_as_clause () const { return trait != nullptr; }
- std::string as_string () const;
+ std::string to_string () const;
location_t get_locus () const { return locus; }
location_t locus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
QualifiedPathInExpression (Analysis::NodeMapping mappings,
QualifiedPathType qual_path_type,
QualifiedPathInType (QualifiedPathInType &&other) = default;
QualifiedPathInType &operator= (QualifiedPathInType &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
virtual ~Pattern () {}
- virtual std::string as_string () const = 0;
+ virtual std::string to_string () const = 0;
+
+ std::string to_debug_string () const
+ {
+ return to_string () + get_mappings ().as_string ();
+ }
virtual void accept_vis (HIRPatternVisitor &vis) = 0;
bool has_minus;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Constructor for a literal pattern
LiteralPattern (Analysis::NodeMapping mappings, Literal lit, location_t locus)
Analysis::NodeMapping mappings;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns whether the IdentifierPattern has a pattern to bind.
bool has_subpattern () const { return subpattern != nullptr; }
Analysis::NodeMapping mappings;
public:
- std::string as_string () const override { return std::string (1, '_'); }
+ std::string to_string () const override { return "_"; }
WildcardPattern (Analysis::NodeMapping mappings, location_t locus)
: locus (locus), mappings (mappings)
clone_range_pattern_bound_impl ());
}
- virtual std::string as_string () const = 0;
+ virtual std::string to_string () const = 0;
virtual void accept_vis (HIRFullVisitor &vis) = 0;
: literal (literal), has_minus (has_minus), locus (locus)
{}
- std::string as_string () const override;
+ std::string to_string () const override;
location_t get_locus () const { return locus; }
public:
RangePatternBoundPath (PathInExpression path) : path (std::move (path)) {}
- std::string as_string () const override { return path.as_string (); }
+ std::string to_string () const override { return path.to_string (); }
location_t get_locus () const { return path.get_locus (); }
: path (std::move (path))
{}
- std::string as_string () const override { return path.as_string (); }
+ std::string to_string () const override { return path.to_string (); }
location_t get_locus () const { return path.get_locus (); }
Analysis::NodeMapping mappings;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Constructor
RangePattern (Analysis::NodeMapping mappings,
Analysis::NodeMapping mappings;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
ReferencePattern (Analysis::NodeMapping mappings,
std::unique_ptr<Pattern> pattern, Mutability reference_mut,
clone_struct_pattern_field_impl ());
}
- virtual std::string as_string () const;
+ virtual std::string to_string () const;
virtual void accept_vis (HIRFullVisitor &vis) = 0;
virtual ItemType get_item_type () const = 0;
StructPatternFieldTuplePat &operator= (StructPatternFieldTuplePat &&other)
= default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
StructPatternFieldIdentPat &operator= (StructPatternFieldIdentPat &&other)
= default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
has_ref (is_ref), mut (mut), ident (std::move (ident))
{}
- std::string as_string () const override;
+ std::string to_string () const override;
bool is_mut () const { return mut == Mutability::Mut; }
std::vector<std::unique_ptr<StructPatternField>> ());
}
- std::string as_string () const;
+ std::string to_string () const;
std::vector<std::unique_ptr<StructPatternField>> &get_struct_pattern_fields ()
{
Analysis::NodeMapping mappings;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
StructPattern (Analysis::NodeMapping mappings, PathInExpression struct_path,
StructPatternElements elems)
virtual ItemType get_item_type () const = 0;
- virtual std::string as_string () const = 0;
+ virtual std::string to_string () const = 0;
protected:
// pure virtual clone implementation
TupleStructItemsNoRest (TupleStructItemsNoRest &&other) = default;
TupleStructItemsNoRest &operator= (TupleStructItemsNoRest &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
TupleStructItemsHasRest &operator= (TupleStructItemsHasRest &&other)
= default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
* data */
public:
- std::string as_string () const override;
+ std::string to_string () const override;
TupleStructPattern (Analysis::NodeMapping mappings,
PathInExpression tuple_struct_path,
TuplePatternItemsNoRest &operator= (TuplePatternItemsNoRest &&other)
= default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
TuplePatternItemsHasRest &operator= (TuplePatternItemsHasRest &&other)
= default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
Analysis::NodeMapping mappings;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
// Returns true if the tuple pattern has items
bool has_tuple_pattern_items () const { return items != nullptr; }
SlicePatternItemsNoRest &operator= (SlicePatternItemsNoRest &&other)
= default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
SlicePatternItemsHasRest &operator= (SlicePatternItemsHasRest &&other)
= default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
Analysis::NodeMapping mappings;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
SlicePattern (Analysis::NodeMapping mappings,
std::unique_ptr<SlicePatternItems> items, location_t locus)
Analysis::NodeMapping mappings;
public:
- std::string as_string () const override;
+ std::string to_string () const override;
AltPattern (Analysis::NodeMapping mappings,
std::vector<std::unique_ptr<Pattern>> alts, location_t locus)
virtual ~Stmt () {}
- virtual std::string as_string () const = 0;
+ virtual std::string to_string () const = 0;
+
+ std::string to_debug_string () const
+ {
+ return to_string () + mappings.as_string ();
+ }
virtual void accept_vis (HIRStmtVisitor &vis) = 0;
location_t locus;
public:
- std::string as_string () const override { return std::string (1, ';'); }
+ std::string to_string () const override { return ";"; }
EmptyStmt (Analysis::NodeMapping mappings, location_t locus)
: Stmt (std::move (mappings)), locus (locus)
// Returns whether let statement has a diverging else expression.
bool has_else_expr () const { return else_expr.has_value (); }
- std::string as_string () const override;
+ std::string to_string () const override;
LetStmt (Analysis::NodeMapping mappings,
std::unique_ptr<Pattern> variables_pattern,
ExprStmt (Analysis::NodeMapping mappings, std::unique_ptr<Expr> expr,
location_t locus);
- std::string as_string () const override;
+ std::string to_string () const override;
location_t get_locus () const override final { return locus; }
type_path (std::move (type_path)), locus (locus), mappings (mapping)
{}
- std::string as_string () const override;
+ std::string to_string () const override;
+
+ std::string to_debug_string () const;
location_t get_locus () const override final { return locus; }
BaseKind get_hir_kind () override final { return TYPE; }
- virtual std::string as_string () const = 0;
+ virtual std::string to_string () const = 0;
+
+ std::string to_debug_string () const
+ {
+ return to_string () + mappings.as_string ();
+ }
/* HACK: convert to trait bound. Virtual method overriden by classes that
* enable this. */
ImplTraitType (ImplTraitType &&other) = default;
ImplTraitType &operator= (ImplTraitType &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ()
{
return type_param_bounds;
TraitObjectType (TraitObjectType &&other) = default;
TraitObjectType &operator= (TraitObjectType &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
bool get_has_dyn () { return has_dyn; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
ParenthesisedType (ParenthesisedType &&other) = default;
ParenthesisedType &operator= (ParenthesisedType &&other) = default;
- std::string as_string () const override
+ std::string to_string () const override
{
- return "(" + type_in_parens->as_string () + ")";
+ return "(" + type_in_parens->to_string () + ")";
}
// Creates a trait bound (clone of this one's trait bound) - HACK
TupleType (TupleType &&other) = default;
TupleType &operator= (TupleType &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
public:
NeverType (Analysis::NodeMapping mappings, location_t locus);
- std::string as_string () const override { return "! (never type)"; }
+ std::string to_string () const override { return "! (never type)"; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
RawPointerType (RawPointerType &&other) = default;
RawPointerType &operator= (RawPointerType &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
ReferenceType (ReferenceType &&other) = default;
ReferenceType &operator= (ReferenceType &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
ArrayType (ArrayType &&other) = default;
ArrayType &operator= (ArrayType &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
SliceType (SliceType &&other) = default;
SliceType &operator= (SliceType &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
public:
InferredType (Analysis::NodeMapping mappings, location_t locus);
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
MaybeNamedParam (MaybeNamedParam &&other) = default;
MaybeNamedParam &operator= (MaybeNamedParam &&other) = default;
- std::string as_string () const;
+ std::string to_string () const;
// Returns whether the param is in an error state.
bool is_error () const { return param_type == nullptr; }
BareFunctionType (BareFunctionType &&other) = default;
BareFunctionType &operator= (BareFunctionType &&other) = default;
- std::string as_string () const override;
+ std::string to_string () const override;
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRTypeVisitor &vis) override;
return path;
}
- std::string as_string () const;
+ std::string to_string () const;
location_t get_locus () const { return locus; }
};
}
std::string
-Crate::as_string () const
+Crate::to_debug_string () const
{
std::string str ("HIR::Crate: ");
return "nullptr_POINTER_MARK";
}
- str += "\n " + item->as_string ();
+ str += "\n " + item->to_string ();
}
}
- return str + "\n::" + get_mappings ().as_string () + "\n";
+ return str;
+}
+
+std::string
+Crate::to_string () const
+{
+ std::string str;
+ if (!inner_attrs.empty ())
+ for (const auto &attr : inner_attrs)
+ str += attr.as_string () + "\n";
+
+ if (!items.empty ())
+ for (const auto &item : items)
+ str += item->to_string () + "\n";
+
+ return str;
}
std::string
-Visibility::as_string () const
+Visibility::to_string () const
{
switch (vis_type)
{
// Creates a string that reflects the visibility stored.
std::string
-VisItem::as_string () const
+VisItem::to_string () const
{
// FIXME: can't do formatting on string to make identation occur.
- std::string str = Item::as_string ();
+ std::string str = Item::to_string ();
if (has_visibility ())
{
- str = visibility.as_string () + " ";
+ str = visibility.to_string () + " ";
}
return str;
// Creates a string that reflects the outer attributes stored.
std::string
-Item::as_string () const
+Item::to_string () const
{
std::string str;
}
std::string
-Module::as_string () const
+Module::to_string () const
{
// get module string for "[vis] mod [name]"
- std::string str = VisItem::as_string () + "mod " + module_name.as_string ();
+ std::string str = VisItem::to_string () + "mod " + module_name.as_string ();
// inner attributes
str += "\n inner attributes: ";
return "nullptr_POINTER_MARK";
}
- str += "\n " + item->as_string ();
+ str += "\n " + item->to_string ();
}
}
}
std::string
-StaticItem::as_string () const
+StaticItem::to_string () const
{
- std::string str = VisItem::as_string ();
+ std::string str = VisItem::to_string ();
str += indent_spaces (stay) + "static";
"pointer type in static item.");
return "nullptr_POINTER_MARK";
}
- str += "\n" + indent_spaces (stay) + "Type: " + type->as_string ();
+ str += "\n" + indent_spaces (stay) + "Type: " + type->to_string ();
// DEBUG: null pointer check
if (expr == nullptr)
"pointer expr in static item.");
return "nullptr_POINTER_MARK";
}
- str += "\n" + indent_spaces (stay) + "Expression: " + expr->as_string ();
+ str += "\n" + indent_spaces (stay) + "Expression: " + expr->to_string ();
return str + "\n";
}
std::string
-ExternCrate::as_string () const
+ExternCrate::to_string () const
{
- std::string str = VisItem::as_string ();
+ std::string str = VisItem::to_string ();
str += "extern crate " + referenced_crate;
}
std::string
-TupleStruct::as_string () const
+TupleStruct::to_string () const
{
- std::string str = VisItem::as_string ();
+ std::string str = VisItem::to_string ();
str += "struct " + struct_name.as_string ();
return "nullptr_POINTER_MARK";
}
- str += "\n " + param->as_string ();
+ str += "\n " + param->to_string ();
}
}
{
for (const auto &field : fields)
{
- str += "\n " + field.as_string ();
+ str += "\n " + field.to_string ();
}
}
str += "\n Where clause: ";
if (has_where_clause ())
{
- str += where_clause.as_string ();
+ str += where_clause.to_string ();
}
else
{
}
std::string
-ConstantItem::as_string () const
+ConstantItem::to_string () const
{
- std::string str = VisItem::as_string ();
+ std::string str = VisItem::to_string ();
str += "const " + identifier.as_string ();
"pointer type in const item.");
return "nullptr_POINTER_MARK";
}
- str += "\n Type: " + type->as_string ();
+ str += "\n Type: " + type->to_string ();
// DEBUG: null pointer check
if (const_expr == nullptr)
"pointer expr in const item.");
return "nullptr_POINTER_MARK";
}
- str += "\n Expression: " + const_expr->as_string ();
+ str += "\n Expression: " + const_expr->to_string ();
return str + "\n";
}
std::string
-ImplBlock::as_string () const
+ImplBlock::to_string () const
{
- std::string str = VisItem::as_string ();
+ std::string str = VisItem::to_string ();
str += "impl ";
return "nullptr_POINTER_MARK";
}
- str += "\n " + param->as_string ();
+ str += "\n " + param->to_string ();
}
}
- str += "\n Type: " + impl_type->as_string ();
+ str += "\n Type: " + impl_type->to_string ();
str += "\n Where clause: ";
if (has_where_clause ())
{
- str += where_clause.as_string ();
+ str += where_clause.to_string ();
}
else
{
{
for (const auto &item : impl_items)
{
- str += "\n " + item->as_string ();
+ str += "\n " + item->to_string ();
}
}
}
std::string
-StructStruct::as_string () const
+StructStruct::to_string () const
{
- std::string str = VisItem::as_string ();
+ std::string str = VisItem::to_string ();
str += "struct " + struct_name.as_string ();
return "nullptr_POINTER_MARK";
}
- str += "\n " + param->as_string ();
+ str += "\n " + param->to_string ();
}
}
str += "\n Where clause: ";
if (has_where_clause ())
{
- str += where_clause.as_string ();
+ str += where_clause.to_string ();
}
else
{
{
for (const auto &field : fields)
{
- str += "\n - " + field.as_string ();
+ str += "\n - " + field.to_string ();
}
str += "\n";
}
- return str + "::" + get_mappings ().as_string () + "\n";
+ return str;
}
std::string
-UseDeclaration::as_string () const
+UseDeclaration::to_string () const
{
- std::string str = VisItem::as_string ();
+ std::string str = VisItem::to_string ();
// DEBUG: null pointer check
if (use_tree == nullptr)
return "nullptr_POINTER_MARK";
}
- str += "use " + use_tree->as_string ();
+ str += "use " + use_tree->to_string ();
return str;
}
std::string
-UseTreeGlob::as_string () const
+UseTreeGlob::to_string () const
{
switch (glob_type)
{
}
std::string
-UseTreeList::as_string () const
+UseTreeList::to_string () const
{
std::string path_str;
switch (path_type)
for (; i != e; i++)
{
- path_str += (*i)->as_string ();
+ path_str += (*i)->to_string ();
if (e != i + 1)
path_str += ", ";
}
}
std::string
-UseTreeRebind::as_string () const
+UseTreeRebind::to_string () const
{
std::string path_str = path.as_string ();
}
std::string
-Enum::as_string () const
+Enum::to_string () const
{
- std::string str = VisItem::as_string ();
+ std::string str = VisItem::to_string ();
str += enum_name.as_string ();
// generic params
return "nullptr_POINTER_MARK";
}
- str += "\n " + param->as_string ();
+ str += "\n " + param->to_string ();
}
}
str += "\n Where clause: ";
if (has_where_clause ())
{
- str += where_clause.as_string ();
+ str += where_clause.to_string ();
}
else
{
return "nullptr_POINTER_MARK";
}
- str += "\n " + item->as_string ();
+ str += "\n " + item->to_string ();
}
}
}
std::string
-Trait::as_string () const
+Trait::to_string () const
{
- std::string str = VisItem::as_string ();
+ std::string str = VisItem::to_string ();
if (unsafety == Unsafety::Unsafe)
{
return "nullptr_POINTER_MARK";
}
- str += "\n " + param->as_string ();
+ str += "\n " + param->to_string ();
}
}
return "nullptr_POINTER_MARK";
}
- str += "\n " + bound->as_string ();
+ str += "\n " + bound->to_string ();
}
}
}
else
{
- str += where_clause.as_string ();
+ str += where_clause.to_string ();
}
str += "\n Trait items: ";
return "nullptr_POINTER_MARK";
}
- str += "\n " + item->as_string ();
+ str += "\n " + item->to_string ();
}
}
}
std::string
-Union::as_string () const
+Union::to_string () const
{
- std::string str = VisItem::as_string ();
+ std::string str = VisItem::to_string ();
str += "union " + union_name.as_string ();
return "nullptr_POINTER_MARK";
}
- str += "\n " + param->as_string ();
+ str += "\n " + param->to_string ();
}
}
str += "\n Where clause: ";
if (has_where_clause ())
{
- str += where_clause.as_string ();
+ str += where_clause.to_string ();
}
else
{
{
for (const auto &field : variants)
{
- str += "\n " + field.as_string ();
+ str += "\n " + field.to_string ();
}
}
}
std::string
-Function::as_string () const
+Function::to_string () const
{
- std::string str = VisItem::as_string () + "\n";
- std::string qstr = qualifiers.as_string ();
+ std::string str = VisItem::to_string () + "\n";
+ std::string qstr = qualifiers.to_string ();
if ("" != qstr)
str += qstr + " ";
return "nullptr_POINTER_MARK";
}
- str += return_type->as_string () + " ";
+ str += return_type->to_string () + " ";
}
else
{
for (; i != e; i++)
{
- str += (*i)->as_string ();
+ str += (*i)->to_string ();
if (e != i + 1)
str += ", ";
}
str += "(";
for (; i != e; i++)
{
- str += (*i).as_string ();
+ str += (*i).to_string ();
if (e != i + 1)
str += ", ";
}
if (has_where_clause ())
{
- str += " where " + where_clause.as_string ();
+ str += " where " + where_clause.to_string ();
}
str += "\n";
"body in function.");
return "nullptr_POINTER_MARK";
}
- return str + function_body->as_string () + "::" + get_mappings ().as_string ()
- + "\n";
+ return str + function_body->to_string ();
}
std::string
-WhereClause::as_string () const
+WhereClause::to_string () const
{
// just print where clause items, don't mention "where" or "where clause"
std::string str;
{
for (const auto &item : where_clause_items)
{
- str += "\n " + item->as_string ();
+ str += "\n " + item->to_string ();
}
}
}
std::string
-BlockExpr::as_string () const
+BlockExpr::to_string () const
{
std::string istr = indent_spaces (enter);
std::string str = istr + "BlockExpr:\n" + istr;
// get outer attributes
- str += "{\n" + indent_spaces (stay) + Expr::as_string ();
+ str += "{\n" + indent_spaces (stay) + Expr::to_string ();
// inner attributes
str += "\n" + indent_spaces (stay) + "inner attributes: ";
return "nullptr_POINTER_MARK";
}
- str += "\n" + indent_spaces (stay) + stmt->as_string ();
+ str += "\n" + indent_spaces (stay) + stmt->to_string ();
}
}
}
else
{
- str += "\n" + expr->as_string ();
+ str += "\n" + expr->to_string ();
}
str += "\n" + indent_spaces (out) + "}";
}
std::string
-AnonConst::as_string () const
+AnonConst::to_string () const
{
std::string istr = indent_spaces (enter);
std::string str = istr + "AnonConst:\n" + istr;
if (expr.has_value ())
- str += get_inner_expr ().as_string ();
+ str += get_inner_expr ().to_string ();
else
str += "_";
}
std::string
-ConstBlock::as_string () const
+ConstBlock::to_string () const
{
std::string istr = indent_spaces (enter);
std::string str = istr + "ConstBlock:\n" + istr;
- str += get_const_expr ().as_string ();
+ str += get_const_expr ().to_string ();
str += "\n" + indent_spaces (out);
}
std::string
-TypeAlias::as_string () const
+TypeAlias::to_string () const
{
- std::string str = VisItem::as_string ();
+ std::string str = VisItem::to_string ();
str += " " + new_type_name.as_string ();
for (; i != e; i++)
{
- str += (*i)->as_string ();
+ str += (*i)->to_string ();
if (e != i + 1)
str += ", ";
}
}
else
{
- str += where_clause.as_string ();
+ str += where_clause.to_string ();
}
- str += "\n Type: " + existing_type->as_string ();
+ str += "\n Type: " + existing_type->to_string ();
return str;
}
std::string
-ExternBlock::as_string () const
+ExternBlock::to_string () const
{
- std::string str = VisItem::as_string ();
+ std::string str = VisItem::to_string ();
str += "extern ";
str += "\"" + get_string_from_abi (abi) + "\" ";
{
for (const auto &item : extern_items)
{
- str += "\n " + item->as_string ();
+ str += "\n " + item->to_string ();
}
}
}
std::string
-PathInExpression::as_string () const
+PathInExpression::to_string () const
{
std::string str;
str = "::";
}
- return str + PathPattern::as_string () + "::" + get_mappings ().as_string ();
+ return str + PathPattern::to_string ();
}
std::string
-ExprStmt::as_string () const
+ExprStmt::to_string () const
{
std::string str = indent_spaces (enter) + "ExprStmt:\n";
else
{
indent_spaces (enter);
- str += expr->as_string ();
+ str += expr->to_string ();
indent_spaces (out);
}
}
std::string
-ClosureParam::as_string () const
+ClosureParam::to_string () const
{
- std::string str (pattern->as_string ());
+ std::string str (pattern->to_string ());
if (has_type_given ())
{
- str += " : " + type->as_string ();
+ str += " : " + type->to_string ();
}
return str;
}
std::string
-ClosureExpr::as_string () const
+ClosureExpr::to_string () const
{
std::string str ("ClosureExpr:\n Has move: ");
if (has_move)
{
for (const auto ¶m : params)
{
- str += "\n " + param.as_string ();
+ str += "\n " + param.to_string ();
}
}
str += "\n Return type: "
- + (has_return_type () ? return_type->as_string () : "none");
+ + (has_return_type () ? return_type->to_string () : "none");
- str += "\n Body: " + expr->as_string ();
+ str += "\n Body: " + expr->to_string ();
return str;
}
std::string
-PathPattern::as_string () const
+PathPattern::to_string () const
{
if (is_lang_item ())
return LangItem::PrettyString (*lang_item);
for (const auto &segment : segments)
{
- str += segment.as_string () + "::";
+ str += segment.to_string () + "::";
}
// basically a hack - remove last two characters of string (remove final ::)
}
std::string
-QualifiedPathType::as_string () const
+QualifiedPathType::to_string () const
{
std::string str ("<");
- str += type->as_string ();
+ str += type->to_string ();
if (has_as_clause ())
{
- str += " as " + trait->as_string ();
+ str += " as " + trait->to_string ();
}
return str + ">";
}
std::string
-QualifiedPathInExpression::as_string () const
+QualifiedPathInExpression::to_string () const
{
- return path_type.as_string () + "::" + PathPattern::as_string ();
+ return path_type.to_string () + "::" + PathPattern::to_string ();
}
std::string
-BorrowExpr::as_string () const
+BorrowExpr::to_string () const
{
std::string str ("&");
str += "mut ";
}
- str += main_or_left_expr->as_string ();
+ str += main_or_left_expr->to_string ();
return str;
}
std::string
-ReturnExpr::as_string () const
+ReturnExpr::to_string () const
{
std::string str ("return ");
if (has_return_expr ())
{
- str += return_expr->as_string ();
+ str += return_expr->to_string ();
}
- return str + "::" + get_mappings ().as_string ();
+ return str;
}
std::string
-GroupedExpr::as_string () const
+GroupedExpr::to_string () const
{
std::string str ("Grouped expr:");
}
}
- str += "\n Expr in parens: " + expr_in_parens->as_string ();
+ str += "\n Expr in parens: " + expr_in_parens->to_string ();
return str;
}
std::string
-RangeToExpr::as_string () const
+RangeToExpr::to_string () const
{
- return ".." + to->as_string ();
+ return ".." + to->to_string ();
}
std::string
-ContinueExpr::as_string () const
+ContinueExpr::to_string () const
{
std::string str ("continue ");
if (has_label ())
{
- str += get_label ().as_string ();
+ str += get_label ().to_string ();
}
return str;
}
std::string
-NegationExpr::as_string () const
+NegationExpr::to_string () const
{
std::string str;
return "ERROR_MARK_STRING - negation expr";
}
- str += main_or_left_expr->as_string ();
+ str += main_or_left_expr->to_string ();
return str;
}
std::string
-RangeFromExpr::as_string () const
+RangeFromExpr::to_string () const
{
- return from->as_string () + "..";
+ return from->to_string () + "..";
}
std::string
-RangeFullExpr::as_string () const
+RangeFullExpr::to_string () const
{
return "..";
}
std::string
-ArrayIndexExpr::as_string () const
+ArrayIndexExpr::to_string () const
{
- return array_expr->as_string () + "[" + index_expr->as_string () + "]";
+ return array_expr->to_string () + "[" + index_expr->to_string () + "]";
}
std::string
-AssignmentExpr::as_string () const
+AssignmentExpr::to_string () const
{
- return main_or_left_expr->as_string () + " = " + right_expr->as_string ()
- + "::" + get_mappings ().as_string ();
+ return main_or_left_expr->to_string () + " = " + right_expr->to_string ();
}
std::string
}
std::string
-CompoundAssignmentExpr::as_string () const
+CompoundAssignmentExpr::to_string () const
{
std::string str ("CompoundAssignmentExpr: ");
std::string operator_str = get_operator_str ();
}
else
{
- str += "\n left: " + main_or_left_expr->as_string ();
- str += "\n right: " + right_expr->as_string ();
+ str += "\n left: " + main_or_left_expr->to_string ();
+ str += "\n right: " + right_expr->to_string ();
str += "\n operator: " + operator_str;
}
}
std::string
-AsyncBlockExpr::as_string () const
+AsyncBlockExpr::to_string () const
{
std::string str = "AsyncBlockExpr: ";
// get outer attributes
- str += "\n " + Expr::as_string ();
+ str += "\n " + Expr::to_string ();
str += "\n Has move: ";
str += has_move ? "true" : "false";
- return str + "\n" + block_expr->as_string ();
+ return str + "\n" + block_expr->to_string ();
}
std::string
-ComparisonExpr::as_string () const
+ComparisonExpr::to_string () const
{
- std::string str (main_or_left_expr->as_string ());
+ std::string str (main_or_left_expr->to_string ());
switch (expr_type)
{
return "ERROR_MARK_STRING - comparison expr";
}
- str += right_expr->as_string ();
+ str += right_expr->to_string ();
return str;
}
std::string
-MethodCallExpr::as_string () const
+MethodCallExpr::to_string () const
{
std::string str ("MethodCallExpr: \n Object (receiver) expr: ");
- str += receiver->as_string ();
+ str += receiver->to_string ();
str += "\n Method path segment: \n";
- str += method_name.as_string ();
+ str += method_name.to_string ();
str += "\n Call params:";
if (params.empty ())
return "ERROR_MARK_STRING - method call expr param is null";
}
- str += "\n " + param->as_string ();
+ str += "\n " + param->to_string ();
}
}
}
std::string
-TupleIndexExpr::as_string () const
+TupleIndexExpr::to_string () const
{
- return tuple_expr->as_string () + "." + std::to_string (tuple_index);
+ return tuple_expr->to_string () + "." + std::to_string (tuple_index);
}
std::string
-DereferenceExpr::as_string () const
+DereferenceExpr::to_string () const
{
- return "*" + main_or_left_expr->as_string ();
+ return "*" + main_or_left_expr->to_string ();
}
std::string
-FieldAccessExpr::as_string () const
+FieldAccessExpr::to_string () const
{
- return receiver->as_string () + "." + field.as_string ();
+ return receiver->to_string () + "." + field.as_string ();
}
std::string
-LazyBooleanExpr::as_string () const
+LazyBooleanExpr::to_string () const
{
- std::string str (main_or_left_expr->as_string ());
+ std::string str (main_or_left_expr->to_string ());
switch (expr_type)
{
return "ERROR_MARK_STRING - lazy boolean expr out of bounds";
}
- str += right_expr->as_string ();
+ str += right_expr->to_string ();
return str;
}
std::string
-RangeFromToExpr::as_string () const
+RangeFromToExpr::to_string () const
{
- return from->as_string () + ".." + to->as_string ();
+ return from->to_string () + ".." + to->to_string ();
}
std::string
-RangeToInclExpr::as_string () const
+RangeToInclExpr::to_string () const
{
- return "..=" + to->as_string ();
+ return "..=" + to->to_string ();
}
std::string
-UnsafeBlockExpr::as_string () const
+UnsafeBlockExpr::to_string () const
{
std::string istr = indent_spaces (enter);
std::string str = istr + "UnsafeBlockExpr:";
str += istr + "{";
// get outer attributes
- str += "\n" + indent_spaces (stay) + Expr::as_string ();
+ str += "\n" + indent_spaces (stay) + Expr::to_string ();
- return str + "\n" + indent_spaces (out) + "}\n" + expr->as_string ();
+ return str + "\n" + indent_spaces (out) + "}\n" + expr->to_string ();
}
std::string
-IfExpr::as_string () const
+IfExpr::to_string () const
{
std::string str ("IfExpr: ");
- str += "\n Condition expr: " + condition->as_string ();
+ str += "\n Condition expr: " + condition->to_string ();
- str += "\n If block expr: " + if_block->as_string ();
+ str += "\n If block expr: " + if_block->to_string ();
return str;
}
std::string
-IfExprConseqElse::as_string () const
+IfExprConseqElse::to_string () const
{
- std::string str = IfExpr::as_string ();
+ std::string str = IfExpr::to_string ();
- str += "\n Else expr: " + else_block->as_string ();
+ str += "\n Else expr: " + else_block->to_string ();
return str;
}
std::string
-RangeFromToInclExpr::as_string () const
+RangeFromToInclExpr::to_string () const
{
- return from->as_string () + "..=" + to->as_string ();
+ return from->to_string () + "..=" + to->to_string ();
}
std::string
-ErrorPropagationExpr::as_string () const
+ErrorPropagationExpr::to_string () const
{
- return main_or_left_expr->as_string () + "?";
+ return main_or_left_expr->to_string () + "?";
}
std::string
}
std::string
-ArithmeticOrLogicalExpr::as_string () const
+ArithmeticOrLogicalExpr::to_string () const
{
- std::string str = main_or_left_expr->as_string () + " ";
+ std::string str = main_or_left_expr->to_string () + " ";
str += get_operator_str () + " ";
- str += right_expr->as_string ();
+ str += right_expr->to_string ();
- return "( " + str + " (" + get_mappings ().as_string () + "))";
+ return "( " + str + " )";
}
std::string
-CallExpr::as_string () const
+CallExpr::to_string () const
{
- std::string str = function->as_string () + "(";
+ std::string str = function->to_string () + "(";
if (!has_params ())
str += "none";
else
return "ERROR_MARK_STRING - call expr param is null";
}
- str += param->as_string () + ",";
+ str += param->to_string () + ",";
}
}
- return str + ")" + "::" + get_mappings ().as_string ();
+ return str + ")";
}
std::string
-WhileLoopExpr::as_string () const
+WhileLoopExpr::to_string () const
{
std::string str ("WhileLoopExpr: ");
}
else
{
- str += get_loop_label ().as_string ();
+ str += get_loop_label ().to_string ();
}
- str += "\n Conditional expr: " + condition->as_string ();
+ str += "\n Conditional expr: " + condition->to_string ();
- str += "\n Loop block: " + loop_block->as_string ();
+ str += "\n Loop block: " + loop_block->to_string ();
return str;
}
std::string
-WhileLetLoopExpr::as_string () const
+WhileLetLoopExpr::to_string () const
{
std::string str ("WhileLetLoopExpr: ");
}
else
{
- str += get_loop_label ().as_string ();
+ str += get_loop_label ().to_string ();
}
str += "\n Match arm patterns: ";
{
for (const auto &pattern : match_arm_patterns)
{
- str += "\n " + pattern->as_string ();
+ str += "\n " + pattern->to_string ();
}
}
- str += "\n Scrutinee expr: " + condition->as_string ();
+ str += "\n Scrutinee expr: " + condition->to_string ();
- str += "\n Loop block: " + loop_block->as_string ();
+ str += "\n Loop block: " + loop_block->to_string ();
return str;
}
std::string
-LoopExpr::as_string () const
+LoopExpr::to_string () const
{
std::string str ("LoopExpr: (infinite loop)");
}
else
{
- str += get_loop_label ().as_string ();
+ str += get_loop_label ().to_string ();
}
- str += "\n Loop block: " + loop_block->as_string ();
+ str += "\n Loop block: " + loop_block->to_string ();
return str;
}
std::string
-ArrayExpr::as_string () const
+ArrayExpr::to_string () const
{
std::string str ("ArrayExpr:");
}
else
{
- str += internal_elements->as_string ();
+ str += internal_elements->to_string ();
}
return str;
}
std::string
-AwaitExpr::as_string () const
+AwaitExpr::to_string () const
{
- return awaited_expr->as_string () + ".await";
+ return awaited_expr->to_string () + ".await";
}
std::string
-BreakExpr::as_string () const
+BreakExpr::to_string () const
{
std::string str ("break ");
if (has_label ())
{
- str += get_label ().as_string () + " ";
+ str += get_label ().to_string () + " ";
}
if (has_break_expr ())
{
- str += break_expr->as_string ();
+ str += break_expr->to_string ();
}
return str;
}
std::string
-LoopLabel::as_string () const
+LoopLabel::to_string () const
{
- return label.as_string () + ": (label) ";
+ return label.to_string () + ": (label) ";
}
std::string
-MatchArm::as_string () const
+MatchArm::to_string () const
{
// outer attributes
std::string str = "Outer attributes: ";
{
for (const auto &pattern : match_arm_patterns)
{
- str += "\n " + pattern->as_string ();
+ str += "\n " + pattern->to_string ();
}
}
}
else
{
- str += guard_expr->as_string ();
+ str += guard_expr->to_string ();
}
return str;
}
std::string
-MatchCase::as_string () const
+MatchCase::to_debug_string () const
{
std::string str ("MatchCase: (match arm) ");
- str += "\n Match arm matcher: \n" + arm.as_string ();
- str += "\n Expr: " + expr->as_string ();
+ str += "\n Match arm matcher: \n" + arm.to_string ();
+ str += "\n Expr: " + expr->to_string ();
return str;
}
+std::string
+MatchCase::to_string () const
+{
+ std::string str = arm.to_string ();
+ str += " => ";
+ str += expr ? expr->to_string () : "null";
+ return str;
+}
+
/*std::string
-MatchCaseBlockExpr::as_string () const
+MatchCaseBlockExpr::to_string () const
{
- std::string str = MatchCase::as_string ();
+ std::string str = MatchCase::to_string ();
- str += "\n Block expr: " + block_expr->as_string ();
+ str += "\n Block expr: " + block_expr->to_string ();
return str;
}
std::string
-MatchCaseExpr::as_string () const
+MatchCaseExpr::to_string () const
{
- std::string str = MatchCase::as_string ();
+ std::string str = MatchCase::to_string ();
- str += "\n Expr: " + expr->as_string ();
+ str += "\n Expr: " + expr->to_string ();
return str;
}*/
std::string
-MatchExpr::as_string () const
+MatchExpr::to_string () const
{
std::string str ("MatchExpr:");
- str += "\n Scrutinee expr: " + branch_value->as_string ();
+ str += "\n Scrutinee expr: " + branch_value->to_string ();
// inner attributes
str += "\n inner attributes: ";
else
{
for (const auto &arm : match_arms)
- str += "\n " + arm.as_string ();
+ str += "\n " + arm.to_string ();
}
return str;
}
std::string
-TupleExpr::as_string () const
+TupleExpr::to_string () const
{
std::string str ("TupleExpr:");
{
for (const auto &elem : tuple_elems)
{
- str += "\n " + elem->as_string ();
+ str += "\n " + elem->to_string ();
}
}
}
std::string
-FunctionParam::as_string () const
+FunctionParam::to_string () const
{
- return param_name->as_string () + " : " + type->as_string ();
+ return param_name->to_string () + " : " + type->to_string ();
}
std::string
-FunctionQualifiers::as_string () const
+FunctionQualifiers::to_string () const
{
std::string str;
}
std::string
-TraitBound::as_string () const
+TraitBound::to_debug_string () const
{
std::string str ("TraitBound:");
{
for (const auto &lifetime : for_lifetimes)
{
- str += "\n " + lifetime.as_string ();
+ str += "\n " + lifetime.to_string ();
}
}
- str += "\n Type path: " + type_path.as_string ();
+ str += "\n Type path: " + type_path.to_string ();
return str;
}
std::string
-LifetimeParam::as_string () const
+TraitBound::to_string () const
{
- std::string str ("LifetimeParam: ");
-
- str += "\n Outer attributes: ";
- if (outer_attrs.empty ())
- {
- str += "none";
- }
- else
+ std::string str;
+ switch (polarity)
{
- /* note that this does not print them with "outer attribute" syntax -
- * just the body */
- for (const auto &attr : outer_attrs)
- {
- str += "\n " + attr.as_string ();
- }
+ case RegularBound:
+ break;
+ case NegativeBound:
+ str += "!";
+ break;
+ case AntiBound:
+ str += "?";
+ break;
}
- str += "\n Lifetime: " + lifetime.as_string ();
+ if (has_for_lifetimes ())
+ for (const auto &lifetime : for_lifetimes)
+ str += "\n " + lifetime.to_string ();
- str += "\n Lifetime bounds: ";
- if (!has_lifetime_bounds ())
- {
- str += "none";
- }
- else
- {
- for (const auto &bound : lifetime_bounds)
- {
- str += "\n " + bound.as_string ();
- }
- }
+ str += "\n" + type_path.to_string ();
return str;
}
std::string
-QualifiedPathInType::as_string () const
+QualifiedPathInType::to_string () const
{
- std::string str = path_type.as_string ();
+ std::string str = path_type.to_string ();
- str += "::" + associated_segment->as_string ();
+ str += "::" + associated_segment->to_string ();
for (const auto &segment : segments)
{
- str += "::" + segment->as_string ();
+ str += "::" + segment->to_string ();
}
return str;
}
std::string
-Lifetime::as_string () const
+Lifetime::to_string () const
{
switch (lifetime_type)
{
}
std::string
-TypePath::as_string () const
+TypePath::to_string () const
{
std::string str;
for (const auto &segment : segments)
{
- str += segment->as_string () + "::";
+ str += segment->to_string () + "::";
}
// kinda hack - remove last 2 '::' characters
}
std::string
-TypeParam::as_string () const
+TypeParam::to_debug_string () const
{
std::string str ("TypeParam: ");
str += "\n Outer attributes: ";
if (outer_attrs.empty ())
{
- str += "none";
+ str += "\nnone";
}
else
{
{
for (const auto &bound : type_param_bounds)
{
- str += "\n " + bound->as_string ();
+ str += "\n " + bound->to_string ();
}
}
}
else
{
- str += type.value ()->as_string ();
+ str += type.value ()->to_string ();
+ }
+
+ return str;
+}
+
+std::string
+TypeParam::to_string () const
+{
+ std::string str;
+ if (!outer_attrs.empty ())
+ {
+ for (const auto &attr : outer_attrs)
+ {
+ str += attr.as_string () + "\n";
+ }
+ }
+
+ str += type_representation.as_string ();
+
+ if (!has_type_param_bounds ())
+ {
+ str += ": ";
+ for (size_t i = 0; i < type_param_bounds.size (); ++i)
+ {
+ if (i > 0)
+ str += " + ";
+ str += type_param_bounds[i]->to_string ();
+ }
}
+ if (has_type ())
+ str += ": " + type.value ()->to_string ();
+
return str;
}
for (const auto &segment : segments)
{
// return empty path if doesn't meet simple path segment requirements
- if (segment.has_generic_args () || segment.as_string () == "Self")
+ if (segment.has_generic_args () || segment.to_string () == "Self")
{
return AST::SimplePath::create_empty ();
}
// create segment and add to vector
- std::string segment_str = segment.as_string ();
+ std::string segment_str = segment.to_string ();
simple_segments.emplace_back (std::move (segment_str),
segment.get_locus ());
}
{
// return empty path if doesn't meet simple path segment requirements
if (segment == nullptr || segment->is_error ()
- || !segment->is_ident_only () || segment->as_string () == "Self")
+ || !segment->is_ident_only () || segment->to_string () == "Self")
{
return AST::SimplePath::create_empty ();
}
// create segment and add to vector
- std::string segment_str = segment->as_string ();
+ std::string segment_str = segment->to_string ();
simple_segments.emplace_back (std::move (segment_str),
segment->get_locus ());
}
}
std::string
-PathExprSegment::as_string () const
+PathExprSegment::to_string () const
{
- std::string ident_str = segment_name.as_string ();
+ std::string ident_str = segment_name.to_string ();
if (has_generic_args ())
{
- ident_str += "::<" + generic_args.as_string () + ">";
+ ident_str += "::<" + generic_args.to_string () + ">";
}
return ident_str;
}
std::string
-GenericArgs::as_string () const
+GenericArgs::to_string () const
{
std::string args;
for (; i != e; i++)
{
- args += (*i).as_string ();
+ args += (*i).to_string ();
if (e != i + 1)
args += ", ";
}
for (; i != e; i++)
{
- args += (*i)->as_string ();
+ args += (*i)->to_string ();
if (e != i + 1)
args += ", ";
}
for (; i != e; i++)
{
- args += (*i).as_string ();
+ args += (*i).to_string ();
if (e != i + 1)
args += ", ";
}
}
std::string
-GenericArgsBinding::as_string () const
+GenericArgsBinding::to_string () const
{
- return identifier.as_string () + " = " + type->as_string ();
+ return identifier.as_string () + " = " + type->to_string ();
}
std::string
-RangePattern::as_string () const
+RangePattern::to_string () const
{
if (has_ellipsis_syntax)
{
- return lower->as_string () + "..." + upper->as_string ();
+ return lower->to_string () + "..." + upper->to_string ();
}
else
{
- return lower->as_string () + "..=" + upper->as_string ();
+ return lower->to_string () + "..=" + upper->to_string ();
}
}
std::string
-RangePatternBoundLiteral::as_string () const
+RangePatternBoundLiteral::to_string () const
{
std::string str;
}
std::string
-SlicePatternItemsNoRest::as_string () const
+SlicePatternItemsNoRest::to_string () const
{
std::string str;
for (const auto &pattern : patterns)
{
- str += "\n " + pattern->as_string ();
+ str += "\n " + pattern->to_string ();
}
return str;
}
std::string
-SlicePatternItemsHasRest::as_string () const
+SlicePatternItemsHasRest::to_string () const
{
std::string str;
{
for (const auto &lower : lower_patterns)
{
- str += "\n " + lower->as_string ();
+ str += "\n " + lower->to_string ();
}
}
{
for (const auto &upper : upper_patterns)
{
- str += "\n " + upper->as_string ();
+ str += "\n " + upper->to_string ();
}
}
}
std::string
-SlicePattern::as_string () const
+SlicePattern::to_string () const
{
- return "SlicePattern: " + items->as_string ();
+ return "SlicePattern: " + items->to_string ();
}
std::string
-AltPattern::as_string () const
+AltPattern::to_string () const
{
std::string str ("AltPattern: ");
for (const auto &pattern : alts)
{
- str += "\n " + pattern->as_string ();
+ str += "\n " + pattern->to_string ();
}
return str;
}
std::string
-TuplePatternItemsNoRest::as_string () const
+TuplePatternItemsNoRest::to_string () const
{
std::string str;
for (const auto &pattern : patterns)
{
- str += "\n " + pattern->as_string ();
+ str += "\n " + pattern->to_string ();
}
return str;
}
std::string
-TuplePatternItemsHasRest::as_string () const
+TuplePatternItemsHasRest::to_string () const
{
std::string str;
{
for (const auto &lower : lower_patterns)
{
- str += "\n " + lower->as_string ();
+ str += "\n " + lower->to_string ();
}
}
{
for (const auto &upper : upper_patterns)
{
- str += "\n " + upper->as_string ();
+ str += "\n " + upper->to_string ();
}
}
}
std::string
-TuplePattern::as_string () const
+TuplePattern::to_string () const
{
- return "TuplePattern: " + items->as_string ();
+ return items->to_string ();
}
std::string
-StructPatternField::as_string () const
+StructPatternField::to_string () const
{
// outer attributes
std::string str ("Outer attributes: ");
break;
}
- str += "\n mapping: " + mappings.as_string ();
-
return str;
}
std::string
-StructPatternFieldIdent::as_string () const
+StructPatternFieldIdent::to_string () const
{
- std::string str = StructPatternField::as_string ();
+ std::string str = StructPatternField::to_string ();
str += "\n";
}
std::string
-StructPatternFieldTuplePat::as_string () const
+StructPatternFieldTuplePat::to_string () const
{
- std::string str = StructPatternField::as_string ();
+ std::string str = StructPatternField::to_string ();
str += "\n";
- str += std::to_string (index) + " : " + tuple_pattern->as_string ();
+ str += std::to_string (index) + " : " + tuple_pattern->to_string ();
return str;
}
std::string
-StructPatternFieldIdentPat::as_string () const
+StructPatternFieldIdentPat::to_string () const
{
- std::string str = StructPatternField::as_string ();
+ std::string str = StructPatternField::to_string ();
str += "\n";
- str += ident.as_string () + " : " + ident_pattern->as_string ();
+ str += ident.as_string () + " : " + ident_pattern->to_string ();
return str;
}
std::string
-StructPatternElements::as_string () const
+StructPatternElements::to_string () const
{
std::string str ("\n Fields: ");
{
for (const auto &field : fields)
{
- str += "\n " + field->as_string ();
+ str += "\n " + field->to_string ();
}
}
}
std::string
-StructPattern::as_string () const
+StructPattern::to_string () const
{
std::string str ("StructPattern: \n Path: ");
- str += path.as_string ();
+ str += path.to_string ();
str += "\n Struct pattern elems: ";
if (!has_struct_pattern_elems ())
}
else
{
- str += elems.as_string ();
+ str += elems.to_string ();
}
return str;
}
std::string
-LiteralPattern::as_string () const
+LiteralPattern::to_string () const
{
return (has_minus ? "-" : "") + lit.as_string ();
}
std::string
-ReferencePattern::as_string () const
+ReferencePattern::to_string () const
{
std::string str ("&");
str += "mut ";
}
- str += pattern->as_string ();
+ str += pattern->to_string ();
return str;
}
std::string
-IdentifierPattern::as_string () const
+IdentifierPattern::to_string () const
{
std::string str;
if (has_subpattern ())
{
- str += " @ " + subpattern->as_string ();
+ str += " @ " + subpattern->to_string ();
}
return str;
}
std::string
-TupleStructItemsNoRest::as_string () const
+TupleStructItemsNoRest::to_string () const
{
std::string str;
for (const auto &pattern : patterns)
{
- str += "\n " + pattern->as_string ();
+ str += "\n " + pattern->to_string ();
}
return str;
}
std::string
-TupleStructItemsHasRest::as_string () const
+TupleStructItemsHasRest::to_string () const
{
std::string str ("\n Lower patterns: ");
{
for (const auto &lower : lower_patterns)
{
- str += "\n " + lower->as_string ();
+ str += "\n " + lower->to_string ();
}
}
{
for (const auto &upper : upper_patterns)
{
- str += "\n " + upper->as_string ();
+ str += "\n " + upper->to_string ();
}
}
}
std::string
-TupleStructPattern::as_string () const
+TupleStructPattern::to_string () const
{
std::string str ("TupleStructPattern: \n Path: ");
- str += path.as_string ();
+ str += path.to_string ();
- str += "\n Tuple struct items: " + items->as_string ();
+ str += "\n Tuple struct items: " + items->to_string ();
return str;
}
std::string
-LetStmt::as_string () const
+LetStmt::to_string () const
{
// outer attributes
std::string str = "Outer attributes: ";
indent_spaces (out);
}
- str += "\n" + indent_spaces (stay) + "let " + variables_pattern->as_string ();
+ str += "\n" + indent_spaces (stay) + "let " + variables_pattern->to_string ();
if (has_type ())
{
- str += " : " + get_type ().as_string ();
+ str += " : " + get_type ().to_string ();
}
if (has_init_expr ())
{
- str += " = " + get_init_expr ().as_string ();
+ str += " = " + get_init_expr ().to_string ();
}
return str;
// Used to get outer attributes for expressions.
std::string
-Expr::as_string () const
+Expr::to_string () const
{
// outer attributes
std::string str = "outer attributes: ";
}
std::string
-InferredType::as_string () const
+InferredType::to_string () const
{
- return "_ (inferred) " + get_mappings ().as_string ();
+ return "_ (inferred)";
}
std::string
-TypeCastExpr::as_string () const
+TypeCastExpr::to_string () const
{
- return main_or_left_expr->as_string () + " as "
- + type_to_convert_to->as_string ();
+ return main_or_left_expr->to_string () + " as "
+ + type_to_convert_to->to_string ();
}
std::string
-ImplTraitType::as_string () const
+ImplTraitType::to_string () const
{
std::string str ("ImplTraitType: \n TypeParamBounds: ");
{
for (const auto &bound : type_param_bounds)
{
- str += "\n " + bound->as_string ();
+ str += "\n " + bound->to_string ();
}
}
}
std::string
-ReferenceType::as_string () const
+ReferenceType::to_string () const
{
std::string str ("&");
if (has_lifetime ())
{
- str += get_lifetime ().as_string () + " ";
+ str += get_lifetime ().to_string () + " ";
}
if (is_mut ())
str += "mut ";
}
- str += type->as_string ();
+ str += type->to_string ();
return str;
}
std::string
-RawPointerType::as_string () const
+RawPointerType::to_string () const
{
return std::string ("*") + (is_mut () ? "mut " : "const ")
- + type->as_string ();
+ + type->to_string ();
}
std::string
-TraitObjectType::as_string () const
+TraitObjectType::to_string () const
{
std::string str ("TraitObjectType: \n Has dyn dispatch: ");
{
for (const auto &bound : type_param_bounds)
{
- str += "\n " + bound->as_string ();
+ str += "\n " + bound->to_string ();
}
}
}
std::string
-BareFunctionType::as_string () const
+BareFunctionType::to_string () const
{
std::string str ("BareFunctionType: \n For lifetimes: ");
{
for (const auto &for_lifetime : for_lifetimes)
{
- str += "\n " + for_lifetime.as_string ();
+ str += "\n " + for_lifetime.to_string ();
}
}
- str += "\n Qualifiers: " + function_qualifiers.as_string ();
+ str += "\n Qualifiers: " + function_qualifiers.to_string ();
str += "\n Params: ";
if (params.empty ())
{
for (const auto ¶m : params)
{
- str += "\n " + param.as_string ();
+ str += "\n " + param.to_string ();
}
}
}
else
{
- str += return_type->as_string ();
+ str += return_type->to_string ();
}
return str;
}
std::string
-TypePathSegmentGeneric::as_string () const
+TypePathSegmentGeneric::to_string () const
{
- return TypePathSegment::as_string () + "<" + generic_args.as_string () + ">";
+ return TypePathSegment::to_string () + "<" + generic_args.to_string () + ">";
}
std::string
-TypePathFunction::as_string () const
+TypePathFunction::to_string () const
{
std::string str ("(");
for (; i != e; i++)
{
- str += (*i)->as_string ();
+ str += (*i)->to_string ();
if (e != i + 1)
str += ", ";
}
if (has_return_type ())
{
- str += " -> " + return_type->as_string ();
+ str += " -> " + return_type->to_string ();
}
return str;
}
std::string
-TypePathSegmentFunction::as_string () const
+TypePathSegmentFunction::to_string () const
{
- return TypePathSegment::as_string () + function_path.as_string ();
+ return TypePathSegment::to_string () + function_path.to_string ();
}
std::string
-ArrayType::as_string () const
+ArrayType::to_string () const
{
- return "[" + elem_type->as_string () + "; " + size->as_string () + "]";
+ return "[" + elem_type->to_string () + "; " + size->to_string () + "]";
}
std::string
-SliceType::as_string () const
+SliceType::to_string () const
{
- return "[" + elem_type->as_string () + "]";
+ return "[" + elem_type->to_string () + "]";
}
std::string
-TupleType::as_string () const
+TupleType::to_string () const
{
std::string str ("(");
for (; i != e; i++)
{
- str += (*i)->as_string ();
+ str += (*i)->to_string ();
if (e != i + 1)
str += ", ";
}
}
std::string
-StructExpr::as_string () const
+StructExpr::to_string () const
{
- std::string str = ExprWithoutBlock::as_string ();
+ std::string str = ExprWithoutBlock::to_string ();
indent_spaces (enter);
str += "\n" + indent_spaces (stay) + "StructExpr:";
indent_spaces (enter);
str += "\n" + indent_spaces (stay) + "PathInExpr:\n";
- str += indent_spaces (stay) + struct_name.as_string ();
+ str += indent_spaces (stay) + struct_name.to_string ();
indent_spaces (out);
indent_spaces (out);
return str;
}
std::string
-StructExprStruct::as_string () const
+StructExprStruct::to_string () const
{
std::string str ("StructExprStruct (or subclass): ");
- str += "\n Path: " + struct_name.as_string ();
+ str += "\n Path: " + struct_name.to_string ();
// inner attributes
str += "\n inner attributes: ";
}
std::string
-StructBase::as_string () const
+StructBase::to_string () const
{
if (base_struct != nullptr)
{
- return base_struct->as_string ();
+ return base_struct->to_string ();
}
else
{
}
std::string
-StructExprFieldWithVal::as_string () const
+StructExprFieldWithVal::to_string () const
{
// used to get value string
- return value->as_string ();
+ return value->to_string ();
}
std::string
-StructExprFieldIdentifierValue::as_string () const
+StructExprFieldIdentifierValue::to_string () const
{
- return field_name.as_string () + " : " + StructExprFieldWithVal::as_string ();
+ return field_name.as_string () + " : " + StructExprFieldWithVal::to_string ();
}
std::string
-StructExprFieldIndexValue::as_string () const
+StructExprFieldIndexValue::to_string () const
{
- return std::to_string (index) + " : " + StructExprFieldWithVal::as_string ();
+ return std::to_string (index) + " : " + StructExprFieldWithVal::to_string ();
}
std::string
-StructExprStructFields::as_string () const
+StructExprStructFields::to_string () const
{
- std::string str = StructExprStruct::as_string ();
+ std::string str = StructExprStruct::to_string ();
str += "\n Fields: ";
if (fields.empty ())
{
for (const auto &field : fields)
{
- str += "\n " + field->as_string ();
+ str += "\n " + field->to_string ();
}
}
}
else
{
- str += (*struct_base)->as_string ();
+ str += (*struct_base)->to_string ();
}
return str;
}
std::string
-EnumItem::as_string () const
+EnumItem::to_string () const
{
- std::string str = Item::as_string ();
+ std::string str = Item::to_string ();
str += variant_name.as_string ();
str += " ";
switch (get_enum_item_kind ())
}
std::string
-EnumItemTuple::as_string () const
+EnumItemTuple::to_string () const
{
- std::string str = EnumItem::as_string ();
+ std::string str = EnumItem::to_string ();
// add tuple opening parens
str += "(";
for (; i != e; i++)
{
- str += (*i).as_string ();
+ str += (*i).to_string ();
if (e != i + 1)
str += ", ";
}
}
std::string
-TupleField::as_string () const
+TupleField::to_string () const
{
// outer attributes
std::string str = "outer attributes: ";
if (has_visibility ())
{
- str += "\n" + visibility.as_string ();
+ str += "\n" + visibility.to_string ();
}
- str += " " + field_type->as_string ();
+ str += " " + field_type->to_string ();
return str;
}
std::string
-EnumItemStruct::as_string () const
+EnumItemStruct::to_string () const
{
- std::string str = EnumItem::as_string ();
+ std::string str = EnumItem::to_string ();
// add struct opening parens
str += "{";
for (; i != e; i++)
{
- str += (*i).as_string ();
+ str += (*i).to_string ();
if (e != i + 1)
str += ", ";
}
}
std::string
-StructField::as_string () const
+StructField::to_string () const
{
// outer attributes
std::string str = "outer attributes: ";
if (has_visibility ())
{
- str += "\n" + visibility.as_string ();
+ str += "\n" + visibility.to_string ();
}
- str += " " + field_name.as_string () + " : " + field_type->as_string ();
+ str += " " + field_name.as_string () + " : " + field_type->to_string ();
return str;
}
std::string
-EnumItemDiscriminant::as_string () const
+EnumItemDiscriminant::to_string () const
{
- std::string str = EnumItem::as_string ();
+ std::string str = EnumItem::to_string ();
// add equal and expression
- str += " = " + expression->as_string ();
+ str += " = " + expression->to_string ();
return str;
}
std::string
-ExternalItem::as_string () const
+ExternalItem::to_string () const
{
// outer attributes
std::string str = "outer attributes: ";
}
// start visibility on new line and with a space
- str += "\n" + visibility.as_string () + " ";
+ str += "\n" + visibility.to_string () + " ";
return str;
}
std::string
-ExternalStaticItem::as_string () const
+ExternalStaticItem::to_string () const
{
- std::string str = ExternalItem::as_string ();
+ std::string str = ExternalItem::to_string ();
str += "static ";
str += get_item_name ().as_string ();
// add type on new line
- str += "\n Type: " + item_type->as_string ();
+ str += "\n Type: " + item_type->to_string ();
return str;
}
std::string
-ExternalFunctionItem::as_string () const
+ExternalFunctionItem::to_string () const
{
- std::string str = ExternalItem::as_string ();
+ std::string str = ExternalItem::to_string ();
str += "fn ";
return "nullptr_POINTER_MARK";
}
- str += "\n " + param->as_string ();
+ str += "\n " + param->to_string ();
}
}
{
for (const auto ¶m : function_params)
{
- str += "\n " + param.as_string ();
+ str += "\n " + param.to_string ();
}
if (has_variadics)
{
// add type on new line)
str += "\n (return) Type: "
- + (has_return_type () ? return_type->as_string () : "()");
+ + (has_return_type () ? return_type->to_string () : "()");
// where clause
str += "\n Where clause: ";
if (has_where_clause ())
{
- str += where_clause.as_string ();
+ str += where_clause.to_string ();
}
else
{
}
std::string
-ExternalTypeItem::as_string () const
+ExternalTypeItem::to_string () const
{
- std::string str = ExternalItem::as_string ();
+ std::string str = ExternalItem::to_string ();
str += "type ";
}
std::string
-NamedFunctionParam::as_string () const
+NamedFunctionParam::to_string () const
{
std::string str = name.as_string ();
- str += "\n Type: " + param_type->as_string ();
+ str += "\n Type: " + param_type->to_string ();
return str;
}
-/*std::string TraitItem::as_string() const {
+/*std::string TraitItem::to_string() const {
// outer attributes
std::string str = "outer attributes: ";
if (outer_attrs.empty()) {
} else {
// note that this does not print them with "outer attribute" syntax -
just the body for (const auto& attr : outer_attrs) { str += "\n " +
-attr.as_string();
+attr.to_string();
}
}
}*/
std::string
-TraitItemFunc::as_string () const
+TraitItemFunc::to_string () const
{
std::string str = "outer attributes: ";
if (outer_attrs.empty ())
}
}
- str += "\n" + decl.as_string ();
+ str += "\n" + decl.to_string ();
str += "\n Definition (block expr): ";
if (has_definition ())
{
- str += block_expr->as_string ();
+ str += block_expr->to_string ();
}
else
{
}
std::string
-TraitFunctionDecl::as_string () const
+TraitFunctionDecl::to_string () const
{
std::string str
- = qualifiers.as_string () + "fn " + function_name.as_string ();
+ = qualifiers.to_string () + "fn " + function_name.as_string ();
// generic params
str += "\n Generic params: ";
return "nullptr_POINTER_MARK";
}
- str += "\n " + param->as_string ();
+ str += "\n " + param->to_string ();
}
}
str += "\n Function params: ";
if (is_method ())
{
- str += get_self_unchecked ().as_string () + (has_params () ? ", " : "");
+ str += get_self_unchecked ().to_string () + (has_params () ? ", " : "");
}
if (has_params ())
{
for (const auto ¶m : function_params)
{
- str += "\n " + param.as_string ();
+ str += "\n " + param.to_string ();
}
}
else if (!is_method ())
str += "\n Return type: ";
if (has_return_type ())
{
- str += return_type->as_string ();
+ str += return_type->to_string ();
}
else
{
str += "\n Where clause: ";
if (has_where_clause ())
{
- str += where_clause.as_string ();
+ str += where_clause.to_string ();
}
else
{
}
std::string
-TraitItemConst::as_string () const
+TraitItemConst::to_string () const
{
std::string str = "outer attributes: ";
if (outer_attrs.empty ())
}
}
- str += "\nconst " + name.as_string () + " : " + type->as_string ();
+ str += "\nconst " + name.as_string () + " : " + type->to_string ();
if (has_expression ())
{
- str += " = " + expr->as_string ();
+ str += " = " + expr->to_string ();
}
return str;
}
std::string
-TraitItemType::as_string () const
+TraitItemType::to_string () const
{
std::string str = "outer attributes: ";
if (outer_attrs.empty ())
{
if (i > 0)
str += ", ";
- str += generic_params[i]->as_string ();
+ str += generic_params[i]->to_string ();
}
str += ">";
}
return "nullptr_POINTER_MARK";
}
- str += "\n " + bound->as_string ();
+ str += "\n " + bound->to_string ();
}
}
}
std::string
-SelfParam::as_string () const
+SelfParam::to_string () const
{
if (has_type ())
{
str += "self : ";
- str += type->as_string ();
+ str += type->to_string ();
return str;
}
else if (has_lifetime ())
{
// ref and lifetime
- std::string str = "&" + get_lifetime ().as_string () + " ";
+ std::string str = "&" + get_lifetime ().to_string () + " ";
if (is_mut ())
{
}
std::string
-ArrayElemsCopied::as_string () const
+ArrayElemsCopied::to_string () const
{
- return elem_to_copy->as_string () + "; " + num_copies->as_string ();
+ return elem_to_copy->to_string () + "; " + num_copies->to_string ();
}
std::string
-LifetimeWhereClauseItem::as_string () const
+LifetimeWhereClauseItem::to_string () const
{
std::string str ("Lifetime: ");
- str += lifetime.as_string ();
+ str += lifetime.to_string ();
str += "\nLifetime bounds: ";
for (const auto &bound : lifetime_bounds)
{
- str += "\n " + bound.as_string ();
+ str += "\n " + bound.to_string ();
}
return str;
}
std::string
-TypeBoundWhereClauseItem::as_string () const
+TypeBoundWhereClauseItem::to_string () const
{
std::string str ("For lifetimes: ");
{
for (const auto &for_lifetime : for_lifetimes)
{
- str += "\n " + for_lifetime.as_string ();
+ str += "\n " + for_lifetime.to_string ();
}
}
- str += "\nType: " + bound_type->as_string ();
+ str += "\nType: " + bound_type->to_string ();
str += "\nType param bounds bounds: ";
return "nullptr_POINTER_MARK - type param bounds";
}
- str += "\n " + bound->as_string ();
+ str += "\n " + bound->to_string ();
}
return str;
}
std::string
-ArrayElemsValues::as_string () const
+ArrayElemsValues::to_string () const
{
std::string str;
return "nullptr_POINTER_MARK";
}
- str += "\n " + expr->as_string ();
+ str += "\n " + expr->to_string ();
}
return str;
}
std::string
-MaybeNamedParam::as_string () const
+MaybeNamedParam::to_string () const
{
std::string str;
return "ERROR_MARK_STRING - maybe named param unrecognised param kind";
}
- str += param_type->as_string ();
+ str += param_type->to_string ();
return str;
}
return std::unique_ptr<TraitItem> (clone_trait_item_impl ());
}
- virtual std::string as_string () const = 0;
+ virtual std::string to_string () const = 0;
+
+ std::string to_debug_string () const
+ {
+ return to_string () + mappings.as_string ();
+ }
virtual void accept_vis (HIRTraitItemVisitor &vis) = 0;
return std::unique_ptr<ImplItem> (clone_inherent_impl_item_impl ());
}
- virtual std::string as_string () const = 0;
+ virtual std::string to_string () const = 0;
+
+ std::string to_debug_string () const
+ {
+ return to_string () + get_impl_mappings ().as_string ();
+ }
virtual void accept_vis (HIRImplVisitor &vis) = 0;
virtual void accept_vis (HIRStmtVisitor &vis) = 0;
Crate &operator= (Crate &&other) = default;
// Get crate representation as string (e.g. for debugging).
- std::string as_string () const;
+ std::string to_string () const;
+
+ std::string to_debug_string () const;
const Analysis::NodeMapping &get_mappings () const { return mappings; }
std::vector<std::unique_ptr<Item>> &get_items () { return items; }
return;
}
- out << crate.as_string ();
+ out << crate.to_string ();
out.close ();
}
return true;
bool name_matches = func->get_function_name ().as_string ().compare (
- segment_name.as_string ())
+ segment_name.to_string ())
== 0;
if (!name_matches)
return true;
continue;
bool name_matches = func->get_function_name ().as_string ().compare (
- segment_name.as_string ())
+ segment_name.to_string ())
== 0;
if (!name_matches)
continue;
rust_assert (!trait_ref->is_error ());
auto item_ref
- = trait_ref->lookup_trait_item (segment_name.as_string (),
+ = trait_ref->lookup_trait_item (segment_name.to_string (),
TraitItemReference::TraitItemType::FN);
if (item_ref->is_error ())
return true;
{
rust_debug ("MethodResolver::select reciever=[%s] path=[%s]",
receiver.debug_str ().c_str (),
- segment_name.as_string ().c_str ());
+ segment_name.to_string ().c_str ());
// Assemble candidates
std::vector<impl_item_candidate> inherent_impl_fns
for (auto &bound : specified_bounds)
{
tl::optional<TyTy::TypeBoundPredicateItem> lookup
- = bound.lookup_associated_item (segment_name.as_string ());
+ = bound.lookup_associated_item (segment_name.to_string ());
if (!lookup.has_value ())
continue;
PathProbeType::visit (HIR::TypeAlias &alias)
{
Identifier name = alias.get_new_type_name ();
- if (search.as_string ().compare (name.as_string ()) == 0)
+ if (search.to_string ().compare (name.as_string ()) == 0)
{
HirId tyid = alias.get_mappings ().get_hirid ();
TyTy::BaseType *ty = nullptr;
PathProbeType::visit (HIR::ConstantItem &constant)
{
Identifier name = constant.get_identifier ();
- if (search.as_string ().compare (name.as_string ()) == 0)
+ if (search.to_string ().compare (name.as_string ()) == 0)
{
HirId tyid = constant.get_mappings ().get_hirid ();
TyTy::BaseType *ty = nullptr;
PathProbeType::visit (HIR::Function &function)
{
Identifier name = function.get_function_name ();
- if (search.as_string ().compare (name.as_string ()) == 0)
+ if (search.to_string ().compare (name.as_string ()) == 0)
{
HirId tyid = function.get_mappings ().get_hirid ();
TyTy::BaseType *ty = nullptr;
return;
TyTy::VariantDef *v;
- if (!adt->lookup_variant (search.as_string (), &v))
+ if (!adt->lookup_variant (search.to_string (), &v))
return;
PathProbeCandidate::EnumItemCandidate enum_item_candidate{adt, v};
bool ignore_mandatory_trait_items)
{
const TraitItemReference *trait_item_ref = nullptr;
- if (!trait_ref->lookup_trait_item (search.as_string (), &trait_item_ref))
+ if (!trait_ref->lookup_trait_item (search.to_string (), &trait_item_ref))
return;
bool trait_item_needs_implementation = !trait_item_ref->is_optional ();
const TraitReference *trait_ref = predicate.get ();
tl::optional<TyTy::TypeBoundPredicateItem> item
- = predicate.lookup_associated_item (search.as_string ());
+ = predicate.lookup_associated_item (search.to_string ());
if (!item.has_value ())
return;
for (auto &c : candidates)
r.add_range (c.locus);
- std::string rich_msg = "multiple " + query.as_string () + " found";
+ std::string rich_msg = "multiple " + query.to_string () + " found";
r.add_fixit_replace (rich_msg.c_str ());
rust_error_at (r, ErrorCode::E0034,
"multiple applicable items in scope for: %qs",
- query.as_string ().c_str ());
+ query.to_string ().c_str ());
}
};
{
rich_location r (line_table, expr.get_method_name ().get_locus ());
std::string rich_msg = "multiple "
- + expr.get_method_name ().get_segment ().as_string ()
+ + expr.get_method_name ().get_segment ().to_string ()
+ " found";
// We have to filter out default candidates
r.add_fixit_replace (rich_msg.c_str ());
rust_error_at (r, ErrorCode::E0592, "duplicate definitions with name %qs",
- expr.get_method_name ().get_segment ().as_string ().c_str ());
+ expr.get_method_name ().get_segment ().to_string ().c_str ());
}
// We are allowed to have multiple candidates if they are all specializable
rust_error_at (
richloc, ErrorCode::E0599,
"no method named %qs found in the current scope",
- expr.get_method_name ().get_segment ().as_string ().c_str ());
+ expr.get_method_name ().get_segment ().to_string ().c_str ());
return;
}
rust_error_at (
r, "multiple candidates found for function trait method call %qs",
- method_name.as_string ().c_str ());
+ method_name.to_string ().c_str ());
return false;
}
HIR::PathExprSegment &item_seg = expr.get_segments ().at (0);
HIR::PathIdentSegment item_seg_identifier = item_seg.get_segment ();
tl::optional<TyTy::TypeBoundPredicateItem> item
- = specified_bound.lookup_associated_item (item_seg_identifier.as_string ());
+ = specified_bound.lookup_associated_item (item_seg_identifier.to_string ());
if (!item.has_value ())
{
rust_error_at (item_seg.get_locus (), "unknown associated item");
associated_impl_trait->get_impl_block ()->get_impl_items ())
{
bool found = i->get_impl_item_name ().compare (
- item_seg_identifier.as_string ())
+ item_seg_identifier.to_string ())
== 0;
if (found)
{
rust_error_at (seg.get_locus (), "456 reverse lookup failure");
rust_debug_loc (seg.get_locus (),
"failure with [%s] mappings [%s] ref_node_id [%u]",
- seg.as_string ().c_str (),
+ seg.to_string ().c_str (),
seg.get_mappings ().as_string ().c_str (),
ref_node_id);
auto seg_is_crate = mappings.is_local_hirid_crate (ref);
auto seg_is_pattern = mappings.lookup_hir_pattern (ref).has_value ();
auto seg_is_self = is_root && !have_more_segments
- && seg.get_segment ().as_string () == "self";
+ && seg.get_segment ().to_string () == "self";
if (seg_is_module || seg_is_crate)
{
// A::B::C::this_is_a_module::D::E::F
#include "rust-hir-type-check-pattern.h"
#include "rust-hir-pattern.h"
#include "rust-hir-type-check-expr.h"
+#include "rust-token.h"
#include "rust-type-util.h"
#include "rust-immutable-name-resolution-context.h"
#include "rust-tyty.h"
for (size_t i = 0; i < pattern.get_segments ().size (); i++)
{
HIR::PathExprSegment &seg = pattern.get_segments ().at (i);
- path_buf += seg.as_string ();
+ path_buf += seg.to_string ();
if (i != pattern.get_segments ().size () - 1)
path_buf += "::";
}
auto first_elem
= struct_pattern_elems.get_struct_pattern_fields ()
.at (0)
- ->as_string ();
+ ->to_string ();
rust_error_at (pattern.get_locus (),
"%qs cannot be used in union patterns",
first_elem.c_str ());
void
TypeCheckType::visit (HIR::TypePath &path)
{
- rust_debug ("{ARTHUR}: Path visited: %s", path.as_string ().c_str ());
+ rust_debug ("{ARTHUR}: Path visited: %s", path.to_string ().c_str ());
// this can happen so we need to look up the root then resolve the
// remaining segments if possible
HIR::TypePathSegment &item_seg = path.get_associated_segment ();
HIR::PathIdentSegment item_seg_identifier = item_seg.get_ident_segment ();
tl::optional<TyTy::TypeBoundPredicateItem> item
- = specified_bound.lookup_associated_item (item_seg_identifier.as_string ());
+ = specified_bound.lookup_associated_item (item_seg_identifier.to_string ());
if (!item.has_value ())
{
std::string item_seg_ident_name, rich_msg;
- item_seg_ident_name = qual_path_type.get_trait ().as_string ();
+ item_seg_ident_name = qual_path_type.get_trait ().to_string ();
rich_msg = "not found in `" + item_seg_ident_name + "`";
rich_location richloc (line_table, item_seg.get_locus ());
rust_error_at (richloc, ErrorCode::E0576,
"cannot find associated type %qs in trait %qs",
- item_seg_identifier.as_string ().c_str (),
+ item_seg_identifier.to_string ().c_str (),
item_seg_ident_name.c_str ());
return;
}
associated_impl_trait->get_impl_block ()->get_impl_items ())
{
bool found = i->get_impl_item_name ().compare (
- item_seg_identifier.as_string ())
+ item_seg_identifier.to_string ())
== 0;
if (found)
{
{
rust_error_at (seg->get_locus (),
"unknown reference for resolved name: %qs",
- seg->as_string ().c_str ());
+ seg->to_string ().c_str ());
return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
}
else if (root_tyty == nullptr)
{
rust_error_at (seg->get_locus (),
"unknown reference for resolved name: %qs",
- seg->as_string ().c_str ());
+ seg->to_string ().c_str ());
return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
}
return root_tyty;
}
- if (seg->is_ident_only () && seg->as_string () == "Self")
+ if (seg->is_ident_only () && seg->to_string () == "Self")
*wasBigSelf = true;
// node back to HIR
rust_debug_loc (
seg->get_locus (),
"failure with [%s] mappings [%s] ref_node_id [%u]",
- seg->as_string ().c_str (),
+ seg->to_string ().c_str (),
seg->get_mappings ().as_string ().c_str (), ref_node_id);
return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
{
rust_error_at (seg->get_locus (),
"failed to resolve type path segment: %qs",
- seg->as_string ().c_str ());
+ seg->to_string ().c_str ());
return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
}
TypeCheckBlockContextItem ctx = context->block_context ().peek ();
TyTy::BaseType *lookup = nullptr;
selfResolveOk
- = resolve_associated_type (seg->as_string (), ctx, &lookup);
+ = resolve_associated_type (seg->to_string (), ctx, &lookup);
if (selfResolveOk)
{
prev_segment = tyseg;
// FIXME
rust_error_at (UNDEF_LOCATION,
"Failed to lookup type reference for node: %s",
- binding_type_path.as_string ().c_str ());
+ binding_type_path.to_string ().c_str ());
return;
}
{
rust_error_at (mappings.lookup_location (*hid),
"Failed to resolve where-clause binding type: %s",
- binding_type_path.as_string ().c_str ());
+ binding_type_path.to_string ().c_str ());
return;
}
= "required by this bound in: " + ptref.get_name ();
std::string fixit2 = "the trait " + sptref.get_name ()
+ " is not implemented for "
- + impl_type.as_string ();
+ + impl_type.to_string ();
rich_location r (line_table, trait.get_locus ());
r.add_fixit_insert_after (super.get_locus (), fixit1.c_str ());
r.add_fixit_insert_after (trait.get_locus (), fixit2.c_str ());
rust_error_at (r, ErrorCode::E0277,
"the trait bound %<%s: %s%> is not satisfied",
- impl_type.as_string ().c_str (),
+ impl_type.to_string ().c_str (),
sptref.get_name ().c_str ());
return false;
{
if (type == VariantType::NUM)
return identifier
- + (has_discriminant () ? " = " + get_discriminant ().as_string ()
+ + (has_discriminant () ? " = " + get_discriminant ().to_string ()
: "");
std::string buffer;
{
auto &pattern = param.get_pattern ();
auto ty = param.get_type ();
- params_str += pattern.as_string () + " " + ty->as_string ();
+ params_str += pattern.to_string () + " " + ty->as_string ();
params_str += ",";
}