Class: Sfp::SasTranslator::ParameterGrounder

Inherits:
Object
  • Object
show all
Defined in:
lib/sfp/sas_translator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, map = {}) ⇒ ParameterGrounder

Returns a new instance of ParameterGrounder.



1717
1718
1719
1720
# File 'lib/sfp/sas_translator.rb', line 1717

def initialize(root, map={})
  @root = root
  @map = map
end

Instance Attribute Details

#mapObject

Returns the value of attribute map.



1715
1716
1717
# File 'lib/sfp/sas_translator.rb', line 1715

def map
  @map
end

Instance Method Details

#visit(name, value, obj) ⇒ Object



1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
# File 'lib/sfp/sas_translator.rb', line 1722

def visit(name, value, obj)
  return if name[0,1] == '_' and name != '_value' and name != '_template'
  # substituting left side
  if name[0,1] != '_'
    modified = false
    map.each { |k,v|
      #puts k + ',' + name if v.is_a?(Sfp::Undefined) or v.is_a?(Sfp::Unknown)
      next if v.is_a?(Sfp::Undefined) or v.is_a?(Sfp::Unknown)
      if name == k
        obj[v] = value
        obj.delete(name)
        name = v
        value['_self'] = name if value.is_a?(Hash)
        modified = true
        break
      elsif name.length > k.length and name[k.length,1] == '.' and name[0, k.length] == k
        #next if v.is_a?(Sfp::Undefined) or v.is_a?(Sfp::Unknown)
        grounded = v + name[k.length, (name.length-k.length)]
        obj[grounded] = value
        obj.delete(name)
        name = grounded
        value['_self'] = name if value.is_a?(Hash)
        modified = true
        break
      end
    }
  
    if modified and (name =~ /.*\.parent(\..*)?/ )
      parent, last = name.pop_ref
      parent_value = @root.at?(parent)
      raise VariableNotFoundException, parent if parent_value.nil?
      new_name = @root.at?(parent).ref.push(last) if last != 'parent'
      new_name = @root.at?(parent).ref.to_top if last == 'parent'
      obj[new_name] = value
      obj.delete(name)
      name = new_name
      value['_self'] = name if value.is_a?(Hash)
    end
  end
  # TODO ----- HACK! -----
  if obj.is_a?(Hash) and obj.isconstraint and obj['_type'] == 'iterator' and
      value.is_a?(String) and value.isref and map.has_key?(value)
    obj[name] = value = map[value]
    #puts map[value].inspect
    #puts "==>> " + obj.ref.push(name)
  end
  # ------ END of HACK! ----

  # substituting right side
  if value.is_a?(String) and value.isref
    map.each { |k,v|
      if value == k
        obj[name] = v
        break
      elsif value.length > k.length and value[k.length,1] == '.' and value[0,k.length] == k and
        not(v.is_a?(Sfp::Undefined) or v.is_a?(Sfp::Unknown))
        obj[name] = v + value[k.length, (value.length-k.length)]
        break
      end
    }
  end
  return true
end