solidity_parser.ast.symtab¶
Attributes¶
Exceptions¶
Common base class for all non-exit exceptions. |
Classes¶
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Element that can be added as a child of a Scope |
|
Symbol for a function that was added to the current scope by a Solidity using statement. Solidity docs state that |
|
Similar to UsingFunctionSymbol except for operator overloads |
|
Functions¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Module Contents¶
- solidity_parser.ast.symtab.Aliases: TypeAlias = str | list[str]¶
- solidity_parser.ast.symtab.bytes()¶
- solidity_parser.ast.symtab.bytesn(n)¶
- solidity_parser.ast.symtab.bytes32()¶
- solidity_parser.ast.symtab.uint(size=256)¶
- solidity_parser.ast.symtab.ACCEPT(x)¶
- solidity_parser.ast.symtab.unit_scope_of(s)¶
- solidity_parser.ast.symtab.ACCEPT_INHERITABLE(base_scope)¶
- solidity_parser.ast.symtab.is_top_level(node: solidity_parser.ast.nodebase.Node)¶
- solidity_parser.ast.symtab.predicate_ignore_inherited_usings(base_scope)¶
- solidity_parser.ast.symtab.ACCEPT_NO_INHERITED_USINGS(base_scope)¶
- solidity_parser.ast.symtab.ACCEPT_CALLABLES(x)¶
- solidity_parser.ast.symtab.ACCEPT_NOT(p)¶
- solidity_parser.ast.symtab.ACCEPT_TOP_LEVEL_SCOPE(x)¶
- solidity_parser.ast.symtab.ACCEPT_ALL(*predicates)¶
- solidity_parser.ast.symtab.test_predicate(xs, predicate=None)¶
- solidity_parser.ast.symtab._add_to_results(possible_symbols: Collection, results: list, found_already: Set)¶
- exception solidity_parser.ast.symtab.TypeNotFound¶
Bases:
Exception
Common base class for all non-exit exceptions.
- class solidity_parser.ast.symtab.Scopeable(aliases: Aliases | None)¶
Element that can be added as a child of a Scope
- aliases: list[str]¶
- set_parent_scope(parent_scope: Scope)¶
Sets the parent scope of this element, subclasses can check the type of the parent for sanity checks
- _T¶
- find_first_ancestor(predicate: Callable[[Scopeable], bool], get_parent: Callable[[Scopeable], Scope] | None = None) _T | None ¶
Walks up the symbol tree and finds the first element that satisfies the given predicate
- Parameters:
predicate – a function that takes a Scopeable and returns a bool to determine if it matches
get_parent – a function that takes a Scopeable and returns its parent, defaults to the parent_scope of a Scopeable
- Returns:
the first Scopeable that satisfies the predicate
- find_first_ancestor_of(ttype: Type[_T]) _T | None ¶
Find the first ancestor that is of the given type, note: these are python types and not solc types.
- Parameters:
ttype – e.g. ContractOrInterfaceScope
- Returns:
the first ancestor that is of the given type
- _check_single_symbol(name, results, default)¶
- class solidity_parser.ast.symtab.Symbol(aliases: Aliases | None, value)¶
Bases:
Scopeable
Element that can be added as a child of a Scope
- value¶
- order¶
- res_syms_single()¶
- set_parent_scope(parent_scope: Scope)¶
Sets the parent scope of this element, subclasses can check the type of the parent for sanity checks
- str_type()¶
- __str__(level=0)¶
Return str(self).
- class solidity_parser.ast.symtab.CrossScopeSymbolAlias(aliases: Aliases, other_symbol: Symbol)¶
Bases:
Symbol
Element that can be added as a child of a Scope
- other_symbol¶
- class solidity_parser.ast.symtab.Scope(aliases: Aliases | None)¶
Bases:
Scopeable
Element that can be added as a child of a Scope
- is_defined(name: str) bool ¶
Check if the name exists in the current scopes local table, i.e. whether it was declared in the current scope
- get_all_children(collect_predicate, explore_branch_predicate)¶
Tree explorer for all DECLARED children and grandchildren, i.e. doesn’t look at imports
- get_all_functions() list[ModFunErrEvtScope] ¶
Gets all DECLARED functions in the current scope/descendant scopes
- import_symbols_from_scope(other_scope: Scope)¶
Links the symbols in another scope to the current scope, i.e. makes the imported symbols visible in the current scope
- Parameters:
other_scope – The scope whose symbols should be imported
- find_current_level(name: str, predicate=None, visited_scopes: Set[Scope] = None) list[Symbol] ¶
Finds symbols in this scope or any imported scopes at the current “level”. A level is roughly the scopes that are visible by an expression in the current scope.
- find_imported(name: str, predicate=None, visited_scopes: Set = None) list[Symbol] ¶
Finds the given name in all the imported scopes that are linked to the current scope. This can match many valid symbols so it is up to the caller to choose the right one, however, the results are deduplicated by checking that two symbols dealias to the same symbol.
- find_multi_part_symbol(name: str, find_base_symbol: bool = False, predicate=None)¶
Finds a potentially multi-part/qualified symbol (e.g. a.b.c)
- find(name: str, find_base_symbol: bool = False, predicate=None, dealias: bool = True) list[Symbol] ¶
Entry point for the symbol finder. Finds the given name in this scope and any imported scopes
- Parameters:
name (str): The name to search for. find_base_symbol (bool): Whether to find base symbols. predicate (function): A function to filter symbols. dealias (bool): Whether to dealias symbols.
- Returns:
list[Symbol]: A list of symbols that match the search criteria.
- find_single(name: str, find_base_symbol: bool = False, default=None, predicate=None) Symbol | None ¶
- find_user_type_scope(name, find_base_symbol: bool = False, default=None, predicate=None) Scope | list[Scope] ¶
Finds the scope of a user-defined type based on the given name. :param name: The name of the type :param find_base_symbol: Whether to find the base symbol or whether using scopes are acceptable results :param default: The default value to return if no matches are found :param predicate: Optional function to filter during the search
- Returns:
A single scope if find_base_symbol is True, or a list of scopes if find_base_symbol is False
- Raises:
TypeNotFound – if no type matching the name was found
- find_type(ttype, predicate=None, as_single=False) Scope | None | list[Scope] ¶
Finds the scope for the given type in the current scope. The type scope might be different to the scope of the type where the type was defined because of using statements. A scope is created if one isn’t visible in the current scope.
- Parameters:
ttype – The type to search for, CANNOT be a user type, use find_user_type_scope for that case
predicate – Optional function to filter during the search
as_single – Whether to return a single scope or a list of scopes
- Returns:
The scope if as_single is True or a list of scopes if as_single is False
- str__symbols(level=0)¶
Returns a string representation of all symbols in this scope and its children with indentation
- __str__(level=0)¶
Return str(self).
- class solidity_parser.ast.symtab.ScopeAndSymbol(aliases: Aliases | None, ast_node)¶
-
Element that can be added as a child of a Scope
- set_parent_scope(parent_scope: Scope)¶
Sets the parent scope of this element, subclasses can check the type of the parent for sanity checks
- __str__(level=0)¶
Return str(self).
- class solidity_parser.ast.symtab.BuiltinObject(name: str, value=None)¶
Bases:
ScopeAndSymbol
Element that can be added as a child of a Scope
- name¶
- class solidity_parser.ast.symtab.BuiltinFunction(name: str, input_types: list[solidity_parser.ast.types.Type] | None, output_types: list[solidity_parser.ast.types.Type] | None)¶
Bases:
Symbol
Element that can be added as a child of a Scope
- input_types¶
- output_types¶
- class solidity_parser.ast.symtab.BuiltinValue(name: str, ttype: solidity_parser.ast.types.Type)¶
Bases:
Symbol
Element that can be added as a child of a Scope
- ttype¶
- solidity_parser.ast.symtab.create_builtin_scope(key, value=None, values=None, functions=None)¶
- solidity_parser.ast.symtab.simple_name_resolver(scope, name)¶
- solidity_parser.ast.symtab.type_key(ttype, name_resolver=simple_name_resolver) str ¶
- solidity_parser.ast.symtab.meta_type_key(ttype, name_resolver=simple_name_resolver) str ¶
- class solidity_parser.ast.symtab.RootScope(parser_version: solidity_parser.util.version_util.Version)¶
Bases:
Scope
Element that can be added as a child of a Scope
- compiler_version = None¶
- msg_object¶
- abi_object¶
- block_object¶
- tx_object¶
- bytes_object¶
- string_object¶
- class solidity_parser.ast.symtab.FileScope(builder: Builder2, vfs: solidity_parser.filesys.VirtualFileSystem, source_unit_name: str, ast1_units: list[solidity_parser.ast.solnodes.SourceUnit])¶
Bases:
ScopeAndSymbol
Element that can be added as a child of a Scope
- static alias(source_unit_name: str)¶
- builder¶
- vfs¶
- source_unit_name¶
- class solidity_parser.ast.symtab.LibraryScope(ast_node: solidity_parser.ast.solnodes.LibraryDefinition)¶
Bases:
ScopeAndSymbol
Element that can be added as a child of a Scope
- class solidity_parser.ast.symtab.ContractOrInterfaceScope(ast_node: solidity_parser.ast.solnodes.ContractDefinition | solidity_parser.ast.solnodes.InterfaceDefinition)¶
Bases:
ScopeAndSymbol
Element that can be added as a child of a Scope
- find_current_level(name: str, predicate=None, visited_scopes: Set = None, check_hierarchy=True) list[Symbol] | None ¶
Finds symbols in this scope or any imported scopes at the current “level”. A level is roughly the scopes that are visible by an expression in the current scope.
- find_in_contract_hierarchy(name: str, predicate, visited_scopes)¶
- get_supers() list[ContractOrInterfaceScope] ¶
- class solidity_parser.ast.symtab.StructScope(ast_node: solidity_parser.ast.solnodes.StructDefinition)¶
Bases:
ScopeAndSymbol
Element that can be added as a child of a Scope
- class solidity_parser.ast.symtab.UserDefinedValueTypeScope(ast_node: solidity_parser.ast.solnodes.UserValueType)¶
Bases:
ScopeAndSymbol
Element that can be added as a child of a Scope
- class solidity_parser.ast.symtab.LibraryScope(ast_node: solidity_parser.ast.solnodes.LibraryDefinition)¶
Bases:
ScopeAndSymbol
Element that can be added as a child of a Scope
- class solidity_parser.ast.symtab.EnumScope(ast_node: solidity_parser.ast.solnodes.EnumDefinition)¶
Bases:
ScopeAndSymbol
Element that can be added as a child of a Scope
- class solidity_parser.ast.symtab.ModFunErrEvtScope(ast_node: solidity_parser.ast.solnodes.FunctionDefinition | solidity_parser.ast.solnodes.EventDefinition | solidity_parser.ast.solnodes.ErrorDefinition | solidity_parser.ast.solnodes.ModifierDefinition)¶
Bases:
ScopeAndSymbol
Element that can be added as a child of a Scope
- class solidity_parser.ast.symtab.ImportSymbol(aliases: Aliases | None, ast_node: solidity_parser.ast.solnodes.ImportDirective)¶
Bases:
ScopeAndSymbol
Element that can be added as a child of a Scope
- find(name: str, find_base_symbol: bool = False, predicate=None, dealias: bool = True) list[Symbol] | None ¶
Entry point for the symbol finder. Finds the given name in this scope and any imported scopes
- Parameters:
name (str): The name to search for. find_base_symbol (bool): Whether to find base symbols. predicate (function): A function to filter symbols. dealias (bool): Whether to dealias symbols.
- Returns:
list[Symbol]: A list of symbols that match the search criteria.
- find_first_ancestor(predicate, get_parent=None)¶
Walks up the symbol tree and finds the first element that satisfies the given predicate
- Parameters:
predicate – a function that takes a Scopeable and returns a bool to determine if it matches
get_parent – a function that takes a Scopeable and returns its parent, defaults to the parent_scope of a Scopeable
- Returns:
the first Scopeable that satisfies the predicate
- find_first_ancestor_of(ttype: Type | Tuple[Type])¶
Find the first ancestor that is of the given type, note: these are python types and not solc types.
- Parameters:
ttype – e.g. ContractOrInterfaceScope
- Returns:
the first ancestor that is of the given type
- find_imported(name: str, predicate=None, visited_scopes: Set = None) list[Symbol] | None ¶
Finds the given name in all the imported scopes that are linked to the current scope. This can match many valid symbols so it is up to the caller to choose the right one, however, the results are deduplicated by checking that two symbols dealias to the same symbol.
- find_current_level(name: str, predicate=None, visited_scopes: Set = None) list[Symbol] | None ¶
Finds symbols in this scope or any imported scopes at the current “level”. A level is roughly the scopes that are visible by an expression in the current scope.
- class solidity_parser.ast.symtab.AliasImportSymbol(ast_node: solidity_parser.ast.solnodes.SymbolImportDirective, alias_index)¶
Bases:
ImportSymbol
Element that can be added as a child of a Scope
- alias_index¶
- class solidity_parser.ast.symtab.UnitImportSymbol(ast_node: solidity_parser.ast.solnodes.UnitImportDirective)¶
Bases:
ImportSymbol
Element that can be added as a child of a Scope
- class solidity_parser.ast.symtab.ProxyScope(name: str, base_scope: ScopeAndSymbol)¶
Bases:
ScopeAndSymbol
Element that can be added as a child of a Scope
- base_scope¶
- created_by = None¶
- class solidity_parser.ast.symtab.UsingDirectiveScope(node: solidity_parser.ast.solnodes.UsingDirective)¶
Bases:
ScopeAndSymbol
Element that can be added as a child of a Scope
- class solidity_parser.ast.symtab.UsingFunctionSymbol(target: ModFunErrEvtScope, override_type: solidity_parser.ast.types.Type)¶
Bases:
Symbol
Symbol for a function that was added to the current scope by a Solidity using statement. Solidity docs state that all functions, even those that don’t match the type specifier in the using statement have to be added to the scope the using statement is declared in. This symbol type is required instead of the usual ModFunErrEvtSymbol as we need to be able to associate the bound type from the using statement and the first parameter type of the “value” of this symbol(i.e. the FunctionDefinition) may or may not be the same as the specified one.
- target¶
- override_type¶
- class solidity_parser.ast.symtab.UsingOperatorSymbol(target: ModFunErrEvtScope, override_type: solidity_parser.ast.types.Type, operator: solidity_parser.ast.solnodes.UnaryOpCode | solidity_parser.ast.solnodes.BinaryOpCode)¶
Bases:
Symbol
Similar to UsingFunctionSymbol except for operator overloads
- target¶
- override_type¶
- operator¶
- class solidity_parser.ast.symtab.Builder2(vfs: solidity_parser.filesys.VirtualFileSystem, parser_version: solidity_parser.util.version_util.Version = None)¶
-
- root_scope¶
- vfs¶
- parser_version¶
- process_or_find(loaded_source: solidity_parser.filesys.LoadedSource)¶
- process_or_find_from_base_dir(relative_source_unit_name: str | pathlib.Path)¶
- process_file(source_unit_name: str, source_units: list[solidity_parser.ast.solnodes.SourceUnit] = None)¶
- sort_ast_nodes(nodes)¶
- add_node_dfs(parent_scope, node, context: Context, build_skeletons, visit_index=0)¶
Recursively traverse a node and its children and create symbols and scopes in a nested hierarchy
This function adds newly created symbols and scopes to the given parent scope and does not return anything
- make_using_scope(node: solidity_parser.ast.solnodes.UsingDirective)¶
- make_var_decl_scope(node: solidity_parser.ast.solnodes.VarDecl)¶
- make_scope(node: solidity_parser.ast.nodebase.Node, name=None)¶
- make_symbol(node: solidity_parser.ast.nodebase.Node, sym_type=Symbol, name=None)¶
- scope_name(base_name, node)¶
- find_using_target_scope_and_name(current_scope, target_type: solidity_parser.ast.types.Type)¶
- make_proxy_scope(scope_name, creator_scope, base_scope, library_scope=None)¶
- get_proxy_scope_for_type(cur_scope, target_type, target_scope_name, target_type_scope, library_scope=None, check_lib=True)¶
- get_using_function_symbol_for_func(target_type, target_type_scope, symbol, operator=None)¶
- process_using_any_type(context: Context, node: solidity_parser.ast.solnodes.UsingDirective)¶
- process_using_library_type(context: Context, node: solidity_parser.ast.solnodes.UsingDirective)¶
- find_using_current_scope(node, context)¶
- process_using_functions(node: solidity_parser.ast.solnodes.UsingDirective, context: Context)¶
- process_using_directive(node: solidity_parser.ast.solnodes.UsingDirective, context: Context)¶