aboutsummaryrefslogtreecommitdiffstats
path: root/Types.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-03-16 23:15:13 +0800
committerchriseth <c@ethdev.com>2015-03-18 01:13:27 +0800
commit895c08342c4b236c2928a5af9fb23def218eca3d (patch)
tree8def3be200aa9c7b740dfd98ba48e3c7a961817c /Types.cpp
parented757ba5bf1090ba8a9a5e3e6a29da8785afb861 (diff)
downloaddexon-solidity-895c08342c4b236c2928a5af9fb23def218eca3d.tar.gz
dexon-solidity-895c08342c4b236c2928a5af9fb23def218eca3d.tar.zst
dexon-solidity-895c08342c4b236c2928a5af9fb23def218eca3d.zip
Provide access to storage offsets via contract type.
Diffstat (limited to 'Types.cpp')
-rw-r--r--Types.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/Types.cpp b/Types.cpp
index 04f86b92..ed3cb8fd 100644
--- a/Types.cpp
+++ b/Types.cpp
@@ -20,14 +20,14 @@
* Solidity data types
*/
+#include <libsolidity/Types.h>
+#include <limits>
+#include <boost/range/adaptor/reversed.hpp>
#include <libdevcore/CommonIO.h>
#include <libdevcore/CommonData.h>
#include <libsolidity/Utils.h>
-#include <libsolidity/Types.h>
#include <libsolidity/AST.h>
-#include <limits>
-
using namespace std;
namespace dev
@@ -812,6 +812,26 @@ u256 ContractType::getFunctionIdentifier(string const& _functionName) const
return Invalid256;
}
+vector<tuple<VariableDeclaration const*, u256, unsigned>> ContractType::getStateVariables() const
+{
+ vector<VariableDeclaration const*> variables;
+ for (ContractDefinition const* contract: boost::adaptors::reverse(m_contract.getLinearizedBaseContracts()))
+ for (ASTPointer<VariableDeclaration> const& variable: contract->getStateVariables())
+ if (!variable->isConstant())
+ variables.push_back(variable.get());
+ TypePointers types;
+ for (auto variable: variables)
+ types.push_back(variable->getType());
+ StorageOffsets offsets;
+ offsets.computeOffsets(types);
+
+ vector<tuple<VariableDeclaration const*, u256, unsigned>> variablesAndOffsets;
+ for (size_t index = 0; index < variables.size(); ++index)
+ if (auto const* offset = offsets.getOffset(index))
+ variablesAndOffsets.push_back(make_tuple(variables[index], offset->first, offset->second));
+ return variablesAndOffsets;
+}
+
TypePointer StructType::unaryOperatorResult(Token::Value _operator) const
{
return _operator == Token::Delete ? make_shared<VoidType>() : TypePointer();