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
pub fn array_type_names(&self) -> Vec<&ArrayTypeName>Retrieves all ArrayTypeName nodes from the AST.
Returns:
Vec<&ArrayTypeName>: A vector of references toArrayTypeNamenodes.
assignments
pub fn assignments(&self) -> Vec<&Assignment>Retrieves all Assignment nodes from the AST.
Returns:
Vec<&Assignment>: A vector of references toAssignmentnodes.
binary_operations
pub fn binary_operations(&self) -> Vec<&BinaryOperation>Retrieves all BinaryOperation nodes from the AST.
Returns:
Vec<&BinaryOperation>: A vector of references toBinaryOperationnodes.
blocks
pub fn blocks(&self) -> Vec<&Block>Retrieves all Block nodes from the AST.
Returns:
Vec<&Block>: A vector of references toBlocknodes.
conditionals
pub fn conditionals(&self) -> Vec<&Conditional>Retrieves all Conditional nodes from the AST.
Returns:
Vec<&Conditional>: A vector of references toConditionalnodes.
contract_definitions
pub fn contract_definitions(&self) -> Vec<&ContractDefinition>Retrieves all ContractDefinition nodes from the AST.
Returns:
Vec<&ContractDefinition>: A vector of references toContractDefinitionnodes.
elementary_type_names
pub fn elementary_type_names(&self) -> Vec<&ElementaryTypeName>Retrieves all ElementaryTypeName nodes from the AST.
Returns:
Vec<&ElementaryTypeName>: A vector of references toElementaryTypeNamenodes.
elementary_type_name_expressions
pub fn elementary_type_name_expressions(&self) -> Vec<&ElementaryTypeNameExpression>Retrieves all ElementaryTypeNameExpression nodes from the AST.
Returns:
Vec<&ElementaryTypeNameExpression>: A vector of references toElementaryTypeNameExpressionnodes.
emit_statements
pub fn emit_statements(&self) -> Vec<&EmitStatement>Retrieves all EmitStatement nodes from the AST.
Returns:
Vec<&EmitStatement>: A vector of references toEmitStatementnodes.
enum_definitions
pub fn enum_definitions(&self) -> Vec<&EnumDefinition>Retrieves all EnumDefinition nodes from the AST.
Returns:
Vec<&EnumDefinition>: A vector of references toEnumDefinitionnodes.
enum_values
pub fn enum_values(&self) -> Vec<&EnumValue>Retrieves all EnumValue nodes from the AST.
Returns:
Vec<&EnumValue>: A vector of references toEnumValuenodes.
event_definitions
pub fn event_definitions(&self) -> Vec<&EventDefinition>Retrieves all EventDefinition nodes from the AST.
Returns:
Vec<&EventDefinition>: A vector of references toEventDefinitionnodes.
error_definitions
pub fn error_definitions(&self) -> Vec<&ErrorDefinition>Retrieves all ErrorDefinition nodes from the AST.
Returns:
Vec<&ErrorDefinition>: A vector of references toErrorDefinitionnodes.
expression_statements
pub fn expression_statements(&self) -> Vec<&ExpressionStatement>Retrieves all ExpressionStatement nodes from the AST.
Returns:
Vec<&ExpressionStatement>: A vector of references toExpressionStatementnodes.
function_calls
pub fn function_calls(&self) -> Vec<&FunctionCall>Retrieves all FunctionCall nodes from the AST.
Returns:
Vec<&FunctionCall>: A vector of references toFunctionCallnodes.
function_call_options
pub fn function_call_options(&self) -> Vec<&FunctionCallOptions>Retrieves all FunctionCallOptions nodes from the AST.
Returns:
Vec<&FunctionCallOptions>: A vector of references to `FunctionCall
Options` nodes.
function_definitions
pub fn function_definitions(&self) -> Vec<&FunctionDefinition>Retrieves all FunctionDefinition nodes from the AST.
Returns:
Vec<&FunctionDefinition>: A vector of references toFunctionDefinitionnodes.
function_type_names
pub fn function_type_names(&self) -> Vec<&FunctionTypeName>Retrieves all FunctionTypeName nodes from the AST.
Returns:
Vec<&FunctionTypeName>: A vector of references toFunctionTypeNamenodes.
for_statements
pub fn for_statements(&self) -> Vec<&ForStatement>Retrieves all ForStatement nodes from the AST.
Returns:
Vec<&ForStatement>: A vector of references toForStatementnodes.
identifiers
pub fn identifiers(&self) -> Vec<&Identifier>Retrieves all Identifier nodes from the AST.
Returns:
Vec<&Identifier>: A vector of references toIdentifiernodes.
identifier_paths
pub fn identifier_paths(&self) -> Vec<&IdentifierPath>Retrieves all IdentifierPath nodes from the AST.
Returns:
Vec<&IdentifierPath>: A vector of references toIdentifierPathnodes.
if_statements
pub fn if_statements(&self) -> Vec<&IfStatement>Retrieves all IfStatement nodes from the AST.
Returns:
Vec<&IfStatement>: A vector of references toIfStatementnodes.
[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
pub fn get_parent(&self, node_id: NodeID) -> Option<&ASTNode>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. ReturnsNoneif the parent does not exist.
get_ancestral_line
pub fn get_ancestral_line(&self, node_id: NodeID) -> Vec<&ASTNode>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
pub fn get_closest_ancestor(&self, node_id: NodeID, node_type: NodeType) -> Option<&ASTNode>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. ReturnsNoneif no such ancestor exists.
Last updated
Was this helpful?