ink-analyzer-ir 0.4.0

Intermediate representations (IRs) and abstractions of ink! smart contract code for ink! analyzer.
Documentation

ink! Analyzer IR

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

This library implements types and utilities for parsing ink! smart contract code into ink! intermediate representations (IRs) and abstractions.

It uses rust-analyzer's ra_ap_syntax crate for generating the syntax tree of the ink! smart contract code that it then converts into ink! entity intermediate representations and abstractions.

It's the main dependency for the semantic analyzer crate.

Installation

Run the following Cargo command in your project directory

cargo add ink-analyzer-ir

Usage

Example:

Generate an IR of ink! smart contract code.

use ink_analyzer_ir::{InkFile, quote_as_str};

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

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

            #[ink(event)]
            pub struct MyEvent {
                #[ink(topic)]
                value: bool,
            }

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

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

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

Documentation

https://docs.rs/ink-analyzer-ir/latest/ink_analyzer_ir/

Or you can access documentation locally by running the following command from the project root

cargo doc -p ink-analyzer-ir --open

Testing

You can run unit tests for all the core functionality by running the following command from the project root

cargo test -p ink-analyzer-ir

License

This code is released under both MIT and Apache-2.0 licenses.