2017-08-28 17:48:34 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2017-08-28 17:48:34 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <libsolidity/ast/ASTEnums.h>
|
|
|
|
#include <libsolidity/ast/ASTForward.h>
|
|
|
|
#include <libsolidity/ast/ASTVisitor.h>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2019-10-28 10:39:30 +00:00
|
|
|
#include <optional>
|
2017-08-28 17:48:34 +00:00
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::langutil
|
2018-11-14 16:11:55 +00:00
|
|
|
{
|
|
|
|
class ErrorReporter;
|
|
|
|
struct SourceLocation;
|
|
|
|
}
|
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::frontend
|
2017-08-28 17:48:34 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
class ViewPureChecker: private ASTConstVisitor
|
|
|
|
{
|
|
|
|
public:
|
2018-11-14 16:11:55 +00:00
|
|
|
ViewPureChecker(std::vector<std::shared_ptr<ASTNode>> const& _ast, langutil::ErrorReporter& _errorReporter):
|
2017-08-28 17:48:34 +00:00
|
|
|
m_ast(_ast), m_errorReporter(_errorReporter) {}
|
|
|
|
|
|
|
|
bool check();
|
|
|
|
|
|
|
|
private:
|
2018-07-26 19:45:24 +00:00
|
|
|
struct MutabilityAndLocation
|
|
|
|
{
|
|
|
|
StateMutability mutability;
|
2018-11-14 16:11:55 +00:00
|
|
|
langutil::SourceLocation location;
|
2018-07-26 19:45:24 +00:00
|
|
|
};
|
2017-08-28 17:48:34 +00:00
|
|
|
|
2022-03-11 16:01:30 +00:00
|
|
|
bool visit(ImportDirective const&) override;
|
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
bool visit(FunctionDefinition const& _funDef) override;
|
|
|
|
void endVisit(FunctionDefinition const& _funDef) override;
|
2022-07-06 07:17:59 +00:00
|
|
|
void endVisit(BinaryOperation const& _binaryOperation) override;
|
|
|
|
void endVisit(UnaryOperation const& _unaryOperation) override;
|
2018-11-16 01:09:04 +00:00
|
|
|
bool visit(ModifierDefinition const& _modifierDef) override;
|
|
|
|
void endVisit(ModifierDefinition const& _modifierDef) override;
|
|
|
|
void endVisit(Identifier const& _identifier) override;
|
|
|
|
bool visit(MemberAccess const& _memberAccess) override;
|
|
|
|
void endVisit(MemberAccess const& _memberAccess) override;
|
|
|
|
void endVisit(IndexAccess const& _indexAccess) override;
|
2019-09-03 16:30:00 +00:00
|
|
|
void endVisit(IndexRangeAccess const& _indexAccess) override;
|
2018-11-16 01:09:04 +00:00
|
|
|
void endVisit(ModifierInvocation const& _modifier) override;
|
|
|
|
void endVisit(FunctionCall const& _functionCall) override;
|
|
|
|
void endVisit(InlineAssembly const& _inlineAssembly) override;
|
2017-08-28 17:48:34 +00:00
|
|
|
|
|
|
|
/// Called when an element of mutability @a _mutability is encountered.
|
|
|
|
/// Creates appropriate warnings and errors and sets @a m_currentBestMutability.
|
2018-07-26 19:45:24 +00:00
|
|
|
void reportMutability(
|
|
|
|
StateMutability _mutability,
|
2018-11-14 16:11:55 +00:00
|
|
|
langutil::SourceLocation const& _location,
|
2019-10-28 10:39:30 +00:00
|
|
|
std::optional<langutil::SourceLocation> const& _nestedLocation = {}
|
2018-07-26 19:45:24 +00:00
|
|
|
);
|
2017-08-28 17:48:34 +00:00
|
|
|
|
2022-07-12 10:00:23 +00:00
|
|
|
void reportFunctionCallMutability(StateMutability _mutability, langutil::SourceLocation const& _location);
|
|
|
|
|
2020-08-04 08:38:31 +00:00
|
|
|
/// Determines the mutability of modifier if not already cached.
|
|
|
|
MutabilityAndLocation const& modifierMutability(ModifierDefinition const& _modifier);
|
|
|
|
|
2017-08-28 17:48:34 +00:00
|
|
|
std::vector<std::shared_ptr<ASTNode>> const& m_ast;
|
2018-11-14 16:11:55 +00:00
|
|
|
langutil::ErrorReporter& m_errorReporter;
|
2017-08-28 17:48:34 +00:00
|
|
|
|
|
|
|
bool m_errors = false;
|
2018-11-14 16:11:55 +00:00
|
|
|
MutabilityAndLocation m_bestMutabilityAndLocation = MutabilityAndLocation{StateMutability::Payable, langutil::SourceLocation()};
|
2017-08-28 17:48:34 +00:00
|
|
|
FunctionDefinition const* m_currentFunction = nullptr;
|
2018-07-26 19:45:24 +00:00
|
|
|
std::map<ModifierDefinition const*, MutabilityAndLocation> m_inferredMutability;
|
2017-08-28 17:48:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|