wake.ir.reference_resolver
module
#
ReferenceResolver
class
#
The reference resolver is responsible for resolving references between IR nodes.
A single Solidity source file can be compiled in multiple compilation units (CUs). Each CU may use different AST node IDs for the same AST node. The reference resolver can map between different AST node IDs for the same AST node by indexing the AST IDs by their file path and traversal order. Different compiler versions may produce (structurally) different ASTs for the same source code. All of these cases should be handled by the reference resolver.
Wake holds only a single SourceUnit IR node for each source file. If a source file is compiled in multiple CUs, a canonical AST representation is chosen and the other CUs only perform indexing of the AST nodes. Which CU is chosen as the canonical is internal to Wake and should not be relied upon.
A unique identifier across all CUs is a tuple (path, traversal_order).
Source code in wake/ir/reference_resolver.py
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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
get_ast_id_from_cu_node_path_order(node_path_order, cu_hash)
#
Get the AST node ID for a given (path, traversal_order) in a given CU.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_path_order
|
Tuple[Path, int]
|
(path, traversal_order) tuple |
required |
cu_hash
|
bytes
|
hash of the compilation unit that contains the returned AST node ID |
required |
Returns:
Type | Description |
---|---|
AstNodeId
|
AST node ID for the given (path, traversal_order) tuple in the given CU |
Source code in wake/ir/reference_resolver.py
get_global_symbol_references(node_id)
#
Get all references to a given global symbol.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
GlobalSymbol
|
global symbol |
required |
Returns:
Type | Description |
---|---|
Tuple[Union[Identifier, MemberAccess], ...]
|
Tuple of all references to the given global symbol |
Source code in wake/ir/reference_resolver.py
get_node_path_order(node_id, cu_hash)
#
Get the (path, traversal_order) for a given AST node ID in a given CU.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
AstNodeId
|
AST node ID |
required |
cu_hash
|
bytes
|
hash of the compilation unit that contains the AST node ID |
required |
Returns:
Type | Description |
---|---|
Tuple[Path, int]
|
Tuple of (path, traversal_order) for the AST node ID |
Source code in wake/ir/reference_resolver.py
resolve_node(node_id, cu_hash)
#
Get the IR node for a given AST node ID in a given CU.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
AstNodeId
|
AST node ID |
required |
cu_hash
|
bytes
|
hash of the compilation unit that contains the AST node ID |
required |
Returns:
Type | Description |
---|---|
SolidityAbc
|
IR node for the given AST node ID in the given CU |
Source code in wake/ir/reference_resolver.py
resolve_source_file_id(source_file_id, cu_hash)
#
solc
compiler output also assigns integer IDs to source files.
This function can be used to get the absolute path to the source file for a given source file ID in a given CU.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_file_id
|
int
|
source file ID |
required |
cu_hash
|
bytes
|
hash of the compilation unit that contains the source file ID |
required |
Returns:
Type | Description |
---|---|
Path
|
Absolute path to the source file for the given source file ID in the given CU |