autoc 2.0.1 → 2.0.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: 63b8d589357ec8f39556052ab6f23730e6a884620fe20dc32cb1d37707af9500
4
- data.tar.gz: ccf9cc7c3183b92851edcac67e4d79f8ab42b0e927ca561a2e3038a9d1d74f74
3
+ metadata.gz: e1800467846d30e1b98d5f124f250ef87f9adf1aab5f319f7593dcd8a6d4e8ea
4
+ data.tar.gz: de7e6b5457c9bf747df18b86b5c06d05b065c11d13649709f2f02b7eb4eedb11
5
5
  SHA512:
6
- metadata.gz: fb3a6280555ff59a3249d6b1081f69df54106249b988bf8c81d46ca4537e70d55e7634f5f755db83f893bfa03cc4dfb85f12cc60de91ae4808cef7a08733cd83
7
- data.tar.gz: b4939c6e87831c8ee72efa5dbd0489105b638e16b92fdba2a8b1eb5d8e5c5ba13cfeef8edc4b3ef4640c910b82fe153d28afaf2756e8cb78a461a09caef66d01
6
+ metadata.gz: 476a8dac04a57b7e313232b904f73297a4e5d76a0919423535f356c29fa4b48690941d04f75f79a623bac23076c2ec56f4d2f20d0d72ecfbb24ad24eb9f3b06c
7
+ data.tar.gz: e449fbe1e182aa541bc7bc861e4f653c5b7b23b0eb7f99dfbb769e7c44e6ef210df0e4ad8e1c2799ed99121ed0b71411c280a28ae8183a7a369fa60908132a9a
data/CHANGES.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 2.0.2
2
+
3
+ - Introduce private visibility specifier for functions.
4
+
5
+ - Fix missing constraint checks in custom constructors.
6
+
7
+ - Documentation tags streamlining.
8
+
1
9
  # 2.0.1
2
10
 
3
11
  - Introduce switch for incremental module generation mode.
@@ -18,7 +18,7 @@ module AutoC
18
18
  # @abstract
19
19
  class Composite < Type
20
20
 
21
- PRIVATE = '/** @private */'
21
+ PRIVATE = "\n/** @private */\n"
22
22
 
23
23
  include STD
24
24
 
@@ -67,6 +67,10 @@ module AutoC
67
67
 
68
68
  def public? = @visibility == :public
69
69
 
70
+ def private? = @visibility == :private
71
+
72
+ def internal? = @visibility == :internal
73
+
70
74
  def respond_to_missing?(meth, include_private = false) = @methods.has_key?(meth) ? true : super
71
75
 
72
76
  def type_tag = signature
@@ -95,40 +99,41 @@ module AutoC
95
99
 
96
100
  self.hasher = Hasher.instance # Default cycle-xor hasher
97
101
 
98
- # Pluggable CamelCase identifier decorator
99
- CAMEL_CASE_DECORATOR = -> (type, symbol, abbreviate: false, **kws) {
100
- id = symbol.to_s.sub(/[!?]$/, '') # Strip trailing !?
101
- _ = # Check for leading underscore
102
- if /^(_+)(.*)/ =~ id
103
- id = Regexp.last_match(2) # Chop leading underscore
104
- true
105
- else
106
- false
107
- end
108
- id = id[0] if abbreviate
109
- # Convert _separated_names to the CamelCase
110
- id = type.prefix + id.split('_').collect{ |s| s[0].upcase << s[1..-1] }.join
111
- # Carry over the method name's leading underscore only if the prefix is not in turn underscored
112
- _ && !type.prefix.start_with?('_') ? Regexp.last_match(1) + id : id
113
- }
114
-
115
- # Pluggable _snake_case identifier decorator
116
- SNAKE_CASE_DECORATOR = -> (type, symbol, abbreviate: false, **kws) {
117
- id = symbol.to_s.sub(/[!?]$/, '') # Strip trailing !?
118
- # Check for leading underscore
119
- _ =
120
- if /^(_+)(.*)/ =~ id
121
- id = Regexp.last_match(2)
122
- true
123
- else
124
- false
125
- end
126
- id = abbreviate ? "#{type.prefix}#{id[0]}" : "#{type.prefix}_#{id}"
127
- # Carry over the method name's leading underscore only if the prefix is not in turn underscored
128
- _ && !type.prefix.start_with?('_') ? Regexp.last_match(1) + id : id
129
- }
130
-
131
- self.decorator = CAMEL_CASE_DECORATOR
102
+ module Decorator
103
+ # Pluggable CamelCase identifier decorator
104
+ CAMEL_CASE = -> (type, symbol, abbreviate: false, **kws) {
105
+ id = symbol.to_s.sub(/[!?]$/, '') # Strip trailing !?
106
+ _ = # Check for leading underscore
107
+ if /^(_+)(.*)/ =~ id
108
+ id = Regexp.last_match(2) # Chop leading underscore
109
+ true
110
+ else
111
+ false
112
+ end
113
+ id = id[0] if abbreviate
114
+ # Convert _separated_names to the CamelCase
115
+ id = type.prefix + id.split('_').collect{ |s| s[0].upcase << s[1..-1] }.join
116
+ # Carry over the method name's leading underscore only if the prefix is not in turn underscored
117
+ _ && !type.prefix.start_with?('_') ? Regexp.last_match(1) + id : id
118
+ }
119
+ # Pluggable _snake_case identifier decorator
120
+ SNAKE_CASE = -> (type, symbol, abbreviate: false, **kws) {
121
+ id = symbol.to_s.sub(/[!?]$/, '') # Strip trailing !?
122
+ # Check for leading underscore
123
+ _ =
124
+ if /^(_+)(.*)/ =~ id
125
+ id = Regexp.last_match(2)
126
+ true
127
+ else
128
+ false
129
+ end
130
+ id = abbreviate ? "#{type.prefix}#{id[0]}" : "#{type.prefix}_#{id}"
131
+ # Carry over the method name's leading underscore only if the prefix is not in turn underscored
132
+ _ && !type.prefix.start_with?('_') ? Regexp.last_match(1) + id : id
133
+ }
134
+ end # Decorator
135
+
136
+ self.decorator = Decorator::CAMEL_CASE
132
137
 
133
138
  private
134
139
 
@@ -294,6 +299,8 @@ module AutoC
294
299
  #{@header}
295
300
  */
296
301
  }
302
+ else
303
+ stream << Composite::PRIVATE
297
304
  end
298
305
  end
299
306
 
data/lib/autoc/cstring.rb CHANGED
@@ -76,7 +76,7 @@ module AutoC
76
76
 
77
77
  def configure
78
78
  super
79
- method(:void, :create, { target: lvalue, source: const_rvalue }, instance: :custom_create).configure do
79
+ method(:void, :create, { target: lvalue, source: const_rvalue }, instance: :custom_create, constraint:-> { custom_constructible? }).configure do
80
80
  header %{
81
81
  @brief Create string
82
82
 
@@ -4,6 +4,7 @@
4
4
  require 'autoc/type'
5
5
  require 'autoc/module'
6
6
  require 'autoc/primitive'
7
+ require 'autoc/composite'
7
8
 
8
9
 
9
10
  module AutoC
@@ -134,15 +135,19 @@ module AutoC
134
135
 
135
136
  def public? = @visibility == :public
136
137
 
138
+ def private? = @visibility == :private
139
+
140
+ def internal? = @visibility == :internal
141
+
137
142
  def abstract? = @abstract == true
138
143
 
139
144
  def variadic? = @variadic == true
140
145
 
141
146
  def live? = (@constraint.is_a?(Proc) ? @constraint.() : @constraint) == true
142
147
 
143
- def signature = '%s(%s)' % [result.signature, (parameters.to_a.collect(&:signature) << (variadic? ? '...' : nil)).compact.join(',')]
148
+ def signature = '%s(%s)' % [result, (parameters.to_a.collect(&:signature) << (variadic? ? '...' : nil)).compact.join(',')]
144
149
 
145
- def prototype = '%s %s(%s)' % [result.signature, name, (parameters.to_a.collect(&:declaration) << (variadic? ? '...' : nil)).compact.join(',')]
150
+ def prototype = '%s %s(%s)' % [result, name, (parameters.to_a.collect(&:declaration) << (variadic? ? '...' : nil)).compact.join(',')]
146
151
 
147
152
  def definition = '%s {%s}' % [prototype, @code]
148
153
 
@@ -183,16 +188,20 @@ module AutoC
183
188
 
184
189
  # Render the commentary block preceding the function declaration, both inline or external
185
190
  def render_function_header(stream)
186
- stream << %{
187
- /* #{@header} */
188
- } unless @header.nil?
191
+ if public?
192
+ stream << %{
193
+ /* #{@header} */
194
+ } unless @header.nil?
195
+ else
196
+ stream << Composite::PRIVATE
197
+ end
189
198
  end
190
199
 
191
200
  # Render full function declaration statement including the commentary block
192
201
  # For inline functions this also renders a function body effectively making this also a function definition
193
202
  # The declaration comes into either public interface of forward declaration block depending on the function's visibility status
194
203
  def render_function_declaration(stream)
195
- render_function_header(stream)
204
+ render_function_header(stream) if @render_interface
196
205
  render_declaration_specifier(stream)
197
206
  if inline?
198
207
  render_function_definition(stream)
@@ -211,18 +220,22 @@ module AutoC
211
220
  end
212
221
 
213
222
  # Render function's public interface
214
- # Only public functions are rendered
223
+ # Render non-internal function declarations
224
+ # @render_interface is used internally to distinguish header-time rendering from source-time rendering
215
225
  def render_interface(stream)
216
- render_function_declaration(stream) if live? && public?
226
+ @render_interface = true
227
+ render_function_declaration(stream) if live? && (public? || private?)
217
228
  end
218
229
 
219
230
  # Render function's interface for non-public functions which should not appear in the public interface
220
231
  def render_forward_declarations(stream)
221
- render_function_declaration(stream) if live? && !public?
232
+ @render_interface = false
233
+ render_function_declaration(stream) if live? && !(public? || private?)
222
234
  end
223
235
 
224
236
  # Render non-inline function definition regardless of function's visibility status
225
237
  def render_implementation(stream)
238
+ @render_interface = false
226
239
  render_function_definition(stream) if live? && !inline?
227
240
  end
228
241
 
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
 
4
+ require 'autoc/std'
4
5
  require 'autoc/record'
5
6
  require 'autoc/hash_set'
6
7
  require 'autoc/association'
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
 
4
- require 'autoc/vector'
5
- require 'autoc/list'
4
+ require 'autoc/std'
6
5
  require 'autoc/set'
6
+ require 'autoc/list'
7
+ require 'autoc/vector'
7
8
 
8
9
 
9
10
  module AutoC
data/lib/autoc/hashers.rb CHANGED
@@ -55,7 +55,7 @@ module AutoC
55
55
  #if defined(__cplusplus)
56
56
  extern "C" void _autoc_hasher_randomize_seed(void);
57
57
  #elif defined(__GNUC__) || defined(__clang__)
58
- void _autoc_hasher_randomize_seed(void) __attribute__((__constructor__));
58
+ void _autoc_hasher_randomize_seed(void) __attribute__((__constructor__));
59
59
  #elif defined(__POCC__)
60
60
  #pragma startup _autoc_hasher_randomize_seed
61
61
  #elif defined(_MSC_VER) || defined(__POCC__)
data/lib/autoc/list.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
 
4
+ require 'autoc/std'
4
5
  require 'autoc/ranges'
5
6
  require 'autoc/sequential'
6
7
  require 'autoc/collection'
data/lib/autoc/module.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
 
4
- require 'set'
5
4
  require 'digest'
6
5
 
7
6
  require 'autoc'
data/lib/autoc/ranges.rb CHANGED
@@ -25,7 +25,7 @@ module AutoC
25
25
  def to_value = @v ||= Value.new(self)
26
26
 
27
27
  def initialize(iterable, visibility:)
28
- super(iterable.identifier(:range, abbreviate: visibility == :internal), visibility:)
28
+ super(iterable.identifier(:range, abbreviate: internal?), visibility:)
29
29
  dependencies << (@iterable = iterable) << INFO
30
30
  end
31
31
 
@@ -62,7 +62,7 @@ module AutoC
62
62
 
63
63
  def configure
64
64
  super
65
- method(:void, :create, { range: lvalue, iterable: iterable.const_rvalue }, instance: :custom_create).configure do
65
+ method(:void, :create, { range: lvalue, iterable: iterable.const_rvalue }, instance: :custom_create, constraint:-> { custom_constructible? }).configure do
66
66
  header %{
67
67
  @brief Create a new range for the specified iterable
68
68
 
@@ -440,8 +440,6 @@ module AutoC
440
440
  */
441
441
  }
442
442
  end
443
- else
444
- stream << PRIVATE
445
443
  end
446
444
  if public?
447
445
  stream << %{
data/lib/autoc/record.rb CHANGED
@@ -131,7 +131,7 @@ module AutoC
131
131
  args[formal] = value
132
132
  docs << "@param[in] #{formal} `#{name}` field initializer of type @ref #{type}"
133
133
  end
134
- method(:void, :create_set, args, instance: :custom_create).configure do
134
+ method(:void, :create_set, args, instance: :custom_create, constraint:-> { custom_constructible? }).configure do
135
135
  _code = 'assert(target);'
136
136
  params.each do |field, parameter|
137
137
  _code += parameter.value.type.copy.("target->#{field}", parameter) + ';'
@@ -0,0 +1,17 @@
1
+ require 'autoc/vector'
2
+
3
+ require_relative 'composite_value'
4
+
5
+ type_test(AutoC::Vector, :CompositeValueVector, CompositeValue.new(:CompositeValue)) do
6
+
7
+ ###
8
+
9
+ setup %{
10
+ #{self} t;
11
+ }
12
+
13
+ cleanup %{
14
+ #{destroy}(&t);
15
+ }
16
+
17
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ require 'autoc/std'
5
+ require 'autoc/module'
6
+ require 'autoc/primitive'
7
+
8
+
9
+ class CompositeValue < AutoC::STD::Primitive
10
+
11
+ def orderable? = false
12
+
13
+ def render_interface(stream)
14
+ stream << %{
15
+ typedef struct {
16
+ int a;
17
+ char b;
18
+ } #{self};
19
+ }
20
+ end
21
+ end
@@ -35,7 +35,7 @@ private
35
35
 
36
36
  def configure
37
37
  super
38
- method(:void, :set, { target: lvalue, value: :int.const_rvalue }, instance: :custom_create).configure do
38
+ method(:void, :set, { target: lvalue, value: :int.const_rvalue }, instance: :custom_create, constraint:-> { custom_constructible? }).configure do
39
39
  code %{
40
40
  #{default_create.(target)};
41
41
  *target->value = value;
@@ -4,6 +4,4 @@
4
4
  require 'autoc/record'
5
5
 
6
6
 
7
- GlassRecord = AutoC::Record.new(:GlassRecord, { i: :int }, profile: :glassbox)
8
-
9
- #p GlassRecord.equal
7
+ GlassRecord = AutoC::Record.new(:GlassRecord, { i: :int }, profile: :glassbox, visibility: :public)
@@ -2,7 +2,7 @@ require 'autoc/record'
2
2
 
3
3
  require_relative 'glass_record'
4
4
 
5
- t = type_test(AutoC::Record, :RecordRecord, { r: GlassRecord }) do
5
+ t = type_test(AutoC::Record, :RecordRecord, { r: GlassRecord }) do
6
6
 
7
7
  ###
8
8
 
@@ -29,7 +29,7 @@ def type_test(cls, *opts, **kws, &code)
29
29
  t = Class.new(cls) do
30
30
  attr_reader :tests
31
31
  def initialize(*args, **kws)
32
- super
32
+ super(*args, visibility: :public, **kws)
33
33
  @tests = []
34
34
  @test_names = []
35
35
  dependencies << $common
@@ -160,11 +160,11 @@ $tests = []
160
160
 
161
161
  require 'autoc/composite'
162
162
 
163
- #AutoC::Composite.decorator = AutoC::Composite::SNAKE_CASE_DECORATOR
163
+ #AutoC::Composite.decorator = AutoC::Composite::Decorator::SNAKE_CASE
164
164
 
165
165
  require_relative 'generic_value'
166
166
 
167
- Value = GenericValue.new(:Value)
167
+ Value = GenericValue.new(:Value, visibility: :public)
168
168
 
169
169
  Dir[File.join(File.dirname(__FILE__), 'test_*.rb')].each { |t| require t }
170
170
 
data/lib/autoc/std.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
 
4
- require 'set'
5
4
  require 'autoc/module'
6
5
  require 'autoc/primitive'
7
6
 
data/lib/autoc/vector.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
 
4
+ require 'autoc/std'
4
5
  require 'autoc/ranges'
5
6
  require 'autoc/sequential'
6
7
  require 'autoc/association'
data/lib/autoc.rb CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  module AutoC
5
5
 
6
- VERSION = '2.0.1'
6
+ VERSION = '2.0.2'
7
7
 
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg A. Khlybov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-20 00:00:00.000000000 Z
11
+ date: 2023-04-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  The package contains a functionality related to the C source code generation,
@@ -43,6 +43,8 @@ files:
43
43
  - lib/autoc/ranges.rb
44
44
  - lib/autoc/record.rb
45
45
  - lib/autoc/scaffold.rb
46
+ - lib/autoc/scaffold/1test_composite_value_vector.rb
47
+ - lib/autoc/scaffold/composite_value.rb
46
48
  - lib/autoc/scaffold/docs.rb
47
49
  - lib/autoc/scaffold/generic_value.rb
48
50
  - lib/autoc/scaffold/glass_record.rb
@@ -83,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
85
  - !ruby/object:Gem::Version
84
86
  version: '0'
85
87
  requirements: []
86
- rubygems_version: 3.4.6
88
+ rubygems_version: 3.4.10
87
89
  signing_key:
88
90
  specification_version: 4
89
91
  summary: C source code generation package