From 2113e8c0558c2476fad9136667b9a96981e2599f Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Mon, 28 Nov 2022 04:19:34 +0100 Subject: [PATCH] Refactor `MacroReferenceFinder` class a bit --- src/ameba/ast/variabling/variable.cr | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ameba/ast/variabling/variable.cr b/src/ameba/ast/variabling/variable.cr index 3b1987d6..b27648b0 100644 --- a/src/ameba/ast/variabling/variable.cr +++ b/src/ameba/ast/variabling/variable.cr @@ -175,28 +175,32 @@ module Ameba::AST node.accept self end + # @[AlwaysInline] + private def includes_reference?(val) + val.to_s.includes?(@reference) + end + def visit(node : Crystal::ASTNode) true end def visit(node : Crystal::MacroLiteral) - !(self.references ||= node.value.includes?(@reference)) + !(@references ||= includes_reference?(node.value)) end def visit(node : Crystal::MacroExpression) - !(self.references ||= node.exp.to_s.includes?(@reference)) + !(@references ||= includes_reference?(node.exp)) end def visit(node : Crystal::MacroFor) - exp, body = node.exp, node.body - !(self.references ||= exp.to_s.includes?(@reference) || - body.to_s.includes?(@reference)) + !(@references ||= includes_reference?(node.exp) || + includes_reference?(node.body)) end def visit(node : Crystal::MacroIf) - !(self.references ||= node.cond.to_s.includes?(@reference) || - node.then.to_s.includes?(@reference) || - node.else.to_s.includes?(@reference)) + !(@references ||= includes_reference?(node.cond) || + includes_reference?(node.then) || + includes_reference?(node.else)) end end