class RbGCCXML::NodeCache

Manager of the tree of Nodes we build from GCC-XML.

This is a static class that keeps around references to the entire generated Node tree as well as other structures designed for quick and easy searching of Nodes



Hash of id => node for all nodes


Hash of Type => [node list] for easy searching of all nodes of a given type

Public Class Methods

<<(node) click to toggle source

Add a new node to the index list

# File lib/rbgccxml/node_cache.rb, line 19
def <<(node)
  @index_list ||= {}
  @types_list ||= {}

  @index_list[] = node

  class_name ="::")[-1]
  @types_list[class_name] ||= []
  @types_list[class_name] << node
all(type) click to toggle source

Get the list of all nodes of a given type

# File lib/rbgccxml/node_cache.rb, line 48
def all(type)
  @types_list[type] || []
clear() click to toggle source
# File lib/rbgccxml/node_cache.rb, line 30
def clear
  @index_list = {}
  @types_list = {}
find(id) click to toggle source

Given an id, find the node

# File lib/rbgccxml/node_cache.rb, line 43
def find(id)
find_by_ids(ids) click to toggle source

Given an array of ids return an array of nodes that match

# File lib/rbgccxml/node_cache.rb, line 53
def find_by_ids(ids) {|id| @index_list[id] })
find_children_of_type(node, type, matcher = nil) click to toggle source

Look through the DOM under node for type nodes. type must be the string name of an existing Node subclass.

Returns a QueryResult with the findings.

# File lib/rbgccxml/node_cache.rb, line 61
def find_children_of_type(node, type, matcher = nil)
  results =, type))
  results = results.find(:name => matcher) if matcher
process_tree() click to toggle source

Once all parsing is done and all nodes are in memory we need to actually build up the parent / child relationships of the nodes. We can’t do this during parsing because there is no guarentee the nodes will come in the right order

# File lib/rbgccxml/node_cache.rb, line 71
def process_tree
  @index_list.each do |id, node|

    # If this node has a context, link to that context as a parent
    # and then put ourselves as that parent's child
    if node["context"]
      node.parent = @index_list[node["context"]]
      node.parent.children << node

root() click to toggle source

Get the root node of the parse

# File lib/rbgccxml/node_cache.rb, line 36
def root
  # This is simply a way to hide GCC_XML specifics,
  # the :: Namespace node is always id _1

Protected Class Methods

select_nodes_of_type(nodes, type) click to toggle source
# File lib/rbgccxml/node_cache.rb, line 86
def select_nodes_of_type(nodes, type) {|node| node.class.to_s == "RbGCCXML::#{type}" }