Class: VCD::Scope
- Inherits:
-
Object
- Object
- VCD::Scope
- Defined in:
- lib/libfst/vcd.rb
Overview
A Scope corresponds to a design element
Instance Attribute Summary collapse
- #children ⇒ Array<Scope> readonly
- #name ⇒ String readonly
- #parent ⇒ Scope? readonly
-
#type ⇒ Symbol
readonly
Begin, fork, function, module or task.
- #variables ⇒ Array<Variable> readonly
Instance Method Summary collapse
Instance Attribute Details
#children ⇒ Array<Scope> (readonly)
26 27 28 |
# File 'lib/libfst/vcd.rb', line 26 def children @children end |
#name ⇒ String (readonly)
23 24 25 |
# File 'lib/libfst/vcd.rb', line 23 def name @name end |
#type ⇒ Symbol (readonly)
Returns begin, fork, function, module or task.
24 25 26 |
# File 'lib/libfst/vcd.rb', line 24 def type @type end |
#variables ⇒ Array<Variable> (readonly)
25 26 27 |
# File 'lib/libfst/vcd.rb', line 25 def variables @variables end |
Instance Method Details
#path ⇒ String
44 45 46 47 |
# File 'lib/libfst/vcd.rb', line 44 def path return '/' if @parent.nil? # root "#{@parent.path}#{@name}/" end |
#to_s ⇒ String
39 40 41 |
# File 'lib/libfst/vcd.rb', line 39 def to_s "<#{self.class} @name=#{@name.inspect}, @type=#{@type.inspect}>" end |
#tree ⇒ String
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/libfst/vcd.rb', line 51 def tree(prefix = '', last: true, first: true) return @children.first.tree(prefix, last: last, first: first) if @parent.nil? && @variables.empty? && @children.length == 1 str = prefix + (first ? '' : (last ? '└─ ' : '├─ ')) str += "\e[34;1m#{@name}\e[0m (#{@type})\n" prefix = prefix + (first ? '' : (last ? ' ' : '│ ')) mxvarnamelen = ([0] + @variables.collect{|v| v.name.length}).max mxlenlen = ([0] + @variables.collect{|v| v.width == 0 ? 0 : v.width.to_s.length}).max @variables.each_with_index do |v, i| l = (@children.empty? and (i+1 == @variables.length)) str += prefix + (l ? '└─ ' : '├─ ') + v.name + ' '*(mxvarnamelen+1-v.name.length) str += (v.width > 0 ? v.width.to_s : '').rjust(mxlenlen) str += " #{v.type}\n" end @children.each_with_index do |c, i| str += c.tree(prefix, last: (i+1 == @children.length), first: false) end str end |