mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Refactor: Replace inheritance hierarchy by most derived contract.
This commit is contained in:
@@ -319,6 +319,37 @@ FunctionDefinitionAnnotation& FunctionDefinition::annotation() const
|
||||
return initAnnotation<FunctionDefinitionAnnotation>();
|
||||
}
|
||||
|
||||
FunctionDefinition const& FunctionDefinition::resolveVirtual(
|
||||
ContractDefinition const& _mostDerivedContract,
|
||||
ContractDefinition const* _searchStart
|
||||
) const
|
||||
{
|
||||
solAssert(!isConstructor(), "");
|
||||
// If we are not doing super-lookup and the function is not virtual, we can stop here.
|
||||
if (_searchStart == nullptr && !virtualSemantics())
|
||||
return *this;
|
||||
|
||||
solAssert(!dynamic_cast<ContractDefinition const&>(*scope()).isLibrary(), "");
|
||||
|
||||
FunctionType const* functionType = TypeProvider::function(*this)->asCallableFunction(false);
|
||||
|
||||
for (ContractDefinition const* c: _mostDerivedContract.annotation().linearizedBaseContracts)
|
||||
{
|
||||
if (_searchStart != nullptr && c != _searchStart)
|
||||
continue;
|
||||
_searchStart = nullptr;
|
||||
for (FunctionDefinition const* function: c->definedFunctions())
|
||||
if (
|
||||
function->name() == name() &&
|
||||
!function->isConstructor() &&
|
||||
FunctionType(*function).asCallableFunction(false)->hasEqualParameterTypes(*functionType)
|
||||
)
|
||||
return *function;
|
||||
}
|
||||
solAssert(false, "Virtual function " + name() + " not found.");
|
||||
return *this; // not reached
|
||||
}
|
||||
|
||||
TypePointer ModifierDefinition::type() const
|
||||
{
|
||||
return TypeProvider::modifier(*this);
|
||||
@@ -329,6 +360,33 @@ ModifierDefinitionAnnotation& ModifierDefinition::annotation() const
|
||||
return initAnnotation<ModifierDefinitionAnnotation>();
|
||||
}
|
||||
|
||||
ModifierDefinition const& ModifierDefinition::resolveVirtual(
|
||||
ContractDefinition const& _mostDerivedContract,
|
||||
ContractDefinition const* _searchStart
|
||||
) const
|
||||
{
|
||||
solAssert(_searchStart == nullptr, "Used super in connection with modifiers.");
|
||||
|
||||
// If we are not doing super-lookup and the modifier is not virtual, we can stop here.
|
||||
if (_searchStart == nullptr && !virtualSemantics())
|
||||
return *this;
|
||||
|
||||
solAssert(!dynamic_cast<ContractDefinition const&>(*scope()).isLibrary(), "");
|
||||
|
||||
for (ContractDefinition const* c: _mostDerivedContract.annotation().linearizedBaseContracts)
|
||||
{
|
||||
if (_searchStart != nullptr && c != _searchStart)
|
||||
continue;
|
||||
_searchStart = nullptr;
|
||||
for (ModifierDefinition const* modifier: c->functionModifiers())
|
||||
if (modifier->name() == name())
|
||||
return *modifier;
|
||||
}
|
||||
solAssert(false, "Virtual modifier " + name() + " not found.");
|
||||
return *this; // not reached
|
||||
}
|
||||
|
||||
|
||||
TypePointer EventDefinition::type() const
|
||||
{
|
||||
return TypeProvider::function(*this);
|
||||
|
||||
Reference in New Issue
Block a user