aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast/ASTAnnotations.h
blob: 5cbe42bdee358b8df037a215d7b9094e50c91047 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
    This file is part of solidity.

    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.

    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.

    You should have received a copy of the GNU General Public License
    along with solidity.  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 <libsolidity/ast/ASTForward.h>
#include <libsolidity/ast/ExperimentalFeatures.h>

#include <map>
#include <memory>
#include <vector>
#include <set>

namespace dev
{
namespace solidity
{

class Type;
using TypePointer = std::shared_ptr<Type const>;

struct ASTAnnotation
{
    virtual ~ASTAnnotation() {}
};

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;
};

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;
    /// Experimental features.
    std::set<ExperimentalFeature> experimentalFeatures;
};

struct ImportAnnotation: ASTAnnotation
{
    /// The absolute path of the source unit to import.
    std::string absolutePath;
    /// The actual source unit.
    SourceUnit const* sourceUnit = nullptr;
};

struct TypeDeclarationAnnotation: ASTAnnotation
{
    /// The name of this type, prefixed by proper namespaces if globally accessible.
    std::string canonicalName;
};

struct ContractDefinitionAnnotation: TypeDeclarationAnnotation, DocumentedAnnotation
{
    /// List of functions without a body. Can also contain functions from base classes.
    std::vector<FunctionDefinition const*> unimplementedFunctions;
    /// List of all (direct and indirect) base contracts in order from derived to
    /// base, including the contract itself.
    std::vector<ContractDefinition const*> linearizedBaseContracts;
    /// 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;
    /// Mapping containing the nodes that define the arguments for base constructors.
    /// These can either be inheritance specifiers or modifier invocations.
    std::map<FunctionDefinition const*, ASTNode const*> baseConstructorArguments;
};

struct FunctionDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation
{
    /// The function this function overrides, if any. This is always the closest
    /// in the linearized inheritance hierarchy.
    FunctionDefinition const* superFunction = nullptr;
};

struct EventDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation
{
};

struct ModifierDefinitionAnnotation: ASTAnnotation, DocumentedAnnotation
{
};

struct VariableDeclarationAnnotation: ASTAnnotation
{
    /// Type of variable (type of identifier referencing this variable).
    TypePointer type;
};

struct StatementAnnotation: ASTAnnotation, DocumentedAnnotation
{
};

namespace assembly
{
    struct AsmAnalysisInfo;
    struct Identifier;
}

struct InlineAssemblyAnnotation: StatementAnnotation
{
    struct ExternalIdentifierInfo
    {
        Declaration const* declaration = nullptr;
        bool isSlot = false; ///< Whether the storage slot of a variable is queried.
        bool isOffset = false; ///< Whether the intra-slot offset of a storage variable is queried.
        size_t valueSize = size_t(-1);
    };

    /// Mapping containing resolved references to external identifiers and their value size
    std::map<assembly::Identifier const*, ExternalIdentifierInfo> externalReferences;
    /// Information generated during analysis phase.
    std::shared_ptr<assembly::AsmAnalysisInfo> analysisInfo;
};

struct ReturnAnnotation: StatementAnnotation
{
    /// 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;
    /// Stores a reference to the current contract.
    /// This is needed because types of base contracts change depending on the context.
    ContractDefinition const* contractScope = nullptr;
};

struct VariableDeclarationStatementAnnotation: StatementAnnotation
{
    /// Information about which component of the value is assigned to which variable.
    /// The pointer can be null to signify that the component is discarded.
    std::vector<VariableDeclaration const*> assignments;
};

struct ExpressionAnnotation: ASTAnnotation
{
    /// Inferred type of the expression.
    TypePointer type;
    /// Whether the expression is a constant variable
    bool isConstant = false;
    /// Whether the expression is pure, i.e. compile-time constant.
    bool isPure = false;
    /// Whether it is an LValue (i.e. something that can be assigned to).
    bool isLValue = false;
    /// Whether the expression is used in a context where the LValue is actually required.
    bool lValueRequested = false;
    /// Types of arguments if the expression is a function that is called - used
    /// for overload resolution.
    std::shared_ptr<std::vector<TypePointer>> argumentTypes;
};

struct IdentifierAnnotation: ExpressionAnnotation
{
    /// Referenced declaration, set at latest during overload resolution stage.
    Declaration const* referencedDeclaration = nullptr;
    /// List of possible declarations it could refer to.
    std::vector<Declaration const*> overloadedDeclarations;
};

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;
};

enum class FunctionCallKind
{
    Unset,
    FunctionCall,
    TypeConversion,
    StructConstructorCall
};

struct FunctionCallAnnotation: ExpressionAnnotation
{
    FunctionCallKind kind = FunctionCallKind::Unset;
};

}
}