Class: Puppet::Pops::Model::BinaryExpression

Inherits:
Expression show all
Defined in:
lib/puppet/pops/model/ast.rb

Instance Attribute Summary collapse

Attributes inherited from Positioned

#length, #locator, #offset

Attributes inherited from PopsObject

#hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Positioned

#file, #line, #pos

Methods inherited from PopsObject

#to_s

Methods included from Types::PuppetObject

#_pcore_type, #to_s

Constructor Details

#initialize(locator, offset, length, left_expr, right_expr) ⇒ BinaryExpression

Returns a new instance of BinaryExpression.



191
192
193
194
195
196
# File 'lib/puppet/pops/model/ast.rb', line 191

def initialize(locator, offset, length, left_expr, right_expr)
  super(locator, offset, length)
  @hash = @hash ^ left_expr.hash ^ right_expr.hash
  @left_expr = left_expr
  @right_expr = right_expr
end

Instance Attribute Details

#left_exprObject (readonly)



188
189
190
# File 'lib/puppet/pops/model/ast.rb', line 188

def left_expr
  @left_expr
end

#right_exprObject (readonly)



189
190
191
# File 'lib/puppet/pops/model/ast.rb', line 189

def right_expr
  @right_expr
end

Class Method Details

._pcore_typeObject



153
154
155
156
157
158
159
160
161
162
# File 'lib/puppet/pops/model/ast.rb', line 153

def self._pcore_type
  @_pcore_type ||=
    Types::PObjectType.new('Puppet::AST::BinaryExpression', {
                             'parent' => Expression._pcore_type,
                             'attributes' => {
                               'left_expr' => Expression._pcore_type,
                               'right_expr' => Expression._pcore_type
                             }
                           })
end

.create(locator, offset, length, left_expr, right_expr) ⇒ Object



177
178
179
180
181
182
183
184
185
186
# File 'lib/puppet/pops/model/ast.rb', line 177

def self.create(locator, offset, length, left_expr, right_expr)
  ta = Types::TypeAsserter
  attrs = _pcore_type.attributes(true)
  ta.assert_instance_of('Puppet::AST::Positioned[locator]', attrs['locator'].type, locator)
  ta.assert_instance_of('Puppet::AST::Positioned[offset]', attrs['offset'].type, offset)
  ta.assert_instance_of('Puppet::AST::Positioned[length]', attrs['length'].type, length)
  ta.assert_instance_of('Puppet::AST::BinaryExpression[left_expr]', attrs['left_expr'].type, left_expr)
  ta.assert_instance_of('Puppet::AST::BinaryExpression[right_expr]', attrs['right_expr'].type, right_expr)
  new(locator, offset, length, left_expr, right_expr)
end

.from_asserted_hash(init_hash) ⇒ Object



168
169
170
171
172
173
174
175
# File 'lib/puppet/pops/model/ast.rb', line 168

def self.from_asserted_hash(init_hash)
  new(
    init_hash['locator'],
    init_hash['offset'],
    init_hash['length'],
    init_hash['left_expr'],
    init_hash['right_expr'])
end

.from_hash(init_hash) ⇒ Object



164
165
166
# File 'lib/puppet/pops/model/ast.rb', line 164

def self.from_hash(init_hash)
  from_asserted_hash(Types::TypeAsserter.assert_instance_of('Puppet::AST::BinaryExpression initializer', _pcore_type.init_hash_type, init_hash))
end

Instance Method Details

#_pcore_all_contents(path, &block) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/puppet/pops/model/ast.rb', line 210

def _pcore_all_contents(path, &block)
  path << self
  unless @left_expr.nil?
    block.call(@left_expr, path)
    @left_expr._pcore_all_contents(path, &block)
  end
  unless @right_expr.nil?
    block.call(@right_expr, path)
    @right_expr._pcore_all_contents(path, &block)
  end
  path.pop
end

#_pcore_contents {|@left_expr| ... } ⇒ Object

Yields:



205
206
207
208
# File 'lib/puppet/pops/model/ast.rb', line 205

def _pcore_contents
  yield(@left_expr) unless @left_expr.nil?
  yield(@right_expr) unless @right_expr.nil?
end

#_pcore_init_hashObject



198
199
200
201
202
203
# File 'lib/puppet/pops/model/ast.rb', line 198

def _pcore_init_hash
  result = super
  result['left_expr'] = @left_expr
  result['right_expr'] = @right_expr
  result
end

#eql?(o) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


223
224
225
226
227
# File 'lib/puppet/pops/model/ast.rb', line 223

def eql?(o)
  super &&
  @left_expr.eql?(o.left_expr) &&
  @right_expr.eql?(o.right_expr)
end