Skip to content

Sort types #100

Open
Open
@kornilova203

Description

@kornilova203

Bindgen generates types in the order they appear in a header file.

Consider following example:

typedef struct points points;
typedef struct point point;

struct points {
    point *point1;
    point *point2;
};

struct point {
    int x;
    int y;
};

It will generate types in the following order:

type struct_points = native.CStruct2[native.Ptr[point], native.Ptr[point]]
type points = struct_points
type struct_point = native.CStruct2[native.CInt, native.CInt]
type point = struct_point

In generated code points appear before point although points uses point.

To sort types we need to know what types are used by other types and then do topological sort.

There is also one problem that should be considered, types may have cyclic dependency:

struct b;
struct c;

struct a {
   struct b *b;
};

struct b {
    struct c *c;
};

struct c {
    struct a *a;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    bindgenBinding generator

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions