Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow #43

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft

Flow #43

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Prototype unified babeltrace 2 generator.
  • Loading branch information
Kerilk committed Aug 3, 2022
commit d1615129bf0d1ebfb8a51967cd01182a93b8c04a
322 changes: 322 additions & 0 deletions utils/gen_babeltrace_base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,322 @@
module Babeltrac2Gen
class BTFieldClass
def self.from_h(model)
FIELD_CLASS_NAME_MAP[model[:class]].from_h(model)
end
end

class BTFieldClass::Bool < BTFieldClass
def self.from_h(model)
self.new
end
end
BTFieldClassBool = BTFieldClass::Bool

class BTFieldClass::BitArray < BTFieldClass
attr_reader :length

def intialize(length:)
@length = length
end

def self.from_h(model)
self.new(length: model[:length])
end
end
BTFieldClassBitArray = BTFieldClass::BitArray

class BTFieldClass::Integer < BTFieldClass
attr_reader :field_value_range, :preferred_display_base

def initialize(field_value_range:, preferred_display_base: 10)
@field_value_range = field_value_range
@preferred_display_base = preferred_display_base
end

def self.from_h(model)
self.new(**model[:class_properties])
end
end
BTFieldClassInteger = BTFieldClass::Integer

class BTFieldClass::Integer::Unsigned < BTFieldClassInteger
end
BTFieldClass::IntegerUnsigned = BTFieldClass::Integer::Unsigned
BTFieldClassIntegerUnsigned = BTFieldClass::Integer::Unsigned

class BTFieldClass::Integer::Signed < BTFieldClassInteger
end
BTFieldClass::IntegerSigned = BTFieldClass::Integer::Signed
BTFieldClassIntegerSigned = BTFieldClass::Integer::Signed

class BTFieldClass::Real < BTFieldClass
def self.from_h(model)
self.new
end
end
BTFieldClassReal = BTFieldClass::Real

class BTFieldClass::Real::SinglePrecision < BTFieldClassReal
end
BTFieldClass::RealSinglePrecision = BTFieldClass::Real::SinglePrecision
BTFieldClassRealSinglePrecision = BTFieldClass::Real::SinglePrecision

class BTFieldClass::Real::DoublePrecision < BTFieldClassReal
end
BTFieldClass::RealDoublePrecision = BTFieldClass::Real::DoublePrecision
BTFieldClassRealDoublePrecision = BTFieldClass::Real::DoublePrecision

module BTFieldClass::Enumeration
attr_reader :mappings
class Mapping
end
end
BTFieldClassEnumeration = BTFieldClass::Enumeration
BTFieldClassEnumerationMapping = BTFieldClass::Enumeration::Mapping

class BTFieldClass::Enumeration::Unsigned < BTFieldClass::Integer::Unsigned
include BTFieldClass::Enumeration
class Mapping < BTFieldClass::Enumeration::Mapping
end

def initialize(field_value_range:, preferred_display_base: 10, mappings:)
@mappings = mappings #TODO init Mapping
super(field_value_range: field_value_range, preferred_display_base: preferred_display_base)
end

def self.from_h(model)
self.new(**model)
end
end
BTFieldClassEnumerationUnsigned = BTFieldClass::Enumeration::Unsigned
BTFieldClassEnumerationUnsignedMapping = BTFieldClass::Enumeration::Unsigned::Mapping

class BTFieldClass::Enumeration::Signed < BTFieldClass::Integer::Signed
include BTFieldClass::Enumeration
class Mapping < BTFieldClass::Enumeration::Mapping
end

def initialize(field_value_range:, preferred_display_base: 10, mappings:)
@mappings = mappings #TODO init Mapping
super(field_value_range: field_value_range, preferred_display_base: preferred_display_base)
end

def self.from_h(model)
self.new(**model)
end
end
BTFieldClassEnumerationSigned = BTFieldClass::Enumeration::Signed
BTFieldClassEnumerationSignedMapping = BTFieldClass::Enumeration::Signed::Mapping

class BTFieldClass::String < BTFieldClass
def self.from_h(model)
self.new
end
end
BTFieldClassString = BTFieldClass::String

class BTFieldClass::Array < BTFieldClass
attr_reader :element_field_class
def initialize(element_field_class:)
@element_field_class = BTFieldClass.from_h(element_field_class)
end
end
BTFieldClassArray = BTFieldClass::Array

class BTFieldClass::Array::Static < BTFieldClass::Array
attr_reader :length

def initialize(element_field_class:, length:)
@length = length
super(element_field_class: element_field_class)
end

def self.from_h(model)
self.new(element_field_class: model[:field], length: model[:length])
end
end
BTFieldClassArrayStatic = BTFieldClass::Array::Static

class BTFieldClass::Array::Dynamic < BTFieldClass::Array
module WithLengthField
attr_reader :length_field_path
end

def initialize(element_field_class:, length_field_path: nil)
super(element_field_class: element_field_class)
if length_field_path
self.extend(WithLengthField)
@length_field_path = length_field_path
end
end

def self.from_h(model)
self.new(element_field_class: model[:field], length_field_path: model[:length_field_path])
end
end
BTFieldClassArrayDynamic = BTFieldClass::Array::Dynamic
BTFieldClassArrayDynamicWithLengthField = BTFieldClass::Array::Dynamic::WithLengthField

class BTFieldClass::Structure < BTFieldClass
attr_reader :members

class Member
attr_reader :name, :field_class

def initialize(name:, field_class:)
@name = name
@field_class = BTFieldClass.from_h(field_class)
end
end

def initialize(members:)
@members = members.collect { |m| Member.new(name: m[:name], field_class: m) }
end

def self.from_h(model)
self.new(members: model[:members])
end
end
BTFieldClassStructure = BTFieldClass::Structure
BTFieldClassStructureMember = BTFieldClass::Structure::Member

class BTFieldClass::Option < BTFieldClass
attr_reader :field_class

def initialize(field_class:)
@field_class = BTFieldClass.from_h(field_class)
end
end
BTFieldClassOption = BTFieldClass::Option

class BTFieldClass::Option::WithoutSelectorField < BTFieldClass::Option
def self.from_h(model)
self.new(field_class: model[:field])
end
end
BTFieldClassOptionWithoutSelectorField = BTFieldClass::Option::WithoutSelectorField

class BTFieldClass::Option::WithSelectorField < BTFieldClass::Option
attr_reader :selector_field_path

def initialize(field_class:, selector_field_path:)
@selector_field_path = selector_field_path
super(field_class: field_class)
end
end
BTFieldClassOptionWithSelectorField = BTFieldClass::Option::WithSelectorField

class BTFieldClass::Option::WithSelectorField::Bool < BTFieldClass::Option::WithSelectorField
attr_reader :selector_is_reversed

def initialize(field_class:, selector_field_path:, selector_is_reversed: nil)
@selector_is_reversed = selector_is_reversed
super(field_class: field_class, selector_field_path: selector_field_path)
end

def self.from_h(model)
self.new(field_class: model[:field], selector_field_path: model[:selector_field_path], selector_is_reversed: [selector_field_path])
end
end
BTFieldClassOptionWithSelectorFieldBool = BTFieldClass::Option::WithSelectorField::Bool

class BTFieldClass::Option::WithSelectorField::IntegerUnsigned < BTFieldClass::Option::WithSelectorField
attr_reader :selector_ranges

def initialize(field_class:, selector_field_path:, selector_ranges:)
@selector_ranges = selector_ranges
super(field_class: field_class, selector_field_path: selector_field_path)
end

def self.from_h(model)
self.new(field_class: model[:field], selector_field_path: model[:selector_field_path], selector_ranges: model[:selector_ranges])
end
end
BTFieldClassOptionWithSelectorFieldIntegerUnsigned = BTFieldClass::Option::WithSelectorField::IntegerUnsigned

class BTFieldClass::Option::WithSelectorField::IntegerSigned < BTFieldClass::Option::WithSelectorField
attr_reader :selector_ranges

def initialize(field_class:, selector_field_path:, selector_ranges:)
@selector_ranges = selector_ranges
super(field_class: field_class, selector_field_path: selector_field_path)
end

def self.from_h(model)
self.new(field_class: model[:field], selector_field_path: model[:selector_field_path], selector_ranges: model[:selector_ranges])
end
end
BTFieldClassOptionWithSelectorFieldIntegerSigned = BTFieldClass::Option::WithSelectorField::IntegerSigned

class BTFieldClass::Variant < BTFieldClass
attr_reader :options

class Option
attr_reader :name, :field_class
def initialize(name:, field_class:)
@name = name
@field_class = BTFieldClass.from_h(field_class)
end
end

end
BTFieldClassVariant = BTFieldClass::Variant
BTFieldClassVariantOption = BTFieldClass::Variant::Option

class BTFieldClass::Variant
module WithoutSelectorField
end
module WithSelectorField
attr_reader :selector_field_class
class Option < BTFieldClassVariantOption
attr_reader :ranges
def initialize(name:, field_class:, ranges:)
@ranges = ranges
super(name: name, field_class: field_class)
end
end
end

def initialize(options:, selector_field_class: nil)
if selector_field_class
self.extend(WithSelectorField)
@selector_field_class = selector_field_class
@options = options.collect { |o|
BTFieldClass::Variant::WithSelectorField::Option.new(name: o[:name], field_class: o[:field], range: o[:range])
}
else
self.extend(WithoutSelectorField)
@options = options.collect { |o|
BTFieldClass::Variant::Option.new(name: o[:name], field_class: o[:field])
}
end
end
end
BTFieldClassVariantWithoutSelectorField =
BTFieldClass::Variant::WithoutSelectorField
BTFieldClassVariantWithSelectorField =
BTFieldClass::Variant::WithSelectorField
BTFieldClassVariantWithSelectorFieldOption =
BTFieldClass::Variant::WithSelectorField::Option

FIELD_CLASS_NAME_MAP = {
"bool" => BTFieldClass::Bool,
"bit_array" => BTFieldClass::BitArray,
"unsigned" => BTFieldClass::Integer::Unsigned,
"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
}

end