WorkspaceContext
The WorkspaceContext
struct is designed to manage and interact with an Abstract Syntax Tree (AST) of source code. It facilitates access to various node types in the AST and provides methods to retrieve parental and ancestral relationships between these nodes. The following API documentation details the methods implemented in the WorkspaceContext
struct.
Definition: https://github.com/Cyfrin/aderyn/blob/dev/aderyn_core/src/context/workspace_context.rs
WorkspaceContext Struct API Reference - Getters
The getters in the WorkspaceContext
struct provides access to vectors of references to various AST node types, each stored in a separate context within the struct. These methods are crucial for retrieving collections of specific node types for analysis or manipulation.
Getters
array_type_names
Retrieves all ArrayTypeName
nodes from the AST.
Returns:
Vec<&ArrayTypeName>
: A vector of references toArrayTypeName
nodes.
assignments
Retrieves all Assignment
nodes from the AST.
Returns:
Vec<&Assignment>
: A vector of references toAssignment
nodes.
binary_operations
Retrieves all BinaryOperation
nodes from the AST.
Returns:
Vec<&BinaryOperation>
: A vector of references toBinaryOperation
nodes.
blocks
Retrieves all Block
nodes from the AST.
Returns:
Vec<&Block>
: A vector of references toBlock
nodes.
conditionals
Retrieves all Conditional
nodes from the AST.
Returns:
Vec<&Conditional>
: A vector of references toConditional
nodes.
contract_definitions
Retrieves all ContractDefinition
nodes from the AST.
Returns:
Vec<&ContractDefinition>
: A vector of references toContractDefinition
nodes.
elementary_type_names
Retrieves all ElementaryTypeName
nodes from the AST.
Returns:
Vec<&ElementaryTypeName>
: A vector of references toElementaryTypeName
nodes.
elementary_type_name_expressions
Retrieves all ElementaryTypeNameExpression
nodes from the AST.
Returns:
Vec<&ElementaryTypeNameExpression>
: A vector of references toElementaryTypeNameExpression
nodes.
emit_statements
Retrieves all EmitStatement
nodes from the AST.
Returns:
Vec<&EmitStatement>
: A vector of references toEmitStatement
nodes.
enum_definitions
Retrieves all EnumDefinition
nodes from the AST.
Returns:
Vec<&EnumDefinition>
: A vector of references toEnumDefinition
nodes.
enum_values
Retrieves all EnumValue
nodes from the AST.
Returns:
Vec<&EnumValue>
: A vector of references toEnumValue
nodes.
event_definitions
Retrieves all EventDefinition
nodes from the AST.
Returns:
Vec<&EventDefinition>
: A vector of references toEventDefinition
nodes.
error_definitions
Retrieves all ErrorDefinition
nodes from the AST.
Returns:
Vec<&ErrorDefinition>
: A vector of references toErrorDefinition
nodes.
expression_statements
Retrieves all ExpressionStatement
nodes from the AST.
Returns:
Vec<&ExpressionStatement>
: A vector of references toExpressionStatement
nodes.
function_calls
Retrieves all FunctionCall
nodes from the AST.
Returns:
Vec<&FunctionCall>
: A vector of references toFunctionCall
nodes.
function_call_options
Retrieves all FunctionCallOptions
nodes from the AST.
Returns:
Vec<&FunctionCallOptions>
: A vector of references to `FunctionCall
Options` nodes.
function_definitions
Retrieves all FunctionDefinition
nodes from the AST.
Returns:
Vec<&FunctionDefinition>
: A vector of references toFunctionDefinition
nodes.
function_type_names
Retrieves all FunctionTypeName
nodes from the AST.
Returns:
Vec<&FunctionTypeName>
: A vector of references toFunctionTypeName
nodes.
for_statements
Retrieves all ForStatement
nodes from the AST.
Returns:
Vec<&ForStatement>
: A vector of references toForStatement
nodes.
identifiers
Retrieves all Identifier
nodes from the AST.
Returns:
Vec<&Identifier>
: A vector of references toIdentifier
nodes.
identifier_paths
Retrieves all IdentifierPath
nodes from the AST.
Returns:
Vec<&IdentifierPath>
: A vector of references toIdentifierPath
nodes.
if_statements
Retrieves all IfStatement
nodes from the AST.
Returns:
Vec<&IfStatement>
: A vector of references toIfStatement
nodes.
[Methods continue in a similar format for each specific AST node type]
Navigation Methods
Methods in this section are used to navigate the AST based on node relationships.
get_parent
Fetches the parent node of the specified node ID.
Parameters:
node_id
: The unique identifier for an AST node, typically encapsulating the location or the specific instance of the node within the AST.
Returns:
Option<&ASTNode>
: An optional reference to the AST node that is the parent of the specified node. ReturnsNone
if the parent does not exist.
get_ancestral_line
Constructs the ancestral line of AST nodes from the specified node up to the root.
Parameters:
node_id
: The unique identifier for an AST node.
Returns:
Vec<&ASTNode>
: A vector containing references to each node in the ancestral line, starting from the specified node and extending to the root node.
get_closest_ancestor
Searches for the closest ancestor of the specified node that matches the given node type.
Parameters:
node_id
: The unique identifier for an AST node.node_type
: The type of node to find as an ancestor (e.g.,FunctionDefinition
,Block
).
Returns:
Option<&ASTNode>
: An optional reference to the closest ancestor node of the specified type. ReturnsNone
if no such ancestor exists.
Last updated