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 collapse
- TEMP_KEYWORD =
:temp
Instance Attribute Summary collapse
-
#did_work ⇒ Object
Returns the value of attribute did_work.
-
#tmp_tables ⇒ Object
readonly
:nodoc: all.
Instance Method Summary collapse
-
#initialize ⇒ TempExpander
constructor
A new instance of TempExpander.
- #process_defn(exp) ⇒ Object
Constructor Details
#initialize ⇒ TempExpander
Returns a new instance of TempExpander.
576 577 578 579 580 581 582 |
# File 'lib/bud/rewrite.rb', line 576 def initialize super() self.require_empty = false self.expected = Sexp @tmp_tables = [] @did_work = false end |
Instance Attribute Details
#did_work ⇒ Object
Returns the value of attribute did_work.
572 573 574 |
# File 'lib/bud/rewrite.rb', line 572 def did_work @did_work end |
#tmp_tables ⇒ Object (readonly)
:nodoc: all
571 572 573 |
# File 'lib/bud/rewrite.rb', line 571 def tmp_tables @tmp_tables end |
Instance Method Details
#process_defn(exp) ⇒ Object
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/bud/rewrite.rb', line 584 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 |