class TypeProf::Core::AST::BranchNode::LoopNode - typeprof: Ruby Standard Library Documentation

# class TypeProf::Core::AST::BranchNode::LoopNode

### Attributes

body[R]
cond[R]

### Public Class Methods

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

    # File typeprof-0.30.1/lib/typeprof/core/ast/control.rb, line 116
    def initialize(raw_node, lenv)
      super(raw_node, lenv)
      @cond = AST.create_node(raw_node.predicate, lenv)
      @body = raw_node.statements ? AST.create_node(raw_node.statements, lenv) : DummyNilNode.new(code_range, lenv)
    end

### Public Instance Methods

install0(genv) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/ast/control.rb, line 126
    def install0(genv)
      vars = []
      vars << @cond.var if @cond.is_a?(LocalVariableReadNode)
      @cond.modified_vars(@lenv.locals.keys, vars)
      @body.modified_vars(@lenv.locals.keys, vars)
      vars.uniq!
      old_vtxs = {}
      vars.each do |var|
        vtx = @lenv.get_var(var)
        nvtx = vtx.new_vertex(genv, self)
        old_vtxs[var] = nvtx
        @lenv.set_var(var, nvtx)
      end

      @cond.install(genv)
      if @cond.is_a?(LocalVariableReadNode)
        nvtx_then = NilFilter.new(genv, self, old_vtxs[@cond.var], self.is_a?(UntilNode)).next_vtx
        @lenv.set_var(@cond.var, nvtx_then)
      end

      if @lenv.exist_var?(:"*expected_block_ret")
        expected_block_ret = @lenv.locals[:"*expected_block_ret"]
        @lenv.set_var(:"*expected_block_ret", nil)
      end

      @body.install(genv)

      if expected_block_ret
        @lenv.set_var(:"*expected_block_ret", expected_block_ret)
      end

      vars.each do |var|
        @changes.add_edge(genv, @lenv.get_var(var), old_vtxs[var])
        @lenv.set_var(var, old_vtxs[var])
      end
      if @cond.is_a?(LocalVariableReadNode)
        nvtx_then = NilFilter.new(genv, self, old_vtxs[@cond.var], !self.is_a?(UntilNode)).next_vtx
        @lenv.set_var(@cond.var, nvtx_then)
      end

      Source.new(genv.nil_type)
    end

subnodes(= { cond:, body: }) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/ast/control.rb, line 124
      def subnodes = { cond:, body: }

      def install0(genv)
        vars = []
        vars << @cond.var if @cond.is_a?(LocalVariableReadNode)
        @cond.modified_vars(@lenv.locals.keys, vars)
        @body.modified_vars(@lenv.locals.keys, vars)
        vars.uniq!
        old_vtxs = {}
        vars.each do |var|
          vtx = @lenv.get_var(var)
          nvtx = vtx.new_vertex(genv, self)
          old_vtxs[var] = nvtx
          @lenv.set_var(var, nvtx)
        end

        @cond.install(genv)
        if @cond.is_a?(LocalVariableReadNode)
          nvtx_then = NilFilter.new(genv, self, old_vtxs[@cond.var], self.is_a?(UntilNode)).next_vtx
          @lenv.set_var(@cond.var, nvtx_then)
        end

        if @lenv.exist_var?(:"*expected_block_ret")
          expected_block_ret = @lenv.locals[:"*expected_block_ret"]
          @lenv.set_var(:"*expected_block_ret", nil)
        end

        @body.install(genv)

        if expected_block_ret
          @lenv.set_var(:"*expected_block_ret", expected_block_ret)
        end

        vars.each do |var|
          @changes.add_edge(genv, @lenv.get_var(var), old_vtxs[var])
          @lenv.set_var(var, old_vtxs[var])
        end
        if @cond.is_a?(LocalVariableReadNode)
          nvtx_then = NilFilter.new(genv, self, old_vtxs[@cond.var], !self.is_a?(UntilNode)).next_vtx
          @lenv.set_var(@cond.var, nvtx_then)
        end

        Source.new(genv.nil_type)
      end
    end