rggen-core 0.34.0 → 0.35.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/rggen/core/base/feature_variable.rb +17 -6
- data/lib/rggen/core/generator.rb +0 -2
- data/lib/rggen/core/input_base/component_factory.rb +17 -8
- data/lib/rggen/core/input_base/feature.rb +10 -5
- data/lib/rggen/core/input_base/loader.rb +22 -4
- data/lib/rggen/core/input_base/property.rb +6 -16
- data/lib/rggen/core/output_base/code_generatable.rb +12 -7
- data/lib/rggen/core/register_map/component_factory.rb +7 -0
- data/lib/rggen/core/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad164f2506fbd5c91ea5a9340bc69e6fd492b628b38e12a87de290bea0ab6596
|
4
|
+
data.tar.gz: a57b33a6aff4642c98397bbcf6cf1d680cf899cfe83d0eca0dc552b085771ada
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6829f31ec7048843959afa0a84ef5980cc9a4bb8c4d792b631c658ea782ce8433fe46b9cc0cb76310c61b0a5aeaeb44757c845e87ed8a541f75033ba915d27f
|
7
|
+
data.tar.gz: f204f714996fac3302b7638bbdc7e7f83a3a4921e13ebec6c195a09dfdcddc9e1dcfb73cb9b310e092b6c26773de04ffdd3cd61a2b70c2750175412be88e1fd5
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/rggen-core.svg)](https://badge.fury.io/rb/rggen-core)
|
2
2
|
[![CI](https://github.com/rggen/rggen-core/workflows/CI/badge.svg)](https://github.com/rggen/rggen-core/actions?query=workflow%3ACI)
|
3
|
-
[![Maintainability](https://
|
3
|
+
[![Maintainability](https://qlty.sh/badges/40f53c48-7f4c-4094-9907-2736e69527b3/maintainability.svg)](https://qlty.sh/gh/rggen/projects/rggen-core)
|
4
4
|
[![codecov](https://codecov.io/gh/rggen/rggen-core/branch/master/graph/badge.svg)](https://codecov.io/gh/rggen/rggen-core)
|
5
5
|
[![Gitter](https://badges.gitter.im/rggen/rggen.svg)](https://gitter.im/rggen/rggen?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
6
6
|
|
@@ -19,6 +19,10 @@ module RgGen
|
|
19
19
|
self.class.feature_hash_variable_get(name)
|
20
20
|
end
|
21
21
|
|
22
|
+
def feature_hash_variable_fetch(name, key)
|
23
|
+
self.class.feature_hash_variable_fetch(name, key)
|
24
|
+
end
|
25
|
+
|
22
26
|
def feature_hash_array_variable_get(name)
|
23
27
|
self.class.feature_hash_array_variable_get(name)
|
24
28
|
end
|
@@ -32,12 +36,12 @@ module RgGen
|
|
32
36
|
if instance_variable_defined?(name)
|
33
37
|
instance_variable_get(name)
|
34
38
|
else
|
35
|
-
|
39
|
+
call_parent_feature_variable_method(__method__, name)
|
36
40
|
end
|
37
41
|
end
|
38
42
|
|
39
43
|
def feature_array_variable_get(name)
|
40
|
-
parent =
|
44
|
+
parent = call_parent_feature_variable_method(__method__, name)
|
41
45
|
own = instance_variable_get(name)
|
42
46
|
|
43
47
|
if [parent, own] in [Array, Array]
|
@@ -48,7 +52,7 @@ module RgGen
|
|
48
52
|
end
|
49
53
|
|
50
54
|
def feature_hash_variable_get(name)
|
51
|
-
parent =
|
55
|
+
parent = call_parent_feature_variable_method(__method__, name)
|
52
56
|
own = instance_variable_get(name)
|
53
57
|
|
54
58
|
if [parent, own] in [Hash, Hash]
|
@@ -58,8 +62,15 @@ module RgGen
|
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
65
|
+
def feature_hash_variable_fetch(name, key)
|
66
|
+
hash = instance_variable_get(name)
|
67
|
+
return hash[key] if hash&.key?(key)
|
68
|
+
|
69
|
+
call_parent_feature_variable_method(__method__, name, key)
|
70
|
+
end
|
71
|
+
|
61
72
|
def feature_hash_array_variable_get(name)
|
62
|
-
parent =
|
73
|
+
parent = call_parent_feature_variable_method(__method__, name)
|
63
74
|
own = instance_variable_get(name)
|
64
75
|
|
65
76
|
if [parent, own] in [Hash, Hash]
|
@@ -101,10 +112,10 @@ module RgGen
|
|
101
112
|
feature_hash_array_variable_update(name, :prepend, key, value)
|
102
113
|
end
|
103
114
|
|
104
|
-
def
|
115
|
+
def call_parent_feature_variable_method(method, ...)
|
105
116
|
return unless superclass.respond_to?(method, true)
|
106
117
|
|
107
|
-
superclass.__send__(method,
|
118
|
+
superclass.__send__(method, ...)
|
108
119
|
end
|
109
120
|
end
|
110
121
|
end
|
data/lib/rggen/core/generator.rb
CHANGED
@@ -26,26 +26,35 @@ module RgGen
|
|
26
26
|
|
27
27
|
def preprocess(args)
|
28
28
|
if root_factory?
|
29
|
-
[*args[0..-2],
|
29
|
+
[*args[0..-2], load_inputs(args)]
|
30
30
|
else
|
31
31
|
args
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def load_inputs(args)
|
36
36
|
files = args.last
|
37
37
|
create_input_data(*args[0..-2]) do |input_data|
|
38
|
-
files.
|
38
|
+
if files.empty?
|
39
|
+
handle_empty_input(input_data)
|
40
|
+
else
|
41
|
+
files.each { |file| load_file(input_data, file) }
|
42
|
+
end
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
42
|
-
def
|
43
|
-
find_loader(file).load_file(file, input_data, valid_value_lists)
|
46
|
+
def handle_empty_input(_input_data)
|
44
47
|
end
|
45
48
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
+
def load_file(input_data, file)
|
50
|
+
loader = find_loader { _1.support?(file) }
|
51
|
+
raise Core::LoadError.new('unsupported file type', file) unless loader
|
52
|
+
|
53
|
+
loader.load_data(input_data, valid_value_lists, file)
|
54
|
+
end
|
55
|
+
|
56
|
+
def find_loader(&)
|
57
|
+
loaders.reverse_each.find(&)
|
49
58
|
end
|
50
59
|
|
51
60
|
def valid_value_lists
|
@@ -11,7 +11,7 @@ module RgGen
|
|
11
11
|
|
12
12
|
class << self
|
13
13
|
def properties
|
14
|
-
|
14
|
+
feature_hash_variable_get(:@properties)&.keys
|
15
15
|
end
|
16
16
|
|
17
17
|
def active_feature?
|
@@ -25,9 +25,10 @@ module RgGen
|
|
25
25
|
private
|
26
26
|
|
27
27
|
def property(name, ...)
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
feature_hash_variable_store(:@properties, name, Property.new(name, ...))
|
29
|
+
return if method_defined?(name)
|
30
|
+
|
31
|
+
public alias_method(name, :property_method)
|
31
32
|
end
|
32
33
|
|
33
34
|
alias_method :field, :property
|
@@ -67,7 +68,7 @@ module RgGen
|
|
67
68
|
end
|
68
69
|
|
69
70
|
def properties
|
70
|
-
|
71
|
+
feature_hash_variable_get(:@properties)&.keys
|
71
72
|
end
|
72
73
|
|
73
74
|
def build(*args)
|
@@ -119,6 +120,10 @@ module RgGen
|
|
119
120
|
|
120
121
|
private
|
121
122
|
|
123
|
+
def property_method(...)
|
124
|
+
feature_hash_variable_fetch(:@properties, __callee__).evaluate(self, ...)
|
125
|
+
end
|
126
|
+
|
122
127
|
def do_build(builders, args)
|
123
128
|
@position = args.last.position
|
124
129
|
match_automatically? && match_pattern(args.last)
|
@@ -11,6 +11,10 @@ module RgGen
|
|
11
11
|
@support_types
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.require_no_input_file
|
15
|
+
@require_input_file = false
|
16
|
+
end
|
17
|
+
|
14
18
|
def initialize(extractors, ignore_values)
|
15
19
|
@extractors = extractors
|
16
20
|
@ignore_values = ignore_values
|
@@ -22,19 +26,33 @@ module RgGen
|
|
22
26
|
types&.any? { |type| type.casecmp?(ext) } || false
|
23
27
|
end
|
24
28
|
|
25
|
-
def
|
29
|
+
def require_input_file?
|
30
|
+
loader = self.class
|
31
|
+
!loader.instance_variable_defined?(:@require_input_file) ||
|
32
|
+
loader.instance_variable_get(:@require_input_file)
|
33
|
+
end
|
34
|
+
|
35
|
+
def load_data(input_data, valid_value_lists, file = nil)
|
36
|
+
if require_input_file?
|
37
|
+
load_file(input_data, valid_value_lists, file)
|
38
|
+
else
|
39
|
+
load_builtin_data(input_data)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def load_file(input_data, valid_value_lists, file)
|
26
44
|
File.readable?(file) ||
|
27
45
|
(raise Core::LoadError.new('cannot load such file', file))
|
28
46
|
@input_data = input_data
|
29
47
|
@valid_value_lists = valid_value_lists
|
30
|
-
|
48
|
+
format_data(read_file(file), input_data, input_data.layer, file)
|
31
49
|
end
|
32
50
|
|
33
51
|
private
|
34
52
|
|
35
53
|
attr_reader :input_data
|
36
54
|
|
37
|
-
def
|
55
|
+
def format_data(read_data, input_data, layer, file)
|
38
56
|
layer_data =
|
39
57
|
format_layer_data(read_data, layer, file) ||
|
40
58
|
format_layer_data_by_extractors(read_data, layer)
|
@@ -45,7 +63,7 @@ module RgGen
|
|
45
63
|
|
46
64
|
def format_sub_layer(read_data, input_data, layer, file)
|
47
65
|
format_sub_layer_data(read_data, layer, file)&.each do |(sub_layer, data)|
|
48
|
-
|
66
|
+
format_data(data, input_data.child(sub_layer), sub_layer, file)
|
49
67
|
end
|
50
68
|
end
|
51
69
|
|
@@ -4,11 +4,7 @@ module RgGen
|
|
4
4
|
module Core
|
5
5
|
module InputBase
|
6
6
|
class Property
|
7
|
-
def
|
8
|
-
new(name, options, &).define(feature)
|
9
|
-
end
|
10
|
-
|
11
|
-
def initialize(name, options, &)
|
7
|
+
def initialize(name, **options, &)
|
12
8
|
@name = name
|
13
9
|
@options = options
|
14
10
|
@costom_property =
|
@@ -21,14 +17,6 @@ module RgGen
|
|
21
17
|
|
22
18
|
attr_reader :name
|
23
19
|
|
24
|
-
def define(feature)
|
25
|
-
feature.class_exec(self) do |property|
|
26
|
-
define_method(property.name) do |*args, **kwargs, &block|
|
27
|
-
property.evaluate(self, *args, **kwargs, &block)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
20
|
def evaluate(feature, ...)
|
33
21
|
feature.verify(@options[:verify]) if @options.key?(:verify)
|
34
22
|
if proxy_property?
|
@@ -40,9 +28,11 @@ module RgGen
|
|
40
28
|
|
41
29
|
private
|
42
30
|
|
43
|
-
def create_costom_property(&
|
44
|
-
|
45
|
-
|
31
|
+
def create_costom_property(&)
|
32
|
+
return unless block_given?
|
33
|
+
|
34
|
+
Module.new.module_eval do
|
35
|
+
define_method(:__costom_property__, &)
|
46
36
|
instance_method(:__costom_property__)
|
47
37
|
end
|
48
38
|
end
|
@@ -13,6 +13,9 @@ module RgGen
|
|
13
13
|
.to_h { |phase| [phase, :"@#{phase}_blocks"] }
|
14
14
|
.freeze
|
15
15
|
|
16
|
+
TEMPLATE_PROCESSOR =
|
17
|
+
->(path, location) { process_template(path, location) }
|
18
|
+
|
16
19
|
module Extension
|
17
20
|
private
|
18
21
|
|
@@ -27,9 +30,9 @@ module RgGen
|
|
27
30
|
if options[:from_template]
|
28
31
|
path = extract_template_path(options)
|
29
32
|
location = caller_locations(2, 1).first
|
30
|
-
|
31
|
-
|
32
|
-
body
|
33
|
+
[TEMPLATE_PROCESSOR, path, location]
|
34
|
+
elsif block_given?
|
35
|
+
[body]
|
33
36
|
end
|
34
37
|
return unless block
|
35
38
|
|
@@ -55,11 +58,13 @@ module RgGen
|
|
55
58
|
blocks = feature_hash_array_variable_get(VARIABLE_NAMES[phase])
|
56
59
|
return unless blocks
|
57
60
|
|
58
|
-
blocks[kind]&.each do |
|
59
|
-
|
60
|
-
|
61
|
+
blocks[kind]&.each do |block_and_args|
|
62
|
+
block = block_and_args[0]
|
63
|
+
args = block_and_args[1..]
|
64
|
+
if block.arity == (args&.size || 0)
|
65
|
+
code << instance_exec(*args, &block)
|
61
66
|
else
|
62
|
-
instance_exec(code, &block)
|
67
|
+
instance_exec(code, *args, &block)
|
63
68
|
end
|
64
69
|
end
|
65
70
|
end
|
@@ -14,6 +14,13 @@ module RgGen
|
|
14
14
|
InputData.new(:root, valid_value_lists, configuration, &)
|
15
15
|
end
|
16
16
|
|
17
|
+
def handle_empty_input(input_data)
|
18
|
+
loader = find_loader { !_1.require_input_file? }
|
19
|
+
raise LoadError.new('no register map files are given') unless loader
|
20
|
+
|
21
|
+
loader.load_data(input_data, valid_value_lists)
|
22
|
+
end
|
23
|
+
|
17
24
|
def find_child_factory(_configuration, register_map)
|
18
25
|
component_factories[register_map.layer]
|
19
26
|
end
|
data/lib/rggen/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rggen-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.35.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taichi Ishitani
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-02-19 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: docile
|
@@ -207,5 +207,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
207
|
requirements: []
|
208
208
|
rubygems_version: 3.6.2
|
209
209
|
specification_version: 4
|
210
|
-
summary: rggen-core-0.
|
210
|
+
summary: rggen-core-0.35.0
|
211
211
|
test_files: []
|