2015-09-16 14:56:30 +00:00
|
|
|
/*
|
2019-02-13 15:56:46 +00:00
|
|
|
This file is part of solidity.
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2019-02-13 15:56:46 +00:00
|
|
|
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.
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2019-02-13 15:56:46 +00:00
|
|
|
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.
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2019-02-13 15:56:46 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
2015-09-16 14:56:30 +00:00
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2015-09-16 14:56:30 +00:00
|
|
|
/**
|
|
|
|
* @author Christian <c@ethdev.com>
|
|
|
|
* @date 2014
|
|
|
|
* Component that resolves type names to types and annotates the AST accordingly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/ast/ASTVisitor.h>
|
|
|
|
#include <libsolidity/ast/ASTAnnotations.h>
|
2019-11-14 11:44:33 +00:00
|
|
|
#include <liblangutil/EVMVersion.h>
|
2019-12-19 12:13:48 +00:00
|
|
|
#include <libyul/optimiser/ASTWalker.h>
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2018-12-17 11:30:08 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
|
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
|
2015-09-16 14:56:30 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
class NameAndTypeResolver;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves references to declarations (of variables and types) and also establishes the link
|
|
|
|
* between a return statement and the return parameter list.
|
|
|
|
*/
|
2019-12-19 12:13:48 +00:00
|
|
|
class ReferencesResolver: private ASTConstVisitor, private yul::ASTWalker
|
2015-09-16 14:56:30 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ReferencesResolver(
|
2018-11-14 16:11:55 +00:00
|
|
|
langutil::ErrorReporter& _errorReporter,
|
2015-09-16 14:56:30 +00:00
|
|
|
NameAndTypeResolver& _resolver,
|
2019-11-14 11:44:33 +00:00
|
|
|
langutil::EVMVersion _evmVersion,
|
2015-09-16 14:56:30 +00:00
|
|
|
bool _resolveInsideCode = false
|
2015-10-26 16:31:35 +00:00
|
|
|
):
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter(_errorReporter),
|
2015-10-26 16:31:35 +00:00
|
|
|
m_resolver(_resolver),
|
2019-11-14 11:44:33 +00:00
|
|
|
m_evmVersion(_evmVersion),
|
2015-10-26 16:31:35 +00:00
|
|
|
m_resolveInsideCode(_resolveInsideCode)
|
|
|
|
{}
|
|
|
|
|
2017-02-16 11:36:43 +00:00
|
|
|
/// @returns true if no errors during resolving and throws exceptions on fatal errors.
|
2015-11-23 22:57:17 +00:00
|
|
|
bool resolve(ASTNode const& _root);
|
2015-09-16 14:56:30 +00:00
|
|
|
|
|
|
|
private:
|
2019-12-19 12:13:48 +00:00
|
|
|
using yul::ASTWalker::visit;
|
|
|
|
using yul::ASTWalker::operator();
|
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
bool visit(Block const& _block) override;
|
|
|
|
void endVisit(Block const& _block) override;
|
2020-03-08 16:27:43 +00:00
|
|
|
bool visit(TryCatchClause const& _tryCatchClause) override;
|
|
|
|
void endVisit(TryCatchClause const& _tryCatchClause) override;
|
2018-11-16 01:09:04 +00:00
|
|
|
bool visit(ForStatement const& _for) override;
|
|
|
|
void endVisit(ForStatement const& _for) override;
|
|
|
|
void endVisit(VariableDeclarationStatement const& _varDeclStatement) override;
|
2020-06-29 12:30:09 +00:00
|
|
|
bool visit(VariableDeclaration const& _varDecl) override;
|
2018-11-16 01:09:04 +00:00
|
|
|
bool visit(Identifier const& _identifier) override;
|
|
|
|
bool visit(FunctionDefinition const& _functionDefinition) override;
|
|
|
|
void endVisit(FunctionDefinition const& _functionDefinition) override;
|
|
|
|
bool visit(ModifierDefinition const& _modifierDefinition) override;
|
|
|
|
void endVisit(ModifierDefinition const& _modifierDefinition) override;
|
2020-08-11 09:18:22 +00:00
|
|
|
void endVisit(IdentifierPath const& _path) override;
|
2018-11-16 01:09:04 +00:00
|
|
|
bool visit(InlineAssembly const& _inlineAssembly) override;
|
|
|
|
bool visit(Return const& _return) override;
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2019-12-19 12:13:48 +00:00
|
|
|
void operator()(yul::FunctionDefinition const& _function) override;
|
|
|
|
void operator()(yul::Identifier const& _identifier) override;
|
|
|
|
void operator()(yul::VariableDeclaration const& _varDecl) override;
|
|
|
|
|
2020-06-29 12:30:09 +00:00
|
|
|
void resolveInheritDoc(StructuredDocumentation const& _documentation, StructurallyDocumentedAnnotation& _annotation);
|
|
|
|
|
2020-07-02 12:38:36 +00:00
|
|
|
/// Checks if the name contains a '.'.
|
|
|
|
void validateYulIdentifierName(yul::YulString _name, langutil::SourceLocation const& _location);
|
|
|
|
|
2018-11-14 16:11:55 +00:00
|
|
|
langutil::ErrorReporter& m_errorReporter;
|
2015-09-16 14:56:30 +00:00
|
|
|
NameAndTypeResolver& m_resolver;
|
2019-11-14 11:44:33 +00:00
|
|
|
langutil::EVMVersion m_evmVersion;
|
2017-01-27 17:27:59 +00:00
|
|
|
/// Stack of return parameters.
|
|
|
|
std::vector<ParameterList const*> m_returnParameters;
|
2015-11-06 16:22:46 +00:00
|
|
|
bool const m_resolveInsideCode;
|
2019-12-19 12:13:48 +00:00
|
|
|
|
|
|
|
InlineAssemblyAnnotation* m_yulAnnotation = nullptr;
|
|
|
|
bool m_yulInsideFunction = false;
|
2015-09-16 14:56:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|