2015-09-16 14:56:30 +00:00
|
|
|
/*
|
|
|
|
This file is part of cpp-ethereum.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @author Christian <c@ethdev.com>
|
|
|
|
* @date 2015
|
|
|
|
* Object containing the type and other annotations for the AST nodes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2015-10-07 13:57:17 +00:00
|
|
|
#include <set>
|
2015-10-20 22:21:52 +00:00
|
|
|
#include <libsolidity/ast/ASTForward.h>
|
2015-09-16 14:56:30 +00:00
|
|
|
|
|
|
|
namespace dev
|
|
|
|
{
|
|
|
|
namespace solidity
|
|
|
|
{
|
|
|
|
|
|
|
|
class Type;
|
|
|
|
using TypePointer = std::shared_ptr<Type const>;
|
|
|
|
|
|
|
|
struct ASTAnnotation
|
|
|
|
{
|
2015-09-21 16:55:58 +00:00
|
|
|
virtual ~ASTAnnotation() {}
|
|
|
|
};
|
|
|
|
|
2015-10-26 14:13:36 +00:00
|
|
|
struct DocTag
|
|
|
|
{
|
|
|
|
std::string content; ///< The text content of the tag.
|
|
|
|
std::string paramName; ///< Only used for @param, stores the parameter name.
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DocumentedAnnotation
|
|
|
|
{
|
|
|
|
virtual ~DocumentedAnnotation() {}
|
|
|
|
/// Mapping docstring tag name -> content.
|
|
|
|
std::multimap<std::string, DocTag> docTags;
|
|
|
|
};
|
|
|
|
|
2015-12-15 14:46:03 +00:00
|
|
|
struct SourceUnitAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// The "absolute" (in the compiler sense) path of this source unit.
|
|
|
|
std::string path;
|
|
|
|
/// The exported symbols (all global symbols).
|
|
|
|
std::map<ASTString, std::vector<Declaration const*>> exportedSymbols;
|
|
|
|
};
|
|
|
|
|
2015-12-09 16:35:20 +00:00
|
|
|
struct ImportAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// The absolute path of the source unit to import.
|
|
|
|
std::string absolutePath;
|
2015-12-15 14:46:03 +00:00
|
|
|
/// The actual source unit.
|
|
|
|
SourceUnit const* sourceUnit = nullptr;
|
2015-12-09 16:35:20 +00:00
|
|
|
};
|
|
|
|
|
2015-10-05 15:19:23 +00:00
|
|
|
struct TypeDeclarationAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// The name of this type, prefixed by proper namespaces if globally accessible.
|
|
|
|
std::string canonicalName;
|
|
|
|
};
|
|
|
|
|
2015-10-26 14:13:36 +00:00
|
|
|
struct ContractDefinitionAnnotation: TypeDeclarationAnnotation, DocumentedAnnotation
|
2015-09-21 16:55:58 +00:00
|
|
|
{
|
|
|
|
/// Whether all functions are implemented.
|
|
|
|
bool isFullyImplemented = true;
|
|
|
|
/// List of all (direct and indirect) base contracts in order from derived to
|
|
|
|
/// base, including the contract itself.
|
|
|
|
std::vector<ContractDefinition const*> linearizedBaseContracts;
|
2015-10-07 13:57:17 +00:00
|
|
|
/// List of contracts this contract creates, i.e. which need to be compiled first.
|
|
|
|
/// Also includes all contracts from @a linearizedBaseContracts.
|
|
|
|
std::set<ContractDefinition const*> contractDependencies;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
2015-10-26 14:13:36 +00:00
|
|
|
struct FunctionDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EventDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ModifierDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
struct VariableDeclarationAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// Type of variable (type of identifier referencing this variable).
|
|
|
|
TypePointer type;
|
|
|
|
};
|
|
|
|
|
2015-10-26 16:20:29 +00:00
|
|
|
struct StatementAnnotation: ASTAnnotation, DocumentedAnnotation
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2016-03-01 21:56:39 +00:00
|
|
|
namespace assembly
|
|
|
|
{
|
|
|
|
struct Identifier; // forward
|
|
|
|
}
|
|
|
|
|
|
|
|
struct InlineAssemblyAnnotation: StatementAnnotation
|
|
|
|
{
|
|
|
|
/// Mapping containing resolved references to external identifiers.
|
|
|
|
std::map<assembly::Identifier const*, Declaration const*> externalReferences;
|
|
|
|
};
|
|
|
|
|
2015-10-26 16:20:29 +00:00
|
|
|
struct ReturnAnnotation: StatementAnnotation
|
2015-09-21 16:55:58 +00:00
|
|
|
{
|
|
|
|
/// Reference to the return parameters of the function.
|
|
|
|
ParameterList const* functionReturnParameters = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TypeNameAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// Type declared by this type name, i.e. type of a variable where this type name is used.
|
|
|
|
/// Set during reference resolution stage.
|
|
|
|
TypePointer type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UserDefinedTypeNameAnnotation: TypeNameAnnotation
|
|
|
|
{
|
|
|
|
/// Referenced declaration, set during reference resolution stage.
|
|
|
|
Declaration const* referencedDeclaration = nullptr;
|
2015-11-16 23:06:57 +00:00
|
|
|
/// Stores a reference to the current contract.
|
|
|
|
/// This is needed because types of base contracts change depending on the context.
|
|
|
|
ContractDefinition const* contractScope = nullptr;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
2015-09-16 14:56:30 +00:00
|
|
|
|
2015-10-26 16:20:29 +00:00
|
|
|
struct VariableDeclarationStatementAnnotation: StatementAnnotation
|
2015-10-09 18:44:56 +00:00
|
|
|
{
|
2015-10-13 10:22:57 +00:00
|
|
|
/// Information about which component of the value is assigned to which variable.
|
2015-10-09 18:44:56 +00:00
|
|
|
/// The pointer can be null to signify that the component is discarded.
|
|
|
|
std::vector<VariableDeclaration const*> assignments;
|
|
|
|
};
|
|
|
|
|
2015-09-21 16:55:58 +00:00
|
|
|
struct ExpressionAnnotation: ASTAnnotation
|
|
|
|
{
|
|
|
|
/// Inferred type of the expression.
|
2015-09-16 14:56:30 +00:00
|
|
|
TypePointer type;
|
2015-09-21 16:55:58 +00:00
|
|
|
/// Whether it is an LValue (i.e. something that can be assigned to).
|
2015-09-16 14:56:30 +00:00
|
|
|
bool isLValue = false;
|
2015-09-21 16:55:58 +00:00
|
|
|
/// Whether the expression is used in a context where the LValue is actually required.
|
2015-09-16 14:56:30 +00:00
|
|
|
bool lValueRequested = false;
|
2015-09-21 16:55:58 +00:00
|
|
|
/// Types of arguments if the expression is a function that is called - used
|
2015-09-16 14:56:30 +00:00
|
|
|
/// for overload resolution.
|
|
|
|
std::shared_ptr<std::vector<TypePointer>> argumentTypes;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IdentifierAnnotation: ExpressionAnnotation
|
|
|
|
{
|
|
|
|
/// Referenced declaration, set at latest during overload resolution stage.
|
2015-09-16 14:56:30 +00:00
|
|
|
Declaration const* referencedDeclaration = nullptr;
|
2015-09-21 16:55:58 +00:00
|
|
|
/// List of possible declarations it could refer to.
|
2015-09-16 14:56:30 +00:00
|
|
|
std::vector<Declaration const*> overloadedDeclarations;
|
2015-09-21 16:55:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MemberAccessAnnotation: ExpressionAnnotation
|
|
|
|
{
|
|
|
|
/// Referenced declaration, set at latest during overload resolution stage.
|
|
|
|
Declaration const* referencedDeclaration = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BinaryOperationAnnotation: ExpressionAnnotation
|
|
|
|
{
|
|
|
|
/// The common type that is used for the operation, not necessarily the result type (which
|
|
|
|
/// e.g. for comparisons is bool).
|
|
|
|
TypePointer commonType;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FunctionCallAnnotation: ExpressionAnnotation
|
|
|
|
{
|
|
|
|
/// Whether this is an explicit type conversion.
|
2015-09-16 14:56:30 +00:00
|
|
|
bool isTypeConversion = false;
|
2015-09-21 16:55:58 +00:00
|
|
|
/// Whether this is a struct constructor call.
|
2015-09-16 14:56:30 +00:00
|
|
|
bool isStructConstructorCall = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|