Provide access to the name of contracts.

This commit is contained in:
Alex Beregszaszi
2019-02-26 14:07:03 +00:00
parent 1169004cec
commit d2f493268b
10 changed files with 93 additions and 8 deletions
@@ -1361,6 +1361,18 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
);
m_context << Instruction::POP;
}
else if (member == "name")
{
TypePointer arg = dynamic_cast<MagicType const&>(*_memberAccess.expression().annotation().type).typeArgument();
ContractDefinition const& contract = dynamic_cast<ContractType const&>(*arg).contractDefinition();
m_context << u256(contract.name().length() + 32);
utils().allocateMemory();
// store string length
m_context << u256(contract.name().length()) << Instruction::DUP2 << Instruction::MSTORE;
// adjust pointer
m_context << Instruction::DUP1 << u256(32) << Instruction::ADD;
utils().storeStringData(contract.name());
}
else
solAssert(false, "Unknown magic member.");
break;