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

Sort types #100

Open
kornilova203 opened this issue Jul 4, 2018 · 1 comment
Open

Sort types #100

kornilova203 opened this issue Jul 4, 2018 · 1 comment
Labels
bindgen Binding generator
Milestone

Comments

@kornilova203
Copy link
Member

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;
};
@kornilova203 kornilova203 added the bindgen Binding generator label Jul 4, 2018
@jonas jonas added this to the 0.3 milestone Jul 6, 2018
@kornilova203
Copy link
Member Author

I think this should be moved to 0.4

@kornilova203 kornilova203 modified the milestones: 0.3, 0.4 Aug 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bindgen Binding generator
Projects
None yet
Development

No branches or pull requests

2 participants