In Files

  • doc/language/mrbdoc/lib/mrbdoc_analyze.rb

MRBFile

Attributes

file[R]
name[R]

Public Class Methods

new(mrb_file) click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 87
def initialize mrb_file
  @file = mrb_file
  @name = File.basename file
  @c_funcs = {}
  @rb_class_c_def = {}
  @rb_method_c_def = {}
  @rb_class_method_c_def = {}
  @rb_module_c_def = {}
  @last_line = nil
  @assignments = {}

  @assignments['mrb->object_class'] = 'Object'
  @assignments['mrb->kernel_module'] = 'Kernel'
  @assignments['mrb->module_class'] = 'Module'
  @assignments['mrb->nil_class'] = 'NilClass'
  @assignments['mrb->true_class'] = 'TrueClass'
  @assignments['mrb->class_class'] = 'Class'

  analyze
end
            

Public Instance Methods

c_funcs(c_func_name;) click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 139
def c_funcs c_func_name; @c_funcs[c_func_name]; end
            
each_class(&block) click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 108
def each_class &block
  @rb_class_c_def.each do |class_name, class_hsh|
    block.call class_name, class_hsh
  end
end
            
each_class_method(name, &block) click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 121
def each_class_method name, &block
  @rb_class_method_c_def.each do |met_name, met_hsh|
    met_name_tmp = met_name.sub /^#{name}_/, ''
    block.call met_name_tmp, met_hsh if met_hsh[:rb_class] == name
  end
end
            
each_core_object(&block) click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 134
def each_core_object &block
  each_class {|n| block.call n}
  each_module {|n| block.call n}
end
            
each_method(name, &block) click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 114
def each_method name, &block
  @rb_method_c_def.each do |met_name, met_hsh|
    met_name_tmp = met_name.sub /^#{name}_/, ''
    block.call met_name_tmp, met_hsh if met_hsh[:rb_class] == name
  end
end
            
each_module(&block) click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 128
def each_module &block
  @rb_module_c_def.each do |module_name, module_hsh|
    block.call module_name, module_hsh
  end
end
            
rb_class(rb_class_name;) click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 140
def rb_class rb_class_name; @rb_class_c_def[rb_class_name]; end
            
rb_module(rb_module_name;) click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 141
def rb_module rb_module_name; @rb_module_c_def[rb_module_name]; end
            

Private Instance Methods

analyze() click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 145
def analyze
  File.open(file).each_line.each_with_index do |line, idx|
    line_no = idx.succ
    if c_file?
      analyze_c_line line, line_no
    elsif rb_file?
      analyze_rb_line line, line_no
    else
      raise ArgumentError.new "#{file} is a not supported file type"
    end
    @last_line = line.strip
  end
end
            
analyze_c_line(line, line_no) click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 167
def analyze_c_line line, line_no
  case line.strip
  when /^([a-zA-Z\_][a-zA-Z\_0-9]*?)\((.*?)\)\s*?$/
    # assuming c method definition
    @c_funcs[$1] = {:line_no => line_no, :args => $2, :return => @last_line}
  when /mrb_define_class\(.*?\,#{RXP_C_STR}\,#{RXP_C_VAR}\)#{RXP_C_ISO}/
    # assuming ruby class definition in c
    class_name = $1.clone
    iso = $3.clone
    iso.strip!
    @rb_class_c_def[class_name] = {:c_object => $2, :iso => iso}
    assigns = line.split '='
    if assigns.size > 1
      assigns[0..-2].each do |v|
        @assignments[v.strip] = class_name
      end
    end
  when /mrb_define_module\(.*?\,#{RXP_C_STR}\)#{RXP_C_ISO}/
    # assuming ruby class definition in c
    module_name = $1.clone
    iso = $2.clone
    iso.strip!
    @rb_module_c_def[module_name] = {:iso => iso}
    assigns = line.split '='
    if assigns.size > 1
      assigns[0..-2].each do |v|
        @assignments[v.strip] = module_name
      end
    end
  when /mrb_define_method\(.*?\,#{RXP_C_VAR}\,#{RXP_C_STR}\,#{RXP_C_VAR}\,#{RXP_C_VAR}\)#{RXP_C_ISO}/
    # assuming ruby method definition in c
    name = $1.clone
    name = resolve_obj(name)
    iso = $5.clone
    iso.strip!
    @rb_method_c_def["#{name}_#{$2}"] = {:c_func => $3, :args => $4, :rb_class => name, :iso => iso}
  when /mrb_define_class_method\(.*?\,#{RXP_C_VAR}\,#{RXP_C_STR}\,#{RXP_C_VAR}\,#{RXP_C_VAR}\)#{RXP_C_ISO}/
    # assuming ruby class method definition in c
    class_name = $1.clone
    class_name = resolve_obj(class_name)
    iso = $5.clone
    iso.strip!
    @rb_class_method_c_def["#{class_name}_#{$2}"] = {:c_func => $3, :args => $4, :rb_class => class_name, :iso => iso}
  when /mrb_name_class\(.*?\,#{RXP_C_VAR}\,\s*mrb_intern\(.*?,#{RXP_C_STR}\)\)#{RXP_C_ISO}/
    class_name = $2.clone
    iso = $3.clone
    iso.strip!
    @rb_class_c_def[class_name] = {:c_object => $1, :iso => iso}
    @assignments[$1] = class_name
  when /mrb_include_module\(.*?\,#{RXP_C_VAR}\,\s*mrb_class_get\(.*?\,#{RXP_C_STR}\)\)/
    class_name = resolve_obj($1)
    mod = $2.clone
    @rb_class_c_def[class_name][:include] = [] unless @rb_class_c_def[class_name].has_key? :include
    @rb_class_c_def[class_name][:include] << mod
  end
end
            
analyze_rb_line(line, line_no) click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 224
def analyze_rb_line line, line_no

end
            
c_file?() click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 159
def c_file?; (name =~ /\.c$/); end
            
rb_file?() click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 160
def rb_file?; (name =~ /\.rb$/); end
            
resolve_obj(c_var) click to toggle source
 
               # File doc/language/mrbdoc/lib/mrbdoc_analyze.rb, line 228
def resolve_obj c_var
  @assignments[c_var]
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus