Provides access to AST elements using their unique IDs.

The generated AST entries includes all the dependent elements, including imported code which is included in the project AST in C/C++ style.

Constructors

  • Constructs a AstStore with mappings to all major AST components accessible by their unique AST identifiers.

    Parameters

    • stdlibIds: Set<number> = ...

      Identifiers of AST elements defined in stdlib.

    • contractEntries: Map<number, Set<number>> = ...

      Items defined within contracts and traits.

    • programEntries: Map<string, Set<number>>

      Identifiers of AST elements defined on the top-level of each file.

    • functionNames: Map<number, FunctionName>

      Unique names for each function definition.

    • functions: Map<number, AstStoreFunction>

      Functions and methods including user-defined and special methods.

    • constants: Map<number, AstConstantDef>

      Constants defined across the compilation unit.

    • contracts: Map<number, AstContract>

      Contracts defined within the project.

    • nativeFunctions: Map<number, AstNativeFunctionDecl>

      Functions defined natively (not in user's source code).

    • asmFunctions: Map<number, AstAsmFunctionDef>

      Tact asm functions.

    • primitives: Map<number, AstPrimitiveTypeDecl>

      Primitive types defined in the project.

    • structs: Map<number, AstStructDecl>

      Structs defined in the project.

    • messages: Map<number, AstMessageDecl>

      Messages defined in the project.

    • traits: Map<number, AstTrait>

      Traits defined in the project.

    • statements: Map<number, AstStatement>

      All executable statements within all functions of the project.

    Returns AstStore

Methods

  • Returns all the constants defined within the program, including top-level constants and contract constants.

    Parameters

    • params: Partial<{
          filename?: string;
          includeStdlib: boolean;
      }> & {
          includeContract?: boolean;
      } = {}

      Additional parameters:

      • includeContract: If true, includes constants defined within a contract.

    Returns IterableIterator<AstConstantDef, any, any>

  • Retrieves the IDs of constants associated with a specified contract.

    Parameters

    • contractId: number

      The ID of the contract.

    Returns undefined | number[]

    An array of constant IDs or undefined if no contract is found.

  • Retrieves fields defined within a specified contract.

    Parameters

    • contractId: number

      The ID of the contract.

    Returns undefined | AstFieldDecl[]

    An array of AstFieldDecl or undefined if no contract is found.

  • Returns all the functions and methods defined within the program.

    Parameters

    • params: Partial<{
          filename?: string;
          includeStdlib: boolean;
      }> = {}

    Returns IterableIterator<AstStoreFunction, any, any>

  • Retrieves fields defined in the traits the contract inherited.

    Parameters

    • contractId: number

      The ID of the contract.

    Returns undefined | AstFieldDecl[]

    An array of AstFieldDecl or undefined if no contract or one its trait are found.

  • Retrieves the ID of the initialization function for a specified contract.

    Parameters

    • contractId: number

      The ID of the contract.

    Returns undefined | number

    The ID of the init function or undefined if the contract does not exist.

  • Returns all the items defined within the program.

    Type Parameters

    • T extends {
          id: number;
          loc: SrcInfo;
      }

    Parameters

    • items: Map<number, T>

      The collection of items (functions or constants).

    • params: Partial<{
          filename?: string;
          includeStdlib: boolean;
      }> = {}

      Additional parameters:

      • includeStdlib: If true, includes items defined in stdlib.
      • filename: Filters out nodes defined in the given file.

    Returns IterableIterator<T, any, any>

    An iterator for the items.

  • Retrieves items of specified kinds defined within a given file.

    Parameters

    • kinds: (
          | "string"
          | "number"
          | "boolean"
          | "slice"
          | "op_binary"
          | "op_unary"
          | "conditional"
          | "method_call"
          | "field_access"
          | "static_call"
          | "struct_instance"
          | "id"
          | "init_of"
          | "code_of"
          | "null"
          | "address"
          | "cell"
          | "struct_value"
          | "statement_let"
          | "statement_return"
          | "statement_expression"
          | "statement_assign"
          | "statement_augmentedassign"
          | "statement_condition"
          | "statement_while"
          | "statement_until"
          | "statement_repeat"
          | "statement_try"
          | "statement_foreach"
          | "statement_destruct"
          | "statement_block"
          | "func_id"
          | "wildcard"
          | "destruct_mapping"
          | "destruct_end"
          | "primitive_type_decl"
          | "struct_decl"
          | "message_decl"
          | "contract"
          | "trait"
          | "field_decl"
          | "typed_parameter"
          | "function_def"
          | "function_attribute"
          | "asm_function_def"
          | "function_decl"
          | "module"
          | "native_function_decl"
          | "struct_field_initializer"
          | "struct_field_value"
          | "type_id"
          | "optional_type"
          | "map_type"
          | "bounced_message_type"
          | "contract_init"
          | "receiver"
          | "import"
          | "constant_def"
          | "constant_decl"
          | "internal"
          | "external"
          | "bounce"
          | "simple"
          | "fallback"
          | "comment")[]

      An array of kinds to filter the items.

    • params: Partial<{
          filename?: string;
          includeStdlib: boolean;
      }> & {
          filename: string;
      }

      Additional parameters:

      • includeStdlib: If true, includes items defined in stdlib.
      • filename: The filename to filter items by (required).

    Returns (
        | FuncId
        | Wildcard
        | DestructMapping
        | DestructEnd
        | AstExpression
        | AstStatement
        | AstTypeDecl
        | AstFieldDecl
        | AstTypedParameter
        | AstFunctionDef
        | FunctionAttribute
        | AstAsmFunctionDef
        | AstFunctionDecl
        | AstNativeFunctionDecl
        | AstStructFieldInitializer
        | StructFieldValue
        | AstType
        | AstContractInit
        | AstReceiver
        | AstImport
        | AstConstantDef
        | AstConstantDecl
        | ReceiverKind
        | ReceiverSubKind)[]

    An array of matching AstNode items.

  • Retrieves return types from the callable methods defined in the given contract/trait.

    Parameters

    • entryId: number

      AST identifier of the contract or trait to analyze.

    • withTraits: boolean = true

      Include methods from directly or indirectly inherited traits.

    • visited: Set<number> = ...

    Returns Map<FunctionName, undefined | AstType>

  • Retrieves the IDs of methods for a specified contract which have one of the following types: AstFunctionDef, AstReceiver, AstContractInit.

    Parameters

    • contractId: number

      The ID of the contract.

    Returns undefined | number[]

    An array of method IDs or undefined if no contract is found.