46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/normalize_ast.rb', line 46
def rewrite_ast(ast)
if ast.is_a? AST::Node
type = ast.type
case type
when :lvar, :ivar, :gvar
update_complexity(:var, ast.children.first)
ast.updated(nil, ast.children.map { |child| @track.rename(:var, child) })
when :lvasgn, :gvasgn, :ivasgn, :cvasgn
update_complexity(:assignment, ast.children.first)
ast.updated(nil, ast.children.map.with_index { |child,i|
i == 0 ? @track.rename(:var,child) : rewrite_ast(child)
})
when :int, :float, :str, :sym, :arg, :restarg, :blockarg
update_complexity(type, ast.children.first)
ast.updated(nil, ast.children.map { |child| @track.rename(type, child) })
when :optarg
update_complexity(:arg, ast.children.first)
ast.updated(nil, ast.children.map.with_index { |child,i|
if i == 0
@track.rename(:var, child)
else
rewrite_ast(child)
end
})
when :def
update_complexity(:def, ast.children.first)
ast.updated(nil, ast.children.map.with_index { |child,i|
i == 0 ? :method : rewrite_ast(child)
})
when :defs
update_complexity(:def, ast.children.first)
ast.updated(nil, ast.children.map.with_index { |child,i|
i == 1 ? :method : rewrite_ast(child)
})
when :send
update_complexity(:send, ast.children[1])
ast.updated(nil, ast.children.map { |child| rewrite_ast(child) })
else
ast.updated(nil, ast.children.map { |child| rewrite_ast(child) })
end
else
ast
end
end
|