lib/ffi/clang/index.rb in ffi-clang-0.2.0 vs lib/ffi/clang/index.rb in ffi-clang-0.2.1

- old
+ new

@@ -1,7 +1,8 @@ # Copyright, 2010-2012 by Jari Bakken. # Copyright, 2013, by Samuel G. D. Williams. <http://www.codeotaku.com> +# Copyright, 2014, by Masahiro Sano. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -27,24 +28,30 @@ def initialize(exclude_declarations = true, display_diagnostics = false) super Lib.create_index(exclude_declarations ? 1 : 0, display_diagnostics ? 1 : 0) end def self.release(pointer) - Lib.dispose_index_debug(pointer) + Lib.dispose_index(pointer) end def parse_translation_unit(source_file, command_line_args = nil, unsaved = [], opts = {}) command_line_args = Array(command_line_args) - unsaved_files = unsaved_pointer_from(unsaved) + unsaved_files = UnsavedFile.unsaved_pointer_from(unsaved) translation_unit_pointer = Lib.parse_translation_unit(self, source_file, args_pointer_from(command_line_args), command_line_args.size, unsaved_files, unsaved.length, options_bitmask_from(opts)) raise Error, "error parsing #{source_file.inspect}" if translation_unit_pointer.null? TranslationUnit.new translation_unit_pointer, self end + def create_translation_unit(ast_filename) + tu_pointer = Lib.create_translation_unit(self, ast_filename) + raise Error, "error parsing #{ast_filename.inspect}" if tu_pointer.null? + TranslationUnit.new tu_pointer, self + end + private def args_pointer_from(command_line_args) args_pointer = MemoryPointer.new(:pointer, command_line_args.length) @@ -56,24 +63,9 @@ args_pointer end def options_bitmask_from(opts) Lib.bitmask_from Lib::TranslationUnitFlags, opts - end - - def unsaved_pointer_from(unsaved) - return nil if unsaved.length == 0 - - vec = MemoryPointer.new(Lib::CXUnsavedFile, unsaved.length) - - unsaved.each_with_index do |file, i| - uf = Lib::CXUnsavedFile.new(vec + i * Lib::CXUnsavedFile.size) - uf[:filename] = MemoryPointer.from_string(file.filename) - uf[:contents] = MemoryPointer.from_string(file.contents) - uf[:length] = file.contents.length - end - - vec end end end end