2017-09-05 11:06:20 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Jos van den Oever <jos@vandenoever.info>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License or (at your option) version 3 or any later version
|
|
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
|
|
* defined in Section 14 of version 3 of the license.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-08-22 04:45:34 -07:00
|
|
|
#include "structs.h"
|
|
|
|
#include "helper.h"
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
QString rustType(const T& p)
|
|
|
|
{
|
|
|
|
if (p.optional) {
|
|
|
|
return "Option<" + p.type.rustType + ">";
|
|
|
|
}
|
|
|
|
return p.type.rustType;
|
|
|
|
}
|
|
|
|
|
2017-08-30 12:58:01 -07:00
|
|
|
template <typename T>
|
|
|
|
QString rustReturnType(const T& p)
|
|
|
|
{
|
|
|
|
QString type = p.type.rustType;
|
|
|
|
if (type == "String" && !p.rustByValue) {
|
|
|
|
type = "str";
|
|
|
|
}
|
|
|
|
if (type == "Vec<u8>" && !p.rustByValue) {
|
|
|
|
type = "[u8]";
|
|
|
|
}
|
|
|
|
if (p.type.isComplex() && !p.rustByValue) {
|
|
|
|
type = "&" + type;
|
|
|
|
}
|
|
|
|
if (p.optional) {
|
|
|
|
return "Option<" + type + ">";
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2017-08-22 04:45:34 -07:00
|
|
|
template <typename T>
|
|
|
|
QString rustCType(const T& p)
|
|
|
|
{
|
|
|
|
if (p.optional) {
|
|
|
|
return "COption<" + p.type.rustType + ">";
|
|
|
|
}
|
|
|
|
return p.type.rustType;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
QString rustTypeInit(const T& p)
|
|
|
|
{
|
|
|
|
if (p.optional) {
|
|
|
|
return "None";
|
|
|
|
}
|
|
|
|
return p.type.rustTypeInit;
|
|
|
|
}
|
|
|
|
|
2017-08-26 10:10:18 -07:00
|
|
|
void rConstructorArgsDecl(QTextStream& r, const QString& name, const Object& o, const Configuration& conf) {
|
2017-08-31 10:20:25 -07:00
|
|
|
r << QString(" %2: *mut %1QObject").arg(o.name, snakeCase(name));
|
2017-08-26 10:10:18 -07:00
|
|
|
for (const Property& p: o.properties) {
|
|
|
|
if (p.type.type == BindingType::Object) {
|
2017-08-29 11:37:51 -07:00
|
|
|
r << QString(",\n");
|
2017-08-26 10:10:18 -07:00
|
|
|
rConstructorArgsDecl(r, p.name, conf.findObject(p.type.name), conf);
|
|
|
|
} else {
|
2018-06-30 11:23:29 -07:00
|
|
|
r << QString(",\n %3_%2_changed: fn(*const %1QObject)")
|
|
|
|
.arg(o.name, snakeCase(p.name), snakeCase(name));
|
2017-08-26 10:10:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (o.type == ObjectType::List) {
|
2017-08-31 10:20:25 -07:00
|
|
|
r << QString(",\n %2_new_data_ready: fn(*const %1QObject)")
|
2018-06-30 11:23:29 -07:00
|
|
|
.arg(o.name, snakeCase(name));
|
2017-09-03 06:13:11 -07:00
|
|
|
} else if (o.type == ObjectType::Tree) {
|
2018-09-08 11:47:48 -07:00
|
|
|
r << QString(",\n %2_new_data_ready: fn(*const %1QObject, index: COption<usize>)")
|
2018-06-30 11:23:29 -07:00
|
|
|
.arg(o.name, snakeCase(name));
|
2017-08-26 10:10:18 -07:00
|
|
|
}
|
|
|
|
if (o.type != ObjectType::Object) {
|
|
|
|
QString indexDecl;
|
2017-09-03 06:13:11 -07:00
|
|
|
if (o.type == ObjectType::Tree) {
|
2018-09-08 11:47:48 -07:00
|
|
|
indexDecl = " index: COption<usize>,";
|
2017-08-26 10:10:18 -07:00
|
|
|
}
|
2018-09-08 12:54:34 -07:00
|
|
|
QString destDecl;
|
|
|
|
if (o.type == ObjectType::Tree) {
|
|
|
|
destDecl = " index: COption<usize>,";
|
|
|
|
}
|
2017-08-26 10:10:18 -07:00
|
|
|
r << QString(R"(,
|
2018-09-08 13:48:59 -07:00
|
|
|
%3_layout_about_to_be_changed: fn(*const %1QObject),
|
|
|
|
%3_layout_changed: fn(*const %1QObject),
|
2017-08-31 10:20:25 -07:00
|
|
|
%3_data_changed: fn(*const %1QObject, usize, usize),
|
|
|
|
%3_begin_reset_model: fn(*const %1QObject),
|
|
|
|
%3_end_reset_model: fn(*const %1QObject),
|
|
|
|
%3_begin_insert_rows: fn(*const %1QObject,%2 usize, usize),
|
|
|
|
%3_end_insert_rows: fn(*const %1QObject),
|
2018-09-08 12:54:34 -07:00
|
|
|
%3_begin_move_rows: fn(*const %1QObject,%2 usize, usize,%4 usize),
|
|
|
|
%3_end_move_rows: fn(*const %1QObject),
|
2017-08-31 10:20:25 -07:00
|
|
|
%3_begin_remove_rows: fn(*const %1QObject,%2 usize, usize),
|
|
|
|
%3_end_remove_rows: fn(*const %1QObject))").arg(o.name, indexDecl,
|
2018-09-08 12:54:34 -07:00
|
|
|
snakeCase(name), destDecl);
|
2017-08-26 10:10:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rConstructorArgs(QTextStream& r, const QString& name, const Object& o, const Configuration& conf) {
|
|
|
|
const QString lcname(snakeCase(o.name));
|
|
|
|
for (const Property& p: o.properties) {
|
|
|
|
if (p.type.type == BindingType::Object) {
|
|
|
|
rConstructorArgs(r, p.name, conf.findObject(p.type.name), conf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r << QString(R"( let %2_emit = %1Emitter {
|
|
|
|
qobject: Arc::new(Mutex::new(%2)),
|
2017-08-31 10:20:25 -07:00
|
|
|
)").arg(o.name, snakeCase(name));
|
2017-08-26 10:10:18 -07:00
|
|
|
for (const Property& p: o.properties) {
|
|
|
|
if (p.type.type == BindingType::Object) continue;
|
2018-06-30 11:23:29 -07:00
|
|
|
r << QString(" %1_changed: %2_%1_changed,\n").arg(snakeCase(p.name), snakeCase(name));
|
2017-08-26 10:10:18 -07:00
|
|
|
}
|
|
|
|
if (o.type != ObjectType::Object) {
|
2017-08-31 10:20:25 -07:00
|
|
|
r << QString(" new_data_ready: %1_new_data_ready,\n")
|
2018-06-30 11:23:29 -07:00
|
|
|
.arg(snakeCase(name));
|
2017-08-26 10:10:18 -07:00
|
|
|
}
|
|
|
|
QString model = "";
|
|
|
|
if (o.type != ObjectType::Object) {
|
2017-09-03 06:13:11 -07:00
|
|
|
const QString type = o.type == ObjectType::List ? "List" : "Tree";
|
2017-08-26 10:10:18 -07:00
|
|
|
model = ", model";
|
|
|
|
r << QString(R"( };
|
|
|
|
let model = %1%2 {
|
|
|
|
qobject: %3,
|
2018-09-08 13:48:59 -07:00
|
|
|
layout_about_to_be_changed: %4_layout_about_to_be_changed,
|
|
|
|
layout_changed: %4_layout_changed,
|
2017-08-31 10:20:25 -07:00
|
|
|
data_changed: %4_data_changed,
|
|
|
|
begin_reset_model: %4_begin_reset_model,
|
|
|
|
end_reset_model: %4_end_reset_model,
|
|
|
|
begin_insert_rows: %4_begin_insert_rows,
|
|
|
|
end_insert_rows: %4_end_insert_rows,
|
2018-09-08 12:54:34 -07:00
|
|
|
begin_move_rows: %4_begin_move_rows,
|
|
|
|
end_move_rows: %4_end_move_rows,
|
2017-08-31 10:20:25 -07:00
|
|
|
begin_remove_rows: %4_begin_remove_rows,
|
|
|
|
end_remove_rows: %4_end_remove_rows,
|
2018-06-30 11:23:29 -07:00
|
|
|
)").arg(o.name, type, snakeCase(name), snakeCase(name));
|
2017-08-26 10:10:18 -07:00
|
|
|
}
|
2017-09-03 08:32:46 -07:00
|
|
|
r << QString(" };\n let d_%3 = %1::new(%3_emit%2")
|
2017-08-31 10:20:25 -07:00
|
|
|
.arg(o.name, model, snakeCase(name));
|
2017-08-26 10:10:18 -07:00
|
|
|
for (const Property& p: o.properties) {
|
|
|
|
if (p.type.type == BindingType::Object) {
|
2017-08-31 10:20:25 -07:00
|
|
|
r << ",\n d_" << snakeCase(p.name);
|
2017-08-26 10:10:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
r << ");\n";
|
|
|
|
}
|
|
|
|
|
2018-05-12 04:58:43 -07:00
|
|
|
void writeFunction(QTextStream& r, const Function& f, const QString& lcname, const Object& o) {
|
|
|
|
const QString lc(snakeCase(f.name));
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %1_%2(ptr: *%3 %4)").arg(lcname, lc, f.mut ? "mut" : "const", o.name);
|
2018-05-12 04:58:43 -07:00
|
|
|
// write all the input arguments, for QString and QByteArray, write
|
|
|
|
// pointers to their content and the length which is int in Qt
|
|
|
|
for (auto a = f.args.begin(); a < f.args.end(); a++) {
|
|
|
|
r << ", ";
|
|
|
|
if (a->type.name == "QString") {
|
|
|
|
r << QString("%1_str: *const c_ushort, %1_len: c_int").arg(a->name);
|
2018-05-16 13:38:30 -07:00
|
|
|
} else if (a->type.name == "QByteArray") {
|
|
|
|
r << QString("%1_str: *const c_char, %1_len: c_int").arg(a->name);
|
2018-05-12 04:58:43 -07:00
|
|
|
} else {
|
|
|
|
r << a->name << ": " << a->type.rustType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If the return type is QString or QByteArray, append a pointer to the
|
|
|
|
// variable that will be set to the argument list. Also add a setter
|
|
|
|
// function.
|
2018-05-16 00:12:03 -07:00
|
|
|
if (f.type.isComplex()) {
|
|
|
|
r << QString(", d: *mut %1, set: fn(*mut %1, str: *const c_char, len: c_int)) {\n").arg(f.type.name);
|
2018-05-12 04:58:43 -07:00
|
|
|
} else {
|
|
|
|
r << ") -> " << f.type.rustType << " {\n";
|
|
|
|
}
|
|
|
|
for (auto a = f.args.begin(); a < f.args.end(); a++) {
|
|
|
|
if (a->type.name == "QString") {
|
|
|
|
r << " let mut " << a->name << " = String::new();\n";
|
|
|
|
r << QString(" set_string_from_utf16(&mut %1, %1_str, %1_len);\n").arg(a->name);
|
|
|
|
} else if (a->type.name == "QByteArray") {
|
2018-09-11 14:29:06 -07:00
|
|
|
r << QString(" let %1 = { slice::from_raw_parts(%1_str as *const u8, to_usize(%1_len)) };\n").arg(a->name);
|
2018-05-12 04:58:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (f.mut) {
|
2018-09-11 14:29:06 -07:00
|
|
|
r << " let o = &mut *ptr;\n";
|
2018-05-12 04:58:43 -07:00
|
|
|
} else {
|
2018-09-11 14:29:06 -07:00
|
|
|
r << " let o = &*ptr;\n";
|
2018-05-12 04:58:43 -07:00
|
|
|
}
|
|
|
|
r << " let r = o." << lc << "(";
|
|
|
|
for (auto a = f.args.begin(); a < f.args.end(); a++) {
|
|
|
|
if (a != f.args.begin()) {
|
|
|
|
r << ", ";
|
|
|
|
}
|
|
|
|
r << a->name;
|
|
|
|
}
|
|
|
|
r << ");\n";
|
|
|
|
if (f.type.isComplex()) {
|
|
|
|
r << " let s: *const c_char = r.as_ptr() as (*const c_char);\n";
|
|
|
|
r << " set(d, s, r.len() as i32);\n";
|
2018-05-16 13:38:30 -07:00
|
|
|
} else {
|
2018-05-12 04:58:43 -07:00
|
|
|
r << " r\n";
|
|
|
|
}
|
|
|
|
r << "}\n";
|
|
|
|
}
|
|
|
|
|
2017-08-26 10:10:18 -07:00
|
|
|
void writeRustInterfaceObject(QTextStream& r, const Object& o, const Configuration& conf) {
|
2017-08-22 04:45:34 -07:00
|
|
|
const QString lcname(snakeCase(o.name));
|
|
|
|
r << QString(R"(
|
|
|
|
pub struct %1QObject {}
|
|
|
|
|
2017-08-29 11:37:51 -07:00
|
|
|
#[derive(Clone)]
|
2017-08-22 04:45:34 -07:00
|
|
|
pub struct %1Emitter {
|
|
|
|
qobject: Arc<Mutex<*const %1QObject>>,
|
|
|
|
)").arg(o.name);
|
|
|
|
for (const Property& p: o.properties) {
|
2017-08-26 10:10:18 -07:00
|
|
|
if (p.type.type == BindingType::Object) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
r << QString(" %2_changed: fn(*const %1QObject),\n")
|
|
|
|
.arg(o.name, snakeCase(p.name));
|
|
|
|
}
|
|
|
|
if (o.type == ObjectType::List) {
|
|
|
|
r << QString(" new_data_ready: fn(*const %1QObject),\n")
|
|
|
|
.arg(o.name);
|
2017-09-03 06:13:11 -07:00
|
|
|
} else if (o.type == ObjectType::Tree) {
|
2018-09-08 11:47:48 -07:00
|
|
|
r << QString(" new_data_ready: fn(*const %1QObject, index: COption<usize>),\n")
|
2017-08-22 04:45:34 -07:00
|
|
|
.arg(o.name);
|
|
|
|
}
|
|
|
|
r << QString(R"(}
|
|
|
|
|
|
|
|
unsafe impl Send for %1Emitter {}
|
|
|
|
|
|
|
|
impl %1Emitter {
|
|
|
|
fn clear(&self) {
|
|
|
|
*self.qobject.lock().unwrap() = null();
|
|
|
|
}
|
|
|
|
)").arg(o.name);
|
|
|
|
for (const Property& p: o.properties) {
|
2017-08-26 10:10:18 -07:00
|
|
|
if (p.type.type == BindingType::Object) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
r << QString(R"( pub fn %1_changed(&self) {
|
|
|
|
let ptr = *self.qobject.lock().unwrap();
|
|
|
|
if !ptr.is_null() {
|
|
|
|
(self.%1_changed)(ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)").arg(snakeCase(p.name));
|
|
|
|
}
|
|
|
|
if (o.type == ObjectType::List) {
|
|
|
|
r << R"( pub fn new_data_ready(&self) {
|
|
|
|
let ptr = *self.qobject.lock().unwrap();
|
|
|
|
if !ptr.is_null() {
|
|
|
|
(self.new_data_ready)(ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)";
|
2017-09-03 06:13:11 -07:00
|
|
|
} else if (o.type == ObjectType::Tree) {
|
2017-08-22 10:17:35 -07:00
|
|
|
r << R"( pub fn new_data_ready(&self, item: Option<usize>) {
|
2017-08-22 04:45:34 -07:00
|
|
|
let ptr = *self.qobject.lock().unwrap();
|
|
|
|
if !ptr.is_null() {
|
2018-09-08 11:47:48 -07:00
|
|
|
(self.new_data_ready)(ptr, item.into());
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
}
|
|
|
|
|
|
|
|
QString modelStruct = "";
|
|
|
|
if (o.type != ObjectType::Object) {
|
2017-09-03 06:13:11 -07:00
|
|
|
QString type = o.type == ObjectType::List ? "List" : "Tree";
|
2017-08-22 04:45:34 -07:00
|
|
|
modelStruct = ", model: " + o.name + type;
|
|
|
|
QString index;
|
|
|
|
QString indexDecl;
|
2017-08-22 10:17:35 -07:00
|
|
|
QString indexCDecl;
|
2018-09-08 12:54:34 -07:00
|
|
|
QString dest;
|
|
|
|
QString destDecl;
|
|
|
|
QString destCDecl;
|
2017-09-03 06:13:11 -07:00
|
|
|
if (o.type == ObjectType::Tree) {
|
2018-06-08 05:21:35 -07:00
|
|
|
indexDecl = " index: Option<usize>,";
|
2018-09-08 11:47:48 -07:00
|
|
|
indexCDecl = " index: COption<usize>,";
|
|
|
|
index = " index.into(),";
|
2018-09-08 12:54:34 -07:00
|
|
|
destDecl = " dest: Option<usize>,";
|
|
|
|
destCDecl = " dest: COption<usize>,";
|
|
|
|
dest = " dest.into(),";
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
r << QString(R"(}
|
|
|
|
|
2018-09-08 14:13:20 -07:00
|
|
|
#[derive(Clone)]
|
2017-08-22 04:45:34 -07:00
|
|
|
pub struct %1%2 {
|
|
|
|
qobject: *const %1QObject,
|
2018-09-08 13:48:59 -07:00
|
|
|
layout_about_to_be_changed: fn(*const %1QObject),
|
|
|
|
layout_changed: fn(*const %1QObject),
|
2017-08-28 12:17:06 -07:00
|
|
|
data_changed: fn(*const %1QObject, usize, usize),
|
2017-08-22 04:45:34 -07:00
|
|
|
begin_reset_model: fn(*const %1QObject),
|
|
|
|
end_reset_model: fn(*const %1QObject),
|
2017-08-22 10:17:35 -07:00
|
|
|
begin_insert_rows: fn(*const %1QObject,%5 usize, usize),
|
2017-08-22 04:45:34 -07:00
|
|
|
end_insert_rows: fn(*const %1QObject),
|
2018-09-08 12:54:34 -07:00
|
|
|
begin_move_rows: fn(*const %1QObject,%5 usize, usize,%8 usize),
|
|
|
|
end_move_rows: fn(*const %1QObject),
|
2017-08-22 10:17:35 -07:00
|
|
|
begin_remove_rows: fn(*const %1QObject,%5 usize, usize),
|
2017-08-22 04:45:34 -07:00
|
|
|
end_remove_rows: fn(*const %1QObject),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl %1%2 {
|
2018-09-08 13:48:59 -07:00
|
|
|
pub fn layout_about_to_be_changed(&self) {
|
|
|
|
(self.layout_about_to_be_changed)(self.qobject);
|
|
|
|
}
|
|
|
|
pub fn layout_changed(&self) {
|
|
|
|
(self.layout_changed)(self.qobject);
|
|
|
|
}
|
2017-08-28 12:38:57 -07:00
|
|
|
pub fn data_changed(&self, first: usize, last: usize) {
|
2017-08-28 12:17:06 -07:00
|
|
|
(self.data_changed)(self.qobject, first, last);
|
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
pub fn begin_reset_model(&self) {
|
|
|
|
(self.begin_reset_model)(self.qobject);
|
|
|
|
}
|
|
|
|
pub fn end_reset_model(&self) {
|
|
|
|
(self.end_reset_model)(self.qobject);
|
|
|
|
}
|
|
|
|
pub fn begin_insert_rows(&self,%3 first: usize, last: usize) {
|
|
|
|
(self.begin_insert_rows)(self.qobject,%4 first, last);
|
|
|
|
}
|
|
|
|
pub fn end_insert_rows(&self) {
|
|
|
|
(self.end_insert_rows)(self.qobject);
|
|
|
|
}
|
2018-09-08 12:54:34 -07:00
|
|
|
pub fn begin_move_rows(&self,%3 first: usize, last: usize,%6 destination: usize) {
|
|
|
|
(self.begin_move_rows)(self.qobject,%4 first, last,%7 destination);
|
|
|
|
}
|
|
|
|
pub fn end_move_rows(&self) {
|
|
|
|
(self.end_move_rows)(self.qobject);
|
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
pub fn begin_remove_rows(&self,%3 first: usize, last: usize) {
|
|
|
|
(self.begin_remove_rows)(self.qobject,%4 first, last);
|
|
|
|
}
|
|
|
|
pub fn end_remove_rows(&self) {
|
|
|
|
(self.end_remove_rows)(self.qobject);
|
|
|
|
}
|
2018-09-08 12:54:34 -07:00
|
|
|
)").arg(o.name, type, indexDecl, index, indexCDecl, destDecl, dest, destCDecl);
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
r << QString(R"(}
|
|
|
|
|
|
|
|
pub trait %1Trait {
|
2017-09-03 08:32:46 -07:00
|
|
|
fn new(emit: %1Emitter%2)").arg(o.name, modelStruct);
|
2017-08-26 10:10:18 -07:00
|
|
|
for (const Property& p: o.properties) {
|
|
|
|
if (p.type.type == BindingType::Object) {
|
|
|
|
r << ",\n " << snakeCase(p.name) << ": " << p.type.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r << QString(R"() -> Self;
|
2017-08-22 04:45:34 -07:00
|
|
|
fn emit(&self) -> &%1Emitter;
|
2017-08-26 10:10:18 -07:00
|
|
|
)").arg(o.name);
|
2017-08-22 04:45:34 -07:00
|
|
|
for (const Property& p: o.properties) {
|
|
|
|
const QString lc(snakeCase(p.name));
|
2017-08-26 10:10:18 -07:00
|
|
|
if (p.type.type == BindingType::Object) {
|
2017-08-31 00:01:14 -07:00
|
|
|
r << QString(" fn %1(&self) -> &%2;\n").arg(lc, rustType(p));
|
2017-08-31 00:02:56 -07:00
|
|
|
r << QString(" fn %1_mut(&mut self) -> &mut %2;\n").arg(lc, rustType(p));
|
2017-08-26 10:10:18 -07:00
|
|
|
} else {
|
2018-08-26 10:47:25 -07:00
|
|
|
if (p.rustByFunction) {
|
|
|
|
r << QString(" fn %1<F>(&self, getter: F) where F: FnOnce(%2);").arg(lc, rustReturnType(p));
|
|
|
|
} else {
|
|
|
|
r << QString(" fn %1(&self) -> %2;\n").arg(lc, rustReturnType(p));
|
|
|
|
}
|
2017-08-26 10:10:18 -07:00
|
|
|
if (p.write) {
|
2018-05-16 00:12:03 -07:00
|
|
|
if (p.type.name == "QByteArray") {
|
|
|
|
if (p.optional) {
|
|
|
|
r << QString(" fn set_%1(&mut self, value: Option<&[u8]>);\n").arg(lc);
|
|
|
|
} else {
|
|
|
|
r << QString(" fn set_%1(&mut self, value: &[u8]);\n").arg(lc);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r << QString(" fn set_%1(&mut self, value: %2);\n").arg(lc, rustType(p));
|
|
|
|
}
|
2017-08-26 10:10:18 -07:00
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
}
|
2017-10-14 16:56:03 -07:00
|
|
|
for (const Function& f: o.functions) {
|
|
|
|
const QString lc(snakeCase(f.name));
|
|
|
|
QString argList;
|
|
|
|
if (f.args.size() > 0) {
|
|
|
|
for (auto a = f.args.begin(); a < f.args.end(); a++) {
|
2018-05-16 13:38:30 -07:00
|
|
|
auto t = a->type.name == "QByteArray" ?"&[u8]" :a->type.rustType;
|
|
|
|
argList.append(QString(", %1: %2").arg(a->name, t));
|
2017-10-14 16:56:03 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
r << QString(" fn %1(&%2self%4) -> %3;\n")
|
|
|
|
.arg(lc, f.mut ? "mut " : "", f.type.rustType, argList);
|
|
|
|
}
|
2017-08-22 10:17:35 -07:00
|
|
|
if (o.type == ObjectType::List) {
|
|
|
|
r << R"( fn row_count(&self) -> usize;
|
2018-05-15 12:45:05 -07:00
|
|
|
fn insert_rows(&mut self, _row: usize, _count: usize) -> bool { false }
|
|
|
|
fn remove_rows(&mut self, _row: usize, _count: usize) -> bool { false }
|
2017-08-29 11:37:51 -07:00
|
|
|
fn can_fetch_more(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
2017-08-22 10:17:35 -07:00
|
|
|
fn fetch_more(&mut self) {}
|
|
|
|
fn sort(&mut self, u8, SortOrder) {}
|
|
|
|
)";
|
2017-09-03 06:13:11 -07:00
|
|
|
} else if (o.type == ObjectType::Tree) {
|
2017-08-22 10:17:35 -07:00
|
|
|
r << R"( fn row_count(&self, Option<usize>) -> usize;
|
2017-08-29 11:37:51 -07:00
|
|
|
fn can_fetch_more(&self, Option<usize>) -> bool {
|
|
|
|
false
|
|
|
|
}
|
2017-08-22 10:17:35 -07:00
|
|
|
fn fetch_more(&mut self, Option<usize>) {}
|
2017-08-22 04:45:34 -07:00
|
|
|
fn sort(&mut self, u8, SortOrder) {}
|
2018-09-11 14:06:52 -07:00
|
|
|
fn check_row(&self, index: usize, row: usize) -> Option<usize>;
|
2017-08-22 10:17:35 -07:00
|
|
|
fn index(&self, item: Option<usize>, row: usize) -> usize;
|
2018-06-08 05:21:35 -07:00
|
|
|
fn parent(&self, index: usize) -> Option<usize>;
|
|
|
|
fn row(&self, index: usize) -> usize;
|
2017-08-22 10:17:35 -07:00
|
|
|
)";
|
|
|
|
}
|
|
|
|
if (o.type != ObjectType::Object) {
|
2017-08-22 04:45:34 -07:00
|
|
|
for (auto ip: o.itemProperties) {
|
2018-06-08 05:21:35 -07:00
|
|
|
r << QString(" fn %1(&self, index: usize) -> %2;\n")
|
2017-08-30 12:58:01 -07:00
|
|
|
.arg(snakeCase(ip.name), rustReturnType(ip));
|
2017-08-22 04:45:34 -07:00
|
|
|
if (ip.write) {
|
2018-05-16 00:12:03 -07:00
|
|
|
if (ip.type.name == "QByteArray") {
|
|
|
|
if (ip.optional) {
|
2018-06-08 05:21:35 -07:00
|
|
|
r << QString(" fn set_%1(&mut self, index: usize, Option<&[u8]>) -> bool;\n")
|
2018-05-16 00:12:03 -07:00
|
|
|
.arg(snakeCase(ip.name));
|
|
|
|
} else {
|
2018-06-08 05:21:35 -07:00
|
|
|
r << QString(" fn set_%1(&mut self, index: usize, &[u8]) -> bool;\n")
|
2018-05-16 00:12:03 -07:00
|
|
|
.arg(snakeCase(ip.name));
|
|
|
|
}
|
|
|
|
} else {
|
2018-06-08 05:21:35 -07:00
|
|
|
r << QString(" fn set_%1(&mut self, index: usize, %2) -> bool;\n")
|
2018-05-16 00:12:03 -07:00
|
|
|
.arg(snakeCase(ip.name), rustType(ip));
|
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r << QString(R"(}
|
|
|
|
|
|
|
|
#[no_mangle]
|
2017-08-29 11:37:51 -07:00
|
|
|
pub extern "C" fn %1_new(
|
|
|
|
)").arg(lcname);
|
2017-08-26 10:10:18 -07:00
|
|
|
rConstructorArgsDecl(r, lcname, o, conf);
|
2017-08-29 11:37:51 -07:00
|
|
|
r << QString(",\n) -> *mut %1 {\n").arg(o.name);
|
2017-08-26 10:10:18 -07:00
|
|
|
rConstructorArgs(r, lcname, o, conf);
|
|
|
|
r << QString(R"( Box::into_raw(Box::new(d_%2))
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn %2_free(ptr: *mut %1) {
|
|
|
|
Box::from_raw(ptr).emit().clear();
|
|
|
|
}
|
2017-08-26 10:10:18 -07:00
|
|
|
)").arg(o.name, lcname);
|
2017-08-22 04:45:34 -07:00
|
|
|
for (const Property& p: o.properties) {
|
|
|
|
const QString base = QString("%1_%2").arg(lcname, snakeCase(p.name));
|
|
|
|
QString ret = ") -> " + rustType(p);
|
2017-08-26 10:10:18 -07:00
|
|
|
if (p.type.type == BindingType::Object) {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn %2_get(ptr: *mut %1) -> *mut %4 {
|
2017-08-31 00:02:56 -07:00
|
|
|
(&mut *ptr).%3_mut()
|
2017-08-26 10:10:18 -07:00
|
|
|
}
|
|
|
|
)").arg(o.name, base, snakeCase(p.name), rustType(p));
|
|
|
|
|
|
|
|
} else if (p.type.isComplex() && !p.optional) {
|
2018-08-26 10:47:25 -07:00
|
|
|
if (p.rustByFunction) {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_get(
|
2018-08-26 10:47:25 -07:00
|
|
|
ptr: *const %1,
|
|
|
|
p: *mut %4,
|
|
|
|
set: fn(*mut %4, *const c_char, c_int),
|
|
|
|
) {
|
2018-09-11 14:29:06 -07:00
|
|
|
let o = &*ptr;
|
2018-08-26 10:47:25 -07:00
|
|
|
o.%3(|v| {
|
|
|
|
let s: *const c_char = v.as_ptr() as (*const c_char);
|
|
|
|
set(p, s, to_c_int(v.len()));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
)").arg(o.name, base, snakeCase(p.name), p.type.name);
|
|
|
|
} else {
|
|
|
|
r << QString(R"(
|
2017-08-22 04:45:34 -07:00
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_get(
|
2017-08-29 11:37:51 -07:00
|
|
|
ptr: *const %1,
|
2018-05-16 00:12:03 -07:00
|
|
|
p: *mut %4,
|
|
|
|
set: fn(*mut %4, *const c_char, c_int),
|
2017-08-29 11:37:51 -07:00
|
|
|
) {
|
2018-09-11 14:29:06 -07:00
|
|
|
let o = &*ptr;
|
2018-05-01 14:46:17 -07:00
|
|
|
let v = o.%3();
|
|
|
|
let s: *const c_char = v.as_ptr() as (*const c_char);
|
2018-05-18 00:36:05 -07:00
|
|
|
set(p, s, to_c_int(v.len()));
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
2018-05-16 00:12:03 -07:00
|
|
|
)").arg(o.name, base, snakeCase(p.name), p.type.name);
|
2018-08-26 10:47:25 -07:00
|
|
|
}
|
2018-05-01 16:23:06 -07:00
|
|
|
if (p.write && p.type.name == "QString") {
|
2017-08-22 04:45:34 -07:00
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: *const c_ushort, len: c_int) {
|
|
|
|
let o = &mut *ptr;
|
2018-05-01 14:46:17 -07:00
|
|
|
let mut s = String::new();
|
|
|
|
set_string_from_utf16(&mut s, v, len);
|
|
|
|
o.set_%3(s);
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
2018-05-01 16:23:06 -07:00
|
|
|
)").arg(o.name, base, snakeCase(p.name));
|
|
|
|
} else if (p.write) {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: *const c_char, len: c_int) {
|
|
|
|
let o = &mut *ptr;
|
|
|
|
let v = slice::from_raw_parts(v as *const u8, to_usize(len));
|
2018-05-16 00:12:03 -07:00
|
|
|
o.set_%3(v);
|
2018-05-01 16:23:06 -07:00
|
|
|
}
|
|
|
|
)").arg(o.name, base, snakeCase(p.name));
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
} else if (p.type.isComplex()) {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_get(
|
2017-08-29 11:37:51 -07:00
|
|
|
ptr: *const %1,
|
2018-05-16 00:12:03 -07:00
|
|
|
p: *mut %4,
|
|
|
|
set: fn(*mut %4, *const c_char, c_int),
|
2017-08-29 11:37:51 -07:00
|
|
|
) {
|
2018-09-11 14:29:06 -07:00
|
|
|
let o = &*ptr;
|
2018-05-01 16:23:06 -07:00
|
|
|
let v = o.%3();
|
|
|
|
if let Some(v) = v {
|
|
|
|
let s: *const c_char = v.as_ptr() as (*const c_char);
|
2018-05-18 00:36:05 -07:00
|
|
|
set(p, s, to_c_int(v.len()));
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
}
|
2018-05-16 00:12:03 -07:00
|
|
|
)").arg(o.name, base, snakeCase(p.name), p.type.name);
|
2018-05-01 16:23:06 -07:00
|
|
|
if (p.write && p.type.name == "QString") {
|
2017-08-22 04:45:34 -07:00
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: *const c_ushort, len: c_int) {
|
|
|
|
let o = &mut *ptr;
|
2018-05-01 16:23:06 -07:00
|
|
|
let mut s = String::new();
|
|
|
|
set_string_from_utf16(&mut s, v, len);
|
|
|
|
o.set_%3(Some(s));
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
2018-05-01 16:23:06 -07:00
|
|
|
)").arg(o.name, base, snakeCase(p.name));
|
|
|
|
} else if (p.write) {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: *const c_char, len: c_int) {
|
|
|
|
let o = &mut *ptr;
|
|
|
|
let v = slice::from_raw_parts(v as *const u8, to_usize(len));
|
2018-05-01 16:23:06 -07:00
|
|
|
o.set_%3(Some(v.into()));
|
|
|
|
}
|
2018-05-15 12:45:05 -07:00
|
|
|
)").arg(o.name, base, snakeCase(p.name));
|
|
|
|
}
|
|
|
|
} else if (p.optional) {
|
|
|
|
r << QString(R"(
|
2018-05-01 16:23:06 -07:00
|
|
|
#[no_mangle]
|
2018-05-15 12:45:05 -07:00
|
|
|
pub unsafe extern "C" fn %2_get(ptr: *const %1) -> COption<%4> {
|
|
|
|
match (&*ptr).%3() {
|
|
|
|
Some(value) => COption { data: value, some: true },
|
|
|
|
None => COption { data: %4::default(), some: false}
|
|
|
|
}
|
2018-05-01 16:23:06 -07:00
|
|
|
}
|
2018-05-15 12:45:05 -07:00
|
|
|
)").arg(o.name, base, snakeCase(p.name), p.type.rustType);
|
|
|
|
if (p.write) {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: %4) {
|
|
|
|
(&mut *ptr).set_%3(Some(v));
|
|
|
|
}
|
|
|
|
)").arg(o.name, base, snakeCase(p.name), p.type.rustType);
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn %2_get(ptr: *const %1) -> %4 {
|
2017-08-31 00:01:14 -07:00
|
|
|
(&*ptr).%3()
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
)").arg(o.name, base, snakeCase(p.name), rustType(p));
|
|
|
|
if (p.write) {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: %4) {
|
|
|
|
(&mut *ptr).set_%3(v);
|
|
|
|
}
|
|
|
|
)").arg(o.name, base, snakeCase(p.name), rustType(p));
|
|
|
|
}
|
|
|
|
}
|
2018-05-15 12:45:05 -07:00
|
|
|
if (p.write && p.optional) {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_set_none(ptr: *mut %1) {
|
|
|
|
let o = &mut *ptr;
|
2018-05-15 12:45:05 -07:00
|
|
|
o.set_%3(None);
|
|
|
|
}
|
|
|
|
)").arg(o.name, base, snakeCase(p.name));
|
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
2017-10-14 16:56:03 -07:00
|
|
|
for (const Function& f: o.functions) {
|
2018-05-12 04:58:43 -07:00
|
|
|
writeFunction(r, f, lcname, o);
|
2017-10-14 16:56:03 -07:00
|
|
|
}
|
2017-08-22 10:17:35 -07:00
|
|
|
if (o.type == ObjectType::List) {
|
2017-08-22 04:45:34 -07:00
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2017-08-22 10:17:35 -07:00
|
|
|
pub unsafe extern "C" fn %2_row_count(ptr: *const %1) -> c_int {
|
2018-05-18 00:36:05 -07:00
|
|
|
to_c_int((&*ptr).row_count())
|
2017-08-22 10:17:35 -07:00
|
|
|
}
|
|
|
|
#[no_mangle]
|
2017-10-02 15:34:44 -07:00
|
|
|
pub unsafe extern "C" fn %2_insert_rows(ptr: *mut %1, row: c_int, count: c_int) -> bool {
|
2018-05-18 00:36:05 -07:00
|
|
|
(&mut *ptr).insert_rows(to_usize(row), to_usize(count))
|
2017-10-03 11:22:44 -07:00
|
|
|
}
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn %2_remove_rows(ptr: *mut %1, row: c_int, count: c_int) -> bool {
|
2018-05-18 00:36:05 -07:00
|
|
|
(&mut *ptr).remove_rows(to_usize(row), to_usize(count))
|
2017-10-02 15:34:44 -07:00
|
|
|
}
|
|
|
|
#[no_mangle]
|
2017-08-22 10:17:35 -07:00
|
|
|
pub unsafe extern "C" fn %2_can_fetch_more(ptr: *const %1) -> bool {
|
|
|
|
(&*ptr).can_fetch_more()
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
#[no_mangle]
|
2017-08-22 10:17:35 -07:00
|
|
|
pub unsafe extern "C" fn %2_fetch_more(ptr: *mut %1) {
|
|
|
|
(&mut *ptr).fetch_more()
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
#[no_mangle]
|
2017-08-29 11:37:51 -07:00
|
|
|
pub unsafe extern "C" fn %2_sort(
|
|
|
|
ptr: *mut %1,
|
|
|
|
column: u8,
|
|
|
|
order: SortOrder,
|
|
|
|
) {
|
2017-08-22 10:17:35 -07:00
|
|
|
(&mut *ptr).sort(column, order)
|
|
|
|
}
|
|
|
|
)").arg(o.name, lcname);
|
2017-09-03 06:13:11 -07:00
|
|
|
} else if (o.type == ObjectType::Tree) {
|
2017-08-22 10:17:35 -07:00
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2017-08-29 11:37:51 -07:00
|
|
|
pub unsafe extern "C" fn %2_row_count(
|
|
|
|
ptr: *const %1,
|
2018-09-08 11:47:48 -07:00
|
|
|
index: COption<usize>,
|
2017-08-29 11:37:51 -07:00
|
|
|
) -> c_int {
|
2018-09-08 11:47:48 -07:00
|
|
|
to_c_int((&*ptr).row_count(index.into()))
|
2017-08-22 10:17:35 -07:00
|
|
|
}
|
|
|
|
#[no_mangle]
|
2017-08-29 11:37:51 -07:00
|
|
|
pub unsafe extern "C" fn %2_can_fetch_more(
|
|
|
|
ptr: *const %1,
|
2018-09-08 11:47:48 -07:00
|
|
|
index: COption<usize>,
|
2017-08-29 11:37:51 -07:00
|
|
|
) -> bool {
|
2018-09-08 11:47:48 -07:00
|
|
|
(&*ptr).can_fetch_more(index.into())
|
2017-08-22 10:17:35 -07:00
|
|
|
}
|
|
|
|
#[no_mangle]
|
2018-09-08 11:47:48 -07:00
|
|
|
pub unsafe extern "C" fn %2_fetch_more(ptr: *mut %1, index: COption<usize>) {
|
|
|
|
(&mut *ptr).fetch_more(index.into())
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
#[no_mangle]
|
2017-08-29 11:37:51 -07:00
|
|
|
pub unsafe extern "C" fn %2_sort(
|
|
|
|
ptr: *mut %1,
|
|
|
|
column: u8,
|
|
|
|
order: SortOrder
|
|
|
|
) {
|
2017-08-22 04:45:34 -07:00
|
|
|
(&mut *ptr).sort(column, order)
|
|
|
|
}
|
2017-08-22 10:17:35 -07:00
|
|
|
#[no_mangle]
|
2018-09-11 14:06:52 -07:00
|
|
|
pub unsafe extern "C" fn %2_check_row(
|
|
|
|
ptr: *const %1,
|
|
|
|
index: usize,
|
|
|
|
row: c_int,
|
|
|
|
) -> COption<usize> {
|
|
|
|
(&*ptr).check_row(index.into(), to_usize(row)).into()
|
|
|
|
}
|
|
|
|
#[no_mangle]
|
2017-08-29 11:37:51 -07:00
|
|
|
pub unsafe extern "C" fn %2_index(
|
|
|
|
ptr: *const %1,
|
2018-09-08 11:47:48 -07:00
|
|
|
index: COption<usize>,
|
2017-08-29 11:37:51 -07:00
|
|
|
row: c_int,
|
|
|
|
) -> usize {
|
2018-09-08 11:47:48 -07:00
|
|
|
(&*ptr).index(index.into(), to_usize(row))
|
2017-08-22 10:17:35 -07:00
|
|
|
}
|
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern "C" fn %2_parent(ptr: *const %1, index: usize) -> QModelIndex {
|
|
|
|
if let Some(parent) = (&*ptr).parent(index) {
|
2017-08-29 11:37:51 -07:00
|
|
|
QModelIndex {
|
2018-05-18 00:36:05 -07:00
|
|
|
row: to_c_int((&*ptr).row(parent)),
|
2017-08-29 11:37:51 -07:00
|
|
|
internal_id: parent,
|
|
|
|
}
|
2017-08-22 10:17:35 -07:00
|
|
|
} else {
|
2017-08-29 11:37:51 -07:00
|
|
|
QModelIndex {
|
|
|
|
row: -1,
|
|
|
|
internal_id: 0,
|
|
|
|
}
|
2017-08-22 10:17:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#[no_mangle]
|
2018-06-08 05:21:35 -07:00
|
|
|
pub unsafe extern "C" fn %2_row(ptr: *const %1, index: usize) -> c_int {
|
|
|
|
to_c_int((&*ptr).row(index))
|
2017-08-22 10:17:35 -07:00
|
|
|
}
|
|
|
|
)").arg(o.name, lcname);
|
|
|
|
}
|
|
|
|
if (o.type != ObjectType::Object) {
|
|
|
|
QString indexDecl = ", row: c_int";
|
2018-05-18 00:36:05 -07:00
|
|
|
QString index = "to_usize(row)";
|
2017-09-03 06:13:11 -07:00
|
|
|
if (o.type == ObjectType::Tree) {
|
2018-06-08 05:21:35 -07:00
|
|
|
indexDecl = ", index: usize";
|
|
|
|
index = "index";
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
for (auto ip: o.itemProperties) {
|
|
|
|
if (ip.type.isComplex() && !ip.optional) {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_data_%3(
|
2018-05-16 00:12:03 -07:00
|
|
|
ptr: *const %1%4,
|
|
|
|
d: *mut %6,
|
|
|
|
set: fn(*mut %6, *const c_char, len: c_int),
|
2017-08-29 11:37:51 -07:00
|
|
|
) {
|
2018-09-11 14:29:06 -07:00
|
|
|
let o = &*ptr;
|
2018-05-16 00:12:03 -07:00
|
|
|
let data = o.%3(%5);
|
2018-05-02 08:02:07 -07:00
|
|
|
let s: *const c_char = data.as_ptr() as (*const c_char);
|
2018-05-18 00:36:05 -07:00
|
|
|
set(d, s, to_c_int(data.len()));
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
2018-05-16 00:12:03 -07:00
|
|
|
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index, ip.type.name);
|
2018-05-15 08:08:58 -07:00
|
|
|
} else if (ip.type.isComplex()) {
|
2017-08-22 04:45:34 -07:00
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_data_%3(
|
2018-05-02 13:18:37 -07:00
|
|
|
ptr: *const %1%4,
|
2018-05-16 00:12:03 -07:00
|
|
|
d: *mut %6,
|
|
|
|
set: fn(*mut %6, *const c_char, len: c_int),
|
2017-08-29 11:37:51 -07:00
|
|
|
) {
|
2018-09-11 14:29:06 -07:00
|
|
|
let o = &*ptr;
|
2018-05-02 13:18:37 -07:00
|
|
|
let data = o.%3(%5);
|
2017-08-22 04:45:34 -07:00
|
|
|
if let Some(data) = data {
|
2018-05-02 08:02:07 -07:00
|
|
|
let s: *const c_char = data.as_ptr() as (*const c_char);
|
2018-05-18 00:36:05 -07:00
|
|
|
set(d, s, to_c_int(data.len()));
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
}
|
2018-05-16 00:12:03 -07:00
|
|
|
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index, ip.type.name);
|
2017-08-22 04:45:34 -07:00
|
|
|
} else {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_data_%3(ptr: *const %1%5) -> %4 {
|
|
|
|
let o = &*ptr;
|
2018-05-02 08:02:07 -07:00
|
|
|
o.%3(%6).into()
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
)").arg(o.name, lcname, snakeCase(ip.name), rustCType(ip), indexDecl, index);
|
|
|
|
}
|
|
|
|
if (ip.write) {
|
|
|
|
QString val = "v";
|
|
|
|
if (ip.optional) {
|
|
|
|
val = "Some(" + val + ")";
|
|
|
|
}
|
2018-05-02 08:02:07 -07:00
|
|
|
if (ip.type.name == "QString") {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_set_data_%3(
|
2018-05-02 08:02:07 -07:00
|
|
|
ptr: *mut %1%4,
|
|
|
|
s: *const c_ushort, len: c_int,
|
|
|
|
) -> bool {
|
2018-09-11 14:29:06 -07:00
|
|
|
let o = &mut *ptr;
|
2018-05-02 08:02:07 -07:00
|
|
|
let mut v = String::new();
|
|
|
|
set_string_from_utf16(&mut v, s, len);
|
|
|
|
o.set_%3(%5, %6)
|
|
|
|
}
|
|
|
|
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index, val);
|
|
|
|
} else if (ip.type.name == "QByteArray") {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-09-11 14:29:06 -07:00
|
|
|
pub unsafe extern "C" fn %2_set_data_%3(
|
2018-05-02 08:02:07 -07:00
|
|
|
ptr: *mut %1%4,
|
|
|
|
s: *const c_char, len: c_int,
|
|
|
|
) -> bool {
|
2018-09-11 14:29:06 -07:00
|
|
|
let o = &mut *ptr;
|
|
|
|
let slice = ::std::slice::from_raw_parts(s as *const u8, to_usize(len));
|
2018-05-02 08:02:07 -07:00
|
|
|
o.set_%3(%5, %6)
|
|
|
|
}
|
2018-05-16 00:12:03 -07:00
|
|
|
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index, ip.optional ?"Some(slice)" :"slice");
|
2018-05-02 08:02:07 -07:00
|
|
|
} else {
|
|
|
|
const QString type = ip.type.rustType;
|
|
|
|
r << QString(R"(
|
2017-08-22 04:45:34 -07:00
|
|
|
#[no_mangle]
|
2017-08-29 11:37:51 -07:00
|
|
|
pub unsafe extern "C" fn %2_set_data_%3(
|
|
|
|
ptr: *mut %1%4,
|
|
|
|
v: %6,
|
|
|
|
) -> bool {
|
2017-08-22 04:45:34 -07:00
|
|
|
(&mut *ptr).set_%3(%5, %7)
|
|
|
|
}
|
|
|
|
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index, type, val);
|
2018-05-02 08:02:07 -07:00
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
if (ip.write && ip.optional) {
|
|
|
|
r << QString(R"(
|
|
|
|
#[no_mangle]
|
2018-05-15 08:08:58 -07:00
|
|
|
pub unsafe extern "C" fn %2_set_data_%3_none(ptr: *mut %1%4) -> bool {
|
|
|
|
(&mut *ptr).set_%3(%5, None)
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString rustFile(const QDir rustdir, const QString& module) {
|
|
|
|
QDir src(rustdir.absoluteFilePath("src"));
|
2017-08-31 10:20:25 -07:00
|
|
|
QString modulePath = src.absoluteFilePath(module + "/mod.rs");
|
|
|
|
if (QFile::exists(modulePath)) {
|
|
|
|
return modulePath;
|
|
|
|
}
|
|
|
|
return src.absoluteFilePath(module + ".rs");
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
|
2017-08-25 06:42:56 -07:00
|
|
|
void writeRustTypes(const Configuration& conf, QTextStream& r) {
|
|
|
|
bool hasOption = false;
|
|
|
|
bool hasString = 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;
|
|
|
|
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;
|
|
|
|
}
|
2018-08-05 10:51:38 -07:00
|
|
|
for (auto f: o.functions) {
|
|
|
|
hasString |= f.type.type == BindingType::QString;
|
|
|
|
hasByteArray |= f.type.type == BindingType::QByteArray;
|
|
|
|
for (auto a: f.args) {
|
|
|
|
hasString |= a.type.type == BindingType::QString;
|
|
|
|
hasByteArray |= a.type.type == BindingType::QByteArray;
|
|
|
|
}
|
|
|
|
}
|
2017-08-25 06:42:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hasOption || hasListOrTree) {
|
|
|
|
r << R"(
|
2017-08-25 06:10:07 -07:00
|
|
|
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct COption<T> {
|
|
|
|
data: T,
|
|
|
|
some: bool,
|
|
|
|
}
|
|
|
|
|
2018-09-08 11:47:48 -07:00
|
|
|
impl<T> COption<T> {
|
|
|
|
#![allow(dead_code)]
|
|
|
|
fn into(self) -> Option<T> {
|
|
|
|
if self.some {
|
|
|
|
Some(self.data)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-29 11:37:51 -07:00
|
|
|
impl<T> From<Option<T>> for COption<T>
|
|
|
|
where
|
|
|
|
T: Default,
|
|
|
|
{
|
|
|
|
fn from(t: Option<T>) -> COption<T> {
|
2017-08-25 06:10:07 -07:00
|
|
|
if let Some(v) = t {
|
|
|
|
COption {
|
|
|
|
data: v,
|
2017-08-29 11:37:51 -07:00
|
|
|
some: true,
|
2017-08-25 06:10:07 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
COption {
|
|
|
|
data: T::default(),
|
2017-08-29 11:37:51 -07:00
|
|
|
some: false,
|
2017-08-25 06:10:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-25 06:42:56 -07:00
|
|
|
)";
|
|
|
|
}
|
|
|
|
if (hasString) {
|
|
|
|
r << R"(
|
2017-08-25 06:10:07 -07:00
|
|
|
|
2018-05-01 14:46:17 -07:00
|
|
|
pub enum QString {}
|
2017-08-25 06:10:07 -07:00
|
|
|
|
2018-05-01 14:46:17 -07:00
|
|
|
fn set_string_from_utf16(s: &mut String, str: *const c_ushort, len: c_int) {
|
2018-05-18 00:36:05 -07:00
|
|
|
let utf16 = unsafe { slice::from_raw_parts(str, to_usize(len)) };
|
2018-05-01 14:46:17 -07:00
|
|
|
let characters = decode_utf16(utf16.iter().cloned())
|
|
|
|
.map(|r| r.unwrap());
|
|
|
|
s.clear();
|
|
|
|
s.extend(characters);
|
2017-08-30 12:58:01 -07:00
|
|
|
}
|
|
|
|
|
2017-08-25 06:42:56 -07:00
|
|
|
)";
|
|
|
|
}
|
|
|
|
if (hasByteArray) {
|
|
|
|
r << R"(
|
2017-08-25 06:10:07 -07:00
|
|
|
|
2018-05-01 16:23:06 -07:00
|
|
|
pub enum QByteArray {}
|
2017-08-25 06:42:56 -07:00
|
|
|
)";
|
2017-08-25 06:10:07 -07:00
|
|
|
}
|
2017-08-25 06:42:56 -07:00
|
|
|
if (hasListOrTree) {
|
|
|
|
r << R"(
|
2017-08-25 06:10:07 -07:00
|
|
|
|
|
|
|
#[repr(C)]
|
2018-06-30 11:23:29 -07:00
|
|
|
#[derive(PartialEq, Eq, Debug)]
|
2017-08-25 06:10:07 -07:00
|
|
|
pub enum SortOrder {
|
|
|
|
Ascending = 0,
|
2017-08-29 11:37:51 -07:00
|
|
|
Descending = 1,
|
2017-08-25 06:10:07 -07:00
|
|
|
}
|
|
|
|
|
2017-08-25 06:42:56 -07:00
|
|
|
#[repr(C)]
|
|
|
|
pub struct QModelIndex {
|
|
|
|
row: c_int,
|
|
|
|
internal_id: usize,
|
|
|
|
}
|
2018-05-18 00:36:05 -07:00
|
|
|
)";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasString || hasByteArray || hasListOrTree) {
|
|
|
|
r << R"(
|
|
|
|
|
|
|
|
fn to_usize(n: c_int) -> usize {
|
|
|
|
if n < 0 {
|
|
|
|
panic!("Cannot cast {} to usize", n);
|
|
|
|
}
|
|
|
|
n as usize
|
|
|
|
}
|
|
|
|
|
|
|
|
)";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasString || hasByteArray || hasListOrTree) {
|
|
|
|
r << R"(
|
|
|
|
fn to_c_int(n: usize) -> c_int {
|
|
|
|
if n > c_int::max_value() as usize {
|
|
|
|
panic!("Cannot cast {} to c_int", n);
|
|
|
|
}
|
|
|
|
n as c_int
|
|
|
|
}
|
|
|
|
|
2017-08-25 06:42:56 -07:00
|
|
|
)";
|
|
|
|
}
|
2017-08-25 06:10:07 -07:00
|
|
|
}
|
|
|
|
|
2017-08-22 04:45:34 -07:00
|
|
|
void writeRustInterface(const Configuration& conf) {
|
|
|
|
DifferentFileWriter w(rustFile(conf.rustdir, conf.interfaceModule));
|
|
|
|
QTextStream r(&w.buffer);
|
|
|
|
r << QString(R"(/* generated by rust_qt_binding_generator */
|
|
|
|
#![allow(unknown_lints)]
|
|
|
|
#![allow(mutex_atomic, needless_pass_by_value)]
|
2018-05-16 00:12:03 -07:00
|
|
|
use libc::{c_char, c_ushort, c_int};
|
2017-08-25 06:10:07 -07:00
|
|
|
use std::slice;
|
2018-05-01 14:46:17 -07:00
|
|
|
use std::char::decode_utf16;
|
2017-08-25 06:10:07 -07:00
|
|
|
|
2017-08-22 04:45:34 -07:00
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
use std::ptr::null;
|
|
|
|
|
|
|
|
use %1::*;
|
|
|
|
)").arg(conf.implementationModule);
|
|
|
|
|
2017-08-25 06:42:56 -07:00
|
|
|
writeRustTypes(conf, r);
|
2017-08-25 06:10:07 -07:00
|
|
|
|
2017-08-22 04:45:34 -07:00
|
|
|
for (auto object: conf.objects) {
|
2017-08-26 10:10:18 -07:00
|
|
|
writeRustInterfaceObject(r, object, conf);
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeRustImplementationObject(QTextStream& r, const Object& o) {
|
|
|
|
const QString lcname(snakeCase(o.name));
|
|
|
|
if (o.type != ObjectType::Object) {
|
2017-08-29 11:37:51 -07:00
|
|
|
r << "#[derive(Default, Clone)]\n";
|
2017-08-22 04:45:34 -07:00
|
|
|
r << QString("struct %1Item {\n").arg(o.name);
|
|
|
|
for (auto ip: o.itemProperties) {
|
|
|
|
const QString lc(snakeCase(ip.name));
|
|
|
|
r << QString(" %1: %2,\n").arg(lc, ip.type.rustType);
|
|
|
|
}
|
|
|
|
r << "}\n\n";
|
|
|
|
}
|
|
|
|
QString modelStruct = "";
|
|
|
|
r << QString("pub struct %1 {\n emit: %1Emitter,\n").arg((o.name));
|
|
|
|
if (o.type == ObjectType::List) {
|
|
|
|
modelStruct = ", model: " + o.name + "List";
|
|
|
|
r << QString(" model: %1List,\n").arg(o.name);
|
2017-09-03 06:13:11 -07:00
|
|
|
} else if (o.type == ObjectType::Tree) {
|
|
|
|
modelStruct = ", model: " + o.name + "Tree";
|
|
|
|
r << QString(" model: %1Tree,\n").arg(o.name);
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
for (const Property& p: o.properties) {
|
|
|
|
const QString lc(snakeCase(p.name));
|
|
|
|
r << QString(" %1: %2,\n").arg(lc, rustType(p));
|
|
|
|
}
|
|
|
|
if (o.type != ObjectType::Object) {
|
|
|
|
r << QString(" list: Vec<%1Item>,\n").arg(o.name);
|
|
|
|
}
|
|
|
|
r << "}\n\n";
|
2017-08-26 10:10:18 -07:00
|
|
|
for (const Property& p: o.properties) {
|
|
|
|
if (p.type.type == BindingType::Object) {
|
|
|
|
modelStruct += ", " + p.name + ": " + p.type.name;
|
|
|
|
}
|
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
r << QString(R"(impl %1Trait for %1 {
|
2017-09-03 08:32:46 -07:00
|
|
|
fn new(emit: %1Emitter%2) -> %1 {
|
2017-08-22 04:45:34 -07:00
|
|
|
%1 {
|
|
|
|
emit: emit,
|
|
|
|
)").arg(o.name, modelStruct);
|
|
|
|
if (o.type != ObjectType::Object) {
|
|
|
|
r << QString(" model: model,\n");
|
|
|
|
}
|
|
|
|
for (const Property& p: o.properties) {
|
|
|
|
const QString lc(snakeCase(p.name));
|
2017-08-26 10:10:18 -07:00
|
|
|
if (p.type.type == BindingType::Object) {
|
|
|
|
r << QString(" %1: %1,\n").arg(lc);
|
|
|
|
} else {
|
|
|
|
r << QString(" %1: %2,\n").arg(lc, rustTypeInit(p));
|
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
r << QString(R"( }
|
|
|
|
}
|
|
|
|
fn emit(&self) -> &%1Emitter {
|
|
|
|
&self.emit
|
|
|
|
}
|
|
|
|
)").arg(o.name);
|
|
|
|
for (const Property& p: o.properties) {
|
|
|
|
const QString lc(snakeCase(p.name));
|
2017-08-26 10:10:18 -07:00
|
|
|
if (p.type.type == BindingType::Object) {
|
2017-08-31 00:01:14 -07:00
|
|
|
r << QString(R"( fn %1(&self) -> &%2 {
|
2017-08-26 10:10:18 -07:00
|
|
|
&self.%1
|
|
|
|
}
|
2017-08-31 00:02:56 -07:00
|
|
|
fn %1_mut(&mut self) -> &mut %2 {
|
2017-08-26 10:10:18 -07:00
|
|
|
&mut self.%1
|
|
|
|
}
|
2017-08-30 12:58:01 -07:00
|
|
|
)").arg(lc, rustReturnType(p));
|
2017-08-22 04:45:34 -07:00
|
|
|
} else {
|
2017-08-31 00:01:14 -07:00
|
|
|
r << QString(" fn %1(&self) -> %2 {\n").arg(lc, rustReturnType(p));
|
2017-08-26 10:10:18 -07:00
|
|
|
if (p.type.isComplex()) {
|
2017-08-30 12:58:01 -07:00
|
|
|
if (p.optional) {
|
|
|
|
/*
|
|
|
|
if (rustType(p) == "Option<String>") {
|
|
|
|
r << QString(" self.%1.as_ref().map(|p|p.as_str())\n").arg(lc);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
r << QString(" self.%1.as_ref().map(|p|&p[..])\n").arg(lc);
|
|
|
|
} else {
|
|
|
|
r << QString(" &self.%1\n").arg(lc);
|
|
|
|
}
|
2017-08-26 10:10:18 -07:00
|
|
|
} else {
|
|
|
|
r << QString(" self.%1\n").arg(lc);
|
|
|
|
}
|
|
|
|
r << " }\n";
|
|
|
|
if (p.write) {
|
|
|
|
r << QString(R"( fn set_%1(&mut self, value: %2) {
|
2017-08-22 04:45:34 -07:00
|
|
|
self.%1 = value;
|
|
|
|
self.emit.%1_changed();
|
|
|
|
}
|
2017-08-29 11:37:51 -07:00
|
|
|
)").arg(lc, rustType(p));
|
2017-08-26 10:10:18 -07:00
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
}
|
2017-08-22 10:17:35 -07:00
|
|
|
if (o.type == ObjectType::List) {
|
|
|
|
r << " fn row_count(&self) -> usize {\n self.list.len()\n }\n";
|
2017-09-03 06:13:11 -07:00
|
|
|
} else if (o.type == ObjectType::Tree) {
|
2017-08-22 10:17:35 -07:00
|
|
|
r << R"( fn row_count(&self, item: Option<usize>) -> usize {
|
|
|
|
self.list.len()
|
|
|
|
}
|
|
|
|
fn index(&self, item: Option<usize>, row: usize) -> usize {
|
|
|
|
0
|
|
|
|
}
|
2018-06-08 05:21:35 -07:00
|
|
|
fn parent(&self, index: usize) -> Option<usize> {
|
2017-08-22 10:17:35 -07:00
|
|
|
None
|
|
|
|
}
|
2018-06-08 05:21:35 -07:00
|
|
|
fn row(&self, index: usize) -> usize {
|
2017-08-22 10:17:35 -07:00
|
|
|
item
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
if (o.type != ObjectType::Object) {
|
|
|
|
QString index;
|
2017-09-03 06:13:11 -07:00
|
|
|
if (o.type == ObjectType::Tree) {
|
2018-06-08 05:21:35 -07:00
|
|
|
index = ", index: usize";
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
for (auto ip: o.itemProperties) {
|
|
|
|
const QString lc(snakeCase(ip.name));
|
2018-06-08 05:21:35 -07:00
|
|
|
r << QString(" fn %1(&self, index: usize) -> %2 {\n")
|
2017-08-30 12:58:01 -07:00
|
|
|
.arg(lc, rustReturnType(ip));
|
|
|
|
if (ip.type.isComplex()) {
|
2018-08-05 05:41:22 -07:00
|
|
|
r << " &self.list[index]." << lc << "\n";
|
2017-08-30 12:58:01 -07:00
|
|
|
} else {
|
2018-08-05 05:41:22 -07:00
|
|
|
r << " self.list[index]." << lc << "\n";
|
2017-08-30 12:58:01 -07:00
|
|
|
}
|
2017-08-22 04:45:34 -07:00
|
|
|
r << " }\n";
|
|
|
|
if (ip.write) {
|
2018-06-08 05:21:35 -07:00
|
|
|
r << QString(" fn set_%1(&mut self, index: usize, v: %2) -> bool {\n")
|
2017-08-22 04:45:34 -07:00
|
|
|
.arg(snakeCase(ip.name), rustType(ip));
|
2018-08-05 05:41:22 -07:00
|
|
|
r << " self.list[index]." << lc << " = v;\n";
|
2017-08-22 04:45:34 -07:00
|
|
|
r << " true\n";
|
|
|
|
r << " }\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-28 00:28:48 -07:00
|
|
|
r << "}\n\n";
|
2017-08-22 04:45:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void writeRustImplementation(const Configuration& conf) {
|
|
|
|
DifferentFileWriter w(rustFile(conf.rustdir, conf.implementationModule),
|
|
|
|
conf.overwriteImplementation);
|
|
|
|
QTextStream r(&w.buffer);
|
|
|
|
r << QString(R"(#![allow(unused_imports)]
|
|
|
|
#![allow(unused_variables)]
|
|
|
|
#![allow(dead_code)]
|
|
|
|
use %1::*;
|
|
|
|
|
|
|
|
)").arg(conf.interfaceModule);
|
|
|
|
|
|
|
|
for (auto object: conf.objects) {
|
|
|
|
writeRustImplementationObject(r, object);
|
|
|
|
}
|
|
|
|
}
|