Abc
woke.ast.ir.abc.IrAbc
class
#
Bases: ABC
Base class for all IR nodes. Defines attributes and methods that are common to all Solidity and Yul IR nodes.
IR model is built on top of the AST (Abstract Syntax Tree) output of the solc compiler.
Each IR node is associated with a source code location in a source file. This means that each IR node has a corresponding (typically non-empty) Solidity or Yul source code.
Info
Yul IR nodes can have empty source code. In the case of Solidity IR nodes, this should not happen.
Source code in woke/ast/ir/abc.py
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 |
|
ast_tree_depth: int
property
#
The depth of this node in the AST tree. The root node (Source unit) of each file has depth 0. Direct child nodes of a node
have depth {node}.ast_tree_depth + 1
.
Tip
Woke uses interval trees to get a list of all IR nodes at a given byte offset in a given file. This property can be used to sort these nodes by their depth in the AST tree and (for example) to choose the most nested one.
Returns:
Type | Description |
---|---|
int
|
Depth of this node in the AST tree, starting from 0. |
byte_location: Tuple[int, int]
property
#
The start and end byte offsets of this node in the source file. {node}.byte_location[0]
is the start byte offset, {node}.byte_location[1]
is the end byte offset.
{node}.byte_location[1]
is always greater than or equal to {node}.byte_location[0]
.
The byte location of a child node is typically a subrange of the byte location of its parent node.
Info
This is not true for Structured documentation, where documentation strings must be located before a declaration.
Returns:
Type | Description |
---|---|
Tuple[int, int]
|
Tuple of the start and end byte offsets of this node in the source file. |
file: Path
property
#
The absolute path to the source file that contains this IR node. For a given IR node, all child and parent nodes have the same file path.
Returns:
Type | Description |
---|---|
Path
|
Absolute path to the file containing this node. |
parent: Optional[IrAbc]
abstractmethod
property
#
The parent node of this node. Can only be None
for the root (Source unit) node.
Returns:
Type | Description |
---|---|
Optional[IrAbc]
|
Parent node of this node. |
source: str
property
#
UTF-8 decoded source code from the source file at the byte offset of this node.
Returns:
Type | Description |
---|---|
str
|
Solidity or Yul source code corresponding to this node. |
version_ranges: SolidityVersionRanges
property
#
woke.ast.ir.abc.SolidityAbc
class
#
Abstract base class for all Solidity IR nodes.
Source code in woke/ast/ir/abc.py
woke.ast.ir.yul.abc.YulAbc
class
#
Abstract base class for all Yul IR nodes.
Source code in woke/ast/ir/yul/abc.py
woke.ast.ir.declaration.abc.DeclarationAbc
class
#
Bases: SolidityAbc
, ABC
Abstract base class for all Solidity declarations.
Source code in woke/ast/ir/declaration/abc.py
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 |
|
canonical_name: str
abstractmethod
property
#
Example
ContractName.StructName.FieldName
in the case of the FieldName
VariableDeclaration declaration in the following example:
Returns:
Type | Description |
---|---|
str
|
Canonical name of the declared object. |
declaration_string: str
abstractmethod
property
#
Declaration string that can be used for example in LSP hover. Does not include the declaration body, if any. Does not need to match the actual declaration string in the source code (may use a different order of keywords, for example).
Example
function foo(uint a, uint b) public payable virtual onlyOwner returns (uint)
of the FunctionDefinition declaration in the following example:
Returns:
Type | Description |
---|---|
str
|
String representation of the declaration. |
name_location: Tuple[int, int]
property
#
Similar to byte_location, but returns the location of the declaration name in the source code.
Returns:
Type | Description |
---|---|
Tuple[int, int]
|
Tuple of the start and end byte offsets of the declaration name in the source code. |
references: FrozenSet[Union[Identifier, IdentifierPathPart, MemberAccess, ExternalReference, UnaryOperation, BinaryOperation]]
property
#
Returns:
Type | Description |
---|---|
FrozenSet[Union[Identifier, IdentifierPathPart, MemberAccess, ExternalReference, UnaryOperation, BinaryOperation]]
|
Set of all IR nodes referencing to this declaration. |
woke.ast.ir.expression.abc.ExpressionAbc
class
#
Bases: SolidityAbc
, ABC
Abstract base class for all IR expression nodes.
Something that has a value.
Source code in woke/ast/ir/expression/abc.py
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 |
|
is_ref_to_state_variable: bool
abstractmethod
property
#
In many cases it may be useful to know if an Assignment to an expression modifies a state variable or not. This may not be straightforward to determine, e.g. if the expression is a MemberAccess or IndexAccess to a state variable.
Returns:
Type | Description |
---|---|
bool
|
|
modifies_state: Set[Tuple[IrAbc, ModifiesStateFlag]]
abstractmethod
property
#
Returns:
Type | Description |
---|---|
Set[Tuple[IrAbc, ModifiesStateFlag]]
|
Set of child IR nodes (including |
type: Optional[TypeAbc]
cached
property
#
Can be None
in case of an Identifier in an ImportDirective.
Example
Ownable
in the following example has no type information:
Returns:
Type | Description |
---|---|
Optional[TypeAbc]
|
Type of the expression. |
type_string: Optional[str]
property
#
Example
function (uint256,uint256) returns (uint256)
in the case of the foo
Identifier in the foo(1, 2)
expression for the following function:
Can be None
in case of an Identifier in an ImportDirective.
Example
Ownable
in the following example has no type information:
Returns:
Type | Description |
---|---|
Optional[str]
|
User-friendly string describing the expression type. |
woke.ast.ir.statement.abc.StatementAbc
class
#
Bases: SolidityAbc
, ABC
Abstract base class for all Solidity statements.
Source code in woke/ast/ir/statement/abc.py
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 |
|
documentation: Optional[str]
property
#
modifies_state: Set[Tuple[IrAbc, ModifiesStateFlag]]
abstractmethod
property
#
Returns:
Type | Description |
---|---|
Set[Tuple[IrAbc, ModifiesStateFlag]]
|
Set of child IR nodes (including |
parent: Union[Block, DoWhileStatement, ForStatement, IfStatement, UncheckedBlock, WhileStatement, FunctionDefinition, ModifierDefinition, TryCatchClause]
abstractmethod
property
#
Returns:
Type | Description |
---|---|
Union[Block, DoWhileStatement, ForStatement, IfStatement, UncheckedBlock, WhileStatement, FunctionDefinition, ModifierDefinition, TryCatchClause]
|
Parent node of the statement. |
statements_iter()
#
Yields:
Type | Description |
---|---|
Iterator[StatementAbc]
|
Child statements of the statement (recursively) including |
woke.ast.ir.type_name.abc.TypeNameAbc
class
#
Bases: SolidityAbc
, ABC
Abstract base class for all IR type name nodes.
Source code in woke/ast/ir/type_name/abc.py
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 |
|
parent: Union[VariableDeclaration, UserDefinedValueTypeDefinition, ElementaryTypeNameExpression, NewExpression, UsingForDirective, ArrayTypeName, Mapping]
abstractmethod
property
#
Returns:
Type | Description |
---|---|
Union[VariableDeclaration, UserDefinedValueTypeDefinition, ElementaryTypeNameExpression, NewExpression, UsingForDirective, ArrayTypeName, Mapping]
|
Parent node of the type name. |