Beispiel #1
0
void Compiler::appendInitAndConstructorCode(ContractDefinition const& _contract)
{
	// Determine the arguments that are used for the base constructors.
	std::vector<ContractDefinition const*> const& bases = _contract.getLinearizedBaseContracts();
	for (ContractDefinition const* contract: bases)
	{
		if (FunctionDefinition const* constructor = contract->getConstructor())
			for (auto const& modifier: constructor->getModifiers())
			{
				auto baseContract = dynamic_cast<ContractDefinition const*>(
					&modifier->getName()->getReferencedDeclaration());
				if (baseContract)
					if (m_baseArguments.count(baseContract->getConstructor()) == 0)
						m_baseArguments[baseContract->getConstructor()] = &modifier->getArguments();
			}

		for (ASTPointer<InheritanceSpecifier> const& base: contract->getBaseContracts())
		{
			ContractDefinition const* baseContract = dynamic_cast<ContractDefinition const*>(
						&base->getName()->getReferencedDeclaration());
			solAssert(baseContract, "");

			if (m_baseArguments.count(baseContract->getConstructor()) == 0)
				m_baseArguments[baseContract->getConstructor()] = &base->getArguments();
		}
	}
	// Initialization of state variables in base-to-derived order.
	for (ContractDefinition const* contract: boost::adaptors::reverse(bases))
		initializeStateVariables(*contract);

	if (FunctionDefinition const* constructor = _contract.getConstructor())
		appendConstructor(*constructor);
	else if (auto c = m_context.getNextConstructor(_contract))
		appendBaseConstructor(*c);
}
Beispiel #2
0
void Compiler::initializeContext(ContractDefinition const& _contract,
								 map<ContractDefinition const*, bytes const*> const& _contracts)
{
	CompilerUtils(m_context).initialiseFreeMemoryPointer();
	m_context.setCompiledContracts(_contracts);
	m_context.setInheritanceHierarchy(_contract.getLinearizedBaseContracts());
	registerStateVariables(_contract);
	m_context.resetVisitedNodes(&_contract);
}