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
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
2019-03-19 16:12:21 +00:00
|
|
|
#include <boost/optional.hpp>
|
|
|
|
|
2015-09-16 14:56:30 +00:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
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
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
namespace yul
|
|
|
|
{
|
2019-05-22 11:57:48 +00:00
|
|
|
struct AsmAnalysisInfo;
|
|
|
|
struct Identifier;
|
|
|
|
struct Dialect;
|
2018-11-21 11:42:34 +00:00
|
|
|
}
|
|
|
|
|
2015-09-16 14:56:30 +00:00
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
|
|
|
|
|
|
|
class Type;
|
2019-04-15 13:33:39 +00:00
|
|
|
using TypePointer = Type const*;
|
2015-09-16 14:56:30 +00:00
|
|
|
|
|
|
|
struct ASTAnnotation
|
|
|
|
{
|
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.
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DocumentedAnnotation
|
|
|
|
{
|
2018-12-12 13:51:22 +00:00
|
|
|
virtual ~DocumentedAnnotation() = default;
|
2015-10-26 14:13:36 +00:00
|
|
|
/// Mapping docstring tag name -> content.
|
|
|
|
std::multimap<std::string, DocTag> docTags;
|
|
|
|
};
|
|
|
|
|
2015-12-15 14:46:03 +00:00
|
|
|
struct SourceUnitAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// The "absolute" (in the compiler sense) path of this source unit.
|
|
|
|
std::string path;
|
|
|
|
/// The exported symbols (all global symbols).
|
|
|
|
std::map<ASTString, std::vector<Declaration const*>> exportedSymbols;
|
2017-08-08 13:09:57 +00:00
|
|
|
/// Experimental features.
|
|
|
|
std::set<ExperimentalFeature> experimentalFeatures;
|
2015-12-15 14:46:03 +00:00
|
|
|
};
|
|
|
|
|
2015-12-09 16:35:20 +00:00
|
|
|
struct ImportAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// The absolute path of the source unit to import.
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2015-10-05 15:19:23 +00:00
|
|
|
struct TypeDeclarationAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// The name of this type, prefixed by proper namespaces if globally accessible.
|
|
|
|
std::string canonicalName;
|
|
|
|
};
|
|
|
|
|
2015-10-26 14:13:36 +00:00
|
|
|
struct ContractDefinitionAnnotation: TypeDeclarationAnnotation, DocumentedAnnotation
|
2015-09-21 16:55:58 +00:00
|
|
|
{
|
2017-08-04 19:38:45 +00:00
|
|
|
/// List of functions without a body. Can also contain functions from base classes.
|
2017-07-10 09:47:12 +00:00
|
|
|
std::vector<FunctionDefinition const*> unimplementedFunctions;
|
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;
|
2015-10-07 13:57:17 +00:00
|
|
|
/// List of contracts this contract creates, i.e. which need to be compiled first.
|
|
|
|
/// Also includes all contracts from @a linearizedBaseContracts.
|
|
|
|
std::set<ContractDefinition const*> contractDependencies;
|
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;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
2015-10-26 14:13:36 +00:00
|
|
|
struct FunctionDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation
|
|
|
|
{
|
2017-08-29 15:07:32 +00:00
|
|
|
/// The function this function overrides, if any. This is always the closest
|
|
|
|
/// in the linearized inheritance hierarchy.
|
|
|
|
FunctionDefinition const* superFunction = nullptr;
|
2015-10-26 14:13:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct EventDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ModifierDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
struct VariableDeclarationAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// Type of variable (type of identifier referencing this variable).
|
2019-04-15 13:33:39 +00:00
|
|
|
TypePointer type = nullptr;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
2015-10-26 16:20:29 +00:00
|
|
|
struct StatementAnnotation: ASTAnnotation, DocumentedAnnotation
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
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;
|
2017-04-21 17:13:46 +00:00
|
|
|
bool isSlot = false; ///< Whether the storage slot of a variable is queried.
|
|
|
|
bool isOffset = false; ///< Whether the intra-slot offset of a storage variable is queried.
|
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
|
|
|
};
|
|
|
|
|
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.
|
2019-04-15 13:33:39 +00:00
|
|
|
TypePointer type = nullptr;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct UserDefinedTypeNameAnnotation: TypeNameAnnotation
|
|
|
|
{
|
|
|
|
/// Referenced declaration, set during reference resolution stage.
|
|
|
|
Declaration const* referencedDeclaration = nullptr;
|
2015-11-16 23:06:57 +00:00
|
|
|
/// Stores a reference to the current contract.
|
|
|
|
/// This is needed because types of base contracts change depending on the context.
|
|
|
|
ContractDefinition const* contractScope = nullptr;
|
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.
|
2019-04-15 13:33:39 +00:00
|
|
|
TypePointer type = nullptr;
|
2016-12-13 02:59:53 +00:00
|
|
|
/// Whether the expression is a constant variable
|
|
|
|
bool isConstant = false;
|
2017-03-01 18:12:40 +00:00
|
|
|
/// Whether the expression is pure, i.e. compile-time constant.
|
|
|
|
bool isPure = false;
|
2015-09-21 16:55:58 +00:00
|
|
|
/// Whether it is an LValue (i.e. something that can be assigned to).
|
2015-09-16 14:56:30 +00:00
|
|
|
bool isLValue = false;
|
2015-09-21 16:55:58 +00:00
|
|
|
/// Whether the expression is used in a context where the LValue is actually required.
|
2015-09-16 14:56:30 +00:00
|
|
|
bool lValueRequested = false;
|
2019-03-19 16:12:21 +00:00
|
|
|
|
|
|
|
/// Types and - if given - names of arguments if the expr. is a function
|
|
|
|
/// that is called, used for overload resoultion
|
|
|
|
boost::optional<FuncCallArguments> arguments;
|
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;
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BinaryOperationAnnotation: ExpressionAnnotation
|
|
|
|
{
|
|
|
|
/// The common type that is used for the operation, not necessarily the result type (which
|
|
|
|
/// e.g. for comparisons is bool).
|
2019-04-15 13:33:39 +00:00
|
|
|
TypePointer commonType = nullptr;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
2017-05-19 13:45:01 +00:00
|
|
|
enum class FunctionCallKind
|
|
|
|
{
|
|
|
|
Unset,
|
|
|
|
FunctionCall,
|
|
|
|
TypeConversion,
|
|
|
|
StructConstructorCall
|
|
|
|
};
|
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
struct FunctionCallAnnotation: ExpressionAnnotation
|
|
|
|
{
|
2017-05-19 13:45:01 +00:00
|
|
|
FunctionCallKind kind = FunctionCallKind::Unset;
|
2015-09-16 14:56:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|