ruby_header_parser 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 73e54692bd969e0639672d95e7b5315bd5bbf8857c988343c0291af3ff5a3ab6
4
+ data.tar.gz: '099e7a0d30b0ef67d5c21853d123bf34927bae48915fef6cc1377fcea9e56689'
5
+ SHA512:
6
+ metadata.gz: 282901b284812616deb5c0f5c180aa67397fac1b52c6b121df2462e6094f8e0b88e4ab57b45d2a371fe5f6682cd113e5ff2fb7b99f23f77660a803865a3f61c6
7
+ data.tar.gz: c87c969a18e295904f4e35f56d83fb8173f7606464c46828ac27f56d1ebb4a4d2db164bcff20d6865fe2446e266fbbfde725ac3773327982e493d0077ce2e70e
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format progress
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,55 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.3
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Gemspec/DevelopmentDependencies:
7
+ EnforcedStyle: gemspec
8
+
9
+ Layout/DotPosition:
10
+ EnforcedStyle: trailing
11
+
12
+ Layout/HashAlignment:
13
+ EnforcedColonStyle: table
14
+ EnforcedHashRocketStyle: table
15
+
16
+ Layout/SpaceAroundOperators:
17
+ Exclude:
18
+ # Suppress line breaks in spec files (e.g `it { should xxxx }`, `its(:method) { should xxxx }` )
19
+ - "**/*_spec.rb"
20
+
21
+ Lint/BinaryOperatorWithIdenticalOperands:
22
+ Exclude:
23
+ - "**/*_spec.rb" # for rspec-parameterized
24
+
25
+ Metrics/AbcSize:
26
+ Max: 20
27
+
28
+ Metrics/BlockLength:
29
+ Exclude:
30
+ - "*.gemspec"
31
+ - "**/*_spec.rb"
32
+
33
+ Metrics/MethodLength:
34
+ Max: 21
35
+
36
+ Style/NumericPredicate:
37
+ EnforcedStyle: comparison
38
+
39
+ Style/SingleLineMethods:
40
+ Enabled: false
41
+
42
+ Style/StringLiterals:
43
+ EnforcedStyle: double_quotes
44
+
45
+ Style/StringLiteralsInInterpolation:
46
+ EnforcedStyle: double_quotes
47
+
48
+ Style/TrailingCommaInArguments:
49
+ EnforcedStyleForMultiline: comma
50
+
51
+ Style/TrailingCommaInArrayLiteral:
52
+ EnforcedStyleForMultiline: comma
53
+
54
+ Style/TrailingCommaInHashLiteral:
55
+ EnforcedStyleForMultiline: comma
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --markup markdown
2
+ --no-private
3
+ --hide-void-return
4
+ -
5
+ CHANGELOG.md
6
+ CONFIG.md
7
+ LICENSE.txt
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0](https://github.com/sue445/ruby_header_parser/releases/tag/v0.1.0) - 2024-10-14
4
+
5
+ - Initial release
data/CONFIG.md ADDED
@@ -0,0 +1,126 @@
1
+ # Configuration file specification
2
+
3
+ ## Example
4
+ ```yaml
5
+ function:
6
+ include_name:
7
+ - !ruby/regexp /^rb_/i
8
+ - !ruby/regexp /^rstring_/i
9
+
10
+ exclude_name:
11
+ # deprecated functions
12
+ - !ruby/regexp /^rb_check_safe_str$/i
13
+ - !ruby/regexp /^rb_clear_constant_cache$/i
14
+ - !ruby/regexp /^rb_clone_setup$/i
15
+
16
+ pointer_hint:
17
+ RSTRING_PTR:
18
+ self: raw
19
+ rb_data_object_make:
20
+ 4: sref
21
+
22
+ struct:
23
+ include_name:
24
+ - !ruby/regexp /^rb_/i
25
+ - re_registers
26
+
27
+ exclude_name:
28
+ - rb_data_type_struct
29
+
30
+ type:
31
+ include_name:
32
+ - !ruby/regexp /^rb_/i
33
+ - !ruby/regexp /^st_/i
34
+ - ID
35
+ - VALUE
36
+
37
+ exclude_name: []
38
+
39
+ enum:
40
+ include_name:
41
+ - ruby_value_type
42
+ - rb_io_wait_readwrite
43
+
44
+ exclude_name: []
45
+ ```
46
+
47
+ ## Full configuration file
48
+ [config/default.yml](config/default.yml) is used by https://github.com/sue445/go-gem-wrapper to generate bindings for Go.
49
+
50
+ ## `function.include_name`, `struct.include_name`, `type.include_name`, `enum.include_name`
51
+ Return functions and structures that match the condition with a [RubyHeaderParser::Parser](lib/ruby_header_parser/parser.rb)
52
+
53
+ e.g.
54
+
55
+ ```yaml
56
+ struct:
57
+ include_name:
58
+ - !ruby/regexp /^rb_/i
59
+ - re_registers
60
+ ```
61
+
62
+ Elements in the array accept the following
63
+
64
+ * `String`: Exact match
65
+ * `Regexp`(`!ruby/regexp`): Regular expression match
66
+
67
+ ## `function.exclude_name`, `struct.exclude_name`, `type.exclude_name`, `enum.exclude_name`
68
+ Doesn't return functions and structures that match the condition with a [RubyHeaderParser::Parser](lib/ruby_header_parser/parser.rb)
69
+
70
+ e.g.
71
+
72
+ ```yaml
73
+ function:
74
+ exclude_name:
75
+ - !ruby/regexp /^rb_check_safe_str$/i
76
+ - rb_scan_args_bad_format
77
+ ```
78
+
79
+ `exclude_name` is preferred over `include_name`
80
+
81
+ Other specifications are the same as `include_name`
82
+
83
+ ## `function.pointer_hint`
84
+ Provide a hint if the function argument type is a pointer
85
+
86
+ e.g.
87
+
88
+ ```yaml
89
+ function:
90
+ pointer_hint:
91
+ RSTRING_PTR: # function name (Exact match)
92
+ self: raw
93
+ rb_data_object_make:
94
+ 4: sref
95
+ ```
96
+
97
+ ### Function arguments (`1`, `2`, `3`, ...)
98
+ * `ref` (default)
99
+ * normal pointer
100
+ * e.g. 1st argument of `VALUE rb_const_list(void*)`
101
+ * `in_ref`
102
+ * input only pointer
103
+ * e.g. 2nd argument of `void rb_define_variable(const char *name, VALUE *var)`
104
+ * `sref`
105
+ * special one for multiple pointer
106
+ * e.g. 3rd argument of `rb_data_typed_object_make(VALUE klass, const rb_data_type_t *type, void **datap, size_t size)`
107
+ * `array`
108
+ * array
109
+ * e.g. 4th argument of `VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)`
110
+ * `ref_array`
111
+ * array of pointer
112
+ * e.g. 10th argument of `rb_scan_args_set(int kw_flag, int argc, const VALUE *argv, int n_lead, int n_opt, int n_trail, bool f_var, bool f_hash, bool f_block, VALUE *vars[], RB_UNUSED_VAR(const char *fmt), RB_UNUSED_VAR(int varc))`
113
+ * `str_array`
114
+ * array of string
115
+ * e.g. 2nd argument of `int rb_find_file_ext(VALUE *feature, const char *const *exts)`
116
+ * `function`
117
+ * function pointer
118
+ * e.g. 4th argument of `void rb_define_method(VALUE klass, const char *mid, VALUE (*func)(), int arity)`
119
+
120
+ ### Function return value (`self`)
121
+ * `ref` (default)
122
+ * normal pointer
123
+ * e.g. Return value of `int *rb_errno_ptr(void)`
124
+ * `raw`
125
+ * In many cases `char*` can be interpreted as a string. But if `raw` is specified, it suppresses interpretation as a string
126
+ * e.g. Return value of `char* RSTRING_PTR(VALUE str)`
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 sue445
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # RubyHeaderParser
2
+ Parser for `ruby.h`
3
+
4
+ [![test](https://github.com/sue445/ruby_header_parser/actions/workflows/test.yml/badge.svg)](https://github.com/sue445/ruby_header_parser/actions/workflows/test.yml)
5
+
6
+ ## Installation
7
+
8
+ Install the gem and add to the application's Gemfile by executing:
9
+
10
+ ```bash
11
+ bundle add ruby_header_parser
12
+ ```
13
+
14
+ If bundler is not being used to manage dependencies, install the gem by executing:
15
+
16
+ ```bash
17
+ gem install ruby_header_parser
18
+ ```
19
+
20
+ ## Requirements
21
+ Following is required in addition to Ruby.
22
+
23
+ ### ctags
24
+ macOS
25
+
26
+ ```bash
27
+ brew install universal-ctags
28
+ ```
29
+
30
+ Ubuntu
31
+
32
+ ```bash
33
+ apt-get install -y universal-ctags
34
+ ```
35
+
36
+ ## Usage
37
+ ```ruby
38
+ require "ruby_header_parser"
39
+
40
+ parser = RubyHeaderParser::Parser.new
41
+
42
+ function_definitions = parser.extract_function_definitions
43
+ static_inline_function_definitions = parser.extract_static_inline_function_definitions
44
+ struct_definitions = parser.extract_struct_definitions
45
+ type_definitions = parser.extract_type_definitions
46
+ enum_definitions = parser.extract_enum_definitions
47
+ ```
48
+
49
+ See below for details.
50
+
51
+ https://sue445.github.io/ruby_header_parser/RubyHeaderParser/Parser.html
52
+
53
+ See [CONFIG.md](CONFIG.md) for config file details
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sue445/ruby_header_parser.
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ namespace :rbs do
13
+ desc "`rbs collection install` and `git commit`"
14
+ task :install do
15
+ sh "rbs collection install"
16
+ sh "git add rbs_collection.lock.yaml"
17
+ sh "git commit -m 'rbs collection install' || true"
18
+ end
19
+ end
20
+
21
+ desc "Check rbs"
22
+ task :rbs do
23
+ sh "rbs validate"
24
+ sh "steep check"
25
+ end
26
+
27
+ desc "Run all development tasks"
28
+ task dev_all: %i[spec rubocop rbs]
29
+
30
+ task default: :dev_all
data/Steepfile ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # D = Steep::Diagnostic
4
+
5
+ target :lib do
6
+ signature "sig"
7
+
8
+ check "lib" # Directory name
9
+ # check "Gemfile" # File name
10
+ # check "app/models/**/*.rb" # Glob
11
+ # ignore "lib/templates/*.rb"
12
+
13
+ # library "pathname" # Standard libraries
14
+ # library "strong_json" # Gems
15
+
16
+ collection_config "rbs_collection.yaml"
17
+
18
+ # configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default)
19
+ # configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
20
+ # configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
21
+ # configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting
22
+ # configure_code_diagnostics do |hash| # You can setup everything yourself
23
+ # hash[D::Ruby::NoMethod] = :information
24
+ # end
25
+ end
26
+
27
+ # target :test do
28
+ # signature "sig", "sig-private"
29
+ #
30
+ # check "test"
31
+ #
32
+ # # library "pathname" # Standard libraries
33
+ # end
@@ -0,0 +1,170 @@
1
+ function:
2
+ include_name:
3
+ - !ruby/regexp /^rb_/i
4
+ - !ruby/regexp /^rstring_/i
5
+
6
+ exclude_name:
7
+ # deprecated functions
8
+ - !ruby/regexp /^rb_check_safe_str$/i
9
+ - !ruby/regexp /^rb_clear_constant_cache$/i
10
+ - !ruby/regexp /^rb_clone_setup$/i
11
+ - !ruby/regexp /^rb_complex_polar$/i
12
+ - !ruby/regexp /^rb_data_object_alloc$/i
13
+ - !ruby/regexp /^rb_data_object_get_warning$/i
14
+ - !ruby/regexp /^rb_data_object_wrap_warning$/i
15
+ - !ruby/regexp /^rb_data_typed_object_alloc$/i
16
+ - !ruby/regexp /^rb_dup_setup$/i
17
+ - !ruby/regexp /^rb_gc_force_recycle$/i
18
+ - !ruby/regexp /^rb_iterate$/i
19
+ - !ruby/regexp /^rb_obj_infect$/i
20
+ - !ruby/regexp /^rb_obj_infect_raw$/i
21
+ - !ruby/regexp /^rb_obj_taint$/i
22
+ - !ruby/regexp /^rb_obj_taint_raw$/i
23
+ - !ruby/regexp /^rb_obj_taintable$/i
24
+ - !ruby/regexp /^rb_obj_tainted$/i
25
+ - !ruby/regexp /^rb_obj_tainted_raw$/i
26
+ - !ruby/regexp /^rb_scan_args_length_mismatch$/i
27
+ - !ruby/regexp /^rb_varargs_bad_length$/i
28
+
29
+ # internal functions in ruby.h
30
+ - rb_scan_args_bad_format
31
+
32
+ # internal macros
33
+ - !ruby/regexp /^rb_define_global_function_(m?[0-9]+|notimpl)$/i
34
+ - !ruby/regexp /^rb_define_method_(m?[0-9]+|notimpl)$/i
35
+ - !ruby/regexp /^rb_define_method_id_(m?[0-9]+|notimpl)$/i
36
+ - !ruby/regexp /^rb_define_module_function_(m?[0-9]+|notimpl)$/i
37
+ - !ruby/regexp /^rb_define_private_method_(m?[0-9]+|notimpl)$/i
38
+ - !ruby/regexp /^rb_define_protected_method_(m?[0-9]+|notimpl)$/i
39
+ - !ruby/regexp /^rb_define_singleton_method_(m?[0-9]+|notimpl)$/i
40
+
41
+ # FIXME: Both `rb_hash` and `rb_Hash` are defined in ruby.h
42
+ # Converting to Go function names would result in both being `RbHash`
43
+ # Exclude one of the function names because duplicate function names will result in an error.
44
+ - rb_Hash
45
+
46
+ # Available only in certain platform
47
+ - !ruby/regexp /^rb_w32_/i
48
+
49
+ # FIXME: Workaround for "could not determine kind of name for C.rb_gc_unprotect_logging"
50
+ - rb_gc_unprotect_logging
51
+
52
+ # FIXME: Workaround for "could not determine kind of name for C.rb_iterate_deprecated"
53
+ - rb_iterate_deprecated
54
+
55
+ # FIXME: Workaround for "could not determine kind of name for C.rb_gc_guarded_ptr_val"
56
+ - rb_gc_guarded_ptr_val
57
+
58
+ # FIXME: Workaround for "cannot use _cgo2 (variable of type _Ctype_va_list) as *_Ctype_struct___va_list_tag value in argument to _Cfunc_rb_str_vcatf" on GitHub Actions (Ubuntu 22.04)
59
+ - rb_str_vcatf
60
+
61
+ # FIXME: Workaround for "cannot use _cgo4 (variable of type _Ctype_va_list) as *_Ctype_struct___va_list_tag value in argument to _Cfunc_rb_vrescue2" on GitHub Actions (Ubuntu 22.04)
62
+ - rb_vrescue2
63
+
64
+ # FIXME: Workaround for "cannot use _cgo1 (variable of type _Ctype_va_list) as *_Ctype_struct___va_list_tag value in argument to _Cfunc_rb_vsprintf" on GitHub Actions (Ubuntu 22.04)
65
+ - rb_vsprintf
66
+
67
+ # FIXME: Workaround for "undefined reference to `rb_class_descendants'" on GitHub Actions (Ubuntu 22.04)
68
+ - rb_class_descendants
69
+
70
+ pointer_hint:
71
+ RSTRING_PTR:
72
+ self: raw
73
+ rb_data_object_make:
74
+ 4: sref
75
+ rb_data_typed_object_make:
76
+ 3: sref
77
+ rb_define_global_function:
78
+ 2: function
79
+ rb_define_method:
80
+ 3: function
81
+ rb_define_method_id:
82
+ 3: function
83
+ rb_define_module_function:
84
+ 3: function
85
+ rb_define_private_method:
86
+ 3: function
87
+ rb_define_protected_method:
88
+ 3: function
89
+ rb_define_singleton_method:
90
+ 3: function
91
+ rb_define_variable:
92
+ 2: in_ref
93
+ rb_ensure:
94
+ 1: function
95
+ 3: function
96
+ rb_exec_recursive:
97
+ 1: function
98
+ rb_exec_recursive_outer:
99
+ 1: function
100
+ rb_exec_recursive_paired:
101
+ 1: function
102
+ rb_exec_recursive_paired_outer:
103
+ 1: function
104
+ rb_feature_provided:
105
+ 2: sref
106
+ rb_find_file_ext:
107
+ 2: str_array
108
+ rb_funcallv:
109
+ 4: array
110
+ rb_funcallv_public:
111
+ 4: array
112
+ rb_get_values_at:
113
+ 5: function
114
+ rb_glob:
115
+ 2: function
116
+ rb_hash_foreach:
117
+ 2: function
118
+ rb_ivar_foreach:
119
+ 2: function
120
+ rb_marshal_define_compat:
121
+ 3: function
122
+ 4: function
123
+ rb_mutex_synchronize:
124
+ 2: function
125
+ rb_protect:
126
+ 1: function
127
+ rb_rescue:
128
+ 1: function
129
+ 3: function
130
+ rb_scan_args_set:
131
+ 10: ref_array
132
+ rb_set_end_proc:
133
+ 1: function
134
+ rb_st_insert2:
135
+ 4: function
136
+ rb_thread_call_with_gvl:
137
+ 1: function
138
+ rb_thread_create:
139
+ 1: function
140
+ rb_vrescue2:
141
+ 1: function
142
+ 3: function
143
+
144
+ struct:
145
+ include_name:
146
+ - !ruby/regexp /^rb_/i
147
+ - re_registers
148
+
149
+ exclude_name:
150
+ - rb_data_type_struct
151
+
152
+ type:
153
+ include_name:
154
+ - !ruby/regexp /^rb_/i
155
+ - !ruby/regexp /^st_/i
156
+ - ID
157
+ - VALUE
158
+ - regex_t
159
+ - OnigPosition
160
+ - pid_t
161
+ - off_t
162
+
163
+ exclude_name: []
164
+
165
+ enum:
166
+ include_name:
167
+ - ruby_value_type
168
+ - rb_io_wait_readwrite
169
+
170
+ exclude_name: []
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyHeaderParser
4
+ # argument definition for {RubyHeaderParser::FunctionDefinition}
5
+ class ArgumentDefinition
6
+ # @!attribute type
7
+ # @return [String]
8
+ attr_accessor :type
9
+
10
+ # @!attribute name
11
+ # @return [String]
12
+ attr_accessor :name
13
+
14
+ # @!attribute pointer
15
+ # @return [Symbol,nil] :ref, :array
16
+ attr_accessor :pointer
17
+
18
+ # @!attribute length
19
+ # @return [Integer]
20
+ attr_accessor :length
21
+
22
+ # @param type [String]
23
+ # @param name [String]
24
+ # @param pointer [Symbol,nil] :ref, :array
25
+ # @param length [String]
26
+ def initialize(type:, name:, pointer: nil, length: 0)
27
+ @type = type
28
+ @name = name
29
+ @pointer = pointer
30
+ @length = length
31
+ end
32
+
33
+ # @param other [ArgumentDefinition]
34
+ # @return [Boolean]
35
+ def ==(other)
36
+ other.is_a?(ArgumentDefinition) && type == other.type && name == other.name && pointer == other.pointer &&
37
+ length == other.length
38
+ end
39
+
40
+ # @return [Boolean]
41
+ def pointer?
42
+ !!pointer
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyHeaderParser
4
+ # Manager for config file
5
+ class Config
6
+ # @!attribute [r] data
7
+ # @return [Hash]
8
+ attr_reader :data
9
+
10
+ # @param config_file [String]
11
+ #
12
+ # @note See [CONFIG.md](../file.CONFIG.html) for config file details
13
+ def initialize(config_file)
14
+ yaml = File.read(config_file)
15
+ @data = YAML.safe_load(yaml, aliases: true, permitted_classes: [Regexp])
16
+ end
17
+
18
+ # @param function_name [String]
19
+ # @param pos [Integer] arg position (1 origin)
20
+ # @return [Symbol] :ref, :array, :ref_array, :function, :sref, :str_array, :in_ref
21
+ def function_arg_pointer_hint(function_name:, pos:)
22
+ pointer_hint = data["function"]["pointer_hint"].dig(function_name, pos)
23
+ return pointer_hint.to_sym if pointer_hint
24
+
25
+ :ref
26
+ end
27
+
28
+ # @param function_name [String]
29
+ # @return [Symbol] :ref, :raw
30
+ def function_self_pointer_hint(function_name)
31
+ pointer_hint = data["function"]["pointer_hint"].dig(function_name, "self")
32
+ return pointer_hint.to_sym if pointer_hint
33
+
34
+ :ref
35
+ end
36
+
37
+ # rubocop:disable Style/CaseEquality
38
+
39
+ # Whether generate C function to go
40
+ # @param function_name [String]
41
+ # @return [Boolean]
42
+ def should_generate_function?(function_name)
43
+ return false if data["function"]["exclude_name"].any? { |format| format === function_name }
44
+
45
+ data["function"]["include_name"].any? { |format| format === function_name }
46
+ end
47
+
48
+ # Whether generate C struct to go
49
+ # @param struct_name [String]
50
+ # @return [Boolean]
51
+ def should_generate_struct?(struct_name)
52
+ return false if data["struct"]["exclude_name"].any? { |format| format === struct_name }
53
+
54
+ data["struct"]["include_name"].any? { |format| format === struct_name }
55
+ end
56
+
57
+ # Whether generate C type to go
58
+ # @param type_name [String]
59
+ # @return [Boolean]
60
+ def should_generate_type?(type_name)
61
+ return false if data["type"]["exclude_name"].any? { |format| format === type_name }
62
+
63
+ data["type"]["include_name"].any? { |format| format === type_name }
64
+ end
65
+
66
+ # Whether generate C enum to go
67
+ # @param enum_name [String]
68
+ # @return [Boolean]
69
+ def should_generate_enum?(enum_name)
70
+ return false if data["enum"]["exclude_name"].any? { |format| format === enum_name }
71
+
72
+ data["enum"]["include_name"].any? { |format| format === enum_name }
73
+ end
74
+
75
+ # rubocop:enable Style/CaseEquality
76
+ end
77
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyHeaderParser
4
+ # enum definition in header file
5
+ class EnumDefinition
6
+ # @!attribute name
7
+ # @return [String]
8
+ attr_accessor :name
9
+
10
+ # @!attribute enum_value_definitions
11
+ # @return [Array<String>]
12
+ attr_accessor :values
13
+
14
+ # @param name [String]
15
+ # @param values [Array<String>]
16
+ def initialize(name:, values: [])
17
+ @name = name
18
+ @values = values
19
+ end
20
+
21
+ # @param other [EnumDefinition]
22
+ # @return [Boolean]
23
+ def ==(other)
24
+ other.is_a?(EnumDefinition) && name == other.name && values == other.values
25
+ end
26
+ end
27
+ end