wrapture 0.4.2 → 0.5.0
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.
- checksums.yaml +4 -4
- data/bin/wrapture +4 -0
- data/lib/wrapture/class_spec.rb +19 -11
- data/lib/wrapture/comment.rb +5 -4
- data/lib/wrapture/constant_spec.rb +5 -5
- data/lib/wrapture/enum_spec.rb +4 -3
- data/lib/wrapture/errors.rb +0 -16
- data/lib/wrapture/function_spec.rb +36 -15
- data/lib/wrapture/struct_spec.rb +1 -1
- data/lib/wrapture/template_spec.rb +9 -6
- data/lib/wrapture/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a2ff7411136ffd84e6078406f6a4a8bf76cfaf0c2f1398d9409d019d29a6b8a
|
4
|
+
data.tar.gz: 8c91f45af881ad5f7f28b184d5d9d63ce9cabde0320af43303efb51764a2d458
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfb9b375f81fbfb6e75af4f52882fcff232ff5a9757732deb3446a1ae5b6de39cb1d4ddc2fd93d0c31f9fa3d9344e917119ad428a2040c2ec6415cdb002761ea
|
7
|
+
data.tar.gz: 936c998fd990eec6b580257b50a4e2d440ff9d6670c62250d1a38c6e42b7f70c1c7f8c02113a572388cd74beeeef7d235566d9bf89d90d028905eece199d2bc7
|
data/bin/wrapture
CHANGED
@@ -26,6 +26,10 @@ scope = Wrapture::Scope.new
|
|
26
26
|
ARGV.each do |spec_file|
|
27
27
|
spec = YAML.load_file(spec_file)
|
28
28
|
|
29
|
+
if spec.key?('version') && !Wrapture.supports_version?(spec['version'])
|
30
|
+
raise Wrapture::UnsupportedSpecVersion
|
31
|
+
end
|
32
|
+
|
29
33
|
spec.fetch('templates', []).each do |temp_spec|
|
30
34
|
scope << Wrapture::TemplateSpec.new(temp_spec)
|
31
35
|
end
|
data/lib/wrapture/class_spec.rb
CHANGED
@@ -350,9 +350,9 @@ module Wrapture
|
|
350
350
|
includes.uniq
|
351
351
|
end
|
352
352
|
|
353
|
-
#
|
354
|
-
def documentation
|
355
|
-
@doc&.format_as_doxygen(max_line_length: 78) { |line|
|
353
|
+
# Calls the given block for each line of the class documentation.
|
354
|
+
def documentation(&block)
|
355
|
+
@doc&.format_as_doxygen(max_line_length: 78) { |line| block.call(line) }
|
356
356
|
end
|
357
357
|
|
358
358
|
# Yields the declaration of the equivalent member if this class has one.
|
@@ -470,6 +470,18 @@ module Wrapture
|
|
470
470
|
@scope.overloads(self).map { |overload| "#{overload.name}.hpp" }
|
471
471
|
end
|
472
472
|
|
473
|
+
# The initializer for the pointer constructor, if one is available, or an
|
474
|
+
# empty string if not.
|
475
|
+
def parent_provides_initializer?
|
476
|
+
return false if !pointer_wrapper? || !child?
|
477
|
+
|
478
|
+
parent_spec = @scope.type(TypeSpec.new(parent_name))
|
479
|
+
|
480
|
+
!parent_spec.nil? &&
|
481
|
+
parent_spec.pointer_wrapper? &&
|
482
|
+
parent_spec.struct_name == @struct.name
|
483
|
+
end
|
484
|
+
|
473
485
|
# Yields the declaration of the pointer constructor for a class.
|
474
486
|
#
|
475
487
|
# If this class does not have an equivalent struct, or if there is already
|
@@ -523,15 +535,11 @@ module Wrapture
|
|
523
535
|
# The initializer for the pointer constructor, if one is available, or an
|
524
536
|
# empty string if not.
|
525
537
|
def pointer_constructor_initializer
|
526
|
-
if
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
parent_spec.struct_name == @struct.name
|
531
|
-
return ": #{parent_name}( equivalent ) " if parent_usable
|
538
|
+
if parent_provides_initializer?
|
539
|
+
": #{parent_name}( equivalent ) "
|
540
|
+
else
|
541
|
+
''
|
532
542
|
end
|
533
|
-
|
534
|
-
''
|
535
543
|
end
|
536
544
|
|
537
545
|
# The signature of the constructor given an equivalent strucct pointer.
|
data/lib/wrapture/comment.rb
CHANGED
@@ -57,11 +57,12 @@ module Wrapture
|
|
57
57
|
yield last_line if last_line
|
58
58
|
end
|
59
59
|
|
60
|
-
#
|
61
|
-
|
60
|
+
# Calls the given block for each line of the comment formatted using Doxygen
|
61
|
+
# style.
|
62
|
+
def format_as_doxygen(max_line_length: 80, &block)
|
62
63
|
format(line_prefix: ' * ', first_line: '/**',
|
63
64
|
last_line: ' */', max_line_length: max_line_length) do |line|
|
64
|
-
|
65
|
+
block.call(line)
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
@@ -93,7 +94,7 @@ module Wrapture
|
|
93
94
|
line.scan(/\S+/) do |word|
|
94
95
|
if running_line.length + word.length > line_length
|
95
96
|
yield running_line
|
96
|
-
running_line = word
|
97
|
+
running_line = String.new("#{word} ")
|
97
98
|
else
|
98
99
|
running_line << word << ' '
|
99
100
|
end
|
@@ -63,11 +63,11 @@ module Wrapture
|
|
63
63
|
@spec['includes'].dup
|
64
64
|
end
|
65
65
|
|
66
|
-
#
|
67
|
-
# documentation.
|
68
|
-
def declaration
|
69
|
-
@doc&.format_as_doxygen(max_line_length: 76) { |line|
|
70
|
-
|
66
|
+
# Calls the given block once for each line of the declaration of this
|
67
|
+
# constant, including any documentation.
|
68
|
+
def declaration(&block)
|
69
|
+
@doc&.format_as_doxygen(max_line_length: 76) { |line| block.call(line) }
|
70
|
+
block.call("static const #{@type.variable(@spec['name'])};")
|
71
71
|
end
|
72
72
|
|
73
73
|
# The definition of this constant.
|
data/lib/wrapture/enum_spec.rb
CHANGED
@@ -140,10 +140,11 @@ module Wrapture
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
#
|
144
|
-
|
143
|
+
# Calls the given block once for each line of the documentation for an
|
144
|
+
# element.
|
145
|
+
def element_doc(element, &block)
|
145
146
|
doc = Comment.new(element.fetch('doc', nil))
|
146
|
-
doc.format_as_doxygen(max_line_length: 74) { |line|
|
147
|
+
doc.format_as_doxygen(max_line_length: 74) { |line| block.call(line) }
|
147
148
|
end
|
148
149
|
|
149
150
|
# The header guard for the enumeration.
|
data/lib/wrapture/errors.rb
CHANGED
@@ -25,18 +25,10 @@ module Wrapture
|
|
25
25
|
|
26
26
|
# A documentation string is invalid.
|
27
27
|
class InvalidDoc < WraptureError
|
28
|
-
# Creates an InvalidDoc with the given message.
|
29
|
-
def initialize(message)
|
30
|
-
super(message)
|
31
|
-
end
|
32
28
|
end
|
33
29
|
|
34
30
|
# A template has been invoked in an unsupported way.
|
35
31
|
class InvalidTemplateUsage < WraptureError
|
36
|
-
# Creates an InvalidTemplateUsage with the given message.
|
37
|
-
def initialize(message)
|
38
|
-
super(message)
|
39
|
-
end
|
40
32
|
end
|
41
33
|
|
42
34
|
# The spec has a key that is not valid.
|
@@ -59,10 +51,6 @@ module Wrapture
|
|
59
51
|
|
60
52
|
# The spec is missing a key that is required.
|
61
53
|
class MissingSpecKey < WraptureError
|
62
|
-
# Creates a MissingSpecKey with the given message.
|
63
|
-
def initialize(message)
|
64
|
-
super(message)
|
65
|
-
end
|
66
54
|
end
|
67
55
|
|
68
56
|
# Missing a namespace in the class spec
|
@@ -71,10 +59,6 @@ module Wrapture
|
|
71
59
|
|
72
60
|
# The spec cannot be defined due to missing information.
|
73
61
|
class UndefinableSpec < WraptureError
|
74
|
-
# Creates an UndefinableSpec with error +message+.
|
75
|
-
def initialize(message)
|
76
|
-
super(message)
|
77
|
-
end
|
78
62
|
end
|
79
63
|
|
80
64
|
# The spec version is not supported by this version of Wrapture.
|
@@ -198,10 +198,10 @@ module Wrapture
|
|
198
198
|
"#{func_name}( #{param_list} )"
|
199
199
|
end
|
200
200
|
|
201
|
-
#
|
202
|
-
# documentation.
|
203
|
-
def declaration
|
204
|
-
doc.format_as_doxygen(max_line_length: 76) { |line|
|
201
|
+
# Calls the given block once for each line of the declaration of the
|
202
|
+
# function, including any documentation.
|
203
|
+
def declaration(&block)
|
204
|
+
doc.format_as_doxygen(max_line_length: 76) { |line| block.call(line) }
|
205
205
|
|
206
206
|
modifier_prefix = if @spec['static']
|
207
207
|
'static '
|
@@ -211,7 +211,7 @@ module Wrapture
|
|
211
211
|
''
|
212
212
|
end
|
213
213
|
|
214
|
-
|
214
|
+
block.call("#{modifier_prefix}#{return_expression};")
|
215
215
|
end
|
216
216
|
|
217
217
|
# Gives the definition of the function in a block, line by line.
|
@@ -237,7 +237,11 @@ module Wrapture
|
|
237
237
|
|
238
238
|
yield ' va_end( variadic_args );' if variadic?
|
239
239
|
|
240
|
-
|
240
|
+
if @return_type.self?
|
241
|
+
yield ' return *this;'
|
242
|
+
elsif @spec['return']['type'] != 'void' && !returns_call_directly?
|
243
|
+
yield ' return return_val;'
|
244
|
+
end
|
241
245
|
|
242
246
|
yield '}'
|
243
247
|
end
|
@@ -285,9 +289,11 @@ module Wrapture
|
|
285
289
|
|
286
290
|
private
|
287
291
|
|
288
|
-
#
|
289
|
-
|
290
|
-
|
292
|
+
# True if the return value of the wrapped call needs to be captured in a
|
293
|
+
# local variable.
|
294
|
+
def capture_return?
|
295
|
+
!@constructor &&
|
296
|
+
@wrapped.use_return? || returns_return_val?
|
291
297
|
end
|
292
298
|
|
293
299
|
# True if the provided wrapped param spec can be cast to when used in this
|
@@ -314,12 +320,17 @@ module Wrapture
|
|
314
320
|
def locals
|
315
321
|
yield 'va_list variadic_args;' if variadic?
|
316
322
|
|
317
|
-
if
|
323
|
+
if capture_return?
|
318
324
|
wrapped_type = resolve_type(@wrapped.return_val_type)
|
319
325
|
yield "#{wrapped_type.variable('return_val')};"
|
320
326
|
end
|
321
327
|
end
|
322
328
|
|
329
|
+
# The resolved type of the return type.
|
330
|
+
def resolved_return
|
331
|
+
@return_type.resolve(self)
|
332
|
+
end
|
333
|
+
|
323
334
|
# The function to use to create the return value of the function.
|
324
335
|
def return_cast(value)
|
325
336
|
if @return_type == @wrapped.return_val_type
|
@@ -340,10 +351,20 @@ module Wrapture
|
|
340
351
|
end
|
341
352
|
end
|
342
353
|
|
343
|
-
# True if the function returns the result of the wrapped function call
|
344
|
-
|
345
|
-
|
346
|
-
|
354
|
+
# True if the function returns the result of the wrapped function call
|
355
|
+
# directly without any after actions.
|
356
|
+
def returns_call_directly?
|
357
|
+
!@constructor &&
|
358
|
+
!@destructor &&
|
359
|
+
!%w[void self-reference].include?(@spec['return']['type']) &&
|
360
|
+
!@wrapped.error_check?
|
361
|
+
end
|
362
|
+
|
363
|
+
# True if the function returns the return_val variable.
|
364
|
+
def returns_return_val?
|
365
|
+
!@return_type.self? &&
|
366
|
+
@spec['return']['type'] != 'void' &&
|
367
|
+
!returns_call_directly?
|
347
368
|
end
|
348
369
|
|
349
370
|
# The expression containing the call to the underlying wrapped function.
|
@@ -354,7 +375,7 @@ module Wrapture
|
|
354
375
|
"this->equivalent = #{call}"
|
355
376
|
elsif @wrapped.error_check?
|
356
377
|
"return_val = #{call}"
|
357
|
-
elsif
|
378
|
+
elsif returns_call_directly?
|
358
379
|
"return #{return_cast(call)}"
|
359
380
|
else
|
360
381
|
call
|
data/lib/wrapture/struct_spec.rb
CHANGED
@@ -256,9 +256,10 @@ module Wrapture
|
|
256
256
|
# Replaces all instances of a parameter with the given name with the given
|
257
257
|
# value in the provided spec.
|
258
258
|
def self.replace_param!(spec, param_name, param_value)
|
259
|
-
|
259
|
+
case spec
|
260
|
+
when Hash
|
260
261
|
replace_param_in_hash(spec, param_name, param_value)
|
261
|
-
|
262
|
+
when Array
|
262
263
|
replace_param_in_array(spec, param_name, param_value)
|
263
264
|
else
|
264
265
|
spec
|
@@ -334,9 +335,10 @@ module Wrapture
|
|
334
335
|
# multiple replacements are needed, then you will need to call this function
|
335
336
|
# multiple times.
|
336
337
|
def replace_uses(spec)
|
337
|
-
|
338
|
+
case spec
|
339
|
+
when Hash
|
338
340
|
replace_uses_in_hash(spec)
|
339
|
-
|
341
|
+
when Array
|
340
342
|
replace_uses_in_array(spec)
|
341
343
|
else
|
342
344
|
false
|
@@ -348,9 +350,10 @@ module Wrapture
|
|
348
350
|
return false unless spec.is_a?(Hash) && spec.key?(TEMPLATE_USE_KEYWORD)
|
349
351
|
|
350
352
|
invocation = spec[TEMPLATE_USE_KEYWORD]
|
351
|
-
|
353
|
+
case invocation
|
354
|
+
when String
|
352
355
|
invocation == name
|
353
|
-
|
356
|
+
when Hash
|
354
357
|
unless invocation.key?('name')
|
355
358
|
error_message = "invocations of #{TEMPLATE_USE_KEYWORD} must have a "\
|
356
359
|
'name member'
|
data/lib/wrapture/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrapture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Anderson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 1.6.4
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '2.
|
22
|
+
version: '2.3'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 1.6.4
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '2.
|
32
|
+
version: '2.3'
|
33
33
|
description: Wraps C code in C++.
|
34
34
|
email: joelanderson333@gmail.com
|
35
35
|
executables:
|
@@ -56,12 +56,12 @@ files:
|
|
56
56
|
- lib/wrapture/type_spec.rb
|
57
57
|
- lib/wrapture/version.rb
|
58
58
|
- lib/wrapture/wrapped_function_spec.rb
|
59
|
-
homepage:
|
59
|
+
homepage: https://goatshriek.github.io/wrapture/
|
60
60
|
licenses:
|
61
61
|
- Apache-2.0
|
62
62
|
metadata:
|
63
63
|
bug_tracker_uri: https://github.com/goatshriek/wrapture/issues
|
64
|
-
changelog_uri: https://github.com/goatshriek/wrapture/blob/
|
64
|
+
changelog_uri: https://github.com/goatshriek/wrapture/blob/latest/ChangeLog.md
|
65
65
|
documentation_uri: https://goatshriek.github.io/wrapture/rdoc/
|
66
66
|
source_code_uri: https://github.com/goatshriek/wrapture/
|
67
67
|
post_install_message:
|
@@ -72,14 +72,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '2.
|
75
|
+
version: '2.4'
|
76
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
78
|
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
|
-
rubygems_version: 3.1
|
82
|
+
rubygems_version: 3.2.1
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: wrap C in C++
|