mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add isFallback() helper
This commit is contained in:
parent
53f747b7de
commit
9fc6eccc26
@ -93,7 +93,7 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
|
|||||||
FunctionDefinition const* fallbackFunction = nullptr;
|
FunctionDefinition const* fallbackFunction = nullptr;
|
||||||
for (FunctionDefinition const* function: _contract.definedFunctions())
|
for (FunctionDefinition const* function: _contract.definedFunctions())
|
||||||
{
|
{
|
||||||
if (function->name().empty())
|
if (function->isFallback())
|
||||||
{
|
{
|
||||||
if (fallbackFunction)
|
if (fallbackFunction)
|
||||||
{
|
{
|
||||||
@ -482,7 +482,7 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
|
|||||||
{
|
{
|
||||||
if (isLibraryFunction)
|
if (isLibraryFunction)
|
||||||
m_errorReporter.typeError(_function.location(), "Library functions cannot be payable.");
|
m_errorReporter.typeError(_function.location(), "Library functions cannot be payable.");
|
||||||
if (!_function.isConstructor() && !_function.name().empty() && !_function.isPartOfExternalInterface())
|
if (!_function.isConstructor() && !_function.isFallback() && !_function.isPartOfExternalInterface())
|
||||||
m_errorReporter.typeError(_function.location(), "Internal functions cannot be payable.");
|
m_errorReporter.typeError(_function.location(), "Internal functions cannot be payable.");
|
||||||
if (_function.isDeclaredConst())
|
if (_function.isDeclaredConst())
|
||||||
m_errorReporter.typeError(_function.location(), "Functions cannot be constant and payable at the same time.");
|
m_errorReporter.typeError(_function.location(), "Functions cannot be constant and payable at the same time.");
|
||||||
|
@ -162,7 +162,7 @@ FunctionDefinition const* ContractDefinition::fallbackFunction() const
|
|||||||
{
|
{
|
||||||
for (ContractDefinition const* contract: annotation().linearizedBaseContracts)
|
for (ContractDefinition const* contract: annotation().linearizedBaseContracts)
|
||||||
for (FunctionDefinition const* f: contract->definedFunctions())
|
for (FunctionDefinition const* f: contract->definedFunctions())
|
||||||
if (f->name().empty())
|
if (f->isFallback())
|
||||||
return f;
|
return f;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -589,6 +589,7 @@ public:
|
|||||||
virtual void accept(ASTConstVisitor& _visitor) const override;
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
||||||
|
|
||||||
bool isConstructor() const { return m_isConstructor; }
|
bool isConstructor() const { return m_isConstructor; }
|
||||||
|
bool isFallback() const { return name().empty(); }
|
||||||
bool isDeclaredConst() const { return m_isDeclaredConst; }
|
bool isDeclaredConst() const { return m_isDeclaredConst; }
|
||||||
bool isPayable() const { return m_isPayable; }
|
bool isPayable() const { return m_isPayable; }
|
||||||
std::vector<ASTPointer<ModifierInvocation>> const& modifiers() const { return m_functionModifiers; }
|
std::vector<ASTPointer<ModifierInvocation>> const& modifiers() const { return m_functionModifiers; }
|
||||||
@ -596,9 +597,9 @@ public:
|
|||||||
Block const& body() const { solAssert(m_body, ""); return *m_body; }
|
Block const& body() const { solAssert(m_body, ""); return *m_body; }
|
||||||
virtual bool isVisibleInContract() const override
|
virtual bool isVisibleInContract() const override
|
||||||
{
|
{
|
||||||
return Declaration::isVisibleInContract() && !isConstructor() && !name().empty();
|
return Declaration::isVisibleInContract() && !isConstructor() && !isFallback();
|
||||||
}
|
}
|
||||||
virtual bool isPartOfExternalInterface() const override { return isPublic() && !m_isConstructor && !name().empty(); }
|
virtual bool isPartOfExternalInterface() const override { return isPublic() && !isConstructor() && !isFallback(); }
|
||||||
|
|
||||||
/// @returns the external signature of the function
|
/// @returns the external signature of the function
|
||||||
/// That consists of the name of the function followed by the types of the
|
/// That consists of the name of the function followed by the types of the
|
||||||
|
@ -935,7 +935,7 @@ Json::Value CompilerStack::gasEstimates(string const& _contractName) const
|
|||||||
for (auto const& it: contract.definedFunctions())
|
for (auto const& it: contract.definedFunctions())
|
||||||
{
|
{
|
||||||
/// Exclude externally visible functions, constructor and the fallback function
|
/// Exclude externally visible functions, constructor and the fallback function
|
||||||
if (it->isPartOfExternalInterface() || it->isConstructor() || it->name().empty())
|
if (it->isPartOfExternalInterface() || it->isConstructor() || it->isFallback())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
size_t entry = functionEntryPoint(_contractName, *it);
|
size_t entry = functionEntryPoint(_contractName, *it);
|
||||||
@ -943,12 +943,14 @@ Json::Value CompilerStack::gasEstimates(string const& _contractName) const
|
|||||||
if (entry > 0)
|
if (entry > 0)
|
||||||
gas = GasEstimator::functionalEstimation(*items, entry, *it);
|
gas = GasEstimator::functionalEstimation(*items, entry, *it);
|
||||||
|
|
||||||
|
/// TODO: This could move into a method shared with externalSignature()
|
||||||
FunctionType type(*it);
|
FunctionType type(*it);
|
||||||
string sig = it->name() + "(";
|
string sig = it->name() + "(";
|
||||||
auto paramTypes = type.parameterTypes();
|
auto paramTypes = type.parameterTypes();
|
||||||
for (auto it = paramTypes.begin(); it != paramTypes.end(); ++it)
|
for (auto it = paramTypes.begin(); it != paramTypes.end(); ++it)
|
||||||
sig += (*it)->toString() + (it + 1 == paramTypes.end() ? "" : ",");
|
sig += (*it)->toString() + (it + 1 == paramTypes.end() ? "" : ",");
|
||||||
sig += ")";
|
sig += ")";
|
||||||
|
|
||||||
internalFunctions[sig] = gasToJson(gas);
|
internalFunctions[sig] = gasToJson(gas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user