class Puppet::Pops::Types::PCollectionType

@api public

Constants

DEFAULT
DEFAULT_SIZE
NOT_EMPTY_SIZE
ZERO_SIZE

Attributes

size_type[R]

Public Class Methods

new(size_type) click to toggle source
     # File lib/puppet/pops/types/types.rb
1321 def initialize(size_type)
1322   @size_type = size_type.nil? ? nil : size_type.to_size
1323 end
register_ptype(loader, ir) click to toggle source
     # File lib/puppet/pops/types/types.rb
1310 def self.register_ptype(loader, ir)
1311   create_ptype(loader, ir, 'AnyType',
1312     'size_type' => {
1313       KEY_TYPE => POptionalType.new(PTypeType.new(PIntegerType::DEFAULT)),
1314       KEY_VALUE => nil
1315     }
1316   )
1317 end

Public Instance Methods

accept(visitor, guard) click to toggle source
Calls superclass method Puppet::Pops::Types::PAnyType#accept
     # File lib/puppet/pops/types/types.rb
1325 def accept(visitor, guard)
1326   super
1327   @size_type.accept(visitor, guard) unless @size_type.nil?
1328 end
eql?(o) click to toggle source
     # File lib/puppet/pops/types/types.rb
1365 def eql?(o)
1366   self.class == o.class && @size_type == o.size_type
1367 end
generalize() click to toggle source
     # File lib/puppet/pops/types/types.rb
1330 def generalize
1331   DEFAULT
1332 end
has_empty_range?() click to toggle source
     # File lib/puppet/pops/types/types.rb
1352 def has_empty_range?
1353   from, to = size_range
1354   from == 0 && to == 0
1355 end
hash() click to toggle source
     # File lib/puppet/pops/types/types.rb
1357 def hash
1358   @size_type.hash
1359 end
instance?(o, guard = nil) click to toggle source
     # File lib/puppet/pops/types/types.rb
1338 def instance?(o, guard = nil)
1339   # The inferred type of a class derived from Array or Hash is either Runtime or Object. It's not assignable to the Collection type.
1340   if o.instance_of?(Array) || o.instance_of?(Hash)
1341     @size_type.nil? || @size_type.instance?(o.size)
1342   else
1343     false
1344   end
1345 end
iterable?(guard = nil) click to toggle source
     # File lib/puppet/pops/types/types.rb
1361 def iterable?(guard = nil)
1362   true
1363 end
normalize(guard = nil) click to toggle source
     # File lib/puppet/pops/types/types.rb
1334 def normalize(guard = nil)
1335   DEFAULT
1336 end
size_range() click to toggle source

Returns an array with from (min) size to (max) size

     # File lib/puppet/pops/types/types.rb
1348 def size_range
1349   (@size_type || DEFAULT_SIZE).range
1350 end

Protected Instance Methods

_assignable?(o, guard) click to toggle source

@api private

     # File lib/puppet/pops/types/types.rb
1379 def _assignable?(o, guard)
1380   case o
1381     when PCollectionType
1382       (@size_type || DEFAULT_SIZE).assignable?(o.size_type || DEFAULT_SIZE, guard)
1383     when PTupleType
1384       # compute the tuple's min/max size, and check if that size matches
1385       size_s = size_type || DEFAULT_SIZE
1386       size_o = o.size_type
1387       if size_o.nil?
1388         type_count = o.types.size
1389         size_o = PIntegerType.new(type_count, type_count)
1390       end
1391       size_s.assignable?(size_o)
1392     when PStructType
1393       from = to = o.elements.size
1394       (@size_type || DEFAULT_SIZE).assignable?(PIntegerType.new(from, to), guard)
1395     else
1396       false
1397   end
1398 end