Refactor MacroReferenceFinder class a bit

This commit is contained in:
Sijawusz Pur Rahnama 2022-11-28 04:19:34 +01:00
parent a8f953a2b2
commit 2113e8c055

View file

@ -175,28 +175,32 @@ module Ameba::AST
node.accept self node.accept self
end end
# @[AlwaysInline]
private def includes_reference?(val)
val.to_s.includes?(@reference)
end
def visit(node : Crystal::ASTNode) def visit(node : Crystal::ASTNode)
true true
end end
def visit(node : Crystal::MacroLiteral) def visit(node : Crystal::MacroLiteral)
!(self.references ||= node.value.includes?(@reference)) !(@references ||= includes_reference?(node.value))
end end
def visit(node : Crystal::MacroExpression) def visit(node : Crystal::MacroExpression)
!(self.references ||= node.exp.to_s.includes?(@reference)) !(@references ||= includes_reference?(node.exp))
end end
def visit(node : Crystal::MacroFor) def visit(node : Crystal::MacroFor)
exp, body = node.exp, node.body !(@references ||= includes_reference?(node.exp) ||
!(self.references ||= exp.to_s.includes?(@reference) || includes_reference?(node.body))
body.to_s.includes?(@reference))
end end
def visit(node : Crystal::MacroIf) def visit(node : Crystal::MacroIf)
!(self.references ||= node.cond.to_s.includes?(@reference) || !(@references ||= includes_reference?(node.cond) ||
node.then.to_s.includes?(@reference) || includes_reference?(node.then) ||
node.else.to_s.includes?(@reference)) includes_reference?(node.else))
end end
end end