Fix #229
Place constants back inside namespace and add a test to make sure they are namespaced correctly.
This commit is contained in:
@@ -126,6 +126,10 @@ impl Bindings {
|
||||
self.write_headers(&mut out);
|
||||
}
|
||||
|
||||
if self.config.language == Language::Cxx {
|
||||
self.open_namespaces(&mut out);
|
||||
}
|
||||
|
||||
for constant in &self.constants {
|
||||
if constant.ty.is_primitive_or_ptr_primitive() {
|
||||
out.new_line_if_not_start();
|
||||
@@ -134,9 +138,6 @@ impl Bindings {
|
||||
}
|
||||
}
|
||||
|
||||
if self.config.language == Language::Cxx {
|
||||
self.open_namespaces(&mut out);
|
||||
}
|
||||
for item in &self.items {
|
||||
if item
|
||||
.deref()
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FOO 10
|
||||
|
||||
#define ZOM 3.14
|
||||
|
||||
typedef struct Foo {
|
||||
int32_t x[FOO];
|
||||
} Foo;
|
||||
|
||||
void root(Foo x);
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FOO 10
|
||||
|
||||
#define ZOM 3.14
|
||||
|
||||
typedef struct Foo {
|
||||
int32_t x[FOO];
|
||||
} Foo;
|
||||
|
||||
void root(Foo x);
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FOO 10
|
||||
|
||||
#define ZOM 3.14
|
||||
|
||||
typedef struct {
|
||||
int32_t x[FOO];
|
||||
} Foo;
|
||||
|
||||
void root(Foo x);
|
||||
@@ -0,0 +1,20 @@
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace constants {
|
||||
|
||||
static const int32_t FOO = 10;
|
||||
|
||||
static const float ZOM = 3.14;
|
||||
|
||||
struct Foo {
|
||||
int32_t x[FOO];
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
||||
void root(Foo x);
|
||||
|
||||
} // extern "C"
|
||||
|
||||
} // namespace constants
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FOO 10
|
||||
|
||||
#define ZOM 3.14
|
||||
|
||||
typedef struct {
|
||||
int32_t x[FOO];
|
||||
} Foo;
|
||||
|
||||
void root(Foo x);
|
||||
@@ -0,0 +1,22 @@
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace constants {
|
||||
namespace test {
|
||||
|
||||
static const int32_t FOO = 10;
|
||||
|
||||
static const float ZOM = 3.14;
|
||||
|
||||
struct Foo {
|
||||
int32_t x[FOO];
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
||||
void root(Foo x);
|
||||
|
||||
} // extern "C"
|
||||
|
||||
} // namespace test
|
||||
} // namespace constants
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FOO 10
|
||||
|
||||
#define ZOM 3.14
|
||||
|
||||
struct Foo {
|
||||
int32_t x[FOO];
|
||||
};
|
||||
|
||||
void root(struct Foo x);
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define FOO 10
|
||||
|
||||
#define ZOM 3.14
|
||||
|
||||
struct Foo {
|
||||
int32_t x[FOO];
|
||||
};
|
||||
|
||||
void root(struct Foo x);
|
||||
@@ -0,0 +1,11 @@
|
||||
const FOO: i32 = 10;
|
||||
const BAR: &'static str = "hello world";
|
||||
const ZOM: f32 = 3.14;
|
||||
|
||||
#[repr(C)]
|
||||
struct Foo {
|
||||
x: [i32; FOO],
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn root(x: Foo) { }
|
||||
@@ -0,0 +1 @@
|
||||
namespace = "constants"
|
||||
@@ -0,0 +1,11 @@
|
||||
const FOO: i32 = 10;
|
||||
const BAR: &'static str = "hello world";
|
||||
const ZOM: f32 = 3.14;
|
||||
|
||||
#[repr(C)]
|
||||
struct Foo {
|
||||
x: [i32; FOO],
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn root(x: Foo) { }
|
||||
@@ -0,0 +1 @@
|
||||
namespaces = ["constants", "test"]
|
||||
Reference in New Issue
Block a user