class TypeProf::Core::AST::ConstantReadNode::ConstantWriteNode - typeprof: Ruby Standard Library Documentation

# class TypeProf::Core::AST::ConstantReadNode::ConstantWriteNode

### Attributes

cname_code_range[R]
cpath[R]
rhs[R]
static_cpath[R]

### Public Class Methods

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

    # File typeprof-0.30.1/lib/typeprof/core/ast/const.rb, line 58
    def initialize(raw_node, rhs, lenv)
      super(raw_node, lenv)
      case raw_node.type
      when :constant_write_node, :constant_target_node, :constant_operator_write_node, :constant_or_write_node, :constant_and_write_node
        # C = expr
        @cpath = nil
        @static_cpath = lenv.cref.cpath + [raw_node.name]
        @cname_code_range = TypeProf::CodeRange.from_node(raw_node.respond_to?(:name_loc) ? raw_node.name_loc : raw_node)
      when :constant_path_write_node, :constant_path_operator_write_node, :constant_path_or_write_node, :constant_path_and_write_node
        # expr::C = expr
        @cpath = AST.create_node(raw_node.target, lenv)
        @static_cpath = AST.parse_cpath(raw_node.target, lenv.cref)
        @cname_code_range = TypeProf::CodeRange.from_node(raw_node.target)
      when :constant_path_target_node
        # expr::C, * = ary
        @cpath = ConstantReadNode.new(raw_node, lenv)
        @static_cpath = AST.parse_cpath(raw_node, lenv.cref)
        @cname_code_range = TypeProf::CodeRange.from_node(raw_node)
      else
        raise
      end
      @rhs = rhs
    end

### Public Instance Methods

attrs(= { static_cpath: }) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/ast/const.rb, line 85
      def attrs = { static_cpath: }

      def define0(genv)
        @cpath.define(genv) if @cpath
        @rhs.define(genv) if @rhs
        if @static_cpath
          mod = genv.resolve_const(@static_cpath)
          mod.add_def(self)
          mod
        else
          nil
        end
      end

      def define_copy(genv)
        if @static_cpath
          mod = genv.resolve_const(@static_cpath)
          mod.add_def(self)
          mod.remove_def(@prev_node)
        end
        super(genv)
      end

      def undefine0(genv)
        if @static_cpath
          genv.resolve_const(@static_cpath).remove_def(self)
        end
        @rhs.undefine(genv) if @rhs
        @cpath.undefine(genv) if @cpath
      end

      def install0(genv)
        @cpath.install(genv) if @cpath
        val = @rhs.install(genv)
        if @static_cpath
          @changes.add_edge(genv, val, @static_ret.vtx)
        end
        val
      end
    end

define0(genv) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/ast/const.rb, line 87
    def define0(genv)
      @cpath.define(genv) if @cpath
      @rhs.define(genv) if @rhs
      if @static_cpath
        mod = genv.resolve_const(@static_cpath)
        mod.add_def(self)
        mod
      else
        nil
      end
    end

define_copy(genv) click to toggle source
Calls superclass method `TypeProf::Core::AST::Node#define_copy`

    # File typeprof-0.30.1/lib/typeprof/core/ast/const.rb, line 99
    def define_copy(genv)
      if @static_cpath
        mod = genv.resolve_const(@static_cpath)
        mod.add_def(self)
        mod.remove_def(@prev_node)
      end
      super(genv)
    end

install0(genv) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/ast/const.rb, line 116
    def install0(genv)
      @cpath.install(genv) if @cpath
      val = @rhs.install(genv)
      if @static_cpath
        @changes.add_edge(genv, val, @static_ret.vtx)
      end
      val
    end

subnodes(= { cpath:, rhs: }) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/ast/const.rb, line 84
        def subnodes = { cpath:, rhs: }
        def attrs = { static_cpath: }

        def define0(genv)
          @cpath.define(genv) if @cpath
          @rhs.define(genv) if @rhs
          if @static_cpath
            mod = genv.resolve_const(@static_cpath)
            mod.add_def(self)
            mod
          else
            nil
          end
        end

        def define_copy(genv)
          if @static_cpath
            mod = genv.resolve_const(@static_cpath)
            mod.add_def(self)
            mod.remove_def(@prev_node)
          end
          super(genv)
        end

        def undefine0(genv)
          if @static_cpath
            genv.resolve_const(@static_cpath).remove_def(self)
          end
          @rhs.undefine(genv) if @rhs
          @cpath.undefine(genv) if @cpath
        end

        def install0(genv)
          @cpath.install(genv) if @cpath
          val = @rhs.install(genv)
          if @static_cpath
            @changes.add_edge(genv, val, @static_ret.vtx)
          end
          val
        end
      end
    end

undefine0(genv) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/ast/const.rb, line 108
    def undefine0(genv)
      if @static_cpath
        genv.resolve_const(@static_cpath).remove_def(self)
      end
      @rhs.undefine(genv) if @rhs
      @cpath.undefine(genv) if @cpath
    end