Class: Minjs::ECMA262::StFor

Inherits:
Statement show all
Defined in:
lib/minjs/ecma262/statement.rb

Overview

Base class of ECMA262 ‘for(;;)’ IterationStatement element.

See Also:

Instance Attribute Summary collapse

Attributes inherited from Base

#parent

Instance Method Summary collapse

Methods inherited from Statement

#empty?, #priority, #to_exp?, #to_return?

Methods inherited from Base

#add_remove_paren, #concat

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

#exp1Object (readonly)

Returns the value of attribute exp1.



633
634
635
# File 'lib/minjs/ecma262/statement.rb', line 633

def exp1
  @exp1
end

#exp2Object (readonly)

Returns the value of attribute exp2.



633
634
635
# File 'lib/minjs/ecma262/statement.rb', line 633

def exp2
  @exp2
end

#exp3Object (readonly)

Returns the value of attribute exp3.



633
634
635
# File 'lib/minjs/ecma262/statement.rb', line 633

def exp3
  @exp3
end

#statementObject (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_parenObject

add parenthesis if need



710
711
712
# File 'lib/minjs/ecma262/statement.rb', line 710

def add_paren
  self
end

#deep_dupObject

duplicate object

See Also:



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_parenObject

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.

See Also:



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.

See Also:



685
686
687
688
689
690
691
692
693
# File 'lib/minjs/ecma262/statement.rb', line 685

def to_js(options = {})
  if @statement.kind_of? StBlock and @statement.statement_list.length == 1
    statement = @statement.statement_list.statement_list[0]
  else
    statement = @statement
  end

  concat options, :for, "(", @exp1, ";;", @exp2, ";;", @exp3, ")", statement
end

#traverse(parent) {|parent, _self| ... } ⇒ Object

Traverses this children and itself with given block.

Yields:

Yield Parameters:



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