Paweł Bylica
10 years ago
52 changed files with 3159 additions and 644 deletions
@ -0,0 +1,101 @@ |
|||||
|
/*
|
||||
|
This file is part of cpp-ethereum. |
||||
|
|
||||
|
cpp-ethereum is free software: you can redistribute it and/or modify |
||||
|
it under the terms of the GNU General Public License as published by |
||||
|
the Free Software Foundation, either version 3 of the License, or |
||||
|
(at your option) any later version. |
||||
|
|
||||
|
cpp-ethereum is distributed in the hope that it will be useful, |
||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
GNU General Public License for more details. |
||||
|
|
||||
|
You should have received a copy of the GNU General Public License |
||||
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
/**
|
||||
|
* @author Christian <c@ethdev.com> |
||||
|
* @date 2014 |
||||
|
* Container of the (implicit and explicit) global objects. |
||||
|
*/ |
||||
|
|
||||
|
#include <memory> |
||||
|
#include <libsolidity/GlobalContext.h> |
||||
|
#include <libsolidity/AST.h> |
||||
|
#include <libsolidity/Types.h> |
||||
|
|
||||
|
using namespace std; |
||||
|
|
||||
|
namespace dev |
||||
|
{ |
||||
|
namespace solidity |
||||
|
{ |
||||
|
|
||||
|
GlobalContext::GlobalContext(): |
||||
|
m_magicVariables{make_shared<MagicVariableDeclaration>("block", make_shared<MagicType>(MagicType::Kind::BLOCK)), |
||||
|
make_shared<MagicVariableDeclaration>("msg", make_shared<MagicType>(MagicType::Kind::MSG)), |
||||
|
make_shared<MagicVariableDeclaration>("tx", make_shared<MagicType>(MagicType::Kind::TX)), |
||||
|
make_shared<MagicVariableDeclaration>("suicide", |
||||
|
make_shared<FunctionType>(TypePointers({std::make_shared<IntegerType>(0, |
||||
|
IntegerType::Modifier::ADDRESS)}), |
||||
|
TypePointers(), |
||||
|
FunctionType::Location::SUICIDE)), |
||||
|
make_shared<MagicVariableDeclaration>("sha3", |
||||
|
make_shared<FunctionType>(TypePointers({std::make_shared<IntegerType>(256, IntegerType::Modifier::HASH)}), |
||||
|
TypePointers({std::make_shared<IntegerType>(256, IntegerType::Modifier::HASH)}), |
||||
|
FunctionType::Location::SHA3)), |
||||
|
make_shared<MagicVariableDeclaration>("sha256", |
||||
|
make_shared<FunctionType>(TypePointers({std::make_shared<IntegerType>(256, IntegerType::Modifier::HASH)}), |
||||
|
TypePointers({std::make_shared<IntegerType>(256, IntegerType::Modifier::HASH)}), |
||||
|
FunctionType::Location::SHA256)), |
||||
|
make_shared<MagicVariableDeclaration>("ecrecover", |
||||
|
make_shared<FunctionType>(TypePointers({std::make_shared<IntegerType>(256, IntegerType::Modifier::HASH), |
||||
|
std::make_shared<IntegerType>(8, IntegerType::Modifier::HASH), |
||||
|
std::make_shared<IntegerType>(256, IntegerType::Modifier::HASH), |
||||
|
std::make_shared<IntegerType>(256, IntegerType::Modifier::HASH)}), |
||||
|
TypePointers({std::make_shared<IntegerType>(0, IntegerType::Modifier::ADDRESS)}), |
||||
|
FunctionType::Location::ECRECOVER)), |
||||
|
make_shared<MagicVariableDeclaration>("ripemd160", |
||||
|
make_shared<FunctionType>(TypePointers({std::make_shared<IntegerType>(256, IntegerType::Modifier::HASH)}), |
||||
|
TypePointers({std::make_shared<IntegerType>(256, IntegerType::Modifier::HASH)}), |
||||
|
FunctionType::Location::RIPEMD160))} |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
void GlobalContext::setCurrentContract(ContractDefinition const& _contract) |
||||
|
{ |
||||
|
m_currentContract = &_contract; |
||||
|
} |
||||
|
|
||||
|
vector<Declaration*> GlobalContext::getDeclarations() const |
||||
|
{ |
||||
|
vector<Declaration*> declarations; |
||||
|
declarations.reserve(m_magicVariables.size() + 1); |
||||
|
for (ASTPointer<Declaration> const& variable: m_magicVariables) |
||||
|
declarations.push_back(variable.get()); |
||||
|
declarations.push_back(getCurrentThis()); |
||||
|
return declarations; |
||||
|
} |
||||
|
|
||||
|
MagicVariableDeclaration*GlobalContext::getCurrentThis() const |
||||
|
{ |
||||
|
if (!m_thisPointer[m_currentContract]) |
||||
|
m_thisPointer[m_currentContract] = make_shared<MagicVariableDeclaration>( |
||||
|
"this", make_shared<ContractType>(*m_currentContract)); |
||||
|
return m_thisPointer[m_currentContract].get(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
vector<MagicVariableDeclaration const*> GlobalContext::getMagicVariables() const |
||||
|
{ |
||||
|
vector<MagicVariableDeclaration const*> declarations; |
||||
|
declarations.reserve(m_magicVariables.size() + 1); |
||||
|
for (ASTPointer<MagicVariableDeclaration const> const& variable: m_magicVariables) |
||||
|
declarations.push_back(variable.get()); |
||||
|
declarations.push_back(getCurrentThis()); |
||||
|
return declarations; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,62 @@ |
|||||
|
/*
|
||||
|
This file is part of cpp-ethereum. |
||||
|
|
||||
|
cpp-ethereum is free software: you can redistribute it and/or modify |
||||
|
it under the terms of the GNU General Public License as published by |
||||
|
the Free Software Foundation, either version 3 of the License, or |
||||
|
(at your option) any later version. |
||||
|
|
||||
|
cpp-ethereum is distributed in the hope that it will be useful, |
||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
GNU General Public License for more details. |
||||
|
|
||||
|
You should have received a copy of the GNU General Public License |
||||
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
*/ |
||||
|
/**
|
||||
|
* @author Christian <c@ethdev.com> |
||||
|
* @date 2014 |
||||
|
* Container of the (implicit and explicit) global objects. |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <string> |
||||
|
#include <vector> |
||||
|
#include <map> |
||||
|
#include <memory> |
||||
|
#include <boost/noncopyable.hpp> |
||||
|
#include <libsolidity/ASTForward.h> |
||||
|
|
||||
|
namespace dev |
||||
|
{ |
||||
|
namespace solidity |
||||
|
{ |
||||
|
|
||||
|
class Type; // forward
|
||||
|
|
||||
|
/**
|
||||
|
* Container for all global objects which look like AST nodes, but are not part of the AST |
||||
|
* that is currently being compiled. |
||||
|
* @note must not be destroyed or moved during compilation as its objects can be referenced from |
||||
|
* other objects. |
||||
|
*/ |
||||
|
class GlobalContext: private boost::noncopyable |
||||
|
{ |
||||
|
public: |
||||
|
GlobalContext(); |
||||
|
void setCurrentContract(ContractDefinition const& _contract); |
||||
|
|
||||
|
std::vector<MagicVariableDeclaration const*> getMagicVariables() const; |
||||
|
std::vector<Declaration*> getDeclarations() const; |
||||
|
|
||||
|
private: |
||||
|
MagicVariableDeclaration* getCurrentThis() const; |
||||
|
std::vector<std::shared_ptr<MagicVariableDeclaration>> m_magicVariables; |
||||
|
ContractDefinition const* m_currentContract; |
||||
|
std::map<ContractDefinition const*, std::shared_ptr<MagicVariableDeclaration>> mutable m_thisPointer; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
{ |
||||
|
"makeMoney" : { |
||||
|
"env" : { |
||||
|
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", |
||||
|
"currentNumber" : "0", |
||||
|
"currentGasLimit" : "1000000", |
||||
|
"currentDifficulty" : "256", |
||||
|
"currentTimestamp" : 1, |
||||
|
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" |
||||
|
}, |
||||
|
"pre" : { |
||||
|
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : { |
||||
|
"balance" : "1000000000000000000", |
||||
|
"nonce" : 0, |
||||
|
"code" : "{ (MSTORE 0 0x601080600c6000396000f20060003554156009570060203560003555) (CALL 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec 0xaaaaaaaaace5edbc8e2a8697c15331677e6ebf0b 23 0 0 0 0) }", |
||||
|
"storage": {} |
||||
|
}, |
||||
|
"aaaaaaaaace5edbc8e2a8697c15331677e6ebf0b" : { |
||||
|
"balance" : "1000000000000000000", |
||||
|
"nonce" : 0, |
||||
|
"code" : "0x600160015532600255", |
||||
|
"storage": {} |
||||
|
}, |
||||
|
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { |
||||
|
"balance" : "1000", |
||||
|
"nonce" : 0, |
||||
|
"code" : "", |
||||
|
"storage": {} |
||||
|
} |
||||
|
}, |
||||
|
"transaction" : { |
||||
|
"nonce" : "0", |
||||
|
"gasPrice" : "1", |
||||
|
"gasLimit" : "850", |
||||
|
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", |
||||
|
"value" : "10", |
||||
|
"secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", |
||||
|
"data" : "" |
||||
|
} |
||||
|
} |
||||
|
} |
File diff suppressed because it is too large
Loading…
Reference in new issue