Class: Puppet::Pops::Types::PCallableType
- Inherits:
-
PAnyType
- Object
- TypedModelObject
- PAnyType
- Puppet::Pops::Types::PCallableType
- Defined in:
- lib/puppet/pops/types/types.rb
Constant Summary collapse
- DEFAULT =
PCallableType.new(nil, nil, nil)
Instance Attribute Summary collapse
-
#block_type ⇒ PAnyType|nil
readonly
Although being an abstract type reference, only Callable, or all Callables wrapped in Optional or Variant are supported If not set, the meaning is that block is not supported.
-
#param_types ⇒ PTupleType
readonly
Types of parameters as a Tuple with required/optional count, or an Integer with min (required), max count.
-
#return_type ⇒ PAnyType
readonly
The type for the values returned by this callable.
Class Method Summary collapse
Instance Method Summary collapse
- #accept(visitor, guard) ⇒ Object
-
#block_range ⇒ Object
Range [0,0], [0,1], or [1,1] for the block.
- #callable_args?(required_callable_t, guard) ⇒ Boolean private
- #eql?(o) ⇒ Boolean
- #generalize ⇒ Object
- #hash ⇒ Object
-
#initialize(param_types, block_type = nil, return_type = nil) ⇒ PCallableType
constructor
A new instance of PCallableType.
- #instance?(o, guard = nil) ⇒ Boolean
- #kind_of_callable?(optional = true, guard = nil) ⇒ Boolean
-
#last_range ⇒ Object
Returns the number of accepted arguments for the last parameter type [min, max].
- #normalize(guard = nil) ⇒ Object
- #resolve(type_parser, loader) ⇒ Object
-
#size_range ⇒ Object
Returns the number of accepted arguments [min, max].
Methods inherited from PAnyType
#==, #assignable?, #callable?, #check_self_recursion, #iterable?, #iterable_type, #name, #new_function, new_function, #really_instance?, #simple_name, simple_name, #to_alias_expanded_s, #to_s
Methods inherited from TypedModelObject
_ptype, create_ptype, register_ptypes
Methods included from PuppetObject
Constructor Details
#initialize(param_types, block_type = nil, return_type = nil) ⇒ PCallableType
Returns a new instance of PCallableType.
2096 2097 2098 2099 2100 |
# File 'lib/puppet/pops/types/types.rb', line 2096 def initialize(param_types, block_type = nil, return_type = nil) @param_types = param_types @block_type = block_type @return_type = return_type == PAnyType::DEFAULT ? nil : return_type end |
Instance Attribute Details
#block_type ⇒ PAnyType|nil (readonly)
Although being an abstract type reference, only Callable, or all Callables wrapped in Optional or Variant are supported If not set, the meaning is that block is not supported.
2091 2092 2093 |
# File 'lib/puppet/pops/types/types.rb', line 2091 def block_type @block_type end |
#param_types ⇒ PTupleType (readonly)
Types of parameters as a Tuple with required/optional count, or an Integer with min (required), max count
2085 2086 2087 |
# File 'lib/puppet/pops/types/types.rb', line 2085 def param_types @param_types end |
#return_type ⇒ PAnyType (readonly)
Returns The type for the values returned by this callable. Returns ‘nil` if return value is unconstrained.
2081 2082 2083 |
# File 'lib/puppet/pops/types/types.rb', line 2081 def return_type @return_type end |
Class Method Details
.register_ptype(loader, ir) ⇒ Object
2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 |
# File 'lib/puppet/pops/types/types.rb', line 2067 def self.register_ptype(loader, ir) create_ptype(loader, ir, 'AnyType', 'param_types' => { KEY_TYPE => POptionalType.new(PTupleType::DEFAULT), KEY_VALUE => nil }, 'block_type' => { KEY_TYPE => POptionalType.new(PCallableType::DEFAULT), KEY_VALUE => nil } ) end |
Instance Method Details
#accept(visitor, guard) ⇒ Object
2102 2103 2104 2105 2106 2107 |
# File 'lib/puppet/pops/types/types.rb', line 2102 def accept(visitor, guard) super @param_types.accept(visitor, guard) unless @param_types.nil? @block_type.accept(visitor, guard) unless @block_type.nil? @return_type.accept(visitor, guard) unless @return_type.nil? end |
#block_range ⇒ Object
Range [0,0], [0,1], or [1,1] for the block
2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 |
# File 'lib/puppet/pops/types/types.rb', line 2158 def block_range case block_type when POptionalType [0,1] when PVariantType, PCallableType [1,1] else [0,0] end end |
#callable_args?(required_callable_t, guard) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
2136 2137 2138 2139 |
# File 'lib/puppet/pops/types/types.rb', line 2136 def callable_args?(required_callable_t, guard) # If the required callable is euqal or more specific than self, self is acceptable arguments required_callable_t.assignable?(self, guard) end |
#eql?(o) ⇒ Boolean
2173 2174 2175 |
# File 'lib/puppet/pops/types/types.rb', line 2173 def eql?(o) self.class == o.class && @param_types == o.param_types && @block_type == o.block_type && @return_type == o.return_type end |
#generalize ⇒ Object
2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 |
# File 'lib/puppet/pops/types/types.rb', line 2109 def generalize if self == DEFAULT DEFAULT else params_t = @param_types.nil? ? nil : @param_types.generalize block_t = @block_type.nil? ? nil : @block_type.generalize return_t = @return_type.nil? ? nil : @return_type.generalize @param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : PCallableType.new(params_t, block_t, return_t) end end |
#hash ⇒ Object
2169 2170 2171 |
# File 'lib/puppet/pops/types/types.rb', line 2169 def hash [@param_types, @block_type, @return_type].hash end |
#instance?(o, guard = nil) ⇒ Boolean
2131 2132 2133 |
# File 'lib/puppet/pops/types/types.rb', line 2131 def instance?(o, guard = nil) assignable?(TypeCalculator.infer(o), guard) end |
#kind_of_callable?(optional = true, guard = nil) ⇒ Boolean
2141 2142 2143 |
# File 'lib/puppet/pops/types/types.rb', line 2141 def kind_of_callable?(optional=true, guard = nil) true end |
#last_range ⇒ Object
Returns the number of accepted arguments for the last parameter type [min, max]
2152 2153 2154 |
# File 'lib/puppet/pops/types/types.rb', line 2152 def last_range @param_types.nil? ? nil : @param_types.repeat_last_range end |
#normalize(guard = nil) ⇒ Object
2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 |
# File 'lib/puppet/pops/types/types.rb', line 2120 def normalize(guard = nil) if self == DEFAULT DEFAULT else params_t = @param_types.nil? ? nil : @param_types.normalize(guard) block_t = @block_type.nil? ? nil : @block_type.normalize(guard) return_t = @return_type.nil? ? nil : @return_type.normalize(guard) @param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : PCallableType.new(params_t, block_t, return_t) end end |
#resolve(type_parser, loader) ⇒ Object
2177 2178 2179 2180 2181 2182 |
# File 'lib/puppet/pops/types/types.rb', line 2177 def resolve(type_parser, loader) params_t = @param_types.nil? ? nil : @param_types.resolve(type_parser, loader) block_t = @block_type.nil? ? nil : @block_type.resolve(type_parser, loader) return_t = @return_type.nil? ? nil : @return_type.resolve(type_parser, loader) @param_types.equal?(params_t) && @block_type.equal?(block_t) && @return_type.equal?(return_t) ? self : self.class.new(params_t, block_t, return_t) end |
#size_range ⇒ Object
Returns the number of accepted arguments [min, max]
2146 2147 2148 |
# File 'lib/puppet/pops/types/types.rb', line 2146 def size_range @param_types.nil? ? nil : @param_types.size_range end |