Place constants back inside namespace and add a test to make sure they
are namespaced correctly.
This commit is contained in:
IGI-111
2018-10-22 11:14:41 +02:00
committed by Ryan Hunt
parent 26828c9f3e
commit d32127e3d7
13 changed files with 148 additions and 3 deletions
+4 -3
View File
@@ -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);
+13
View File
@@ -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);
+20
View File
@@ -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
+13
View File
@@ -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);
+11
View File
@@ -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) { }
+1
View File
@@ -0,0 +1 @@
namespace = "constants"
+11
View File
@@ -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) { }
+1
View File
@@ -0,0 +1 @@
namespaces = ["constants", "test"]