rggen-core 0.19.0 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/exe/rggen +0 -0
  3. data/lib/rggen/core.rb +4 -3
  4. data/lib/rggen/core/base/component.rb +16 -7
  5. data/lib/rggen/core/base/component_factory.rb +12 -9
  6. data/lib/rggen/core/base/component_layer_extension.rb +194 -0
  7. data/lib/rggen/core/base/feature_layer_extension.rb +158 -0
  8. data/lib/rggen/core/builder/builder.rb +25 -25
  9. data/lib/rggen/core/builder/component_entry.rb +3 -2
  10. data/lib/rggen/core/builder/component_registry.rb +22 -17
  11. data/lib/rggen/core/builder/{category.rb → layer.rb} +27 -26
  12. data/lib/rggen/core/builder/plugins.rb +5 -3
  13. data/lib/rggen/core/configuration/component.rb +5 -0
  14. data/lib/rggen/core/configuration/component_factory.rb +1 -1
  15. data/lib/rggen/core/configuration/input_data.rb +15 -0
  16. data/lib/rggen/core/input_base/component_factory.rb +37 -6
  17. data/lib/rggen/core/input_base/feature.rb +3 -3
  18. data/lib/rggen/core/input_base/input_data.rb +13 -10
  19. data/lib/rggen/core/input_base/loader.rb +2 -3
  20. data/lib/rggen/core/input_base/yaml_loader.rb +5 -4
  21. data/lib/rggen/core/output_base/code_generator.rb +10 -23
  22. data/lib/rggen/core/output_base/component.rb +42 -39
  23. data/lib/rggen/core/output_base/component_factory.rb +4 -0
  24. data/lib/rggen/core/output_base/feature.rb +6 -7
  25. data/lib/rggen/core/register_map.rb +3 -3
  26. data/lib/rggen/core/register_map/component.rb +4 -3
  27. data/lib/rggen/core/register_map/component_factory.rb +18 -1
  28. data/lib/rggen/core/register_map/feature.rb +2 -2
  29. data/lib/rggen/core/register_map/hash_loader.rb +16 -23
  30. data/lib/rggen/core/register_map/input_data.rb +30 -16
  31. data/lib/rggen/core/register_map/loader.rb +1 -1
  32. data/lib/rggen/core/register_map/ruby_loader.rb +1 -1
  33. data/lib/rggen/core/utility/code_utility.rb +8 -2
  34. data/lib/rggen/core/version.rb +1 -1
  35. metadata +7 -6
  36. data/lib/rggen/core/base/hierarchical_accessors.rb +0 -91
  37. data/lib/rggen/core/base/hierarchical_feature_accessors.rb +0 -83
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07b141658bda7d5c43afba30ecbff539ab05beb383844f5a5b8fc9d9b605ebb5
4
- data.tar.gz: faac4148e8c6c2e1bfa2632e1e1a589139db03280e3d25af8d39a1172708950e
3
+ metadata.gz: d9079e5f068e752e9f083fd64c97dda8cdc9f47f2e4ce3c6f1d0568f4950caa3
4
+ data.tar.gz: e60e14aa24f9f7b003391f0d87d773a35adbdf99c794016cdd803fc8025df8de
5
5
  SHA512:
6
- metadata.gz: 4838ab9d430ae360da7d223db91171e4460221ecec07e8ed475053eec91ed3a6af1ac10f62350731fb9593e34d7c332f135e68d4d459290cc440b9c7b882065e
7
- data.tar.gz: 696f4186513d88b855434a295182dea303b54c52b6a04c251bb8a8dd2910bbeb42147abd9dfe292e28e42c91e4aba4971901490895b3685d375a18c988dd9d70
6
+ metadata.gz: 7f2b3f56089899d459e62bd6873166a467eec667d559690ad26a17558a72b4e399744d156c9a092181067a1313c82615db12a63469e8b7d9145678adfed2c830
7
+ data.tar.gz: a5cf836ea12ba57a905d925f29406f76155ce3e389d4678f76adee6da8bec9f5964c3f973f2803019c4aa8756f7223abf1de958f2ceb6b6fd97024d663c02327
data/exe/rggen CHANGED
File without changes
@@ -31,10 +31,10 @@ require_relative 'core/base/internal_struct'
31
31
  require_relative 'core/base/shared_context'
32
32
  require_relative 'core/base/component'
33
33
  require_relative 'core/base/component_factory'
34
+ require_relative 'core/base/component_layer_extension'
34
35
  require_relative 'core/base/feature'
35
36
  require_relative 'core/base/feature_factory'
36
- require_relative 'core/base/hierarchical_accessors'
37
- require_relative 'core/base/hierarchical_feature_accessors'
37
+ require_relative 'core/base/feature_layer_extension'
38
38
 
39
39
  require_relative 'core/input_base/input_value'
40
40
  require_relative 'core/input_base/input_data'
@@ -49,6 +49,7 @@ require_relative 'core/input_base/property'
49
49
  require_relative 'core/input_base/feature'
50
50
  require_relative 'core/input_base/feature_factory'
51
51
 
52
+ require_relative 'core/configuration/input_data'
52
53
  require_relative 'core/configuration/error'
53
54
  require_relative 'core/configuration/component'
54
55
  require_relative 'core/configuration/component_factory'
@@ -91,7 +92,7 @@ require_relative 'core/builder/output_component_registry'
91
92
  require_relative 'core/builder/simple_feature_entry'
92
93
  require_relative 'core/builder/list_feature_entry'
93
94
  require_relative 'core/builder/feature_registry'
94
- require_relative 'core/builder/category'
95
+ require_relative 'core/builder/layer'
95
96
  require_relative 'core/builder/plugins'
96
97
  require_relative 'core/builder/builder'
97
98
  require_relative 'core/builder'
@@ -4,28 +4,37 @@ module RgGen
4
4
  module Core
5
5
  module Base
6
6
  class Component
7
- def initialize(base_name, *args)
7
+ def initialize(parent, base_name, layer, *args)
8
+ @parent = parent
8
9
  @base_name = base_name
9
- @parent = args.first
10
+ @layer = layer
10
11
  @children = []
11
12
  @need_children = true
12
- @level = (parent && parent.level + 1) || 0
13
13
  @features = {}
14
+ @depth = (parent&.depth || 0) + 1
14
15
  @component_index = parent&.children&.size || 0
15
16
  post_initialize(*args)
16
17
  block_given? && yield(self)
17
18
  end
18
19
 
19
20
  attr_reader :parent
21
+ attr_reader :layer
20
22
  attr_reader :children
21
- attr_reader :level
23
+ attr_reader :depth
22
24
  attr_reader :component_index
23
25
 
24
- def component_name
25
- [hierarchy, @base_name].compact.join('@')
26
+ def ancestors
27
+ [].tap do |components|
28
+ component = self
29
+ while component
30
+ components.unshift(component)
31
+ component = component.parent
32
+ end
33
+ end
26
34
  end
27
35
 
28
- def hierarchy
36
+ def component_name
37
+ [@layer, @base_name].compact.join('@')
29
38
  end
30
39
 
31
40
  alias_method :to_s, :component_name
@@ -4,15 +4,19 @@ module RgGen
4
4
  module Core
5
5
  module Base
6
6
  class ComponentFactory
7
- def initialize(component_name)
7
+ def initialize(component_name, layer)
8
8
  @component_name = component_name
9
+ @layer = layer
9
10
  @root_factory = false
10
11
  block_given? && yield(self)
11
12
  end
12
13
 
14
+ attr_reader :component_name
15
+ attr_reader :layer
16
+
13
17
  attr_setter :target_component
18
+ attr_setter :component_factories
14
19
  attr_setter :feature_factories
15
- attr_setter :child_factory
16
20
 
17
21
  def root_factory
18
22
  @root_factory = true
@@ -40,7 +44,7 @@ module RgGen
40
44
  def create_component(parent, sources, &block)
41
45
  actual_sources = Array(select_actual_sources(*sources))
42
46
  @target_component
43
- .new(@component_name, parent, *actual_sources, &block)
47
+ .new(parent, component_name, layer, *actual_sources, &block)
44
48
  end
45
49
 
46
50
  def select_actual_sources(*sources)
@@ -54,8 +58,7 @@ module RgGen
54
58
  end
55
59
 
56
60
  def do_create_features(component, sources)
57
- return unless create_features?
58
- create_features(component, *sources)
61
+ create_features? && create_features(component, *sources)
59
62
  end
60
63
 
61
64
  def create_features?
@@ -63,12 +66,11 @@ module RgGen
63
66
  end
64
67
 
65
68
  def do_create_children(component, sources)
66
- return unless create_children?(component)
67
- create_children(component, *sources)
69
+ create_children?(component) && create_children(component, *sources)
68
70
  end
69
71
 
70
72
  def create_children?(component)
71
- @child_factory && component.need_children?
73
+ @component_factories && component.need_children?
72
74
  end
73
75
 
74
76
  def preprocess(args)
@@ -86,7 +88,8 @@ module RgGen
86
88
  end
87
89
 
88
90
  def create_child(component, *args)
89
- @child_factory.create(component, *args)
91
+ factory = find_child_factory(*args)
92
+ factory.create(component, *args)
90
93
  end
91
94
  end
92
95
  end
@@ -0,0 +1,194 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module Core
5
+ module Base
6
+ module ComponentLayerExtension
7
+ private
8
+
9
+ module Common
10
+ def root?
11
+ layer == :root
12
+ end
13
+
14
+ def register_block?
15
+ layer == :register_block
16
+ end
17
+
18
+ def register_file?
19
+ layer == :register_file
20
+ end
21
+
22
+ def register?
23
+ layer == :register
24
+ end
25
+
26
+ def bit_field?
27
+ layer == :bit_field
28
+ end
29
+ end
30
+
31
+ module Root
32
+ include Common
33
+
34
+ def register_blocks
35
+ children
36
+ end
37
+
38
+ def register_files
39
+ register_blocks.flat_map(&:register_files)
40
+ end
41
+
42
+ def registers
43
+ register_blocks.flat_map(&:registers)
44
+ end
45
+
46
+ def bit_fields
47
+ register_blocks.flat_map(&:bit_fields)
48
+ end
49
+ end
50
+
51
+ module RegisterBlock
52
+ include Common
53
+
54
+ def root
55
+ parent
56
+ end
57
+
58
+ def files_and_registers
59
+ children
60
+ end
61
+
62
+ def register_files(include_lower_layer = true)
63
+ files_and_registers
64
+ .select(&:register_file?)
65
+ .flat_map { |rf| [rf, *(include_lower_layer ? rf : nil)&.register_files] }
66
+ end
67
+
68
+ def registers(include_lower_layer = true)
69
+ files_and_registers.flat_map do |file_or_register|
70
+ if file_or_register.register?
71
+ file_or_register
72
+ else
73
+ [*(include_lower_layer ? file_or_register : nil)&.registers]
74
+ end
75
+ end
76
+ end
77
+
78
+ def bit_fields
79
+ registers.flat_map(&:bit_fields)
80
+ end
81
+ end
82
+
83
+ module RegisterFile
84
+ include Common
85
+
86
+ def root
87
+ register_block.root
88
+ end
89
+
90
+ def block_or_file
91
+ parent
92
+ end
93
+
94
+ def register_block
95
+ parent.register_block? && parent || parent.register_block
96
+ end
97
+
98
+ def register_file
99
+ parent.register_file? && parent || nil
100
+ end
101
+
102
+ def files_and_registers
103
+ children
104
+ end
105
+
106
+ def register_files(include_lower_layer = true)
107
+ files_and_registers
108
+ .select(&:register_file?)
109
+ .flat_map { |rf| [rf, *(include_lower_layer ? rf : nil)&.register_files] }
110
+ end
111
+
112
+ def registers(include_lower_layer = true)
113
+ files_and_registers.flat_map do |file_or_register|
114
+ if file_or_register.register?
115
+ file_or_register
116
+ else
117
+ [*(include_lower_layer ? file_or_register : nil)&.registers]
118
+ end
119
+ end
120
+ end
121
+
122
+ def bit_fields
123
+ registers.flat_map(&:bit_fields)
124
+ end
125
+ end
126
+
127
+ module Register
128
+ include Common
129
+
130
+ def root
131
+ parent.root
132
+ end
133
+
134
+ def register_block
135
+ parent.register_block? && parent || parent.register_block
136
+ end
137
+
138
+ def register_file
139
+ parent.register_file? && parent || nil
140
+ end
141
+
142
+ def register_files
143
+ ancestors.select(&:register_file?)
144
+ end
145
+
146
+ def block_or_file
147
+ parent
148
+ end
149
+
150
+ def bit_fields
151
+ children
152
+ end
153
+ end
154
+
155
+ module BitField
156
+ include Common
157
+
158
+ def root
159
+ parent.root
160
+ end
161
+
162
+ def register_block
163
+ parent.register_block
164
+ end
165
+
166
+ def register_file
167
+ parent.register_file
168
+ end
169
+
170
+ def register_files
171
+ parent.register_files
172
+ end
173
+
174
+ def register
175
+ parent
176
+ end
177
+ end
178
+
179
+ ACCESSOR_EXTENSIONS = {
180
+ root: Root,
181
+ register_block: RegisterBlock,
182
+ register_file: RegisterFile,
183
+ register: Register,
184
+ bit_field: BitField
185
+ }.freeze
186
+
187
+ def define_layer_methods
188
+ ACCESSOR_EXTENSIONS.key?(layer) &&
189
+ (extend ACCESSOR_EXTENSIONS[layer])
190
+ end
191
+ end
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,158 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RgGen
4
+ module Core
5
+ module Base
6
+ module FeatureLayerExtension
7
+ private
8
+
9
+ module Common
10
+ def root?
11
+ @component.root?
12
+ end
13
+
14
+ def register_block?
15
+ @component.register_block?
16
+ end
17
+
18
+ def register_file?
19
+ @component.register_file?
20
+ end
21
+
22
+ def register?
23
+ @component.register?
24
+ end
25
+
26
+ def bit_field?
27
+ @component.bit_field?
28
+ end
29
+ end
30
+
31
+ module Root
32
+ include Common
33
+
34
+ def root
35
+ @component
36
+ end
37
+ end
38
+
39
+ module RegisterBlock
40
+ include Common
41
+
42
+ def root
43
+ register_block.root
44
+ end
45
+
46
+ def register_block
47
+ @component
48
+ end
49
+
50
+ def register_blocks
51
+ root.register_blocks
52
+ end
53
+ end
54
+
55
+ module RegisterFile
56
+ include Common
57
+
58
+ def root
59
+ register_file.root
60
+ end
61
+
62
+ def register_block
63
+ register_file.register_block
64
+ end
65
+
66
+ def block_or_file
67
+ register_file.block_or_file
68
+ end
69
+
70
+ def register_file(layer = nil)
71
+ layer == :upper ? @component.register_file : @component
72
+ end
73
+
74
+ def files_and_registers
75
+ block_or_file.files_and_registers
76
+ end
77
+ end
78
+
79
+ module Register
80
+ include Common
81
+
82
+ def root
83
+ register.root
84
+ end
85
+
86
+ def register_block
87
+ register.register_block
88
+ end
89
+
90
+ def register_file
91
+ register.register_file
92
+ end
93
+
94
+ def register_files
95
+ register.register_files
96
+ end
97
+
98
+ def block_or_file
99
+ register.block_or_file
100
+ end
101
+
102
+ def register
103
+ @component
104
+ end
105
+
106
+ def files_and_registers
107
+ block_or_file.files_and_registers
108
+ end
109
+ end
110
+
111
+ module BitField
112
+ include Common
113
+
114
+ def root
115
+ bit_field.root
116
+ end
117
+
118
+ def register_block
119
+ bit_field.register_block
120
+ end
121
+
122
+ def register_file
123
+ bit_field.register_file
124
+ end
125
+
126
+ def register_files
127
+ bit_field.register_files
128
+ end
129
+
130
+ def register
131
+ bit_field.register
132
+ end
133
+
134
+ def bit_field
135
+ @component
136
+ end
137
+
138
+ def bit_fields
139
+ register.bit_fields
140
+ end
141
+ end
142
+
143
+ ACCESSOR_EXTENSIONS = {
144
+ root: Root,
145
+ register_block: RegisterBlock,
146
+ register_file: RegisterFile,
147
+ register: Register,
148
+ bit_field: BitField
149
+ }.freeze
150
+
151
+ def define_layer_methods
152
+ ACCESSOR_EXTENSIONS.key?(component.layer) &&
153
+ (extend ACCESSOR_EXTENSIONS[component.layer])
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end