Class: OrigenVerilog::Node

Inherits:
AST::Node
  • Object
show all
Defined in:
lib/origen_verilog/node.rb

Direct Known Subclasses

Preprocessor::Node, Verilog::Node

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/origen_verilog/node.rb', line 5

def file
  @file
end

#inputObject (readonly)

Returns the value of attribute input.



5
6
7
# File 'lib/origen_verilog/node.rb', line 5

def input
  @input
end

#intervalObject (readonly)

Returns the value of attribute interval.



5
6
7
# File 'lib/origen_verilog/node.rb', line 5

def interval
  @interval
end

#number_of_linesObject (readonly)

Returns the value of attribute number_of_lines.



5
6
7
# File 'lib/origen_verilog/node.rb', line 5

def number_of_lines
  @number_of_lines
end

Instance Method Details

#directoryObject



42
43
44
45
46
# File 'lib/origen_verilog/node.rb', line 42

def directory
  if file
    Pathname.new(file).dirname
  end
end

#find(type) ⇒ Object

Returns the first child node of the given type that is found



24
25
26
27
# File 'lib/origen_verilog/node.rb', line 24

def find(type)
  nodes = find_all(type)
  nodes.first
end

#find_all(*types) ⇒ Object

Returns an array containing all child nodes of the given type(s)



30
31
32
# File 'lib/origen_verilog/node.rb', line 30

def find_all(*types)
  Extractor.new.process(self, types)
end

#line_numberObject



34
35
36
# File 'lib/origen_verilog/node.rb', line 34

def line_number
  input.line_of(interval.first)
end

#text_valueObject



38
39
40
# File 'lib/origen_verilog/node.rb', line 38

def text_value
  input[interval]
end

#valueObject

Returns the value at the root of an AST node like this:

node # => (module-def
            (module-name
              (SCALAR-ID "Instrument"))

node.value  # => "Instrument"

No error checking is done and the caller is responsible for calling this only on compatible nodes



17
18
19
20
21
# File 'lib/origen_verilog/node.rb', line 17

def value
  val = children.first
  val = val.children.first while val.respond_to?(:children)
  val
end