Remove generated code that is not needed.

master
Jos van den Oever 2017-08-25 15:42:56 +02:00
parent 9e1419e8fe
commit d3312d6ce3
11 changed files with 100 additions and 420 deletions

View File

@ -32,76 +32,6 @@ impl<T> From<Option<T>> for COption<T> where T: Default {
}
}
#[repr(C)]
pub struct QString {
data: *const uint8_t,
len: c_int,
}
#[repr(C)]
pub struct QStringIn {
data: *const uint16_t,
len: c_int,
}
impl QStringIn {
fn convert(&self) -> String {
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
String::from_utf16_lossy(data)
}
}
impl<'a> From<&'a String> for QString {
fn from(string: &'a String) -> QString {
QString {
len: string.len() as c_int,
data: string.as_ptr(),
}
}
}
#[repr(C)]
pub struct QByteArray {
data: *const uint8_t,
len: c_int,
}
impl QByteArray {
fn convert(&self) -> Vec<u8> {
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
Vec::from(data)
}
}
impl<'a> From<&'a Vec<u8>> for QByteArray {
fn from(value: &'a Vec<u8>) -> QByteArray {
QByteArray {
len: value.len() as c_int,
data: value.as_ptr(),
}
}
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
impl QModelIndex {
fn invalid() -> QModelIndex {
QModelIndex {
row: -1,
internal_id: 0,
}
}
fn create(row: c_int, id: usize) -> QModelIndex {
QModelIndex {
row: row,
internal_id: id,
}
}
}
#[repr(C)]
pub enum SortOrder {
@ -109,6 +39,11 @@ pub enum SortOrder {
Descending = 1
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
pub struct FibonacciQObject {}

View File

@ -32,6 +32,7 @@ impl<T> From<Option<T>> for COption<T> where T: Default {
}
}
#[repr(C)]
pub struct QString {
data: *const uint8_t,
@ -60,6 +61,7 @@ impl<'a> From<&'a String> for QString {
}
}
#[repr(C)]
pub struct QByteArray {
data: *const uint8_t,
@ -82,26 +84,6 @@ impl<'a> From<&'a Vec<u8>> for QByteArray {
}
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
impl QModelIndex {
fn invalid() -> QModelIndex {
QModelIndex {
row: -1,
internal_id: 0,
}
}
fn create(row: c_int, id: usize) -> QModelIndex {
QModelIndex {
row: row,
internal_id: id,
}
}
}
#[repr(C)]
pub enum SortOrder {
@ -109,6 +91,11 @@ pub enum SortOrder {
Descending = 1
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
pub struct TreeQObject {}
@ -286,9 +273,9 @@ pub unsafe extern "C" fn tree_index(ptr: *const Tree, item: usize, valid: bool,
#[no_mangle]
pub unsafe extern "C" fn tree_parent(ptr: *const Tree, index: usize) -> QModelIndex {
if let Some(parent) = (&*ptr).parent(index) {
QModelIndex::create((&*ptr).row(parent) as c_int, parent)
QModelIndex{row: (&*ptr).row(parent) as c_int, internal_id: parent}
} else {
QModelIndex::invalid()
QModelIndex{row: -1, internal_id: 0}
}
}
#[no_mangle]

View File

@ -32,6 +32,7 @@ impl<T> From<Option<T>> for COption<T> where T: Default {
}
}
#[repr(C)]
pub struct QString {
data: *const uint8_t,
@ -60,48 +61,6 @@ impl<'a> From<&'a String> for QString {
}
}
#[repr(C)]
pub struct QByteArray {
data: *const uint8_t,
len: c_int,
}
impl QByteArray {
fn convert(&self) -> Vec<u8> {
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
Vec::from(data)
}
}
impl<'a> From<&'a Vec<u8>> for QByteArray {
fn from(value: &'a Vec<u8>) -> QByteArray {
QByteArray {
len: value.len() as c_int,
data: value.as_ptr(),
}
}
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
impl QModelIndex {
fn invalid() -> QModelIndex {
QModelIndex {
row: -1,
internal_id: 0,
}
}
fn create(row: c_int, id: usize) -> QModelIndex {
QModelIndex {
row: row,
internal_id: id,
}
}
}
#[repr(C)]
pub enum SortOrder {
@ -109,6 +68,11 @@ pub enum SortOrder {
Descending = 1
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
pub struct ProcessesQObject {}
@ -257,9 +221,9 @@ pub unsafe extern "C" fn processes_index(ptr: *const Processes, item: usize, val
#[no_mangle]
pub unsafe extern "C" fn processes_parent(ptr: *const Processes, index: usize) -> QModelIndex {
if let Some(parent) = (&*ptr).parent(index) {
QModelIndex::create((&*ptr).row(parent) as c_int, parent)
QModelIndex{row: (&*ptr).row(parent) as c_int, internal_id: parent}
} else {
QModelIndex::invalid()
QModelIndex{row: -1, internal_id: 0}
}
}
#[no_mangle]

View File

@ -32,76 +32,6 @@ impl<T> From<Option<T>> for COption<T> where T: Default {
}
}
#[repr(C)]
pub struct QString {
data: *const uint8_t,
len: c_int,
}
#[repr(C)]
pub struct QStringIn {
data: *const uint16_t,
len: c_int,
}
impl QStringIn {
fn convert(&self) -> String {
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
String::from_utf16_lossy(data)
}
}
impl<'a> From<&'a String> for QString {
fn from(string: &'a String) -> QString {
QString {
len: string.len() as c_int,
data: string.as_ptr(),
}
}
}
#[repr(C)]
pub struct QByteArray {
data: *const uint8_t,
len: c_int,
}
impl QByteArray {
fn convert(&self) -> Vec<u8> {
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
Vec::from(data)
}
}
impl<'a> From<&'a Vec<u8>> for QByteArray {
fn from(value: &'a Vec<u8>) -> QByteArray {
QByteArray {
len: value.len() as c_int,
data: value.as_ptr(),
}
}
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
impl QModelIndex {
fn invalid() -> QModelIndex {
QModelIndex {
row: -1,
internal_id: 0,
}
}
fn create(row: c_int, id: usize) -> QModelIndex {
QModelIndex {
row: row,
internal_id: id,
}
}
}
#[repr(C)]
pub enum SortOrder {
@ -109,6 +39,11 @@ pub enum SortOrder {
Descending = 1
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
pub struct TimeSeriesQObject {}

View File

@ -5,8 +5,9 @@
#include <QJsonArray>
#include <QMetaEnum>
BindingTypeProperties simpleType(const char* name, const char* init) {
BindingTypeProperties simpleType(BindingType type, const char* name, const char* init) {
return {
.type = type,
.name = name,
.cppSetType = name,
.cSetType = name,
@ -19,8 +20,9 @@ const QMap<BindingType, BindingTypeProperties>& bindingTypeProperties() {
static QMap<BindingType, BindingTypeProperties> p;
if (p.empty()) {
QMap<BindingType, BindingTypeProperties> f;
f.insert(BindingType::Bool, simpleType("bool", "true"));
f.insert(BindingType::Bool, simpleType(BindingType::Bool, "bool", "true"));
f.insert(BindingType::UChar, {
.type = BindingType::UChar,
.name = "quint8",
.cppSetType = "quint8",
.cSetType = "quint8",
@ -28,6 +30,7 @@ const QMap<BindingType, BindingTypeProperties>& bindingTypeProperties() {
.rustTypeInit = "0",
});
f.insert(BindingType::Int, {
.type = BindingType::Int,
.name = "qint32",
.cppSetType = "qint32",
.cSetType = "qint32",
@ -35,6 +38,7 @@ const QMap<BindingType, BindingTypeProperties>& bindingTypeProperties() {
.rustTypeInit = "0",
});
f.insert(BindingType::UInt, {
.type = BindingType::UInt,
.name = "quint32",
.cppSetType = "uint",
.cSetType = "uint",
@ -42,6 +46,7 @@ const QMap<BindingType, BindingTypeProperties>& bindingTypeProperties() {
.rustTypeInit = "0"
});
f.insert(BindingType::ULongLong, {
.type = BindingType::ULongLong,
.name = "quint64",
.cppSetType = "quint64",
.cSetType = "quint64",
@ -49,6 +54,7 @@ const QMap<BindingType, BindingTypeProperties>& bindingTypeProperties() {
.rustTypeInit = "0"
});
f.insert(BindingType::Float, {
.type = BindingType::Float,
.name = "float",
.cppSetType = "float",
.cSetType = "float",
@ -56,6 +62,7 @@ const QMap<BindingType, BindingTypeProperties>& bindingTypeProperties() {
.rustTypeInit = "0.0"
});
f.insert(BindingType::QString, {
.type = BindingType::QString,
.name = "QString",
.cppSetType = "const QString&",
.cSetType = "qstring_t",
@ -63,6 +70,7 @@ const QMap<BindingType, BindingTypeProperties>& bindingTypeProperties() {
.rustTypeInit = "String::new()"
});
f.insert(BindingType::QByteArray, {
.type = BindingType::QByteArray,
.name = "QByteArray",
.cppSetType = "const QByteArray&",
.cSetType = "qbytearray_t",

View File

@ -362,9 +362,9 @@ pub unsafe extern "C" fn %2_index(ptr: *const %1, item: usize, valid: bool, row:
#[no_mangle]
pub unsafe extern "C" fn %2_parent(ptr: *const %1, index: usize) -> QModelIndex {
if let Some(parent) = (&*ptr).parent(index) {
QModelIndex::create((&*ptr).row(parent) as c_int, parent)
QModelIndex{row: (&*ptr).row(parent) as c_int, internal_id: parent}
} else {
QModelIndex::invalid()
QModelIndex{row: -1, internal_id: 0}
}
}
#[no_mangle]
@ -446,8 +446,31 @@ QString rustFile(const QDir rustdir, const QString& module) {
return path;
}
void writeRustTypes(QTextStream& r) {
r << QString(R"(
void writeRustTypes(const Configuration& conf, QTextStream& r) {
bool hasOption = false;
bool hasString = false;
bool hasStringWrite = false;
bool hasByteArray = false;
bool hasListOrTree = false;
for (auto o: conf.objects) {
hasListOrTree |= o.type != ObjectType::Object;
for (auto p: o.properties) {
hasOption |= p.optional;
hasString |= p.type.type == BindingType::QString;
hasStringWrite |= p.type.type == BindingType::QString
&& p.write;
hasByteArray |= p.type.type == BindingType::QByteArray;
}
for (auto p: o.itemProperties) {
hasOption |= p.optional;
hasString |= p.type.type == BindingType::QString;
hasByteArray |= p.type.type == BindingType::QByteArray;
}
}
if (hasOption || hasListOrTree) {
r << R"(
#[repr(C)]
pub struct COption<T> {
@ -470,6 +493,10 @@ impl<T> From<Option<T>> for COption<T> where T: Default {
}
}
}
)";
}
if (hasString) {
r << R"(
#[repr(C)]
pub struct QString {
@ -498,6 +525,10 @@ impl<'a> From<&'a String> for QString {
}
}
}
)";
}
if (hasByteArray) {
r << R"(
#[repr(C)]
pub struct QByteArray {
@ -520,27 +551,10 @@ impl<'a> From<&'a Vec<u8>> for QByteArray {
}
}
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
impl QModelIndex {
fn invalid() -> QModelIndex {
QModelIndex {
row: -1,
internal_id: 0,
}
)";
}
fn create(row: c_int, id: usize) -> QModelIndex {
QModelIndex {
row: row,
internal_id: id,
}
}
}
if (hasListOrTree) {
r << R"(
#[repr(C)]
pub enum SortOrder {
@ -548,7 +562,13 @@ pub enum SortOrder {
Descending = 1
}
)");
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
)";
}
}
void writeRustInterface(const Configuration& conf) {
@ -566,7 +586,7 @@ use std::ptr::null;
use %1::*;
)").arg(conf.implementationModule);
writeRustTypes(r);
writeRustTypes(conf, r);
for (auto object: conf.objects) {
writeRustInterfaceObject(r, object);

View File

@ -22,6 +22,7 @@ enum class BindingType {
};
struct BindingTypeProperties {
BindingType type;
QString name;
QString cppSetType;
QString cSetType;

View File

@ -32,6 +32,7 @@ impl<T> From<Option<T>> for COption<T> where T: Default {
}
}
#[repr(C)]
pub struct QString {
data: *const uint8_t,
@ -60,48 +61,6 @@ impl<'a> From<&'a String> for QString {
}
}
#[repr(C)]
pub struct QByteArray {
data: *const uint8_t,
len: c_int,
}
impl QByteArray {
fn convert(&self) -> Vec<u8> {
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
Vec::from(data)
}
}
impl<'a> From<&'a Vec<u8>> for QByteArray {
fn from(value: &'a Vec<u8>) -> QByteArray {
QByteArray {
len: value.len() as c_int,
data: value.as_ptr(),
}
}
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
impl QModelIndex {
fn invalid() -> QModelIndex {
QModelIndex {
row: -1,
internal_id: 0,
}
}
fn create(row: c_int, id: usize) -> QModelIndex {
QModelIndex {
row: row,
internal_id: id,
}
}
}
#[repr(C)]
pub enum SortOrder {
@ -109,6 +68,11 @@ pub enum SortOrder {
Descending = 1
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
pub struct PersonsQObject {}

View File

@ -10,28 +10,6 @@ use std::ptr::null;
use implementation::*;
#[repr(C)]
pub struct COption<T> {
data: T,
some: bool,
}
impl<T> From<Option<T>> for COption<T> where T: Default {
fn from(t: Option<T>) -> COption <T> {
if let Some(v) = t {
COption {
data: v,
some: true
}
} else {
COption {
data: T::default(),
some: false
}
}
}
}
#[repr(C)]
pub struct QString {
data: *const uint8_t,
@ -60,56 +38,6 @@ impl<'a> From<&'a String> for QString {
}
}
#[repr(C)]
pub struct QByteArray {
data: *const uint8_t,
len: c_int,
}
impl QByteArray {
fn convert(&self) -> Vec<u8> {
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
Vec::from(data)
}
}
impl<'a> From<&'a Vec<u8>> for QByteArray {
fn from(value: &'a Vec<u8>) -> QByteArray {
QByteArray {
len: value.len() as c_int,
data: value.as_ptr(),
}
}
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
impl QModelIndex {
fn invalid() -> QModelIndex {
QModelIndex {
row: -1,
internal_id: 0,
}
}
fn create(row: c_int, id: usize) -> QModelIndex {
QModelIndex {
row: row,
internal_id: id,
}
}
}
#[repr(C)]
pub enum SortOrder {
Ascending = 0,
Descending = 1
}
pub struct PersonQObject {}
#[derive (Clone)]

View File

@ -32,6 +32,7 @@ impl<T> From<Option<T>> for COption<T> where T: Default {
}
}
#[repr(C)]
pub struct QString {
data: *const uint8_t,
@ -60,6 +61,7 @@ impl<'a> From<&'a String> for QString {
}
}
#[repr(C)]
pub struct QByteArray {
data: *const uint8_t,
@ -82,34 +84,6 @@ impl<'a> From<&'a Vec<u8>> for QByteArray {
}
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
impl QModelIndex {
fn invalid() -> QModelIndex {
QModelIndex {
row: -1,
internal_id: 0,
}
}
fn create(row: c_int, id: usize) -> QModelIndex {
QModelIndex {
row: row,
internal_id: id,
}
}
}
#[repr(C)]
pub enum SortOrder {
Ascending = 0,
Descending = 1
}
pub struct ObjectQObject {}
#[derive (Clone)]

View File

@ -32,6 +32,7 @@ impl<T> From<Option<T>> for COption<T> where T: Default {
}
}
#[repr(C)]
pub struct QString {
data: *const uint8_t,
@ -60,48 +61,6 @@ impl<'a> From<&'a String> for QString {
}
}
#[repr(C)]
pub struct QByteArray {
data: *const uint8_t,
len: c_int,
}
impl QByteArray {
fn convert(&self) -> Vec<u8> {
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
Vec::from(data)
}
}
impl<'a> From<&'a Vec<u8>> for QByteArray {
fn from(value: &'a Vec<u8>) -> QByteArray {
QByteArray {
len: value.len() as c_int,
data: value.as_ptr(),
}
}
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
impl QModelIndex {
fn invalid() -> QModelIndex {
QModelIndex {
row: -1,
internal_id: 0,
}
}
fn create(row: c_int, id: usize) -> QModelIndex {
QModelIndex {
row: row,
internal_id: id,
}
}
}
#[repr(C)]
pub enum SortOrder {
@ -109,6 +68,11 @@ pub enum SortOrder {
Descending = 1
}
#[repr(C)]
pub struct QModelIndex {
row: c_int,
internal_id: usize,
}
pub struct PersonsQObject {}
@ -252,9 +216,9 @@ pub unsafe extern "C" fn persons_index(ptr: *const Persons, item: usize, valid:
#[no_mangle]
pub unsafe extern "C" fn persons_parent(ptr: *const Persons, index: usize) -> QModelIndex {
if let Some(parent) = (&*ptr).parent(index) {
QModelIndex::create((&*ptr).row(parent) as c_int, parent)
QModelIndex{row: (&*ptr).row(parent) as c_int, internal_id: parent}
} else {
QModelIndex::invalid()
QModelIndex{row: -1, internal_id: 0}
}
}
#[no_mangle]