Class: Sfp::SasTranslator::VariableCollector
- Defined in:
- lib/sfp/sas_translator.rb
Overview
collecting all variables and put them into @bucket
Instance Method Summary collapse
- #add_value(type, value) ⇒ Object
- #get_type(name, value, parent) ⇒ Object
-
#initialize(main) ⇒ VariableCollector
constructor
A new instance of VariableCollector.
- #is_final(value) ⇒ Object
- #isa?(value) ⇒ Boolean
- #null_value(isa) ⇒ Object
- #visit(name, value, parent) ⇒ Object
Constructor Details
#initialize(main) ⇒ VariableCollector
Returns a new instance of VariableCollector.
1665 1666 1667 1668 |
# File 'lib/sfp/sas_translator.rb', line 1665 def initialize(main) super(main) @init = main.root['initial'] end |
Instance Method Details
#add_value(type, value) ⇒ Object
1725 1726 1727 1728 1729 1730 1731 |
# File 'lib/sfp/sas_translator.rb', line 1725 def add_value(type, value) if not @types.has_key?(type) @types[type] = Array.new @types[type] << Sfp::SasTranslator.null_of(type) if @types[type].length <= 0 end @types[type] << value if not (value.is_a?(Hash) and value.isnull) end |
#get_type(name, value, parent) ⇒ Object
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 |
# File 'lib/sfp/sas_translator.rb', line 1702 def get_type(name, value, parent) return value.type if value.is_a?(Sfp::Undefined) or value.is_a?(Sfp::Unknown) type = nil if parent.has_key?('_isa') isa = @main.root.at?(parent['_isa']) if not isa.nil? type = isa.type?(name) return type if not type.nil? end end type = self.isa?(value) return "(#{value['_isa']})" if value.is_a?(Hash) and value.isset and value.has_key?('_isa') return nil if type == nil return type if type.is_a?(String) and type.isref parent_class = @root.at?( @vars[parent.ref].type ) return parent_class[name]['_isa'] end |
#is_final(value) ⇒ Object
1741 1742 1743 1744 |
# File 'lib/sfp/sas_translator.rb', line 1741 def is_final(value) return true if value.is_a?(Hash) and not value.isnull and not value.isset return false end |
#isa?(value) ⇒ Boolean
1733 1734 1735 1736 1737 1738 1739 |
# File 'lib/sfp/sas_translator.rb', line 1733 def isa?(value) return '$.Boolean' if value.is_a?(TrueClass) or value.is_a?(FalseClass) return '$.Integer' if value.is_a?(Numeric) return '$.String' if value.is_a?(String) and not value.isref return value['_isa'] if value.is_a?(Hash) and value.isobject return nil end |
#null_value(isa) ⇒ Object
1698 1699 1700 |
# File 'lib/sfp/sas_translator.rb', line 1698 def null_value(isa) return {'_context' => 'null', '_isa' => isa} end |
#visit(name, value, parent) ⇒ Object
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 |
# File 'lib/sfp/sas_translator.rb', line 1670 def visit(name, value, parent) return false if name[0,1] == '_' return false if (value.is_a?(Hash) and not (value.isobject or value.isnull or value.isset)) # or value.is_a?(Array) var_name = parent.ref.push(name) isfinal = self.is_final(value) isref = (value.is_a?(String) and value.isref) isset = false value = @init.at?(value) if isref type = (isfinal ? self.isa?(value) : self.get_type(name, value, parent)) if type == nil raise Exception, "Unrecognized type of variable: #{var_name}:#{value.class}" else value = null_value(type) if value == nil isset = true if type[0,1] == '(' var = Variable.new(var_name, type, -1, value, nil, isfinal) var.isset = isset @vars[var.name] = var if isfinal and value.is_a?(Hash) value['_classes'].each { |c| add_value(c, value) } elsif not isref add_value(type, value) end end return true end |