2015-09-16 14:56:30 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is free software: you can redistribute it and/or modify
|
2015-09-16 14:56:30 +00:00
|
|
|
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.
|
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
solidity is distributed in the hope that it will be useful,
|
2015-09-16 14:56:30 +00:00
|
|
|
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
|
2016-11-18 23:13:20 +00:00
|
|
|
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 2015
|
|
|
|
* Object containing the type and other annotations for the AST nodes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-26 13:41:08 +00:00
|
|
|
#include <libsolidity/ast/ASTForward.h>
|
2019-03-19 16:12:21 +00:00
|
|
|
#include <libsolidity/ast/ASTEnums.h>
|
2017-08-08 13:09:57 +00:00
|
|
|
#include <libsolidity/ast/ExperimentalFeatures.h>
|
2017-04-26 13:41:08 +00:00
|
|
|
|
2020-04-08 17:38:30 +00:00
|
|
|
#include <libsolutil/SetOnce.h>
|
|
|
|
|
2015-09-16 14:56:30 +00:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2019-10-28 10:39:30 +00:00
|
|
|
#include <optional>
|
2015-10-07 13:57:17 +00:00
|
|
|
#include <set>
|
2018-12-17 14:33:15 +00:00
|
|
|
#include <vector>
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::yul
|
2018-11-21 11:42:34 +00:00
|
|
|
{
|
2019-05-22 11:57:48 +00:00
|
|
|
struct AsmAnalysisInfo;
|
|
|
|
struct Identifier;
|
|
|
|
struct Dialect;
|
2018-11-21 11:42:34 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::frontend
|
2015-09-16 14:56:30 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
class Type;
|
2021-02-03 20:48:45 +00:00
|
|
|
class ArrayType;
|
2020-09-10 10:01:23 +00:00
|
|
|
using namespace util;
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2021-02-23 09:21:13 +00:00
|
|
|
struct CallGraph;
|
|
|
|
|
2015-09-16 14:56:30 +00:00
|
|
|
struct ASTAnnotation
|
|
|
|
{
|
2020-03-26 19:11:00 +00:00
|
|
|
ASTAnnotation() = default;
|
|
|
|
|
|
|
|
ASTAnnotation(ASTAnnotation const&) = delete;
|
|
|
|
ASTAnnotation(ASTAnnotation&&) = delete;
|
|
|
|
|
|
|
|
ASTAnnotation& operator=(ASTAnnotation const&) = delete;
|
|
|
|
ASTAnnotation& operator=(ASTAnnotation&&) = delete;
|
|
|
|
|
2018-12-12 13:51:22 +00:00
|
|
|
virtual ~ASTAnnotation() = default;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
2015-10-26 14:13:36 +00:00
|
|
|
struct DocTag
|
|
|
|
{
|
|
|
|
std::string content; ///< The text content of the tag.
|
|
|
|
std::string paramName; ///< Only used for @param, stores the parameter name.
|
|
|
|
};
|
|
|
|
|
2020-01-29 22:13:42 +00:00
|
|
|
struct StructurallyDocumentedAnnotation
|
2015-10-26 14:13:36 +00:00
|
|
|
{
|
2020-03-26 19:11:00 +00:00
|
|
|
StructurallyDocumentedAnnotation() = default;
|
|
|
|
|
|
|
|
StructurallyDocumentedAnnotation(StructurallyDocumentedAnnotation const&) = delete;
|
|
|
|
StructurallyDocumentedAnnotation(StructurallyDocumentedAnnotation&&) = delete;
|
|
|
|
|
|
|
|
StructurallyDocumentedAnnotation& operator=(StructurallyDocumentedAnnotation const&) = delete;
|
|
|
|
StructurallyDocumentedAnnotation& operator=(StructurallyDocumentedAnnotation&&) = delete;
|
|
|
|
|
2020-01-29 22:13:42 +00:00
|
|
|
virtual ~StructurallyDocumentedAnnotation() = default;
|
2020-03-26 19:11:00 +00:00
|
|
|
|
2015-10-26 14:13:36 +00:00
|
|
|
/// Mapping docstring tag name -> content.
|
|
|
|
std::multimap<std::string, DocTag> docTags;
|
2020-06-29 12:30:09 +00:00
|
|
|
/// contract that @inheritdoc references if it exists
|
|
|
|
ContractDefinition const* inheritdocReference = nullptr;
|
2015-10-26 14:13:36 +00:00
|
|
|
};
|
|
|
|
|
2015-12-15 14:46:03 +00:00
|
|
|
struct SourceUnitAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// The "absolute" (in the compiler sense) path of this source unit.
|
2020-09-10 10:01:23 +00:00
|
|
|
SetOnce<std::string> path;
|
2015-12-15 14:46:03 +00:00
|
|
|
/// The exported symbols (all global symbols).
|
2020-09-10 10:01:23 +00:00
|
|
|
SetOnce<std::map<ASTString, std::vector<Declaration const*>>> exportedSymbols;
|
2017-08-08 13:09:57 +00:00
|
|
|
/// Experimental features.
|
|
|
|
std::set<ExperimentalFeature> experimentalFeatures;
|
2020-11-26 21:33:36 +00:00
|
|
|
/// Using the new ABI coder. Set to `false` if using ABI coder v1.
|
2020-10-22 17:19:14 +00:00
|
|
|
SetOnce<bool> useABICoderV2;
|
2015-12-15 14:46:03 +00:00
|
|
|
};
|
|
|
|
|
2019-12-19 23:01:43 +00:00
|
|
|
struct ScopableAnnotation
|
|
|
|
{
|
2020-03-26 19:11:00 +00:00
|
|
|
ScopableAnnotation() = default;
|
|
|
|
|
|
|
|
ScopableAnnotation(ScopableAnnotation const&) = delete;
|
|
|
|
ScopableAnnotation(ScopableAnnotation&&) = delete;
|
|
|
|
|
|
|
|
ScopableAnnotation& operator=(ScopableAnnotation const&) = delete;
|
|
|
|
ScopableAnnotation& operator=(ScopableAnnotation&&) = delete;
|
|
|
|
|
|
|
|
virtual ~ScopableAnnotation() = default;
|
|
|
|
|
2019-12-19 23:01:43 +00:00
|
|
|
/// The scope this declaration resides in. Can be nullptr if it is the global scope.
|
2020-08-06 12:46:04 +00:00
|
|
|
/// Filled by the Scoper.
|
2019-12-19 23:01:43 +00:00
|
|
|
ASTNode const* scope = nullptr;
|
2020-01-14 13:00:51 +00:00
|
|
|
/// Pointer to the contract this declaration resides in. Can be nullptr if the current scope
|
2020-08-06 12:46:04 +00:00
|
|
|
/// is not part of a contract. Filled by the Scoper.
|
2020-01-14 13:00:51 +00:00
|
|
|
ContractDefinition const* contract = nullptr;
|
2019-12-19 23:01:43 +00:00
|
|
|
};
|
|
|
|
|
2019-12-19 23:04:46 +00:00
|
|
|
struct DeclarationAnnotation: ASTAnnotation, ScopableAnnotation
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2019-12-19 23:14:53 +00:00
|
|
|
struct ImportAnnotation: DeclarationAnnotation
|
2015-12-09 16:35:20 +00:00
|
|
|
{
|
|
|
|
/// The absolute path of the source unit to import.
|
2020-09-10 10:01:23 +00:00
|
|
|
SetOnce<std::string> absolutePath;
|
2015-12-15 14:46:03 +00:00
|
|
|
/// The actual source unit.
|
|
|
|
SourceUnit const* sourceUnit = nullptr;
|
2015-12-09 16:35:20 +00:00
|
|
|
};
|
|
|
|
|
2019-12-19 23:14:53 +00:00
|
|
|
struct TypeDeclarationAnnotation: DeclarationAnnotation
|
2015-10-05 15:19:23 +00:00
|
|
|
{
|
|
|
|
/// The name of this type, prefixed by proper namespaces if globally accessible.
|
2020-09-10 10:01:23 +00:00
|
|
|
SetOnce<std::string> canonicalName;
|
2015-10-05 15:19:23 +00:00
|
|
|
};
|
|
|
|
|
2020-04-14 14:36:37 +00:00
|
|
|
struct StructDeclarationAnnotation: TypeDeclarationAnnotation
|
|
|
|
{
|
2020-04-15 14:00:01 +00:00
|
|
|
/// Whether the struct is recursive, i.e. if the struct (recursively) contains a member that involves a struct of the same
|
|
|
|
/// type, either in a dynamic array, as member of another struct or inside a mapping.
|
|
|
|
/// Only cases in which the recursive occurrence is within a dynamic array or a mapping are valid, while direct
|
|
|
|
/// recursion immediately raises an error.
|
|
|
|
/// Will be filled in by the DeclarationTypeChecker.
|
2020-04-14 14:36:37 +00:00
|
|
|
std::optional<bool> recursive;
|
2020-06-03 10:38:35 +00:00
|
|
|
/// Whether the struct contains a mapping type, either directly or, indirectly inside another
|
|
|
|
/// struct or an array.
|
|
|
|
std::optional<bool> containsNestedMapping;
|
2020-04-14 14:36:37 +00:00
|
|
|
};
|
|
|
|
|
2020-01-29 22:13:42 +00:00
|
|
|
struct ContractDefinitionAnnotation: TypeDeclarationAnnotation, StructurallyDocumentedAnnotation
|
2015-09-21 16:55:58 +00:00
|
|
|
{
|
2020-04-15 10:42:15 +00:00
|
|
|
/// List of functions and modifiers without a body. Can also contain functions from base classes.
|
2020-09-10 10:01:23 +00:00
|
|
|
std::optional<std::vector<Declaration const*>> unimplementedDeclarations;
|
2015-09-21 16:55:58 +00:00
|
|
|
/// List of all (direct and indirect) base contracts in order from derived to
|
|
|
|
/// base, including the contract itself.
|
|
|
|
std::vector<ContractDefinition const*> linearizedBaseContracts;
|
2018-04-05 14:25:20 +00:00
|
|
|
/// Mapping containing the nodes that define the arguments for base constructors.
|
|
|
|
/// These can either be inheritance specifiers or modifier invocations.
|
|
|
|
std::map<FunctionDefinition const*, ASTNode const*> baseConstructorArguments;
|
2021-02-23 09:21:13 +00:00
|
|
|
/// A graph with edges representing calls between functions that may happen during contract construction.
|
|
|
|
SetOnce<std::shared_ptr<CallGraph const>> creationCallGraph;
|
|
|
|
/// A graph with edges representing calls between functions that may happen in a deployed contract.
|
|
|
|
SetOnce<std::shared_ptr<CallGraph const>> deployedCallGraph;
|
2020-10-29 14:07:09 +00:00
|
|
|
|
|
|
|
/// List of contracts whose bytecode is referenced by this contract, e.g. through "new".
|
|
|
|
/// The Value represents the ast node that referenced the contract.
|
|
|
|
std::map<ContractDefinition const*, ASTNode const*, ASTCompareByID<ContractDefinition>> contractDependencies;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
2019-12-19 23:14:53 +00:00
|
|
|
struct CallableDeclarationAnnotation: DeclarationAnnotation
|
2019-12-09 15:54:52 +00:00
|
|
|
{
|
|
|
|
/// The set of functions/modifiers/events this callable overrides.
|
|
|
|
std::set<CallableDeclaration const*> baseFunctions;
|
|
|
|
};
|
|
|
|
|
2020-01-29 22:13:42 +00:00
|
|
|
struct FunctionDefinitionAnnotation: CallableDeclarationAnnotation, StructurallyDocumentedAnnotation
|
2015-10-26 14:13:36 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2020-01-29 22:13:42 +00:00
|
|
|
struct EventDefinitionAnnotation: CallableDeclarationAnnotation, StructurallyDocumentedAnnotation
|
2015-10-26 14:13:36 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2021-01-28 11:56:22 +00:00
|
|
|
struct ErrorDefinitionAnnotation: CallableDeclarationAnnotation, StructurallyDocumentedAnnotation
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-01-29 22:13:42 +00:00
|
|
|
struct ModifierDefinitionAnnotation: CallableDeclarationAnnotation, StructurallyDocumentedAnnotation
|
2015-10-26 14:13:36 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2020-03-05 20:59:26 +00:00
|
|
|
struct VariableDeclarationAnnotation: DeclarationAnnotation, StructurallyDocumentedAnnotation
|
2015-09-21 16:55:58 +00:00
|
|
|
{
|
|
|
|
/// Type of variable (type of identifier referencing this variable).
|
2021-03-22 16:12:05 +00:00
|
|
|
Type const* type = nullptr;
|
2019-12-10 08:48:01 +00:00
|
|
|
/// The set of functions this (public state) variable overrides.
|
|
|
|
std::set<CallableDeclaration const*> baseFunctions;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
2020-01-29 22:13:42 +00:00
|
|
|
struct StatementAnnotation: ASTAnnotation
|
2015-10-26 16:20:29 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2016-03-01 21:56:39 +00:00
|
|
|
struct InlineAssemblyAnnotation: StatementAnnotation
|
|
|
|
{
|
2017-03-14 14:41:23 +00:00
|
|
|
struct ExternalIdentifierInfo
|
|
|
|
{
|
|
|
|
Declaration const* declaration = nullptr;
|
2021-09-22 10:06:57 +00:00
|
|
|
/// Suffix used, one of "slot", "offset", "length", "address", "selector" or empty.
|
2020-11-05 13:39:39 +00:00
|
|
|
std::string suffix;
|
2017-03-14 14:41:23 +00:00
|
|
|
size_t valueSize = size_t(-1);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Mapping containing resolved references to external identifiers and their value size
|
2018-11-21 11:42:34 +00:00
|
|
|
std::map<yul::Identifier const*, ExternalIdentifierInfo> externalReferences;
|
2017-04-26 13:41:08 +00:00
|
|
|
/// Information generated during analysis phase.
|
2018-11-21 11:42:34 +00:00
|
|
|
std::shared_ptr<yul::AsmAnalysisInfo> analysisInfo;
|
2016-03-01 21:56:39 +00:00
|
|
|
};
|
|
|
|
|
2019-12-20 01:20:27 +00:00
|
|
|
struct BlockAnnotation: StatementAnnotation, ScopableAnnotation
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TryCatchClauseAnnotation: ASTAnnotation, ScopableAnnotation
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ForStatementAnnotation: StatementAnnotation, ScopableAnnotation
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2015-10-26 16:20:29 +00:00
|
|
|
struct ReturnAnnotation: StatementAnnotation
|
2015-09-21 16:55:58 +00:00
|
|
|
{
|
|
|
|
/// Reference to the return parameters of the function.
|
|
|
|
ParameterList const* functionReturnParameters = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TypeNameAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// Type declared by this type name, i.e. type of a variable where this type name is used.
|
|
|
|
/// Set during reference resolution stage.
|
2021-03-22 16:12:05 +00:00
|
|
|
Type const* type = nullptr;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
2020-08-11 09:18:22 +00:00
|
|
|
struct IdentifierPathAnnotation: ASTAnnotation
|
2015-09-21 16:55:58 +00:00
|
|
|
{
|
|
|
|
/// Referenced declaration, set during reference resolution stage.
|
|
|
|
Declaration const* referencedDeclaration = nullptr;
|
2020-08-11 09:18:22 +00:00
|
|
|
/// What kind of lookup needs to be done (static, virtual, super) find the declaration.
|
|
|
|
SetOnce<VirtualLookup> requiredLookup;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
struct ExpressionAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// Inferred type of the expression.
|
2021-03-22 16:12:05 +00:00
|
|
|
Type const* type = nullptr;
|
2016-12-13 02:59:53 +00:00
|
|
|
/// Whether the expression is a constant variable
|
2020-09-10 10:01:23 +00:00
|
|
|
SetOnce<bool> isConstant;
|
2017-03-01 18:12:40 +00:00
|
|
|
/// Whether the expression is pure, i.e. compile-time constant.
|
2020-09-10 10:01:23 +00:00
|
|
|
SetOnce<bool> isPure;
|
2015-09-21 16:55:58 +00:00
|
|
|
/// Whether it is an LValue (i.e. something that can be assigned to).
|
2020-09-10 10:01:23 +00:00
|
|
|
SetOnce<bool> isLValue;
|
2015-09-21 16:55:58 +00:00
|
|
|
/// Whether the expression is used in a context where the LValue is actually required.
|
2020-04-09 10:48:57 +00:00
|
|
|
bool willBeWrittenTo = false;
|
2020-03-10 17:15:50 +00:00
|
|
|
/// Whether the expression is an lvalue that is only assigned.
|
|
|
|
/// Would be false for --, ++, delete, +=, -=, ....
|
2020-10-05 10:21:30 +00:00
|
|
|
/// Only relevant if isLvalue == true
|
2020-10-14 19:00:18 +00:00
|
|
|
bool lValueOfOrdinaryAssignment = false;
|
2019-03-19 16:12:21 +00:00
|
|
|
|
|
|
|
/// Types and - if given - names of arguments if the expr. is a function
|
2020-05-24 17:41:15 +00:00
|
|
|
/// that is called, used for overload resolution
|
2019-10-28 10:39:30 +00:00
|
|
|
std::optional<FuncCallArguments> arguments;
|
2020-11-24 11:27:55 +00:00
|
|
|
|
|
|
|
/// True if the expression consists solely of the name of the function and the function is called immediately
|
|
|
|
/// instead of being stored or processed. The name may be qualified with the name of a contract, library
|
|
|
|
/// module, etc., that clarifies the scope. For example: `m.L.f()`, where `m` is a module, `L` is a library
|
|
|
|
/// and `f` is a function is a direct call. This means that the function to be called is known at compilation
|
|
|
|
/// time and it's not necessary to rely on any runtime dispatch mechanism to resolve it.
|
|
|
|
/// Note that even the simplest expressions, like `(f)()`, result in an indirect call even if they consist of
|
|
|
|
/// values known at compilation time.
|
|
|
|
bool calledDirectly = false;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IdentifierAnnotation: ExpressionAnnotation
|
|
|
|
{
|
|
|
|
/// Referenced declaration, set at latest during overload resolution stage.
|
2015-09-16 14:56:30 +00:00
|
|
|
Declaration const* referencedDeclaration = nullptr;
|
2020-09-16 09:00:07 +00:00
|
|
|
/// What kind of lookup needs to be done (static, virtual, super) find the declaration.
|
|
|
|
SetOnce<VirtualLookup> requiredLookup;
|
2020-04-07 17:31:48 +00:00
|
|
|
/// List of possible declarations it could refer to (can contain duplicates).
|
|
|
|
std::vector<Declaration const*> candidateDeclarations;
|
2015-09-21 16:55:58 +00:00
|
|
|
/// List of possible declarations it could refer to.
|
2015-09-16 14:56:30 +00:00
|
|
|
std::vector<Declaration const*> overloadedDeclarations;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MemberAccessAnnotation: ExpressionAnnotation
|
|
|
|
{
|
|
|
|
/// Referenced declaration, set at latest during overload resolution stage.
|
|
|
|
Declaration const* referencedDeclaration = nullptr;
|
2020-09-16 09:00:07 +00:00
|
|
|
/// What kind of lookup needs to be done (static, virtual, super) find the declaration.
|
|
|
|
SetOnce<VirtualLookup> requiredLookup;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BinaryOperationAnnotation: ExpressionAnnotation
|
|
|
|
{
|
|
|
|
/// The common type that is used for the operation, not necessarily the result type (which
|
|
|
|
/// e.g. for comparisons is bool).
|
2021-03-22 16:12:05 +00:00
|
|
|
Type const* commonType = nullptr;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
2017-05-19 13:45:01 +00:00
|
|
|
enum class FunctionCallKind
|
|
|
|
{
|
|
|
|
FunctionCall,
|
|
|
|
TypeConversion,
|
|
|
|
StructConstructorCall
|
|
|
|
};
|
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
struct FunctionCallAnnotation: ExpressionAnnotation
|
|
|
|
{
|
2020-04-08 17:38:30 +00:00
|
|
|
util::SetOnce<FunctionCallKind> kind;
|
2019-09-02 14:17:02 +00:00
|
|
|
/// If true, this is the external call of a try statement.
|
|
|
|
bool tryCall = false;
|
2015-09-16 14:56:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|