class IDL::AST::Node

Public Class Methods

new(name, enclosure) click to toggle source
Calls superclass method IDL::AST::Leaf::new
# File lib/ridl/node.rb, line 234
def initialize(name, enclosure)
  super
  @introduced = {}
  @children = []
  introduce(self)
end

Public Instance Methods

define(_type, _name, params = {}) click to toggle source
# File lib/ridl/node.rb, line 270
def define(_type, _name, params = {})
  unless is_definable?(_type)
    raise "#{_type.to_s} is not definable in #{self.typename}."
  end

  node = search_self(_name)
  if node.nil?
    node = _type.new(_name, self, params)
    node.annotations.concat(params[:annotations])
    node.prefix = @prefix
    introduce(node)
    @children << node
  else
    if _type != node.class
      raise "#{_name} is already defined as a type of #{node.typename}"
    end

    node = redefine(node, params)
  end
  node
end
introduce(node) click to toggle source
# File lib/ridl/node.rb, line 251
def introduce(node)
  n = (@introduced[node.intern] ||= node)
  raise "#{node.name} is already introduced as a #{n.scoped_name} of #{n.typename}." if n != node
end
is_definable?(_type) click to toggle source
# File lib/ridl/node.rb, line 264
def is_definable?(_type)
  self.class::DEFINABLE.any? do |target|
    _type.ancestors.include? target
  end
end
marshal_dump() click to toggle source
Calls superclass method IDL::AST::Leaf#marshal_dump
# File lib/ridl/node.rb, line 241
def marshal_dump
  super() << @children << @introduced
end
marshal_load(vars) click to toggle source
Calls superclass method IDL::AST::Leaf#marshal_load
# File lib/ridl/node.rb, line 245
def marshal_load(vars)
  @introduced = vars.pop
  @children = vars.pop
  super(vars)
end
match_members(&block) click to toggle source
# File lib/ridl/node.rb, line 302
def match_members(&block)
  !(@children.find(&block)).nil?
end
redefine(node, _params) click to toggle source
# File lib/ridl/node.rb, line 260
def redefine(node, _params)
  raise "\"#{node.name}\" is already defined."
end
replace_prefix(pfx) click to toggle source
Calls superclass method IDL::AST::Leaf#replace_prefix
# File lib/ridl/node.rb, line 310
def replace_prefix(pfx)
  super
  walk_members { |m| m.replace_prefix(pfx) }
end
resolve(_name) click to toggle source
# File lib/ridl/node.rb, line 292
def resolve(_name)
  node = search_enclosure(_name)
  @introduced[node.intern] = node unless node.nil?
  node
end
select_members(&block) click to toggle source
# File lib/ridl/node.rb, line 306
def select_members(&block)
  @children.select(&block)
end
undo_introduction(node) click to toggle source
# File lib/ridl/node.rb, line 256
def undo_introduction(node)
  @introduced.delete(node.intern)
end
walk_members(&block) click to toggle source
# File lib/ridl/node.rb, line 298
def walk_members(&block)
  @children.each(&block)
end

Protected Instance Methods

children() click to toggle source
# File lib/ridl/node.rb, line 316
def children
  @children
end
copy_from(_template, instantiation_context) click to toggle source
Calls superclass method IDL::AST::Leaf#copy_from
# File lib/ridl/node.rb, line 342
def copy_from(_template, instantiation_context)
  super
  _template.__send__(:walk_members_for_copy) do |child|
    _child_copy = child.instantiate(instantiation_context, self)
    @children << _child_copy
    # introduce unless already introduced (happens with module chains)
    @introduced[_child_copy.intern] = _child_copy unless @introduced.has_key?(_child_copy.intern)
  end
  self
end
search_enclosure(_name) click to toggle source
# File lib/ridl/node.rb, line 330
def search_enclosure(_name)
  node = search_self(_name)
  if node.nil? and not @enclosure.nil?
    node = @enclosure.search_enclosure(_name)
  end
  node
end
search_self(_name) click to toggle source
# File lib/ridl/node.rb, line 320
def search_self(_name)
  key = _name.downcase.intern
  node = @introduced[key]
  if not node.nil? and node.name != _name
    raise "\"#{_name}\" clashed with \"#{node.name}\"."
  end

  node
end
walk_members_for_copy(&block) click to toggle source
# File lib/ridl/node.rb, line 338
def walk_members_for_copy(&block)
  self.walk_members(&block)
end