rbgccxml 0.9.1 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +8 -10
- data/lib/rbgccxml/node.rb +65 -64
- data/lib/rbgccxml/node_cache.rb +93 -0
- data/lib/rbgccxml/nodes/argument.rb +4 -1
- data/lib/rbgccxml/nodes/base.rb +1 -1
- data/lib/rbgccxml/nodes/class.rb +22 -15
- data/lib/rbgccxml/nodes/enum_value.rb +2 -4
- data/lib/rbgccxml/nodes/enumeration.rb +1 -1
- data/lib/rbgccxml/nodes/field.rb +3 -1
- data/lib/rbgccxml/nodes/function.rb +2 -2
- data/lib/rbgccxml/nodes/method.rb +3 -3
- data/lib/rbgccxml/nodes/namespace.rb +14 -0
- data/lib/rbgccxml/nodes/type.rb +4 -3
- data/lib/rbgccxml/nodes/types/array_type.rb +3 -2
- data/lib/rbgccxml/nodes/types/cv_qualified_type.rb +12 -6
- data/lib/rbgccxml/nodes/types/pointer_type.rb +2 -1
- data/lib/rbgccxml/nodes/types/reference_type.rb +2 -1
- data/lib/rbgccxml/parser.rb +7 -5
- data/lib/rbgccxml/query_result.rb +8 -2
- data/lib/rbgccxml/sax_parser.rb +69 -0
- data/lib/rbgccxml.rb +3 -1
- data/lib/vendor/facets/once.rb +59 -0
- data/test/arguments_test.rb +14 -14
- data/test/classes_test.rb +85 -80
- data/test/enumerations_test.rb +29 -31
- data/test/function_pointers_test.rb +7 -7
- data/test/functions_test.rb +20 -20
- data/test/methods_test.rb +26 -25
- data/test/namespaces_test.rb +6 -6
- data/test/node_test.rb +7 -7
- data/test/parser_test.rb +23 -23
- data/test/query_results_test.rb +81 -81
- data/test/structs_test.rb +19 -20
- data/test/test_helper.rb +5 -18
- data/test/types_test.rb +60 -58
- data/test/variables_test.rb +12 -12
- metadata +58 -63
- data/lib/rbgccxml/xml_parsing.rb +0 -152
data/lib/rbgccxml/xml_parsing.rb
DELETED
@@ -1,152 +0,0 @@
|
|
1
|
-
module RbGCCXML
|
2
|
-
|
3
|
-
# A module of methods used to parse out the flat GCC-XML xml structure into
|
4
|
-
# a proper heirarchy. These methods are used internally and not intended
|
5
|
-
# for outside use.
|
6
|
-
module XMLParsing
|
7
|
-
|
8
|
-
# Save a reference to the root node of the parsed XML
|
9
|
-
def self.doc_root=(root)
|
10
|
-
@@doc_root = root
|
11
|
-
self.clear_cache
|
12
|
-
end
|
13
|
-
|
14
|
-
# Clear the internal query cache
|
15
|
-
def self.clear_cache
|
16
|
-
@@find_query_cache = {}
|
17
|
-
@@all_query_cache = {}
|
18
|
-
end
|
19
|
-
|
20
|
-
# Generic finding of nodes according to attributes.
|
21
|
-
# Special options:
|
22
|
-
#
|
23
|
-
# <tt>:node_type</tt>:: Specify a certain node type to search by
|
24
|
-
#
|
25
|
-
# Any other options is directly mapped to attributes on the node. For example, to find
|
26
|
-
# a Function node that have the name "functor":
|
27
|
-
#
|
28
|
-
# XMLParsing.find(:node_type => "Function", :name => "functor")
|
29
|
-
#
|
30
|
-
# Returns the first found node
|
31
|
-
def self.find(options = {})
|
32
|
-
return nil if options.empty?
|
33
|
-
|
34
|
-
cache_key = options.to_s
|
35
|
-
cached = @@find_query_cache[cache_key]
|
36
|
-
return cached if cached
|
37
|
-
|
38
|
-
type = options.delete(:node_type)
|
39
|
-
|
40
|
-
attrs = options.map {|key, value| "[@#{key}='#{value}']"}.join
|
41
|
-
xpath = "//#{type || '*'}#{attrs}"
|
42
|
-
|
43
|
-
got = @@doc_root.search(xpath).first
|
44
|
-
|
45
|
-
if got
|
46
|
-
result = build_type(type || got.name, got)
|
47
|
-
@@find_query_cache[cache_key] = result
|
48
|
-
result
|
49
|
-
else
|
50
|
-
nil
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Generic finding of nodes according to attributes.
|
55
|
-
# Special options:
|
56
|
-
#
|
57
|
-
# <tt>:node_type</tt>:: Specify a certain node type to search by
|
58
|
-
#
|
59
|
-
# Any other options is directly mapped to attributes on the node. For example, to find all
|
60
|
-
# Function nodes:
|
61
|
-
#
|
62
|
-
# XMLParsing.find_all(:node_type => "Function")
|
63
|
-
#
|
64
|
-
# Returns all matching nodes
|
65
|
-
def self.find_all(options = {})
|
66
|
-
results = QueryResult.new
|
67
|
-
return results if options.empty?
|
68
|
-
cache_key = options.to_s
|
69
|
-
|
70
|
-
cached = @@all_query_cache[cache_key]
|
71
|
-
return cached if cached
|
72
|
-
|
73
|
-
type = options.delete(:node_type)
|
74
|
-
attrs = options.map {|key, value| "[@#{key}='#{value}']"}.join
|
75
|
-
|
76
|
-
xpath = "//#{type || "*"}#{attrs}"
|
77
|
-
|
78
|
-
found = @@doc_root.search(xpath)
|
79
|
-
|
80
|
-
if found
|
81
|
-
found.each do |got|
|
82
|
-
results << build_type(type || got.name, got)
|
83
|
-
end
|
84
|
-
@@all_query_cache[cache_key] = results
|
85
|
-
end
|
86
|
-
results
|
87
|
-
end
|
88
|
-
|
89
|
-
# Look through the DOM under +node+ for +node_type+ nodes.
|
90
|
-
# +node_type+ must be the string name of an existing Node subclass.
|
91
|
-
#
|
92
|
-
# Returns a QueryResult with the findings.
|
93
|
-
def self.find_nested_nodes_of_type(node, node_type)
|
94
|
-
self.find_all(:node_type => node_type, :context => node["id"])
|
95
|
-
end
|
96
|
-
|
97
|
-
# Arguments are a special case in gccxml as they are actual children of
|
98
|
-
# the functions / methods they are a part of.
|
99
|
-
def self.find_arguments_for(node)
|
100
|
-
get_children_nodes_of_type(node, "Argument")
|
101
|
-
end
|
102
|
-
|
103
|
-
# Classes / Structs can have superclasses. This method finds the
|
104
|
-
# classes that are those superclasses according to the access type
|
105
|
-
# passed in (nil means find all of them)
|
106
|
-
def self.find_bases_for(node, access_type = nil)
|
107
|
-
bases = get_children_nodes_of_type(node, "Base")
|
108
|
-
|
109
|
-
if access_type
|
110
|
-
bases = bases.select {|b| b["access"] == access_type.to_s }
|
111
|
-
end
|
112
|
-
|
113
|
-
bases.map {|b| b.cpp_type }
|
114
|
-
end
|
115
|
-
|
116
|
-
# Enumeration values are children of the Enumeration element
|
117
|
-
def self.get_values_of(enum)
|
118
|
-
get_children_nodes_of_type(enum.node, "EnumValue")
|
119
|
-
end
|
120
|
-
|
121
|
-
# Generic lookup method for nodes that are XML children of the passed in node.
|
122
|
-
# See find_arguments_for and get_values_of for example usage
|
123
|
-
def self.get_children_nodes_of_type(node, type)
|
124
|
-
results = QueryResult.new
|
125
|
-
|
126
|
-
node.children.each do |found|
|
127
|
-
next unless found.element?
|
128
|
-
results << build_type(type, found)
|
129
|
-
end
|
130
|
-
|
131
|
-
results.flatten
|
132
|
-
end
|
133
|
-
|
134
|
-
# Entrance into the type management. Given a GCC-XML node and an attribute
|
135
|
-
# to reference, find the C++ type related. For example, finding the return
|
136
|
-
# type of a function:
|
137
|
-
#
|
138
|
-
# +find_type_of(func_node, "returns")+ could return "std::string" node, "int" node, etc
|
139
|
-
#
|
140
|
-
def self.find_type_of(node, attr)
|
141
|
-
self.find(:id => node[attr])
|
142
|
-
end
|
143
|
-
|
144
|
-
private
|
145
|
-
|
146
|
-
# Builds up the related RbGCCXML node according to the GCC-XML node found
|
147
|
-
# for a given query.
|
148
|
-
def self.build_type(type_name, node)
|
149
|
-
RbGCCXML.const_get(type_name).new(node)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|