Class: BlifUtils::AST::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/blifutils/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, header, commands = []) ⇒ Model

Returns a new instance of Model.



42
43
44
45
46
47
48
49
50
51
# File 'lib/blifutils/ast.rb', line 42

def initialize (name, header, commands = [])
	@name = name
	@header = header
	@commands = commands
	@isBlackBox = not(@commands.index{|command| command.class == AST::BlackBox}.nil?)
	if @isBlackBox and not(@commands.reject{|command| command.class == AST::BlackBox}.empty?) then
		STDERR.puts "WARNING: Blackbox \"#{@name}\" contains non blackbox commands"
		@commands = @commands.reject{|command| command.class == AST::BlackBox}.uniq
	end
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



40
41
42
# File 'lib/blifutils/ast.rb', line 40

def commands
  @commands
end

#headerObject (readonly)

Returns the value of attribute header.



40
41
42
# File 'lib/blifutils/ast.rb', line 40

def header
  @header
end

#isBlackBoxObject (readonly)

Returns the value of attribute isBlackBox.



40
41
42
# File 'lib/blifutils/ast.rb', line 40

def isBlackBox
  @isBlackBox
end

#nameObject (readonly)

Returns the value of attribute name.



40
41
42
# File 'lib/blifutils/ast.rb', line 40

def name
  @name
end

Instance Method Details

#pretty_print(indent) ⇒ Object



53
54
55
56
57
58
# File 'lib/blifutils/ast.rb', line 53

def pretty_print (indent)
	str = '    '*indent + "#{@isBlackBox ? 'Black box' : 'Model'}:\n" + '    '*(indent+1) + "Name:    \"#{@name}\"\n"
	@header.each{|headEl| str += headEl.pretty_print(indent+1)}
	@commands.each{|com| str += com.pretty_print(indent+1)} unless @isBlackBox
	return str
end