Juggernaut.Mutator.ModuleScan (Juggernaut v0.4.0)

Copy Markdown View Source

Finds the modules of a parsed file and what the walk needs to know about each one: its aliases, imports, local functions, whether it is a GenServer, its function clauses in source order, the module-body expressions that run at compile time, and its context: every module-body expression other than a function clause, a nested module or a documentation attribute (what a function's behaviour may depend on besides its own clauses: use, import, alias, attributes, defstruct), which Juggernaut.Cache.Footprint hashes with each function.

A nested defmodule is a module of its own, named inside its parent. defimpl is named Protocol.Target. Clause indices count every def, defp, defmacro and defmacrop of one name and arity in source order, bodiless heads included (design notes §6).

Summary

Functions

The name and arguments of a clause head (f(a), f(a) when g), or :error.

The modules defined in ast, outermost first, in source order.

Types

clause()

@type clause() :: %{
  module: module(),
  kind: atom(),
  name: atom(),
  arity: arity(),
  index: non_neg_integer(),
  node: Macro.t(),
  impl?: boolean(),
  bodiless?: boolean(),
  first_line: pos_integer(),
  last_line: pos_integer()
}

info()

@type info() :: %{
  module: module(),
  aliases: %{required([atom()]) => module()},
  imports: [module()],
  locals: MapSet.t({atom(), arity()}),
  genserver?: boolean(),
  clauses: [clause()],
  compile_time: [Macro.t()],
  context: [Macro.t()]
}

Functions

head_call(arg1)

@spec head_call(Macro.t()) :: {:ok, atom(), [Macro.t()]} | :error

The name and arguments of a clause head (f(a), f(a) when g), or :error.

modules(ast)

@spec modules(Macro.t()) :: [info()]

The modules defined in ast, outermost first, in source order.