Module: Xdrgen::AST::Concerns::HasDefinitions
- Includes:
- HasChildren
- Included in:
- Definitions::Namespace, Top
- Defined in:
- lib/xdrgen/ast/concerns/has_definitions.rb
Instance Method Summary collapse
- #consts ⇒ Object
-
#definition_blocks ⇒ Object
Collapse the flat list of definitions in this container into a nested array, grouping the definitions by contiguous types:.
- #definitions ⇒ Object
- #enums ⇒ Object
- #find_definition(name) ⇒ Object
- #find_enum_value(name) ⇒ Object
- #namespaces ⇒ Object
- #structs ⇒ Object
- #typedefs ⇒ Object
- #unions ⇒ Object
Methods included from HasChildren
Instance Method Details
#consts ⇒ Object
10 11 12 |
# File 'lib/xdrgen/ast/concerns/has_definitions.rb', line 10 def consts find_children(Definitions::Const) end |
#definition_blocks ⇒ Object
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]
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# 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 ⇒ Object
30 31 32 |
# File 'lib/xdrgen/ast/concerns/has_definitions.rb', line 30 def definitions find_children(Definitions::Base) end |
#enums ⇒ Object
18 19 20 |
# File 'lib/xdrgen/ast/concerns/has_definitions.rb', line 18 def enums find_children(Definitions::Enum) end |
#find_definition(name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# 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) ⇒ Object
46 47 48 49 50 51 52 |
# 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 ⇒ Object
26 27 28 |
# File 'lib/xdrgen/ast/concerns/has_definitions.rb', line 26 def namespaces find_children(Definitions::Namespace) end |
#structs ⇒ Object
14 15 16 |
# File 'lib/xdrgen/ast/concerns/has_definitions.rb', line 14 def structs find_children(Definitions::Struct) end |
#typedefs ⇒ Object
6 7 8 |
# File 'lib/xdrgen/ast/concerns/has_definitions.rb', line 6 def typedefs find_children(Definitions::Typedef) end |
#unions ⇒ Object
22 23 24 |
# File 'lib/xdrgen/ast/concerns/has_definitions.rb', line 22 def unions find_children(Definitions::Union) end |