decompiler support for tuples

This commit is contained in:
xensik
2022-07-17 13:49:31 +02:00
parent b8cc78d106
commit c44c54f815
20 changed files with 860 additions and 135 deletions

View File

@ -206,6 +206,9 @@ expr_field::expr_field(const location& loc, expr obj, expr_identifier::ptr field
expr_array::expr_array(expr obj, expr key) : node(kind::expr_array), obj(std::move(obj)), key(std::move(key)) {}
expr_array::expr_array(const location& loc, expr obj, expr key) : node(kind::expr_array, loc), obj(std::move(obj)), key(std::move(key)) {}
expr_tuple::expr_tuple() : node(kind::expr_tuple) {}
expr_tuple::expr_tuple(const location& loc) : node(kind::expr_tuple, loc) {}
expr_reference::expr_reference(expr_path::ptr path, expr_identifier::ptr name) : node(kind::expr_reference), path(std::move(path)), name(std::move(name)) {}
expr_reference::expr_reference(const location& loc, expr_path::ptr path, expr_identifier::ptr name) : node(kind::expr_reference, loc), path(std::move(path)), name(std::move(name)) {}
@ -606,6 +609,19 @@ auto expr_array::print() const -> std::string
return obj.print() + "[" + key.print() + "]";
}
auto expr_tuple::print() const -> std::string
{
std::string data = "[";
for (const auto& entry : list)
{
data += " " + entry.print();
data += (&entry != &list.back()) ? "," : " ";
}
return data += "]";
}
auto expr_reference::print() const -> std::string
{
return path->print() + "::" + name->print();
@ -1576,6 +1592,7 @@ expr::~expr()
case kind::expr_size: as_size.~unique_ptr(); return;
case kind::expr_field: as_field.~unique_ptr(); return;
case kind::expr_array: as_array.~unique_ptr(); return;
case kind::expr_tuple: as_tuple.~unique_ptr(); return;
case kind::expr_reference: as_reference.~unique_ptr(); return;
case kind::expr_arguments: as_arguments.~unique_ptr(); return;
case kind::expr_parameters: as_parameters.~unique_ptr(); return;

View File

@ -33,6 +33,7 @@ enum class kind
expr_size,
expr_field,
expr_array,
expr_tuple,
expr_reference,
expr_istrue,
expr_isdefined,
@ -152,6 +153,7 @@ struct expr_paren;
struct expr_size;
struct expr_field;
struct expr_array;
struct expr_tuple;
struct expr_reference;
struct expr_istrue;
struct expr_isdefined;
@ -292,6 +294,7 @@ union expr
std::unique_ptr<expr_size> as_size;
std::unique_ptr<expr_field> as_field;
std::unique_ptr<expr_array> as_array;
std::unique_ptr<expr_tuple> as_tuple;
std::unique_ptr<expr_reference> as_reference;
std::unique_ptr<expr_istrue> as_istrue;
std::unique_ptr<expr_isdefined> as_isdefined;
@ -718,6 +721,18 @@ struct expr_array : public node
friend bool operator==(const expr_array& lhs, const expr_array& rhs);
};
struct expr_tuple : public node
{
using ptr = std::unique_ptr<expr_tuple>;
std::vector<expr> list;
ast::expr temp;
expr_tuple();
expr_tuple(const location& loc);
auto print() const -> std::string override;
};
struct expr_reference : public node
{
using ptr = std::unique_ptr<expr_reference>;