ir: write declaration of global variable like struct fields

This commit is contained in:
TheKK
2020-02-25 13:32:28 +08:00
committed by Emilio Cobos Álvarez
parent dfa6e5f982
commit 61e55ce4d9
9 changed files with 92 additions and 2 deletions
+3 -2
View File
@@ -6,6 +6,7 @@ use std::io::Write;
use syn;
use crate::bindgen::cdecl;
use crate::bindgen::config::Config;
use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver;
use crate::bindgen::dependencies::Dependencies;
@@ -112,7 +113,7 @@ impl Source for Static {
} else if !self.mutable {
out.write("const ");
}
self.ty.write(config, out);
write!(out, " {};", self.export_name());
cdecl::write_field(out, &self.ty, &self.export_name, config);
out.write(";");
}
}
@@ -0,0 +1,8 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
extern const char CONST_GLOBAL_ARRAY[128];
extern char MUT_GLOBAL_ARRAY[128];
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
extern const char CONST_GLOBAL_ARRAY[128];
extern char MUT_GLOBAL_ARRAY[128];
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+8
View File
@@ -0,0 +1,8 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
extern const char CONST_GLOBAL_ARRAY[128];
extern char MUT_GLOBAL_ARRAY[128];
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
extern const char CONST_GLOBAL_ARRAY[128];
extern char MUT_GLOBAL_ARRAY[128];
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+12
View File
@@ -0,0 +1,12 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <new>
extern "C" {
extern const char CONST_GLOBAL_ARRAY[128];
extern char MUT_GLOBAL_ARRAY[128];
} // extern "C"
+8
View File
@@ -0,0 +1,8 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
extern const char CONST_GLOBAL_ARRAY[128];
extern char MUT_GLOBAL_ARRAY[128];
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
extern const char CONST_GLOBAL_ARRAY[128];
extern char MUT_GLOBAL_ARRAY[128];
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
+5
View File
@@ -0,0 +1,5 @@
#[no_mangle]
pub static mut MUT_GLOBAL_ARRAY: [c_char; 128] = [0; 128];
#[no_mangle]
pub static CONST_GLOBAL_ARRAY: [c_char; 128] = [0; 128];