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.


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

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)


182
183
184
# File 'lib/puppet/pops/model/ast.rb', line 182

def left_expr
  @left_expr
end

#right_exprObject (readonly)


183
184
185
# File 'lib/puppet/pops/model/ast.rb', line 183

def right_expr
  @right_expr
end

Class Method Details

._pcore_typeObject


148
149
150
151
152
153
154
155
156
# File 'lib/puppet/pops/model/ast.rb', line 148

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


171
172
173
174
175
176
177
178
179
180
# File 'lib/puppet/pops/model/ast.rb', line 171

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


162
163
164
165
166
167
168
169
# File 'lib/puppet/pops/model/ast.rb', line 162

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


158
159
160
# File 'lib/puppet/pops/model/ast.rb', line 158

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


204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/puppet/pops/model/ast.rb', line 204

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:


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

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

#_pcore_init_hashObject


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

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)

217
218
219
220
221
# File 'lib/puppet/pops/model/ast.rb', line 217

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