Crate ink_analyzer_ir

Crate ink_analyzer_ir 

Source
Expand description

ink! intermediate representations (IRs) and abstractions for ink! analyzer.

§Example

Generate an IR of ink! smart contract code.

use ink_analyzer_ir::InkFile;

fn generate_ir() {
        let file = InkFile::parse(r#"
            #[ink::contract]
            mod my_contract {

                #[ink(storage)]
                pub struct MyContract {
                    value: bool,
                }

                // --snip--
            }
        "#);
        dbg!(&file);

        let contracts = file.contracts();
        dbg!(&contracts);

        if let Some(contract) = contracts.first() {
            let storage = contract.storage();
            dbg!(&storage);
        }
    }

Re-exports§

pub use ra_ap_syntax as syntax;

Modules§

ast
Re-export ra_ap_syntax::ast as ast. Abstract Syntax Tree, layered on top of untyped SyntaxNodes
meta
ink! attribute meta item IR.

Macros§

resolve_item_path_from_use_scope_and_aliases
Determines an item’s path based on use statements in the current scope.

Structs§

ChainExtension
An ink! chain extension.
Constructor
An ink! constructor.
Contract
An ink! contract.
ContractRef
An ink! contract ref.
EnvArg
An ink! environment argument.
Environment
A chain environment.
Error
An ink! error.
Event
An ink! event.
EventV2
An ink! event 2.0.
Extension
An ink! extension.
Function
An ink! function.
InkArg
An ink! attribute argument.
InkAttribute
An ink! specific attribute.
InkE2ETest
An ink! e2e test.
InkFile
An ink! file.
InkImpl
An ink! impl block.
InkTest
An ink! test.
InkTree
A wrapper for ink! entity tree navigation methods that return opaque iterator types.
ItemAtOffset
A wrapper for offset-based ink! entity tree traversal methods.
Message
An ink! message.
ScaleDerive
An ink! scale derive.
Selector
The selector of an ink! callable entity.
SelectorArg
An ink! selector argument.
Storage
An ink! storage definition.
StorageItem
An ink! storage item.
Topic
An ink! topic.
TraitDefinition
An ink! trait definition.

Enums§

InkArgKind
The ink! attribute argument kind.
InkArgValueKind
The ink! attribute argument value kind.
InkArgValuePathKind
The ink! attribute argument value path kind.
InkArgValueStringKind
The ink! attribute argument value string kind.
InkAttributeKind
The ink! attribute kind.
InkMacroKind
The ink! attribute macro kind.
MinorVersion
ink! language minor version.
SelectorArgKind
The ink! selector argument kind.
Version
ink! language version.

Traits§

HasInkEnvironment
Implemented by ink! entities that accept an Environment configuration (i.e. an ink! contract or ink! e2e test).
HasInkImplParent
Implemented by ink! entities whose valid AST parent item node is an impl item.
InkEntity
Generic representation of an ink! entity (e.g. Contract, Storage, Event, Constructor e.t.c).
IsChainExtensionFn
Convenience trait for unified handling by ink! entities that represent an associated function of a chain extension (i.e. an ink! extension for v4 or ink! function in v5).
IsInkCallable
Implemented by ink! entities that represent an ink! callable entity (i.e. an ink! constructor or ink! message).
IsInkEvent
Convenience trait for unified handling of both macro (i.e. #[ink::event] in v5) and argument (i.e. #[ink(event)]) based ink! events.
IsInkFn
Implemented by ink! entities whose valid AST node is an fn item.
IsInkStruct
Implemented by ink! entities whose valid AST node is a struct item.
IsInkTrait
Implemented by ink! entities whose valid AST node is a trait item.
IsIntId
Convenience trait for unified handling of ink! integer ids.
IsSyntax
Convenience abstraction for shared methods of syntax tree types (i.e. SyntaxToken, SyntaxNode and SyntaxElement).

Functions§

attrs
Returns attributes for the syntax node.
closest_ancestor_ast_type
Returns the closest AST ancestor of a specific type for the syntax “element”.
closest_item_which
Returns the closest non-trivia token based on the input predicates.
closest_non_trivia_token
Returns the closest non-trivia token based on the step expression.
ink_ancestors
Returns the syntax node’s ancestor ink! entities of IR type T.
ink_arg_by_kind
Returns ink! argument of a specific kind (if any) for the syntax node.
ink_args
Returns ink! arguments of the syntax node.
ink_args_by_kind
Returns ink! arguments of a specific kind (if any) for the syntax node.
ink_attr_to_entity
Converts an ink attribute to an ink! entity (if possible).
ink_attrs
Returns ink! attributes for the syntax node.
ink_attrs_ancestors
Returns ink! attributes for all the syntax node’s ancestors.
ink_attrs_closest_ancestors
Returns ink! attributes for all the syntax node’s ancestors that don’t have any ink! descendant between them and the current node.
ink_attrs_closest_descendants
Returns ink! attributes for all the syntax node’s descendants that don’t have any ink! ancestor between them and the current node.
ink_attrs_descendants
Returns ink! attributes for all the syntax node’s descendants.
ink_attrs_in_scope
Returns ink! attributes in the syntax node’s scope. This includes both the nodes own ink! attributes and those of all of it’s descendants.
ink_callable_closest_descendants
Returns the syntax node’s descendant ink! entities of IR type T that either don’t have any ink! ancestor or only have an ink! impl entity between them and the current node.
ink_closest_ancestors
Returns the syntax node’s ancestor ink! entities of IR type T that don’t have any ink! descendant between them and the current node.
ink_closest_descendants
Returns the syntax node’s descendant ink! entities of IR type T that don’t have any ink! ancestor between them and the current node.
ink_descendants
Returns the syntax node’s descendant ink! entities of IR type T.
ink_impl_closest_descendants
Returns the syntax node’s descendant ink! impl items that don’t have any ink! ancestor between them and the current node.
ink_parent
Returns the syntax node’s parent ink! entity of IR type T (if any).
ink_peekable_quasi_closest_descendants
Returns the syntax node’s descendant ink! entities of IR type T that either don’t have any ink! ancestor or only have ink! entities that satisfy a “peekable” predicate between them and the current node.
parent_ast_item
Returns parent AST Item for the syntax “element”.
path_from_str
Converts a string to a path (if possible).
path_from_type
Converts a type to a path (if possible).
path_to_string
Converts a path to a string.
resolve_current_module
Resolves current module (defaults to the file root if there’s no mod item).
resolve_item
Returns the AST item referenced by the path (if any).
resolve_qualifier
Resolves qualifier root/module (if it exists).
simple_use_paths_and_aliases_in_scope
Returns all use paths and aliases in the current scope as flattened simple paths.