diff options
author | Christian <c@ethdev.com> | 2015-01-17 01:52:27 +0800 |
---|---|---|
committer | Christian <c@ethdev.com> | 2015-01-20 06:35:04 +0800 |
commit | e6c0a9b922a28001fcbdc4e4ee729659c987caef (patch) | |
tree | 3f74de859e357b84b8489aa8332a1b8e67abb281 | |
parent | 6633fbb6030cda64bd5c16ac5d59bbaad71967b2 (diff) | |
download | dexon-solidity-e6c0a9b922a28001fcbdc4e4ee729659c987caef.tar dexon-solidity-e6c0a9b922a28001fcbdc4e4ee729659c987caef.tar.gz dexon-solidity-e6c0a9b922a28001fcbdc4e4ee729659c987caef.tar.bz2 dexon-solidity-e6c0a9b922a28001fcbdc4e4ee729659c987caef.tar.lz dexon-solidity-e6c0a9b922a28001fcbdc4e4ee729659c987caef.tar.xz dexon-solidity-e6c0a9b922a28001fcbdc4e4ee729659c987caef.tar.zst dexon-solidity-e6c0a9b922a28001fcbdc4e4ee729659c987caef.zip |
Magic variables are only needed durinng name and type resolution, not during compilation.
-rw-r--r-- | Compiler.cpp | 10 | ||||
-rw-r--r-- | Compiler.h | 6 | ||||
-rw-r--r-- | CompilerStack.cpp | 4 | ||||
-rw-r--r-- | GlobalContext.cpp | 12 | ||||
-rw-r--r-- | GlobalContext.h | 2 |
5 files changed, 9 insertions, 25 deletions
diff --git a/Compiler.cpp b/Compiler.cpp index bd6571b9..d86c939c 100644 --- a/Compiler.cpp +++ b/Compiler.cpp @@ -34,11 +34,11 @@ using namespace std; namespace dev { namespace solidity { -void Compiler::compileContract(ContractDefinition const& _contract, vector<MagicVariableDeclaration const*> const& _magicGlobals, +void Compiler::compileContract(ContractDefinition const& _contract, map<ContractDefinition const*, bytes const*> const& _contracts) { m_context = CompilerContext(); // clear it just in case - initializeContext(_contract, _magicGlobals, _contracts); + initializeContext(_contract, _contracts); for (ASTPointer<FunctionDefinition> const& function: _contract.getDefinedFunctions()) if (function->getName() != _contract.getName()) // don't add the constructor here @@ -51,16 +51,14 @@ void Compiler::compileContract(ContractDefinition const& _contract, vector<Magic // Swap the runtime context with the creation-time context swap(m_context, m_runtimeContext); - initializeContext(_contract, _magicGlobals, _contracts); + initializeContext(_contract, _contracts); packIntoContractCreator(_contract, m_runtimeContext); } -void Compiler::initializeContext(ContractDefinition const& _contract, vector<MagicVariableDeclaration const*> const& _magicGlobals, +void Compiler::initializeContext(ContractDefinition const& _contract, map<ContractDefinition const*, bytes const*> const& _contracts) { m_context.setCompiledContracts(_contracts); - for (MagicVariableDeclaration const* variable: _magicGlobals) - m_context.addMagicGlobal(*variable); registerStateVariables(_contract); } @@ -32,15 +32,15 @@ class Compiler: private ASTConstVisitor public: explicit Compiler(bool _optimize = false): m_optimize(_optimize), m_context(), m_returnTag(m_context.newTag()) {} - void compileContract(ContractDefinition const& _contract, std::vector<MagicVariableDeclaration const*> const& _magicGlobals, + void compileContract(ContractDefinition const& _contract, std::map<ContractDefinition const*, bytes const*> const& _contracts); bytes getAssembledBytecode() { return m_context.getAssembledBytecode(m_optimize); } bytes getRuntimeBytecode() { return m_runtimeContext.getAssembledBytecode(m_optimize);} void streamAssembly(std::ostream& _stream) const { m_context.streamAssembly(_stream); } private: - /// Registers the global objects and the non-function objects inside the contract with the context. - void initializeContext(ContractDefinition const& _contract, std::vector<MagicVariableDeclaration const*> const& _magicGlobals, + /// Registers the non-function objects inside the contract with the context. + void initializeContext(ContractDefinition const& _contract, std::map<ContractDefinition const*, bytes const*> const& _contracts); /// Adds the code that is run at creation time. Should be run after exchanging the run-time context /// with a new and initialized context. diff --git a/CompilerStack.cpp b/CompilerStack.cpp index 5532d74b..790eb983 100644 --- a/CompilerStack.cpp +++ b/CompilerStack.cpp @@ -113,10 +113,8 @@ void CompilerStack::compile(bool _optimize) for (ASTPointer<ASTNode> const& node: source->ast->getNodes()) if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) { - m_globalContext->setCurrentContract(*contract); shared_ptr<Compiler> compiler = make_shared<Compiler>(_optimize); - compiler->compileContract(*contract, m_globalContext->getMagicVariables(), - contractBytecode); + compiler->compileContract(*contract, contractBytecode); Contract& compiledContract = m_contracts[contract->getName()]; compiledContract.bytecode = compiler->getAssembledBytecode(); compiledContract.runtimeBytecode = compiler->getRuntimeBytecode(); diff --git a/GlobalContext.cpp b/GlobalContext.cpp index 92ca9548..c7eea92d 100644 --- a/GlobalContext.cpp +++ b/GlobalContext.cpp @@ -68,7 +68,7 @@ void GlobalContext::setCurrentContract(ContractDefinition const& _contract) vector<Declaration const*> GlobalContext::getDeclarations() const { vector<Declaration const*> declarations; - declarations.reserve(m_magicVariables.size() + 1); + declarations.reserve(m_magicVariables.size()); for (ASTPointer<Declaration const> const& variable: m_magicVariables) declarations.push_back(variable.get()); return declarations; @@ -83,15 +83,5 @@ MagicVariableDeclaration const* GlobalContext::getCurrentThis() const } -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; -} - } } diff --git a/GlobalContext.h b/GlobalContext.h index c6e35f50..dfdc6662 100644 --- a/GlobalContext.h +++ b/GlobalContext.h @@ -49,8 +49,6 @@ public: void setCurrentContract(ContractDefinition const& _contract); MagicVariableDeclaration const* getCurrentThis() const; - /// @returns all magic variables. - std::vector<MagicVariableDeclaration const*> getMagicVariables() const; /// @returns a vector of all implicit global declarations excluding "this". std::vector<Declaration const*> getDeclarations() const; |