Class: Minjs::ECMA262::StFor
- Defined in:
- lib/minjs/ecma262/statement.rb
Overview
Base class of ECMA262 ‘for(;;)’ IterationStatement element.
Instance Attribute Summary collapse
-
#exp1 ⇒ Object
readonly
Returns the value of attribute exp1.
-
#exp2 ⇒ Object
readonly
Returns the value of attribute exp2.
-
#exp3 ⇒ Object
readonly
Returns the value of attribute exp3.
-
#statement ⇒ Object
readonly
Returns the value of attribute statement.
Attributes inherited from Base
Instance Method Summary collapse
-
#==(obj) ⇒ Object
compare object.
-
#add_paren ⇒ Object
add parenthesis if need.
-
#deep_dup ⇒ Object
duplicate object.
-
#initialize(exp1, exp2, exp3, statement) ⇒ StFor
constructor
A new instance of StFor.
-
#remove_paren ⇒ Object
remove parenthesis if possible.
-
#replace(from, to) ⇒ Object
Replaces children object.
-
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
-
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
Methods inherited from Statement
#empty?, #priority, #to_exp?, #to_return?
Methods inherited from Base
Constructor Details
#initialize(exp1, exp2, exp3, statement) ⇒ StFor
Returns a new instance of StFor.
635 636 637 638 639 640 |
# File 'lib/minjs/ecma262/statement.rb', line 635 def initialize(exp1, exp2, exp3, statement) @exp1 = exp1 @exp2 = exp2 @exp3 = exp3 @statement = statement end |
Instance Attribute Details
#exp1 ⇒ Object (readonly)
Returns the value of attribute exp1.
633 634 635 |
# File 'lib/minjs/ecma262/statement.rb', line 633 def exp1 @exp1 end |
#exp2 ⇒ Object (readonly)
Returns the value of attribute exp2.
633 634 635 |
# File 'lib/minjs/ecma262/statement.rb', line 633 def exp2 @exp2 end |
#exp3 ⇒ Object (readonly)
Returns the value of attribute exp3.
633 634 635 |
# File 'lib/minjs/ecma262/statement.rb', line 633 def exp3 @exp3 end |
#statement ⇒ Object (readonly)
Returns the value of attribute statement.
633 634 635 |
# File 'lib/minjs/ecma262/statement.rb', line 633 def statement @statement end |
Instance Method Details
#==(obj) ⇒ Object
compare object
675 676 677 678 679 680 681 |
# File 'lib/minjs/ecma262/statement.rb', line 675 def ==(obj) self.class == obj.class and @exp1 == obj.exp1 and @exp2 == obj.exp2 and @exp3 == obj.exp3 and @statement == obj.statement end |
#add_paren ⇒ Object
add parenthesis if need
710 711 712 |
# File 'lib/minjs/ecma262/statement.rb', line 710 def add_paren self end |
#deep_dup ⇒ Object
duplicate object
644 645 646 647 648 649 |
# File 'lib/minjs/ecma262/statement.rb', line 644 def deep_dup self.class.new(@exp1 && @exp1.deep_dup, @exp2 && @exp2.deep_dup, @exp3 && @exp3.deep_dup, @statement.deep_dup) end |
#remove_paren ⇒ Object
remove parenthesis if possible
696 697 698 699 700 701 702 703 704 705 706 707 |
# File 'lib/minjs/ecma262/statement.rb', line 696 def remove_paren if @exp1.kind_of? ExpParen @exp1 = @exp1.val end if @exp2.kind_of? ExpParen @exp2 = @exp2.val end if @exp3.kind_of? ExpParen @exp3 = @exp3.val end self end |
#replace(from, to) ⇒ Object
Replaces children object.
653 654 655 656 657 658 659 660 661 662 663 |
# File 'lib/minjs/ecma262/statement.rb', line 653 def replace(from, to) if from .eql? @exp1 @exp1 = to elsif from .eql? @exp2 @exp2 = to elsif from .eql? @exp3 @exp3 = to elsif from .eql? @statement @statement = to end end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
685 686 687 688 689 690 691 692 693 |
# File 'lib/minjs/ecma262/statement.rb', line 685 def to_js( = {}) if @statement.kind_of? StBlock and @statement.statement_list.length == 1 statement = @statement.statement_list.statement_list[0] else statement = @statement end concat , :for, "(", @exp1, ";;", @exp2, ";;", @exp3, ")", statement end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
666 667 668 669 670 671 672 |
# File 'lib/minjs/ecma262/statement.rb', line 666 def traverse(parent, &block) @exp1.traverse(self, &block) if @exp1 @exp2.traverse(self, &block) if @exp2 @exp3.traverse(self, &block) if @exp3 @statement.traverse(self, &block) yield parent, self end |