Skip to content

Commit

Permalink
ir: Simplify types in generics.
Browse files Browse the repository at this point in the history
This was an oversight in 1903686
because the code I grabbed to visit the generics was dealing with them
somewhere else.
  • Loading branch information
emilio committed Mar 2, 2021
1 parent a0dc1a1 commit aaef260
Show file tree
Hide file tree
Showing 35 changed files with 85 additions and 78 deletions.
8 changes: 5 additions & 3 deletions src/bindgen/ir/generic_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ impl GenericPath {
if self.path.replace_self_with(self_ty) {
self.export_name = self_ty.name().to_owned();
}
for ty in &mut self.generics {
ty.replace_self_with(self_ty);
}
// Caller deals with generics.
}

pub fn path(&self) -> &Path {
Expand All @@ -107,6 +105,10 @@ impl GenericPath {
&self.generics
}

pub fn generics_mut(&mut self) -> &mut [Type] {
&mut self.generics
}

pub fn ctype(&self) -> Option<&DeclarationType> {
self.ctype.as_ref()
}
Expand Down
7 changes: 6 additions & 1 deletion src/bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,12 @@ impl Type {
fn visit_types(&mut self, mut visitor: impl FnMut(&mut Type)) {
match *self {
Type::Array(ref mut ty, ..) | Type::Ptr { ref mut ty, .. } => visitor(ty),
Type::Path(..) | Type::Primitive(..) => {}
Type::Path(ref mut path) => {
for generic in path.generics_mut() {
visitor(generic);
}
}
Type::Primitive(..) => {}
Type::FuncPtr {
ref mut ret,
ref mut args,
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/box.both.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using Box = T*;
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_Box_i32 NotReprC_Box_i32;
typedef struct NotReprC_____i32 NotReprC_____i32;

typedef struct NotReprC_Box_i32 Foo;
typedef struct NotReprC_____i32 Foo;

typedef struct MyStruct {
int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/box.both.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using Box = T*;
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_Box_i32 NotReprC_Box_i32;
typedef struct NotReprC_____i32 NotReprC_____i32;

typedef struct NotReprC_Box_i32 Foo;
typedef struct NotReprC_____i32 Foo;

typedef struct MyStruct {
int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/box.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using Box = T*;
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_Box_i32 NotReprC_Box_i32;
typedef struct NotReprC_____i32 NotReprC_____i32;

typedef NotReprC_Box_i32 Foo;
typedef NotReprC_____i32 Foo;

typedef struct {
int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/box.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using Box = T*;
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_Box_i32 NotReprC_Box_i32;
typedef struct NotReprC_____i32 NotReprC_____i32;

typedef NotReprC_Box_i32 Foo;
typedef NotReprC_____i32 Foo;

typedef struct {
int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/box.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ cdef extern from *:

cdef extern from *:

ctypedef struct NotReprC_Box_i32:
ctypedef struct NotReprC_____i32:
pass

ctypedef NotReprC_Box_i32 Foo;
ctypedef NotReprC_____i32 Foo;

ctypedef struct MyStruct:
int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/box.tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using Box = T*;
#include <stdint.h>
#include <stdlib.h>

struct NotReprC_Box_i32;
struct NotReprC_____i32;

typedef struct NotReprC_Box_i32 Foo;
typedef struct NotReprC_____i32 Foo;

struct MyStruct {
int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/box.tag.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using Box = T*;
#include <stdint.h>
#include <stdlib.h>

struct NotReprC_Box_i32;
struct NotReprC_____i32;

typedef struct NotReprC_Box_i32 Foo;
typedef struct NotReprC_____i32 Foo;

struct MyStruct {
int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/box.tag.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ cdef extern from *:

cdef extern from *:

cdef struct NotReprC_Box_i32:
cdef struct NotReprC_____i32:
pass

ctypedef NotReprC_Box_i32 Foo;
ctypedef NotReprC_____i32 Foo;

cdef struct MyStruct:
int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/manuallydrop.both.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using ManuallyDrop = T;
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_ManuallyDrop_Point NotReprC_ManuallyDrop_Point;
typedef struct NotReprC_Point NotReprC_Point;

typedef struct NotReprC_ManuallyDrop_Point Foo;
typedef struct NotReprC_Point Foo;

typedef struct Point {
int32_t x;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/manuallydrop.both.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using ManuallyDrop = T;
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_ManuallyDrop_Point NotReprC_ManuallyDrop_Point;
typedef struct NotReprC_Point NotReprC_Point;

typedef struct NotReprC_ManuallyDrop_Point Foo;
typedef struct NotReprC_Point Foo;

typedef struct Point {
int32_t x;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/manuallydrop.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using ManuallyDrop = T;
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_ManuallyDrop_Point NotReprC_ManuallyDrop_Point;
typedef struct NotReprC_Point NotReprC_Point;

typedef NotReprC_ManuallyDrop_Point Foo;
typedef NotReprC_Point Foo;

typedef struct {
int32_t x;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/manuallydrop.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using ManuallyDrop = T;
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_ManuallyDrop_Point NotReprC_ManuallyDrop_Point;
typedef struct NotReprC_Point NotReprC_Point;

typedef NotReprC_ManuallyDrop_Point Foo;
typedef NotReprC_Point Foo;

typedef struct {
int32_t x;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/manuallydrop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ cdef extern from *:

cdef extern from *:

ctypedef struct NotReprC_ManuallyDrop_Point:
ctypedef struct NotReprC_Point:
pass

ctypedef NotReprC_ManuallyDrop_Point Foo;
ctypedef NotReprC_Point Foo;

ctypedef struct Point:
int32_t x;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/manuallydrop.tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using ManuallyDrop = T;
#include <stdint.h>
#include <stdlib.h>

struct NotReprC_ManuallyDrop_Point;
struct NotReprC_Point;

typedef struct NotReprC_ManuallyDrop_Point Foo;
typedef struct NotReprC_Point Foo;

struct Point {
int32_t x;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/manuallydrop.tag.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using ManuallyDrop = T;
#include <stdint.h>
#include <stdlib.h>

struct NotReprC_ManuallyDrop_Point;
struct NotReprC_Point;

typedef struct NotReprC_ManuallyDrop_Point Foo;
typedef struct NotReprC_Point Foo;

struct Point {
int32_t x;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/manuallydrop.tag.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ cdef extern from *:

cdef extern from *:

cdef struct NotReprC_ManuallyDrop_Point:
cdef struct NotReprC_Point:
pass

ctypedef NotReprC_ManuallyDrop_Point Foo;
ctypedef NotReprC_Point Foo;

cdef struct Point:
int32_t x;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/maybeuninit.both.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using MaybeUninit = T;
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_MaybeUninit______i32 NotReprC_MaybeUninit______i32;
typedef struct NotReprC______i32 NotReprC______i32;

typedef struct NotReprC_MaybeUninit______i32 Foo;
typedef struct NotReprC______i32 Foo;

typedef struct MyStruct {
const int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/maybeuninit.both.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using MaybeUninit = T;
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_MaybeUninit______i32 NotReprC_MaybeUninit______i32;
typedef struct NotReprC______i32 NotReprC______i32;

typedef struct NotReprC_MaybeUninit______i32 Foo;
typedef struct NotReprC______i32 Foo;

typedef struct MyStruct {
const int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/maybeuninit.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using MaybeUninit = T;
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_MaybeUninit______i32 NotReprC_MaybeUninit______i32;
typedef struct NotReprC______i32 NotReprC______i32;

typedef NotReprC_MaybeUninit______i32 Foo;
typedef NotReprC______i32 Foo;

typedef struct {
const int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/maybeuninit.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using MaybeUninit = T;
#include <stdint.h>
#include <stdlib.h>

typedef struct NotReprC_MaybeUninit______i32 NotReprC_MaybeUninit______i32;
typedef struct NotReprC______i32 NotReprC______i32;

typedef NotReprC_MaybeUninit______i32 Foo;
typedef NotReprC______i32 Foo;

typedef struct {
const int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/maybeuninit.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ cdef extern from *:

cdef extern from *:

ctypedef struct NotReprC_MaybeUninit______i32:
ctypedef struct NotReprC______i32:
pass

ctypedef NotReprC_MaybeUninit______i32 Foo;
ctypedef NotReprC______i32 Foo;

ctypedef struct MyStruct:
const int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/maybeuninit.tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using MaybeUninit = T;
#include <stdint.h>
#include <stdlib.h>

struct NotReprC_MaybeUninit______i32;
struct NotReprC______i32;

typedef struct NotReprC_MaybeUninit______i32 Foo;
typedef struct NotReprC______i32 Foo;

struct MyStruct {
const int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/maybeuninit.tag.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ using MaybeUninit = T;
#include <stdint.h>
#include <stdlib.h>

struct NotReprC_MaybeUninit______i32;
struct NotReprC______i32;

typedef struct NotReprC_MaybeUninit______i32 Foo;
typedef struct NotReprC______i32 Foo;

struct MyStruct {
const int32_t *number;
Expand Down
4 changes: 2 additions & 2 deletions tests/expectations/maybeuninit.tag.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ cdef extern from *:

cdef extern from *:

cdef struct NotReprC_MaybeUninit______i32:
cdef struct NotReprC______i32:
pass

ctypedef NotReprC_MaybeUninit______i32 Foo;
ctypedef NotReprC______i32 Foo;

cdef struct MyStruct:
const int32_t *number;
Expand Down
6 changes: 3 additions & 3 deletions tests/expectations/nonzero.both.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct NonZeroI64;
#include <stdint.h>
#include <stdlib.h>

typedef struct Option_Option_NonZeroI64 Option_Option_NonZeroI64;
typedef struct Option_i64 Option_i64;

typedef struct NonZeroTest {
uint8_t a;
Expand All @@ -28,7 +28,7 @@ typedef struct NonZeroTest {
int32_t g;
int64_t h;
int64_t i;
const struct Option_Option_NonZeroI64 *j;
const struct Option_i64 *j;
} NonZeroTest;

void root(struct NonZeroTest test,
Expand All @@ -41,4 +41,4 @@ void root(struct NonZeroTest test,
int32_t g,
int64_t h,
int64_t i,
const struct Option_Option_NonZeroI64 *j);
const struct Option_i64 *j);
6 changes: 3 additions & 3 deletions tests/expectations/nonzero.both.compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct NonZeroI64;
#include <stdint.h>
#include <stdlib.h>

typedef struct Option_Option_NonZeroI64 Option_Option_NonZeroI64;
typedef struct Option_i64 Option_i64;

typedef struct NonZeroTest {
uint8_t a;
Expand All @@ -28,7 +28,7 @@ typedef struct NonZeroTest {
int32_t g;
int64_t h;
int64_t i;
const struct Option_Option_NonZeroI64 *j;
const struct Option_i64 *j;
} NonZeroTest;

#ifdef __cplusplus
Expand All @@ -45,7 +45,7 @@ void root(struct NonZeroTest test,
int32_t g,
int64_t h,
int64_t i,
const struct Option_Option_NonZeroI64 *j);
const struct Option_i64 *j);

#ifdef __cplusplus
} // extern "C"
Expand Down
Loading

0 comments on commit aaef260

Please sign in to comment.