diff options
author | Gav Wood <i@gavwood.com> | 2015-01-25 09:42:49 +0800 |
---|---|---|
committer | Gav Wood <i@gavwood.com> | 2015-01-25 09:42:49 +0800 |
commit | 5b576e869181c0f466e080d6d6476335d45c11e0 (patch) | |
tree | b060b876eeae8a781eec94d02c6979017c6b817d | |
parent | 376c6182ad813384af43bdf198c4afd596699750 (diff) | |
download | dexon-solidity-5b576e869181c0f466e080d6d6476335d45c11e0.tar dexon-solidity-5b576e869181c0f466e080d6d6476335d45c11e0.tar.gz dexon-solidity-5b576e869181c0f466e080d6d6476335d45c11e0.tar.bz2 dexon-solidity-5b576e869181c0f466e080d6d6476335d45c11e0.tar.lz dexon-solidity-5b576e869181c0f466e080d6d6476335d45c11e0.tar.xz dexon-solidity-5b576e869181c0f466e080d6d6476335d45c11e0.tar.zst dexon-solidity-5b576e869181c0f466e080d6d6476335d45c11e0.zip |
Fixes to ethereum.js and standard.js.
-rw-r--r-- | CompilerStack.cpp | 28 | ||||
-rw-r--r-- | CompilerStack.h | 3 |
2 files changed, 22 insertions, 9 deletions
diff --git a/CompilerStack.cpp b/CompilerStack.cpp index c0575616..86e97ef0 100644 --- a/CompilerStack.cpp +++ b/CompilerStack.cpp @@ -44,14 +44,14 @@ bool CompilerStack::addSource(string const& _name, string const& _content) { bool existed = m_sources.count(_name) != 0; reset(true); - m_sources[_name].scanner = make_shared<Scanner>(CharStream(_content), _name); + m_sources[_name].scanner = make_shared<Scanner>(CharStream(expanded(_content)), _name); return existed; } void CompilerStack::setSource(string const& _sourceCode) { reset(); - addSource("", _sourceCode); + addSource("", expanded(_sourceCode)); } void CompilerStack::parse() @@ -91,6 +91,7 @@ void CompilerStack::parse() void CompilerStack::parse(string const& _sourceCode) { setSource(_sourceCode); + addSources(StandardSources); parse(); } @@ -124,17 +125,26 @@ void CompilerStack::compile(bool _optimize) } } +const map<string, string> StandardSources = { +/* { "Config", "contract Config{function lookup(uint256 service)constant returns(address a){}function kill(){}function unregister(uint256 id){}function register(uint256 id,address service){}}" }, + { "owned", "contract owned{function owned(){owner = msg.sender;}address owner;}" }, + { "mortal", "import \"owned\";\ncontract mortal is owned {function kill() { if (msg.sender == owner) suicide(owner); }}" }, + { "NameReg", "contract NameReg{function register(string32 name){}function addressOf(string32 name)constant returns(address addr){}function unregister(){}function nameOf(address addr)constant returns(string32 name){}}" }, + { "named", "import \"Config\";\nimport \"NameReg\";\ncontract named is mortal, owned {function named(string32 name) {NameReg(Config().lookup(1)).register(name);}}" }, + { "std", "import \"owned\";\nimport \"mortal\";\nimport \"Config\";\nimport \"NameReg\";\nimport \"named\";\n" }, +*/}; + string CompilerStack::expanded(string const& _sourceCode) { - // TODO: populate some nicer way. - static const map<string, string> c_requires = { + const map<string, string> c_standardSources = { { "Config", "contract Config{function lookup(uint256 service)constant returns(address a){}function kill(){}function unregister(uint256 id){}function register(uint256 id,address service){}}" }, { "owned", "contract owned{function owned(){owner = msg.sender;}address owner;}" }, { "mortal", "#require owned\ncontract mortal is owned {function kill() { if (msg.sender == owner) suicide(owner); }}" }, { "NameReg", "contract NameReg{function register(string32 name){}function addressOf(string32 name)constant returns(address addr){}function unregister(){}function nameOf(address addr)constant returns(string32 name){}}" }, - { "named", "#require Config NameReg\ncontract named is mortal, owned {function named(string32 name) {NameReg(Config().lookup(1)).register(name);}" }, + { "named", "#require Config NameReg\ncontract named is mortal, owned {function named(string32 name) {NameReg(Config().lookup(1)).register(name);}}" }, { "std", "#require owned mortal Config NameReg named" }, }; + string sub; set<string> got; function<string(string const&)> localExpanded; @@ -151,14 +161,14 @@ string CompilerStack::expanded(string const& _sourceCode) for (auto const& r: rs) if (!got.count(r)) { - if (c_requires.count(r)) - sub.append("\n" + localExpanded(c_requires.at(r)) + "\n"); + if (c_standardSources.count(r)) + sub.append("\n" + localExpanded(c_standardSources.at(r)) + "\n"); got.insert(r); } } // TODO: remove once we have genesis contracts. else if ((p = ret.find("Config()")) != string::npos) - ret.replace(p, 8, "Config(0x661005d2720d855f1d9976f88bb10c1a3398c77f)"); + ret.replace(p, 8, "Config(0xc6d9d2cd449a754c494264e1809c50e34d64562b)"); return ret; }; return sub + localExpanded(_sourceCode); @@ -166,7 +176,7 @@ string CompilerStack::expanded(string const& _sourceCode) bytes const& CompilerStack::compile(string const& _sourceCode, bool _optimize) { - parse(expanded(_sourceCode)); + parse(_sourceCode); compile(_optimize); return getBytecode(); } diff --git a/CompilerStack.h b/CompilerStack.h index 68c82a35..09a1ad34 100644 --- a/CompilerStack.h +++ b/CompilerStack.h @@ -49,6 +49,8 @@ enum class DocumentationType: uint8_t ABI_SOLIDITY_INTERFACE }; +extern const std::map<std::string, std::string> StandardSources; + /** * Easy to use and self-contained Solidity compiler with as few header dependencies as possible. * It holds state and can be used to either step through the compilation stages (and abort e.g. @@ -61,6 +63,7 @@ public: /// Adds a source object (e.g. file) to the parser. After this, parse has to be called again. /// @returns true if a source object by the name already existed and was replaced. + void addSources(std::map<std::string, std::string> const& _nameContents) { for (auto const& i: _nameContents) addSource(i.first, i.second); } bool addSource(std::string const& _name, std::string const& _content); void setSource(std::string const& _sourceCode); /// Parses all source units that were added |