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§

Modules§

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

Macros§

Structs§

Enums§

Traits§

  • Implemented by ink! entities that accept an Environment configuration (i.e. an ink! contract or ink! e2e test).
  • Implemented by ink! entities whose valid AST parent item node is an impl item.
  • Generic representation of an ink! entity (e.g. Contract, Storage, Event, Constructor e.t.c).
  • 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).
  • Implemented by ink! entities that represent an ink! callable entity (i.e. an ink! constructor or ink! message).
  • Convenience trait for unified handling of both macro (i.e. #[ink::event] in v5) and argument (i.e. #[ink(event)]) based ink! events.
  • Implemented by ink! entities whose valid AST node is an fn item.
  • Implemented by ink! entities whose valid AST node is a struct item.
  • Implemented by ink! entities whose valid AST node is a trait item.
  • Convenience trait for unified handling of ink! integer ids.
  • Convenience abstraction for shared methods of syntax tree types (i.e. SyntaxToken, SyntaxNode and SyntaxElement).

Functions§

  • Returns attributes for the syntax node.
  • Returns the closest AST ancestor of a specific type for the syntax “element”.
  • Returns the closest non-trivia token based on the input predicates.
  • Returns the closest non-trivia token based on the step expression.
  • Returns the syntax node’s ancestor ink! entities of IR type T.
  • Returns ink! argument of a specific kind (if any) for the syntax node.
  • Returns ink! arguments of the syntax node.
  • Returns ink! arguments of a specific kind (if any) for the syntax node.
  • Converts an ink attribute to an ink! entity (if possible).
  • Returns ink! attributes for the syntax node.
  • Returns ink! attributes for all the syntax node’s ancestors.
  • Returns ink! attributes for all the syntax node’s ancestors that don’t have any ink! descendant between them and the current node.
  • Returns ink! attributes for all the syntax node’s descendants that don’t have any ink! ancestor between them and the current node.
  • Returns ink! attributes for all the syntax node’s descendants.
  • 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.
  • 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.
  • 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.
  • 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.
  • Returns the syntax node’s descendant ink! entities of IR type T.
  • Returns the syntax node’s descendant ink! impl items that don’t have any ink! ancestor between them and the current node.
  • Returns the syntax node’s parent ink! entity of IR type T (if any).
  • 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.
  • Returns parent AST Item for the syntax “element”.
  • Converts a string to a path (if possible).
  • Converts a type to a path (if possible).
  • Converts a path to a string.
  • Resolves current module (defaults to the file root if there’s no mod item).
  • Returns the AST item referenced by the path (if any).
  • Resolves qualifier root/module (if it exists).
  • Returns all use paths and aliases in the current scope as flattened simple paths.