Class: HDLRuby::Low::TypeDef

Inherits:
Type
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/HDLRuby/hruby_low.rb,
lib/HDLRuby/hruby_low2c.rb,
lib/HDLRuby/hruby_low2vhd.rb,
lib/HDLRuby/hruby_low2high.rb,
lib/HDLRuby/hruby_low_mutable.rb,
lib/HDLRuby/hruby_low_skeleton.rb

Overview

Describes a high-level type definition.

NOTE: type definition are actually type with a name refering to another type (and equivalent to it).

Direct Known Subclasses

High::TypeDef

Constant Summary

Constants included from Low2Symbol

Low2Symbol::Low2SymbolPrefix, Low2Symbol::Low2SymbolTable, Low2Symbol::Symbol2LowTable

Instance Attribute Summary collapse

Attributes inherited from Type

#name

Attributes included from Hparent

#parent

Instance Method Summary collapse

Methods inherited from Type

#base, #base?, #boolean?, #break_types!, #direction, #equivalent?, #fixed?, #float?, #leaf?, #range, #range?, #regular?, #set_name!, #signed?, #struct?, #to_vector, #to_verilog, #types?, #unsigned?, #width

Methods included from Low2Symbol

#to_sym

Methods included from Hparent

#scope

Methods included from Ltype

included, #ltype?

Constructor Details

#initialize(name, type) ⇒ TypeDef

Creates a new type definition named +name+ from +type+.



1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
# File 'lib/HDLRuby/hruby_low.rb', line 1396

def initialize(name,type)
    # Initialize with name.
    super(name)
    # Checks the referered type.
    unless type.is_a?(Type) then
        raise AnyError, "Invalid class for a type: #{type.class}"
    end
    # Set the referened type.
    @def = type
end

Instance Attribute Details

#defObject (readonly)

The definition of the type.



1391
1392
1393
# File 'lib/HDLRuby/hruby_low.rb', line 1391

def def
  @def
end

Instance Method Details

#each_type_deep(&ruby_block) ⇒ Object

Iterates over the types deeply if any.



1423
1424
1425
1426
1427
1428
1429
1430
# File 'lib/HDLRuby/hruby_low.rb', line 1423

def each_type_deep(&ruby_block)
    # No ruby block? Return an enumerator.
    return to_enum(:each_type_deep) unless ruby_block
    # A ruby block? First apply it to current.
    ruby_block.call(self)
    # And recurse on the definition.
    @def.each_type_deep(&ruby_block)
end

#eql?(obj) ⇒ Boolean

Comparison for hash: structural comparison.

Returns:

  • (Boolean)


1408
1409
1410
1411
1412
1413
1414
1415
# File 'lib/HDLRuby/hruby_low.rb', line 1408

def eql?(obj)
    # General type comparison.
    return false unless super(obj)
    # Specific comparison.
    return false unless obj.is_a?(TypeDef)
    return false unless @def.eql?(obj.def)
    return true
end

#hashObject

Hash function.



1418
1419
1420
# File 'lib/HDLRuby/hruby_low.rb', line 1418

def hash
    return [super,@def].hash
end

#set_def!(type) ⇒ Object

Sets the type definition to +type+.



255
256
257
258
259
260
261
262
# File 'lib/HDLRuby/hruby_low_mutable.rb', line 255

def set_def!(type)
    # Checks the referered type.
    unless type.is_a?(Type) then
        raise AnyError, "Invalid class for a type: #{type.class}"
    end
    # Set the referened type.
    @def = type
end

#to_c(level = 0) ⇒ Object

Generates the C text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.



521
522
523
524
# File 'lib/HDLRuby/hruby_low2c.rb', line 521

def to_c(level = 0)
    # Simply use the name of the type.
    return Low2C.type_name(self.name) + "()"
end

#to_high(level = 0) ⇒ Object

Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.



184
185
186
187
# File 'lib/HDLRuby/hruby_low2high.rb', line 184

def to_high(level = 0)
    # Simply generates the redefined type.
    self.def.to_high(level)
end

#to_vhdl(level = 0) ⇒ Object

Generates the text of the equivalent HDLRuby::High code. +level+ is the hierachical level of the object.



616
617
618
619
620
621
# File 'lib/HDLRuby/hruby_low2vhd.rb', line 616

def to_vhdl(level = 0)
    # # Simply generates the redefined type.
    # return self.def.to_vhdl(level)
    # Simply use the name of the type.
    return Low2VHDL.vhdl_name(self.name)
end