Introduce contract inheritance

This commit is contained in:
Bhargava Shastry 2021-05-06 14:42:14 +02:00
parent d56dfcf750
commit 23e76926ea

View File

@ -229,12 +229,15 @@ string ContractGenerator::visit()
ostringstream os; ostringstream os;
string inheritance; string inheritance;
if (state->sourceUnitState[state->currentPath()]->contractType()) if (state->sourceUnitState[state->currentPath()]->contractType())
inheritance = state->sourceUnitState[state->currentPath()]->randomContract(); inheritance = state->currentSourceState()->randomContract();
string name = state->newContract(); string name = state->newContract();
state->updateContract(name); state->updateContract(name);
os << "contract " << name; os << "contract " << name;
if (!inheritance.empty()) if (!inheritance.empty())
{
os << " is " << inheritance; os << " is " << inheritance;
state->currentContractState()->functions += state->contractState[inheritance]->functions;
}
os << " {" << endl; os << " {" << endl;
set(); set();
os << visitChildren(); os << visitChildren();
@ -723,7 +726,7 @@ SolidityTypePtr TypeProvider::type()
case Type::ADDRESS: case Type::ADDRESS:
return make_shared<AddressType>(); return make_shared<AddressType>();
case Type::FUNCTION: case Type::FUNCTION:
return make_shared<FunctionType>(false); return make_shared<FunctionType>(true);
case Type::CONTRACT: case Type::CONTRACT:
if (state->sourceUnitState[state->currentPath()]->contractType()) if (state->sourceUnitState[state->currentPath()]->contractType())
return state->sourceUnitState[state->currentPath()]->randomContractType(); return state->sourceUnitState[state->currentPath()]->randomContractType();
@ -840,6 +843,7 @@ string FunctionCallGenerator::callStmt(shared_ptr<FunctionState> _callee)
// Create lhs expression only if function outputs non-zero return values. // Create lhs expression only if function outputs non-zero return values.
if (!_callee->outputs.empty()) if (!_callee->outputs.empty())
lhsExpr = lhs(_callee->outputs); lhsExpr = lhs(_callee->outputs);
callStmtStream << indentation() callStmtStream << indentation()
<< lhsExpr << lhsExpr
<< rhsExpr; << rhsExpr;