wrapture 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b96407ba9b0bc6b336041a035ad5f383d624a5f54b251ddeea0047c3e17bbfb
4
- data.tar.gz: 4443073a21063dc4c448a378df1179422ce3bc3353ce47b68586538af491d2b3
3
+ metadata.gz: 5a2ff7411136ffd84e6078406f6a4a8bf76cfaf0c2f1398d9409d019d29a6b8a
4
+ data.tar.gz: 8c91f45af881ad5f7f28b184d5d9d63ce9cabde0320af43303efb51764a2d458
5
5
  SHA512:
6
- metadata.gz: 78143a9ca60a5f041b9cabe35814cd609bbdce55384e37f83cfc7eee9c9c0c0d7714754e6ced7f1bd29f5f16b5840f2c7674dc85558135a92b3a06c33bd614c4
7
- data.tar.gz: ff53c37bac35253b8df395606fecf81ef4587bc03fd2531d36908f07dad33ba52e6c62981f6bd458a4027de73fd063b360219b796aa00f9ac46c9bce4292d7e8
6
+ metadata.gz: cfb9b375f81fbfb6e75af4f52882fcff232ff5a9757732deb3446a1ae5b6de39cb1d4ddc2fd93d0c31f9fa3d9344e917119ad428a2040c2ec6415cdb002761ea
7
+ data.tar.gz: 936c998fd990eec6b580257b50a4e2d440ff9d6670c62250d1a38c6e42b7f70c1c7f8c02113a572388cd74beeeef7d235566d9bf89d90d028905eece199d2bc7
@@ -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
@@ -350,9 +350,9 @@ module Wrapture
350
350
  includes.uniq
351
351
  end
352
352
 
353
- # Yields the class documentation one line at a time.
354
- def documentation
355
- @doc&.format_as_doxygen(max_line_length: 78) { |line| yield 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 pointer_wrapper? && child?
527
- parent_spec = @scope.type(TypeSpec.new(parent_name))
528
- parent_usable = !parent_spec.nil? &&
529
- parent_spec.pointer_wrapper? &&
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.
@@ -57,11 +57,12 @@ module Wrapture
57
57
  yield last_line if last_line
58
58
  end
59
59
 
60
- # Yields each line of the comment formatted using Doxygen style.
61
- def format_as_doxygen(max_line_length: 80)
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
- yield line
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
- # Yields each line of the declaration of this constant, including any
67
- # documentation.
68
- def declaration
69
- @doc&.format_as_doxygen(max_line_length: 76) { |line| yield line }
70
- yield "static const #{@type.variable(@spec['name'])};"
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.
@@ -140,10 +140,11 @@ module Wrapture
140
140
  end
141
141
  end
142
142
 
143
- # Yields each line of the documentation for an element.
144
- def element_doc(element)
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| yield 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.
@@ -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
- # Yields each line of the declaration of the function, including any
202
- # documentation.
203
- def declaration
204
- doc.format_as_doxygen(max_line_length: 76) { |line| yield 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
- yield "#{modifier_prefix}#{return_expression};"
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
- yield ' return *this;' if @return_type.self?
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
- # The resolved type of the return type.
289
- def resolved_return
290
- @return_type.resolve(self)
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 @wrapped.use_return? && !@constructor
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
- def returns_call_result?
345
- !@constructor && !@destructor &&
346
- !%w[void self-reference].include?(@spec['return']['type'])
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 returns_call_result?
378
+ elsif returns_call_directly?
358
379
  "return #{return_cast(call)}"
359
380
  else
360
381
  call
@@ -88,7 +88,7 @@ module Wrapture
88
88
 
89
89
  member_str += ' = '
90
90
  member_str += if member['type'] == 'const char *'
91
- '"' + default_value + '"'
91
+ "\"#{default_value}\""
92
92
  elsif member['type'].end_with?('char')
93
93
  "'#{default_value}'"
94
94
  else
@@ -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
- if spec.is_a?(Hash)
259
+ case spec
260
+ when Hash
260
261
  replace_param_in_hash(spec, param_name, param_value)
261
- elsif spec.is_a?(Array)
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
- if spec.is_a?(Hash)
338
+ case spec
339
+ when Hash
338
340
  replace_uses_in_hash(spec)
339
- elsif spec.is_a?(Array)
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
- if invocation.is_a?(String)
353
+ case invocation
354
+ when String
352
355
  invocation == name
353
- elsif invocation.is_a?(Hash)
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'
@@ -20,7 +20,7 @@
20
20
 
21
21
  module Wrapture
22
22
  # the current version of Wrapture
23
- VERSION = '0.4.2'
23
+ VERSION = '0.5.0'
24
24
 
25
25
  # Returns true if the version of the spec is supported by this version of
26
26
  # Wrapture. Otherwise returns false.
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.2
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-05-11 00:00:00.000000000 Z
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.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.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: http://rubygems.org/gems/wrapture
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/master/ChangeLog.md
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.3'
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.3
82
+ rubygems_version: 3.2.1
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: wrap C in C++