module Xdrgen::AST::Concerns::HasDefinitions

Public Instance Methods

consts() click to toggle source
# File lib/xdrgen/ast/concerns/has_definitions.rb, line 10
def consts
  find_children(Definitions::Const)
end
definition_blocks() click to toggle source

Collapse the flat list of definitions in this container into a nested array, grouping the definitions by contiguous types:

Example:

Typedef, Typedef, Typedef, Const, Struct, Struct, Typedef

becomes:

[Typedef, Typedef, Typedef], [Const], [Struct, Struct], [Typedef]
# File lib/xdrgen/ast/concerns/has_definitions.rb, line 68
def definition_blocks
  children.each_with_object([]) do |child, result|
    next unless child.is_a?(Definitions::Base)

    current_group = result.last
    
    if current_group.blank?
      result.push [child]
    elsif current_group.last.is_a?(child.class)
      current_group.push child
    else
      result.push [child]
    end
  end
end
definitions() click to toggle source
# File lib/xdrgen/ast/concerns/has_definitions.rb, line 30
def definitions
  find_children(Definitions::Base)
end
enums() click to toggle source
# File lib/xdrgen/ast/concerns/has_definitions.rb, line 18
def enums
  find_children(Definitions::Enum)
end
find_definition(name) click to toggle source
# File lib/xdrgen/ast/concerns/has_definitions.rb, line 34
def find_definition(name)
  found = definitions.find{|d| d.name == name}
  return found if found

  namespaces.each do |ns|
    found = ns.find_definition(name)
    return found if found
  end

  nil
end
find_enum_value(name) click to toggle source
# File lib/xdrgen/ast/concerns/has_definitions.rb, line 46
def find_enum_value(name)
  enums.each do |e|
    found = e.members.find{|d| d.name == name}
    return found if found
  end
  raise "Could not find enum value #{name}"
end
namespaces() click to toggle source
# File lib/xdrgen/ast/concerns/has_definitions.rb, line 26
def namespaces
  find_children(Definitions::Namespace)
end
structs() click to toggle source
# File lib/xdrgen/ast/concerns/has_definitions.rb, line 14
def structs
  find_children(Definitions::Struct)
end
typedefs() click to toggle source
# File lib/xdrgen/ast/concerns/has_definitions.rb, line 6
def typedefs
  find_children(Definitions::Typedef)
end
unions() click to toggle source
# File lib/xdrgen/ast/concerns/has_definitions.rb, line 22
def unions
  find_children(Definitions::Union)
end

Private Instance Methods

find_children(type) click to toggle source
# File lib/xdrgen/ast/concerns/has_definitions.rb, line 85
def find_children(type)
  children.select{|c| c.is_a? type}
end