2014-10-07 16:25:04 +00:00
|
|
|
/*
|
2014-10-16 12:08:54 +00:00
|
|
|
This file is part of cpp-ethereum.
|
2014-10-07 16:25:04 +00:00
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
cpp-ethereum 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
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
cpp-ethereum 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
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2014-10-07 16:25:04 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @author Christian <c@ethdev.com>
|
|
|
|
* @date 2014
|
|
|
|
* Solidity abstract syntax tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-10-13 16:22:15 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <memory>
|
2014-10-23 17:22:30 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
2015-04-24 15:35:16 +00:00
|
|
|
#include <libevmasm/SourceLocation.h>
|
2016-04-01 20:11:01 +00:00
|
|
|
#include <libevmasm/Instruction.h>
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/interface/Utils.h>
|
|
|
|
#include <libsolidity/ast/ASTForward.h>
|
|
|
|
#include <libsolidity/parsing/Token.h>
|
|
|
|
#include <libsolidity/ast/Types.h>
|
|
|
|
#include <libsolidity/interface/Exceptions.h>
|
|
|
|
#include <libsolidity/ast/ASTAnnotations.h>
|
2014-10-07 16:25:04 +00:00
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
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:
|
2015-09-16 14:56:30 +00:00
|
|
|
explicit ASTNode(SourceLocation const& _location);
|
|
|
|
virtual ~ASTNode();
|
2014-10-09 13:57:49 +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)
|
2014-10-16 12:08:54 +00:00
|
|
|
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)
|
2014-12-05 16:29:20 +00:00
|
|
|
element->accept(_visitor);
|
|
|
|
}
|
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.
|
|
|
|
template <class _T>
|
|
|
|
static std::vector<_T const*> filteredNodes(std::vector<ASTPointer<ASTNode>> const& _nodes);
|
|
|
|
|
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
|
|
|
|
2014-10-24 10:42:44 +00:00
|
|
|
/// Creates a @ref TypeError exception and decorates it with the location of the node and
|
2014-10-23 17:22:30 +00:00
|
|
|
/// the given description
|
2015-10-02 12:41:40 +00:00
|
|
|
Error createTypeError(std::string const& _description) const;
|
2014-10-23 17:22:30 +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:
|
|
|
|
/// Annotation - is specialised in derived classes, is created upon request (because of polymorphism).
|
|
|
|
mutable ASTAnnotation* m_annotation = nullptr;
|
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2015-02-23 16:14:59 +00:00
|
|
|
SourceLocation m_location;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2015-11-26 16:28:44 +00:00
|
|
|
template <class _T>
|
|
|
|
std::vector<_T const*> ASTNode::filteredNodes(std::vector<ASTPointer<ASTNode>> const& _nodes)
|
|
|
|
{
|
|
|
|
std::vector<_T const*> ret;
|
|
|
|
for (auto const& n: _nodes)
|
|
|
|
if (auto const* nt = dynamic_cast<_T const*>(n.get()))
|
|
|
|
ret.push_back(nt);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-12-03 06:46:55 +00:00
|
|
|
/**
|
|
|
|
* Source unit containing import directives and contract definitions.
|
|
|
|
*/
|
|
|
|
class SourceUnit: public ASTNode
|
|
|
|
{
|
|
|
|
public:
|
2015-02-23 16:14:59 +00:00
|
|
|
SourceUnit(SourceLocation const& _location, std::vector<ASTPointer<ASTNode>> const& _nodes):
|
2014-12-03 06:46:55 +00:00
|
|
|
ASTNode(_location), m_nodes(_nodes) {}
|
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
2015-12-15 14:46:03 +00:00
|
|
|
virtual SourceUnitAnnotation& annotation() const override;
|
2014-12-03 06:46:55 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<ASTPointer<ASTNode>> m_nodes;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class Declaration: public ASTNode
|
2014-10-13 16:22:15 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-02-13 23:43:02 +00:00
|
|
|
/// Visibility ordered from restricted to unrestricted.
|
2015-02-22 18:37:54 +00:00
|
|
|
enum class Visibility { Default, Private, Internal, Public, External };
|
2015-01-22 00:02:38 +00:00
|
|
|
|
2015-09-24 09:03:44 +00:00
|
|
|
Declaration(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
|
|
|
Visibility _visibility = Visibility::Default
|
|
|
|
):
|
2015-02-02 16:24:09 +00:00
|
|
|
ASTNode(_location), m_name(_name), m_visibility(_visibility), m_scope(nullptr) {}
|
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; }
|
|
|
|
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; }
|
|
|
|
bool isVisibleInDerivedContracts() const { return isVisibleInContract() && visibility() >= Visibility::Internal; }
|
2015-02-02 16:24:09 +00:00
|
|
|
|
2014-12-01 14:22:45 +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.
|
2015-12-05 02:09:47 +00:00
|
|
|
ASTNode const* scope() const { return m_scope; }
|
|
|
|
void setScope(ASTNode const* _scope) { m_scope = _scope; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2015-09-16 14:56:30 +00:00
|
|
|
virtual bool isLValue() const { return false; }
|
|
|
|
virtual bool isPartOfExternalInterface() const { return false; }
|
|
|
|
|
2015-01-22 00:02:38 +00:00
|
|
|
/// @returns the type of expressions referencing this declaration.
|
|
|
|
/// The current contract has to be given since this context can change the type, especially of
|
|
|
|
/// contract types.
|
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
|
|
|
|
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;
|
2015-02-02 16:24:09 +00:00
|
|
|
Visibility m_visibility;
|
2015-12-05 02:09:47 +00:00
|
|
|
ASTNode const* m_scope;
|
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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
std::vector<Token::Value> const& _tokens,
|
|
|
|
std::vector<ASTString> const& _literals
|
|
|
|
): ASTNode(_location), m_tokens(_tokens), m_literals(_literals)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
|
|
|
std::vector<Token::Value> const& tokens() const { return m_tokens; }
|
|
|
|
std::vector<ASTString> const& literals() const { return m_literals; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/// Sequence of tokens following the "pragma" keyword.
|
|
|
|
std::vector<Token::Value> m_tokens;
|
|
|
|
/// 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:
|
|
|
|
ImportDirective(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _path,
|
|
|
|
ASTPointer<ASTString> const& _unitAlias,
|
|
|
|
std::vector<std::pair<ASTPointer<Identifier>, ASTPointer<ASTString>>>&& _symbolAliases
|
|
|
|
):
|
|
|
|
Declaration(_location, _unitAlias),
|
|
|
|
m_path(_path),
|
|
|
|
m_symbolAliases(_symbolAliases)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
|
|
|
ASTString const& path() const { return *m_path; }
|
2016-01-11 12:55:58 +00:00
|
|
|
std::vector<std::pair<ASTPointer<Identifier>, ASTPointer<ASTString>>> const& symbolAliases() const
|
|
|
|
{
|
|
|
|
return m_symbolAliases;
|
|
|
|
}
|
2015-12-15 14:46:03 +00:00
|
|
|
virtual ImportAnnotation& annotation() const override;
|
|
|
|
|
|
|
|
virtual TypePointer type() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ASTPointer<ASTString> m_path;
|
|
|
|
/// The aliases for the specific symbols to import. If non-empty import the specific symbols.
|
|
|
|
/// If the second component is empty, import the identifier unchanged.
|
|
|
|
/// If both m_unitAlias and m_symbolAlias are empty, import all symbols into the current scope.
|
|
|
|
std::vector<std::pair<ASTPointer<Identifier>, ASTPointer<ASTString>>> m_symbolAliases;
|
|
|
|
};
|
|
|
|
|
2015-01-29 16:28:14 +00:00
|
|
|
/**
|
|
|
|
* Abstract class that is added to each AST node that can store local variables.
|
|
|
|
*/
|
|
|
|
class VariableScope
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract class that is added to each AST node that can receive documentation.
|
|
|
|
*/
|
|
|
|
class Documented
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit Documented(ASTPointer<ASTString> const& _documentation): m_documentation(_documentation) {}
|
|
|
|
|
|
|
|
/// @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;
|
|
|
|
};
|
|
|
|
|
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:
|
|
|
|
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.
|
|
|
|
*/
|
2015-09-16 14:56:30 +00:00
|
|
|
class ContractDefinition: public Declaration, public Documented
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-03-20 16:50:26 +00:00
|
|
|
ContractDefinition(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
|
|
|
ASTPointer<ASTString> const& _documentation,
|
|
|
|
std::vector<ASTPointer<InheritanceSpecifier>> const& _baseContracts,
|
2015-11-23 22:57:17 +00:00
|
|
|
std::vector<ASTPointer<ASTNode>> const& _subNodes,
|
2015-09-08 14:48:33 +00:00
|
|
|
bool _isLibrary
|
2015-03-20 16:50:26 +00:00
|
|
|
):
|
|
|
|
Declaration(_location, _name),
|
|
|
|
Documented(_documentation),
|
2015-01-15 15:15:01 +00:00
|
|
|
m_baseContracts(_baseContracts),
|
2015-11-23 22:57:17 +00:00
|
|
|
m_subNodes(_subNodes),
|
2015-09-08 14:48:33 +00:00
|
|
|
m_isLibrary(_isLibrary)
|
2014-10-09 10:28:37 +00:00
|
|
|
{}
|
2014-10-07 16:25:04 +00:00
|
|
|
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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;
|
2015-09-08 14:48:33 +00:00
|
|
|
bool isLibrary() const { return m_isLibrary; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2015-01-07 15:39:21 +00:00
|
|
|
/// @returns a map of canonical function signatures to FunctionDefinitions
|
|
|
|
/// as intended for use by the ABI.
|
2015-08-31 16:44:29 +00:00
|
|
|
std::map<FixedHash<4>, FunctionTypePointer> interfaceFunctions() const;
|
2015-09-16 14:56:30 +00:00
|
|
|
std::vector<std::pair<FixedHash<4>, FunctionTypePointer>> const& interfaceFunctionList() const;
|
2014-11-23 23:00:46 +00:00
|
|
|
|
2015-02-25 19:35:55 +00:00
|
|
|
/// @returns a list of the inheritable members of this contract
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<Declaration const*> const& inheritableMembers() const;
|
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;
|
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
|
|
|
|
2015-06-19 13:40:09 +00:00
|
|
|
std::string const& userDocumentation() const;
|
2015-06-15 13:21:23 +00:00
|
|
|
void setUserDocumentation(std::string const& _userDocumentation);
|
|
|
|
|
2015-06-19 13:40:09 +00:00
|
|
|
std::string const& devDocumentation() const;
|
2015-06-15 13:21:23 +00:00
|
|
|
void setDevDocumentation(std::string const& _devDocumentation);
|
|
|
|
|
2015-11-19 17:02:04 +00:00
|
|
|
virtual TypePointer type() const override;
|
2015-01-16 16:50:10 +00:00
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
virtual ContractDefinitionAnnotation& annotation() const override;
|
2015-01-14 09:16:58 +00:00
|
|
|
|
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;
|
2015-09-08 14:48:33 +00:00
|
|
|
bool m_isLibrary;
|
2015-01-15 19:04:06 +00:00
|
|
|
|
2015-06-15 13:21:23 +00:00
|
|
|
// parsed Natspec documentation of the contract.
|
|
|
|
std::string m_userDocumentation;
|
|
|
|
std::string m_devDocumentation;
|
|
|
|
|
2015-01-15 19:04:06 +00:00
|
|
|
std::vector<ContractDefinition const*> m_linearizedBaseContracts;
|
2015-01-29 15:48:39 +00:00
|
|
|
mutable std::unique_ptr<std::vector<std::pair<FixedHash<4>, FunctionTypePointer>>> m_interfaceFunctionList;
|
2015-11-23 22:57:17 +00:00
|
|
|
mutable std::unique_ptr<std::vector<EventDefinition const*>> m_interfaceEvents;
|
2015-03-02 11:08:32 +00:00
|
|
|
mutable std::unique_ptr<std::vector<Declaration const*>> m_inheritableMembers;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2015-01-19 20:05:47 +00:00
|
|
|
class InheritanceSpecifier: public ASTNode
|
|
|
|
{
|
|
|
|
public:
|
2015-09-16 14:56:30 +00:00
|
|
|
InheritanceSpecifier(
|
|
|
|
SourceLocation const& _location,
|
2015-12-21 17:44:21 +00:00
|
|
|
ASTPointer<UserDefinedTypeName> const& _baseName,
|
2015-09-16 14:56:30 +00:00
|
|
|
std::vector<ASTPointer<Expression>> _arguments
|
|
|
|
):
|
2015-01-19 20:05:47 +00:00
|
|
|
ASTNode(_location), m_baseName(_baseName), m_arguments(_arguments) {}
|
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
2015-12-21 17:44:21 +00:00
|
|
|
UserDefinedTypeName const& name() const { return *m_baseName; }
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<ASTPointer<Expression>> const& arguments() const { return m_arguments; }
|
2015-01-19 20:05:47 +00:00
|
|
|
|
|
|
|
private:
|
2015-12-21 17:44:21 +00:00
|
|
|
ASTPointer<UserDefinedTypeName> m_baseName;
|
2015-01-19 20:05:47 +00:00
|
|
|
std::vector<ASTPointer<Expression>> m_arguments;
|
|
|
|
};
|
|
|
|
|
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(
|
|
|
|
SourceLocation const& _location,
|
2015-12-21 17:44:21 +00:00
|
|
|
ASTPointer<UserDefinedTypeName> const& _libraryName,
|
2015-11-22 19:39:10 +00:00
|
|
|
ASTPointer<TypeName> const& _typeName
|
|
|
|
):
|
|
|
|
ASTNode(_location), m_libraryName(_libraryName), m_typeName(_typeName) {}
|
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
2015-12-21 17:44:21 +00:00
|
|
|
UserDefinedTypeName 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:
|
2015-12-21 17:44:21 +00:00
|
|
|
ASTPointer<UserDefinedTypeName> m_libraryName;
|
2015-11-22 19:39:10 +00:00
|
|
|
ASTPointer<TypeName> m_typeName;
|
|
|
|
};
|
|
|
|
|
2014-10-16 21:49:45 +00:00
|
|
|
class StructDefinition: public Declaration
|
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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& _members
|
|
|
|
):
|
2014-10-22 22:24:07 +00:00
|
|
|
Declaration(_location, _name), m_members(_members) {}
|
2015-09-17 13:04:44 +00:00
|
|
|
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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
|
|
|
|
2015-11-19 17:02:04 +00:00
|
|
|
virtual TypePointer type() const override;
|
2014-11-20 17:33:23 +00:00
|
|
|
|
2015-10-05 15:19:23 +00:00
|
|
|
virtual TypeDeclarationAnnotation& annotation() const override;
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2015-02-09 17:08:56 +00:00
|
|
|
class EnumDefinition: public Declaration
|
|
|
|
{
|
|
|
|
public:
|
2015-09-16 14:56:30 +00:00
|
|
|
EnumDefinition(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
|
|
|
std::vector<ASTPointer<EnumValue>> const& _members
|
|
|
|
):
|
2015-02-09 17:08:56 +00:00
|
|
|
Declaration(_location, _name), m_members(_members) {}
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
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
|
|
|
|
2015-11-19 17:02:04 +00:00
|
|
|
virtual TypePointer type() const override;
|
2015-02-09 17:08:56 +00:00
|
|
|
|
2015-10-05 15:19:23 +00:00
|
|
|
virtual TypeDeclarationAnnotation& annotation() const override;
|
|
|
|
|
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:
|
|
|
|
EnumValue(SourceLocation const& _location, ASTPointer<ASTString> const& _name):
|
2015-02-13 21:52:04 +00:00
|
|
|
Declaration(_location, _name) {}
|
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2015-11-19 17:02:04 +00:00
|
|
|
virtual TypePointer type() const override;
|
2015-02-13 21:52:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Parameter list, used as function parameter list and return list.
|
|
|
|
* 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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& _parameters
|
|
|
|
):
|
2014-10-22 22:24:07 +00:00
|
|
|
ASTNode(_location), m_parameters(_parameters) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
|
|
|
Declaration::Visibility _visibility,
|
|
|
|
ASTPointer<ParameterList> const& _parameters,
|
|
|
|
ASTPointer<ParameterList> const& _returnParameters = ASTPointer<ParameterList>()
|
|
|
|
):
|
|
|
|
Declaration(_location, _name, _visibility),
|
|
|
|
m_parameters(_parameters),
|
|
|
|
m_returnParameters(_returnParameters)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& parameters() const { return m_parameters->parameters(); }
|
|
|
|
ParameterList const& parameterList() const { return *m_parameters; }
|
|
|
|
ASTPointer<ParameterList> const& returnParameterList() const { return m_returnParameters; }
|
2015-06-09 12:26:08 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ASTPointer<ParameterList> m_parameters;
|
|
|
|
ASTPointer<ParameterList> m_returnParameters;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FunctionDefinition: public CallableDeclaration, public Documented, public ImplementationOptional
|
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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
2015-06-09 12:26:08 +00:00
|
|
|
Declaration::Visibility _visibility,
|
|
|
|
bool _isConstructor,
|
2015-03-20 16:50:26 +00:00
|
|
|
ASTPointer<ASTString> const& _documentation,
|
|
|
|
ASTPointer<ParameterList> const& _parameters,
|
|
|
|
bool _isDeclaredConst,
|
|
|
|
std::vector<ASTPointer<ModifierInvocation>> const& _modifiers,
|
|
|
|
ASTPointer<ParameterList> const& _returnParameters,
|
2016-06-18 10:11:55 +00:00
|
|
|
bool _isPayable,
|
2015-03-20 16:50:26 +00:00
|
|
|
ASTPointer<Block> const& _body
|
|
|
|
):
|
2015-06-09 12:26:08 +00:00
|
|
|
CallableDeclaration(_location, _name, _visibility, _parameters, _returnParameters),
|
2015-03-20 16:50:26 +00:00
|
|
|
Documented(_documentation),
|
|
|
|
ImplementationOptional(_body != nullptr),
|
|
|
|
m_isConstructor(_isConstructor),
|
|
|
|
m_isDeclaredConst(_isDeclaredConst),
|
2016-06-18 10:11:55 +00:00
|
|
|
m_isPayable(_isPayable),
|
2015-03-20 16:50:26 +00:00
|
|
|
m_functionModifiers(_modifiers),
|
|
|
|
m_body(_body)
|
2014-11-28 00:26:37 +00:00
|
|
|
{}
|
|
|
|
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2015-01-20 14:58:04 +00:00
|
|
|
bool isConstructor() const { return m_isConstructor; }
|
2014-10-10 14:37:54 +00:00
|
|
|
bool isDeclaredConst() const { return m_isDeclaredConst; }
|
2016-06-18 10:11:55 +00:00
|
|
|
bool isPayable() const { return m_isPayable; }
|
2015-08-31 16:44:29 +00:00
|
|
|
std::vector<ASTPointer<ModifierInvocation>> const& modifiers() const { return m_functionModifiers; }
|
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& returnParameters() const { return m_returnParameters->parameters(); }
|
|
|
|
Block const& body() const { return *m_body; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2015-04-21 11:35:38 +00:00
|
|
|
virtual bool isVisibleInContract() const override
|
2015-02-27 09:08:14 +00:00
|
|
|
{
|
2015-08-31 16:44:29 +00:00
|
|
|
return Declaration::isVisibleInContract() && !isConstructor() && !name().empty();
|
2015-02-27 09:08:14 +00:00
|
|
|
}
|
2015-08-31 16:44:29 +00:00
|
|
|
virtual bool isPartOfExternalInterface() const override { return isPublic() && !m_isConstructor && !name().empty(); }
|
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
|
|
|
|
2015-11-19 17:02:04 +00:00
|
|
|
virtual TypePointer type() const override;
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2015-10-26 14:13:36 +00:00
|
|
|
virtual FunctionDefinitionAnnotation& annotation() const override;
|
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2015-01-20 14:58:04 +00:00
|
|
|
bool m_isConstructor;
|
2014-10-09 10:28:37 +00:00
|
|
|
bool m_isDeclaredConst;
|
2016-06-18 10:11:55 +00:00
|
|
|
bool m_isPayable;
|
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
|
|
|
|
* lists, struct definitions and even function bodys.
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class VariableDeclaration: public Declaration
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-06-05 09:07:50 +00:00
|
|
|
enum Location { Default, Storage, Memory };
|
|
|
|
|
2015-03-03 11:58:01 +00:00
|
|
|
VariableDeclaration(
|
2015-06-05 09:07:50 +00:00
|
|
|
SourceLocation const& _sourceLocation,
|
2015-03-16 13:45:11 +00:00
|
|
|
ASTPointer<TypeName> const& _type,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
|
|
|
ASTPointer<Expression> _value,
|
|
|
|
Visibility _visibility,
|
|
|
|
bool _isStateVar = false,
|
|
|
|
bool _isIndexed = false,
|
2015-06-05 09:07:50 +00:00
|
|
|
bool _isConstant = false,
|
|
|
|
Location _referenceLocation = Location::Default
|
2015-03-16 13:45:11 +00:00
|
|
|
):
|
2015-06-05 09:07:50 +00:00
|
|
|
Declaration(_sourceLocation, _name, _visibility),
|
2015-03-03 11:58:01 +00:00
|
|
|
m_typeName(_type),
|
|
|
|
m_value(_value),
|
|
|
|
m_isStateVariable(_isStateVar),
|
|
|
|
m_isIndexed(_isIndexed),
|
2015-06-05 09:07:50 +00:00
|
|
|
m_isConstant(_isConstant),
|
|
|
|
m_location(_referenceLocation) {}
|
2015-03-03 11:58:01 +00:00
|
|
|
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2015-09-16 14:56:30 +00:00
|
|
|
TypeName* typeName() const { return m_typeName.get(); }
|
2015-08-31 16:44:29 +00:00
|
|
|
ASTPointer<Expression> const& value() const { return m_value; }
|
2014-10-13 16:22:15 +00:00
|
|
|
|
2015-02-14 00:22:44 +00:00
|
|
|
virtual bool isLValue() const override;
|
2015-08-21 15:57:57 +00:00
|
|
|
virtual bool isPartOfExternalInterface() const override { return isPublic(); }
|
2015-02-17 15:21:38 +00:00
|
|
|
|
2016-10-05 18:49:47 +00:00
|
|
|
bool isLocalVariable() const { return !!dynamic_cast<CallableDeclaration const*>(scope()); }
|
2015-06-05 09:07:50 +00:00
|
|
|
/// @returns true if this variable is a parameter or return parameter of a function.
|
2015-06-09 12:26:08 +00:00
|
|
|
bool isCallableParameter() const;
|
2015-06-05 09:07:50 +00:00
|
|
|
/// @returns true if this variable is a parameter (not return parameter) of an external function.
|
2015-06-09 12:26:08 +00:00
|
|
|
bool isExternalCallableParameter() const;
|
2015-09-16 14:56:30 +00:00
|
|
|
/// @returns true if the type of the variable does not need to be specified, i.e. it is declared
|
|
|
|
/// in the body of a function or modifier.
|
|
|
|
bool canHaveAutoType() const;
|
2015-01-26 15:14:40 +00:00
|
|
|
bool isStateVariable() const { return m_isStateVariable; }
|
2015-01-29 13:35:28 +00:00
|
|
|
bool isIndexed() const { return m_isIndexed; }
|
2015-03-03 11:58:01 +00:00
|
|
|
bool isConstant() const { return m_isConstant; }
|
2015-06-05 09:07:50 +00:00
|
|
|
Location referenceLocation() const { return m_location; }
|
2014-10-13 16:22:15 +00:00
|
|
|
|
2015-11-19 17:02:04 +00:00
|
|
|
virtual TypePointer type() const override;
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
virtual VariableDeclarationAnnotation& annotation() const override;
|
|
|
|
|
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:
|
2015-06-05 12:45:47 +00:00
|
|
|
ASTPointer<TypeName> m_typeName; ///< can be empty ("var")
|
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;
|
2015-06-05 12:45:47 +00:00
|
|
|
bool m_isStateVariable; ///< Whether or not this is a contract state variable
|
|
|
|
bool m_isIndexed; ///< Whether this is an indexed variable (used by events).
|
|
|
|
bool m_isConstant; ///< Whether the variable is a compile-time constant.
|
2015-06-05 09:07:50 +00:00
|
|
|
Location m_location; ///< 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.
|
|
|
|
*/
|
2015-06-09 12:26:08 +00:00
|
|
|
class ModifierDefinition: public CallableDeclaration, public Documented
|
2015-01-21 10:16:18 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-06-15 12:39:34 +00:00
|
|
|
ModifierDefinition(
|
|
|
|
SourceLocation const& _location,
|
2015-06-09 12:26:08 +00:00
|
|
|
ASTPointer<ASTString> const& _name,
|
|
|
|
ASTPointer<ASTString> const& _documentation,
|
|
|
|
ASTPointer<ParameterList> const& _parameters,
|
|
|
|
ASTPointer<Block> const& _body
|
|
|
|
):
|
|
|
|
CallableDeclaration(_location, _name, Visibility::Default, _parameters),
|
|
|
|
Documented(_documentation),
|
|
|
|
m_body(_body)
|
|
|
|
{
|
|
|
|
}
|
2015-01-21 10:16:18 +00:00
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
Block const& body() const { return *m_body; }
|
2015-01-21 10:16:18 +00:00
|
|
|
|
2015-11-19 17:02:04 +00:00
|
|
|
virtual TypePointer type() const override;
|
2015-01-21 10:16:18 +00:00
|
|
|
|
2015-10-26 14:13:36 +00:00
|
|
|
virtual ModifierDefinitionAnnotation& annotation() 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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<Identifier> const& _name,
|
|
|
|
std::vector<ASTPointer<Expression>> _arguments
|
|
|
|
):
|
2015-01-22 00:02:38 +00:00
|
|
|
ASTNode(_location), m_modifierName(_name), m_arguments(_arguments) {}
|
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
ASTPointer<Identifier> const& name() const { return m_modifierName; }
|
|
|
|
std::vector<ASTPointer<Expression>> const& arguments() const { return m_arguments; }
|
2015-01-22 00:02:38 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ASTPointer<Identifier> m_modifierName;
|
|
|
|
std::vector<ASTPointer<Expression>> m_arguments;
|
|
|
|
};
|
|
|
|
|
2015-01-29 13:35:28 +00:00
|
|
|
/**
|
|
|
|
* Definition of a (loggable) event.
|
|
|
|
*/
|
2015-06-09 12:26:08 +00:00
|
|
|
class EventDefinition: public CallableDeclaration, public Documented
|
2015-01-29 13:35:28 +00:00
|
|
|
{
|
|
|
|
public:
|
2015-03-17 09:48:46 +00:00
|
|
|
EventDefinition(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name,
|
|
|
|
ASTPointer<ASTString> const& _documentation,
|
|
|
|
ASTPointer<ParameterList> const& _parameters,
|
|
|
|
bool _anonymous = false
|
|
|
|
):
|
2015-06-09 12:26:08 +00:00
|
|
|
CallableDeclaration(_location, _name, Visibility::Default, _parameters),
|
2015-03-17 09:48:46 +00:00
|
|
|
Documented(_documentation),
|
2015-06-09 12:26:08 +00:00
|
|
|
m_anonymous(_anonymous)
|
|
|
|
{
|
|
|
|
}
|
2015-01-29 13:35:28 +00:00
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
2015-03-17 10:34:56 +00:00
|
|
|
bool isAnonymous() const { return m_anonymous; }
|
2015-01-29 13:35:28 +00:00
|
|
|
|
2015-11-19 17:02:04 +00:00
|
|
|
virtual TypePointer type() const override;
|
2015-01-29 13:35:28 +00:00
|
|
|
|
2015-10-26 14:13:36 +00:00
|
|
|
virtual EventDefinitionAnnotation& annotation() const override;
|
|
|
|
|
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
|
|
|
|
* 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:
|
2014-11-26 12:19:17 +00:00
|
|
|
MagicVariableDeclaration(ASTString const& _name, std::shared_ptr<Type const> const& _type):
|
2015-02-23 16:14:59 +00:00
|
|
|
Declaration(SourceLocation(), std::make_shared<ASTString>(_name)), m_type(_type) {}
|
2015-10-02 12:41:40 +00:00
|
|
|
virtual void accept(ASTVisitor&) override
|
|
|
|
{
|
|
|
|
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("MagicVariableDeclaration used inside real AST."));
|
|
|
|
}
|
|
|
|
virtual void accept(ASTConstVisitor&) const override
|
|
|
|
{
|
|
|
|
BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("MagicVariableDeclaration used inside real AST."));
|
|
|
|
}
|
2014-11-21 18:14:56 +00:00
|
|
|
|
2015-11-19 17:02:04 +00:00
|
|
|
virtual TypePointer type() const override { return m_type; }
|
2014-11-21 18:14:56 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::shared_ptr<Type const> m_type;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
|
|
|
public:
|
2015-02-23 16:14:59 +00:00
|
|
|
explicit TypeName(SourceLocation const& _location): ASTNode(_location) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-13 16:22:15 +00:00
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
virtual TypeNameAnnotation& annotation() const override;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Any pre-defined type name represented by a single keyword, i.e. it excludes mappings,
|
|
|
|
* contracts, functions, etc.
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class ElementaryTypeName: public TypeName
|
2014-10-07 16:25:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2016-02-08 21:43:22 +00:00
|
|
|
ElementaryTypeName(SourceLocation const& _location, ElementaryTypeNameToken const& _elem):
|
|
|
|
TypeName(_location), m_type(_elem)
|
|
|
|
{}
|
|
|
|
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2016-02-08 21:43:22 +00:00
|
|
|
ElementaryTypeNameToken m_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:
|
2015-10-06 10:35:10 +00:00
|
|
|
UserDefinedTypeName(SourceLocation const& _location, std::vector<ASTString> const& _namePath):
|
|
|
|
TypeName(_location), m_namePath(_namePath) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2015-10-06 10:35:10 +00:00
|
|
|
std::vector<ASTString> const& namePath() const { return m_namePath; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
virtual UserDefinedTypeNameAnnotation& annotation() const override;
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2015-10-06 10:35:10 +00:00
|
|
|
std::vector<ASTString> m_namePath;
|
2014-10-07 16:25:04 +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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ElementaryTypeName> const& _keyType,
|
|
|
|
ASTPointer<TypeName> const& _valueType
|
|
|
|
):
|
2014-10-22 22:24:07 +00:00
|
|
|
TypeName(_location), m_keyType(_keyType), m_valueType(_valueType) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
2014-11-10 16:31:09 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
ElementaryTypeName const& keyType() const { return *m_keyType; }
|
|
|
|
TypeName const& valueType() const { return *m_valueType; }
|
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<ElementaryTypeName> m_keyType;
|
|
|
|
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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<TypeName> const& _baseType,
|
|
|
|
ASTPointer<Expression> const& _length
|
|
|
|
):
|
2015-02-20 14:52:30 +00:00
|
|
|
TypeName(_location), m_baseType(_baseType), m_length(_length) {}
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _docString
|
|
|
|
): ASTNode(_location), Documented(_docString) {}
|
|
|
|
|
|
|
|
virtual StatementAnnotation& annotation() const override;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2016-03-01 21:56:39 +00:00
|
|
|
namespace assembly
|
|
|
|
{
|
|
|
|
// Forward-declaration to AsmData.h
|
|
|
|
struct Block;
|
|
|
|
}
|
2016-02-22 01:13:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Inline assembly.
|
|
|
|
*/
|
|
|
|
class InlineAssembly: public Statement
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InlineAssembly(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _docString,
|
2016-03-01 21:56:39 +00:00
|
|
|
std::shared_ptr<assembly::Block> const& _operations
|
2016-02-22 01:13:41 +00:00
|
|
|
):
|
|
|
|
Statement(_location, _docString), m_operations(_operations) {}
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
2016-03-01 21:56:39 +00:00
|
|
|
assembly::Block const& operations() const { return *m_operations; }
|
|
|
|
|
|
|
|
virtual InlineAssemblyAnnotation& annotation() const override;
|
2016-02-22 01:13:41 +00:00
|
|
|
|
|
|
|
private:
|
2016-03-01 21:56:39 +00:00
|
|
|
std::shared_ptr<assembly::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.
|
|
|
|
*/
|
2014-10-16 21:49:45 +00:00
|
|
|
class Block: public Statement
|
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(
|
|
|
|
SourceLocation const& _location,
|
2015-10-26 16:20:29 +00:00
|
|
|
ASTPointer<ASTString> const& _docString,
|
2015-09-24 09:03:44 +00:00
|
|
|
std::vector<ASTPointer<Statement>> const& _statements
|
|
|
|
):
|
2015-10-26 16:20:29 +00:00
|
|
|
Statement(_location, _docString), m_statements(_statements) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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; }
|
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2014-10-20 12:00:37 +00:00
|
|
|
std::vector<ASTPointer<Statement>> m_statements;
|
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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _docString
|
|
|
|
): Statement(_location, _docString) {}
|
2015-01-21 10:16:18 +00:00
|
|
|
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
};
|
|
|
|
|
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(
|
|
|
|
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> const& _condition,
|
|
|
|
ASTPointer<Statement> const& _trueBody,
|
|
|
|
ASTPointer<Statement> const& _falseBody
|
|
|
|
):
|
2015-10-26 16:20:29 +00:00
|
|
|
Statement(_location, _docString),
|
2015-09-24 09:03:44 +00:00
|
|
|
m_condition(_condition),
|
|
|
|
m_trueBody(_trueBody),
|
|
|
|
m_falseBody(_falseBody)
|
|
|
|
{}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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
|
|
|
};
|
|
|
|
|
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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _docString
|
|
|
|
): Statement(_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(
|
|
|
|
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> const& _condition,
|
|
|
|
ASTPointer<Statement> const& _body
|
|
|
|
):
|
2015-10-26 16:20:29 +00:00
|
|
|
BreakableStatement(_location, _docString), m_condition(_condition), m_body(_body) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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; }
|
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;
|
2014-10-07 16:25:04 +00:00
|
|
|
};
|
|
|
|
|
2014-12-16 13:46:17 +00:00
|
|
|
/**
|
|
|
|
* For loop statement
|
|
|
|
*/
|
2014-12-15 16:45:18 +00:00
|
|
|
class ForStatement: public BreakableStatement
|
|
|
|
{
|
|
|
|
public:
|
2015-09-16 14:56:30 +00:00
|
|
|
ForStatement(
|
|
|
|
SourceLocation const& _location,
|
2015-10-26 16:20:29 +00:00
|
|
|
ASTPointer<ASTString> const& _docString,
|
2015-09-16 14:56:30 +00:00
|
|
|
ASTPointer<Statement> const& _initExpression,
|
|
|
|
ASTPointer<Expression> const& _conditionExpression,
|
|
|
|
ASTPointer<ExpressionStatement> const& _loopExpression,
|
|
|
|
ASTPointer<Statement> const& _body
|
|
|
|
):
|
2015-10-26 16:20:29 +00:00
|
|
|
BreakableStatement(_location, _docString),
|
2014-12-15 16:45:18 +00:00
|
|
|
m_initExpression(_initExpression),
|
|
|
|
m_condExpression(_conditionExpression),
|
|
|
|
m_loopExpression(_loopExpression),
|
2015-09-16 14:56:30 +00:00
|
|
|
m_body(_body)
|
|
|
|
{}
|
2014-12-15 16:45:18 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
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
|
|
|
|
2014-12-15 16:45:18 +00:00
|
|
|
private:
|
2014-12-16 13:46:17 +00:00
|
|
|
/// For statement's initialization expresion. for(XXX; ; ). Can be empty
|
2014-12-16 12:20:50 +00:00
|
|
|
ASTPointer<Statement> m_initExpression;
|
2014-12-16 13:46:17 +00:00
|
|
|
/// For statement's condition expresion. for(; XXX ; ). Can be empty
|
2014-12-15 16:45:18 +00:00
|
|
|
ASTPointer<Expression> m_condExpression;
|
2014-12-16 13:46:17 +00:00
|
|
|
/// For statement's loop expresion. 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:
|
2015-10-26 16:20:29 +00:00
|
|
|
explicit Continue(SourceLocation const& _location, ASTPointer<ASTString> const& _docString):
|
|
|
|
Statement(_location, _docString) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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:
|
2015-10-26 16:20:29 +00:00
|
|
|
explicit Break(SourceLocation const& _location, ASTPointer<ASTString> const& _docString):
|
|
|
|
Statement(_location, _docString) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _docString,
|
|
|
|
ASTPointer<Expression> _expression
|
|
|
|
): Statement(_location, _docString), m_expression(_expression) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
virtual ReturnAnnotation& annotation() const override;
|
|
|
|
|
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:
|
2015-10-26 16:20:29 +00:00
|
|
|
explicit Throw(SourceLocation const& _location, ASTPointer<ASTString> const& _docString):
|
|
|
|
Statement(_location, _docString) {}
|
2015-09-15 14:33:14 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
};
|
|
|
|
|
2014-10-28 15:51:26 +00:00
|
|
|
/**
|
|
|
|
* Definition of a variable as a statement inside a function. It requires a type name (which can
|
|
|
|
* also be "var") but the actual assignment can be missing.
|
|
|
|
* Examples: var a = 2; uint256 a;
|
2015-10-08 16:01:12 +00:00
|
|
|
* As a second form, multiple variables can be declared, cannot have a type and must be assigned
|
|
|
|
* right away. If the first or last component is unnamed, it can "consume" an arbitrary number
|
|
|
|
* of components.
|
|
|
|
* Examples: var (a, b) = f(); var (a,,,c) = g(); var (a,) = d();
|
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(
|
|
|
|
SourceLocation const& _location,
|
2015-10-26 16:20:29 +00:00
|
|
|
ASTPointer<ASTString> const& _docString,
|
2015-10-08 16:01:12 +00:00
|
|
|
std::vector<ASTPointer<VariableDeclaration>> const& _variables,
|
|
|
|
ASTPointer<Expression> const& _initialValue
|
|
|
|
):
|
2015-10-26 16:20:29 +00:00
|
|
|
Statement(_location, _docString), m_variables(_variables), m_initialValue(_initialValue) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-13 16:22:15 +00:00
|
|
|
|
2015-10-09 18:44:56 +00:00
|
|
|
VariableDeclarationStatementAnnotation& annotation() const override;
|
|
|
|
|
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).
|
|
|
|
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(
|
|
|
|
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
|
|
|
|
):
|
2015-10-26 16:20:29 +00:00
|
|
|
Statement(_location, _docString), m_expression(_expression) {}
|
2014-10-30 00:20:32 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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:
|
2015-09-24 09:03:44 +00:00
|
|
|
explicit Expression(SourceLocation const& _location): ASTNode(_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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<Expression> const& _condition,
|
|
|
|
ASTPointer<Expression> const& _trueExpression,
|
|
|
|
ASTPointer<Expression> const& _falseExpression
|
|
|
|
):
|
|
|
|
Expression(_location),
|
|
|
|
m_condition(_condition),
|
|
|
|
m_trueExpression(_trueExpression),
|
|
|
|
m_falseExpression(_falseExpression)
|
|
|
|
{}
|
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
|
|
|
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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<Expression> const& _leftHandSide,
|
|
|
|
Token::Value _assignmentOperator,
|
|
|
|
ASTPointer<Expression> const& _rightHandSide
|
|
|
|
):
|
|
|
|
Expression(_location),
|
|
|
|
m_leftHandSide(_leftHandSide),
|
|
|
|
m_assigmentOperator(_assignmentOperator),
|
|
|
|
m_rightHandSide(_rightHandSide)
|
2014-11-05 13:20:56 +00:00
|
|
|
{
|
2014-12-17 15:23:18 +00:00
|
|
|
solAssert(Token::isAssignmentOp(_assignmentOperator), "");
|
2014-11-05 13:20:56 +00:00
|
|
|
}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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; }
|
|
|
|
Token::Value assignmentOperator() const { return m_assigmentOperator; }
|
|
|
|
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;
|
2014-10-09 10:28:37 +00:00
|
|
|
Token::Value 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.
|
|
|
|
* 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(
|
|
|
|
SourceLocation const& _location,
|
2015-12-15 17:16:54 +00:00
|
|
|
std::vector<ASTPointer<Expression>> const& _components,
|
|
|
|
bool _isArray
|
2015-10-12 21:02:35 +00:00
|
|
|
):
|
2015-12-15 17:16:54 +00:00
|
|
|
Expression(_location),
|
|
|
|
m_components(_components),
|
|
|
|
m_isArray(_isArray) {}
|
2015-10-12 21:02:35 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
|
|
|
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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
Token::Value _operator,
|
|
|
|
ASTPointer<Expression> const& _subExpression,
|
|
|
|
bool _isPrefix
|
|
|
|
):
|
|
|
|
Expression(_location),
|
|
|
|
m_operator(_operator),
|
|
|
|
m_subExpression(_subExpression),
|
|
|
|
m_isPrefix(_isPrefix)
|
2014-11-05 13:20:56 +00:00
|
|
|
{
|
2014-12-17 15:23:18 +00:00
|
|
|
solAssert(Token::isUnaryOp(_operator), "");
|
2014-11-05 13:20:56 +00:00
|
|
|
}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-09 13:57:49 +00:00
|
|
|
|
2014-10-10 14:37:54 +00:00
|
|
|
Token::Value getOperator() const { return m_operator; }
|
|
|
|
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:
|
2014-10-09 10:28:37 +00:00
|
|
|
Token::Value 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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<Expression> const& _left,
|
|
|
|
Token::Value _operator,
|
|
|
|
ASTPointer<Expression> const& _right
|
|
|
|
):
|
2014-11-05 13:20:56 +00:00
|
|
|
Expression(_location), m_left(_left), m_operator(_operator), m_right(_right)
|
|
|
|
{
|
2014-12-17 15:23:18 +00:00
|
|
|
solAssert(Token::isBinaryOp(_operator) || Token::isCompareOp(_operator), "");
|
2014-11-05 13:20:56 +00:00
|
|
|
}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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; }
|
2014-10-10 14:37:54 +00:00
|
|
|
Token::Value 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;
|
2014-10-09 10:28:37 +00:00
|
|
|
Token::Value 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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<Expression> const& _expression,
|
|
|
|
std::vector<ASTPointer<Expression>> const& _arguments,
|
|
|
|
std::vector<ASTPointer<ASTString>> const& _names
|
|
|
|
):
|
2015-01-29 17:26:00 +00:00
|
|
|
Expression(_location), m_expression(_expression), m_arguments(_arguments), m_names(_names) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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; }
|
|
|
|
std::vector<ASTPointer<Expression const>> arguments() const { return {m_arguments.begin(), m_arguments.end()}; }
|
|
|
|
std::vector<ASTPointer<ASTString>> const& names() const { return m_names; }
|
2014-10-25 14:52:22 +00:00
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
virtual 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
|
|
|
};
|
|
|
|
|
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(
|
|
|
|
SourceLocation const& _location,
|
2015-11-16 23:06:57 +00:00
|
|
|
ASTPointer<TypeName> const& _typeName
|
2015-09-24 09:03:44 +00:00
|
|
|
):
|
2015-11-16 23:06:57 +00:00
|
|
|
Expression(_location), m_typeName(_typeName) {}
|
2014-12-12 15:49:26 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
|
|
|
|
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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<Expression> _expression,
|
|
|
|
ASTPointer<ASTString> const& _memberName
|
|
|
|
):
|
2014-10-22 22:24:07 +00:00
|
|
|
Expression(_location), m_expression(_expression), m_memberName(_memberName) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
virtual 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
|
|
|
/**
|
|
|
|
* Index access to an array. Example: a[2]
|
|
|
|
*/
|
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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<Expression> const& _base,
|
|
|
|
ASTPointer<Expression> const& _index
|
|
|
|
):
|
2014-10-22 22:24:07 +00:00
|
|
|
Expression(_location), m_base(_base), m_index(_index) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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
|
|
|
};
|
|
|
|
|
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:
|
2015-02-23 16:14:59 +00:00
|
|
|
PrimaryExpression(SourceLocation const& _location): Expression(_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(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
ASTPointer<ASTString> const& _name
|
|
|
|
):
|
2015-03-01 03:34:39 +00:00
|
|
|
PrimaryExpression(_location), m_name(_name) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
virtual 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:
|
2016-02-08 21:43:22 +00:00
|
|
|
ElementaryTypeNameExpression(SourceLocation const& _location, ElementaryTypeNameToken const& _type):
|
|
|
|
PrimaryExpression(_location), m_typeToken(_type)
|
|
|
|
{}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual 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_typeToken; }
|
2014-10-20 14:28:24 +00:00
|
|
|
|
2014-10-09 13:57:49 +00:00
|
|
|
private:
|
2016-02-08 21:43:22 +00:00
|
|
|
ElementaryTypeNameToken m_typeToken;
|
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
|
|
|
|
{
|
2015-02-09 13:00:12 +00:00
|
|
|
None = Token::Illegal,
|
2015-02-05 22:03:24 +00:00
|
|
|
Wei = Token::SubWei,
|
|
|
|
Szabo = Token::SubSzabo,
|
|
|
|
Finney = Token::SubFinney,
|
2015-03-04 16:35:23 +00:00
|
|
|
Ether = Token::SubEther,
|
|
|
|
Second = Token::SubSecond,
|
|
|
|
Minute = Token::SubMinute,
|
|
|
|
Hour = Token::SubHour,
|
|
|
|
Day = Token::SubDay,
|
|
|
|
Week = Token::SubWeek,
|
|
|
|
Year = Token::SubYear
|
2015-02-05 21:38:07 +00:00
|
|
|
};
|
2015-09-24 09:03:44 +00:00
|
|
|
Literal(
|
|
|
|
SourceLocation const& _location,
|
|
|
|
Token::Value _token,
|
|
|
|
ASTPointer<ASTString> const& _value,
|
|
|
|
SubDenomination _sub = SubDenomination::None
|
|
|
|
):
|
2015-02-06 12:38:10 +00:00
|
|
|
PrimaryExpression(_location), m_token(_token), m_value(_value), m_subDenomination(_sub) {}
|
2014-10-10 14:37:54 +00:00
|
|
|
virtual void accept(ASTVisitor& _visitor) override;
|
2014-12-06 01:19:10 +00:00
|
|
|
virtual void accept(ASTConstVisitor& _visitor) const override;
|
2014-10-10 14:37:54 +00:00
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
Token::Value 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
|
|
|
|
2015-08-31 16:44:29 +00:00
|
|
|
SubDenomination subDenomination() const { return m_subDenomination; }
|
2015-02-04 15:37:54 +00:00
|
|
|
|
2014-10-07 16:25:04 +00:00
|
|
|
private:
|
2014-10-09 13:57:49 +00:00
|
|
|
Token::Value 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
|
|
|
};
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
|
2015-01-22 16:40:22 +00:00
|
|
|
|
2014-10-16 12:08:54 +00:00
|
|
|
}
|
|
|
|
}
|