Class: MilkTea::Bindgen::Generator
- Inherits:
-
Object
- Object
- MilkTea::Bindgen::Generator
- Includes:
- GeneratorAstParser, GeneratorDeclaration, GeneratorEmitter, GeneratorOverrides, GeneratorTypeMapper
- Defined in:
- lib/milk_tea/bindings/bindgen.rb,
lib/milk_tea/bindings/bindgen/emitter.rb,
lib/milk_tea/bindings/bindgen/overrides.rb,
lib/milk_tea/bindings/bindgen/ast_parser.rb,
lib/milk_tea/bindings/bindgen/declaration.rb,
lib/milk_tea/bindings/bindgen/type_mapper.rb
Defined Under Namespace
Modules: GeneratorAstParser, GeneratorDeclaration, GeneratorEmitter, GeneratorOverrides, GeneratorTypeMapper
Instance Method Summary collapse
- #generate ⇒ Object
- #generate_with_report ⇒ Object
-
#initialize(module_name:, header_path:, tracked_header_paths:, tracked_header_prefixes:, declaration_name_prefixes:, excluded_declaration_names:, link_libraries:, include_directives:, bindgen_defines:, bindgen_include_directives:, module_imports:, clang:, clang_args:, type_name_overrides:, type_overrides:, function_param_type_overrides:, function_return_type_overrides:, field_type_overrides:, allow_static_inline_functions:, strip_leading_underscores: false) ⇒ Generator
constructor
A new instance of Generator.
Methods included from GeneratorOverrides
#field_type_override, #function_param_type_override, #function_return_type_override, #normalize_field_type_overrides, #normalize_function_param_type_overrides, #normalize_function_return_type_overrides, #normalize_module_imports, #normalize_type_name_overrides, #normalize_type_overrides
Methods included from GeneratorEmitter
#aggregate_field_name, #aggregate_field_type, #anonymous_record_decl_for_field, #bindgen_param_name, #discover_synthetic_aggregate_dependencies, #discover_synthetic_field_type_dependencies, #emit_aggregate_declaration, #emit_declaration, #emit_enum_declaration, #emit_float_value, #emit_function_declaration, #emit_module, #emitted_name, #enum_member_values, #generated_binding_name_conflict?, #generated_module_path, #integer_value, #lower_aggregate_init_list, #lower_constant_expression, #lower_init_list_expression, #lower_zero_value, #parse_array_type, #pointer_zero_literal, #source_location_key, #synthetic_aggregate_name
Methods included from GeneratorTypeMapper
#aggregate_explicit_c_name, #apply_nullability, #array_type?, #build_function_type, #c_string_pointer?, #direct_typedef_surface?, #enum_name_for, #extract_function_proto, #extract_top_level_nullability, #function_params_from_source, #function_pointer_surface_nullability, #function_pointer_type?, #function_type_typedef?, #infer_bindgen_type, #integer_typedef_primitive, #known_generated_type_name?, #long_width_bytes, #long_width_type, #map_array_type, #map_c_type, #map_function_pointer_type, #map_function_pointer_typedef, #map_function_proto_node, #map_long_type, #map_type_node, #matching_open_paren_index, #normalize_c_type, #nullability_for_token, #nullable_policy_type?, #parse_function_pointer_signature, #pointer_suffix_qualifiers, #pointer_type?, #preserve_typedef_name?, #record_c_name, #record_name_for, #record_nullable_param_override, #record_nullable_return_override, #split_top_level_csv, #standard_typedef_primitive, #string_literal_macro_compatible_c_type?, #strip_pointer_suffix_qualifiers, #strip_qualifiers, #synthesize_record_dependency, #synthesize_typedef_dependency, #synthetic_declarations_for, #top_level_const_qualified?, #typedef_name_from_type_node, #unresolved_alias_target?, #va_list_pointer?, #visible_type_name, #void_type_node?
Methods included from GeneratorDeclaration
#alias_qual_type, #constant_expression_kind, #constant_qual_type, #constant_var_decl?, #enum_kind, #function_return_type, #macro_string_constant_type, #power_of_two?, #record_complete_definition?, #select_constant_declarations, #select_enum_declarations, #select_function_declarations, #select_record_declarations, #select_type_alias_declarations, #type_qual_type, #validate_field_type_overrides!, #validate_function_param_type_overrides!, #validate_function_return_type_overrides!
Methods included from GeneratorAstParser
#active_macro_name?, #allowed_declaration_name?, #build_alias_maps, #constant_name_for, #contains_disallowed_macro_call?, #dump_ast, #each_macro_definition, #extract_top_level_header_nodes, #index_referenceable_record_declarations, #interesting_top_level_kind?, #macro_constant_candidate?, #macro_constant_candidates, #macro_probe_declaration?, #macro_probe_declarations, #macro_probe_name, #matching_paren_index, #node_from_header?, #node_include_files, #node_source_files, #normalize_macro_body, #normalize_preprocessor_path, #preprocessed_macro_names, #preprocessed_macro_source, #tracked_header_path?, #typedef_owned_tag_nodes, #typedef_owned_tag_nodes_from, #typedef_target, #write_translation_unit_prelude
Constructor Details
#initialize(module_name:, header_path:, tracked_header_paths:, tracked_header_prefixes:, declaration_name_prefixes:, excluded_declaration_names:, link_libraries:, include_directives:, bindgen_defines:, bindgen_include_directives:, module_imports:, clang:, clang_args:, type_name_overrides:, type_overrides:, function_param_type_overrides:, function_return_type_overrides:, field_type_overrides:, allow_static_inline_functions:, strip_leading_underscores: false) ⇒ Generator
Returns a new instance of Generator.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/milk_tea/bindings/bindgen.rb', line 109 def initialize(module_name:, header_path:, tracked_header_paths:, tracked_header_prefixes:, declaration_name_prefixes:, excluded_declaration_names:, link_libraries:, include_directives:, bindgen_defines:, bindgen_include_directives:, module_imports:, clang:, clang_args:, type_name_overrides:, type_overrides:, function_param_type_overrides:, function_return_type_overrides:, field_type_overrides:, allow_static_inline_functions:, strip_leading_underscores: false) @module_name = module_name @header_path = File.(header_path) @tracked_header_paths = ([header_path] + tracked_header_paths).map { |path| File.(path) }.uniq.freeze @tracked_header_prefixes = tracked_header_prefixes.map { |path| File.(path) }.uniq.freeze @declaration_name_prefixes = declaration_name_prefixes.dup.freeze @excluded_declaration_names = excluded_declaration_names.map(&:to_s).freeze @link_libraries = link_libraries.dup @include_directives = include_directives&.dup @bindgen_defines = bindgen_defines.dup.freeze @bindgen_include_directives = bindgen_include_directives.dup.freeze @module_imports = normalize_module_imports(module_imports) @clang = clang @clang_args = clang_args.dup @type_name_overrides = normalize_type_name_overrides(type_name_overrides) @type_overrides = normalize_type_overrides(type_overrides) @function_param_type_overrides = normalize_function_param_type_overrides(function_param_type_overrides) @function_return_type_overrides = normalize_function_return_type_overrides(function_return_type_overrides) @field_type_overrides = normalize_field_type_overrides(field_type_overrides) @allow_static_inline_functions = allow_static_inline_functions @strip_leading_underscores = strip_leading_underscores @record_aliases = {} @record_aliases_by_tag_name = {} @enum_aliases = {} @record_visible_names = {} @enum_visible_names = {} @referenceable_record_declarations = {} @referenceable_record_declarations_by_id = {} @aggregate_declarations = {} @synthetic_declarations = [] @manual_nullable_param_overrides = [] @manual_nullable_return_overrides = [] end |
Instance Method Details
#generate ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/milk_tea/bindings/bindgen.rb', line 143 def generate ast = dump_ast index_referenceable_record_declarations(ast) top_level_nodes = extract_top_level_header_nodes(ast) @visible_typedef_names = top_level_nodes.filter_map do |node| node["name"] if node["kind"] == "TypedefDecl" && allowed_declaration_name?(node["name"]) end @function_type_typedef_names = top_level_nodes.filter_map do |node| if node["kind"] == "TypedefDecl" && allowed_declaration_name?(node["name"]) && extract_function_proto(node) && !function_pointer_type?(type_qual_type(node)) node["name"] end end build_alias_maps(top_level_nodes) declarations = [] declarations.concat(select_record_declarations(top_level_nodes)) validate_field_type_overrides!(declarations) discover_synthetic_aggregate_dependencies(declarations) discover_synthetic_field_type_dependencies(declarations) declarations.concat(select_enum_declarations(top_level_nodes)) declarations.concat(select_type_alias_declarations(top_level_nodes)) declarations.concat(select_constant_declarations(top_level_nodes)) function_declarations = select_function_declarations(top_level_nodes) validate_function_param_type_overrides!(function_declarations) validate_function_return_type_overrides!(function_declarations) declarations.concat(function_declarations) declarations.sort_by! { |declaration| declaration[:index] } emit_module(declarations) end |
#generate_with_report ⇒ Object
174 175 176 177 178 179 180 |
# File 'lib/milk_tea/bindings/bindgen.rb', line 174 def generate_with_report source = generate { source:, nullable_policy_report: nullable_policy_report, } end |