2014-10-07 16:25:04 +00:00
|
|
|
/*
|
2019-02-13 15:56:46 +00:00
|
|
|
This file is part of solidity.
|
2014-10-07 16:25:04 +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.
|
2014-10-07 16:25:04 +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.
|
2014-10-07 16:25:04 +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/>.
|
2014-10-07 16:25:04 +00:00
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2014-10-07 16:25:04 +00:00
|
|
|
/**
|
|
|
|
* @author Christian <c@ethdev.com>
|
|
|
|
* @date 2014
|
|
|
|
* Solidity abstract syntax tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/ast/ASTForward.h>
|
|
|
|
#include <libsolidity/ast/Types.h>
|
|
|
|
#include <libsolidity/ast/ASTAnnotations.h>
|
2017-07-01 09:09:24 +00:00
|
|
|
#include <libsolidity/ast/ASTEnums.h>
|
2018-12-17 14:33:15 +00:00
|
|
|
#include <libsolidity/parsing/Token.h>
|
2017-07-13 09:33:06 +00:00
|
|
|
|
2018-11-14 13:59:30 +00:00
|
|
|
#include <liblangutil/SourceLocation.h>
|
2017-07-13 09:33:06 +00:00
|
|
|
#include <libevmasm/Instruction.h>
|
2020-01-06 10:52:23 +00:00
|
|
|
#include <libsolutil/FixedHash.h>
|
2020-05-13 17:57:20 +00:00
|
|
|
#include <libsolutil/LazyInit.h>
|
2014-10-07 16:25:04 +00:00
|
|
|
|
2017-07-13 09:33:06 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
2018-12-17 14:33:15 +00:00
|
|
|
#include <json/json.h>
|
2017-07-13 09:33:06 +00:00
|
|
|
|
2018-12-17 14:33:15 +00:00
|
|
|
#include <memory>
|
2019-10-28 10:39:30 +00:00
|
|
|
#include <optional>
|
2017-07-13 09:33:06 +00:00
|
|
|
#include <string>
|
2020-04-01 03:04:29 +00:00
|
|
|
#include <utility>
|
2017-07-13 09:33:06 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::yul
|
2018-11-21 11:42:34 +00:00
|
|
|
{
|
2020-10-29 14:00:27 +00:00
|
|
|
// Forward-declaration to <yul/AST.h>
|
2018-11-21 11:42:34 +00:00
|
|
|
struct Block;
|
2019-05-22 11:57:48 +00:00
|
|
|
struct Dialect;
|
2018-11-21 11:42:34 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::frontend
|
2014-10-16 12:08:54 +00:00
|
|
|
{
|
2014-10-07 16:25:04 +00:00
|
|
|
|
2014-10-10 14:37:54 +00:00
|
|
|
class ASTVisitor;
|
2014-12-06 01:19:10 +00:00
|
|
|
class ASTConstVisitor;
|
2014-10-07 16:25:04 +00:00
|
|
|
|
2014-10-22 18:35:35 +00:00
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* The root (abstract) class of the AST inheritance tree.
|
|
|
|
* It is possible to traverse all direct and indirect children of an AST node by calling
|
|
|
|
* accept, providing an ASTVisitor.
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class ASTNode: private boost::noncopyable
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-03-10 17:15:50 +00:00
|
|
|
struct CompareByID
|
|
|
|
{
|
|
|
|
using is_transparent = void;
|
|
|
|
|
|
|
|
bool operator()(ASTNode const* _lhs, ASTNode const* _rhs) const
|
|
|
|
{
|
|
|
|
return _lhs->id() < _rhs->id();
|
|
|
|
}
|
|
|
|
bool operator()(ASTNode const* _lhs, int64_t _rhs) const
|
|
|
|
{
|
|
|
|
return _lhs->id() < _rhs;
|
|
|
|
}
|
|
|
|
bool operator()(int64_t _lhs, ASTNode const* _rhs) const
|
|
|
|
{
|
|
|
|
return _lhs < _rhs->id();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-14 16:11:55 +00:00
|
|
|
using SourceLocation = langutil::SourceLocation;
|
|
|
|
|
2020-04-01 03:04:29 +00:00
|
|
|
explicit ASTNode(int64_t _id, SourceLocation _location);
|
2019-11-27 17:03:09 +00:00
|
|
|
virtual ~ASTNode() {}
|
2014-10-09 13:57:49 +00:00
|
|
|
|
2017-01-17 09:31:09 +00:00
|
|
|
/// @returns an identifier of this AST node that is unique for a single compilation run.
|
2020-06-02 13:42:46 +00:00
|
|
|
int64_t id() const { return int64_t(m_id); }
|
2017-01-17 09:31:09 +00:00
|
|
|
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) = 0;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const = 0;
|
2014-10-10 14:37:54 +00:00
|
|
|
template <class T>
|
2015-11-23 22:57:17 +00:00
|
|
|
static void listAccept(std::vector<T> const& _list, ASTVisitor& _visitor)
|
2014-10-16 12:08:54 +00:00
|
|
|
{
|
2015-11-23 22:57:17 +00:00
|
|
|
for (T const& element: _list)
|
2019-05-28 15:24:54 +00:00
|
|
|
if (element)
|
|
|
|
element->accept(_visitor);
|
2014-10-10 14:37:54 +00:00
|
|
|
}
|
2014-12-05 16:29:20 +00:00
|
|
|
template <class T>
|
2015-11-23 22:57:17 +00:00
|
|
|
static void listAccept(std::vector<T> const& _list, ASTConstVisitor& _visitor)
|
2014-12-05 16:29:20 +00:00
|
|
|
{
|
2015-11-23 22:57:17 +00:00
|
|
|
for (T const& element: _list)
|
2019-05-28 15:24:54 +00:00
|
|
|
if (element)
|
|
|
|
element->accept(_visitor);
|
2014-12-05 16:29:20 +00:00
|
|
|
}
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2015-11-26 16:28:44 +00:00
|
|
|
/// @returns a copy of the vector containing only the nodes which derive from T.
|
2020-02-17 17:44:39 +00:00
|
|
|
template <class T>
|
|
|
|
static std::vector<T const*> filteredNodes(std::vector<ASTPointer<ASTNode>> const& _nodes);
|
2015-11-26 16:28:44 +00:00
|
|
|
|
2014-10-22 18:35:35 +00:00
|
|
|
/// Returns the source code location of this node.
|
2015-08-31 16:44:29 +00:00
|
|
|
SourceLocation const& location() const { return m_location; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2015-09-16 14:56:30 +00:00
|
|
|
///@todo make this const-safe by providing a different way to access the annotation
|
2015-09-21 16:55:58 +00:00
|
|
|
virtual ASTAnnotation& annotation() const;
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2014-10-20 10:41:56 +00:00
|
|
|
///@{
|
2014-10-22 18:35:35 +00:00
|
|
|
///@name equality operators
|
2014-10-20 10:41:56 +00:00
|
|
|
/// Equality relies on the fact that nodes cannot be copied.
|
|
|
|
bool operator==(ASTNode const& _other) const { return this == &_other; }
|
|
|
|
bool operator!=(ASTNode const& _other) const { return !operator==(_other); }
|
|
|
|
///@}
|
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
protected:
|
2017-01-20 14:56:56 +00:00
|
|
|
size_t const m_id = 0;
|
2019-12-21 04:10:01 +00:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
T& initAnnotation() const
|
|
|
|
{
|
|
|
|
if (!m_annotation)
|
|
|
|
m_annotation = std::make_unique<T>();
|
|
|
|
return dynamic_cast<T&>(*m_annotation);
|
|
|
|
}
|
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2019-12-21 04:10:01 +00:00
|
|
|
/// Annotation - is specialised in derived classes, is created upon request (because of polymorphism).
|
|
|
|
mutable std::unique_ptr<ASTAnnotation> m_annotation;
|
2015-02-23 16:14:59 +00:00
|
|
|
SourceLocation m_location;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2020-02-17 17:44:39 +00:00
|
|
|
template <class T>
|
|
|
|
std::vector<T const*> ASTNode::filteredNodes(std::vector<ASTPointer<ASTNode>> const& _nodes)
|
2015-11-26 16:28:44 +00:00
|
|
|
{
|
2020-02-17 17:44:39 +00:00
|
|
|
std::vector<T const*> ret;
|
2015-11-26 16:28:44 +00:00
|
|
|
for (auto const& n: _nodes)
|
2020-02-17 17:44:39 +00:00
|
|
|
if (auto const* nt = dynamic_cast<T const*>(n.get()))
|
2015-11-26 16:28:44 +00:00
|
|
|
ret.push_back(nt);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-08-06 12:46:04 +00:00
|
|
|
/**
|
|
|
|
* Abstract marker class that specifies that this AST node opens a scope.
|
|
|
|
*/
|
|
|
|
class ScopeOpener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ScopeOpener() = default;
|
|
|
|
};
|
|
|
|
|
2014-12-03 06:46:55 +00:00
|
|
|
/**
|
|
|
|
* Source unit containing import directives and contract definitions.
|
|
|
|
*/
|
2020-08-06 12:46:04 +00:00
|
|
|
class SourceUnit: public ASTNode, public ScopeOpener
|
2014-12-03 06:46:55 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-05-12 09:56:28 +00:00
|
|
|
SourceUnit(
|
|
|
|
int64_t _id,
|
|
|
|
SourceLocation const& _location,
|
|
|
|
std::optional<std::string> _licenseString,
|
|
|
|
std::vector<ASTPointer<ASTNode>> _nodes
|
|
|
|
):
|
|
|
|
ASTNode(_id, _location), m_licenseString(std::move(_licenseString)), m_nodes(std::move(_nodes)) {}
|
2014-12-03 06:46:55 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
SourceUnitAnnotation& annotation() const override;
|
2014-12-03 06:46:55 +00:00
|
|
|
|
2020-05-12 09:56:28 +00:00
|
|
|
std::optional<std::string> const& licenseString() const { return m_licenseString; }
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<ASTPointer<ASTNode>> nodes() const { return m_nodes; }
|
2014-12-03 06:46:55 +00:00
|
|
|
|
2017-07-12 23:17:25 +00:00
|
|
|
/// @returns a set of referenced SourceUnits. Recursively if @a _recurse is true.
|
2017-07-13 00:07:23 +00:00
|
|
|
std::set<SourceUnit const*> referencedSourceUnits(bool _recurse = false, std::set<SourceUnit const*> _skipList = std::set<SourceUnit const*>()) const;
|
2017-07-12 23:08:28 +00:00
|
|
|
|
2014-12-03 06:46:55 +00:00
|
|
|
private:
|
2020-05-12 09:56:28 +00:00
|
|
|
std::optional<std::string> m_licenseString;
|
2014-12-03 06:46:55 +00:00
|
|
|
std::vector<ASTPointer<ASTNode>> m_nodes;
|
|
|
|
};
|
|
|
|
|
2018-02-09 15:53:25 +00:00
|
|
|
/**
|
|
|
|
* Abstract class that is added to each AST node that is stored inside a scope
|
|
|
|
* (including scopes).
|
|
|
|
*/
|
|
|
|
class Scopable
|
|
|
|
{
|
|
|
|
public:
|
2018-05-02 11:29:16 +00:00
|
|
|
virtual ~Scopable() = default;
|
2018-02-09 15:53:25 +00:00
|
|
|
/// @returns the scope this declaration resides in. Can be nullptr if it is the global scope.
|
|
|
|
/// Available only after name and type resolution step.
|
2019-12-20 01:49:43 +00:00
|
|
|
ASTNode const* scope() const { return annotation().scope; }
|
2018-02-09 15:53:25 +00:00
|
|
|
|
2018-02-14 00:48:40 +00:00
|
|
|
/// @returns the source unit this scopable is present in.
|
|
|
|
SourceUnit const& sourceUnit() const;
|
|
|
|
|
2019-05-07 09:51:32 +00:00
|
|
|
/// @returns the function or modifier definition this scopable is present in or nullptr.
|
|
|
|
CallableDeclaration const* functionOrModifierDefinition() const;
|
|
|
|
|
2018-02-14 00:48:40 +00:00
|
|
|
/// @returns the source name this scopable is present in.
|
|
|
|
/// Can be combined with annotation().canonicalName (if present) to form a globally unique name.
|
|
|
|
std::string sourceUnitName() const;
|
|
|
|
|
2019-12-20 01:49:43 +00:00
|
|
|
virtual ScopableAnnotation& annotation() const = 0;
|
2018-02-09 15:53:25 +00:00
|
|
|
};
|
|
|
|
|
2014-12-03 06:46:55 +00:00
|
|
|
/**
|
2015-12-15 14:46:03 +00:00
|
|
|
* Abstract AST class for a declaration (contract, function, struct, variable, import directive).
|
2014-10-28 15:51:26 +00:00
|
|
|
*/
|
2018-02-09 15:53:25 +00:00
|
|
|
class Declaration: public ASTNode, public Scopable
|
2014-10-13 16:22:15 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-01-22 00:02:38 +00:00
|
|
|
|
2019-12-10 14:54:09 +00:00
|
|
|
static std::string visibilityToString(Visibility _visibility)
|
2017-08-09 13:29:03 +00:00
|
|
|
{
|
2019-11-11 16:09:59 +00:00
|
|
|
switch (_visibility)
|
2017-08-09 13:29:03 +00:00
|
|
|
{
|
2019-12-10 14:54:09 +00:00
|
|
|
case Visibility::Public:
|
2017-08-09 13:29:03 +00:00
|
|
|
return "public";
|
2019-12-10 14:54:09 +00:00
|
|
|
case Visibility::Internal:
|
2017-08-09 13:29:03 +00:00
|
|
|
return "internal";
|
2019-12-10 14:54:09 +00:00
|
|
|
case Visibility::Private:
|
2017-08-09 13:29:03 +00:00
|
|
|
return "private";
|
2019-12-10 14:54:09 +00:00
|
|
|
case Visibility::External:
|
2017-08-09 13:29:03 +00:00
|
|
|
return "external";
|
|
|
|
default:
|
|
|
|
solAssert(false, "Invalid visibility specifier.");
|
|
|
|
}
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
2015-09-24 09:03:44 +00:00
|
|
|
Declaration(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<ASTString> _name,
|
2021-01-21 15:01:39 +00:00
|
|
|
SourceLocation _nameLocation,
|
2015-09-24 09:03:44 +00:00
|
|
|
Visibility _visibility = Visibility::Default
|
|
|
|
):
|
2021-01-21 15:01:39 +00:00
|
|
|
ASTNode(_id, _location), m_name(std::move(_name)), m_nameLocation(std::move(_nameLocation)), m_visibility(_visibility) {}
|
2014-10-13 16:22:15 +00:00
|
|
|
|
2014-12-01 14:22:45 +00:00
|
|
|
/// @returns the declared name.
|
2015-08-31 16:44:29 +00:00
|
|
|
ASTString const& name() const { return *m_name; }
|
2021-01-21 15:01:39 +00:00
|
|
|
SourceLocation const& nameLocation() const noexcept { return m_nameLocation; }
|
2017-08-15 12:22:50 +00:00
|
|
|
bool noVisibilitySpecified() const { return m_visibility == Visibility::Default; }
|
2015-08-31 16:44:29 +00:00
|
|
|
Visibility visibility() const { return m_visibility == Visibility::Default ? defaultVisibility() : m_visibility; }
|
|
|
|
bool isPublic() const { return visibility() >= Visibility::Public; }
|
|
|
|
virtual bool isVisibleInContract() const { return visibility() != Visibility::External; }
|
2020-01-14 13:00:51 +00:00
|
|
|
virtual bool isVisibleInDerivedContracts() const { return isVisibleInContract() && visibility() >= Visibility::Internal; }
|
2018-03-13 16:18:21 +00:00
|
|
|
bool isVisibleAsLibraryMember() const { return visibility() >= Visibility::Internal; }
|
2020-01-14 13:00:51 +00:00
|
|
|
virtual bool isVisibleViaContractTypeAccess() const { return false; }
|
2015-02-02 16:24:09 +00:00
|
|
|
|
2015-09-16 14:56:30 +00:00
|
|
|
virtual bool isLValue() const { return false; }
|
|
|
|
virtual bool isPartOfExternalInterface() const { return false; }
|
|
|
|
|
2020-09-26 22:00:56 +00:00
|
|
|
/// @returns true if this is a declaration of an enum member.
|
|
|
|
bool isEnumValue() const;
|
|
|
|
/// @returns true if this is a declaration of a struct member.
|
|
|
|
bool isStructMember() const;
|
|
|
|
/// @returns true if this is a declaration of a parameter of an event.
|
|
|
|
bool isEventParameter() const;
|
|
|
|
|
2015-01-22 00:02:38 +00:00
|
|
|
/// @returns the type of expressions referencing this declaration.
|
2015-09-16 14:56:30 +00:00
|
|
|
/// This can only be called once types of variable declarations have already been resolved.
|
2015-11-19 17:02:04 +00:00
|
|
|
virtual TypePointer type() const = 0;
|
2015-01-22 00:02:38 +00:00
|
|
|
|
2020-01-14 13:00:51 +00:00
|
|
|
/// @returns the type for members of the containing contract type that refer to this declaration.
|
|
|
|
/// This can only be called once types of variable declarations have already been resolved.
|
|
|
|
virtual TypePointer typeViaContractName() const { return type(); }
|
|
|
|
|
2017-01-10 15:26:13 +00:00
|
|
|
/// @param _internal false indicates external interface is concerned, true indicates internal interface is concerned.
|
|
|
|
/// @returns null when it is not accessible as a function.
|
2017-12-30 12:44:09 +00:00
|
|
|
virtual FunctionTypePointer functionType(bool /*_internal*/) const { return {}; }
|
2017-01-10 15:26:13 +00:00
|
|
|
|
2019-12-19 23:04:46 +00:00
|
|
|
DeclarationAnnotation& annotation() const override;
|
|
|
|
|
2015-02-02 16:24:09 +00:00
|
|
|
protected:
|
2015-08-31 16:44:29 +00:00
|
|
|
virtual Visibility defaultVisibility() const { return Visibility::Public; }
|
2015-02-02 16:24:09 +00:00
|
|
|
|
2014-10-13 16:22:15 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<ASTString> m_name;
|
2021-01-21 15:01:39 +00:00
|
|
|
SourceLocation m_nameLocation;
|
2015-02-02 16:24:09 +00:00
|
|
|
Visibility m_visibility;
|
2014-10-13 16:22:15 +00:00
|
|
|
};
|
|
|
|
|
2016-08-19 17:57:21 +00:00
|
|
|
/**
|
|
|
|
* Pragma directive, only version requirements in the form `pragma solidity "^0.4.0";` are
|
|
|
|
* supported for now.
|
|
|
|
*/
|
|
|
|
class PragmaDirective: public ASTNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PragmaDirective(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2016-08-19 17:57:21 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
std::vector<Token> _tokens,
|
|
|
|
std::vector<ASTString> _literals
|
|
|
|
): ASTNode(_id, _location), m_tokens(std::move(_tokens)), m_literals(std::move(_literals))
|
2016-08-19 17:57:21 +00:00
|
|
|
{}
|
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2016-08-19 17:57:21 +00:00
|
|
|
|
2018-10-22 14:48:21 +00:00
|
|
|
std::vector<Token> const& tokens() const { return m_tokens; }
|
2016-08-19 17:57:21 +00:00
|
|
|
std::vector<ASTString> const& literals() const { return m_literals; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/// Sequence of tokens following the "pragma" keyword.
|
2018-10-22 14:48:21 +00:00
|
|
|
std::vector<Token> m_tokens;
|
2016-08-19 17:57:21 +00:00
|
|
|
/// Sequence of literals following the "pragma" keyword.
|
|
|
|
std::vector<ASTString> m_literals;
|
|
|
|
};
|
|
|
|
|
2015-12-15 14:46:03 +00:00
|
|
|
/**
|
|
|
|
* Import directive for referencing other files / source objects.
|
|
|
|
* Example: import "abc.sol" // imports all symbols of "abc.sol" into current scope
|
|
|
|
* Source objects are identified by a string which can be a file name but does not have to be.
|
|
|
|
* Other ways to use it:
|
|
|
|
* import "abc" as x; // creates symbol "x" that contains all symbols in "abc"
|
|
|
|
* import * as x from "abc"; // same as above
|
|
|
|
* import {a as b, c} from "abc"; // creates new symbols "b" and "c" referencing "a" and "c" in "abc", respectively.
|
|
|
|
*/
|
|
|
|
class ImportDirective: public Declaration
|
|
|
|
{
|
|
|
|
public:
|
2019-09-25 12:14:44 +00:00
|
|
|
struct SymbolAlias
|
|
|
|
{
|
|
|
|
ASTPointer<Identifier> symbol;
|
|
|
|
ASTPointer<ASTString> alias;
|
|
|
|
SourceLocation location;
|
|
|
|
};
|
|
|
|
|
|
|
|
using SymbolAliasList = std::vector<SymbolAlias>;
|
|
|
|
|
2015-12-15 14:46:03 +00:00
|
|
|
ImportDirective(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-12-15 14:46:03 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<ASTString> _path,
|
2015-12-15 14:46:03 +00:00
|
|
|
ASTPointer<ASTString> const& _unitAlias,
|
2021-01-21 15:01:39 +00:00
|
|
|
SourceLocation _unitAliasLocation,
|
2019-09-25 12:14:44 +00:00
|
|
|
SymbolAliasList _symbolAliases
|
2015-12-15 14:46:03 +00:00
|
|
|
):
|
2021-01-21 15:01:39 +00:00
|
|
|
Declaration(_id, _location, _unitAlias, std::move(_unitAliasLocation)),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_path(std::move(_path)),
|
2019-09-25 12:14:44 +00:00
|
|
|
m_symbolAliases(move(_symbolAliases))
|
2015-12-15 14:46:03 +00:00
|
|
|
{ }
|
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-12-15 14:46:03 +00:00
|
|
|
|
|
|
|
ASTString const& path() const { return *m_path; }
|
2019-09-25 12:14:44 +00:00
|
|
|
SymbolAliasList const& symbolAliases() const
|
2016-01-11 12:55:58 +00:00
|
|
|
{
|
|
|
|
return m_symbolAliases;
|
|
|
|
}
|
2018-11-16 01:09:04 +00:00
|
|
|
ImportAnnotation& annotation() const override;
|
2015-12-15 14:46:03 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
TypePointer type() const override;
|
2015-12-15 14:46:03 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ASTPointer<ASTString> m_path;
|
|
|
|
/// The aliases for the specific symbols to import. If non-empty import the specific symbols.
|
2019-09-25 12:14:44 +00:00
|
|
|
/// If the `alias` component is empty, import the identifier unchanged.
|
2015-12-15 14:46:03 +00:00
|
|
|
/// If both m_unitAlias and m_symbolAlias are empty, import all symbols into the current scope.
|
2019-09-25 12:14:44 +00:00
|
|
|
SymbolAliasList m_symbolAliases;
|
2015-12-15 14:46:03 +00:00
|
|
|
};
|
|
|
|
|
2015-01-29 16:28:14 +00:00
|
|
|
/**
|
|
|
|
* Abstract class that is added to each AST node that can store local variables.
|
2018-02-09 15:53:52 +00:00
|
|
|
* Local variables in functions are always added to functions, even though they are not
|
|
|
|
* in scope for the whole function.
|
2015-01-29 16:28:14 +00:00
|
|
|
*/
|
|
|
|
class VariableScope
|
|
|
|
{
|
|
|
|
public:
|
2018-05-02 11:29:16 +00:00
|
|
|
virtual ~VariableScope() = default;
|
2015-01-29 16:28:14 +00:00
|
|
|
void addLocalVariable(VariableDeclaration const& _localVariable) { m_localVariables.push_back(&_localVariable); }
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<VariableDeclaration const*> const& localVariables() const { return m_localVariables; }
|
2015-01-29 16:28:14 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<VariableDeclaration const*> m_localVariables;
|
|
|
|
};
|
|
|
|
|
2020-01-29 22:13:42 +00:00
|
|
|
/**
|
|
|
|
* The doxygen-style, structured documentation class that represents an AST node.
|
|
|
|
*/
|
|
|
|
class StructuredDocumentation: public ASTNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
StructuredDocumentation(
|
|
|
|
int64_t _id,
|
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<ASTString> _text
|
|
|
|
): ASTNode(_id, _location), m_text(std::move(_text))
|
2020-01-29 22:13:42 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
|
|
|
/// @return A shared pointer of an ASTString.
|
|
|
|
/// Contains doxygen-style, structured documentation that is parsed later on.
|
|
|
|
ASTPointer<ASTString> const& text() const { return m_text; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ASTPointer<ASTString> m_text;
|
|
|
|
};
|
|
|
|
|
2015-01-29 16:28:14 +00:00
|
|
|
/**
|
|
|
|
* Abstract class that is added to each AST node that can receive documentation.
|
|
|
|
*/
|
|
|
|
class Documented
|
|
|
|
{
|
|
|
|
public:
|
2018-05-02 11:29:16 +00:00
|
|
|
virtual ~Documented() = default;
|
2020-04-01 03:04:29 +00:00
|
|
|
explicit Documented(ASTPointer<ASTString> _documentation): m_documentation(std::move(_documentation)) {}
|
2015-01-29 16:28:14 +00:00
|
|
|
|
|
|
|
/// @return A shared pointer of an ASTString.
|
|
|
|
/// Can contain a nullptr in which case indicates absence of documentation
|
2015-08-31 16:44:29 +00:00
|
|
|
ASTPointer<ASTString> const& documentation() const { return m_documentation; }
|
2015-01-29 16:28:14 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ASTPointer<ASTString> m_documentation;
|
|
|
|
};
|
|
|
|
|
2020-01-29 22:13:42 +00:00
|
|
|
/**
|
|
|
|
* Abstract class that is added to each AST node that can receive a structured documentation.
|
|
|
|
*/
|
|
|
|
class StructurallyDocumented
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~StructurallyDocumented() = default;
|
2020-04-01 03:04:29 +00:00
|
|
|
explicit StructurallyDocumented(ASTPointer<StructuredDocumentation> _documentation): m_documentation(std::move(_documentation)) {}
|
2020-01-29 22:13:42 +00:00
|
|
|
|
|
|
|
/// @return A shared pointer of a FormalDocumentation.
|
|
|
|
/// Can contain a nullptr in which case indicates absence of documentation
|
|
|
|
ASTPointer<StructuredDocumentation> const& documentation() const { return m_documentation; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ASTPointer<StructuredDocumentation> m_documentation;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-03-20 16:50:26 +00:00
|
|
|
/**
|
|
|
|
* Abstract class that is added to AST nodes that can be marked as not being fully implemented
|
|
|
|
*/
|
|
|
|
class ImplementationOptional
|
|
|
|
{
|
|
|
|
public:
|
2018-05-02 11:29:16 +00:00
|
|
|
virtual ~ImplementationOptional() = default;
|
2015-03-20 16:50:26 +00:00
|
|
|
explicit ImplementationOptional(bool _implemented): m_implemented(_implemented) {}
|
|
|
|
|
|
|
|
/// @return whether this node is fully implemented or not
|
2015-09-16 14:56:30 +00:00
|
|
|
bool isImplemented() const { return m_implemented; }
|
2015-03-20 16:50:26 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool m_implemented;
|
|
|
|
};
|
|
|
|
|
2015-01-29 16:28:14 +00:00
|
|
|
/// @}
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
2015-09-08 14:48:33 +00:00
|
|
|
* Definition of a contract or library. This is the only AST nodes where child nodes are not visited in
|
2014-10-28 15:51:26 +00:00
|
|
|
* document order. It first visits all struct declarations, then all variable declarations and
|
|
|
|
* finally all function declarations.
|
|
|
|
*/
|
2020-08-06 12:46:04 +00:00
|
|
|
class ContractDefinition: public Declaration, public StructurallyDocumented, public ScopeOpener
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-03-20 16:50:26 +00:00
|
|
|
ContractDefinition(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-03-20 16:50:26 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
2021-01-21 15:01:39 +00:00
|
|
|
SourceLocation _nameLocation,
|
2020-01-29 22:13:42 +00:00
|
|
|
ASTPointer<StructuredDocumentation> const& _documentation,
|
2020-04-01 03:04:29 +00:00
|
|
|
std::vector<ASTPointer<InheritanceSpecifier>> _baseContracts,
|
|
|
|
std::vector<ASTPointer<ASTNode>> _subNodes,
|
2019-09-04 22:01:13 +00:00
|
|
|
ContractKind _contractKind = ContractKind::Contract,
|
|
|
|
bool _abstract = false
|
2015-03-20 16:50:26 +00:00
|
|
|
):
|
2021-01-21 15:01:39 +00:00
|
|
|
Declaration(_id, _location, _name, std::move(_nameLocation)),
|
2020-01-29 22:13:42 +00:00
|
|
|
StructurallyDocumented(_documentation),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_baseContracts(std::move(_baseContracts)),
|
|
|
|
m_subNodes(std::move(_subNodes)),
|
2019-09-04 22:01:13 +00:00
|
|
|
m_contractKind(_contractKind),
|
|
|
|
m_abstract(_abstract)
|
2014-10-09 10:28:37 +00:00
|
|
|
{}
|
2014-10-07 16:25:04 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<ASTPointer<InheritanceSpecifier>> const& baseContracts() const { return m_baseContracts; }
|
2015-11-23 22:57:17 +00:00
|
|
|
std::vector<ASTPointer<ASTNode>> const& subNodes() const { return m_subNodes; }
|
2015-11-25 13:23:35 +00:00
|
|
|
std::vector<UsingForDirective const*> usingForDirectives() const { return filteredNodes<UsingForDirective>(m_subNodes); }
|
2015-11-26 16:28:44 +00:00
|
|
|
std::vector<StructDefinition const*> definedStructs() const { return filteredNodes<StructDefinition>(m_subNodes); }
|
|
|
|
std::vector<EnumDefinition const*> definedEnums() const { return filteredNodes<EnumDefinition>(m_subNodes); }
|
|
|
|
std::vector<VariableDeclaration const*> stateVariables() const { return filteredNodes<VariableDeclaration>(m_subNodes); }
|
|
|
|
std::vector<ModifierDefinition const*> functionModifiers() const { return filteredNodes<ModifierDefinition>(m_subNodes); }
|
|
|
|
std::vector<FunctionDefinition const*> definedFunctions() const { return filteredNodes<FunctionDefinition>(m_subNodes); }
|
|
|
|
std::vector<EventDefinition const*> events() const { return filteredNodes<EventDefinition>(m_subNodes); }
|
2015-11-23 22:57:17 +00:00
|
|
|
std::vector<EventDefinition const*> const& interfaceEvents() const;
|
2019-01-17 11:59:11 +00:00
|
|
|
bool isInterface() const { return m_contractKind == ContractKind::Interface; }
|
2017-02-07 22:11:50 +00:00
|
|
|
bool isLibrary() const { return m_contractKind == ContractKind::Library; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2020-01-14 13:00:51 +00:00
|
|
|
/// @returns true, if the contract derives from @arg _base.
|
|
|
|
bool derivesFrom(ContractDefinition const& _base) const;
|
|
|
|
|
2015-01-07 15:39:21 +00:00
|
|
|
/// @returns a map of canonical function signatures to FunctionDefinitions
|
|
|
|
/// as intended for use by the ABI.
|
2020-04-08 22:08:49 +00:00
|
|
|
std::map<util::FixedHash<4>, FunctionTypePointer> interfaceFunctions(bool _includeInheritedFunctions = true) const;
|
|
|
|
std::vector<std::pair<util::FixedHash<4>, FunctionTypePointer>> const& interfaceFunctionList(bool _includeInheritedFunctions = true) const;
|
2020-09-14 10:39:38 +00:00
|
|
|
/// @returns the EIP-165 compatible interface identifier. This will exclude inherited functions.
|
2020-11-11 18:36:50 +00:00
|
|
|
uint32_t interfaceId() const;
|
2014-11-23 23:00:46 +00:00
|
|
|
|
2020-01-14 13:00:51 +00:00
|
|
|
/// @returns a list of all declarations in this contract
|
|
|
|
std::vector<Declaration const*> declarations() const { return filteredNodes<Declaration>(m_subNodes); }
|
2015-02-25 19:35:55 +00:00
|
|
|
|
2015-01-29 21:50:20 +00:00
|
|
|
/// Returns the constructor or nullptr if no constructor was specified.
|
2015-08-31 16:44:29 +00:00
|
|
|
FunctionDefinition const* constructor() const;
|
2019-01-17 19:08:17 +00:00
|
|
|
/// @returns true iff the contract can be deployed, i.e. is not abstract and has a
|
|
|
|
/// public constructor.
|
|
|
|
/// Should only be called after the type checker has run.
|
|
|
|
bool canBeDeployed() const;
|
2015-02-09 01:06:30 +00:00
|
|
|
/// Returns the fallback function or nullptr if no fallback function was specified.
|
2015-08-31 16:44:29 +00:00
|
|
|
FunctionDefinition const* fallbackFunction() const;
|
2014-12-12 15:49:26 +00:00
|
|
|
|
2019-09-09 16:22:02 +00:00
|
|
|
/// Returns the ether receiver function or nullptr if no receive function was specified.
|
|
|
|
FunctionDefinition const* receiveFunction() const;
|
|
|
|
|
2018-07-24 00:05:11 +00:00
|
|
|
std::string fullyQualifiedName() const { return sourceUnitName() + ":" + name(); }
|
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
TypePointer type() const override;
|
2015-01-16 16:50:10 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
ContractDefinitionAnnotation& annotation() const override;
|
2015-01-14 09:16:58 +00:00
|
|
|
|
2017-02-07 22:11:50 +00:00
|
|
|
ContractKind contractKind() const { return m_contractKind; }
|
|
|
|
|
2019-09-04 22:01:13 +00:00
|
|
|
bool abstract() const { return m_abstract; }
|
|
|
|
|
2020-04-06 15:30:01 +00:00
|
|
|
ContractDefinition const* superContract(ContractDefinition const& _mostDerivedContract) const;
|
|
|
|
/// @returns the next constructor in the inheritance hierarchy.
|
|
|
|
FunctionDefinition const* nextConstructor(ContractDefinition const& _mostDerivedContract) const;
|
|
|
|
|
2015-09-16 14:56:30 +00:00
|
|
|
private:
|
2015-01-19 20:05:47 +00:00
|
|
|
std::vector<ASTPointer<InheritanceSpecifier>> m_baseContracts;
|
2015-11-23 22:57:17 +00:00
|
|
|
std::vector<ASTPointer<ASTNode>> m_subNodes;
|
2017-02-07 22:11:50 +00:00
|
|
|
ContractKind m_contractKind;
|
2019-09-04 22:01:13 +00:00
|
|
|
bool m_abstract{false};
|
2015-01-15 19:04:06 +00:00
|
|
|
|
2020-05-13 17:59:15 +00:00
|
|
|
util::LazyInit<std::vector<std::pair<util::FixedHash<4>, FunctionTypePointer>>> m_interfaceFunctionList[2];
|
2020-05-13 17:57:20 +00:00
|
|
|
util::LazyInit<std::vector<EventDefinition const*>> m_interfaceEvents;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2020-08-31 15:37:03 +00:00
|
|
|
/**
|
2020-08-11 09:18:22 +00:00
|
|
|
* A sequence of identifiers separated by dots used outside the expression context. Inside the expression context, this is a sequence of Identifier and MemberAccess.
|
2020-08-31 15:37:03 +00:00
|
|
|
*/
|
|
|
|
class IdentifierPath: public ASTNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IdentifierPath(int64_t _id, SourceLocation const& _location, std::vector<ASTString> _path):
|
|
|
|
ASTNode(_id, _location), m_path(std::move(_path)) {}
|
|
|
|
|
|
|
|
std::vector<ASTString> const& path() const { return m_path; }
|
|
|
|
IdentifierPathAnnotation& annotation() const override
|
|
|
|
{
|
|
|
|
return initAnnotation<IdentifierPathAnnotation>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
private:
|
|
|
|
std::vector<ASTString> m_path;
|
|
|
|
};
|
|
|
|
|
2015-01-19 20:05:47 +00:00
|
|
|
class InheritanceSpecifier: public ASTNode
|
|
|
|
{
|
|
|
|
public:
|
2015-09-16 14:56:30 +00:00
|
|
|
InheritanceSpecifier(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-16 14:56:30 +00:00
|
|
|
SourceLocation const& _location,
|
2020-08-11 09:18:22 +00:00
|
|
|
ASTPointer<IdentifierPath> _baseName,
|
2018-04-04 18:53:23 +00:00
|
|
|
std::unique_ptr<std::vector<ASTPointer<Expression>>> _arguments
|
2015-09-16 14:56:30 +00:00
|
|
|
):
|
2020-09-16 09:00:07 +00:00
|
|
|
ASTNode(_id, _location), m_baseName(std::move(_baseName)), m_arguments(std::move(_arguments))
|
|
|
|
{
|
|
|
|
solAssert(m_baseName != nullptr, "Name cannot be null.");
|
|
|
|
}
|
2015-01-19 20:05:47 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-01-19 20:05:47 +00:00
|
|
|
|
2020-08-11 09:18:22 +00:00
|
|
|
IdentifierPath const& name() const { return *m_baseName; }
|
2018-04-04 18:53:23 +00:00
|
|
|
// Returns nullptr if no argument list was given (``C``).
|
|
|
|
// If an argument list is given (``C(...)``), the arguments are returned
|
|
|
|
// as a vector of expressions. Note that this vector can be empty (``C()``).
|
|
|
|
std::vector<ASTPointer<Expression>> const* arguments() const { return m_arguments.get(); }
|
2015-01-19 20:05:47 +00:00
|
|
|
|
|
|
|
private:
|
2020-08-11 09:18:22 +00:00
|
|
|
ASTPointer<IdentifierPath> m_baseName;
|
2018-04-04 18:53:23 +00:00
|
|
|
std::unique_ptr<std::vector<ASTPointer<Expression>>> m_arguments;
|
2015-01-19 20:05:47 +00:00
|
|
|
};
|
|
|
|
|
2015-11-22 19:39:10 +00:00
|
|
|
/**
|
|
|
|
* `using LibraryName for uint` will attach all functions from the library LibraryName
|
|
|
|
* to `uint` if the first parameter matches the type. `using LibraryName for *` attaches
|
|
|
|
* the function to any matching type.
|
|
|
|
*/
|
|
|
|
class UsingForDirective: public ASTNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UsingForDirective(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-11-22 19:39:10 +00:00
|
|
|
SourceLocation const& _location,
|
2020-08-11 09:18:22 +00:00
|
|
|
ASTPointer<IdentifierPath> _libraryName,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<TypeName> _typeName
|
2015-11-22 19:39:10 +00:00
|
|
|
):
|
2020-09-16 09:00:07 +00:00
|
|
|
ASTNode(_id, _location), m_libraryName(std::move(_libraryName)), m_typeName(std::move(_typeName))
|
|
|
|
{
|
|
|
|
solAssert(m_libraryName != nullptr, "Name cannot be null.");
|
|
|
|
}
|
2015-11-22 19:39:10 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-11-22 19:39:10 +00:00
|
|
|
|
2020-08-11 09:18:22 +00:00
|
|
|
IdentifierPath const& libraryName() const { return *m_libraryName; }
|
2015-11-22 19:39:10 +00:00
|
|
|
/// @returns the type name the library is attached to, null for `*`.
|
|
|
|
TypeName const* typeName() const { return m_typeName.get(); }
|
|
|
|
|
|
|
|
private:
|
2020-08-11 09:18:22 +00:00
|
|
|
ASTPointer<IdentifierPath> m_libraryName;
|
2015-11-22 19:39:10 +00:00
|
|
|
ASTPointer<TypeName> m_typeName;
|
|
|
|
};
|
|
|
|
|
2020-08-06 12:46:04 +00:00
|
|
|
class StructDefinition: public Declaration, public ScopeOpener
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-08 18:53:50 +00:00
|
|
|
public:
|
2015-09-17 13:04:44 +00:00
|
|
|
StructDefinition(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-17 13:04:44 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
2021-01-21 15:01:39 +00:00
|
|
|
SourceLocation _nameLocation,
|
2020-04-01 03:04:29 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> _members
|
2015-09-17 13:04:44 +00:00
|
|
|
):
|
2021-01-21 15:01:39 +00:00
|
|
|
Declaration(_id, _location, _name, std::move(_nameLocation)), m_members(std::move(_members)) {}
|
2015-09-17 13:04:44 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& members() const { return m_members; }
|
2014-11-07 01:06:37 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
TypePointer type() const override;
|
2014-11-20 17:33:23 +00:00
|
|
|
|
2020-01-14 13:00:51 +00:00
|
|
|
bool isVisibleInDerivedContracts() const override { return true; }
|
|
|
|
bool isVisibleViaContractTypeAccess() const override { return true; }
|
|
|
|
|
2020-04-14 14:36:37 +00:00
|
|
|
StructDeclarationAnnotation& annotation() const override;
|
2015-10-05 15:19:23 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> m_members;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2020-08-06 12:46:04 +00:00
|
|
|
class EnumDefinition: public Declaration, public ScopeOpener
|
2015-02-09 17:08:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-09-16 14:56:30 +00:00
|
|
|
EnumDefinition(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-16 14:56:30 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
2021-01-21 15:01:39 +00:00
|
|
|
SourceLocation _nameLocation,
|
2020-04-01 03:04:29 +00:00
|
|
|
std::vector<ASTPointer<EnumValue>> _members
|
2015-09-16 14:56:30 +00:00
|
|
|
):
|
2021-01-21 15:01:39 +00:00
|
|
|
Declaration(_id, _location, _name, std::move(_nameLocation)), m_members(std::move(_members)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-02-09 17:08:56 +00:00
|
|
|
|
2020-01-14 13:00:51 +00:00
|
|
|
bool isVisibleInDerivedContracts() const override { return true; }
|
|
|
|
bool isVisibleViaContractTypeAccess() const override { return true; }
|
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<ASTPointer<EnumValue>> const& members() const { return m_members; }
|
2015-02-09 17:08:56 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
TypePointer type() const override;
|
2015-02-09 17:08:56 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
TypeDeclarationAnnotation& annotation() const override;
|
2015-10-05 15:19:23 +00:00
|
|
|
|
2015-02-09 17:08:56 +00:00
|
|
|
private:
|
2015-02-13 16:34:46 +00:00
|
|
|
std::vector<ASTPointer<EnumValue>> m_members;
|
2015-02-09 17:08:56 +00:00
|
|
|
};
|
|
|
|
|
2015-02-13 21:52:04 +00:00
|
|
|
/**
|
|
|
|
* Declaration of an Enum Value
|
|
|
|
*/
|
|
|
|
class EnumValue: public Declaration
|
|
|
|
{
|
2015-09-16 14:56:30 +00:00
|
|
|
public:
|
2019-09-11 19:16:35 +00:00
|
|
|
EnumValue(int64_t _id, SourceLocation const& _location, ASTPointer<ASTString> const& _name):
|
2021-01-21 15:01:39 +00:00
|
|
|
Declaration(_id, _location, _name, _location) {}
|
2015-02-13 21:52:04 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
TypePointer type() const override;
|
2015-02-13 21:52:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
2019-09-02 14:17:02 +00:00
|
|
|
* Parameter list, used as function parameter list, return list and for try and catch.
|
2014-10-28 15:51:26 +00:00
|
|
|
* None of the parameters is allowed to contain mappings (not even recursively
|
2014-11-13 00:12:57 +00:00
|
|
|
* inside structs).
|
2014-10-28 15:51:26 +00:00
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class ParameterList: public ASTNode
|
2014-10-08 18:53:50 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
ParameterList(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> _parameters
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTNode(_id, _location), m_parameters(std::move(_parameters)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-13 13:07:21 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& parameters() const { return m_parameters; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2014-10-08 18:53:50 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> m_parameters;
|
2014-10-08 18:53:50 +00:00
|
|
|
};
|
|
|
|
|
2015-06-09 12:26:08 +00:00
|
|
|
/**
|
|
|
|
* Base class for all nodes that define function-like objects, i.e. FunctionDefinition,
|
|
|
|
* EventDefinition and ModifierDefinition.
|
|
|
|
*/
|
|
|
|
class CallableDeclaration: public Declaration, public VariableScope
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CallableDeclaration(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-06-09 12:26:08 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
2021-01-21 15:01:39 +00:00
|
|
|
SourceLocation _nameLocation,
|
2019-12-10 14:54:09 +00:00
|
|
|
Visibility _visibility,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<ParameterList> _parameters,
|
2019-10-30 13:34:37 +00:00
|
|
|
bool _isVirtual = false,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<OverrideSpecifier> _overrides = nullptr,
|
|
|
|
ASTPointer<ParameterList> _returnParameters = ASTPointer<ParameterList>()
|
2015-06-09 12:26:08 +00:00
|
|
|
):
|
2021-01-21 15:01:39 +00:00
|
|
|
Declaration(_id, _location, _name, std::move(_nameLocation), _visibility),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_parameters(std::move(_parameters)),
|
|
|
|
m_overrides(std::move(_overrides)),
|
|
|
|
m_returnParameters(std::move(_returnParameters)),
|
2019-10-30 13:34:37 +00:00
|
|
|
m_isVirtual(_isVirtual)
|
2015-06-09 12:26:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& parameters() const { return m_parameters->parameters(); }
|
2019-09-16 10:32:14 +00:00
|
|
|
ASTPointer<OverrideSpecifier> const& overrides() const { return m_overrides; }
|
2019-03-04 13:31:38 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& returnParameters() const { return m_returnParameters->parameters(); }
|
2015-08-31 16:44:29 +00:00
|
|
|
ParameterList const& parameterList() const { return *m_parameters; }
|
|
|
|
ASTPointer<ParameterList> const& returnParameterList() const { return m_returnParameters; }
|
2019-11-05 17:25:34 +00:00
|
|
|
bool markedVirtual() const { return m_isVirtual; }
|
|
|
|
virtual bool virtualSemantics() const { return markedVirtual(); }
|
2015-06-09 12:26:08 +00:00
|
|
|
|
2020-01-07 13:34:20 +00:00
|
|
|
CallableDeclarationAnnotation& annotation() const override = 0;
|
2019-12-09 15:54:52 +00:00
|
|
|
|
2020-03-24 17:25:59 +00:00
|
|
|
/// Performs virtual or super function/modifier lookup:
|
|
|
|
/// If @a _searchStart is nullptr, performs virtual function lookup, i.e.
|
|
|
|
/// searches the inheritance hierarchy of @a _mostDerivedContract towards the base
|
|
|
|
/// and returns the first function/modifier definition that
|
|
|
|
/// is overwritten by this callable.
|
|
|
|
/// If @a _searchStart is non-null, starts searching only from that contract, but
|
|
|
|
/// still in the hierarchy of @a _mostDerivedContract.
|
|
|
|
virtual CallableDeclaration const& resolveVirtual(
|
|
|
|
ContractDefinition const& _mostDerivedContract,
|
|
|
|
ContractDefinition const* _searchStart = nullptr
|
|
|
|
) const = 0;
|
|
|
|
|
2015-06-09 12:26:08 +00:00
|
|
|
protected:
|
|
|
|
ASTPointer<ParameterList> m_parameters;
|
2019-09-16 10:32:14 +00:00
|
|
|
ASTPointer<OverrideSpecifier> m_overrides;
|
2015-06-09 12:26:08 +00:00
|
|
|
ASTPointer<ParameterList> m_returnParameters;
|
2019-11-05 17:25:34 +00:00
|
|
|
bool m_isVirtual = false;
|
2015-06-09 12:26:08 +00:00
|
|
|
};
|
|
|
|
|
2019-08-13 11:00:46 +00:00
|
|
|
/**
|
|
|
|
* Function override specifier. Consists of a single override keyword
|
|
|
|
* potentially followed by a parenthesized list of base contract names.
|
|
|
|
*/
|
|
|
|
class OverrideSpecifier: public ASTNode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OverrideSpecifier(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2019-08-13 11:00:46 +00:00
|
|
|
SourceLocation const& _location,
|
2020-08-11 09:18:22 +00:00
|
|
|
std::vector<ASTPointer<IdentifierPath>> _overrides
|
2019-08-13 11:00:46 +00:00
|
|
|
):
|
2019-09-11 19:16:35 +00:00
|
|
|
ASTNode(_id, _location),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_overrides(std::move(_overrides))
|
2019-08-13 11:00:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
|
|
|
/// @returns the list of specific overrides, if any
|
2020-08-11 09:18:22 +00:00
|
|
|
std::vector<ASTPointer<IdentifierPath>> const& overrides() const { return m_overrides; }
|
2019-08-13 11:00:46 +00:00
|
|
|
|
|
|
|
protected:
|
2020-08-11 09:18:22 +00:00
|
|
|
std::vector<ASTPointer<IdentifierPath>> m_overrides;
|
2019-08-13 11:00:46 +00:00
|
|
|
};
|
|
|
|
|
2020-08-06 12:46:04 +00:00
|
|
|
class FunctionDefinition: public CallableDeclaration, public StructurallyDocumented, public ImplementationOptional, public ScopeOpener
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-08 18:53:50 +00:00
|
|
|
public:
|
2015-03-20 16:50:26 +00:00
|
|
|
FunctionDefinition(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-03-20 16:50:26 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
2021-01-21 15:01:39 +00:00
|
|
|
SourceLocation const& _nameLocation,
|
2019-12-10 14:54:09 +00:00
|
|
|
Visibility _visibility,
|
2017-07-01 09:09:24 +00:00
|
|
|
StateMutability _stateMutability,
|
2020-05-04 16:38:00 +00:00
|
|
|
bool _free,
|
2019-09-09 16:22:02 +00:00
|
|
|
Token _kind,
|
2019-10-30 13:34:37 +00:00
|
|
|
bool _isVirtual,
|
2019-08-13 11:00:46 +00:00
|
|
|
ASTPointer<OverrideSpecifier> const& _overrides,
|
2020-01-29 22:13:42 +00:00
|
|
|
ASTPointer<StructuredDocumentation> const& _documentation,
|
2015-03-20 16:50:26 +00:00
|
|
|
ASTPointer<ParameterList> const& _parameters,
|
2020-04-01 03:04:29 +00:00
|
|
|
std::vector<ASTPointer<ModifierInvocation>> _modifiers,
|
2015-03-20 16:50:26 +00:00
|
|
|
ASTPointer<ParameterList> const& _returnParameters,
|
|
|
|
ASTPointer<Block> const& _body
|
|
|
|
):
|
2021-01-21 15:01:39 +00:00
|
|
|
CallableDeclaration(_id, _location, _name, std::move(_nameLocation), _visibility, _parameters, _isVirtual, _overrides, _returnParameters),
|
2020-01-29 22:13:42 +00:00
|
|
|
StructurallyDocumented(_documentation),
|
2015-03-20 16:50:26 +00:00
|
|
|
ImplementationOptional(_body != nullptr),
|
2017-07-01 09:09:24 +00:00
|
|
|
m_stateMutability(_stateMutability),
|
2020-05-04 16:38:00 +00:00
|
|
|
m_free(_free),
|
2019-09-09 16:22:02 +00:00
|
|
|
m_kind(_kind),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_functionModifiers(std::move(_modifiers)),
|
2015-03-20 16:50:26 +00:00
|
|
|
m_body(_body)
|
2019-09-09 16:22:02 +00:00
|
|
|
{
|
|
|
|
solAssert(_kind == Token::Constructor || _kind == Token::Function || _kind == Token::Fallback || _kind == Token::Receive, "");
|
2020-08-03 14:35:13 +00:00
|
|
|
solAssert(isOrdinary() == !name().empty(), "");
|
2019-09-09 16:22:02 +00:00
|
|
|
}
|
2014-11-28 00:26:37 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2017-07-01 09:09:24 +00:00
|
|
|
StateMutability stateMutability() const { return m_stateMutability; }
|
2020-06-09 15:56:58 +00:00
|
|
|
bool libraryFunction() const;
|
2019-09-09 16:22:02 +00:00
|
|
|
bool isOrdinary() const { return m_kind == Token::Function; }
|
|
|
|
bool isConstructor() const { return m_kind == Token::Constructor; }
|
|
|
|
bool isFallback() const { return m_kind == Token::Fallback; }
|
|
|
|
bool isReceive() const { return m_kind == Token::Receive; }
|
2020-05-04 16:38:00 +00:00
|
|
|
bool isFree() const { return m_free; }
|
2019-09-09 16:22:02 +00:00
|
|
|
Token kind() const { return m_kind; }
|
2017-07-01 09:09:24 +00:00
|
|
|
bool isPayable() const { return m_stateMutability == StateMutability::Payable; }
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<ASTPointer<ModifierInvocation>> const& modifiers() const { return m_functionModifiers; }
|
2017-03-20 18:06:17 +00:00
|
|
|
Block const& body() const { solAssert(m_body, ""); return *m_body; }
|
2020-06-18 15:34:05 +00:00
|
|
|
Visibility defaultVisibility() const override;
|
2018-11-16 01:09:04 +00:00
|
|
|
bool isVisibleInContract() const override
|
2015-02-27 09:08:14 +00:00
|
|
|
{
|
2020-06-18 15:34:05 +00:00
|
|
|
return isOrdinary() && Declaration::isVisibleInContract();
|
2015-02-27 09:08:14 +00:00
|
|
|
}
|
2020-01-14 13:00:51 +00:00
|
|
|
bool isVisibleViaContractTypeAccess() const override
|
|
|
|
{
|
2020-05-04 16:38:00 +00:00
|
|
|
solAssert(!isFree(), "");
|
2020-06-10 16:19:42 +00:00
|
|
|
return isOrdinary() && visibility() >= Visibility::Public;
|
2020-01-14 13:00:51 +00:00
|
|
|
}
|
2020-06-18 15:34:05 +00:00
|
|
|
bool isPartOfExternalInterface() const override { return isOrdinary() && isPublic(); }
|
2014-11-03 17:39:16 +00:00
|
|
|
|
2015-03-24 10:11:27 +00:00
|
|
|
/// @returns the external signature of the function
|
2015-01-07 09:45:59 +00:00
|
|
|
/// That consists of the name of the function followed by the types of the
|
|
|
|
/// arguments separated by commas all enclosed in parentheses without any spaces.
|
2015-03-27 12:28:32 +00:00
|
|
|
std::string externalSignature() const;
|
2015-01-06 16:42:38 +00:00
|
|
|
|
2019-12-09 00:26:23 +00:00
|
|
|
/// @returns the external identifier of this function (the hash of the signature) as a hex string.
|
|
|
|
std::string externalIdentifierHex() const;
|
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
TypePointer type() const override;
|
2020-01-14 13:00:51 +00:00
|
|
|
TypePointer typeViaContractName() const override;
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2017-01-10 15:26:13 +00:00
|
|
|
/// @param _internal false indicates external interface is concerned, true indicates internal interface is concerned.
|
|
|
|
/// @returns null when it is not accessible as a function.
|
2018-11-16 01:09:04 +00:00
|
|
|
FunctionTypePointer functionType(bool /*_internal*/) const override;
|
2017-01-10 15:26:13 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
FunctionDefinitionAnnotation& annotation() const override;
|
2015-10-26 14:13:36 +00:00
|
|
|
|
2019-11-05 17:25:34 +00:00
|
|
|
bool virtualSemantics() const override
|
|
|
|
{
|
|
|
|
return
|
|
|
|
CallableDeclaration::virtualSemantics() ||
|
2019-12-09 16:01:31 +00:00
|
|
|
(annotation().contract && annotation().contract->isInterface());
|
2019-11-05 17:25:34 +00:00
|
|
|
}
|
2020-03-24 17:25:59 +00:00
|
|
|
|
|
|
|
FunctionDefinition const& resolveVirtual(
|
|
|
|
ContractDefinition const& _mostDerivedContract,
|
|
|
|
ContractDefinition const* _searchStart = nullptr
|
|
|
|
) const override;
|
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2017-07-01 09:09:24 +00:00
|
|
|
StateMutability m_stateMutability;
|
2020-05-04 16:38:00 +00:00
|
|
|
bool m_free;
|
2019-09-09 16:22:02 +00:00
|
|
|
Token const m_kind;
|
2015-01-22 00:02:38 +00:00
|
|
|
std::vector<ASTPointer<ModifierInvocation>> m_functionModifiers;
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<Block> m_body;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Declaration of a variable. This can be used in various places, e.g. in function parameter
|
2017-01-18 15:43:23 +00:00
|
|
|
* lists, struct definitions and even function bodies.
|
2014-10-28 15:51:26 +00:00
|
|
|
*/
|
2020-03-05 20:59:26 +00:00
|
|
|
class VariableDeclaration: public Declaration, public StructurallyDocumented
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-08-17 23:09:31 +00:00
|
|
|
enum Location { Unspecified, Storage, Memory, CallData };
|
2020-04-07 09:10:10 +00:00
|
|
|
enum class Mutability { Mutable, Immutable, Constant };
|
|
|
|
static std::string mutabilityToString(Mutability _mutability)
|
|
|
|
{
|
|
|
|
switch (_mutability)
|
|
|
|
{
|
|
|
|
case Mutability::Mutable: return "mutable";
|
|
|
|
case Mutability::Immutable: return "immutable";
|
|
|
|
case Mutability::Constant: return "constant";
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
2015-06-05 09:07:50 +00:00
|
|
|
|
2015-03-03 11:58:01 +00:00
|
|
|
VariableDeclaration(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<TypeName> _type,
|
2015-03-16 13:45:11 +00:00
|
|
|
ASTPointer<ASTString> const& _name,
|
2021-01-21 15:01:39 +00:00
|
|
|
SourceLocation _nameLocation,
|
2015-03-16 13:45:11 +00:00
|
|
|
ASTPointer<Expression> _value,
|
|
|
|
Visibility _visibility,
|
2020-03-24 22:44:39 +00:00
|
|
|
ASTPointer<StructuredDocumentation> const _documentation = nullptr,
|
2015-03-16 13:45:11 +00:00
|
|
|
bool _isIndexed = false,
|
2020-04-07 09:10:10 +00:00
|
|
|
Mutability _mutability = Mutability::Mutable,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<OverrideSpecifier> _overrides = nullptr,
|
2018-08-17 23:09:31 +00:00
|
|
|
Location _referenceLocation = Location::Unspecified
|
2015-03-16 13:45:11 +00:00
|
|
|
):
|
2021-01-21 15:01:39 +00:00
|
|
|
Declaration(_id, _location, _name, std::move(_nameLocation), _visibility),
|
2020-03-24 22:44:39 +00:00
|
|
|
StructurallyDocumented(std::move(_documentation)),
|
|
|
|
m_typeName(std::move(_type)),
|
|
|
|
m_value(std::move(_value)),
|
2015-03-03 11:58:01 +00:00
|
|
|
m_isIndexed(_isIndexed),
|
2020-04-07 09:10:10 +00:00
|
|
|
m_mutability(_mutability),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_overrides(std::move(_overrides)),
|
2020-07-15 17:50:59 +00:00
|
|
|
m_location(_referenceLocation)
|
|
|
|
{
|
|
|
|
solAssert(m_typeName, "");
|
|
|
|
}
|
2015-03-03 11:58:01 +00:00
|
|
|
|
2019-10-30 13:34:37 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2020-07-15 17:50:59 +00:00
|
|
|
TypeName const& typeName() const { return *m_typeName; }
|
2015-08-31 16:44:29 +00:00
|
|
|
ASTPointer<Expression> const& value() const { return m_value; }
|
2014-10-13 16:22:15 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
bool isLValue() const override;
|
|
|
|
bool isPartOfExternalInterface() const override { return isPublic(); }
|
2015-02-17 15:21:38 +00:00
|
|
|
|
2018-08-07 13:58:34 +00:00
|
|
|
/// @returns true iff this variable is the parameter (or return parameter) of a function
|
|
|
|
/// (or function type name or event) or declared inside a function body.
|
2018-02-09 15:53:52 +00:00
|
|
|
bool isLocalVariable() const;
|
2015-06-05 09:07:50 +00:00
|
|
|
/// @returns true if this variable is a parameter or return parameter of a function.
|
2019-09-05 18:02:34 +00:00
|
|
|
bool isCallableOrCatchParameter() const;
|
2017-07-06 09:05:05 +00:00
|
|
|
/// @returns true if this variable is a return parameter of a function.
|
|
|
|
bool isReturnParameter() const;
|
2019-09-05 18:02:34 +00:00
|
|
|
/// @returns true if this variable is a parameter of the success or failure clausse
|
|
|
|
/// of a try/catch statement.
|
|
|
|
bool isTryCatchParameter() const;
|
2017-07-06 09:05:05 +00:00
|
|
|
/// @returns true if this variable is a local variable or return parameter.
|
|
|
|
bool isLocalOrReturn() const;
|
2015-06-05 09:07:50 +00:00
|
|
|
/// @returns true if this variable is a parameter (not return parameter) of an external function.
|
2018-08-07 13:58:34 +00:00
|
|
|
/// This excludes parameters of external function type names.
|
2015-06-09 12:26:08 +00:00
|
|
|
bool isExternalCallableParameter() const;
|
2020-04-16 14:29:23 +00:00
|
|
|
/// @returns true if this variable is a parameter (not return parameter) of a public function.
|
|
|
|
bool isPublicCallableParameter() const;
|
2018-08-07 13:58:34 +00:00
|
|
|
/// @returns true if this variable is a parameter or return parameter of an internal function
|
|
|
|
/// or a function type of internal visibility.
|
|
|
|
bool isInternalCallableParameter() const;
|
2020-06-18 15:34:05 +00:00
|
|
|
/// @returns true if this variable is the parameter of a constructor.
|
2020-07-06 14:52:51 +00:00
|
|
|
bool isConstructorParameter() const;
|
2018-08-07 13:58:34 +00:00
|
|
|
/// @returns true iff this variable is a parameter(or return parameter of a library function
|
|
|
|
bool isLibraryFunctionParameter() const;
|
|
|
|
/// @returns true if the type of the variable is a reference or mapping type, i.e.
|
|
|
|
/// array, struct or mapping. These types can take a data location (and often require it).
|
|
|
|
/// Can only be called after reference resolution.
|
|
|
|
bool hasReferenceOrMappingType() const;
|
2020-09-28 17:31:54 +00:00
|
|
|
bool isStateVariable() const;
|
2020-09-25 10:15:31 +00:00
|
|
|
bool isFileLevelVariable() const;
|
2015-01-29 13:35:28 +00:00
|
|
|
bool isIndexed() const { return m_isIndexed; }
|
2020-04-07 09:10:10 +00:00
|
|
|
Mutability mutability() const { return m_mutability; }
|
|
|
|
bool isConstant() const { return m_mutability == Mutability::Constant; }
|
|
|
|
bool immutable() const { return m_mutability == Mutability::Immutable; }
|
2019-08-13 11:00:46 +00:00
|
|
|
ASTPointer<OverrideSpecifier> const& overrides() const { return m_overrides; }
|
2015-06-05 09:07:50 +00:00
|
|
|
Location referenceLocation() const { return m_location; }
|
2018-08-07 13:58:34 +00:00
|
|
|
/// @returns a set of allowed storage locations for the variable.
|
|
|
|
std::set<Location> allowedDataLocations() const;
|
2014-10-13 16:22:15 +00:00
|
|
|
|
2019-12-09 00:26:23 +00:00
|
|
|
/// @returns the external identifier of this variable (the hash of the signature) as a hex string (works only for public state variables).
|
|
|
|
std::string externalIdentifierHex() const;
|
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
TypePointer type() const override;
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2017-01-10 15:26:13 +00:00
|
|
|
/// @param _internal false indicates external interface is concerned, true indicates internal interface is concerned.
|
|
|
|
/// @returns null when it is not accessible as a function.
|
2018-11-16 01:09:04 +00:00
|
|
|
FunctionTypePointer functionType(bool /*_internal*/) const override;
|
2017-01-10 15:26:13 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
VariableDeclarationAnnotation& annotation() const override;
|
2015-09-21 16:55:58 +00:00
|
|
|
|
2015-02-02 16:24:09 +00:00
|
|
|
protected:
|
2015-08-31 16:44:29 +00:00
|
|
|
Visibility defaultVisibility() const override { return Visibility::Internal; }
|
2015-02-02 16:24:09 +00:00
|
|
|
|
2015-01-22 16:40:22 +00:00
|
|
|
private:
|
2020-07-15 17:50:59 +00:00
|
|
|
ASTPointer<TypeName> m_typeName;
|
2015-10-09 17:35:41 +00:00
|
|
|
/// Initially assigned value, can be missing. For local variables, this is stored inside
|
|
|
|
/// VariableDeclarationStatement and not here.
|
|
|
|
ASTPointer<Expression> m_value;
|
2019-11-05 17:25:34 +00:00
|
|
|
bool m_isIndexed = false; ///< Whether this is an indexed variable (used by events).
|
2020-02-25 17:42:16 +00:00
|
|
|
/// Whether the variable is "constant", "immutable" or non-marked (mutable).
|
2020-04-07 09:10:10 +00:00
|
|
|
Mutability m_mutability = Mutability::Mutable;
|
2019-08-13 11:00:46 +00:00
|
|
|
ASTPointer<OverrideSpecifier> m_overrides; ///< Contains the override specifier node
|
2019-11-05 17:25:34 +00:00
|
|
|
Location m_location = Location::Unspecified; ///< Location of the variable if it is of reference type.
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2015-01-21 10:16:18 +00:00
|
|
|
/**
|
|
|
|
* Definition of a function modifier.
|
|
|
|
*/
|
2020-08-06 12:46:04 +00:00
|
|
|
class ModifierDefinition: public CallableDeclaration, public StructurallyDocumented, public ImplementationOptional, public ScopeOpener
|
2015-01-21 10:16:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-06-15 12:39:34 +00:00
|
|
|
ModifierDefinition(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-06-15 12:39:34 +00:00
|
|
|
SourceLocation const& _location,
|
2015-06-09 12:26:08 +00:00
|
|
|
ASTPointer<ASTString> const& _name,
|
2021-01-21 15:01:39 +00:00
|
|
|
SourceLocation _nameLocation,
|
2020-01-29 22:13:42 +00:00
|
|
|
ASTPointer<StructuredDocumentation> const& _documentation,
|
2015-06-09 12:26:08 +00:00
|
|
|
ASTPointer<ParameterList> const& _parameters,
|
2019-10-30 13:34:37 +00:00
|
|
|
bool _isVirtual,
|
2019-09-16 10:32:14 +00:00
|
|
|
ASTPointer<OverrideSpecifier> const& _overrides,
|
2020-04-15 10:42:15 +00:00
|
|
|
ASTPointer<Block> const& _body
|
2015-06-09 12:26:08 +00:00
|
|
|
):
|
2021-01-21 15:01:39 +00:00
|
|
|
CallableDeclaration(_id, _location, _name, std::move(_nameLocation), Visibility::Internal, _parameters, _isVirtual, _overrides),
|
2020-01-29 22:13:42 +00:00
|
|
|
StructurallyDocumented(_documentation),
|
2020-04-15 10:42:15 +00:00
|
|
|
ImplementationOptional(_body != nullptr),
|
|
|
|
m_body(_body)
|
2015-06-09 12:26:08 +00:00
|
|
|
{
|
|
|
|
}
|
2015-01-21 10:16:18 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-01-21 10:16:18 +00:00
|
|
|
|
2020-04-15 10:42:15 +00:00
|
|
|
Block const& body() const { solAssert(m_body, ""); return *m_body; }
|
2015-01-21 10:16:18 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
TypePointer type() const override;
|
2015-01-21 10:16:18 +00:00
|
|
|
|
2020-01-14 13:00:51 +00:00
|
|
|
Visibility defaultVisibility() const override { return Visibility::Internal; }
|
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
ModifierDefinitionAnnotation& annotation() const override;
|
2015-10-26 14:13:36 +00:00
|
|
|
|
2020-03-24 17:25:59 +00:00
|
|
|
ModifierDefinition const& resolveVirtual(
|
|
|
|
ContractDefinition const& _mostDerivedContract,
|
|
|
|
ContractDefinition const* _searchStart = nullptr
|
|
|
|
) const override;
|
|
|
|
|
|
|
|
|
2015-01-21 10:16:18 +00:00
|
|
|
private:
|
|
|
|
ASTPointer<Block> m_body;
|
|
|
|
};
|
|
|
|
|
2015-01-22 00:02:38 +00:00
|
|
|
/**
|
2015-02-27 16:41:22 +00:00
|
|
|
* Invocation/usage of a modifier in a function header or a base constructor call.
|
2015-01-22 00:02:38 +00:00
|
|
|
*/
|
|
|
|
class ModifierInvocation: public ASTNode
|
|
|
|
{
|
|
|
|
public:
|
2015-09-16 14:56:30 +00:00
|
|
|
ModifierInvocation(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-16 14:56:30 +00:00
|
|
|
SourceLocation const& _location,
|
2020-08-11 09:18:22 +00:00
|
|
|
ASTPointer<IdentifierPath> _name,
|
2018-04-10 09:22:26 +00:00
|
|
|
std::unique_ptr<std::vector<ASTPointer<Expression>>> _arguments
|
2015-09-16 14:56:30 +00:00
|
|
|
):
|
2020-09-16 09:00:07 +00:00
|
|
|
ASTNode(_id, _location), m_modifierName(std::move(_name)), m_arguments(std::move(_arguments))
|
|
|
|
{
|
|
|
|
solAssert(m_modifierName != nullptr, "Name cannot be null.");
|
|
|
|
}
|
2015-01-22 00:02:38 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-01-22 00:02:38 +00:00
|
|
|
|
2020-08-11 09:18:22 +00:00
|
|
|
IdentifierPath& name() const { return *m_modifierName; }
|
2018-04-10 09:22:26 +00:00
|
|
|
// Returns nullptr if no argument list was given (``mod``).
|
|
|
|
// If an argument list is given (``mod(...)``), the arguments are returned
|
|
|
|
// as a vector of expressions. Note that this vector can be empty (``mod()``).
|
|
|
|
std::vector<ASTPointer<Expression>> const* arguments() const { return m_arguments.get(); }
|
2015-01-22 00:02:38 +00:00
|
|
|
|
|
|
|
private:
|
2020-08-11 09:18:22 +00:00
|
|
|
ASTPointer<IdentifierPath> m_modifierName;
|
2018-04-10 09:22:26 +00:00
|
|
|
std::unique_ptr<std::vector<ASTPointer<Expression>>> m_arguments;
|
2015-01-22 00:02:38 +00:00
|
|
|
};
|
|
|
|
|
2015-01-29 13:35:28 +00:00
|
|
|
/**
|
|
|
|
* Definition of a (loggable) event.
|
|
|
|
*/
|
2020-08-06 12:46:04 +00:00
|
|
|
class EventDefinition: public CallableDeclaration, public StructurallyDocumented, public ScopeOpener
|
2015-01-29 13:35:28 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-03-17 09:48:46 +00:00
|
|
|
EventDefinition(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-03-17 09:48:46 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
2021-01-21 15:01:39 +00:00
|
|
|
SourceLocation _nameLocation,
|
2020-01-29 22:13:42 +00:00
|
|
|
ASTPointer<StructuredDocumentation> const& _documentation,
|
2015-03-17 09:48:46 +00:00
|
|
|
ASTPointer<ParameterList> const& _parameters,
|
|
|
|
bool _anonymous = false
|
|
|
|
):
|
2021-01-21 15:01:39 +00:00
|
|
|
CallableDeclaration(_id, _location, _name, std::move(_nameLocation), Visibility::Default, _parameters),
|
2020-01-29 22:13:42 +00:00
|
|
|
StructurallyDocumented(_documentation),
|
2015-06-09 12:26:08 +00:00
|
|
|
m_anonymous(_anonymous)
|
|
|
|
{
|
|
|
|
}
|
2015-01-29 13:35:28 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-01-29 13:35:28 +00:00
|
|
|
|
2015-03-17 10:34:56 +00:00
|
|
|
bool isAnonymous() const { return m_anonymous; }
|
2015-01-29 13:35:28 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
TypePointer type() const override;
|
|
|
|
FunctionTypePointer functionType(bool /*_internal*/) const override;
|
2015-01-29 13:35:28 +00:00
|
|
|
|
2020-01-14 13:00:51 +00:00
|
|
|
bool isVisibleInDerivedContracts() const override { return true; }
|
|
|
|
bool isVisibleViaContractTypeAccess() const override { return false; /* TODO */ }
|
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
EventDefinitionAnnotation& annotation() const override;
|
2015-10-26 14:13:36 +00:00
|
|
|
|
2020-03-24 17:25:59 +00:00
|
|
|
CallableDeclaration const& resolveVirtual(
|
|
|
|
ContractDefinition const&,
|
|
|
|
ContractDefinition const*
|
|
|
|
) const override
|
|
|
|
{
|
2020-04-01 10:24:08 +00:00
|
|
|
return *this;
|
2020-03-24 17:25:59 +00:00
|
|
|
}
|
|
|
|
|
2015-01-29 13:35:28 +00:00
|
|
|
private:
|
2015-03-17 11:28:24 +00:00
|
|
|
bool m_anonymous = false;
|
2015-01-29 13:35:28 +00:00
|
|
|
};
|
|
|
|
|
2014-11-21 18:14:56 +00:00
|
|
|
/**
|
2014-11-26 12:19:17 +00:00
|
|
|
* Pseudo AST node that is used as declaration for "this", "msg", "tx", "block" and the global
|
2019-09-11 19:16:35 +00:00
|
|
|
* functions when such an identifier is encountered. Will never have a valid location in the source code
|
2014-11-21 18:14:56 +00:00
|
|
|
*/
|
|
|
|
class MagicVariableDeclaration: public Declaration
|
|
|
|
{
|
|
|
|
public:
|
2019-09-11 19:16:35 +00:00
|
|
|
MagicVariableDeclaration(int _id, ASTString const& _name, Type const* _type):
|
2021-01-21 15:01:39 +00:00
|
|
|
Declaration(_id, SourceLocation(), std::make_shared<ASTString>(_name), {}), m_type(_type) { }
|
2019-04-15 13:33:39 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor&) override
|
2015-10-02 12:41:40 +00:00
|
|
|
{
|
2017-07-19 01:19:00 +00:00
|
|
|
solAssert(false, "MagicVariableDeclaration used inside real AST.");
|
2015-10-02 12:41:40 +00:00
|
|
|
}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTConstVisitor&) const override
|
2015-10-02 12:41:40 +00:00
|
|
|
{
|
2017-07-19 01:19:00 +00:00
|
|
|
solAssert(false, "MagicVariableDeclaration used inside real AST.");
|
2015-10-02 12:41:40 +00:00
|
|
|
}
|
2014-11-21 18:14:56 +00:00
|
|
|
|
2019-04-15 13:33:39 +00:00
|
|
|
FunctionType const* functionType(bool) const override
|
2017-12-30 12:46:53 +00:00
|
|
|
{
|
|
|
|
solAssert(m_type->category() == Type::Category::Function, "");
|
2019-04-15 13:33:39 +00:00
|
|
|
return dynamic_cast<FunctionType const*>(m_type);
|
2017-12-30 12:46:53 +00:00
|
|
|
}
|
2018-11-16 01:09:04 +00:00
|
|
|
TypePointer type() const override { return m_type; }
|
2014-11-21 18:14:56 +00:00
|
|
|
|
|
|
|
private:
|
2019-04-15 13:33:39 +00:00
|
|
|
Type const* m_type;
|
2014-11-21 18:14:56 +00:00
|
|
|
};
|
|
|
|
|
2014-10-22 18:35:35 +00:00
|
|
|
/// Types
|
2014-10-07 16:25:04 +00:00
|
|
|
/// @{
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Abstract base class of a type name, can be any built-in or user-defined type.
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class TypeName: public ASTNode
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2017-08-22 13:03:51 +00:00
|
|
|
protected:
|
2019-09-11 19:16:35 +00:00
|
|
|
explicit TypeName(int64_t _id, SourceLocation const& _location): ASTNode(_id, _location) {}
|
2014-10-13 16:22:15 +00:00
|
|
|
|
2017-08-22 13:03:51 +00:00
|
|
|
public:
|
2018-11-16 01:09:04 +00:00
|
|
|
TypeNameAnnotation& annotation() const override;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
2018-09-06 16:59:50 +00:00
|
|
|
* Any pre-defined type name represented by a single keyword (and possibly a state mutability for address types),
|
|
|
|
* i.e. it excludes mappings, contracts, functions, etc.
|
2014-10-28 15:51:26 +00:00
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class ElementaryTypeName: public TypeName
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-09-06 16:59:50 +00:00
|
|
|
ElementaryTypeName(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2018-09-06 16:59:50 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ElementaryTypeNameToken const& _elem,
|
2019-10-28 10:39:30 +00:00
|
|
|
std::optional<StateMutability> _stateMutability = {}
|
2019-09-11 19:16:35 +00:00
|
|
|
): TypeName(_id, _location), m_type(_elem), m_stateMutability(_stateMutability)
|
2018-09-06 16:59:50 +00:00
|
|
|
{
|
2019-10-28 10:39:30 +00:00
|
|
|
solAssert(!_stateMutability.has_value() || _elem.token() == Token::Address, "");
|
2018-09-06 16:59:50 +00:00
|
|
|
}
|
2016-02-08 21:43:22 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2016-02-08 21:43:22 +00:00
|
|
|
ElementaryTypeNameToken const& typeName() const { return m_type; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2019-10-28 10:39:30 +00:00
|
|
|
std::optional<StateMutability> const& stateMutability() const { return m_stateMutability; }
|
2018-09-06 16:59:50 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2016-02-08 21:43:22 +00:00
|
|
|
ElementaryTypeNameToken m_type;
|
2019-10-28 10:39:30 +00:00
|
|
|
std::optional<StateMutability> m_stateMutability; ///< state mutability for address type
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
2014-11-20 17:33:23 +00:00
|
|
|
* Name referring to a user-defined type (i.e. a struct, contract, etc.).
|
2014-10-28 15:51:26 +00:00
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class UserDefinedTypeName: public TypeName
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-08-31 15:37:03 +00:00
|
|
|
UserDefinedTypeName(int64_t _id, SourceLocation const& _location, ASTPointer<IdentifierPath> _namePath):
|
2020-08-11 09:18:22 +00:00
|
|
|
TypeName(_id, _location), m_namePath(std::move(_namePath))
|
|
|
|
{
|
|
|
|
solAssert(m_namePath != nullptr, "Name cannot be null.");
|
|
|
|
}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2020-08-31 15:37:03 +00:00
|
|
|
std::vector<ASTString> const& namePath() const { return m_namePath->path(); }
|
2020-08-11 09:18:22 +00:00
|
|
|
IdentifierPath& pathNode() const { return *m_namePath; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2020-08-31 15:37:03 +00:00
|
|
|
ASTPointer<IdentifierPath> m_namePath;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2016-09-27 19:37:32 +00:00
|
|
|
/**
|
|
|
|
* A literal function type. Its source form is "function (paramType1, paramType2) internal / external returns (retType1, retType2)"
|
|
|
|
*/
|
2020-08-06 12:46:04 +00:00
|
|
|
class FunctionTypeName: public TypeName, public ScopeOpener
|
2016-09-27 19:37:32 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
FunctionTypeName(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2016-09-27 19:37:32 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<ParameterList> _parameterTypes,
|
|
|
|
ASTPointer<ParameterList> _returnTypes,
|
2019-12-10 14:54:09 +00:00
|
|
|
Visibility _visibility,
|
2017-07-01 09:09:24 +00:00
|
|
|
StateMutability _stateMutability
|
2016-09-27 19:37:32 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
TypeName(_id, _location), m_parameterTypes(std::move(_parameterTypes)), m_returnTypes(std::move(_returnTypes)),
|
2017-07-01 09:09:24 +00:00
|
|
|
m_visibility(_visibility), m_stateMutability(_stateMutability)
|
2016-09-27 19:37:32 +00:00
|
|
|
{}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2016-09-27 19:37:32 +00:00
|
|
|
|
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& parameterTypes() const { return m_parameterTypes->parameters(); }
|
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& returnParameterTypes() const { return m_returnTypes->parameters(); }
|
2017-05-24 11:52:16 +00:00
|
|
|
ASTPointer<ParameterList> const& parameterTypeList() const { return m_parameterTypes; }
|
|
|
|
ASTPointer<ParameterList> const& returnParameterTypeList() const { return m_returnTypes; }
|
2016-09-27 19:37:32 +00:00
|
|
|
|
2019-12-10 14:54:09 +00:00
|
|
|
Visibility visibility() const
|
2017-01-19 10:10:09 +00:00
|
|
|
{
|
2019-12-10 14:54:09 +00:00
|
|
|
return m_visibility == Visibility::Default ? Visibility::Internal : m_visibility;
|
2017-01-19 10:10:09 +00:00
|
|
|
}
|
2017-07-01 09:09:24 +00:00
|
|
|
StateMutability stateMutability() const { return m_stateMutability; }
|
|
|
|
bool isPayable() const { return m_stateMutability == StateMutability::Payable; }
|
2016-09-27 19:37:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ASTPointer<ParameterList> m_parameterTypes;
|
|
|
|
ASTPointer<ParameterList> m_returnTypes;
|
2019-12-10 14:54:09 +00:00
|
|
|
Visibility m_visibility;
|
2017-07-01 09:09:24 +00:00
|
|
|
StateMutability m_stateMutability;
|
2016-09-27 19:37:32 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* A mapping type. Its source form is "mapping('keyType' => 'valueType')"
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class Mapping: public TypeName
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
Mapping(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<TypeName> _keyType,
|
|
|
|
ASTPointer<TypeName> _valueType
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
TypeName(_id, _location), m_keyType(std::move(_keyType)), m_valueType(std::move(_valueType)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-11-10 16:31:09 +00:00
|
|
|
|
2020-02-04 09:59:23 +00:00
|
|
|
TypeName const& keyType() const { return *m_keyType; }
|
2015-08-31 16:44:29 +00:00
|
|
|
TypeName const& valueType() const { return *m_valueType; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2020-02-04 09:59:23 +00:00
|
|
|
ASTPointer<TypeName> m_keyType;
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<TypeName> m_valueType;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2015-02-20 14:52:30 +00:00
|
|
|
/**
|
|
|
|
* An array type, can be "typename[]" or "typename[<expression>]".
|
|
|
|
*/
|
|
|
|
class ArrayTypeName: public TypeName
|
|
|
|
{
|
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
ArrayTypeName(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<TypeName> _baseType,
|
|
|
|
ASTPointer<Expression> _length
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
TypeName(_id, _location), m_baseType(std::move(_baseType)), m_length(std::move(_length)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-02-20 14:52:30 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
TypeName const& baseType() const { return *m_baseType; }
|
|
|
|
Expression const* length() const { return m_length.get(); }
|
2015-02-20 14:52:30 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ASTPointer<TypeName> m_baseType;
|
|
|
|
ASTPointer<Expression> m_length; ///< Length of the array, might be empty.
|
|
|
|
};
|
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
/// @}
|
|
|
|
|
|
|
|
/// Statements
|
|
|
|
/// @{
|
|
|
|
|
2014-10-22 18:35:35 +00:00
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Abstract base class for statements.
|
|
|
|
*/
|
2015-10-26 16:20:29 +00:00
|
|
|
class Statement: public ASTNode, public Documented
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-08 18:53:50 +00:00
|
|
|
public:
|
2015-10-26 16:20:29 +00:00
|
|
|
explicit Statement(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-10-26 16:20:29 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _docString
|
2019-09-11 19:16:35 +00:00
|
|
|
): ASTNode(_id, _location), Documented(_docString) {}
|
2015-10-26 16:20:29 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
StatementAnnotation& annotation() const override;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2016-02-22 01:13:41 +00:00
|
|
|
/**
|
|
|
|
* Inline assembly.
|
|
|
|
*/
|
|
|
|
class InlineAssembly: public Statement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InlineAssembly(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2016-02-22 01:13:41 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _docString,
|
2019-05-22 11:57:48 +00:00
|
|
|
yul::Dialect const& _dialect,
|
2020-04-01 03:04:29 +00:00
|
|
|
std::shared_ptr<yul::Block> _operations
|
2016-02-22 01:13:41 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
Statement(_id, _location, _docString), m_dialect(_dialect), m_operations(std::move(_operations)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2016-02-22 01:13:41 +00:00
|
|
|
|
2019-05-22 11:57:48 +00:00
|
|
|
yul::Dialect const& dialect() const { return m_dialect; }
|
2018-11-21 11:42:34 +00:00
|
|
|
yul::Block const& operations() const { return *m_operations; }
|
2016-03-01 21:56:39 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
InlineAssemblyAnnotation& annotation() const override;
|
2016-02-22 01:13:41 +00:00
|
|
|
|
|
|
|
private:
|
2019-05-22 11:57:48 +00:00
|
|
|
yul::Dialect const& m_dialect;
|
2018-11-21 11:42:34 +00:00
|
|
|
std::shared_ptr<yul::Block> m_operations;
|
2016-02-22 01:13:41 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Brace-enclosed block containing zero or more statements.
|
|
|
|
*/
|
2020-08-06 12:46:04 +00:00
|
|
|
class Block: public Statement, public Scopable, public ScopeOpener
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-08 18:53:50 +00:00
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
Block(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2015-10-26 16:20:29 +00:00
|
|
|
ASTPointer<ASTString> const& _docString,
|
2020-07-22 08:28:04 +00:00
|
|
|
bool _unchecked,
|
2020-04-01 03:04:29 +00:00
|
|
|
std::vector<ASTPointer<Statement>> _statements
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2020-07-22 08:28:04 +00:00
|
|
|
Statement(_id, _location, _docString),
|
|
|
|
m_statements(std::move(_statements)),
|
|
|
|
m_unchecked(_unchecked)
|
|
|
|
{}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-13 16:22:15 +00:00
|
|
|
|
2015-11-11 14:20:53 +00:00
|
|
|
std::vector<ASTPointer<Statement>> const& statements() const { return m_statements; }
|
2020-07-22 08:28:04 +00:00
|
|
|
bool unchecked() const { return m_unchecked; }
|
2015-11-11 14:20:53 +00:00
|
|
|
|
2019-12-20 01:20:27 +00:00
|
|
|
BlockAnnotation& annotation() const override;
|
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
std::vector<ASTPointer<Statement>> m_statements;
|
2020-07-22 08:28:04 +00:00
|
|
|
bool m_unchecked;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2015-01-21 10:16:18 +00:00
|
|
|
/**
|
|
|
|
* Special placeholder statement denoted by "_" used in function modifiers. This is replaced by
|
|
|
|
* the original function when the modifier is applied.
|
|
|
|
*/
|
|
|
|
class PlaceholderStatement: public Statement
|
|
|
|
{
|
|
|
|
public:
|
2015-10-26 16:20:29 +00:00
|
|
|
explicit PlaceholderStatement(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-10-26 16:20:29 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _docString
|
2019-09-11 19:16:35 +00:00
|
|
|
): Statement(_id, _location, _docString) {}
|
2015-01-21 10:16:18 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-01-21 10:16:18 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* If-statement with an optional "else" part. Note that "else if" is modeled by having a new
|
|
|
|
* if-statement as the false (else) body.
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class IfStatement: public Statement
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
IfStatement(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2015-10-26 16:20:29 +00:00
|
|
|
ASTPointer<ASTString> const& _docString,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _condition,
|
|
|
|
ASTPointer<Statement> _trueBody,
|
|
|
|
ASTPointer<Statement> _falseBody
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2019-09-11 19:16:35 +00:00
|
|
|
Statement(_id, _location, _docString),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_condition(std::move(_condition)),
|
|
|
|
m_trueBody(std::move(_trueBody)),
|
|
|
|
m_falseBody(std::move(_falseBody))
|
2015-09-24 09:03:44 +00:00
|
|
|
{}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
Expression const& condition() const { return *m_condition; }
|
|
|
|
Statement const& trueStatement() const { return *m_trueBody; }
|
2015-02-10 12:40:21 +00:00
|
|
|
/// @returns the "else" part of the if statement or nullptr if there is no "else" part.
|
2015-08-31 16:44:29 +00:00
|
|
|
Statement const* falseStatement() const { return m_falseBody.get(); }
|
2014-11-03 17:39:16 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<Expression> m_condition;
|
|
|
|
ASTPointer<Statement> m_trueBody;
|
2014-10-31 12:29:32 +00:00
|
|
|
ASTPointer<Statement> m_falseBody; ///< "else" part, optional
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2019-09-02 14:17:02 +00:00
|
|
|
/**
|
|
|
|
* Clause of a try-catch block. Includes both the successful case and the
|
|
|
|
* unsuccessful cases.
|
|
|
|
* Names are only allowed for the unsuccessful cases.
|
|
|
|
*/
|
2020-08-06 12:46:04 +00:00
|
|
|
class TryCatchClause: public ASTNode, public Scopable, public ScopeOpener
|
2019-09-02 14:17:02 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
TryCatchClause(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2019-09-02 14:17:02 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<ASTString> _errorName,
|
|
|
|
ASTPointer<ParameterList> _parameters,
|
|
|
|
ASTPointer<Block> _block
|
2019-09-02 14:17:02 +00:00
|
|
|
):
|
2019-09-11 19:16:35 +00:00
|
|
|
ASTNode(_id, _location),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_errorName(std::move(_errorName)),
|
|
|
|
m_parameters(std::move(_parameters)),
|
|
|
|
m_block(std::move(_block))
|
2019-09-02 14:17:02 +00:00
|
|
|
{}
|
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
|
|
|
ASTString const& errorName() const { return *m_errorName; }
|
|
|
|
ParameterList const* parameters() const { return m_parameters.get(); }
|
|
|
|
Block const& block() const { return *m_block; }
|
|
|
|
|
2019-12-20 01:20:27 +00:00
|
|
|
TryCatchClauseAnnotation& annotation() const override;
|
|
|
|
|
2019-09-02 14:17:02 +00:00
|
|
|
private:
|
|
|
|
ASTPointer<ASTString> m_errorName;
|
|
|
|
ASTPointer<ParameterList> m_parameters;
|
|
|
|
ASTPointer<Block> m_block;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try-statement with a variable number of catch statements.
|
|
|
|
* Syntax:
|
|
|
|
* try <call> returns (uint x, uint y) {
|
|
|
|
* // success code
|
2020-10-20 13:30:46 +00:00
|
|
|
* } catch Panic(uint errorCode) {
|
|
|
|
* // panic
|
2019-09-02 14:17:02 +00:00
|
|
|
* } catch Error(string memory cause) {
|
|
|
|
* // error code, reason provided
|
|
|
|
* } catch (bytes memory lowLevelData) {
|
|
|
|
* // error code, no reason provided or non-matching error signature.
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* The last statement given above can also be specified as
|
|
|
|
* } catch () {
|
|
|
|
*/
|
|
|
|
class TryStatement: public Statement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TryStatement(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2019-09-02 14:17:02 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _docString,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _externalCall,
|
|
|
|
std::vector<ASTPointer<TryCatchClause>> _clauses
|
2019-09-02 14:17:02 +00:00
|
|
|
):
|
2019-09-11 19:16:35 +00:00
|
|
|
Statement(_id, _location, _docString),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_externalCall(std::move(_externalCall)),
|
|
|
|
m_clauses(std::move(_clauses))
|
2019-09-02 14:17:02 +00:00
|
|
|
{}
|
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
|
|
|
Expression const& externalCall() const { return *m_externalCall; }
|
|
|
|
std::vector<ASTPointer<TryCatchClause>> const& clauses() const { return m_clauses; }
|
|
|
|
|
2020-03-16 10:47:39 +00:00
|
|
|
TryCatchClause const* successClause() const;
|
2020-10-20 13:30:46 +00:00
|
|
|
TryCatchClause const* panicClause() const;
|
|
|
|
TryCatchClause const* errorClause() const;
|
2020-03-16 10:47:39 +00:00
|
|
|
TryCatchClause const* fallbackClause() const;
|
|
|
|
|
2019-09-02 14:17:02 +00:00
|
|
|
private:
|
|
|
|
ASTPointer<Expression> m_externalCall;
|
|
|
|
std::vector<ASTPointer<TryCatchClause>> m_clauses;
|
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
2014-12-05 16:29:20 +00:00
|
|
|
* Statement in which a break statement is legal (abstract class).
|
2014-10-28 15:51:26 +00:00
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class BreakableStatement: public Statement
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-10-26 16:20:29 +00:00
|
|
|
explicit BreakableStatement(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-10-26 16:20:29 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _docString
|
2019-09-11 19:16:35 +00:00
|
|
|
): Statement(_id, _location, _docString) {}
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-16 21:49:45 +00:00
|
|
|
class WhileStatement: public BreakableStatement
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
WhileStatement(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2015-10-26 16:20:29 +00:00
|
|
|
ASTPointer<ASTString> const& _docString,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _condition,
|
|
|
|
ASTPointer<Statement> _body,
|
2016-07-30 07:13:05 +00:00
|
|
|
bool _isDoWhile
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
BreakableStatement(_id, _location, _docString), m_condition(std::move(_condition)), m_body(std::move(_body)),
|
2016-07-30 07:13:05 +00:00
|
|
|
m_isDoWhile(_isDoWhile) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
Expression const& condition() const { return *m_condition; }
|
|
|
|
Statement const& body() const { return *m_body; }
|
2016-07-30 07:13:05 +00:00
|
|
|
bool isDoWhile() const { return m_isDoWhile; }
|
2014-11-03 17:39:16 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<Expression> m_condition;
|
|
|
|
ASTPointer<Statement> m_body;
|
2016-07-30 07:13:05 +00:00
|
|
|
bool m_isDoWhile;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-12-16 13:46:17 +00:00
|
|
|
/**
|
|
|
|
* For loop statement
|
|
|
|
*/
|
2020-08-06 12:46:04 +00:00
|
|
|
class ForStatement: public BreakableStatement, public Scopable, public ScopeOpener
|
2014-12-15 16:45:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-09-16 14:56:30 +00:00
|
|
|
ForStatement(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-16 14:56:30 +00:00
|
|
|
SourceLocation const& _location,
|
2015-10-26 16:20:29 +00:00
|
|
|
ASTPointer<ASTString> const& _docString,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Statement> _initExpression,
|
|
|
|
ASTPointer<Expression> _conditionExpression,
|
|
|
|
ASTPointer<ExpressionStatement> _loopExpression,
|
|
|
|
ASTPointer<Statement> _body
|
2015-09-16 14:56:30 +00:00
|
|
|
):
|
2019-09-11 19:16:35 +00:00
|
|
|
BreakableStatement(_id, _location, _docString),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_initExpression(std::move(_initExpression)),
|
|
|
|
m_condExpression(std::move(_conditionExpression)),
|
|
|
|
m_loopExpression(std::move(_loopExpression)),
|
|
|
|
m_body(std::move(_body))
|
2015-09-16 14:56:30 +00:00
|
|
|
{}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-12-15 16:45:18 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
Statement const* initializationExpression() const { return m_initExpression.get(); }
|
|
|
|
Expression const* condition() const { return m_condExpression.get(); }
|
|
|
|
ExpressionStatement const* loopExpression() const { return m_loopExpression.get(); }
|
|
|
|
Statement const& body() const { return *m_body; }
|
2014-12-16 15:52:47 +00:00
|
|
|
|
2019-12-20 01:20:27 +00:00
|
|
|
ForStatementAnnotation& annotation() const override;
|
|
|
|
|
2014-12-15 16:45:18 +00:00
|
|
|
private:
|
2018-11-12 08:14:55 +00:00
|
|
|
/// For statement's initialization expression. for (XXX; ; ). Can be empty
|
2014-12-16 12:20:50 +00:00
|
|
|
ASTPointer<Statement> m_initExpression;
|
2018-11-12 08:14:55 +00:00
|
|
|
/// For statement's condition expression. for (; XXX ; ). Can be empty
|
2014-12-15 16:45:18 +00:00
|
|
|
ASTPointer<Expression> m_condExpression;
|
2018-11-12 08:14:55 +00:00
|
|
|
/// For statement's loop expression. for (;;XXX). Can be empty
|
2014-12-15 16:45:18 +00:00
|
|
|
ASTPointer<ExpressionStatement> m_loopExpression;
|
2014-12-16 13:46:17 +00:00
|
|
|
/// The body of the loop
|
2014-12-15 16:45:18 +00:00
|
|
|
ASTPointer<Statement> m_body;
|
|
|
|
};
|
|
|
|
|
2014-10-16 21:49:45 +00:00
|
|
|
class Continue: public Statement
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2019-09-11 19:16:35 +00:00
|
|
|
explicit Continue(int64_t _id, SourceLocation const& _location, ASTPointer<ASTString> const& _docString):
|
|
|
|
Statement(_id, _location, _docString) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-16 21:49:45 +00:00
|
|
|
class Break: public Statement
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2019-09-11 19:16:35 +00:00
|
|
|
explicit Break(int64_t _id, SourceLocation const& _location, ASTPointer<ASTString> const& _docString):
|
|
|
|
Statement(_id, _location, _docString) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-16 21:49:45 +00:00
|
|
|
class Return: public Statement
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-10-26 16:20:29 +00:00
|
|
|
Return(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-10-26 16:20:29 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _docString,
|
|
|
|
ASTPointer<Expression> _expression
|
2020-04-01 03:04:29 +00:00
|
|
|
): Statement(_id, _location, _docString), m_expression(std::move(_expression)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-13 16:22:15 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
Expression const* expression() const { return m_expression.get(); }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
ReturnAnnotation& annotation() const override;
|
2015-09-21 16:55:58 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2014-10-31 12:29:32 +00:00
|
|
|
ASTPointer<Expression> m_expression; ///< value to return, optional
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2015-09-15 14:33:14 +00:00
|
|
|
/**
|
|
|
|
* @brief The Throw statement to throw that triggers a solidity exception(jump to ErrorTag)
|
|
|
|
*/
|
|
|
|
class Throw: public Statement
|
|
|
|
{
|
|
|
|
public:
|
2019-09-11 19:16:35 +00:00
|
|
|
explicit Throw(int64_t _id, SourceLocation const& _location, ASTPointer<ASTString> const& _docString):
|
|
|
|
Statement(_id, _location, _docString) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-09-15 14:33:14 +00:00
|
|
|
};
|
|
|
|
|
2018-02-16 15:55:21 +00:00
|
|
|
/**
|
|
|
|
* The emit statement is used to emit events: emit EventName(arg1, ..., argn)
|
|
|
|
*/
|
|
|
|
class EmitStatement: public Statement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit EmitStatement(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2018-02-16 15:55:21 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _docString,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<FunctionCall> _functionCall
|
2018-02-16 15:55:21 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
Statement(_id, _location, _docString), m_eventCall(std::move(_functionCall)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2018-02-16 15:55:21 +00:00
|
|
|
|
|
|
|
FunctionCall const& eventCall() const { return *m_eventCall; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ASTPointer<FunctionCall> m_eventCall;
|
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
2018-07-10 12:55:50 +00:00
|
|
|
* Definition of one or more variables as a statement inside a function.
|
|
|
|
* If multiple variables are declared, a value has to be assigned directly.
|
|
|
|
* If only a single variable is declared, the value can be missing.
|
|
|
|
* Examples:
|
|
|
|
* uint[] memory a; uint a = 2;
|
|
|
|
* (uint a, bytes32 b, ) = f(); (, uint a, , StructName storage x) = g();
|
2014-10-28 15:51:26 +00:00
|
|
|
*/
|
2015-02-17 15:21:38 +00:00
|
|
|
class VariableDeclarationStatement: public Statement
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-10-08 16:01:12 +00:00
|
|
|
VariableDeclarationStatement(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-10-08 16:01:12 +00:00
|
|
|
SourceLocation const& _location,
|
2015-10-26 16:20:29 +00:00
|
|
|
ASTPointer<ASTString> const& _docString,
|
2020-04-01 03:04:29 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> _variables,
|
|
|
|
ASTPointer<Expression> _initialValue
|
2015-10-08 16:01:12 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
Statement(_id, _location, _docString), m_variables(std::move(_variables)), m_initialValue(std::move(_initialValue)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-13 16:22:15 +00:00
|
|
|
|
2015-10-08 16:01:12 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& declarations() const { return m_variables; }
|
|
|
|
Expression const* initialValue() const { return m_initialValue.get(); }
|
2014-10-30 00:20:32 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2015-10-08 16:01:12 +00:00
|
|
|
/// List of variables, some of which can be empty pointers (unnamed components).
|
2018-07-10 12:55:50 +00:00
|
|
|
/// Note that the ``m_value`` member of these is unused. Instead, ``m_initialValue``
|
|
|
|
/// below is used, because the initial value can be a single expression assigned
|
|
|
|
/// to all variables.
|
2015-10-08 16:01:12 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> m_variables;
|
|
|
|
/// The assigned expression / initial value.
|
|
|
|
ASTPointer<Expression> m_initialValue;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-30 00:20:32 +00:00
|
|
|
/**
|
|
|
|
* A statement that contains only an expression (i.e. an assignment, function call, ...).
|
|
|
|
*/
|
|
|
|
class ExpressionStatement: public Statement
|
|
|
|
{
|
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
ExpressionStatement(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2015-10-26 16:20:29 +00:00
|
|
|
ASTPointer<ASTString> const& _docString,
|
2015-09-24 09:03:44 +00:00
|
|
|
ASTPointer<Expression> _expression
|
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
Statement(_id, _location, _docString), m_expression(std::move(_expression)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-30 00:20:32 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
Expression const& expression() const { return *m_expression; }
|
2014-10-30 00:20:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ASTPointer<Expression> m_expression;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
/// Expressions
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An expression, i.e. something that has a value (which can also be of type "void" in case
|
|
|
|
* of some function calls).
|
|
|
|
* @abstract
|
|
|
|
*/
|
|
|
|
class Expression: public ASTNode
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2019-09-11 19:16:35 +00:00
|
|
|
explicit Expression(int64_t _id, SourceLocation const& _location): ASTNode(_id, _location) {}
|
2014-10-30 00:20:32 +00:00
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
ExpressionAnnotation& annotation() const override;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2015-12-22 16:44:51 +00:00
|
|
|
class Conditional: public Expression
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Conditional(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-12-22 16:44:51 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _condition,
|
|
|
|
ASTPointer<Expression> _trueExpression,
|
|
|
|
ASTPointer<Expression> _falseExpression
|
2015-12-22 16:44:51 +00:00
|
|
|
):
|
2019-09-11 19:16:35 +00:00
|
|
|
Expression(_id, _location),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_condition(std::move(_condition)),
|
|
|
|
m_trueExpression(std::move(_trueExpression)),
|
|
|
|
m_falseExpression(std::move(_falseExpression))
|
2015-12-22 16:44:51 +00:00
|
|
|
{}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-12-22 16:44:51 +00:00
|
|
|
|
|
|
|
Expression const& condition() const { return *m_condition; }
|
|
|
|
Expression const& trueExpression() const { return *m_trueExpression; }
|
|
|
|
Expression const& falseExpression() const { return *m_falseExpression; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ASTPointer<Expression> m_condition;
|
|
|
|
ASTPointer<Expression> m_trueExpression;
|
|
|
|
ASTPointer<Expression> m_falseExpression;
|
|
|
|
};
|
|
|
|
|
2014-10-22 18:35:35 +00:00
|
|
|
/// Assignment, can also be a compound assignment.
|
|
|
|
/// Examples: (a = 7 + 8) or (a *= 2)
|
2014-10-16 21:49:45 +00:00
|
|
|
class Assignment: public Expression
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-09-16 14:56:30 +00:00
|
|
|
Assignment(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-16 14:56:30 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _leftHandSide,
|
2018-10-22 14:48:21 +00:00
|
|
|
Token _assignmentOperator,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _rightHandSide
|
2015-09-16 14:56:30 +00:00
|
|
|
):
|
2019-09-11 19:16:35 +00:00
|
|
|
Expression(_id, _location),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_leftHandSide(std::move(_leftHandSide)),
|
2015-09-16 14:56:30 +00:00
|
|
|
m_assigmentOperator(_assignmentOperator),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_rightHandSide(std::move(_rightHandSide))
|
2014-11-05 13:20:56 +00:00
|
|
|
{
|
2018-10-22 14:48:21 +00:00
|
|
|
solAssert(TokenTraits::isAssignmentOp(_assignmentOperator), "");
|
2014-11-05 13:20:56 +00:00
|
|
|
}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
Expression const& leftHandSide() const { return *m_leftHandSide; }
|
2018-10-22 14:48:21 +00:00
|
|
|
Token assignmentOperator() const { return m_assigmentOperator; }
|
2015-08-31 16:44:29 +00:00
|
|
|
Expression const& rightHandSide() const { return *m_rightHandSide; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<Expression> m_leftHandSide;
|
2018-10-22 14:48:21 +00:00
|
|
|
Token m_assigmentOperator;
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<Expression> m_rightHandSide;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2015-12-14 23:40:35 +00:00
|
|
|
|
2015-10-12 21:02:35 +00:00
|
|
|
/**
|
2015-12-14 23:40:35 +00:00
|
|
|
* Tuple, parenthesized expression, or bracketed expression.
|
2017-03-20 18:06:17 +00:00
|
|
|
* Examples: (1, 2), (x,), (x), (), [1, 2],
|
2015-10-12 21:02:35 +00:00
|
|
|
* Individual components might be empty shared pointers (as in the second example).
|
|
|
|
* The respective types in lvalue context are: 2-tuple, 2-tuple (with wildcard), type of x, 0-tuple
|
|
|
|
* Not in lvalue context: 2-tuple, _1_-tuple, type of x, 0-tuple.
|
|
|
|
*/
|
|
|
|
class TupleExpression: public Expression
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TupleExpression(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-10-12 21:02:35 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
std::vector<ASTPointer<Expression>> _components,
|
2015-12-15 17:16:54 +00:00
|
|
|
bool _isArray
|
2015-10-12 21:02:35 +00:00
|
|
|
):
|
2019-09-11 19:16:35 +00:00
|
|
|
Expression(_id, _location),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_components(std::move(_components)),
|
2015-12-15 17:16:54 +00:00
|
|
|
m_isArray(_isArray) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-10-12 21:02:35 +00:00
|
|
|
|
|
|
|
std::vector<ASTPointer<Expression>> const& components() const { return m_components; }
|
2015-12-15 18:22:52 +00:00
|
|
|
bool isInlineArray() const { return m_isArray; }
|
2015-10-12 21:02:35 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<ASTPointer<Expression>> m_components;
|
2015-12-15 18:22:52 +00:00
|
|
|
bool m_isArray;
|
2015-10-12 21:02:35 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Operation involving a unary operator, pre- or postfix.
|
|
|
|
* Examples: ++i, delete x or !true
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class UnaryOperation: public Expression
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
UnaryOperation(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2018-10-22 14:48:21 +00:00
|
|
|
Token _operator,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _subExpression,
|
2015-09-24 09:03:44 +00:00
|
|
|
bool _isPrefix
|
|
|
|
):
|
2019-09-11 19:16:35 +00:00
|
|
|
Expression(_id, _location),
|
2015-09-24 09:03:44 +00:00
|
|
|
m_operator(_operator),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_subExpression(std::move(_subExpression)),
|
2015-09-24 09:03:44 +00:00
|
|
|
m_isPrefix(_isPrefix)
|
2014-11-05 13:20:56 +00:00
|
|
|
{
|
2018-10-22 14:48:21 +00:00
|
|
|
solAssert(TokenTraits::isUnaryOp(_operator), "");
|
2014-11-05 13:20:56 +00:00
|
|
|
}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-09 13:57:49 +00:00
|
|
|
|
2018-10-22 14:48:21 +00:00
|
|
|
Token getOperator() const { return m_operator; }
|
2014-10-10 14:37:54 +00:00
|
|
|
bool isPrefixOperation() const { return m_isPrefix; }
|
2015-08-31 16:44:29 +00:00
|
|
|
Expression const& subExpression() const { return *m_subExpression; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2018-10-22 14:48:21 +00:00
|
|
|
Token m_operator;
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<Expression> m_subExpression;
|
2014-10-09 13:57:49 +00:00
|
|
|
bool m_isPrefix;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Operation involving a binary operator.
|
|
|
|
* Examples: 1 + 2, true && false or 1 <= 4
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class BinaryOperation: public Expression
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
BinaryOperation(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _left,
|
2018-10-22 14:48:21 +00:00
|
|
|
Token _operator,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _right
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
Expression(_id, _location), m_left(std::move(_left)), m_operator(_operator), m_right(std::move(_right))
|
2014-11-05 13:20:56 +00:00
|
|
|
{
|
2018-10-22 14:48:21 +00:00
|
|
|
solAssert(TokenTraits::isBinaryOp(_operator) || TokenTraits::isCompareOp(_operator), "");
|
2014-11-05 13:20:56 +00:00
|
|
|
}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
Expression const& leftExpression() const { return *m_left; }
|
|
|
|
Expression const& rightExpression() const { return *m_right; }
|
2018-10-22 14:48:21 +00:00
|
|
|
Token getOperator() const { return m_operator; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
BinaryOperationAnnotation& annotation() const override;
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<Expression> m_left;
|
2018-10-22 14:48:21 +00:00
|
|
|
Token m_operator;
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<Expression> m_right;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Can be ordinary function call, type cast or struct construction.
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class FunctionCall: public Expression
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
FunctionCall(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _expression,
|
|
|
|
std::vector<ASTPointer<Expression>> _arguments,
|
|
|
|
std::vector<ASTPointer<ASTString>> _names
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
Expression(_id, _location), m_expression(std::move(_expression)), m_arguments(std::move(_arguments)), m_names(std::move(_names)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-22 18:35:35 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
Expression const& expression() const { return *m_expression; }
|
2020-11-09 13:09:34 +00:00
|
|
|
/// @returns the given arguments in the order they were written.
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<ASTPointer<Expression const>> arguments() const { return {m_arguments.begin(), m_arguments.end()}; }
|
2020-11-09 13:09:34 +00:00
|
|
|
/// @returns the given arguments sorted by how the called function takes them.
|
|
|
|
std::vector<ASTPointer<Expression const>> sortedArguments() const;
|
|
|
|
/// @returns the list of given argument names if this is a named call,
|
|
|
|
/// in the order they were written.
|
|
|
|
/// If this is not a named call, this is empty.
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<ASTPointer<ASTString>> const& names() const { return m_names; }
|
2014-10-25 14:52:22 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
FunctionCallAnnotation& annotation() const override;
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<Expression> m_expression;
|
|
|
|
std::vector<ASTPointer<Expression>> m_arguments;
|
2015-02-03 20:25:08 +00:00
|
|
|
std::vector<ASTPointer<ASTString>> m_names;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2020-01-22 14:42:50 +00:00
|
|
|
/**
|
|
|
|
* Expression that annotates a function call / a new expression with extra
|
|
|
|
* options like gas, value, salt: new SomeContract{salt=123}(params)
|
|
|
|
*/
|
|
|
|
class FunctionCallOptions: public Expression
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FunctionCallOptions(
|
|
|
|
int64_t _id,
|
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _expression,
|
|
|
|
std::vector<ASTPointer<Expression>> _options,
|
|
|
|
std::vector<ASTPointer<ASTString>> _names
|
2020-01-22 14:42:50 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
Expression(_id, _location), m_expression(std::move(_expression)), m_options(std::move(_options)), m_names(std::move(_names)) {}
|
2020-01-22 14:42:50 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
|
|
|
Expression const& expression() const { return *m_expression; }
|
|
|
|
std::vector<ASTPointer<Expression const>> options() const { return {m_options.begin(), m_options.end()}; }
|
|
|
|
std::vector<ASTPointer<ASTString>> const& names() const { return m_names; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ASTPointer<Expression> m_expression;
|
|
|
|
std::vector<ASTPointer<Expression>> m_options;
|
|
|
|
std::vector<ASTPointer<ASTString>> m_names;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-12-12 15:49:26 +00:00
|
|
|
/**
|
2015-11-16 23:06:57 +00:00
|
|
|
* Expression that creates a new contract or memory-array,
|
|
|
|
* e.g. the "new SomeContract" part in "new SomeContract(1, 2)".
|
2014-12-12 15:49:26 +00:00
|
|
|
*/
|
|
|
|
class NewExpression: public Expression
|
|
|
|
{
|
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
NewExpression(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<TypeName> _typeName
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
Expression(_id, _location), m_typeName(std::move(_typeName)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-12-12 15:49:26 +00:00
|
|
|
|
2015-11-16 23:06:57 +00:00
|
|
|
TypeName const& typeName() const { return *m_typeName; }
|
2014-12-12 15:49:26 +00:00
|
|
|
|
|
|
|
private:
|
2015-11-16 23:06:57 +00:00
|
|
|
ASTPointer<TypeName> m_typeName;
|
2014-12-12 15:49:26 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Access to a member of an object. Example: x.name
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class MemberAccess: public Expression
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
MemberAccess(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<Expression> _expression,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<ASTString> _memberName
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
Expression(_id, _location), m_expression(std::move(_expression)), m_memberName(std::move(_memberName)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2015-08-31 16:44:29 +00:00
|
|
|
Expression const& expression() const { return *m_expression; }
|
|
|
|
ASTString const& memberName() const { return *m_memberName; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
MemberAccessAnnotation& annotation() const override;
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<Expression> m_expression;
|
|
|
|
ASTPointer<ASTString> m_memberName;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
2019-02-21 11:54:39 +00:00
|
|
|
* Index access to an array or mapping. Example: a[2]
|
2014-10-28 15:51:26 +00:00
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class IndexAccess: public Expression
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
IndexAccess(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _base,
|
|
|
|
ASTPointer<Expression> _index
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
Expression(_id, _location), m_base(std::move(_base)), m_index(std::move(_index)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
Expression const& baseExpression() const { return *m_base; }
|
|
|
|
Expression const* indexExpression() const { return m_index.get(); }
|
2014-11-13 00:12:57 +00:00
|
|
|
|
2014-10-09 13:57:49 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<Expression> m_base;
|
|
|
|
ASTPointer<Expression> m_index;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2019-09-03 16:30:00 +00:00
|
|
|
/**
|
|
|
|
* Index range access to an array. Example: a[2:3]
|
|
|
|
*/
|
|
|
|
class IndexRangeAccess: public Expression
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
IndexRangeAccess(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2019-09-03 16:30:00 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<Expression> _base,
|
|
|
|
ASTPointer<Expression> _start,
|
|
|
|
ASTPointer<Expression> _end
|
2019-09-03 16:30:00 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
Expression(_id, _location), m_base(std::move(_base)), m_start(std::move(_start)), m_end(std::move(_end)) {}
|
2019-09-03 16:30:00 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
|
|
|
Expression const& baseExpression() const { return *m_base; }
|
|
|
|
Expression const* startExpression() const { return m_start.get(); }
|
|
|
|
Expression const* endExpression() const { return m_end.get(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ASTPointer<Expression> m_base;
|
|
|
|
ASTPointer<Expression> m_start;
|
|
|
|
ASTPointer<Expression> m_end;
|
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Primary expression, i.e. an expression that cannot be divided any further. Examples are literals
|
|
|
|
* or variable references.
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class PrimaryExpression: public Expression
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2019-09-11 19:16:35 +00:00
|
|
|
PrimaryExpression(int64_t _id, SourceLocation const& _location): Expression(_id, _location) {}
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* An identifier, i.e. a reference to a declaration by name like a variable or function.
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class Identifier: public PrimaryExpression
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-09-24 09:03:44 +00:00
|
|
|
Identifier(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<ASTString> _name
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
PrimaryExpression(_id, _location), m_name(std::move(_name)) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
ASTString const& name() const { return *m_name; }
|
2014-10-22 18:35:35 +00:00
|
|
|
|
2018-11-16 01:09:04 +00:00
|
|
|
IdentifierAnnotation& annotation() const override;
|
2015-09-10 15:17:13 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<ASTString> m_name;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* An elementary type name expression is used in expressions like "a = uint32(2)" to change the
|
|
|
|
* type of an expression explicitly. Here, "uint32" is the elementary type name expression and
|
|
|
|
* "uint32(2)" is a @ref FunctionCall.
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class ElementaryTypeNameExpression: public PrimaryExpression
|
2014-10-09 13:57:49 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-09-04 15:45:12 +00:00
|
|
|
ElementaryTypeNameExpression(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2019-09-04 15:45:12 +00:00
|
|
|
SourceLocation const& _location,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<ElementaryTypeName> _type
|
2019-09-04 15:45:12 +00:00
|
|
|
):
|
2019-09-11 19:16:35 +00:00
|
|
|
PrimaryExpression(_id, _location),
|
2020-04-01 03:04:29 +00:00
|
|
|
m_type(std::move(_type))
|
2019-09-04 15:45:12 +00:00
|
|
|
{
|
|
|
|
}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2019-09-04 15:45:12 +00:00
|
|
|
ElementaryTypeName const& type() const { return *m_type; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2014-10-09 13:57:49 +00:00
|
|
|
private:
|
2019-09-04 15:45:12 +00:00
|
|
|
ASTPointer<ElementaryTypeName> m_type;
|
2014-10-09 13:57:49 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
2015-02-04 15:37:54 +00:00
|
|
|
* A literal string or number. @see ExpressionCompiler::endVisit() is used to actually parse its value.
|
2014-10-28 15:51:26 +00:00
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class Literal: public PrimaryExpression
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
2014-10-09 13:57:49 +00:00
|
|
|
public:
|
2015-02-05 21:38:07 +00:00
|
|
|
enum class SubDenomination
|
|
|
|
{
|
2018-10-22 14:48:21 +00:00
|
|
|
None = static_cast<int>(Token::Illegal),
|
|
|
|
Wei = static_cast<int>(Token::SubWei),
|
2020-06-18 15:09:24 +00:00
|
|
|
Gwei = static_cast<int>(Token::SubGwei),
|
2018-10-22 14:48:21 +00:00
|
|
|
Ether = static_cast<int>(Token::SubEther),
|
|
|
|
Second = static_cast<int>(Token::SubSecond),
|
|
|
|
Minute = static_cast<int>(Token::SubMinute),
|
|
|
|
Hour = static_cast<int>(Token::SubHour),
|
|
|
|
Day = static_cast<int>(Token::SubDay),
|
|
|
|
Week = static_cast<int>(Token::SubWeek),
|
|
|
|
Year = static_cast<int>(Token::SubYear)
|
2015-02-05 21:38:07 +00:00
|
|
|
};
|
2015-09-24 09:03:44 +00:00
|
|
|
Literal(
|
2019-09-11 19:16:35 +00:00
|
|
|
int64_t _id,
|
2015-09-24 09:03:44 +00:00
|
|
|
SourceLocation const& _location,
|
2018-10-22 14:48:21 +00:00
|
|
|
Token _token,
|
2020-04-01 03:04:29 +00:00
|
|
|
ASTPointer<ASTString> _value,
|
2015-09-24 09:03:44 +00:00
|
|
|
SubDenomination _sub = SubDenomination::None
|
|
|
|
):
|
2020-04-01 03:04:29 +00:00
|
|
|
PrimaryExpression(_id, _location), m_token(_token), m_value(std::move(_value)), m_subDenomination(_sub) {}
|
2018-11-16 01:09:04 +00:00
|
|
|
void accept(ASTVisitor& _visitor) override;
|
|
|
|
void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2018-10-22 14:48:21 +00:00
|
|
|
Token token() const { return m_token; }
|
2014-10-22 18:35:35 +00:00
|
|
|
/// @returns the non-parsed value of the literal
|
2015-08-31 16:44:29 +00:00
|
|
|
ASTString const& value() const { return *m_value; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2018-10-01 12:36:57 +00:00
|
|
|
ASTString valueWithoutUnderscores() const;
|
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
SubDenomination subDenomination() const { return m_subDenomination; }
|
2015-02-04 15:37:54 +00:00
|
|
|
|
2017-06-26 11:49:05 +00:00
|
|
|
/// @returns true if this is a number with a hex prefix.
|
2017-06-28 15:59:34 +00:00
|
|
|
bool isHexNumber() const;
|
2017-06-26 11:49:05 +00:00
|
|
|
|
2017-01-24 16:38:06 +00:00
|
|
|
/// @returns true if this looks like a checksummed address.
|
|
|
|
bool looksLikeAddress() const;
|
|
|
|
/// @returns true if it passes the address checksum test.
|
|
|
|
bool passesAddressChecksum() const;
|
2017-10-24 09:54:51 +00:00
|
|
|
/// @returns the checksummed version of an address (or empty string if not valid)
|
2017-10-05 13:28:25 +00:00
|
|
|
std::string getChecksummedAddress() const;
|
2017-01-24 16:38:06 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2018-10-22 14:48:21 +00:00
|
|
|
Token m_token;
|
2014-10-20 12:00:37 +00:00
|
|
|
ASTPointer<ASTString> m_value;
|
2015-02-05 21:38:07 +00:00
|
|
|
SubDenomination m_subDenomination;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
}
|