Class: Duby::AST::TypeReference

Inherits:
Node show all
Includes:
Named
Defined in:
lib/duby/ast.rb

Direct Known Subclasses

TypeDefinition, JVM::Types::Type

Constant Summary collapse

NoType =
TypeReference.new(:notype)
NullType =
TypeReference.new(:null)
ErrorType =
TypeReference.new(:error)
UnreachableType =
TypeReference.new(:unreachable)

Instance Attribute Summary collapse

Attributes included from Named

#name

Attributes inherited from Node

#children, #inferred_type, #newline, #parent, #position

Instance Method Summary collapse

Methods inherited from Node

#[], #each, #expr?, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp

Constructor Details

#initialize(name, array = false, meta = false, position = nil) ⇒ TypeReference

Returns a new instance of TypeReference.



178
179
180
181
182
183
# File 'lib/duby/ast.rb', line 178

def initialize(name, array = false, meta = false, position=nil)
  super(nil, position)
  @name = name
  @array = array
  @meta = meta
end

Instance Attribute Details

#arrayObject Also known as: array?

Returns the value of attribute array.



173
174
175
# File 'lib/duby/ast.rb', line 173

def array
  @array
end

#metaObject

Returns the value of attribute meta.



175
176
177
# File 'lib/duby/ast.rb', line 175

def meta
  @meta
end

Instance Method Details

#==(other) ⇒ Object



189
190
191
# File 'lib/duby/ast.rb', line 189

def ==(other)
  to_s == other.to_s
end

#compatible?(other) ⇒ Boolean

Returns:



206
207
208
209
210
211
# File 'lib/duby/ast.rb', line 206

def compatible?(other)
  # default behavior is only exact match right now
  self == other ||
      error? || other.error? ||
      unreachable? || other.unreachable?
end

#component_typeObject



217
218
219
# File 'lib/duby/ast.rb', line 217

def component_type
  AST.type(name) if array?
end

#eql?(other) ⇒ Boolean

Returns:



193
194
195
# File 'lib/duby/ast.rb', line 193

def eql?(other)
  self == other
end

#error?Boolean

Returns:



238
239
240
# File 'lib/duby/ast.rb', line 238

def error?
  name == :error
end

#hashObject



197
198
199
# File 'lib/duby/ast.rb', line 197

def hash
  to_s.hash
end

#is_parent(other) ⇒ Object



201
202
203
204
# File 'lib/duby/ast.rb', line 201

def is_parent(other)
  # default behavior now is to disallow any polymorphic types
  self == other
end

#iterable?Boolean

Returns:



213
214
215
# File 'lib/duby/ast.rb', line 213

def iterable?
  array?
end

#meta?Object

Returns the value of attribute meta.



176
177
178
# File 'lib/duby/ast.rb', line 176

def meta
  @meta
end

#narrow(other) ⇒ Object



221
222
223
224
225
226
227
228
# File 'lib/duby/ast.rb', line 221

def narrow(other)
  # only exact match allowed for now, so narrowing is a noop
  if error? || unreachable?
    other
  else
    self
  end
end

#primitive?Boolean

Returns:



246
247
248
# File 'lib/duby/ast.rb', line 246

def primitive?
  true
end

#to_sObject



185
186
187
# File 'lib/duby/ast.rb', line 185

def to_s
  "Type(#{name}#{array? ? ' array' : ''}#{meta? ? ' meta' : ''})"
end

#unmetaObject



230
231
232
# File 'lib/duby/ast.rb', line 230

def unmeta
  TypeReference.new(name, array, false)
end

#unreachable?Boolean

Returns:



242
243
244
# File 'lib/duby/ast.rb', line 242

def unreachable?
  name == :unreachable
end