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 +4 -4
- data/CHANGES.md +8 -0
- data/lib/autoc/composite.rb +42 -35
- data/lib/autoc/cstring.rb +1 -1
- data/lib/autoc/function.rb +22 -9
- data/lib/autoc/hash_map.rb +1 -0
- data/lib/autoc/hash_set.rb +3 -2
- data/lib/autoc/hashers.rb +1 -1
- data/lib/autoc/list.rb +1 -0
- data/lib/autoc/module.rb +0 -1
- data/lib/autoc/ranges.rb +2 -4
- data/lib/autoc/record.rb +1 -1
- data/lib/autoc/scaffold/1test_composite_value_vector.rb +17 -0
- data/lib/autoc/scaffold/composite_value.rb +21 -0
- data/lib/autoc/scaffold/generic_value.rb +1 -1
- data/lib/autoc/scaffold/glass_record.rb +1 -3
- data/lib/autoc/scaffold/test_record_record.rb +1 -1
- data/lib/autoc/scaffold/tests.rb +3 -3
- data/lib/autoc/std.rb +0 -1
- data/lib/autoc/vector.rb +1 -0
- data/lib/autoc.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1800467846d30e1b98d5f124f250ef87f9adf1aab5f319f7593dcd8a6d4e8ea
|
4
|
+
data.tar.gz: de7e6b5457c9bf747df18b86b5c06d05b065c11d13649709f2f02b7eb4eedb11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 476a8dac04a57b7e313232b904f73297a4e5d76a0919423535f356c29fa4b48690941d04f75f79a623bac23076c2ec56f4d2f20d0d72ecfbb24ad24eb9f3b06c
|
7
|
+
data.tar.gz: e449fbe1e182aa541bc7bc861e4f653c5b7b23b0eb7f99dfbb769e7c44e6ef210df0e4ad8e1c2799ed99121ed0b71411c280a28ae8183a7a369fa60908132a9a
|
data/CHANGES.md
CHANGED
data/lib/autoc/composite.rb
CHANGED
@@ -18,7 +18,7 @@ module AutoC
|
|
18
18
|
# @abstract
|
19
19
|
class Composite < Type
|
20
20
|
|
21
|
-
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
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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
|
|
data/lib/autoc/function.rb
CHANGED
@@ -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
|
148
|
+
def signature = '%s(%s)' % [result, (parameters.to_a.collect(&:signature) << (variadic? ? '...' : nil)).compact.join(',')]
|
144
149
|
|
145
|
-
def prototype = '%s %s(%s)' % [result
|
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
|
-
|
187
|
-
|
188
|
-
|
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
|
-
#
|
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
|
-
|
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
|
-
|
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
|
|
data/lib/autoc/hash_map.rb
CHANGED
data/lib/autoc/hash_set.rb
CHANGED
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)
|
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
data/lib/autoc/module.rb
CHANGED
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:
|
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,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;
|
data/lib/autoc/scaffold/tests.rb
CHANGED
@@ -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::
|
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
data/lib/autoc/vector.rb
CHANGED
data/lib/autoc.rb
CHANGED
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.
|
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-
|
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.
|
88
|
+
rubygems_version: 3.4.10
|
87
89
|
signing_key:
|
88
90
|
specification_version: 4
|
89
91
|
summary: C source code generation package
|