Class: TempExpander
- Inherits:
-
SexpProcessor
- Object
- SexpProcessor
- TempExpander
- Defined in:
- lib/bud/rewrite.rb
Overview
Look for temp declarations and remove the “temp” keyword, yielding code that we can safely eval. We also record the set of “temp” collections we've seen, and provide a helper method that returns the AST of a state block that contains declarations for all those temp tables.
Constant Summary
- TEMP_KEYWORD =
:temp
Instance Attribute Summary (collapse)
-
- (Object) did_work
Returns the value of attribute did_work.
-
- (Object) tmp_tables
readonly
:nodoc: all.
Instance Method Summary (collapse)
-
- (TempExpander) initialize
constructor
A new instance of TempExpander.
- - (Object) process_defn(exp)
Constructor Details
- (TempExpander) initialize
A new instance of TempExpander
565 566 567 568 569 570 571 |
# File 'lib/bud/rewrite.rb', line 565 def initialize super() self.require_empty = false self.expected = Sexp @tmp_tables = [] @did_work = false end |
Instance Attribute Details
- (Object) did_work
Returns the value of attribute did_work
561 562 563 |
# File 'lib/bud/rewrite.rb', line 561 def did_work @did_work end |
- (Object) tmp_tables (readonly)
:nodoc: all
560 561 562 |
# File 'lib/bud/rewrite.rb', line 560 def tmp_tables @tmp_tables end |
Instance Method Details
- (Object) process_defn(exp)
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'lib/bud/rewrite.rb', line 573 def process_defn(exp) tag, name, args, *body = exp return exp unless name.to_s =~ /^__bloom__.+/ body.each_with_index do |n,i| # temp declarations are misparsed if the RHS contains certain constructs # (e.g., group, "do |f| ... end" rather than "{|f| ... }"). Rewrite to # correct the misparsing. if n.sexp_type == :iter iter_body = n.sexp_body new_n = fix_temp_decl(iter_body) unless new_n.nil? body[i] = n = new_n @did_work = true end end _, recv, meth, meth_args = n if meth == TEMP_KEYWORD and recv.nil? body[i] = rewrite_temp(n) @did_work = true end end s(tag, name, args, *body) end |