autoc 2.0.0 → 2.0.2

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: a598879205b51d5bf574b70b370ef805efe3681e0ea4ad8b6347e45296cc304b
4
- data.tar.gz: d5c3290746c096a666627ff544903afe2b1f31e61b7706cf5a5e531c410191ea
3
+ metadata.gz: e1800467846d30e1b98d5f124f250ef87f9adf1aab5f319f7593dcd8a6d4e8ea
4
+ data.tar.gz: de7e6b5457c9bf747df18b86b5c06d05b065c11d13649709f2f02b7eb4eedb11
5
5
  SHA512:
6
- metadata.gz: cb81338f80898d88975a0bc204b5245c6fe4e0deb931c91ff007bff5dca026f4f99fe5702d56033fa0387786cb20b03445dbb662c07ebcf7f8ba81f993848520
7
- data.tar.gz: da094ff14cf393a2c7178fb45083d18b3513d686e29a693895dd4cea51bbcf406776fe26de0d550605102f7f5976170a3715fedc1d9520e1f4c1944c034b56d1
6
+ metadata.gz: 476a8dac04a57b7e313232b904f73297a4e5d76a0919423535f356c29fa4b48690941d04f75f79a623bac23076c2ec56f4d2f20d0d72ecfbb24ad24eb9f3b06c
7
+ data.tar.gz: e449fbe1e182aa541bc7bc861e4f653c5b7b23b0eb7f99dfbb769e7c44e6ef210df0e4ad8e1c2799ed99121ed0b71411c280a28ae8183a7a369fa60908132a9a
data/CHANGES.md CHANGED
@@ -1,3 +1,19 @@
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
+
9
+ # 2.0.1
10
+
11
+ - Introduce switch for incremental module generation mode.
12
+
13
+ - Fix Record setter function type mismatch bug.
14
+
15
+ - Fix project structure conformance issue in CMake project scaffolder.
16
+
1
17
  # 2.0.0
2
18
 
3
- A complete package overhaul.
19
+ - A complete package overhaul.
@@ -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
 
@@ -148,6 +153,8 @@ module AutoC
148
153
 
149
154
  # Create a new type-bound function (aka method)
150
155
  def method(result, name, parameters, inline: false, visibility: nil, constraint: true, instance: name, **kws)
156
+ name = name.to_sym
157
+ instance = instance.to_sym
151
158
  method = method_class.new(
152
159
  self,
153
160
  result,
@@ -292,6 +299,8 @@ module AutoC
292
299
  #{@header}
293
300
  */
294
301
  }
302
+ else
303
+ stream << Composite::PRIVATE
295
304
  end
296
305
  end
297
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'
@@ -51,7 +50,12 @@ module AutoC
51
50
 
52
51
  attr_accessor :source_threshold
53
52
 
54
- def initialize(name) = @name = name
53
+ def stateful? = @stateful == true
54
+
55
+ def initialize(name, stateful: true)
56
+ @name = name
57
+ @stateful = stateful
58
+ end
55
59
 
56
60
  def header = @header ||= Header.new(self)
57
61
 
@@ -63,7 +67,7 @@ module AutoC
63
67
  distribute_entities
64
68
  header.render
65
69
  sources.each(&:render)
66
- State.new(self).collect.write
70
+ State.new(self).collect.write if stateful?
67
71
  self
68
72
  end
69
73
 
@@ -86,8 +90,8 @@ module AutoC
86
90
  end
87
91
  end
88
92
 
89
- def self.render(name, &code)
90
- m = self.new(name)
93
+ def self.render(name, **, &code)
94
+ m = self.new(name, **)
91
95
  yield(m) if block_given?
92
96
  m.render
93
97
  end
@@ -114,7 +118,7 @@ module AutoC
114
118
  end
115
119
 
116
120
  def read
117
- if File.exist?(file_name)
121
+ if self.module.stateful? && File.exist?(file_name)
118
122
  # It's OK not to have this file but if it exists it must have proper contents
119
123
  io = File.open(file_name, 'rt', chomp: true)
120
124
  begin
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) + ';'
@@ -217,17 +217,17 @@ module AutoC
217
217
  @since 2.0
218
218
  }
219
219
  end
220
- method(:void, "set_#{name}", { target: rvalue, name.to_sym => type.const_rvalue } ).configure do
220
+ method(:void, "set_#{name}", { target: rvalue, value: type.const_rvalue } ).configure do
221
221
  code %{
222
222
  assert(target);
223
223
  #{type.destroy.("target->#{name}") if type.destructible?};
224
- #{type.copy.("target->#{name}", name)};
224
+ #{type.copy.("target->#{name}", value)};
225
225
  }
226
226
  header %{
227
227
  @brief Set value of field #{name}
228
228
 
229
229
  @param[in] target record to modify
230
- @param[in] #{name} value to initalize field #{name} with
230
+ @param[in] value value to initalize field #{name} with
231
231
 
232
232
  This function sets the field #{name} to contain a copy of specified value.
233
233
 
@@ -239,7 +239,7 @@ module AutoC
239
239
  end
240
240
  end
241
241
  end
242
- end
242
+ end
243
243
 
244
244
  end # Record
245
245
 
@@ -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;
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ require 'autoc/record'
5
+
6
+
7
+ GlassRecord = AutoC::Record.new(:GlassRecord, { i: :int }, profile: :glassbox, visibility: :public)
@@ -19,10 +19,10 @@ end
19
19
  ###
20
20
  def cmakelists_txt(project)
21
21
  <<END
22
- project(#{project})
23
-
24
22
  cmake_minimum_required(VERSION 3.15)
25
23
 
24
+ project(#{project})
25
+
26
26
  set(AUTOC_MODULE_NAME _${PROJECT_NAME})
27
27
  set(AUTOC_MODULE_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.rb)
28
28
 
@@ -0,0 +1,21 @@
1
+ require 'autoc/record'
2
+
3
+ require_relative 'glass_record'
4
+
5
+ t = type_test(AutoC::Record, :RecordRecord, { r: GlassRecord }) do
6
+
7
+ ###
8
+
9
+ setup %{
10
+ #{self} t;
11
+ #{default_create.(:t)};
12
+ }
13
+
14
+ cleanup %{
15
+ #{destroy.(:t) if destructible?};
16
+ }
17
+
18
+ test :create_empty, %{
19
+ }
20
+
21
+ end
@@ -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,17 +160,17 @@ $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
 
171
171
  require 'autoc/cmake'
172
172
 
173
- x = AutoC::Module.render(:tests) do |m|
173
+ x = AutoC::Module.render(:tests, stateful: false) do |m|
174
174
  m << $suite
175
175
  m.source_threshold = 100*1024 # Split module code into a set of TUs with ~100 Kb in size
176
176
  $tests.each { |t| $suite.dependencies << t }
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.0'
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.0
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-14 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,8 +43,11 @@ 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
50
+ - lib/autoc/scaffold/glass_record.rb
48
51
  - lib/autoc/scaffold/project.rb
49
52
  - lib/autoc/scaffold/test_cstring.rb
50
53
  - lib/autoc/scaffold/test_cstring_hash_set.rb
@@ -52,6 +55,7 @@ files:
52
55
  - lib/autoc/scaffold/test_int_hash_set.rb
53
56
  - lib/autoc/scaffold/test_int_list.rb
54
57
  - lib/autoc/scaffold/test_int_vector.rb
58
+ - lib/autoc/scaffold/test_record_record.rb
55
59
  - lib/autoc/scaffold/test_v2v_hash_map.rb
56
60
  - lib/autoc/scaffold/test_value_hash_set.rb
57
61
  - lib/autoc/scaffold/test_value_vector.rb
@@ -81,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
85
  - !ruby/object:Gem::Version
82
86
  version: '0'
83
87
  requirements: []
84
- rubygems_version: 3.4.6
88
+ rubygems_version: 3.4.10
85
89
  signing_key:
86
90
  specification_version: 4
87
91
  summary: C source code generation package