rbgccxml 0.8 → 0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +5 -5
- data/lib/rbgccxml/node.rb +75 -73
- data/lib/rbgccxml/nodes/argument.rb +13 -2
- data/lib/rbgccxml/nodes/base.rb +14 -0
- data/lib/rbgccxml/nodes/class.rb +46 -8
- data/lib/rbgccxml/nodes/constructor.rb +8 -1
- data/lib/rbgccxml/nodes/destructor.rb +7 -0
- data/lib/rbgccxml/nodes/enum_value.rb +6 -4
- data/lib/rbgccxml/nodes/enumeration.rb +21 -2
- data/lib/rbgccxml/nodes/field.rb +18 -0
- data/lib/rbgccxml/nodes/file.rb +4 -1
- data/lib/rbgccxml/nodes/function.rb +6 -4
- data/lib/rbgccxml/nodes/function_type.rb +7 -0
- data/lib/rbgccxml/nodes/method.rb +6 -4
- data/lib/rbgccxml/nodes/struct.rb +3 -2
- data/lib/rbgccxml/nodes/type.rb +5 -3
- data/lib/rbgccxml/nodes/types/array_type.rb +29 -0
- data/lib/rbgccxml/nodes/types/cv_qualified_type.rb +9 -5
- data/lib/rbgccxml/nodes/types/fundamental_type.rb +3 -2
- data/lib/rbgccxml/nodes/types/pointer_type.rb +6 -3
- data/lib/rbgccxml/nodes/types/reference_type.rb +6 -3
- data/lib/rbgccxml/nodes/types/typedef.rb +2 -2
- data/lib/rbgccxml/nodes/variable.rb +7 -0
- data/lib/rbgccxml/parser.rb +47 -32
- data/lib/rbgccxml/query_result.rb +62 -25
- data/lib/rbgccxml/rbgccxml.rb +13 -16
- data/lib/rbgccxml/xml_parsing.rb +65 -97
- data/lib/rbgccxml.rb +26 -22
- data/test/arguments_test.rb +29 -0
- data/test/classes_test.rb +164 -26
- data/test/enumerations_test.rb +27 -19
- data/test/function_pointers_test.rb +18 -0
- data/test/functions_test.rb +7 -2
- data/test/methods_test.rb +3 -3
- data/test/namespaces_test.rb +1 -1
- data/test/node_test.rb +11 -31
- data/test/parser_test.rb +1 -1
- data/test/query_results_test.rb +15 -14
- data/test/structs_test.rb +10 -12
- data/test/test_helper.rb +10 -2
- data/test/types_test.rb +63 -38
- data/test/variables_test.rb +26 -0
- metadata +46 -31
data/Rakefile
CHANGED
@@ -4,12 +4,12 @@ require 'rake/contrib/sshpublisher'
|
|
4
4
|
require 'rake/gempackagetask'
|
5
5
|
|
6
6
|
PROJECT_NAME = "rbgccxml"
|
7
|
-
RBGCCXML_VERSION = "0.
|
7
|
+
RBGCCXML_VERSION = "0.9"
|
8
8
|
|
9
9
|
task :default => :test
|
10
10
|
|
11
11
|
Rake::TestTask.new do |t|
|
12
|
-
t.libs
|
12
|
+
t.libs = ["lib", "test"]
|
13
13
|
t.test_files = FileList["test/*_test.rb"]
|
14
14
|
t.verbose = true
|
15
15
|
end
|
@@ -41,7 +41,7 @@ namespace :web do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
desc "Clean up generated web files"
|
44
|
-
task :clean do
|
44
|
+
task :clean => ["clobber_rdoc"] do
|
45
45
|
rm_rf "publish"
|
46
46
|
end
|
47
47
|
end
|
@@ -55,8 +55,8 @@ spec = Gem::Specification.new do |s|
|
|
55
55
|
s.author = 'Jason Roelofs'
|
56
56
|
s.email = 'jameskilton@gmail.com'
|
57
57
|
|
58
|
-
s.add_dependency "
|
59
|
-
s.add_dependency "gccxml_gem", "0.9
|
58
|
+
s.add_dependency "libxml-ruby", "~>1.1"
|
59
|
+
s.add_dependency "gccxml_gem", "~>0.9"
|
60
60
|
|
61
61
|
s.description = <<-END
|
62
62
|
Rbgccxml is a library that parses out GCCXML (http://www.gccxml.org) output
|
data/lib/rbgccxml/node.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module RbGCCXML
|
2
2
|
|
3
3
|
class NotQueryableException < RuntimeError; end
|
4
|
+
class UnsupportedMatcherException < RuntimeError; end
|
4
5
|
|
5
6
|
# A Node is part of the C++ code as dictated by GCC-XML. This class
|
6
7
|
# defines all of the starting points into the querying system, along
|
@@ -8,12 +9,16 @@ module RbGCCXML
|
|
8
9
|
#
|
9
10
|
# Any Node further down the heirarchy chain can and should define which
|
10
11
|
# finder methods are and are not avaiable at that level. For example, the
|
11
|
-
# Class node cannot search for other Namespaces within that class
|
12
|
+
# Class node cannot search for other Namespaces within that class, and any
|
13
|
+
# attempt to will throw a NotQueryableException.
|
12
14
|
class Node
|
15
|
+
|
16
|
+
# The underlying libxml node for this Node.
|
13
17
|
attr_reader :node
|
14
18
|
|
15
19
|
# Initialize this node according to the XML element passed in
|
16
|
-
# Only to be used internally.
|
20
|
+
# Only to be used internally. Use query methods on the object
|
21
|
+
# returned by RbGCCXML::parse
|
17
22
|
def initialize(node)
|
18
23
|
@node = node
|
19
24
|
end
|
@@ -55,18 +60,27 @@ module RbGCCXML
|
|
55
60
|
@node.attributes["access"] ? @node.attributes["access"] == "private" : false
|
56
61
|
end
|
57
62
|
|
58
|
-
#
|
59
|
-
# underlying XML node
|
63
|
+
# Access to the underlying libxml node's attributes
|
60
64
|
def attributes
|
61
65
|
@node.attributes
|
62
66
|
end
|
63
67
|
|
64
|
-
#
|
65
|
-
|
68
|
+
# Some C++ nodes are actually wrappers around other nodes. For example,
|
69
|
+
#
|
70
|
+
# typedef int ThisType;
|
71
|
+
#
|
72
|
+
# You'll get the TypeDef node "ThisType". Use this method if you want the base type for this
|
73
|
+
# typedef, e.g. the "int".
|
74
|
+
def base_type
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns the full path to the file this node is found in.
|
79
|
+
# Returns nil if no File node is found for this node
|
80
|
+
def file
|
66
81
|
file_id = @node.attributes["file"]
|
67
|
-
file_node = XMLParsing.find(:
|
68
|
-
|
69
|
-
basename ? ::File.basename(name) : name
|
82
|
+
file_node = XMLParsing.find(:node_type => "File", :id => file_id) if file_id
|
83
|
+
file_node ? file_node.attributes["name"] : nil
|
70
84
|
end
|
71
85
|
|
72
86
|
# Returns the parent node of this node. e.g. function.parent will get the class
|
@@ -76,97 +90,85 @@ module RbGCCXML
|
|
76
90
|
XMLParsing.find(:id => @node.attributes["context"])
|
77
91
|
end
|
78
92
|
|
93
|
+
# This is a unified search routine for finding nested nodes. It
|
94
|
+
# simplifies the search routines below significantly.
|
95
|
+
def find_nested_nodes_of_type(type, matcher = nil, &block)
|
96
|
+
res = XMLParsing.find_nested_nodes_of_type(@node, type)
|
97
|
+
|
98
|
+
case matcher
|
99
|
+
when String
|
100
|
+
res = res.find(:name => matcher)
|
101
|
+
when Regexp
|
102
|
+
res = res.find_all { |t| t.name =~ matcher }
|
103
|
+
when nil
|
104
|
+
# Do nothing, since not specifying a matcher is okay.
|
105
|
+
else
|
106
|
+
message = "Can't handle a match condition of type #{matcher.class}."
|
107
|
+
raise UnsupportedMatcherException.new(message)
|
108
|
+
end
|
109
|
+
|
110
|
+
res = res.find_all(&block) if block
|
111
|
+
|
112
|
+
res
|
113
|
+
end
|
114
|
+
private :find_nested_nodes_of_type
|
115
|
+
|
79
116
|
# Find all namespaces. There are two ways of calling this method:
|
80
117
|
# #namespaces => Get all namespaces in this scope
|
81
118
|
# #namespaces(name) => Shortcut for namespaces.find(:name => name)
|
82
119
|
#
|
83
120
|
# Returns a QueryResult unless only one node was found
|
84
|
-
def namespaces(name = nil)
|
85
|
-
|
86
|
-
namespaces.find(:name => name)
|
87
|
-
else
|
88
|
-
XMLParsing.find_nested_nodes_of_type(@node, "Namespace")
|
89
|
-
end
|
121
|
+
def namespaces(name = nil, &block)
|
122
|
+
find_nested_nodes_of_type("Namespace", name, &block)
|
90
123
|
end
|
91
124
|
|
92
125
|
# Find all classes in this scope.
|
126
|
+
#
|
93
127
|
# See Node.namespaces
|
94
|
-
def classes(name = nil)
|
95
|
-
|
96
|
-
classes.find(:name => name)
|
97
|
-
else
|
98
|
-
XMLParsing.find_nested_nodes_of_type(@node, "Class")
|
99
|
-
end
|
128
|
+
def classes(name = nil, &block)
|
129
|
+
find_nested_nodes_of_type("Class", name, &block)
|
100
130
|
end
|
101
131
|
|
102
132
|
# Find all structs in this scope.
|
133
|
+
#
|
103
134
|
# See Node.namespaces
|
104
|
-
def structs(name = nil)
|
105
|
-
|
106
|
-
structs.find(:name => name)
|
107
|
-
else
|
108
|
-
XMLParsing.find_nested_nodes_of_type(@node, "Struct")
|
109
|
-
end
|
135
|
+
def structs(name = nil, &block)
|
136
|
+
find_nested_nodes_of_type("Struct", name, &block)
|
110
137
|
end
|
111
138
|
|
112
|
-
# Find all functions in this scope.
|
113
|
-
# functions. To search for class methods, use #methods.
|
139
|
+
# Find all functions in this scope.
|
114
140
|
#
|
115
141
|
# See Node.namespaces
|
116
|
-
def functions(name = nil)
|
117
|
-
|
118
|
-
functions.find(:name => name)
|
119
|
-
else
|
120
|
-
XMLParsing.find_nested_nodes_of_type(@node, "Function")
|
121
|
-
end
|
142
|
+
def functions(name = nil, &block)
|
143
|
+
find_nested_nodes_of_type("Function", name, &block)
|
122
144
|
end
|
123
145
|
|
124
146
|
# Find all enumerations in this scope.
|
147
|
+
#
|
125
148
|
# See Node.namespaces
|
126
|
-
def enumerations(name = nil)
|
127
|
-
|
128
|
-
enumerations.find(:name => name)
|
129
|
-
else
|
130
|
-
XMLParsing.find_nested_nodes_of_type(@node, "Enumeration")
|
131
|
-
end
|
149
|
+
def enumerations(name = nil, &block)
|
150
|
+
find_nested_nodes_of_type("Enumeration", name, &block)
|
132
151
|
end
|
133
|
-
|
134
|
-
#
|
135
|
-
# a String to test against the name of the node. For example
|
136
|
-
#
|
137
|
-
# source.classes("MyClass") == "MyClass" #=> true
|
138
|
-
# source.classes("MyClass") == source.classes.find(:name => "MyClass") #=> true
|
152
|
+
|
153
|
+
# Find all variables in this scope
|
139
154
|
#
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
# Need to take care of '*' which is a regex character, and any leading ::,
|
144
|
-
# which are redundant in our case.
|
145
|
-
if val =~ /::/
|
146
|
-
return true if self.qualified_name =~ /#{val.gsub("*", "\\*").gsub(/^::/, "")}/
|
147
|
-
end
|
148
|
-
|
149
|
-
false
|
150
|
-
elsif val.is_a?(Regexp)
|
151
|
-
self =~ val
|
152
|
-
else
|
153
|
-
super
|
154
|
-
end
|
155
|
+
# See Node.namespaces
|
156
|
+
def variables(name = nil, &block)
|
157
|
+
find_nested_nodes_of_type("Variable", name, &block)
|
155
158
|
end
|
156
159
|
|
157
|
-
#
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
super
|
163
|
-
end
|
160
|
+
# Find all typedefs in this scope
|
161
|
+
#
|
162
|
+
# See Node.namespaces
|
163
|
+
def typedefs(name = nil, &block)
|
164
|
+
find_nested_nodes_of_type("Typedef", name, &block)
|
164
165
|
end
|
165
166
|
|
166
|
-
# Print out the
|
167
|
-
# print out the fully qualified name of this node.
|
168
|
-
|
169
|
-
|
167
|
+
# Print out the full C++ valid code for this node.
|
168
|
+
# By default, it will print out the fully qualified name of this node.
|
169
|
+
# See various Type classes to see how else this method is used.
|
170
|
+
def to_cpp(qualified = true)
|
171
|
+
qualified ? self.qualified_name : self.name
|
170
172
|
end
|
171
173
|
end
|
172
174
|
|
@@ -1,11 +1,22 @@
|
|
1
1
|
module RbGCCXML
|
2
|
-
#
|
2
|
+
# Represents a single <Argument> node.
|
3
|
+
# Can be an argument for a Method, Function, or Constructor
|
3
4
|
class Argument < Node
|
4
5
|
|
5
|
-
# Get the
|
6
|
+
# Get the Node for this argument's type
|
6
7
|
def cpp_type
|
7
8
|
XMLParsing.find_type_of(node, "type")
|
8
9
|
end
|
9
10
|
|
11
|
+
# Get any default value for this argument
|
12
|
+
def value
|
13
|
+
attributes["default"]
|
14
|
+
end
|
15
|
+
|
16
|
+
# See Node#to_cpp, prints out C++ code for this argument
|
17
|
+
def to_cpp(qualified = true)
|
18
|
+
"#{self.cpp_type.to_cpp(qualified)} #{self.name}"
|
19
|
+
end
|
20
|
+
|
10
21
|
end
|
11
22
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RbGCCXML
|
2
|
+
|
3
|
+
# Node type represending <Base> nodes.
|
4
|
+
# These nodes are children to <Class> nodes and define superclass
|
5
|
+
# definitions
|
6
|
+
class Base < Node
|
7
|
+
|
8
|
+
# Get the Class node representing the type of this Base
|
9
|
+
def cpp_type
|
10
|
+
XMLParsing.find_type_of(node, "type")
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
data/lib/rbgccxml/nodes/class.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module RbGCCXML
|
2
|
-
#
|
2
|
+
# Represents a <Class> node.
|
3
3
|
class Class < Node
|
4
4
|
|
5
5
|
# Disabled: Classes cannot have nested namespaces
|
@@ -7,18 +7,56 @@ module RbGCCXML
|
|
7
7
|
raise NotQueryableException.new("Cannot query for Namespaces while in a Class")
|
8
8
|
end
|
9
9
|
|
10
|
+
# Is this class pure virtual?
|
11
|
+
def pure_virtual?
|
12
|
+
@node.attributes["abstract"] ? @node.attributes["abstract"] == "1" : false
|
13
|
+
end
|
14
|
+
|
10
15
|
# Find all the constructors for this class.
|
11
16
|
def constructors
|
12
17
|
XMLParsing::find_nested_nodes_of_type(@node, "Constructor")
|
13
18
|
end
|
14
19
|
|
15
|
-
# Find
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
# Find the destructor for this class.
|
21
|
+
# To tell if a destructor is gcc-generated or not, check the
|
22
|
+
# 'artificial' attribute:
|
23
|
+
#
|
24
|
+
# class_node.destructor.attributes[:artificial]
|
25
|
+
#
|
26
|
+
def destructor
|
27
|
+
XMLParsing::find_nested_nodes_of_type(@node, "Destructor")[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
# Find the superclass for this class.
|
31
|
+
# By default, this will find the superclass of any access type, pass in
|
32
|
+
# the type of access you're looking for if you want specific types (e.g. public, private, protected).
|
33
|
+
#
|
34
|
+
# If there is more than one superclass to this class, this method will only return the first superclass.
|
35
|
+
# If you know or expect there to be multiple superclasses, use #superclasses instead
|
36
|
+
def superclass(access_type = nil)
|
37
|
+
found = superclasses(access_type)
|
38
|
+
found.empty? ? nil : found[0]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Like #superclass above, this will find all superclasses for this class.
|
42
|
+
# Functions the same as #superclass except this method always returns a QueryResult
|
43
|
+
def superclasses(access_type = nil)
|
44
|
+
XMLParsing::find_bases_for(@node, access_type)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Find all methods for this class. See Node#namespaces
|
48
|
+
def methods(name = nil, &block)
|
49
|
+
find_nested_nodes_of_type("Method", name, &block)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Find all instance variables for this class. See Node#namespaces
|
53
|
+
def variables(name = nil, &block)
|
54
|
+
find_nested_nodes_of_type("Field", name, &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Find all constants under this class. See Node#namespaces
|
58
|
+
def constants(name = nil, &block)
|
59
|
+
find_nested_nodes_of_type("Variable", name, &block)
|
22
60
|
end
|
23
61
|
end
|
24
62
|
end
|
@@ -1,9 +1,16 @@
|
|
1
1
|
module RbGCCXML
|
2
|
-
|
2
|
+
|
3
|
+
# Represents a <Constructor> node.
|
4
|
+
#
|
5
|
+
# Constructors act like functions except they don't have
|
6
|
+
# a return value
|
3
7
|
class Constructor < Function
|
8
|
+
|
4
9
|
# Disabled: Constructors do not have a return_type.
|
5
10
|
def return_type
|
6
11
|
raise "There is no return_type of a constructor"
|
7
12
|
end
|
13
|
+
|
8
14
|
end
|
15
|
+
|
9
16
|
end
|
@@ -1,20 +1,22 @@
|
|
1
1
|
module RbGCCXML
|
2
|
-
|
2
|
+
|
3
|
+
# Represents an <EnumValue> node, which is an entry in an <Enumeration>
|
3
4
|
class EnumValue < Node
|
4
5
|
|
5
|
-
# Link to the Enumeration
|
6
|
+
# Link to the Enumeration that holds this EnumValue
|
6
7
|
attr_accessor :parent
|
7
8
|
|
8
|
-
# Get the
|
9
|
+
# Get the defined value of this EnumValue
|
9
10
|
def value
|
10
11
|
node.attributes["init"].to_i
|
11
12
|
end
|
12
13
|
|
13
|
-
# The qualified name of an
|
14
|
+
# The qualified name of an EnumValue doesn't
|
14
15
|
# include the name of the enum itself
|
15
16
|
def qualified_name #:nodoc:
|
16
17
|
"#{self.parent.parent.qualified_name}::#{self.name}"
|
17
18
|
end
|
18
19
|
|
19
20
|
end
|
21
|
+
|
20
22
|
end
|
@@ -1,10 +1,29 @@
|
|
1
1
|
module RbGCCXML
|
2
|
-
|
2
|
+
|
3
|
+
# Represents an <Enumeration> node.
|
4
|
+
# Has many <EnumValue> nodes.
|
3
5
|
class Enumeration < Node
|
4
|
-
|
6
|
+
|
7
|
+
# Get the list of EnumValues for this enumeration
|
5
8
|
def values
|
6
9
|
XMLParsing.get_values_of(self).each {|v| v.parent = self }
|
7
10
|
end
|
8
11
|
|
12
|
+
# Is this enumeration anonymous? As in, does it have a name or is
|
13
|
+
# it just a pretty wrapper around constant values, ala:
|
14
|
+
#
|
15
|
+
# enum {
|
16
|
+
# VALUE1,
|
17
|
+
# VALUE2,
|
18
|
+
# ...
|
19
|
+
# };
|
20
|
+
#
|
21
|
+
def anonymous?
|
22
|
+
# The given GCC-XML name of an anon Enum is _[number]. We don't care what
|
23
|
+
# that number is, only that the name matches this format
|
24
|
+
self.name =~ /_\d+/
|
25
|
+
end
|
26
|
+
|
9
27
|
end
|
28
|
+
|
10
29
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RbGCCXML
|
2
|
+
|
3
|
+
# Represents a <Field> node, which is a Class's instance variable
|
4
|
+
class Field < Node
|
5
|
+
|
6
|
+
# Get the Node representing this field's type
|
7
|
+
def cpp_type
|
8
|
+
XMLParsing.find_type_of(node, "type")
|
9
|
+
end
|
10
|
+
|
11
|
+
# See Node#to_cpp
|
12
|
+
def to_cpp(qualified = false)
|
13
|
+
"#{self.cpp_type.to_cpp(qualified)} #{self.name}"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/rbgccxml/nodes/file.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module RbGCCXML
|
2
|
-
|
3
|
-
#
|
2
|
+
|
3
|
+
# Represents a <Function> node, a global or namespaced function
|
4
|
+
# or static class functions.
|
4
5
|
class Function < Node
|
5
6
|
|
6
7
|
# First of all, no more querying once you're this far in
|
@@ -10,14 +11,15 @@ module RbGCCXML
|
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
|
-
# Get the list of
|
14
|
+
# Get the list of Arguments for this Function.
|
14
15
|
def arguments
|
15
16
|
XMLParsing.find_arguments_for(node)
|
16
17
|
end
|
17
18
|
|
18
|
-
#
|
19
|
+
# Get the Node representing this Function's return type
|
19
20
|
def return_type
|
20
21
|
XMLParsing.find_type_of(node, "returns")
|
21
22
|
end
|
22
23
|
end
|
24
|
+
|
23
25
|
end
|
@@ -1,21 +1,23 @@
|
|
1
1
|
module RbGCCXML
|
2
|
-
|
3
|
-
#
|
2
|
+
|
3
|
+
# Represents a <Method>, which are class instance methods.
|
4
4
|
class Method < Function
|
5
5
|
|
6
6
|
# Is this method static?
|
7
7
|
def static?
|
8
8
|
@node.attributes["static"] == "1"
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
# Is this a virtual method?
|
12
12
|
def virtual?
|
13
13
|
@node.attributes["virtual"] == "1"
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# Is this a pure virtual method? A purely virtual method has no body.
|
17
17
|
def purely_virtual?
|
18
18
|
@node.attributes["pure_virtual"] == "1"
|
19
19
|
end
|
20
|
+
|
20
21
|
end
|
22
|
+
|
21
23
|
end
|
data/lib/rbgccxml/nodes/type.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module RbGCCXML
|
2
|
+
|
2
3
|
# The base class for all type management classes.
|
3
4
|
# RbGCCXML has a pretty extensive type querying sub-system that
|
4
5
|
# allows type matching by names, types, base types, etc
|
@@ -15,8 +16,8 @@ module RbGCCXML
|
|
15
16
|
end
|
16
17
|
|
17
18
|
# Get the base type without any qualifiers. E.g, if you've
|
18
|
-
# got the
|
19
|
-
# will return the
|
19
|
+
# got the CvQualifiedType "const my_space::MyClass&, this
|
20
|
+
# will return the Node for "my_space::MyClass"
|
20
21
|
#
|
21
22
|
# returns: Node related to the base C++ construct of this type
|
22
23
|
def base_type
|
@@ -24,11 +25,12 @@ module RbGCCXML
|
|
24
25
|
n.is_a?(Type) ? n.base_type : n
|
25
26
|
end
|
26
27
|
|
27
|
-
# Is this type
|
28
|
+
# Is this type const qualified?
|
28
29
|
def const?
|
29
30
|
found = XMLParsing.find_type_of(self.node, "type")
|
30
31
|
found ? found.const? : false
|
31
32
|
end
|
33
|
+
|
32
34
|
end
|
33
35
|
|
34
36
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RbGCCXML
|
2
|
+
|
3
|
+
# Node that represents <ArrayType>, which is any static array
|
4
|
+
# declaration.
|
5
|
+
# One oddity on how GCC-XML parses certain array designations:
|
6
|
+
#
|
7
|
+
# void func(int in[4][3]);
|
8
|
+
#
|
9
|
+
# will be parsed out as
|
10
|
+
#
|
11
|
+
# void func(int* in[3]);
|
12
|
+
#
|
13
|
+
# aka, a pointer to a 3-element array, so keep this in mind when doing
|
14
|
+
# comparisons or wondering why the to_cpp output is so odd
|
15
|
+
class ArrayType < Type
|
16
|
+
|
17
|
+
def ==(val)
|
18
|
+
check_sub_type_without(val, /\[\d\]/)
|
19
|
+
end
|
20
|
+
|
21
|
+
# See Node#to_cpp
|
22
|
+
def to_cpp(qualified = true)
|
23
|
+
type = XMLParsing.find_type_of(self.node, "type")
|
24
|
+
"#{type.to_cpp(qualified)}[#{self.node.attributes["max"].gsub(/[^\d]/, '').to_i + 1}]"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -1,20 +1,24 @@
|
|
1
1
|
module RbGCCXML
|
2
|
-
|
3
|
-
#
|
4
|
-
# const
|
2
|
+
|
3
|
+
# Represents a <CvQualifiedType> node. This node keeps track of
|
4
|
+
# the const nature of a Node.
|
5
5
|
class CvQualifiedType < Type
|
6
6
|
|
7
7
|
def ==(val)
|
8
8
|
check_sub_type_without(val, /const/)
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
# See Node#to_cpp
|
12
|
+
def to_cpp(qualified = true)
|
12
13
|
type = XMLParsing.find_type_of(self.node, "type")
|
13
|
-
"const #{type.
|
14
|
+
"const #{type.to_cpp(qualified)}"
|
14
15
|
end
|
15
16
|
|
17
|
+
# Is this node const?
|
16
18
|
def const?
|
17
19
|
self.node.attributes["const"].to_i == 1
|
18
20
|
end
|
21
|
+
|
19
22
|
end
|
23
|
+
|
20
24
|
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module RbGCCXML
|
2
|
-
|
2
|
+
|
3
|
+
# Represents a <FundamentalType>. This represents all the built-in types
|
3
4
|
# of C++ like int, double, char, etc.
|
4
5
|
class FundamentalType < Type
|
5
6
|
|
6
7
|
# We are base types. There's nothing
|
7
8
|
# more to find once we've gotten to this type.
|
8
|
-
def base_type
|
9
|
+
def base_type #:nodoc:
|
9
10
|
self
|
10
11
|
end
|
11
12
|
|