lib/docurium/docparser.rb in docurium-0.4.0 vs lib/docurium/docparser.rb in docurium-0.4.1

- old
+ new

@@ -1,5 +1,7 @@ +require 'tempfile' +require 'fileutils' require 'ffi/clang' include FFI::Clang class Docurium class DocParser @@ -14,11 +16,11 @@ tmpdir = Dir.mktmpdir() unsaved = files.map do |name, contents| full_path = File.join(tmpdir, name) dirname = File.dirname(full_path) - Dir.mkdir(dirname) unless Dir.exists? dirname + FileUtils.mkdir_p(dirname) unless Dir.exists? dirname File.new(full_path, File::CREAT).close() UnsavedFile.new(full_path, contents) end @@ -99,56 +101,65 @@ subject, desc = extract_subject_desc(cursor.comment) rec[:decl] = cursor.spelling rec[:description] = subject rec[:comments] = desc else - raise "typede of unhandled #{child.type.kind}" + rec[:name] = cursor.spelling end when :cursor_enum_decl rec.merge! extract_enum(child) when :cursor_struct #puts "typed struct, #{cursor.spelling}" rec.merge! extract_struct(child) when :cursor_parm_decl - #puts "have parm #{cursor.spelling}, #{cursor.display_name}" - subject, desc = extract_subject_desc(cursor.comment) - rec[:decl] = cursor.spelling - rec[:description] = subject - rec[:comments] = desc - when :cursor_type_ref - rec[:decl] = cursor.spelling + rec.merge! extract_function(cursor) + rec[:type] = :callback + # this is wasteful, but we don't get the array from outside + cmt = extract_function_comment(cursor.comment) + ret = { + :type => extract_callback_result(rec[:underlying_type]), + :comment => cmt[:return] + } + rec[:return] = ret else raise "No idea how to handle #{child.kind}" end # let's make sure we override the empty name the extract # functions stored rec[:name] = cursor.spelling rec end - def extract_subject_desc(comment) - subject = comment.child.text - desc = (comment.find_all { |cmt| cmt.kind == :comment_paragraph }).drop(1).map(&:text).join("\n\n") - return subject, desc + def extract_callback_result(type) + type[0..(type.index('(') - 1)].strip end - def extract_function(cursor) - comment = cursor.comment - - #puts "looking at function #{cursor.spelling}, #{cursor.display_name}" - cmt = extract_function_comment(comment) - + def extract_function_args(cursor, cmt) # We only want to look at parm_decl to avoid looking at a return # struct as a parameter - args = children(cursor) + children(cursor) .select {|c| c.kind == :cursor_parm_decl } .map do |arg| { :name => arg.display_name, :type => arg.type.spelling, :comment => cmt[:args][arg.display_name], } end + end + + def extract_subject_desc(comment) + subject = comment.child.text + desc = (comment.find_all { |cmt| cmt.kind == :comment_paragraph }).drop(1).map(&:text).join("\n\n") + return subject, desc + end + + def extract_function(cursor) + comment = cursor.comment + + #puts "looking at function #{cursor.spelling}, #{cursor.display_name}" + cmt = extract_function_comment(comment) + args = extract_function_args(cursor, cmt) #args = args.reject { |arg| arg[:comment].nil? } ret = { :type => cursor.result_type.spelling, :comment => cmt[:return]