class Minjs::ECMA262::StForVar

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

@see www.ecma-international.org/ecma-262 ECMA262 12.6.3

Attributes

exp2[R]
exp3[R]
statement[R]
var_decl_list[R]
var_env[R]

Public Class Methods

new(var_env, var_decl_list, exp2, exp3, statement) click to toggle source

var_decl_list

[[name0, init0],[name1, init1], ...]
# File lib/minjs/ecma262/statement.rb, line 726
def initialize(var_env, var_decl_list, exp2, exp3, statement)
  @var_env = var_env
  @var_decl_list = var_decl_list
  @exp2 = exp2
  @exp3 = exp3
  @statement = statement
end

Public Instance Methods

==(obj) click to toggle source

compare object

# File lib/minjs/ecma262/statement.rb, line 787
def ==(obj)
  self.class == obj.class and
    @var_decl_list == obj.var_decl_list and
    @exp2 == obj.exp2 and
    @exp3 == obj.exp3 and
    @statement == obj.statement
end
add_paren() click to toggle source

add parenthesis if need

# File lib/minjs/ecma262/statement.rb, line 832
def add_paren
  self
end
deep_dup() click to toggle source

duplicate object @see Base#deep_dup

# File lib/minjs/ecma262/statement.rb, line 736
def deep_dup
  self.class.new(@var_env,
                 @var_decl_list.collect{|x,y|
                   [x.deep_dup, y.deep_dup]
                 },
                 @exp2 && @exp2.deep_dup,
                 @exp3 && @exp3.deep_dup,
                 @statement.deep_dup)
end
remove_paren() click to toggle source

remove parenthesis if possible

# File lib/minjs/ecma262/statement.rb, line 816
def remove_paren
  @var_decl_list.each do|x|
    if x[1] and x[1].kind_of? ExpParen
      x[1] = x[1].val
    end
  end
  if @exp2.kind_of? ExpParen
    @exp2 = @exp2.val
  end
  if @exp3.kind_of? ExpParen
    @exp3 = @exp3.val
  end
  self
end
replace(from, to) click to toggle source

Replaces children object. @see Base#replace

# File lib/minjs/ecma262/statement.rb, line 748
def replace(from, to)
  if from .eql? @statement
    @statement = to
  end
end
to_js(options = {}) click to toggle source

Returns a ECMAScript string containg the representation of element. @see Base#to_js

# File lib/minjs/ecma262/statement.rb, line 797
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

  _var_decl_list = @var_decl_list.collect{|x|
    if x[1] #with initialiser
      concat options, x[0], '=', x[1]
    else
      concat options, x[0]
    end
  }.join(",")
  t = concat(options, :for, "(var", _var_decl_list, ";;", @exp2, ";;", @exp3, ")")
  concat options, t, statement
end
to_st_for() click to toggle source

converts for-var-statement to for-statement

# File lib/minjs/ecma262/statement.rb, line 769
def to_st_for
  tt = nil
  @var_decl_list.each{|x|
    if x[1]
      t = ExpAssign.new(x[0], x[1])
    else
      t = x[0]
    end
    if tt.nil?
      tt = t
    else
      tt = ExpComma.new(tt, t)
    end
  }
  StFor.new(tt, @exp2, @exp3, @statement)
end
traverse(parent) { |parent, self| ... } click to toggle source

Traverses this children and itself with given block.

# File lib/minjs/ecma262/statement.rb, line 755
def traverse(parent, &block)
  @var_decl_list.each do |x|
    x[0].traverse(self, &block)
    if x[1]
      x[1].traverse(self, &block)
    end
  end
  @exp2.traverse(self, &block) if @exp2
  @exp3.traverse(self, &block) if @exp3
  @statement.traverse(self, &block)
  yield parent, self
end