Method: RubyToAnsiC#process_scope

Defined in:
lib/ruby_to_ansi_c.rb

#process_scope(exp) ⇒ Object

Scope has no real equivalent in C-land, except that like process_block above. We put variable declarations here before the body and use this as our opportunity to open a variable scope. Crafty, no?



631
632
633
634
635
636
637
638
639
640
641
642
# File 'lib/ruby_to_ansi_c.rb', line 631

def process_scope(exp)
  declarations = []
  body = nil
  @env.scope do
    body = process exp.shift unless exp.empty?
    @env.current.sort_by { |v,t| v.to_s }.each do |var, var_type|
      var_type = self.class.c_type var_type
      declarations << "#{var_type} #{var};\n"
    end
  end
  return "{\n#{declarations}#{body}}"
end