wrapture 0.4.1 → 0.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a5516a3af955bee34acada560a1c0f67e4a7f6b07772e0fc27accf82103377e
4
- data.tar.gz: ddba6f0862fcde505a9f7501b95ddf22acdffc6f9b4fed15a8fc5b0d3afdcf42
3
+ metadata.gz: 8b96407ba9b0bc6b336041a035ad5f383d624a5f54b251ddeea0047c3e17bbfb
4
+ data.tar.gz: 4443073a21063dc4c448a378df1179422ce3bc3353ce47b68586538af491d2b3
5
5
  SHA512:
6
- metadata.gz: c770a67468d131f448a1640a9f2f76ce7e089bbf42980443cd70ce9388d581d1066e6c4435419bda81c442f4e09a838a52986f6661cf52791ca57cda88ddbb66
7
- data.tar.gz: 27fc54ad64f8375c6815fb9b3263050f551d5a180089c1aa733833ef8a1d80bc3a9e625be74e990645dbd3db9fe78fac466bf90599a80c140e9d88bf05a1e2da
6
+ metadata.gz: 78143a9ca60a5f041b9cabe35814cd609bbdce55384e37f83cfc7eee9c9c0c0d7714754e6ced7f1bd29f5f16b5840f2c7674dc85558135a92b3a06c33bd614c4
7
+ data.tar.gz: ff53c37bac35253b8df395606fecf81ef4587bc03fd2531d36908f07dad33ba52e6c62981f6bd458a4027de73fd063b360219b796aa00f9ac46c9bce4292d7e8
@@ -40,8 +40,8 @@ module Wrapture
40
40
  raise(InvalidSpecKey, extra_msg)
41
41
  end
42
42
 
43
- includes = Wrapture.normalize_includes(spec['constructor']['includes'])
44
- normalized['constructor']['includes'] = includes
43
+ func_spec = WrappedFunctionSpec.normalize_spec_hash(spec['constructor'])
44
+ normalized['constructor'] = func_spec
45
45
 
46
46
  normalized
47
47
  end
@@ -36,5 +36,6 @@ module Wrapture
36
36
 
37
37
  # A list of all keywords.
38
38
  KEYWORDS = [EQUIVALENT_STRUCT_KEYWORD, EQUIVALENT_POINTER_KEYWORD,
39
- RETURN_VALUE_KEYWORD, TEMPLATE_USE_KEYWORD].freeze
39
+ SELF_REFERENCE_KEYWORD, RETURN_VALUE_KEYWORD,
40
+ TEMPLATE_USE_KEYWORD].freeze
40
41
  end
@@ -228,7 +228,9 @@ module Wrapture
228
228
  yield
229
229
  yield " #{wrapped_call_expression};"
230
230
  yield
231
- @wrapped.error_check { |line| yield " #{line}" }
231
+ @wrapped.error_check(return_val: return_variable) do |line|
232
+ yield " #{line}"
233
+ end
232
234
  else
233
235
  yield " #{wrapped_call_expression};"
234
236
  end
@@ -311,17 +313,30 @@ module Wrapture
311
313
  # Yields a declaration of each local variable used by the function.
312
314
  def locals
313
315
  yield 'va_list variadic_args;' if variadic?
314
- yield "#{@wrapped.return_val_type} return_val;" if @wrapped.error_check?
316
+
317
+ if @wrapped.use_return? && !@constructor
318
+ wrapped_type = resolve_type(@wrapped.return_val_type)
319
+ yield "#{wrapped_type.variable('return_val')};"
320
+ end
315
321
  end
316
322
 
317
323
  # The function to use to create the return value of the function.
318
324
  def return_cast(value)
319
- if @spec['return']['type'] == @wrapped.return_val_type
325
+ if @return_type == @wrapped.return_val_type
320
326
  value
321
327
  elsif @spec['return']['overloaded']
322
328
  "new#{@spec['return']['type'].chomp('*').strip} ( #{value} )"
323
329
  else
324
- "#{@spec['return']['type']} ( #{value} )"
330
+ resolved_return.cast_expression(value)
331
+ end
332
+ end
333
+
334
+ # The name of the variable holding the return value.
335
+ def return_variable
336
+ if @constructor
337
+ 'this->equivalent'
338
+ else
339
+ 'return_val'
325
340
  end
326
341
  end
327
342
 
@@ -64,20 +64,36 @@ module Wrapture
64
64
  normalized
65
65
  end
66
66
 
67
- # Creates a rule spec based on the provided spec.
67
+ # Creates a rule spec based on the provided spec. Rules may be one of a
68
+ # number of different varieties.
68
69
  #
69
- # The hash must have the following keys:
70
+ # Available conditions are available in the RuleSpec::CONDITIONS map, with
71
+ # the mapped values being the operate each one translates to.
72
+ #
73
+ # For a rule that checks a struct member against a given value (a
74
+ # +struct-member+ rule):
70
75
  # member-name:: the name of the struct member the rule applies to
71
- # condition:: the condition this rule uses (supported values are keys in the
72
- # RuleSpec::CONDITIONS map, with the mapped values being the
73
- # operator they translate to)
76
+ # condition:: the condition this rule uses
74
77
  # value:: the value to use in the condition check
78
+ #
79
+ # For a rule that compares two expressions against one another (an
80
+ # +expression+ rule):
81
+ # left-expression:: the left expression in the comparison
82
+ # condition:: the condition this rule uses
83
+ # right-expression:: the right expression in the comparison
75
84
  def initialize(spec)
76
85
  @spec = RuleSpec.normalize_spec_hash(spec)
77
86
  end
78
87
 
79
88
  # A string containing a check for a struct of the given name for this rule.
80
- def check(variable: nil)
89
+ #
90
+ # +variable+ can be provided to provide the variable holding a struct
91
+ # pointer for +struct-member+ rules.
92
+ #
93
+ # +return_val+ is used as the replacement for a return value signified by
94
+ # the use of RETURN_VALUE_KEYWORD in the spec. If not specified it defaults
95
+ # to +'return_val'+. This parameter was added in release 0.4.2.
96
+ def check(variable: nil, return_val: 'return_val')
81
97
  condition = RuleSpec::CONDITIONS[@spec['condition']]
82
98
 
83
99
  if @spec['type'] == 'struct-member'
@@ -85,8 +101,18 @@ module Wrapture
85
101
  else
86
102
  left = @spec['left-expression']
87
103
  right = @spec['right-expression']
88
- "#{left} #{condition} #{right}".sub(RETURN_VALUE_KEYWORD, 'return_val')
104
+ "#{left} #{condition} #{right}".sub(RETURN_VALUE_KEYWORD, return_val)
89
105
  end
90
106
  end
107
+
108
+ # True if this rule requires a return value. This is equivalent to checking
109
+ # for the presence of RETURN_VALUE_KEYWORD in any of the expressions.
110
+ #
111
+ # This method was added in release 0.4.2.
112
+ def use_return?
113
+ @spec['type'] == 'expression' &&
114
+ [@spec['left-expression'],
115
+ @spec['right-expression']].include?(RETURN_VALUE_KEYWORD)
116
+ end
91
117
  end
92
118
  end
@@ -54,11 +54,26 @@ module Wrapture
54
54
  @spec = TypeSpec.normalize_spec_hash(actual_spec)
55
55
  end
56
56
 
57
+ # Compares this TypeSpec with +other+. Comparison happens by converting each
58
+ # object to a string using to_s and comparing.
59
+ #
60
+ # Added in release 0.4.2.
61
+ def ==(other)
62
+ to_s == other.to_s
63
+ end
64
+
57
65
  # The name of this type with all special characters removed.
58
66
  def base
59
67
  name.delete('*&').strip
60
68
  end
61
69
 
70
+ # An expression casting the result of a given expression into this type.
71
+ #
72
+ # Added in release 0.4.2.
73
+ def cast_expression(expression)
74
+ "( #{variable} )( #{expression} )"
75
+ end
76
+
62
77
  # True if this type is an equivalent struct pointer reference.
63
78
  def equivalent_pointer?
64
79
  name == EQUIVALENT_POINTER_KEYWORD
@@ -132,6 +147,13 @@ module Wrapture
132
147
  name == SELF_REFERENCE_KEYWORD
133
148
  end
134
149
 
150
+ # Gives a string representation of this type (its name).
151
+ #
152
+ # Added in release 0.4.2.
153
+ def to_s
154
+ name
155
+ end
156
+
135
157
  # A string with a declaration of a variable named +var_name+ of this type.
136
158
  # If +var_name+ is nil then this will simply be a type declaration.
137
159
  def variable(var_name = nil)
@@ -20,7 +20,7 @@
20
20
 
21
21
  module Wrapture
22
22
  # the current version of Wrapture
23
- VERSION = '0.4.1'
23
+ VERSION = '0.4.2'
24
24
 
25
25
  # Returns true if the version of the spec is supported by this version of
26
26
  # Wrapture. Otherwise returns false.
@@ -88,10 +88,14 @@ module Wrapture
88
88
  # Yields each line of the error check and any actions taken for this wrapped
89
89
  # function. If this function does not have any error check defined, then
90
90
  # this function returns without yielding anything.
91
- def error_check
91
+ #
92
+ # +return_val+ is used as the replacement for a return value signified by
93
+ # the use of RETURN_VALUE_KEYWORD in the spec. If not specified it defaults
94
+ # to +'return_val'+. This parameter was added in release 0.4.2.
95
+ def error_check(return_val: 'return_val')
92
96
  return if @error_rules.empty?
93
97
 
94
- checks = @error_rules.map(&:check)
98
+ checks = @error_rules.map { |rule| rule.check(return_val: return_val) }
95
99
  yield "if( #{checks.join(' && ')} ){"
96
100
  yield " #{@error_action.take};"
97
101
  yield '}'
@@ -111,9 +115,20 @@ module Wrapture
111
115
  includes
112
116
  end
113
117
 
114
- # A string with the type of the return value.
118
+ # A TypeSpec describing the type of the return value.
119
+ #
120
+ # Changed in release 0.4.2 to return a TypeSpec instead of a String.
115
121
  def return_val_type
116
- @spec['return']['type']
122
+ TypeSpec.new(@spec['return']['type'])
123
+ end
124
+
125
+ # True if calling this wrapped function needs to save/use the return value
126
+ # for error checking. This is equivalent to checking all error rules for the
127
+ # use of RETURN_VALUE_KEYWORD.
128
+ #
129
+ # This method was added in release 0.4.2.
130
+ def use_return?
131
+ @error_rules.any?(&:use_return?)
117
132
  end
118
133
  end
119
134
  end
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.1
4
+ version: 0.4.2
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-04-24 00:00:00.000000000 Z
11
+ date: 2020-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.1.2
82
+ rubygems_version: 3.1.3
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: wrap C in C++