Class: TEALrb::Rewriters::WhileRewriter

Inherits:
Rewriter
  • Object
show all
Defined in:
lib/tealrb/rewriters.rb

Class Attribute Summary collapse

Attributes inherited from Rewriter

#contract

Instance Method Summary collapse

Methods inherited from Rewriter

#rewrite

Constructor Details

#initialize(*args) ⇒ WhileRewriter

Returns a new instance of WhileRewriter.



258
259
260
261
262
# File 'lib/tealrb/rewriters.rb', line 258

def initialize(*args)
  self.class.while_count = {}
  self.class.while_count[Thread.current] ||= 0
  super
end

Class Attribute Details

.while_countObject

Returns the value of attribute while_count.



255
256
257
# File 'lib/tealrb/rewriters.rb', line 255

def while_count
  @while_count
end

Instance Method Details

#on_while(node) ⇒ Object



268
269
270
271
272
273
274
275
276
277
278
# File 'lib/tealrb/rewriters.rb', line 268

def on_while(node)
  cond_node = node.children.first
  replace(
    node.loc.keyword,
    ":while#{while_count}_condition;#{cond_node.source};bz :while#{while_count}_end; :while#{while_count}_logic;"
  )
  replace(node.loc.begin, '') if node.loc.begin
  replace(node.loc.end, "b :while#{while_count}_condition;:while#{while_count}_end")
  replace(cond_node.loc.expression, '')
  super
end

#while_countObject



264
265
266
# File 'lib/tealrb/rewriters.rb', line 264

def while_count
  self.class.while_count[Thread.current]
end