Sha256: 9d192cd4382d85a530056ae0af648e2839a1b8fe14004e439034ffc5d370f57d

Contents?: true

Size: 1.04 KB

Versions: 25

Compression:

Stored size: 1.04 KB

Contents

module Steep
  module AST
    module Types
      class Var
        attr_reader :name
        attr_reader :location

        def initialize(name:, location: nil)
          @name = name
          @location = location
        end

        def ==(other)
          other.is_a?(Var) &&
            other.name == name
        end

        def hash
          self.class.hash ^ name.hash
        end

        alias eql? ==

        def self.fresh(name)
          @mutex ||= Mutex.new

          @mutex.synchronize do
            @max ||= 0
            @max += 1

            new(name: :"#{name}(#{@max})")
          end
        end

        def to_s
          name.to_s
        end

        def subst(s)
          if s.key?(name)
            s[name]
          else
            self
          end
        end

        def free_variables()
          @fvs ||= Set.new([name])
        end

        def level
          [0]
        end

        def with_location(new_location)
          self.class.new(name: name, location: new_location)
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
steep-0.47.1 lib/steep/ast/types/var.rb
steep-0.47.0 lib/steep/ast/types/var.rb
steep-0.46.0 lib/steep/ast/types/var.rb
steep-0.45.0 lib/steep/ast/types/var.rb
steep-0.44.1 lib/steep/ast/types/var.rb
steep-0.44.0 lib/steep/ast/types/var.rb
steep-0.43.1 lib/steep/ast/types/var.rb
steep-0.43.0 lib/steep/ast/types/var.rb
steep-0.42.0 lib/steep/ast/types/var.rb
steep-0.41.0 lib/steep/ast/types/var.rb
steep-0.40.0 lib/steep/ast/types/var.rb
steep-0.39.0 lib/steep/ast/types/var.rb
steep-0.38.0 lib/steep/ast/types/var.rb
steep-0.37.0 lib/steep/ast/types/var.rb
steep-0.36.0 lib/steep/ast/types/var.rb
steep-0.35.0 lib/steep/ast/types/var.rb
steep-0.34.0 lib/steep/ast/types/var.rb
steep-0.33.0 lib/steep/ast/types/var.rb
steep-0.32.0 lib/steep/ast/types/var.rb
steep-0.31.1 lib/steep/ast/types/var.rb