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.
98
99
100
101
|
# File 'lib/dub/argument.rb', line 98
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
64
|
# File 'lib/dub/argument.rb', line 57
def decision_tree(group)
hash = {}
group.each do |function|
insert_by_arg(hash, function)
end
print(hash.inspect) if group.first.name == 'bind'
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
68
69
70
71
72
73
74
75
|
# File 'lib/dub/argument.rb', line 68
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/dub/argument.rb', line 77
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)
183
184
185
|
# File 'lib/dub/argument.rb', line 183
def array_suffix
@array_suffix
end
|
#complex? ⇒ Boolean
158
159
160
161
|
# File 'lib/dub/argument.rb', line 158
def complex?
resolve_type if @template_params
@is_complex
end
|
#create_type ⇒ Object
171
172
173
174
175
176
177
178
179
|
# File 'lib/dub/argument.rb', line 171
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
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/dub/argument.rb', line 107
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
137
138
139
|
# File 'lib/dub/argument.rb', line 137
def has_default?
!@default.nil?
end
|
#id_name ⇒ Object
119
120
121
|
# File 'lib/dub/argument.rb', line 119
def id_name
full_type.gsub('::', '.')
end
|
#in_call_type ⇒ Object
187
188
189
|
# File 'lib/dub/argument.rb', line 187
def in_call_type
(is_native? || is_pointer?) ? name : "*#{name}"
end
|
#is_const? ⇒ Boolean
133
134
135
|
# File 'lib/dub/argument.rb', line 133
def is_const?
@const
end
|
#is_list? ⇒ Boolean
163
164
165
|
# File 'lib/dub/argument.rb', line 163
def is_list?
@is_list
end
|
#is_list_count? ⇒ Boolean
167
168
169
|
# File 'lib/dub/argument.rb', line 167
def is_list_count?
@is_list_count
end
|
#is_native? ⇒ Boolean
145
146
147
|
# File 'lib/dub/argument.rb', line 145
def is_native?
NATIVE_C_TYPES.include?(type)
end
|
#is_pointer? ⇒ Boolean
129
130
131
|
# File 'lib/dub/argument.rb', line 129
def is_pointer?
!@pointer.nil?
end
|
#is_ref? ⇒ Boolean
125
126
127
|
# File 'lib/dub/argument.rb', line 125
def is_ref?
@ref
end
|
#is_return_value? ⇒ Boolean
141
142
143
|
# File 'lib/dub/argument.rb', line 141
def is_return_value?
@is_return_value
end
|
#signature ⇒ Object
Also known as:
inspect
103
104
105
|
# File 'lib/dub/argument.rb', line 103
def signature
"#{is_const? ? 'const ' : ''}#{type}#{is_ref? ? '&' : ''}"
end
|
#vararg? ⇒ Boolean
154
155
156
|
# File 'lib/dub/argument.rb', line 154
def vararg?
@type == '...'
end
|