class Bpl::Splitting

Public Instance Methods

run!(program) click to toggle source
# File lib/bpl/passes/utility/splitting.rb, line 13
def run! program
  program.declarations.select(&method(:split?)).each_with_index do |p,i|

    info "SPLITTING PROCEDURE"
    info
    info "  #{p.name}"
    info

    split = Program.new(declarations: [])
    program.declarations.each do |decl|
      d = decl.copy
      if split?(decl)
        d.remove_attribute(:entrypoint)
        if d.name == p.name
          d.add_attribute(:entrypoint)
        else
          d.body.remove
        end
      end
      split.append_children(:declarations, d)
    end
    added split
    invalidates :all
  end
  removed program
end
split?(decl) click to toggle source
# File lib/bpl/passes/utility/splitting.rb, line 7
def split?(decl)
  decl.is_a?(ProcedureDeclaration) &&
  ( decl.specifications.any?{|s| s.is_a?(EnsuresClause)} ||
    entrypoint_localization.entrypoints.include?(decl) )
end