Skip to content

Commit

Permalink
Added support for struct_create.
Browse files Browse the repository at this point in the history
  • Loading branch information
Orvid committed Dec 1, 2015
1 parent bcb6be4 commit 9542319
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Decompiler/Node/NodeComparer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ void Node::NodeComparer::visit(Node::PropertyAccess *node)
m_Reference->visit(& m_Visitor);
}

void Node::NodeComparer::visit(Node::StructCreate *node)
{
m_Visitor << (DynamicVisitor::LambdaArrayCreate)[&](ArrayCreate* ref, DynamicVisitor*) {
m_Result = ref->getType() == node->getType();
};
m_Reference->visit(&m_Visitor);
}

void Node::NodeComparer::visit(Node::ArrayCreate *node)
{
m_Visitor << (DynamicVisitor::LambdaArrayCreate)[&](ArrayCreate* ref, DynamicVisitor*) {
Expand Down
1 change: 1 addition & 0 deletions Decompiler/Node/NodeComparer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class NodeComparer final : public Visitor
void visit(Node::Params* node) override;
void visit(Node::Return* node) override;
void visit(Node::PropertyAccess* node) override;
void visit(Node::StructCreate* node) override;
void visit(Node::ArrayCreate* node) override;
void visit(Node::ArrayLength* node) override;
void visit(Node::ArrayAccess* node) override;
Expand Down
1 change: 1 addition & 0 deletions Decompiler/Node/Nodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ArrayLength.hpp"
#include "ArrayAccess.hpp"

#include "StructCreate.hpp"

#include "Constant.hpp"
#include "IdentifierString.hpp"
Expand Down
33 changes: 33 additions & 0 deletions Decompiler/Node/StructCreate.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <cassert>
#include <cstdint>

#include "Base.hpp"
#include "Visitor.hpp"

namespace Node {

class StructCreate final : public Base
{
public:
StructCreate(size_t ip, const Pex::StringTable::Index& result, const Pex::StringTable::Index& type) :
Base(0, ip, 0, result),
m_Type(type)
{
}
virtual ~StructCreate() = default;

void visit(Visitor* visitor) override
{
assert(visitor);
visitor->visit(this);
}

const Pex::StringTable::Index& getType() const { return m_Type; }

private:
const Pex::StringTable::Index& m_Type;
};

}
1 change: 1 addition & 0 deletions Decompiler/Node/Visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Node {
DO_NODE(While) \
DO_NODE(IfElse) \
DO_NODE(Declare) \
DO_NODE(StructCreate) \

#define DO_NODE(NODE) class NODE;
FOR_EACH_NODE_CLASS()
Expand Down
5 changes: 5 additions & 0 deletions Decompiler/PscCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ void Decompiler::PscCodeGenerator::visit(Node::PropertyAccess *node)
m_Result << "." << node->getProperty();
}

void Decompiler::PscCodeGenerator::visit(Node::StructCreate* node)
{
m_Result << "new " << node->getType().asString() << "()";
}

void Decompiler::PscCodeGenerator::visit(Node::ArrayCreate* node)
{
std::string type = node->getType().asString();
Expand Down
1 change: 1 addition & 0 deletions Decompiler/PscCodeGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PscCodeGenerator : public Node::Visitor
virtual void visit(Node::Params* node);
virtual void visit(Node::Return* node);
virtual void visit(Node::PropertyAccess* node);
virtual void visit(Node::StructCreate* node);
virtual void visit(Node::ArrayCreate* node);
virtual void visit(Node::ArrayLength* node);
virtual void visit(Node::ArrayAccess* node);
Expand Down
2 changes: 1 addition & 1 deletion Decompiler/PscDecompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ void Decompiler::PscDecompiler::createNodesForBlocks(size_t block)
}
case Pex::OpCode::STRUCT_CREATE:
{
node = std::make_shared<Node::Assign>(ip, fromValue(ip, args[0]), std::make_shared<Node::IdentifierString>(ip, "parent"));
node = std::make_shared<Node::StructCreate>(ip, args[0].getId(), typeOfVar(args[0].getId()));
break;
}
case Pex::OpCode::STRUCT_GET:
Expand Down

0 comments on commit 9542319

Please sign in to comment.