class RbGCCXML::Node

A Node is part of the C++ code as dictated by GCC-XML. This class defines all of the starting points into the querying system, along with helper methods to access data from the C++ code itself.

Any Node further down the heirarchy chain can and should define which finder methods are and are not avaiable at that level. For example, the Class node cannot search for other Namespaces within that class, and any attempt to will throw a NotQueryableException.

Attributes

attributes[RW]

Hash of all the attributes

children[RW]

Any children this node has

container[RW]

HACK A linking ivar that lets types figure out where they sit, for example an argument type can find the <Argument> it’s a part of.

id[RW]

GCC_XML id of this node

name[RW]

The base name of this node

parent[RW]

The C++ scoping parent of this node

Public Class Methods

new(attributes) click to toggle source

Initialize this node according to the attributes passed in Only to be used internally. Use query methods on the object returned by RbGCCXML.parse

# File lib/rbgccxml/node.rb, line 39
def initialize(attributes)
  @id = attributes["id"]
  @name = attributes["name"]
  @demangled = attributes["demangled"]

  @attributes = attributes

  @children = []
end

Public Instance Methods

[](val) click to toggle source

Access indivitual attributes directly

# File lib/rbgccxml/node.rb, line 87
def [](val)
  @attributes[val]
end
artificial?() click to toggle source

Is this node automatically generated by gcc?

# File lib/rbgccxml/node.rb, line 82
def artificial?
  @attributes["artificial"] ? @attributes["artificial"] == "1" : false
end
base_type() click to toggle source

Some C++ nodes are actually wrappers around other nodes. For example,

typedef int ThisType;

You’ll get the TypeDef node “ThisType”. Use this method if you want the base type for this typedef, e.g. the “int”.

# File lib/rbgccxml/node.rb, line 97
def base_type
  self
end
classes(name = nil) click to toggle source

Find all classes in this scope.

See #namespaces

# File lib/rbgccxml/node.rb, line 129
def classes(name = nil)
  find_children_of_type("Class", name)
end
const?() click to toggle source

Is this node const qualified?

# File lib/rbgccxml/node.rb, line 62
def const?
  @attributes["const"] ? @attributes["const"] == "1" : false
end
enumerations(name = nil) click to toggle source

Find all enumerations in this scope.

See #namespaces

# File lib/rbgccxml/node.rb, line 150
def enumerations(name = nil)
  find_children_of_type("Enumeration", name)
end
file() click to toggle source

Returns the full path to the file this node is found in. Returns nil if no File node is found for this node

# File lib/rbgccxml/node.rb, line 103
def file
  file_id = @attributes["file"]
  file_node = NodeCache.find(file_id)
  file_node ? file_node.name : nil
end
functions(name = nil) click to toggle source

Find all functions in this scope.

See #namespaces

# File lib/rbgccxml/node.rb, line 143
def functions(name = nil)
  find_children_of_type("Function", name)
end
inspect() click to toggle source
Alias for: to_s
namespaces(name = nil) click to toggle source

Find all namespaces. There are two ways of calling this method:

#namespaces  => Get all namespaces in this scope
#namespaces(name) => Shortcut for namespaces.find(:name => name)

Returns a QueryResult unless only one node was found

# File lib/rbgccxml/node.rb, line 122
def namespaces(name = nil)
  find_children_of_type("Namespace", name)
end
private?() click to toggle source

Does this node have private access?

# File lib/rbgccxml/node.rb, line 77
def private?
 @attributes["access"] ? @attributes["access"] == "private" : false
end
protected?() click to toggle source

Does this node have protected access?

# File lib/rbgccxml/node.rb, line 72
def protected?
 @attributes["access"] ? @attributes["access"] == "protected" : false
end
public?() click to toggle source

Does this node have public access?

# File lib/rbgccxml/node.rb, line 67
def public?
 @attributes["access"] ? @attributes["access"] == "public" : true
end
qualified_name() click to toggle source

Get the fully qualified (demangled) C++ name of this node.

# File lib/rbgccxml/node.rb, line 50
def qualified_name
  if @demangled
    # The 'demangled' attribute of the node for methods / functions is the 
    # full signature, so cut that part out.
    @demangled.split(%r\(/)[0]
  else
    @parent ? "#{@parent.qualified_name}::#{@name}" : @name
  end
end
structs(name = nil) click to toggle source

Find all structs in this scope.

See #namespaces

# File lib/rbgccxml/node.rb, line 136
def structs(name = nil)
  find_children_of_type("Struct", name)
end
to_cpp(qualified = true) click to toggle source

Print out the full C++ valid code for this node. By default, it will print out the fully qualified name of this node. See various Type classes to see how else this method is used.

# File lib/rbgccxml/node.rb, line 171
def to_cpp(qualified = true)
  qualified ? self.qualified_name : self.name
end
to_s() click to toggle source
# File lib/rbgccxml/node.rb, line 175
def to_s
  "#<#{self.class.name} @attributes=#{self.attributes.inspect}>"
end
Also aliased as: inspect
typedefs(name = nil) click to toggle source

Find all typedefs in this scope

See #namespaces

# File lib/rbgccxml/node.rb, line 164
def typedefs(name = nil)
  find_children_of_type("Typedef", name)
end
variables(name = nil) click to toggle source

Find all variables in this scope

See #namespaces

# File lib/rbgccxml/node.rb, line 157
def variables(name = nil)
  find_children_of_type("Variable", name)
end