Class: RDL::Type::VarType

Inherits:
RDL::Type show all
Defined in:
lib/rdl/types/var.rb

Constant Summary collapse

@@cache =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RDL::Type

expand_product

Constructor Details

#initialize(name) ⇒ VarType

Returns a new instance of VarType.



19
20
21
# File 'lib/rdl/types/var.rb', line 19

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rdl/types/var.rb', line 3

def name
  @name
end

Class Method Details

.__new__Object



8
# File 'lib/rdl/types/var.rb', line 8

alias :__new__ :new

.new(name) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/rdl/types/var.rb', line 11

def self.new(name)
  name = name.to_s.to_sym
  t = @@cache[name]
  return t if t
  t = self.__new__ name
  return (@@cache[name] = t) # assignment evaluates to t
end

Instance Method Details

#<=(other) ⇒ Object

an uninstantiated variable is only comparable to itself



36
37
38
# File 'lib/rdl/types/var.rb', line 36

def <=(other)
  return Type.leq(self, other)
end

#==(other) ⇒ Object Also known as: eql?



27
28
29
30
31
# File 'lib/rdl/types/var.rb', line 27

def ==(other)
  return false if other.nil?
  other = other.canonical
  return (other.instance_of? self.class) && (other.name.to_s == @name.to_s)
end

#copyObject



66
67
68
# File 'lib/rdl/types/var.rb', line 66

def copy
  self
end

#hashObject

:nodoc:



47
48
49
# File 'lib/rdl/types/var.rb', line 47

def hash # :nodoc:
  return @name.to_s.hash
end

#instantiate(inst) ⇒ Object



56
57
58
59
# File 'lib/rdl/types/var.rb', line 56

def instantiate(inst)
  return inst[@name] if inst[@name]
  return self
end

#match(other) ⇒ Object



40
41
42
43
44
45
# File 'lib/rdl/types/var.rb', line 40

def match(other)
  other = other.canonical
  other = other.type if other.instance_of? AnnotatedArgType
  return true if other.instance_of? WildQuery
  return self == other
end

#member?(obj, vars_wild: false) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



51
52
53
54
# File 'lib/rdl/types/var.rb', line 51

def member?(obj, vars_wild: false)
  return true if vars_wild
  raise TypeError, "Unbound type variable #{@name}"
end

#to_sObject

:nodoc:



23
24
25
# File 'lib/rdl/types/var.rb', line 23

def to_s # :nodoc:
  return @name.to_s
end

#widenObject



61
62
63
64
# File 'lib/rdl/types/var.rb', line 61

def widen
  return inst[@name] if inst[@name]
  return self
end