Class: Woods::Ast::CallSiteExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/woods/ast/call_site_extractor.rb

Overview

Extracts call sites from an AST node tree.

Returns method calls found in the tree, ordered by source line number. Used by both RubyAnalyzer (call graph building) and FlowAssembler (execution flow ordering).

Examples:

Extracting calls from a method body

parser = Ast::Parser.new
root = parser.parse(source)
calls = Ast::CallSiteExtractor.new.extract(root)
calls.first #=> { receiver: "User", method_name: "find", arguments: ["id"], line: 3, block: false }

Instance Method Summary collapse

Instance Method Details

#extract(node) ⇒ Array<Hash>

Extract all call sites from an AST node, ordered by line number.

Parameters:

  • node (Ast::Node)

    The AST node to search

Returns:

  • (Array<Hash>)

    Call site hashes ordered by line ascending



50
51
52
53
54
# File 'lib/woods/ast/call_site_extractor.rb', line 50

def extract(node)
  calls = []
  collect_calls(node, calls)
  calls.sort_by { |c| c[:line] }
end

#extract_significant(node, known_units: []) ⇒ Array<Hash>

Extract only significant call sites, filtering out noise.

Parameters:

  • node (Ast::Node)

    The AST node to search

  • known_units (Array<String>) (defaults to: [])

    Known unit identifiers for relevance filtering

Returns:

  • (Array<Hash>)

    Filtered call site hashes



61
62
63
64
65
66
67
68
69
# File 'lib/woods/ast/call_site_extractor.rb', line 61

def extract_significant(node, known_units: [])
  calls = extract(node)
  known_set = Set.new(known_units)

  calls.reject do |call|
    INSIGNIFICANT_METHODS.include?(call[:method_name]) &&
      (known_units.empty? || !known_set.include?(call[:receiver]))
  end
end