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.
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 toArrayTypeName
nodes.
assignments
pub fn assignments(&self) -> Vec<&Assignment>
Retrieves all Assignment
nodes from the AST.
Returns:
Vec<&Assignment>
: A vector of references toAssignment
nodes.
binary_operations
pub fn binary_operations(&self) -> Vec<&BinaryOperation>
Retrieves all BinaryOperation
nodes from the AST.
Returns:
Vec<&BinaryOperation>
: A vector of references toBinaryOperation
nodes.
blocks
pub fn blocks(&self) -> Vec<&Block>
Retrieves all Block
nodes from the AST.
Returns:
Vec<&Block>
: A vector of references toBlock
nodes.
conditionals
pub fn conditionals(&self) -> Vec<&Conditional>
Retrieves all Conditional
nodes from the AST.
Returns:
Vec<&Conditional>
: A vector of references toConditional
nodes.
contract_definitions
pub fn contract_definitions(&self) -> Vec<&ContractDefinition>
Retrieves all ContractDefinition
nodes from the AST.
Returns:
Vec<&ContractDefinition>
: A vector of references toContractDefinition
nodes.
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 toElementaryTypeName
nodes.
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 toElementaryTypeNameExpression
nodes.
emit_statements
pub fn emit_statements(&self) -> Vec<&EmitStatement>
Retrieves all EmitStatement
nodes from the AST.
Returns:
Vec<&EmitStatement>
: A vector of references toEmitStatement
nodes.
enum_definitions
pub fn enum_definitions(&self) -> Vec<&EnumDefinition>
Retrieves all EnumDefinition
nodes from the AST.
Returns:
Vec<&EnumDefinition>
: A vector of references toEnumDefinition
nodes.
enum_values
pub fn enum_values(&self) -> Vec<&EnumValue>
Retrieves all EnumValue
nodes from the AST.
Returns:
Vec<&EnumValue>
: A vector of references toEnumValue
nodes.
event_definitions
pub fn event_definitions(&self) -> Vec<&EventDefinition>
Retrieves all EventDefinition
nodes from the AST.
Returns:
Vec<&EventDefinition>
: A vector of references toEventDefinition
nodes.
error_definitions
pub fn error_definitions(&self) -> Vec<&ErrorDefinition>
Retrieves all ErrorDefinition
nodes from the AST.
Returns:
Vec<&ErrorDefinition>
: A vector of references toErrorDefinition
nodes.
expression_statements
pub fn expression_statements(&self) -> Vec<&ExpressionStatement>
Retrieves all ExpressionStatement
nodes from the AST.
Returns:
Vec<&ExpressionStatement>
: A vector of references toExpressionStatement
nodes.
function_calls
pub fn function_calls(&self) -> Vec<&FunctionCall>
Retrieves all FunctionCall
nodes from the AST.
Returns:
Vec<&FunctionCall>
: A vector of references toFunctionCall
nodes.
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
function_definitions
pub fn function_definitions(&self) -> Vec<&FunctionDefinition>
Retrieves all FunctionDefinition
nodes from the AST.
Returns:
Vec<&FunctionDefinition>
: A vector of references toFunctionDefinition
nodes.
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 toFunctionTypeName
nodes.
for_statements
pub fn for_statements(&self) -> Vec<&ForStatement>
Retrieves all ForStatement
nodes from the AST.
Returns:
Vec<&ForStatement>
: A vector of references toForStatement
nodes.
identifiers
pub fn identifiers(&self) -> Vec<&Identifier>
Retrieves all Identifier
nodes from the AST.
Returns:
Vec<&Identifier>
: A vector of references toIdentifier
nodes.
identifier_paths
pub fn identifier_paths(&self) -> Vec<&IdentifierPath>
Retrieves all IdentifierPath
nodes from the AST.
Returns:
Vec<&IdentifierPath>
: A vector of references toIdentifierPath
nodes.
if_statements
pub fn if_statements(&self) -> Vec<&IfStatement>
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
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. ReturnsNone
if 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. ReturnsNone
if no such ancestor exists.