Class: Dub::Argument
Constant Summary
collapse
- TYPE_REGEXP =
%r{^\s*(\w+\s+|)(const\s+|)([\w\:]+|\.\.\.)(\s*<(.+)>|)(\s*\*+|\s*&|)$}
- NUMBER_TYPES =
[
'float',
'double',
'size_t',
'unsigned int',
'uint',
'int',
'size_t',
'time_t',
'unsigned int',
'uint',
'bool',
'uchar',
'void',
'int64',
]
- STRING_TYPES =
[
'char',
]
- BOOL_TYPES =
[
'bool',
]
- NATIVE_C_TYPES =
NUMBER_TYPES + STRING_TYPES + BOOL_TYPES
EntitiesUnescape::Decoder
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#unescape
Constructor Details
#initialize(function, xml, arg_pos = nil) ⇒ Argument
Returns a new instance of Argument.
97
98
99
100
|
# File 'lib/dub/argument.rb', line 97
def initialize(function, xml, arg_pos = nil)
@function, @xml, @argument_position = function, xml, arg_pos
parse_xml
end
|
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
6
7
8
|
# File 'lib/dub/argument.rb', line 6
def default
@default
end
|
#function ⇒ Object
Returns the value of attribute function.
6
7
8
|
# File 'lib/dub/argument.rb', line 6
def function
@function
end
|
#is_list ⇒ Object
Returns the value of attribute is_list.
7
8
9
|
# File 'lib/dub/argument.rb', line 7
def is_list
@is_list
end
|
#is_list_count ⇒ Object
Returns the value of attribute is_list_count.
7
8
9
|
# File 'lib/dub/argument.rb', line 7
def is_list_count
@is_list_count
end
|
#name ⇒ Object
Returns the value of attribute name.
6
7
8
|
# File 'lib/dub/argument.rb', line 6
def name
@name
end
|
#type ⇒ Object
Returns the value of attribute type.
7
8
9
|
# File 'lib/dub/argument.rb', line 7
def type
@type
end
|
#xml ⇒ Object
Returns the value of attribute xml.
6
7
8
|
# File 'lib/dub/argument.rb', line 6
def xml
@xml
end
|
Class Method Details
.decision_tree(group) ⇒ Object
group is a list of functions, index = argument index
57
58
59
60
61
62
63
|
# File 'lib/dub/argument.rb', line 57
def decision_tree(group)
hash = {}
group.each do |function|
insert_by_arg(hash, function)
end
hash
end
|
.insert_by_arg(hash, function, index = 0) ⇒ Object
Insert a function into the hash, using the argument at the given index to filter
67
68
69
70
71
72
73
74
|
# File 'lib/dub/argument.rb', line 67
def insert_by_arg(hash, function, index = 0)
arg = function.arguments[index]
type = arg ? type_group(arg) : nil
insert_by_type(hash, function, index, type)
if arg && arg.has_default?
insert_by_type(hash, function, index, nil)
end
end
|
.insert_by_type(hash, function, index, type) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/dub/argument.rb', line 76
def insert_by_type(hash, function, index, type)
slot = hash[type]
if slot.nil?
hash[type] = function
elsif slot.kind_of?(Hash)
insert_by_arg(slot, function, index + 1)
elsif type.nil?
else
h = {}
insert_by_arg(h, slot, index + 1)
insert_by_arg(h, function, index + 1)
hash[type] = h
end
end
|
.type_group(arg) ⇒ Object
This is used to resolve overloaded functions
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/dub/argument.rb', line 39
def type_group(arg)
if NATIVE_C_TYPES.include?(arg.type)
if BOOL_TYPES.include?(arg.type)
:boolean
elsif STRING_TYPES.include?(arg.type) && arg.is_pointer?
:string
else
arg.is_pointer? ? :number_ptr : :number
end
else
arg.id_name
end
end
|
Instance Method Details
#array_suffix ⇒ Object
this is for the cases where we have signatures like HuMoments(double moments)
182
183
184
|
# File 'lib/dub/argument.rb', line 182
def array_suffix
@array_suffix
end
|
#complex? ⇒ Boolean
157
158
159
160
|
# File 'lib/dub/argument.rb', line 157
def complex?
resolve_type if @template_params
@is_complex
end
|
#create_type ⇒ Object
170
171
172
173
174
175
176
177
178
|
# File 'lib/dub/argument.rb', line 170
def create_type
resolve_type if @template_params
(is_const? ? 'const ' : '') +
if (is_return_value? && !is_pointer?) || (is_native? && !is_pointer?)
"#{type} "
else
"#{type} *"
end
end
|
#full_type ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/dub/argument.rb', line 106
def full_type
if type =~ /::/
type
else
container = function.parent
if container.kind_of?(Klass)
container = container.parent
end
container ? "#{container.name}::#{type}" : type
end
end
|
#has_default? ⇒ Boolean
136
137
138
|
# File 'lib/dub/argument.rb', line 136
def has_default?
!@default.nil?
end
|
#id_name ⇒ Object
118
119
120
|
# File 'lib/dub/argument.rb', line 118
def id_name
full_type.gsub('::', '.')
end
|
#in_call_type ⇒ Object
186
187
188
|
# File 'lib/dub/argument.rb', line 186
def in_call_type
(is_native? || is_pointer?) ? name : "*#{name}"
end
|
#is_const? ⇒ Boolean
132
133
134
|
# File 'lib/dub/argument.rb', line 132
def is_const?
@const
end
|
#is_list? ⇒ Boolean
162
163
164
|
# File 'lib/dub/argument.rb', line 162
def is_list?
@is_list
end
|
#is_list_count? ⇒ Boolean
166
167
168
|
# File 'lib/dub/argument.rb', line 166
def is_list_count?
@is_list_count
end
|
#is_native? ⇒ Boolean
144
145
146
|
# File 'lib/dub/argument.rb', line 144
def is_native?
NATIVE_C_TYPES.include?(type)
end
|
#is_pointer? ⇒ Boolean
128
129
130
|
# File 'lib/dub/argument.rb', line 128
def is_pointer?
!@pointer.nil?
end
|
#is_ref? ⇒ Boolean
124
125
126
|
# File 'lib/dub/argument.rb', line 124
def is_ref?
@ref
end
|
#is_return_value? ⇒ Boolean
140
141
142
|
# File 'lib/dub/argument.rb', line 140
def is_return_value?
@is_return_value
end
|
#signature ⇒ Object
Also known as:
inspect
102
103
104
|
# File 'lib/dub/argument.rb', line 102
def signature
"#{is_const? ? 'const ' : ''}#{type}#{is_ref? ? '&' : ''}"
end
|
#vararg? ⇒ Boolean
153
154
155
|
# File 'lib/dub/argument.rb', line 153
def vararg?
@type == '...'
end
|