mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Split out override checker into its own file.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/ast/ASTForward.h>
|
||||
#include <libsolidity/analysis/OverrideChecker.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
@@ -47,6 +48,7 @@ public:
|
||||
|
||||
/// @param _errorReporter provides the error logging functionality.
|
||||
explicit ContractLevelChecker(langutil::ErrorReporter& _errorReporter):
|
||||
m_overrideChecker{_errorReporter},
|
||||
m_errorReporter(_errorReporter)
|
||||
{}
|
||||
|
||||
@@ -55,47 +57,12 @@ public:
|
||||
bool check(ContractDefinition const& _contract);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Comparator that compares
|
||||
* - functions such that equality means that the functions override each other
|
||||
* - modifiers by name
|
||||
* - contracts by AST id.
|
||||
*/
|
||||
struct LessFunction
|
||||
{
|
||||
bool operator()(ModifierDefinition const* _a, ModifierDefinition const* _b) const;
|
||||
bool operator()(FunctionDefinition const* _a, FunctionDefinition const* _b) const;
|
||||
bool operator()(ContractDefinition const* _a, ContractDefinition const* _b) const;
|
||||
};
|
||||
|
||||
using FunctionMultiSet = std::multiset<FunctionDefinition const*, LessFunction>;
|
||||
using ModifierMultiSet = std::multiset<ModifierDefinition const*, LessFunction>;
|
||||
|
||||
/// Checks that two functions defined in this contract with the same name have different
|
||||
/// arguments and that there is at most one constructor.
|
||||
void checkDuplicateFunctions(ContractDefinition const& _contract);
|
||||
void checkDuplicateEvents(ContractDefinition const& _contract);
|
||||
template <class T>
|
||||
void findDuplicateDefinitions(std::map<std::string, std::vector<T>> const& _definitions, std::string _message);
|
||||
void checkIllegalOverrides(ContractDefinition const& _contract);
|
||||
/// Performs various checks related to @a _overriding overriding @a _super like
|
||||
/// different return type, invalid visibility change, etc.
|
||||
/// Works on functions, modifiers and public state variables.
|
||||
/// Also stores @a _super as a base function of @a _function in its AST annotations.
|
||||
template<class T, class U>
|
||||
void checkOverride(T const& _overriding, U const& _super);
|
||||
void overrideListError(
|
||||
CallableDeclaration const& _callable,
|
||||
std::set<ContractDefinition const*, LessFunction> _secondary,
|
||||
std::string const& _message1,
|
||||
std::string const& _message2
|
||||
);
|
||||
void overrideError(
|
||||
Declaration const& _overriding,
|
||||
Declaration const& _super,
|
||||
std::string _message,
|
||||
std::string _secondaryMsg = "Overridden function is here:"
|
||||
);
|
||||
void checkAbstractFunctions(ContractDefinition const& _contract);
|
||||
/// Checks that the base constructor arguments are properly provided.
|
||||
/// Fills the list of unimplemented functions in _contract's annotations.
|
||||
@@ -114,35 +81,12 @@ private:
|
||||
void checkLibraryRequirements(ContractDefinition const& _contract);
|
||||
/// Checks base contracts for ABI compatibility
|
||||
void checkBaseABICompatibility(ContractDefinition const& _contract);
|
||||
/// Checks for functions in different base contracts which conflict with each
|
||||
/// other and thus need to be overridden explicitly.
|
||||
void checkAmbiguousOverrides(ContractDefinition const& _contract) const;
|
||||
void checkAmbiguousOverridesInternal(std::set<
|
||||
CallableDeclaration const*,
|
||||
std::function<bool(CallableDeclaration const*, CallableDeclaration const*)>
|
||||
> _baseCallables, langutil::SourceLocation const& _location) const;
|
||||
/// Resolves an override list of UserDefinedTypeNames to a list of contracts.
|
||||
std::set<ContractDefinition const*, LessFunction> resolveOverrideList(OverrideSpecifier const& _overrides) const;
|
||||
|
||||
template <class T>
|
||||
void checkOverrideList(
|
||||
std::multiset<T const*, LessFunction> const& _funcSet,
|
||||
T const& _function
|
||||
);
|
||||
|
||||
/// Returns all functions of bases that have not yet been overwritten.
|
||||
/// May contain the same function multiple times when used with shared bases.
|
||||
FunctionMultiSet const& inheritedFunctions(ContractDefinition const& _contract) const;
|
||||
ModifierMultiSet const& inheritedModifiers(ContractDefinition const& _contract) const;
|
||||
|
||||
/// Warns if the contract has a payable fallback, but no receive ether function.
|
||||
void checkPayableFallbackWithoutReceive(ContractDefinition const& _contract);
|
||||
|
||||
OverrideChecker m_overrideChecker;
|
||||
langutil::ErrorReporter& m_errorReporter;
|
||||
|
||||
/// Cache for inheritedFunctions().
|
||||
std::map<ContractDefinition const*, FunctionMultiSet> mutable m_inheritedFunctions;
|
||||
std::map<ContractDefinition const*, ModifierMultiSet> mutable m_contractBaseModifiers;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user