class Archruby::Ruby::Parser

Attributes

classes[R]
classes_and_dependencies[R]
dependencies[R]
method_calls[R]
type_inference[R]
type_propagation_parser[R]

Public Class Methods

new(content) click to toggle source
Calls superclass method
# File lib/archruby/ruby/parser.rb, line 11
def initialize(content)
  super()
  #a = Archruby::Presenters::Graph.new
  @content = content
  @dependencies = []
  @classes = []
  @full_class_path = []
  @classes_and_dependencies = {}
  @module_names = []
  @complete_class_name = []
  @var_propagation = Archruby::Ruby::VarPropagation.new
  @type_propagation_parser = Archruby::Ruby::TypeInference::Ruby::ParserForTypeinference.new
  @type_inference = []
  @method_calls = []
  parse
end

Public Instance Methods

add_dependency(const_name) click to toggle source
# File lib/archruby/ruby/parser.rb, line 94
def add_dependency(const_name)
  @dependencies << const_name.to_s if !@dependencies.include?(const_name.to_s)
end
build_call_history(receiver, method_name, params_name) click to toggle source
# File lib/archruby/ruby/parser.rb, line 117
def build_call_history(receiver, method_name, params_name)
  @method_calls << {
    :class => @classes.last,
    :method => @current_method_name,
    :method_arguments => @current_arguments,
    :class_call => receiver,
    :method_call => method_name,
    :method_call_params => params_name
  }
end
build_class_dependency(const_name, line_number) click to toggle source
# File lib/archruby/ruby/parser.rb, line 83
def build_class_dependency(const_name, line_number)
  return if @classes.empty?
  class_name = @classes.last
  @classes_and_dependencies[class_name] = [] if @classes_and_dependencies[class_name].nil?
  @classes_and_dependencies[class_name] << Archruby::Architecture::Dependency.new(const_name, line_number)
end
build_full_name(const_name) click to toggle source
# File lib/archruby/ruby/parser.rb, line 76
def build_full_name(const_name)
  @full_class_path.unshift(const_name)
  full_class_path = @full_class_path.join('::')
  @full_class_path = []
  full_class_path
end
build_type_inference(receiver, method_name, params, line_num) click to toggle source
# File lib/archruby/ruby/parser.rb, line 128
def build_type_inference(receiver, method_name, params, line_num)
  if !@local_types.nil? && receiver && receiver[0] == :lvar
    receiver = @local_types[receiver[1]]
    params_name = []
    deps = []
    params.each do |param|
      if param[0] == :lvar
        params_name << param[1]
        type_inference = TypeInferenceDep.new(
          :class_source => @classes.last,
          :class_dep => @local_types[param[1]],
          :line_source_num => line_num
        )
        deps << type_inference
      elsif param[0] == :call
        process param
        type_inference = TypeInferenceDep.new(
          :class_source => @classes.last,
          :class_dep => @dependencies.last,
          :line_source_num => line_num
        )
        deps << type_inference
      end
    end
    build_call_history(receiver, method_name, params_name)
    @type_inference << {
      :class_name => receiver,
      :method_name => method_name,
      :dep => deps
    } if deps.size >= 1
  end
end
extract_arguments(arguments) click to toggle source
# File lib/archruby/ruby/parser.rb, line 161
def extract_arguments(arguments)
  _, *arg_vars = arguments
  if arg_vars[0].class == Symbol
    @current_arguments = arg_vars
  end
end
get_complete_class_name(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 55
def get_complete_class_name(exp)
  if exp[0] == :const
    _, const_name = exp
    @complete_class_name.unshift(const_name)
    return
  else
    _, first_part, last_constant_part = exp
    @complete_class_name.unshift(last_constant_part)
    get_complete_class_name first_part
  end
end
parse() click to toggle source
# File lib/archruby/ruby/parser.rb, line 28
def parse
  process ruby_parser.parse(@content)
  @type_propagation_parser.parse(@content)
end
process_and(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 295
def process_and(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_arglist(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 342
def process_arglist(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_args(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 215
def process_args(exp)
  _, *args = exp
  args.map! do |sub_tree|
    process sub_tree if sub_tree.class != Symbol
  end
end
process_array(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 286
def process_array(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_attrasgn(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 257
def process_attrasgn(exp)
  _, object, method_call, *args = exp
  process(object)
  args.map! {|sub_tree| process(sub_tree)}
end
process_block(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 33
def process_block(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_block_pass(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 347
def process_block_pass(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_break(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 433
def process_break(exp)
  _ = exp
end
process_call(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 105
def process_call(exp)
  _, receiver, method_name, *args = exp
  process(receiver)
  if receiver && (receiver[0] == :const || receiver[0] == :colon2)
    if @variables
      @var_propagation.push(@variables.last, exp.line, @dependencies.last)
    end
  end
  build_type_inference(receiver, method_name, args, exp.line)
  args.map! {|sub_tree| process sub_tree}
end
process_case(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 327
def process_case(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_cdecl(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 291
def process_cdecl(exp)
  _, constant_name = exp
end
process_class(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 38
def process_class(exp)
  _, class_name, *args = exp
  if class_name.class == Symbol
    if !@module_names.empty?
      @classes << "#{@module_names.join("::")}::#{class_name}"
    else
      @classes << class_name.to_s
    end
  else
    # cai aqui quando a definicao é algo do tipo: class Teste::De end
    get_complete_class_name(class_name)
    @classes << @complete_class_name.join("::")
    @complete_class_name = []
  end
  args.map! {|sub_tree| process(sub_tree)}
end
process_colon2(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 235
def process_colon2(exp)
  _, first_part, last_part = exp
  @full_class_path.unshift(last_part)
  process(first_part)
end
process_colon3(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 98
def process_colon3(exp)
  _, constant_name = exp
  const_name = build_full_name("::#{constant_name}")
  add_dependency(const_name)
  build_class_dependency(const_name, exp.line)
end
process_const(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 67
def process_const(exp)
  _, const_name = exp
  if !@full_class_path.empty?
    const_name = build_full_name(const_name)
  end
  add_dependency(const_name)
  build_class_dependency(const_name, exp.line)
end
process_cvar(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 397
def process_cvar(exp)
  _, variable_name = exp
end
process_cvdecl(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 392
def process_cvdecl(exp)
  _, variable_name, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_defn(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 168
def process_defn(exp)
  @variables = []
  @local_types = {}
  _, method_name, method_arguments, *args = exp
  @current_method_name = method_name
  extract_arguments(method_arguments)
  process(method_arguments)
  args.map! {|sub_tree| process sub_tree}
  @var_propagation.vars.each do |var|
    var = var[var.keys.first]
    if var[:type]
      var[:lines].shift
      var[:lines].each do |line_number|
        build_class_dependency(var[:type], line_number)
      end
    end
  end
  @var_propagation = Archruby::Ruby::VarPropagation.new
  @variables = []
  @current_method_name = nil
  @current_arguments = nil
end
process_defs(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 251
def process_defs(exp)
  _, receiver, method_name, arguments, *args = exp
  process(arguments)
  args.map! {|sub_tree| process(sub_tree)}
end
process_dot2(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 414
def process_dot2(exp)
  _, first, second = exp
end
process_dot3(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 468
def process_dot3(exp)
  _ = exp
end
process_dregx(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 437
def process_dregx(exp)
  _, regex = exp
end
process_dstr(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 267
def process_dstr(exp)
  _, string, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_dxstr(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 463
def process_dxstr(exp)
  # shelling out
  _ = exp
end
process_ensure(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 446
def process_ensure(exp)
  _, rescue_clause, *ensure_clause = exp
  process(rescue_clause)
  ensure_clause.map! {|sub_tree| process(sub_tree)}
end
process_evstr(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 272
def process_evstr(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_false(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 323
def process_false(exp)
  _ = exp
end
process_for(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 90
def process_for(exp)
  
end
process_gvar(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 310
def process_gvar(exp)
  _, ruby_global_var_name = exp
end
process_hash(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 241
def process_hash(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_iasgn(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 246
def process_iasgn exp
  _, variable_name, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_if(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 314
def process_if(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_iter(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 210
def process_iter(exp)
  _, *args = exp
  args.map! {|sub_tree| next if sub_tree.class == Fixnum; process(sub_tree)}
end
process_ivar(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 263
def process_ivar(exp)
  _, instance_variable_name = exp
end
process_lasgn(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 191
def process_lasgn(exp)
  _, variable_name, *args = exp
  const_access = args[0][0] == :call unless args[0].nil?
  @variables.push(variable_name) if @variables
  args.map!{ |sub_tree| process(sub_tree) }
  if @local_types.class == Hash && const_access
    @local_types[variable_name] = @dependencies.last
  end
end
process_lit(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 201
def process_lit(exp)
  _, value = exp
end
process_lvar(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 205
def process_lvar(exp)
  _, variable_name = exp
  @var_propagation.push(variable_name, exp.line)
end
process_masgn(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 281
def process_masgn(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_match3(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 428
def process_match3(exp)
  _, regular_expression, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_module(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 366
def process_module(exp)
  _, module_name, *args = exp
  if module_name.class == Symbol
    @module_names.push(module_name.to_s)
    @classes << @module_names.join('::')
  else
    get_complete_class_name(module_name)
    @classes << @complete_class_name.join('::')
    @module_names.push @complete_class_name.join('::')
    @complete_class_name = []
  end
  args.map! {|sub_tree| process(sub_tree)}
  @module_names.pop
end
process_next(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 362
def process_next(exp)
  _ = exp
end
process_nil(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 222
def process_nil(exp)
  _ = exp
end
process_op_asgn1(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 337
def process_op_asgn1(exp)
  _, variabe_rec, position_to_access, operator, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_op_asgn2(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 452
def process_op_asgn2(exp)
  _, left_assign, variable, method, args = exp
  process(left_assign)
  process(args)
end
process_op_asgn_or(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 422
def process_op_asgn_or(exp)
  _, first, second = exp
  process(first)
  process(second)
end
process_or(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 352
def process_or(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_resbody(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 305
def process_resbody(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_rescue(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 300
def process_rescue(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_return(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 230
def process_return(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree) }
end
process_sclass(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 357
def process_sclass(exp)
  _, *args = exp
  args.map! {|sub_tree| process sub_tree}
end
process_self(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 277
def process_self(exp)
  _ = exp
end
process_splat(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 458
def process_splat(exp)
  _, left_assign = exp
  process(left_assign)
end
process_str(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 226
def process_str(exp)
  _, string = exp
end
process_super(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 441
def process_super(exp)
  _, args = exp
  process(args)
end
process_to_ary(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 381
def process_to_ary(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_true(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 319
def process_true(exp)
  _ = exp
end
process_until(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 401
def process_until(exp)
  _, condition, *args = exp
  true_clause = args.pop
  args.map! {|sub_tree| process(sub_tree)}
end
process_when(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 332
def process_when(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end
process_while(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 386
def process_while(exp)
  _, condition, *args = exp
  true_clause = args.pop
  args.map! {|sub_tree| process(sub_tree)}
end
process_yield(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 407
def process_yield(exp)
  _, *body = exp
  if !body.empty?
    body.map! {|sub_tree| process(sub_tree)}
  end
end
process_zsuper(exp) click to toggle source
# File lib/archruby/ruby/parser.rb, line 418
def process_zsuper(exp)
  _ = exp
end
ruby_parser() click to toggle source
# File lib/archruby/ruby/parser.rb, line 472
def ruby_parser
  RubyParser.new
end