Skip to content

Commit

Permalink
Adds function to print block type
Browse files Browse the repository at this point in the history
Issue: #17
  • Loading branch information
0x7CFE committed May 25, 2016
1 parent c77a616 commit 2f7a417
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/TypeAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@

using namespace type;

static void printBlock(const Type& blockType, std::stringstream& stream) {
if (blockType.getSubTypes().size() < 2) {
stream << "(Block)";
return;
}

TMethod* const method = blockType.getSubTypes()[0].getValue()->cast<TMethod>();
const uint16_t offset = TInteger(blockType.getSubTypes()[1].getValue());

// Class>>method@offset
stream
<< method->klass->name->toString()
<< ">>" << method->name->toString()
<< "@" << offset;
}

std::string Type::toString(bool subtypesOnly /*= false*/) const {
std::stringstream stream;

Expand Down Expand Up @@ -32,7 +48,10 @@ std::string Type::toString(bool subtypesOnly /*= false*/) const {
break;

case tkMonotype:
stream << "(" << getValue()->cast<TClass>()->name->toString() << ")";
if (getValue() == globals.blockClass)
printBlock(*this, stream);
else
stream << "(" << getValue()->cast<TClass>()->name->toString() << ")";
break;

case tkArray:
Expand Down

0 comments on commit 2f7a417

Please sign in to comment.