mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Magic variables are only needed durinng name and type resolution, not during compilation.
This commit is contained in:
parent
6633fbb603
commit
e6c0a9b922
10
Compiler.cpp
10
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.
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user