class TypeProf::Core::AST::BranchNode::LoopNode::BreakNode::NextNode::WhenNode::CaseNode
Attributes
Public Class Methods
Source
# File bundled-src/typeprof-0.31.1/lib/typeprof/core/ast/control.rb, line 306 def initialize(raw_node, lenv) super(raw_node, lenv) @pivot = raw_node.predicate ? AST.create_node(raw_node.predicate, lenv) : nil # pivot変数名を決定 pivot_var = @pivot.is_a?(LocalVariableReadNode) ? @pivot.var : nil @when_nodes = raw_node.conditions.map {|raw_cond| WhenNode.new(raw_cond, lenv, pivot_var) } @else_clause = raw_node.else_clause && raw_node.else_clause.statements ? AST.create_node(raw_node.else_clause.statements, lenv) : DummyNilNode.new(code_range, lenv) # TODO: code_range for NilNode end
Calls superclass method
TypeProf::Core::AST::Node::new
Public Instance Methods
Source
# File bundled-src/typeprof-0.31.1/lib/typeprof/core/ast/control.rb, line 321 def install0(genv) ret = Vertex.new(self) @pivot&.install(genv) # case文での型絞り込みを実装 if @pivot && @pivot.is_a?(LocalVariableReadNode) var = @pivot.var original_vtx = @lenv.get_var(var) # ダミー変数に元の型情報を設定 @lenv.set_var(:"*pivot", original_vtx) # 各when節を実行 @when_nodes.each do |when_node| clause_result = when_node.install(genv) @changes.add_edge(genv, clause_result, ret) # 元の型に戻す @lenv.set_var(var, original_vtx) end # else節(他のwhen節で除外された後の型) filtered_else_vtx = original_vtx.new_vertex(genv, self) @when_nodes.each do |when_node| when_node.get_exclusion_conditions.each do |static_ret| # 各when節の型を除外(negation) filtered_else_vtx = IsAFilter.new(genv, self, filtered_else_vtx, true, static_ret).next_vtx end end @lenv.set_var(var, filtered_else_vtx) @changes.add_edge(genv, @else_clause.install(genv), ret) @lenv.set_var(var, original_vtx) # ダミー変数をクリア @lenv.locals.delete(:"*pivot") else # pivotが変数でない場合は従来通り @when_nodes.each do |when_node| @changes.add_edge(genv, when_node.install(genv), ret) end @changes.add_edge(genv, @else_clause.install(genv), ret) end ret end
Source
# File bundled-src/typeprof-0.31.1/lib/typeprof/core/ast/control.rb, line 319 def subnodes = { pivot:, when_nodes:, else_clause: } def install0(genv) ret = Vertex.new(self) @pivot&.install(genv) # case文での型絞り込みを実装 if @pivot && @pivot.is_a?(LocalVariableReadNode) var = @pivot.var original_vtx = @lenv.get_var(var) # ダミー変数に元の型情報を設定 @lenv.set_var(:"*pivot", original_vtx) # 各when節を実行 @when_nodes.each do |when_node| clause_result = when_node.install(genv) @changes.add_edge(genv, clause_result, ret) # 元の型に戻す @lenv.set_var(var, original_vtx) end # else節(他のwhen節で除外された後の型) filtered_else_vtx = original_vtx.new_vertex(genv, self) @when_nodes.each do |when_node| when_node.get_exclusion_conditions.each do |static_ret| # 各when節の型を除外(negation) filtered_else_vtx = IsAFilter.new(genv, self, filtered_else_vtx, true, static_ret).next_vtx end end @lenv.set_var(var, filtered_else_vtx) @changes.add_edge(genv, @else_clause.install(genv), ret) @lenv.set_var(var, original_vtx) # ダミー変数をクリア @lenv.locals.delete(:"*pivot") else # pivotが変数でない場合は従来通り @when_nodes.each do |when_node| @changes.add_edge(genv, when_node.install(genv), ret) end @changes.add_edge(genv, @else_clause.install(genv), ret) end ret end end