Class: VCD::Scope

Inherits:
Object
  • Object
show all
Defined in:
lib/libfst/vcd.rb

Overview

A Scope corresponds to a design element

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenArray<Scope> (readonly)

Returns:



26
27
28
# File 'lib/libfst/vcd.rb', line 26

def children
  @children
end

#nameString (readonly)

Returns:

  • (String)


23
24
25
# File 'lib/libfst/vcd.rb', line 23

def name
  @name
end

#parentScope? (readonly)

Returns:



27
28
29
# File 'lib/libfst/vcd.rb', line 27

def parent
  @parent
end

#typeSymbol (readonly)

Returns begin, fork, function, module or task.

Returns:

  • (Symbol)

    begin, fork, function, module or task



24
25
26
# File 'lib/libfst/vcd.rb', line 24

def type
  @type
end

#variablesArray<Variable> (readonly)

Returns:



25
26
27
# File 'lib/libfst/vcd.rb', line 25

def variables
  @variables
end

Instance Method Details

#pathString

Returns:

  • (String)


44
45
46
47
# File 'lib/libfst/vcd.rb', line 44

def path
  return '/' if @parent.nil? # root
  "#{@parent.path}#{@name}/"
end

#to_sString

Returns:

  • (String)


39
40
41
# File 'lib/libfst/vcd.rb', line 39

def to_s
  "<#{self.class} @name=#{@name.inspect}, @type=#{@type.inspect}>"
end

#treeString

Returns:

  • (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