Class: RubyBindgen::Parser
- Inherits:
-
Object
- Object
- RubyBindgen::Parser
- Defined in:
- lib/ruby-bindgen/parser.rb
Defined Under Namespace
Classes: ParseError
Instance Attribute Summary collapse
-
#clang_args ⇒ Object
readonly
Returns the value of attribute clang_args.
-
#inputter ⇒ Object
readonly
Returns the value of attribute inputter.
Instance Method Summary collapse
- #generate(visitor) ⇒ Object
-
#initialize(inputter, clang_args, libclang: nil) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(inputter, clang_args, libclang: nil) ⇒ Parser
Returns a new instance of Parser.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby-bindgen/parser.rb', line 28 def initialize(inputter, clang_args, libclang: nil) @inputter = inputter @clang_args = clang_args # Set libclang path before loading ffi-clang (it reads ENV on load) ENV['LIBCLANG'] = libclang if libclang # Lazy-load ffi-clang and its refinements so CMake format doesn't need libclang require 'ffi/clang' require 'ruby-bindgen/refinements/cursor' @index = FFI::Clang::Index.new(exclude_declarations_from_pch: false, display_diagnostics: true) end |
Instance Attribute Details
#clang_args ⇒ Object (readonly)
Returns the value of attribute clang_args.
26 27 28 |
# File 'lib/ruby-bindgen/parser.rb', line 26 def clang_args @clang_args end |
#inputter ⇒ Object (readonly)
Returns the value of attribute inputter.
26 27 28 |
# File 'lib/ruby-bindgen/parser.rb', line 26 def inputter @inputter end |
Instance Method Details
#generate(visitor) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby-bindgen/parser.rb', line 42 def generate(visitor) visitor.visit_start STDOUT << "\n" << "Processing:" << "\n" self.inputter.each do |path, relative_path| STDOUT << " " << path << "\n" begin translation_unit = parse_translation_unit(path) rescue ParseError => error raise unless visitor.respond_to?(:visit_parse_error) visitor.visit_parse_error(path, relative_path, error) next end visitor.visit_translation_unit(translation_unit, path, relative_path) end visitor.visit_end end |