class TypeProf::Core::AST::StatementsNode - typeprof: Ruby Standard Library Documentation

# class TypeProf::Core::AST::StatementsNode

### Attributes

stmts[R]

### Public Class Methods

new(raw_node, lenv, use_result) click to toggle source
Calls superclass method `TypeProf::Core::AST::Node::new`

    # File typeprof-0.30.1/lib/typeprof/core/ast/misc.rb, line 4
    def initialize(raw_node, lenv, use_result)
      super(raw_node, lenv)
      stmts = raw_node.body
      @stmts = stmts.map.with_index do |n, i|
        if n
          AST.create_node(n, lenv, i == stmts.length - 1 ? use_result : false)
        else
          last = code_range.last
          DummyNilNode.new(TypeProf::CodeRange.new(last, last), lenv)
        end
      end
    end

### Public Instance Methods

diff(prev_node) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/ast/misc.rb, line 35
    def diff(prev_node)
      if prev_node.is_a?(StatementsNode)
        i = 0
        while i < @stmts.size
          @stmts[i].diff(prev_node.stmts[i])
          if !@stmts[i].prev_node
            j1 = @stmts.size - 1
            j2 = prev_node.stmts.size - 1
            while j1 >= i && j2 >= i
              @stmts[j1].diff(prev_node.stmts[j2])
              if !@stmts[j1].prev_node
                return
              end
              j1 -= 1
              j2 -= 1
            end
            return
          end
          i += 1
        end
        @prev_node = prev_node if i == prev_node.stmts.size
      end
    end

install0(genv) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/ast/misc.rb, line 21
    def install0(genv)
      ret = nil
      @stmts.each do |stmt|
        ret = stmt ? stmt.install(genv) : nil
      end
      if ret
        ret2 = Vertex.new(self)
        @changes.add_edge(genv, ret, ret2)
        ret2
      else
        Source.new(genv.nil_type)
      end
    end

subnodes(= { stmts: }) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/ast/misc.rb, line 19
      def subnodes = { stmts: }

      def install0(genv)
        ret = nil
        @stmts.each do |stmt|
          ret = stmt ? stmt.install(genv) : nil
        end
        if ret
          ret2 = Vertex.new(self)
          @changes.add_edge(genv, ret, ret2)
          ret2
        else
          Source.new(genv.nil_type)
        end
      end

      def diff(prev_node)
        if prev_node.is_a?(StatementsNode)
          i = 0
          while i < @stmts.size
            @stmts[i].diff(prev_node.stmts[i])
            if !@stmts[i].prev_node
              j1 = @stmts.size - 1
              j2 = prev_node.stmts.size - 1
              while j1 >= i && j2 >= i
                @stmts[j1].diff(prev_node.stmts[j2])
                if !@stmts[j1].prev_node
                  return
                end
                j1 -= 1
                j2 -= 1
              end
              return
            end
            i += 1
          end
          @prev_node = prev_node if i == prev_node.stmts.size
        end
      end
    end