Class: Babeltrace2Gen::BTFieldClass

Inherits:
Object
  • Object
show all
Includes:
BTLocator, BTPrinter
Defined in:
lib/metababel/bt2_stream_classes_generator.rb

Direct Known Subclasses

Array, BitArray, Bool, Integer, Option, Real, String, Structure, Variant

Defined Under Namespace

Modules: Enumeration Classes: Array, BitArray, Bool, Integer, Option, Real, String, Structure, Variant

Constant Summary

Constants included from BTPrinter

Babeltrace2Gen::BTPrinter::INDENT_INCREMENT

Instance Attribute Summary collapse

Attributes included from BTLocator

#parent, #variable

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BTPrinter

context, #name_sanitized, pr, #scope

Methods included from BTLocator

#rec_event_class, #rec_menber_class, #rec_stream_class, #resolve_path

Constructor Details

#initialize(parent:) ⇒ BTFieldClass

Returns a new instance of BTFieldClass.



332
333
334
# File 'lib/metababel/bt2_stream_classes_generator.rb', line 332

def initialize(parent:)
  @parent = parent
end

Instance Attribute Details

#cast_typeObject

Returns the value of attribute cast_type.



330
331
332
# File 'lib/metababel/bt2_stream_classes_generator.rb', line 330

def cast_type
  @cast_type
end

Class Method Details

.from_h(parent, model) ⇒ Object



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/metababel/bt2_stream_classes_generator.rb', line 336

def self.from_h(parent, model)
  key = model.delete(:type)
  raise "No type in #{model}" unless key

  h = {
    'bool' => BTFieldClass::Bool,
    'bit_array' => BTFieldClass::BitArray,
    'integer_unsigned' => BTFieldClass::Integer::Unsigned,
    'integer_signed' => BTFieldClass::Integer::Signed,
    'single' => BTFieldClass::Real::SinglePrecision,
    'double' => BTFieldClass::Real::DoublePrecision,
    'enumeration_unsigned' => BTFieldClass::Enumeration::Unsigned,
    'enumeration_signed' => BTFieldClass::Enumeration::Signed,
    'string' => BTFieldClass::String,
    'array_static' => BTFieldClass::Array::Static,
    'array_dynamic' => BTFieldClass::Array::Dynamic,
    'structure' => BTFieldClass::Structure,
    'option_without_selector_field' => BTFieldClass::Option::WithoutSelectorField,
    'option_with_selector_field_bool' => BTFieldClass::Option::WithSelectorField::Bool,
    'option_with_selector_field_unsigned' => BTFieldClass::Option::WithSelectorField::IntegerUnsigned,
    'option_with_selector_field_signed' => BTFieldClass::Option::WithSelectorField::IntegerSigned,
    'variant' => BTFieldClass::Variant
  }.freeze

  raise "No #{key} in FIELD_CLASS_NAME_MAP" unless h.include?(key)

  cast_type = model.delete(:cast_type)
  fc = h[key].from_h(parent, model)
  fc.cast_type = cast_type if cast_type
  fc
end

Instance Method Details

#bt_get_variable(arg_variables, is_array: false) ⇒ Object



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/metababel/bt2_stream_classes_generator.rb', line 372

def bt_get_variable(arg_variables, is_array: false)
  internal = arg_variables.fetch('internal', [])
  return internal.shift unless internal.empty?

  type =
    if is_array
      "#{element_field_class.class.instance_variable_get(:@bt_type)}*"
    else
      self.class.instance_variable_get(:@bt_type)
    end
  var = GeneratedArg.new(@cast_type || type, rec_menber_class.name)

  arg_variables.fetch_append('outputs_allocated', var) if is_array
  arg_variables.fetch_append('outputs', var)
end

#get_declarator(*args, **dict) ⇒ Object

Raises:

  • (NotImplementedError)


368
369
370
# File 'lib/metababel/bt2_stream_classes_generator.rb', line 368

def get_declarator(*args, **dict)
  raise NotImplementedError, self.class
end

#get_getter(field:, arg_variables:) ⇒ Object



388
389
390
391
392
393
# File 'lib/metababel/bt2_stream_classes_generator.rb', line 388

def get_getter(field:, arg_variables:)
  bt_func_get = self.class.instance_variable_get(:@bt_func) % 'get'
  variable = bt_get_variable(arg_variables).name
  cast_func = @cast_type ? "(#{@cast_type})" : ''
  pr "#{variable} = #{cast_func}#{bt_func_get}(#{field});"
end

#get_setter(field:, arg_variables:) ⇒ Object



395
396
397
398
399
400
# File 'lib/metababel/bt2_stream_classes_generator.rb', line 395

def get_setter(field:, arg_variables:)
  bt_func_get = self.class.instance_variable_get(:@bt_func) % 'set'
  variable = bt_get_variable(arg_variables).name
  cast_func = @cast_type ? "(#{self.class.instance_variable_get(:@bt_type)})" : ''
  pr "#{bt_func_get}(#{field}, #{variable});"
end