Class: IDL::AST::Valuetype
Overview
Constant Summary
collapse
- NAMETYPE =
:class
- DEFINABLE =
[IDL::AST::Include, IDL::AST::Const, IDL::AST::Operation, IDL::AST::Attribute, IDL::AST::StateMember, IDL::AST::Initializer,
IDL::AST::Struct, IDL::AST::Union, IDL::AST::Typedef, IDL::AST::Enum, IDL::AST::Enumerator]
Instance Attribute Summary collapse
Attributes inherited from Leaf
#annotations, #enclosure, #intern, #lm_name, #name, #prefix, #scopes
Instance Method Summary
collapse
Methods inherited from Derivable
#search_self, #search_self_before_derived
Methods inherited from Node
#introduce, #is_definable?, #match_members, #replace_prefix, #resolve, #undo_introduction
Methods inherited from Leaf
#_set_prefix, #has_annotations?, #is_template?, #lm_name_for_scope, #parsed_name_scope, #replace_prefix, #repo_scopes, #repository_id, #resolve, #scoped_lm_name, #scoped_name, #set_repo_id, #set_repo_version, #typename
Constructor Details
#initialize(_name, _enclosure, params) ⇒ Valuetype
Returns a new instance of Valuetype.
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
|
# File 'lib/ridl/node.rb', line 1671
def initialize(_name, _enclosure, params)
super(_name, _enclosure)
@bases = []
@resolved_bases = []
@interfaces = []
@resolved_interfaces = []
@defined = false
@recursive = false
@forward = params[:forward] ? true : false
@abstract = params[:abstract]
@idltype = IDL::Type::Valuetype.new(self)
complete_definition(params)
end
|
Instance Attribute Details
#bases ⇒ Object
Returns the value of attribute bases.
1668
1669
1670
|
# File 'lib/ridl/node.rb', line 1668
def bases
@bases
end
|
#idltype ⇒ Object
Returns the value of attribute idltype.
1669
1670
1671
|
# File 'lib/ridl/node.rb', line 1669
def idltype
@idltype
end
|
#interfaces ⇒ Object
Returns the value of attribute interfaces.
1668
1669
1670
|
# File 'lib/ridl/node.rb', line 1668
def interfaces
@interfaces
end
|
Instance Method Details
#add_bases(inherits_) ⇒ Object
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
|
# File 'lib/ridl/node.rb', line 1789
def add_bases(inherits_)
inherits_.each do |tc|
unless tc.is_a?(IDL::Type::ScopedName) && tc.is_node?(IDL::AST::TemplateParam)
if not (tc.is_a?(IDL::Type::ScopedName) && tc.is_node?(IDL::AST::Valuetype))
raise RuntimeError,
"invalid inheritance identifier for #{typename} #{scoped_lm_name}: #{tc.typename}"
end
rtc = tc.resolved_type
if rtc.node.has_ancestor?(self)
raise RuntimeError,
"circular inheritance detected for #{typename} #{scoped_lm_name}: #{tc.node.scoped_lm_name} is descendant"
end
if not rtc.node.is_defined?
raise RuntimeError,
"#{typename} #{scoped_lm_name} cannot inherit from forward declared #{tc.node.typename} #{tc.node.scoped_lm_name}"
end
if self.is_abstract? and not rtc.node.is_abstract?
raise RuntimeError,
"'abstract' #{typename} #{scoped_lm_name} cannot inherit from non-'abstract' #{tc.node.typename} #{tc.node.scoped_lm_name}"
end
if (not self.is_custom?) and rtc.node.is_custom?
raise RuntimeError,
"non-'custom' #{typename} #{scoped_lm_name} cannot inherit from 'custom' #{tc.node.typename} #{tc.node.scoped_lm_name}"
end
if @resolved_bases.include?(rtc.node)
raise RuntimeError,
"#{typename} #{scoped_lm_name} cannot inherit from #{tc.node.typename} #{tc.node.scoped_lm_name} multiple times"
end
if (not rtc.node.is_abstract?) and @bases.size > 0
raise RuntimeError,
"concrete basevalue #{tc.node.typename} #{tc.node.scoped_lm_name} MUST "+
"be first and only non-abstract in inheritance list for #{typename} #{scoped_lm_name}"
end
@resolved_bases << rtc.node
end
@bases << tc.node
end
end
|
#add_interfaces(iflist_) ⇒ Object
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
|
# File 'lib/ridl/node.rb', line 1828
def add_interfaces(iflist_)
iflist_.each do |if_|
unless if_.is_a?(IDL::Type::ScopedName) && if_.is_node?(IDL::AST::TemplateParam)
if not (if_.is_a?(IDL::Type::ScopedName) && if_.is_node?(IDL::AST::Interface))
raise RuntimeError,
"invalid support identifier for #{typename} #{scoped_lm_name}: #{if_.typename}"
end
rif_ = if_.resolved_type
if (not rif_.node.is_abstract?) and @interfaces.size > 0
raise RuntimeError,
"concrete interface '#{rif_.node.scoped_lm_name}' inheritance not allowed for #{typename} #{scoped_lm_name}. Valuetypes can only inherit (support) a single concrete interface."
end
if (not rif_.node.is_abstract?) && (not is_interface_compatible?(rif_.node))
raise RuntimeError,
"#{typename} #{scoped_lm_name} cannot support concrete interface #{rif_.node.scoped_lm_name} because it does not derive from inherited concrete interfaces"
end
@resolved_interfaces << rif_.node
end
@interfaces << if_.node
end
end
|
#complete_definition(params) ⇒ Object
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
|
# File 'lib/ridl/node.rb', line 1685
def complete_definition(params)
unless params[:forward]
@custom = params[:custom] || false
_inherits = params[:inherits] || {}
_base = _inherits[:base] || {}
@truncatable = _base[:truncatable] || false
if @custom && @truncatable
raise RuntimeError,
"'truncatable' attribute *not* allowed for 'custom' #{typename} #{scoped_lm_name}"
end
add_bases(_base[:list] || [])
add_interfaces(_inherits[:supports] || [])
end
end
|
#define(_type, _name, *args) ⇒ Object
1863
1864
1865
1866
1867
1868
|
# File 'lib/ridl/node.rb', line 1863
def define(_type, _name, *args)
if self.is_abstract? && [IDL::AST::StateMember, IDL::AST::Initializer].include?(_type)
raise RuntimeError, "cannot define statemember #{_name} on abstract #{typename} #{scoped_lm_name}"
end
super(_type, _name, *args)
end
|
#defined=(f) ⇒ Object
1745
|
# File 'lib/ridl/node.rb', line 1745
def defined=(f); @defined = f; end
|
#has_ancestor?(n) ⇒ Boolean
1851
1852
1853
|
# File 'lib/ridl/node.rb', line 1851
def has_ancestor?(n)
@resolved_bases.include?(n.idltype.resolved_type.node) || @resolved_bases.any? { |b| b.has_ancestor?(n) }
end
|
#has_concrete_base? ⇒ Boolean
1771
1772
1773
|
# File 'lib/ridl/node.rb', line 1771
def has_concrete_base?
(not @resolved_bases.empty?) and (not @resolved_bases.first.is_abstract?)
end
|
#has_operations_or_attributes?(include_intf = true) ⇒ Boolean
1890
1891
1892
1893
1894
1895
|
# File 'lib/ridl/node.rb', line 1890
def has_operations_or_attributes?(include_intf = true)
@children.any? { |c| c.is_a?(IDL::AST::Operation) || c.is_a?(IDL::AST::Attribute) } ||
@resolved_bases.any? { |b| b.has_operations_or_attributes? } ||
(include_intf &&
@resolved_interfaces.any? { |intf| !intf.operations(true).empty? || !intf.attributes(true).empty? })
end
|
#initializers ⇒ Object
1886
1887
1888
|
# File 'lib/ridl/node.rb', line 1886
def initializers
@children.find_all { |c| c.is_a?(IDL::AST::Initializer) }
end
|
#instantiate(_context, _enclosure) ⇒ Object
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
|
# File 'lib/ridl/node.rb', line 1723
def instantiate(_context, _enclosure)
_params = {
:forward => self.is_forward?,
:abstract => self.is_abstract?,
:custom => self.is_custom?,
:inherits => {
:base => {
:truncatable => self.is_truncatable?,
:list => self.concrete_bases(_context)
},
:supports => self.concrete_interfaces(_context)
}
}
inst = super(_context, _enclosure, _params)
inst.defined = true
inst
end
|
#interface_members ⇒ Object
1882
1883
1884
|
# File 'lib/ridl/node.rb', line 1882
def interface_members
@children.find_all { |c| c.is_a?(IDL::AST::Operation) or c.is_a?(IDL::AST::Attribute) }
end
|
#is_abstract? ⇒ Boolean
1741
|
# File 'lib/ridl/node.rb', line 1741
def is_abstract?; @abstract; end
|
#is_custom? ⇒ Boolean
1742
|
# File 'lib/ridl/node.rb', line 1742
def is_custom?; @custom; end
|
#is_defined? ⇒ Boolean
1744
|
# File 'lib/ridl/node.rb', line 1744
def is_defined?; @defined; end
|
#is_forward? ⇒ Boolean
1746
|
# File 'lib/ridl/node.rb', line 1746
def is_forward?; @forward; end
|
#is_interface_compatible?(n) ⇒ Boolean
1855
1856
1857
1858
1859
1860
1861
|
# File 'lib/ridl/node.rb', line 1855
def is_interface_compatible?(n)
if @resolved_interfaces.empty? || @resolved_interfaces.first.is_abstract?
@resolved_bases.all? { |b| b.is_interface_compatible?(n) }
else
n.idltype.resolved_type.node.has_ancestor?(@interfaces.first)
end
end
|
#is_local?(recurstk = []) ⇒ Boolean
1750
1751
1752
1753
1754
1755
1756
1757
|
# File 'lib/ridl/node.rb', line 1750
def is_local?(recurstk = [])
return false if is_forward? || recurstk.include?(self)
recurstk.push self
ret = state_members.any? { |m| m.is_local?(recurstk) }
recurstk.pop
ret
end
|
#is_recursive? ⇒ Boolean
1747
|
# File 'lib/ridl/node.rb', line 1747
def is_recursive?; @recursive end
|
#is_truncatable? ⇒ Boolean
1743
|
# File 'lib/ridl/node.rb', line 1743
def is_truncatable?; @truncatable; end
|
#marshal_dump ⇒ Object
1700
1701
1702
1703
1704
1705
1706
|
# File 'lib/ridl/node.rb', line 1700
def marshal_dump
super() << @bases << @resolved_bases <<
@interfaces << @resolved_interfaces <<
@defined << @recursive <<
@forward << @abstract <<
@custom << @truncatable << @idltype
end
|
#marshal_load(vars) ⇒ Object
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
|
# File 'lib/ridl/node.rb', line 1708
def marshal_load(vars)
@idltype = vars.pop
@truncatable = vars.pop
@custom = vars.pop
@abstract = vars.pop
@forward = vars.pop
@recursive = vars.pop
@defined = vars.pop
@resolved_interfaces = vars.pop
@interfaces = vars.pop
@resolved_bases = vars.pop
@bases = vars.pop
super(vars)
end
|
#modifier ⇒ Object
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
|
# File 'lib/ridl/node.rb', line 1759
def modifier
if is_abstract?
:abstract
elsif is_custom?
:custom
elsif is_truncatable?
:truncatable
else
:none
end
end
|
#recursive=(f) ⇒ Object
1748
|
# File 'lib/ridl/node.rb', line 1748
def recursive=(f); @recursive = f end
|
#redefine(node, params) ⇒ Object
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
|
# File 'lib/ridl/node.rb', line 1897
def redefine(node, params)
if node.enclosure == self
case node
when IDL::AST::Struct, IDL::AST::Union
if node.is_defined?
raise RuntimeError, "#{node.typename} \"#{node.name}\" is already defined."
end
node.annotations.concat(params[:annotations])
_new_node = node.class.new(node.name, self, params)
_new_node.annotations.concat(node.annotations)
_new_node.prefix = node.prefix
_new_node.instance_variable_set(:@repo_ver, node.instance_variable_get(:@repo_ver))
_new_node.instance_variable_set(:@repo_id, node.instance_variable_get(:@repo_id))
node.switchtype = params[:switchtype] if node.is_a?(IDL::AST::Union)
@children << _new_node
node.enclosure.undo_introduction(node)
introduce(_new_node)
return _new_node
else
raise RuntimeError, "#{node.typename} \"#{node.name}\" is already defined."
end
end
case node
when IDL::AST::Operation, IDL::AST::Attribute, IDL::AST::StateMember, IDL::AST::Initializer
raise RuntimeError, "#{node.typename} '#{node.scoped_lm_name}' cannot be overridden."
else
newnode = node.class.new(node.name, self, params)
newnode.annotations.concat(params[:annotations])
introduce(newnode)
return newnode
end
end
|
#state_members ⇒ Object
1878
1879
1880
|
# File 'lib/ridl/node.rb', line 1878
def state_members
@children.find_all { |c| c.is_a?(IDL::AST::StateMember) }
end
|
#supports_abstract_interface? ⇒ Boolean
1779
1780
1781
|
# File 'lib/ridl/node.rb', line 1779
def supports_abstract_interface?
@resolved_interfaces.any? { |intf| intf.is_abstract? }
end
|
#supports_concrete_interface? ⇒ Boolean
1775
1776
1777
|
# File 'lib/ridl/node.rb', line 1775
def supports_concrete_interface?
!(@resolved_interfaces.empty? || @resolved_interfaces.first.is_abstract?)
end
|
#truncatable_ids ⇒ Object
1783
1784
1785
1786
1787
|
# File 'lib/ridl/node.rb', line 1783
def truncatable_ids
ids = [self.repository_id()]
ids.concat(@resolved_bases.first().truncatable_ids()) if self.has_concrete_base?() && self.is_truncatable?()
ids
end
|
#walk_members(&block) ⇒ Object
1870
1871
1872
1873
1874
1875
1876
|
# File 'lib/ridl/node.rb', line 1870
def walk_members(&block)
@children.each { |c| yield(c) unless c.is_a?(IDL::AST::StateMember) or
c.is_a?(IDL::AST::Operation) or
c.is_a?(IDL::AST::Attribute) or
c.is_a?(IDL::AST::Initializer)
}
end
|