diff --git a/src/common.rb b/src/common.rb index 9c1e143..3d57093 100644 --- a/src/common.rb +++ b/src/common.rb @@ -91,7 +91,7 @@ def get_tail(x) elsif x.class == Statement if x.name.class == Expression if x.name.operator == :dot - ret = x.name.lop + ret = x.name.rop else ret = x.name end @@ -101,7 +101,7 @@ def get_tail(x) elsif x.class == String ret = nil else - abort "get_name is not allowed to use for #{x.class}" + abort "get_tail is not allowed to use for #{x.class}" end ret end diff --git a/src/intermediate_exp_class.rb b/src/intermediate_exp_class.rb index 834256d..7066e95 100644 --- a/src/intermediate_exp_class.rb +++ b/src/intermediate_exp_class.rb @@ -438,7 +438,9 @@ def expand_tree def replace_name(orig,replaced) abort "name must be Strinng class to replace" if orig.class != String || replaced.class != String if @name.class == String && @name == orig - @name = replaced + @name = replaced + elsif @name.class == Expression && @name.operator == :dot && @name.lop == orig + @name.lop = replaced end end @@ -573,6 +575,25 @@ def isJRelated(list) } ret end + + def replace_recursive(orig,replaced) + @ops.each{ |op| + if orig.class == String + op = op.replace_recursive(orig,replaced) + elsif orig.class == Expression && orig.operator == :dot + op = op.replace_recursive(orig.lop,replaced) + else + abort "error: #{orig} cannot be replaced with #{replaced} in FuncCall" + end + } + self + end + + def replace_by_list(name_list,replaced_list) + name_list.zip(replaced_list){ |n,r| + self.replace_recursive(n,r) + } + end def convert_to_code(conversion_type) case conversion_type @@ -1350,8 +1371,19 @@ def get_opcode(op) end def replace_recursive(orig,replaced) - @lop = @lop.replace_recursive(orig,replaced) - @rop = @rop.replace_recursive(orig,replaced) if @rop != nil + if @operator == :dot + if orig.class == Expression && orig.operator == :dot + if @lop.class == String + @lop = replaced if @lop == orig.lop && @rop == orig.rop + end + else + @lop = @lop.replace_recursive(orig,replaced) + @rop = @rop.replace_recursive(orig,replaced) if @rop != nil + end + else + @lop = @lop.replace_recursive(orig,replaced) + @rop = @rop.replace_recursive(orig,replaced) if @rop != nil + end self end def replace_fdpsname_recursive(h=$varhash) diff --git a/src/parserdriver.rb b/src/parserdriver.rb index f8143a5..e056c8a 100644 --- a/src/parserdriver.rb +++ b/src/parserdriver.rb @@ -1014,12 +1014,17 @@ def make_conditional_branch_block_recursive2(ss,h = $varhash,related_vars = []) tail = get_tail(bs) if related_vars.find(){ |n| n == name } || h[name][0] == "FORCE" tmp_name_hash[name] = add_new_tmpvar(bs.type) if tmp_name_hash[name] == nil - bss.push(Statement.new([name,Merge.new([tmp_name_hash[name],name,bs.type]),bs.type])) + if ["x","y","z","w"].index(tail) + src = Expression.new([:dot,tmp_name_hash[name],tail,bs.type]) + dst = Expression.new([:dot,name,tail,bs.type]) + bss.push(Statement.new([dst,Merge.new([src,dst,bs.type]),bs.type])) + else + bss.push(Statement.new([name,Merge.new([tmp_name_hash[name],name,bs.type]),bs.type])) + end end end } } - #p tmp_name_hash cbb.bodies.each{ |bss| computed_list = [] @@ -1030,7 +1035,7 @@ def make_conditional_branch_block_recursive2(ss,h = $varhash,related_vars = []) bs.replace_name(name,tmp_name_hash[name]) if tmp_name_hash[name] != nil bs.expression.replace_by_list(computed_list,replaced_list) if tmp_name_hash[name] != nil - computed_list.push(name) + computed_list.push(bs.name) replaced_list.push(tmp_name_hash[name]) end end @@ -1060,73 +1065,6 @@ def make_conditional_branch_block_recursive2(ss,h = $varhash,related_vars = []) abort "ConditionalBranch is not terminated" if nest_level > 0 new_s.reverse end - - def make_conditional_branch_block_recursive(ss) - #abort "make_conditional_branch_block_recursive" - new_s = [] - nest_level = 0 - cbb = ConditionalBranch.new([[],[]]) - computed_vars = [] - - ss.each{ |s| - if s.class == IfElseState - nest_level += 1 if s.operator == :if - nest_level -= 1 if s.operator == :endif - abort "nest level is less than 0" if nest_level < 0 - end - if nest_level == 0 - if isStatement(s) - computed_vars.push(get_name(s)) - end - if s.class == IfElseState - abort "operator #{s.operator} of #{s} must be :endif" if s.operator != :endif - new_b = [] - cbb.bodies.each{ |b| - new_b.push(make_conditional_branch_block_recursive(b)) - } - cbb.bodies = new_b - new_s.push(cbb) - cbb.bodies.each{ |bss| - name_list = [] - replaced_list = [] - bss.each{ |bs| - if isStatement(bs) && bs.expression.class != Merge - name = get_name(bs) - tail = get_tail(bs) - if computed_vars.find(){ |n| n == name } - abort "merging after conditional branch is not supported for vector variable" if bs.type =~ /vec/ - tmp_name = name_list.find{ |n| n == name } - tmp_name = add_new_tmpvar(bs.type) if tmp_name == nil - - bs.replace_name(name,tmp_name) - bs.expression.replace_by_list(name_list,replaced_list) - if !(name_list.find{ |n| n == name }) - name_list.push(name) - replaced_list.push(tmp_name) - end - bss.push(Statement.new([name,Merge.new([tmp_name,name,bs.type]),bs.type])) - end - end - } - } - cbb = ConditionalBranch.new([[],[]]) - else - new_s.push(s) - end - elsif nest_level == 1 - if s.class == IfElseState && s.operator != :endif - cbb.push_condition(s) - #p cbb - else - cbb.push_body(s) - end - else - cbb.push_body(s) - end - } - abort "ConditionalBranch is not terminated" if nest_level > 0 - new_s - end end class String