class

Bindgen::Processor::Inheritance

Inherits Bindgen::Processor::Base < Bindgen::Graph::Visitor < Reference < Object

Processor wrapping single- and multiple-inheritance.

Only non-private wrapped classes are possible candidates for this. Of all candidates, the first one is chosen as parent class in Crystal. All others get a #as_X() : X casting method.

Take this C++ class: class Foo : public Bar, public Baz If both Bar and Baz are wrapped, the resulting Crystal wrapper will look like this:

class Foo < Bar # First one is inherited
  def as_baz : Baz
    ...
  end # Later ones converted
end

Classes with further wrapped bases, and polymorphic classes with wrapped polymorphic ancestors or descendants, get a #to?(T.class) method, casting self to the wrapper class T. It returns self for its own class, calls #as_X for the further bases, and casts down to polymorphic sub-classes through a dynamic_cast, returning nil if the instance isn't a T. The result wraps the same C++ object. Other types are passed on to the #to? of the Crystal superclass, or are a compile-time error.

x = Bar.create # Returns a `Bar`, which actually is a `Foo`
x.to?(Foo)     # => #<Foo:...>
x.to?(Baz)     # Compile-time error

Every wrapper class gets the Crystal class method Graph::Class::DISCOVER_METHOD, see SPEC.md §2.3.7, which wraps a pointer in the Crystal object which constructed the object, if any, and else in a new wrapper. A polymorphic class with wrapped sub-classes in Crystal gets type discovery too: a C++ DISCOVER function finding the wrapper class of the dynamic type of an object, which the method wraps in. Crystal::Pass#from_wrapper converts a pointer or reference result, and the argument of a callback, through it: x above is a Foo already.

Constants

Log = ::Log.for(self)

Processor wrapping single- and multiple-inheritance.

Only non-private wrapped classes are possible candidates for this. Of all candidates, the first one is chosen as parent class in Crystal. All others get a #as_X() : X casting method.

Take this C++ class: class Foo : public Bar, public Baz If both Bar and Baz are wrapped, the resulting Crystal wrapper will look like this:

class Foo < Bar # First one is inherited
  def as_baz : Baz
    ...
  end # Later ones converted
end

Classes with further wrapped bases, and polymorphic classes with wrapped polymorphic ancestors or descendants, get a #to?(T.class) method, casting self to the wrapper class T. It returns self for its own class, calls #as_X for the further bases, and casts down to polymorphic sub-classes through a dynamic_cast, returning nil if the instance isn't a T. The result wraps the same C++ object. Other types are passed on to the #to? of the Crystal superclass, or are a compile-time error.

x = Bar.create # Returns a `Bar`, which actually is a `Foo`
x.to?(Foo)     # => #<Foo:...>
x.to?(Baz)     # Compile-time error

Every wrapper class gets the Crystal class method Graph::Class::DISCOVER_METHOD, see SPEC.md §2.3.7, which wraps a pointer in the Crystal object which constructed the object, if any, and else in a new wrapper. A polymorphic class with wrapped sub-classes in Crystal gets type discovery too: a C++ DISCOVER function finding the wrapper class of the dynamic type of an object, which the method wraps in. Crystal::Pass#from_wrapper converts a pointer or reference result, and the argument of a callback, through it: x above is a Foo already.

Constructors

new(config, db)
Source

Instance methods

process(graph : Graph::Container, doc : Parser::Document)

Runs the processor. You may change graph as you see fit.

Source
visit_class(klass : Graph::Class)
Source

Nested types