Add support for adding "using namespace" statements

This commit is contained in:
Rasmus Eneman
2019-08-24 01:09:50 +02:00
committed by Emilio Cobos Álvarez
parent 8e4db4c17f
commit 4bd7b07d2f
11 changed files with 93 additions and 0 deletions
+8
View File
@@ -217,6 +217,14 @@ impl Bindings {
}
if self.config.language == Language::Cxx || self.config.cpp_compat {
if let Some(ref using) = self.config.using {
for namespace in using {
out.new_line();
write!(out, "using namespace {};", namespace);
}
out.new_line();
}
out.new_line();
out.write("extern \"C\" {");
out.new_line();
+3
View File
@@ -621,6 +621,8 @@ pub struct Config {
pub namespace: Option<String>,
/// An optional list of namespaces. Only applicable when language="C++"
pub namespaces: Option<Vec<String>>,
/// An optional list of namespaces to ddeclare as using. Only applicable when language="C++"
pub using: Option<Vec<String>>,
/// The style to use for braces
pub braces: Braces,
/// The preferred length of a line, used for auto breaking function arguments
@@ -672,6 +674,7 @@ impl Default for Config {
no_includes: false,
namespace: None,
namespaces: None,
using: None,
braces: Braces::SameLine,
line_length: 100,
tab_width: 2,
+6
View File
@@ -0,0 +1,6 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
void root(void);
+16
View File
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
using namespace std;
extern "C" {
#endif // __cplusplus
void root(void);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+6
View File
@@ -0,0 +1,6 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
void root(void);
+16
View File
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
using namespace std;
extern "C" {
#endif // __cplusplus
void root(void);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+6
View File
@@ -0,0 +1,6 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
void root(void);
+16
View File
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
using namespace std;
extern "C" {
#endif // __cplusplus
void root(void);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+12
View File
@@ -0,0 +1,12 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <new>
using namespace std;
extern "C" {
void root();
} // extern "C"
+3
View File
@@ -0,0 +1,3 @@
#[no_mangle]
pub extern "C" fn root() {
}
+1
View File
@@ -0,0 +1 @@
using = ["std"]