Provides access to AST elements defined within a single Tact project.

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 TactASTStore 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.

    • functions: Map<number, AstFunctionDef | AstContractInit | AstReceiver>

      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 TactASTStore

Methods

  • Retrieves an asm function by its ID.

    Parameters

    • id: number

      The unique identifier of the asm function.

    Returns undefined | AstAsmFunctionDef

    The asm function if found, otherwise undefined.

  • Parameters

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

    Returns IterableIterator<AstAsmFunctionDef>

  • Retrieves a constant by its ID.

    Parameters

    • id: number

      The unique identifier of the constant.

    Returns undefined | AstConstantDef

    The constant if found, otherwise undefined.

  • 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>

  • Retrieves a contract by its ID.

    Parameters

    • id: number

      The unique identifier of the contract.

    Returns undefined | AstContract

    The contract if found, otherwise undefined.

  • 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.

  • Parameters

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

    Returns IterableIterator<AstContract>

  • Retrieves a function or method by its ID.

    Parameters

    • id: number

      The unique identifier of the function or method.

    Returns
        | undefined
        | AstFunctionDef
        | AstContractInit
        | AstReceiver

    The function or method if found, otherwise undefined.

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

    Parameters

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

    Returns IterableIterator<AstFunctionDef | AstContractInit | AstReceiver>

  • 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>

    An iterator for the items.

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

    Parameters

    • kinds: (
          | "string"
          | "number"
          | "boolean"
          | "op_binary"
          | "op_unary"
          | "field_access"
          | "id"
          | "method_call"
          | "static_call"
          | "struct_instance"
          | "null"
          | "init_of"
          | "conditional"
          | "statement_let"
          | "statement_return"
          | "statement_expression"
          | "statement_assign"
          | "statement_augmentedassign"
          | "statement_condition"
          | "statement_while"
          | "statement_until"
          | "statement_repeat"
          | "statement_try"
          | "statement_try_catch"
          | "statement_foreach"
          | "func_id"
          | "primitive_type_decl"
          | "struct_decl"
          | "message_decl"
          | "contract"
          | "trait"
          | "field_decl"
          | "typed_parameter"
          | "function_def"
          | "asm_function_def"
          | "function_decl"
          | "module"
          | "native_function_decl"
          | "struct_field_initializer"
          | "type_id"
          | "optional_type"
          | "map_type"
          | "bounced_message_type"
          | "contract_init"
          | "receiver"
          | "import"
          | "constant_def"
          | "constant_decl")[]

      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 (
        | AstFuncId
        | AstExpression
        | AstStatement
        | AstTypeDecl
        | AstFieldDecl
        | AstTypedParameter
        | AstFunctionDef
        | AstAsmFunctionDef
        | AstFunctionDecl
        | AstNativeFunctionDecl
        | AstStructFieldInitializer
        | AstType
        | AstContractInit
        | AstReceiver
        | AstImport
        | AstConstantDef
        | AstConstantDecl)[]

    An array of matching AstNode items.

  • Retrieves a message by its ID.

    Parameters

    • id: number

      The unique identifier of the message.

    Returns undefined | AstMessageDecl

    The message if found, otherwise undefined.

  • Parameters

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

    Returns IterableIterator<AstMessageDecl>

  • 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, null | 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.

  • Retrieves a native function by its ID.

    Parameters

    • id: number

      The unique identifier of the native function.

    Returns undefined | AstNativeFunctionDecl

    The native function if found, otherwise undefined.

  • Parameters

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

    Returns IterableIterator<AstNativeFunctionDecl>

  • Retrieves a primitive type by its ID.

    Parameters

    • id: number

      The unique identifier of the primitive type.

    Returns undefined | AstPrimitiveTypeDecl

    The primitive type if found, otherwise undefined.

  • Parameters

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

    Returns IterableIterator<AstPrimitiveTypeDecl>

  • Returns top-level program entries in order as they defined in each file.

    Parameters

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

    Returns (
        | AstFuncId
        | AstExpression
        | AstStatement
        | AstTypeDecl
        | AstFieldDecl
        | AstTypedParameter
        | AstFunctionDef
        | AstAsmFunctionDef
        | AstFunctionDecl
        | AstNativeFunctionDecl
        | AstStructFieldInitializer
        | AstType
        | AstContractInit
        | AstReceiver
        | AstImport
        | AstConstantDef
        | AstConstantDecl)[]

  • Retrieves a statement by its ID.

    Parameters

    • id: number

      The unique identifier of the statement.

    Returns undefined | AstStatement

    The statement if found, otherwise undefined.

  • Returns all the statements defined within the program.

    Returns IterableIterator<AstStatement>

  • Retrieves a struct by its ID.

    Parameters

    • id: number

      The unique identifier of the struct.

    Returns undefined | AstStructDecl

    The struct if found, otherwise undefined.

  • Parameters

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

    Returns IterableIterator<AstStructDecl>

  • Retrieves a trait by its ID.

    Parameters

    • id: number

      The unique identifier of the trait.

    Returns undefined | AstTrait

    The trait if found, otherwise undefined.

  • Parameters

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

    Returns IterableIterator<AstTrait>