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.
- []
- artificial?
- base_type
- classes
- const?
- enumerations
- file
- functions
- inspect
- namespaces
- new
- private?
- protected?
- public?
- qualified_name
- structs
- to_cpp
- to_s
- typedefs
- variables
| [RW] | attributes | Hash of all the attributes |
| [RW] | children | Any children this node has |
| [RW] | container | 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. |
| [RW] | id | GCC_XML id of this node |
| [RW] | name | The base name of this node |
| [RW] | parent | The C++ scoping parent of this node |
Initialize this node according to the attributes passed in Only to be used internally. Use query methods on the object returned by RbGCCXML::parse
[ show source ]
# File lib/rbgccxml/node.rb, line 39
39: def initialize(attributes)
40: @id = attributes["id"]
41: @name = attributes["name"]
42: @demangled = attributes["demangled"]
43:
44: @attributes = attributes
45:
46: @children = []
47: end
Access indivitual attributes directly
[ show source ]
# File lib/rbgccxml/node.rb, line 87
87: def [](val)
88: @attributes[val]
89: end
Is this node automatically generated by gcc?
[ show source ]
# File lib/rbgccxml/node.rb, line 82
82: def artificial?
83: @attributes["artificial"] ? @attributes["artificial"] == "1" : false
84: end
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".
[ show source ]
# File lib/rbgccxml/node.rb, line 97
97: def base_type
98: self
99: end
Find all classes in this scope.
See Node.namespaces
[ show source ]
# File lib/rbgccxml/node.rb, line 129
129: def classes(name = nil)
130: find_children_of_type("Class", name)
131: end
Is this node const qualified?
[ show source ]
# File lib/rbgccxml/node.rb, line 62
62: def const?
63: @attributes["const"] ? @attributes["const"] == "1" : false
64: end
Find all enumerations in this scope.
See Node.namespaces
[ show source ]
# File lib/rbgccxml/node.rb, line 150
150: def enumerations(name = nil)
151: find_children_of_type("Enumeration", name)
152: end
Returns the full path to the file this node is found in. Returns nil if no File node is found for this node
[ show source ]
# File lib/rbgccxml/node.rb, line 103
103: def file
104: file_id = @attributes["file"]
105: file_node = NodeCache.find(file_id)
106: file_node ? file_node.name : nil
107: end
Find all functions in this scope.
See Node.namespaces
[ show source ]
# File lib/rbgccxml/node.rb, line 143
143: def functions(name = nil)
144: find_children_of_type("Function", name)
145: end
Alias for to_s
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
[ show source ]
# File lib/rbgccxml/node.rb, line 122
122: def namespaces(name = nil)
123: find_children_of_type("Namespace", name)
124: end
Does this node have private access?
[ show source ]
# File lib/rbgccxml/node.rb, line 77
77: def private?
78: @attributes["access"] ? @attributes["access"] == "private" : false
79: end
Does this node have protected access?
[ show source ]
# File lib/rbgccxml/node.rb, line 72
72: def protected?
73: @attributes["access"] ? @attributes["access"] == "protected" : false
74: end
Does this node have public access?
[ show source ]
# File lib/rbgccxml/node.rb, line 67
67: def public?
68: @attributes["access"] ? @attributes["access"] == "public" : true
69: end
Get the fully qualified (demangled) C++ name of this node.
[ show source ]
# File lib/rbgccxml/node.rb, line 50
50: def qualified_name
51: if @demangled
52: # The 'demangled' attribute of the node for methods / functions is the
53: # full signature, so cut that part out.
54: @demangled.split(/\(/)[0]
55: else
56: @parent ? "#{@parent.qualified_name}::#{@name}" : @name
57: end
58: end
Find all structs in this scope.
See Node.namespaces
[ show source ]
# File lib/rbgccxml/node.rb, line 136
136: def structs(name = nil)
137: find_children_of_type("Struct", name)
138: end
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.
[ show source ]
# File lib/rbgccxml/node.rb, line 171
171: def to_cpp(qualified = true)
172: qualified ? self.qualified_name : self.name
173: end
[ show source ]
# File lib/rbgccxml/node.rb, line 175
175: def to_s
176: "#<#{self.class.name} @attributes=#{self.attributes.inspect}>"
177: end
Find all typedefs in this scope
See Node.namespaces
[ show source ]
# File lib/rbgccxml/node.rb, line 164
164: def typedefs(name = nil)
165: find_children_of_type("Typedef", name)
166: end
Find all variables in this scope
See Node.namespaces
[ show source ]
# File lib/rbgccxml/node.rb, line 157
157: def variables(name = nil)
158: find_children_of_type("Variable", name)
159: end