class TypeProf::Core::AST::LiteralNode::NilNode::TrueNode::FalseNode::IntegerNode::FloatNode::RationalNode::ComplexNode::SymbolNode::InterpolatedSymbolNode::StringNode::InterpolatedStringNode::RegexpNode::InterpolatedRegexpNode::MatchLastLineNode::InterpolatedMatchLastLineNode::RangeNode::ArrayNode - typeprof: Ruby Standard Library Documentation

# class TypeProf::Core::AST::LiteralNode::NilNode::TrueNode::FalseNode::IntegerNode::FloatNode::RationalNode::ComplexNode::SymbolNode::InterpolatedSymbolNode::StringNode::InterpolatedStringNode::RegexpNode::InterpolatedRegexpNode::MatchLastLineNode::InterpolatedMatchLastLineNode::RangeNode::ArrayNode

### Attributes

elems[R]
splat[R]

### Public Class Methods

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

    # File typeprof-0.30.1/lib/typeprof/core/ast/value.rb, line 235
    def initialize(raw_node, lenv, elems = raw_node.elements)
      super(raw_node, lenv)
      @elems = elems.map {|n| AST.create_node(n, lenv) }
      @splat = @elems.any? {|e| e.is_a?(SplatNode) }
    end

### Public Instance Methods

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

    # File typeprof-0.30.1/lib/typeprof/core/ast/value.rb, line 244
      def attrs = { splat: }

      def install0(genv)
        elems = @elems.map {|e| e.install(genv).new_vertex(genv, self) }
        unified_elem = Vertex.new(self)
        elems.each {|vtx| @changes.add_edge(genv, vtx, unified_elem) }
        base_ty = genv.gen_ary_type(unified_elem)
        if @splat
          Source.new(base_ty)
        else
          Source.new(Type::Array.new(genv, elems, base_ty))
        end
      end
    end

install0(genv) click to toggle source

    # File typeprof-0.30.1/lib/typeprof/core/ast/value.rb, line 246
    def install0(genv)
      elems = @elems.map {|e| e.install(genv).new_vertex(genv, self) }
      unified_elem = Vertex.new(self)
      elems.each {|vtx| @changes.add_edge(genv, vtx, unified_elem) }
      base_ty = genv.gen_ary_type(unified_elem)
      if @splat
        Source.new(base_ty)
      else
        Source.new(Type::Array.new(genv, elems, base_ty))
      end
    end

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

    # File typeprof-0.30.1/lib/typeprof/core/ast/value.rb, line 243
        def subnodes = { elems: }
        def attrs = { splat: }

        def install0(genv)
          elems = @elems.map {|e| e.install(genv).new_vertex(genv, self) }
          unified_elem = Vertex.new(self)
          elems.each {|vtx| @changes.add_edge(genv, vtx, unified_elem) }
          base_ty = genv.gen_ary_type(unified_elem)
          if @splat
            Source.new(base_ty)
          else
            Source.new(Type::Array.new(genv, elems, base_ty))
          end
        end
      end

      class HashNode < Node
        def initialize(raw_node, lenv, keywords)
          super(raw_node, lenv)
          @keys = []
          @vals = []
          @keywords = keywords
          @splat = false

          raw_node.elements.each do |raw_elem|
            # TODO: Support :assoc_splat_node
            case raw_elem.type
            when :assoc_node
              @keys << AST.create_node(raw_elem.key, lenv)
              @vals << AST.create_node(raw_elem.value, lenv)
            when :assoc_splat_node
              @keys << nil
              @vals << AST.create_node(raw_elem.value, lenv)
              @splat = true
            else
              raise "unknown hash elem: #{ raw_elem.type }"
            end
          end
        end

        attr_reader :keys, :vals, :splat, :keywords

        def subnodes = { keys:, vals: }
        def attrs = { splat:, keywords: }

        def install0(genv)
          unified_key = Vertex.new(self)
          unified_val = Vertex.new(self)
          literal_pairs = {}
          @keys.zip(@vals) do |key, val|
            if key
              k = key.install(genv).new_vertex(genv, self)
              v = val.install(genv).new_vertex(genv, self)
              @changes.add_edge(genv, k, unified_key)
              @changes.add_edge(genv, v, unified_val)
              literal_pairs[key.lit] = v if key.is_a?(SymbolNode)
            else
              h = val.install(genv)
              # TODO: do we want to call to_hash on h?
              @changes.add_hash_splat_box(genv, h, unified_key, unified_val)
            end
          end
          if @splat
            Source.new(genv.gen_hash_type(unified_key, unified_val))
          else
            Source.new(Type::Hash.new(genv, literal_pairs, genv.gen_hash_type(unified_key, unified_val)))
          end
        end
      end

      class LambdaNode < Node
        def install0(genv)
          Source.new(genv.proc_type)
        end
      end
    end