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::astasast. Abstract Syntax Tree, layered on top of untypedSyntaxNodes - 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§
- Chain
Extension - An ink! chain extension.
- Constructor
- An ink! constructor.
- Contract
- An ink! contract.
- Contract
Ref - 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.
- InkE2E
Test - 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.
- Item
AtOffset - A wrapper for offset-based ink! entity tree traversal methods.
- Message
- An ink! message.
- Scale
Derive - An ink! scale derive.
- Selector
- The selector of an ink! callable entity.
- Selector
Arg - An ink! selector argument.
- Storage
- An ink! storage definition.
- Storage
Item - An ink! storage item.
- Topic
- An ink! topic.
- Trait
Definition - An ink! trait definition.
Enums§
- InkArg
Kind - The ink! attribute argument kind.
- InkArg
Value Kind - The ink! attribute argument value kind.
- InkArg
Value Path Kind - The ink! attribute argument value path kind.
- InkArg
Value String Kind - The ink! attribute argument value string kind.
- InkAttribute
Kind - The ink! attribute kind.
- InkMacro
Kind - The ink! attribute macro kind.
- Minor
Version - ink! language minor version.
- Selector
ArgKind - The ink! selector argument kind.
- Version
- ink! language version.
Traits§
- HasInk
Environment - Implemented by ink! entities that accept an
Environmentconfiguration (i.e. an ink! contract or ink! e2e test). - HasInk
Impl Parent - Implemented by ink! entities whose valid AST parent item node is an
implitem. - InkEntity
- Generic representation of an ink! entity (e.g. Contract, Storage, Event, Constructor e.t.c).
- IsChain
Extension Fn - 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).
- IsInk
Callable - Implemented by ink! entities that represent an ink! callable entity (i.e. an ink! constructor or ink! message).
- IsInk
Event - 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
fnitem. - IsInk
Struct - Implemented by ink! entities whose valid AST node is a
structitem. - IsInk
Trait - Implemented by ink! entities whose valid AST node is a
traititem. - 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
Tthat 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
Tthat 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
Tthat 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
Tthat 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
moditem). - 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.