mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Misc refactors
This commit is contained in:
		
							parent
							
								
									ffd63ef028
								
							
						
					
					
						commit
						8b43a40a65
					
				
					 4 changed files with 7 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -37,7 +37,7 @@ module Ameba::AST
 | 
			
		|||
 | 
			
		||||
    # Returns true if this node or one of the parent branchables is a loop, false otherwise.
 | 
			
		||||
    def loop?
 | 
			
		||||
      loop?(node) || parent.try(&.loop?) || false
 | 
			
		||||
      loop?(node) || !!parent.try(&.loop?)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,6 +30,7 @@ module Ameba::AST
 | 
			
		|||
    # ```
 | 
			
		||||
    def initialize(@node, @variable, @scope)
 | 
			
		||||
      return unless scope = @variable.scope
 | 
			
		||||
 | 
			
		||||
      @branch = Branch.of(@node, scope)
 | 
			
		||||
      @referenced = true if @variable.special? ||
 | 
			
		||||
                            @variable.scope.type_definition? ||
 | 
			
		||||
| 
						 | 
				
			
			@ -37,7 +38,7 @@ module Ameba::AST
 | 
			
		|||
    end
 | 
			
		||||
 | 
			
		||||
    def referenced_in_loop?
 | 
			
		||||
      @variable.referenced? && @branch.try &.in_loop?
 | 
			
		||||
      @variable.referenced? && !!@branch.try(&.in_loop?)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # Returns true if this assignment is an op assign, false if not.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -161,7 +161,7 @@ module Ameba::AST
 | 
			
		|||
    def declared_before?(node)
 | 
			
		||||
      var_location, node_location = location, node.location
 | 
			
		||||
 | 
			
		||||
      return if var_location.nil? || node_location.nil?
 | 
			
		||||
      return unless var_location && node_location
 | 
			
		||||
 | 
			
		||||
      (var_location.line_number < node_location.line_number) ||
 | 
			
		||||
        (var_location.line_number == node_location.line_number &&
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@ module Ameba::AST
 | 
			
		|||
  class CountingVisitor < Crystal::Visitor
 | 
			
		||||
    DEFAULT_COMPLEXITY = 1
 | 
			
		||||
 | 
			
		||||
    getter macro_condition = false
 | 
			
		||||
    getter? macro_condition = false
 | 
			
		||||
 | 
			
		||||
    # Creates a new counting visitor
 | 
			
		||||
    def initialize(@scope : Crystal::ASTNode)
 | 
			
		||||
| 
						 | 
				
			
			@ -27,13 +27,13 @@ module Ameba::AST
 | 
			
		|||
    {% for node in %i(if while until rescue or and) %}
 | 
			
		||||
      # :nodoc:
 | 
			
		||||
      def visit(node : Crystal::{{ node.id.capitalize }})
 | 
			
		||||
        @complexity += 1 unless macro_condition
 | 
			
		||||
        @complexity += 1 unless macro_condition?
 | 
			
		||||
      end
 | 
			
		||||
    {% end %}
 | 
			
		||||
 | 
			
		||||
    # :nodoc:
 | 
			
		||||
    def visit(node : Crystal::Case)
 | 
			
		||||
      return true if macro_condition
 | 
			
		||||
      return true if macro_condition?
 | 
			
		||||
 | 
			
		||||
      # Count the complexity of an exhaustive `Case` as 1
 | 
			
		||||
      # Otherwise count the number of `When`s
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue