solidity/libsolidity/analysis/ReferencesResolver.h

112 lines
3.7 KiB
C
Raw Normal View History

/*
2019-02-13 15:56:46 +00:00
This file is part of solidity.
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.
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.
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/>.
*/
// SPDX-License-Identifier: GPL-3.0
/**
* @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>
#include <liblangutil/EVMVersion.h>
#include <libyul/optimiser/ASTWalker.h>
2018-12-17 11:30:08 +00:00
#include <list>
#include <map>
2019-12-11 16:31:36 +00:00
namespace solidity::langutil
{
class ErrorReporter;
struct SourceLocation;
}
2019-12-11 16:31:36 +00:00
namespace solidity::frontend
{
class NameAndTypeResolver;
/**
* Resolves references to declarations (of variables and types) and also establishes the link
* between a return statement and the return parameter list.
*/
class ReferencesResolver: private ASTConstVisitor, private yul::ASTWalker
{
public:
ReferencesResolver(
langutil::ErrorReporter& _errorReporter,
NameAndTypeResolver& _resolver,
langutil::EVMVersion _evmVersion,
bool _resolveInsideCode = false
2015-10-26 16:31:35 +00:00
):
m_errorReporter(_errorReporter),
2015-10-26 16:31:35 +00:00
m_resolver(_resolver),
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.
bool resolve(ASTNode const& _root);
private:
using yul::ASTWalker::visit;
using yul::ASTWalker::operator();
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;
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;
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;
void endVisit(IdentifierPath const& _path) override;
bool visit(InlineAssembly const& _inlineAssembly) override;
bool visit(Return const& _return) override;
bool visit(UsingForDirective const& _usingFor) override;
2023-06-14 10:48:38 +00:00
bool visit(BinaryOperation const& _binaryOperation) override;
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);
/// Checks if the name contains a '.'.
void validateYulIdentifierName(yul::YulString _name, langutil::SourceLocation const& _location);
langutil::ErrorReporter& m_errorReporter;
NameAndTypeResolver& m_resolver;
langutil::EVMVersion m_evmVersion;
2023-06-14 10:48:38 +00:00
/// Stack of function definitions.
std::vector<FunctionDefinition const*> m_functionDefinitions;
2015-11-06 16:22:46 +00:00
bool const m_resolveInsideCode;
InlineAssemblyAnnotation* m_yulAnnotation = nullptr;
bool m_yulInsideFunction = false;
2023-06-14 10:48:38 +00:00
bool m_typeContext = false;
};
}