Support renaming for constants with casts, and properly order them in the output.
This commit is contained in:
committed by
Emilio Cobos Álvarez
parent
967c378308
commit
bb00d1c4a8
@@ -216,7 +216,7 @@ impl Bindings {
|
|||||||
self.open_namespaces(&mut out);
|
self.open_namespaces(&mut out);
|
||||||
|
|
||||||
for constant in &self.constants {
|
for constant in &self.constants {
|
||||||
if constant.ty.is_primitive_or_ptr_primitive() {
|
if constant.uses_only_primitive_types() {
|
||||||
out.new_line_if_not_start();
|
out.new_line_if_not_start();
|
||||||
constant.write(&self.config, &mut out, None);
|
constant.write(&self.config, &mut out, None);
|
||||||
out.new_line();
|
out.new_line();
|
||||||
@@ -247,7 +247,7 @@ impl Bindings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for constant in &self.constants {
|
for constant in &self.constants {
|
||||||
if !constant.ty.is_primitive_or_ptr_primitive() {
|
if !constant.uses_only_primitive_types() {
|
||||||
out.new_line_if_not_start();
|
out.new_line_if_not_start();
|
||||||
constant.write(&self.config, &mut out, None);
|
constant.write(&self.config, &mut out, None);
|
||||||
out.new_line();
|
out.new_line();
|
||||||
|
|||||||
@@ -46,11 +46,17 @@ pub enum Literal {
|
|||||||
impl Literal {
|
impl Literal {
|
||||||
fn replace_self_with(&mut self, self_ty: &Path) {
|
fn replace_self_with(&mut self, self_ty: &Path) {
|
||||||
match *self {
|
match *self {
|
||||||
Literal::PostfixUnaryOp { .. }
|
Literal::PostfixUnaryOp { ref mut value, .. } => {
|
||||||
| Literal::BinOp { .. }
|
value.replace_self_with(self_ty);
|
||||||
| Literal::Expr(..)
|
}
|
||||||
| Literal::Path(..)
|
Literal::BinOp {
|
||||||
| Literal::Cast { .. } => {}
|
ref mut left,
|
||||||
|
ref mut right,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
left.replace_self_with(self_ty);
|
||||||
|
right.replace_self_with(self_ty);
|
||||||
|
}
|
||||||
Literal::Struct {
|
Literal::Struct {
|
||||||
ref mut path,
|
ref mut path,
|
||||||
ref mut export_name,
|
ref mut export_name,
|
||||||
@@ -63,6 +69,14 @@ impl Literal {
|
|||||||
expr.replace_self_with(self_ty);
|
expr.replace_self_with(self_ty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Literal::Cast {
|
||||||
|
ref mut ty,
|
||||||
|
ref mut value,
|
||||||
|
} => {
|
||||||
|
ty.replace_self_with(self_ty);
|
||||||
|
value.replace_self_with(self_ty);
|
||||||
|
}
|
||||||
|
Literal::Expr(..) | Literal::Path(..) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +94,23 @@ impl Literal {
|
|||||||
Literal::Cast { ref value, .. } => value.is_valid(bindings),
|
Literal::Cast { ref value, .. } => value.is_valid(bindings),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn uses_only_primitive_types(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
Literal::Expr(..) => true,
|
||||||
|
Literal::Path(..) => true,
|
||||||
|
Literal::PostfixUnaryOp { ref value, .. } => value.uses_only_primitive_types(),
|
||||||
|
Literal::BinOp {
|
||||||
|
ref left,
|
||||||
|
ref right,
|
||||||
|
..
|
||||||
|
} => left.uses_only_primitive_types() & right.uses_only_primitive_types(),
|
||||||
|
Literal::Struct { .. } => false,
|
||||||
|
Literal::Cast { ref value, ref ty } => {
|
||||||
|
value.uses_only_primitive_types() && ty.is_primitive_or_ptr_primitive()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Literal {
|
impl Literal {
|
||||||
@@ -110,7 +141,11 @@ impl Literal {
|
|||||||
right.rename_for_config(config);
|
right.rename_for_config(config);
|
||||||
}
|
}
|
||||||
Literal::Expr(_) => {}
|
Literal::Expr(_) => {}
|
||||||
Literal::Cast { ref mut value, .. } => {
|
Literal::Cast {
|
||||||
|
ref mut ty,
|
||||||
|
ref mut value,
|
||||||
|
} => {
|
||||||
|
ty.rename_for_config(config, &GenericParams::default());
|
||||||
value.rename_for_config(config);
|
value.rename_for_config(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -398,6 +433,10 @@ impl Constant {
|
|||||||
associated_to,
|
associated_to,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn uses_only_primitive_types(&self) -> bool {
|
||||||
|
self.value.uses_only_primitive_types() && self.ty.is_primitive_or_ptr_primitive()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Item for Constant {
|
impl Item for Constant {
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ typedef union C_D {
|
|||||||
|
|
||||||
typedef C_A C_F;
|
typedef C_A C_F;
|
||||||
|
|
||||||
|
#define C_I (intptr_t)(C_F*)10
|
||||||
|
|
||||||
extern const int32_t G;
|
extern const int32_t G;
|
||||||
|
|
||||||
void root(const C_A *a, C_AwesomeB b, C_C c, C_D d, C_E e, C_F f);
|
void root(const C_A *a, C_AwesomeB b, C_C c, C_D d, C_E e, C_F f);
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ typedef union C_D {
|
|||||||
|
|
||||||
typedef C_A C_F;
|
typedef C_A C_F;
|
||||||
|
|
||||||
|
#define C_I (intptr_t)(C_F*)10
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ typedef union {
|
|||||||
|
|
||||||
typedef C_A C_F;
|
typedef C_A C_F;
|
||||||
|
|
||||||
|
#define C_I (intptr_t)(C_F*)10
|
||||||
|
|
||||||
extern const int32_t G;
|
extern const int32_t G;
|
||||||
|
|
||||||
void root(const C_A *a, C_AwesomeB b, C_C c, C_D d, C_E e, C_F f);
|
void root(const C_A *a, C_AwesomeB b, C_C c, C_D d, C_E e, C_F f);
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ typedef union {
|
|||||||
|
|
||||||
typedef C_A C_F;
|
typedef C_A C_F;
|
||||||
|
|
||||||
|
#define C_I (intptr_t)(C_F*)10
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ union C_D {
|
|||||||
|
|
||||||
using C_F = C_A;
|
using C_F = C_A;
|
||||||
|
|
||||||
|
static const intptr_t C_I = (intptr_t)(C_F*)10;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
extern const int32_t G;
|
extern const int32_t G;
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ union C_D {
|
|||||||
|
|
||||||
typedef struct C_A C_F;
|
typedef struct C_A C_F;
|
||||||
|
|
||||||
|
#define C_I (intptr_t)(C_F*)10
|
||||||
|
|
||||||
extern const int32_t G;
|
extern const int32_t G;
|
||||||
|
|
||||||
void root(const struct C_A *a, struct C_AwesomeB b, struct C_C c, union C_D d, C_E e, C_F f);
|
void root(const struct C_A *a, struct C_AwesomeB b, struct C_C c, union C_D d, C_E e, C_F f);
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ union C_D {
|
|||||||
|
|
||||||
typedef struct C_A C_F;
|
typedef struct C_A C_F;
|
||||||
|
|
||||||
|
#define C_I (intptr_t)(C_F*)10
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ pub static G: i32 = 10;
|
|||||||
|
|
||||||
pub const H: i32 = 10;
|
pub const H: i32 = 10;
|
||||||
|
|
||||||
|
pub const I: isize = 10 as *mut F as isize;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn root(
|
pub extern "C" fn root(
|
||||||
a: *const A,
|
a: *const A,
|
||||||
|
|||||||
Reference in New Issue
Block a user