class Kurangu

Public Instance Methods

apply_annotation(annotated_path, original_path) click to toggle source
# File lib/kurangu.rb, line 75
def apply_annotation(annotated_path, original_path)
  puts "\napplying annotations for #{original_path}\n"
  FileUtils.mv(annotated_path, original_path)
end
apply_annotations(paths_file) click to toggle source
# File lib/kurangu.rb, line 80
def apply_annotations(paths_file)
  File.open(paths_file, "r") do |f|
    f.each_line do |annotation_path|
      original_path = annotation_path.chomp('.annotations')
      annotated_path = "#{original_path}.annotated"
      apply_annotation(annotated_path, original_path)
    end
  end
end
generate_annotated_files(paths_file) click to toggle source
# File lib/kurangu.rb, line 29
def generate_annotated_files(paths_file)
  File.open(paths_file, "r") do |f|
    f.each_line do |annotation_path|
      original_path = annotation_path.chomp('.annotations')
      annotated_path = "#{original_path}.annotated"
      puts "\ngenerating annotated file #{annotated_path}\n"
      annotations = Hash.new { |h, k| h[k] = [] }
      File.open(annotation_path, "r") do |f|
        f.each_line do |line|
          split = line.split(" ", 2)
          index = split[0].to_i
          annotations[index].push split[1]
        end
      end
      lines = []
      has_types = false
      File.open(original_path, "r") do |f|
        f.each_line.with_index do |line, index|
          whitespace = line.chomp(line.lstrip)
          if annotations[index + 1].size > 0
            if lines.last and lines.last.start_with?('type')
              has_types = true
              lines.last = "#{whitespace}#{annotations[index + 1][0]}"
              annotations[index + 1].drop(1).each do |annotation|
                lines << "#{whitespace}#{annotation}"
              end
            else
              lines << "#{whitespace}extend RDL::Annotate\n"
              annotations[index + 1].each do |annotation|
                lines << "#{whitespace}#{annotation}"
              end
            end
            lines << "\n"
          end
          lines << line
        end
      end
      if !has_types
        lines.unshift "require 'types/core'\n\n"
        lines.unshift "require 'rdl'\n"
      end
      IO.write(annotated_path, lines.join())
    end
  end
end
generate_annotations(input_file) click to toggle source
# File lib/kurangu.rb, line 6
def generate_annotations(input_file)
  ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
  trace_file = File.expand_path("lib/trace.rb")
  puts "\ngenerating annotations\n"
  Open3.popen2("#{ruby} -r #{trace_file} #{input_file}") {|stdin, stdout, wait_thr|
    stdin.puts(input_file)
    puts stdout.read
  }
end
print_annotations(paths_file) click to toggle source
run(input_file_path) click to toggle source
# File lib/kurangu.rb, line 96
def run(input_file_path)
  input_file = File.expand_path(input_file_path)
  paths_file = "#{File.dirname(input_file)}/annotations_paths.txt"
  self.generate_annotations(input_file)
  self.print_annotations(paths_file)
  self.generate_annotated_files(paths_file)
  self.apply_annotations(paths_file)
  self.run_rdl(input_file)
end
run_rdl(input_file) click to toggle source
# File lib/kurangu.rb, line 90
def run_rdl(input_file)
  puts "\nrunning rdl\n"
  ruby = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
  system(ruby, input_file)
end