• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nshkrdotcom / ElixirScope / 54fc5911e9000f1ebc4a810340870a7b2a41e5f6

29 May 2025 01:33AM UTC coverage: 60.215% (-0.009%) from 60.224%
54fc5911e9000f1ebc4a810340870a7b2a41e5f6

push

github

NSHkr
refactor cfg

351 of 544 new or added lines in 10 files covered. (64.52%)

9 existing lines in 3 files now uncovered.

5703 of 9471 relevant lines covered (60.22%)

3704.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

43.59
/lib/elixir_scope/ast_repository/enhanced/cfg_generator/ast_processor.ex
1
defmodule ElixirScope.ASTRepository.Enhanced.CFGGenerator.ASTProcessor do
2
  @moduledoc """
3
  Processes AST nodes to build the Control Flow Graph by dispatching to specialized handlers.
4
  """
5

6
  alias ElixirScope.ASTRepository.Enhanced.{
7
    # CFGNode, # No longer directly creating nodes here
8
    # CFGEdge, # No longer directly creating edges here
9
    # ScopeInfo, # No longer directly creating scopes here
10
    CFGGenerator.Utils,
11
    CFGGenerator.NodeBuilder,
12
    CFGGenerator.ConditionalHandler,
13
    CFGGenerator.ExceptionHandler,
14
    CFGGenerator.SequentialHandler,
15
    CFGGenerator.BinaryOperatorHandler
16
  }
17

18
  # Public API
19
  def process_ast_node(ast, state) do
20
    # The main AST node processor - delegates to specialized handlers
21
    # or NodeBuilder for simpler constructs.
22
    # The `ast_processor_func` argument for handlers is `&process_ast_node/2` itself.
23

24
    case ast do
6,976✔
25
      # --- Sequential Handlers ---
26
      {:__block__, meta, statements} ->
27
        SequentialHandler.handle_statement_sequence(statements, meta, state, &process_ast_node/2)
100✔
28

29
      {:=, meta, [pattern, expression]} ->
30
        SequentialHandler.handle_assignment(pattern, expression, meta, state, &process_ast_node/2)
200✔
31

32
      {:|>, meta, [left, right]} ->
33
        SequentialHandler.handle_pipe_operation(left, right, meta, state, &process_ast_node/2)
1,202✔
34
        
35
      # --- Conditional Handlers ---
36
      {:case, meta, [condition, [do: clauses]]} ->
37
        ConditionalHandler.handle_case_statement(condition, clauses, meta, state, &process_ast_node/2)
219✔
38

39
      {:if, meta, [condition, clauses]} when is_list(clauses) ->
40
        then_branch = Keyword.get(clauses, :do)
175✔
41
        else_clause = case Keyword.get(clauses, :else) do
175✔
NEW
42
          nil -> []
×
43
          else_branch -> [else: else_branch]
175✔
44
        end
45
        ConditionalHandler.handle_if_statement(condition, then_branch, else_clause, meta, state, &process_ast_node/2)
175✔
46

47
      {:unless, meta, [condition, clauses]} when is_list(clauses) ->
NEW
48
        ConditionalHandler.handle_unless_statement(condition, clauses, meta, state, &process_ast_node/2)
×
49

50
      {:cond, meta, [[do: clauses]]} -> # Note: [[do: clauses]] pattern from original
NEW
51
        ConditionalHandler.handle_cond_statement(clauses, meta, state, &process_ast_node/2)
×
52

53
      # --- Exception Handlers ---
54
      {:try, meta, blocks} ->
55
        ExceptionHandler.handle_try_statement(blocks, meta, state, &process_ast_node/2)
202✔
56

57
      {:with, meta, clauses} ->
58
        ExceptionHandler.handle_with_statement(clauses, meta, state, &process_ast_node/2)
1✔
59

60
      # --- Binary Operation Handler ---
61
      {op, meta, [left, right]} when op in [:+, :-, :*, :/, :==, :!=, :<, :>, :<=, :>=, :and, :or, :&&, :||] ->
62
        BinaryOperatorHandler.handle_binary_operation(op, left, right, meta, state, &process_ast_node/2)
431✔
63

64
      # --- NodeBuilder Delegations (Simpler Constructs) ---
65
      {:for, meta, clauses} ->
66
        NodeBuilder.build_comprehension_node(clauses, meta, state)
4✔
67

68
      {{:., meta1, [module, func_name]}, meta2, args} ->
69
        NodeBuilder.build_module_function_call_node(module, func_name, args, meta1, meta2, state)
1,416✔
70

71
      {func_name, meta, args} when is_atom(func_name) ->
72
        NodeBuilder.build_function_call_node(func_name, args, meta, state)
1,464✔
73

74
      {:when, meta, [expr, guard]} ->
NEW
75
        NodeBuilder.build_when_guard_node(expr, guard, meta, state)
×
76

77
      {:fn, meta, clauses} ->
NEW
78
        NodeBuilder.build_anonymous_function_node(clauses, meta, state)
×
79

80
      {:raise, meta, args} ->
NEW
81
        NodeBuilder.build_raise_node(args, meta, state)
×
82

83
      {:throw, meta, [value]} ->
NEW
84
        NodeBuilder.build_throw_node(value, meta, state)
×
85

86
      {:exit, meta, [reason]} ->
NEW
87
        NodeBuilder.build_exit_node(reason, meta, state)
×
88

89
      {:spawn, meta, args} ->
NEW
90
        NodeBuilder.build_spawn_node(args, meta, state)
×
91

92
      {:send, meta, [pid, message]} ->
NEW
93
        NodeBuilder.build_send_node(pid, message, meta, state)
×
94

95
      {op, meta, [operand]} when op in [:not, :!, :+, :-] ->
NEW
96
        NodeBuilder.build_unary_operation_node(op, operand, meta, state)
×
97

98
      {var_name, meta, nil} when is_atom(var_name) ->
NEW
99
        NodeBuilder.build_variable_reference_node(var_name, meta, state)
×
100

101
      literal when is_atom(literal) or is_number(literal) or is_binary(literal) or is_list(literal) ->
102
        NodeBuilder.build_literal_node(literal, state)
1,527✔
103

104
      nil ->
NEW
105
        {%{}, [], [], %{}, state} # Empty function body
×
106

107
      {:{}, meta, elements} ->
NEW
108
        NodeBuilder.build_tuple_node(elements, meta, state)
×
109

110
      list when is_list(list) ->
NEW
111
        NodeBuilder.build_list_node(list, state)
×
112

113
      {:%{}, meta, pairs} ->
NEW
114
        NodeBuilder.build_map_node(pairs, meta, state)
×
115

116
      {:%{}, meta, [map | updates]} ->
NEW
117
        NodeBuilder.build_map_update_node(map, updates, meta, state)
×
118

119
      {:%, meta, [struct_name, fields]} ->
NEW
120
        NodeBuilder.build_struct_node(struct_name, fields, meta, state)
×
121

122
      {{:., meta1, [Access, :get]}, meta2, [container, key]} ->
NEW
123
        NodeBuilder.build_access_node(container, key, meta1, meta2, state)
×
124

125
      {:@, meta, [attr]} ->
NEW
126
        NodeBuilder.build_attribute_access_node(attr, meta, state)
×
127
        
128
      # --- Receive Statement (Remains here as placeholder) ---
129
      {:receive, meta, clauses} ->
NEW
130
        process_receive_statement(clauses, meta, state)
×
131

132
      # --- Fallback (NodeBuilder) ---
133
      _ ->
134
        NodeBuilder.build_simple_expression_node(ast, state)
35✔
135
    end
136
  end
137

138
  # Placeholder for receive, as it was not fully implemented and not moved.
139
  # If this needs full processing, it could also be moved to a specialized handler.
NEW
140
  defp process_receive_statement(_clauses, _meta, state), do: {%{}, [], [], %{}, state}
×
141

142
  # Note: process_comprehension and analyze_comprehension_clauses were removed earlier when NodeBuilder was created.
143
  # process_unless_statement was moved to ConditionalHandler (and renamed handle_unless_statement there).
144
  # All other process_... functions for specific AST types have been moved to their respective handlers or NodeBuilder.
145
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc