Changeset View
Changeset View
Standalone View
Standalone View
src/rust.cpp
Show First 20 Lines • Show All 276 Lines • ▼ Show 20 Line(s) | 275 | if (p.type.type == BindingType::Object) { | |||
---|---|---|---|---|---|
277 | r << QString(" fn %1_mut(&mut self) -> &mut %2;\n").arg(lc, rustType(p)); | 277 | r << QString(" fn %1_mut(&mut self) -> &mut %2;\n").arg(lc, rustType(p)); | ||
278 | } else { | 278 | } else { | ||
279 | r << QString(" fn %1(&self) -> %2;\n").arg(lc, rustReturnType(p)); | 279 | r << QString(" fn %1(&self) -> %2;\n").arg(lc, rustReturnType(p)); | ||
280 | if (p.write) { | 280 | if (p.write) { | ||
281 | r << QString(" fn set_%1(&mut self, value: %2);\n").arg(lc, rustType(p)); | 281 | r << QString(" fn set_%1(&mut self, value: %2);\n").arg(lc, rustType(p)); | ||
282 | } | 282 | } | ||
283 | } | 283 | } | ||
284 | } | 284 | } | ||
285 | for (const Function& f: o.functions) { | ||||
286 | const QString lc(snakeCase(f.name)); | ||||
287 | QString argList; | ||||
288 | if (f.args.size() > 0) { | ||||
289 | argList.append(", "); | ||||
290 | for (auto a = f.args.begin(); a < f.args.end(); a++) { | ||||
291 | argList.append( | ||||
292 | QString("%1: %2%3") | ||||
293 | .arg(a->name, a->type.rustType, a + 1 < f.args.end() ? ", " : "") | ||||
294 | ); | ||||
295 | } | ||||
296 | } | ||||
297 | r << QString(" fn %1(&%2self%4) -> %3;\n") | ||||
298 | .arg(lc, f.mut ? "mut " : "", f.type.rustType, argList); | ||||
299 | } | ||||
285 | if (o.type == ObjectType::List) { | 300 | if (o.type == ObjectType::List) { | ||
286 | r << R"( fn row_count(&self) -> usize; | 301 | r << R"( fn row_count(&self) -> usize; | ||
287 | fn insert_rows(&mut self, row: usize, count: usize) -> bool { false } | 302 | fn insert_rows(&mut self, row: usize, count: usize) -> bool { false } | ||
288 | fn remove_rows(&mut self, row: usize, count: usize) -> bool { false } | 303 | fn remove_rows(&mut self, row: usize, count: usize) -> bool { false } | ||
289 | fn can_fetch_more(&self) -> bool { | 304 | fn can_fetch_more(&self) -> bool { | ||
290 | false | 305 | false | ||
291 | } | 306 | } | ||
292 | fn fetch_more(&mut self) {} | 307 | fn fetch_more(&mut self) {} | ||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | |||||
404 | #[no_mangle] | 419 | #[no_mangle] | ||
405 | pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: %4) { | 420 | pub unsafe extern "C" fn %2_set(ptr: *mut %1, v: %4) { | ||
406 | (&mut *ptr).set_%3(v); | 421 | (&mut *ptr).set_%3(v); | ||
407 | } | 422 | } | ||
408 | )").arg(o.name, base, snakeCase(p.name), rustType(p)); | 423 | )").arg(o.name, base, snakeCase(p.name), rustType(p)); | ||
409 | } | 424 | } | ||
410 | } | 425 | } | ||
411 | } | 426 | } | ||
427 | for (const Function& f: o.functions) { | ||||
428 | QString argList; | ||||
429 | QString noTypeArgs; | ||||
430 | if (f.args.size() > 0) { | ||||
431 | argList.append(", "); | ||||
432 | for (auto a = f.args.begin(); a < f.args.end(); a++) { | ||||
433 | const QString type = a->type.name == "QString" ? "QStringIn" : a->type.rustType; | ||||
434 | const QString passAlong = a->type.name == "QString" ? QString("%1.convert()").arg(a->name) : a->name; | ||||
435 | argList.append(QString("%1: %2%3").arg(a->name, type, a + 1 < f.args.end() ? ", " : "")); | ||||
436 | noTypeArgs.append(QString("%1%3").arg(passAlong, a + 1 < f.args.end() ? ", " : "")); | ||||
437 | } | ||||
438 | } | ||||
439 | if (f.type.isComplex()) { | ||||
440 | r << QString(R"( | ||||
441 | #[no_mangle] | ||||
442 | pub unsafe extern "C" fn %1_%2(ptr: *%3 %4%7, d: *mut c_void, set: fn(*mut c_void, %5)) { | ||||
443 | let data = (&%6*ptr).%2(%8); | ||||
444 | set(d, (&data).into()); | ||||
445 | } | ||||
446 | )").arg(lcname, f.name, f.mut ? "mut" : "const", o.name, f.type.name, f.mut ? "mut " : "", argList, noTypeArgs); | ||||
447 | | ||||
448 | } else { | ||||
449 | r << QString(R"( | ||||
450 | #[no_mangle] | ||||
451 | pub unsafe extern "C" fn %1_%2(ptr: *%3 %4%7) -> %5 { | ||||
452 | (&%6*ptr).%2(%8) | ||||
453 | } | ||||
454 | )").arg(lcname, f.name, f.mut ? "mut" : "const", o.name, f.type.rustType, f.mut ? "mut " : "", argList, noTypeArgs); | ||||
455 | } | ||||
456 | } | ||||
412 | if (o.type == ObjectType::List) { | 457 | if (o.type == ObjectType::List) { | ||
413 | r << QString(R"( | 458 | r << QString(R"( | ||
414 | #[no_mangle] | 459 | #[no_mangle] | ||
415 | pub unsafe extern "C" fn %2_row_count(ptr: *const %1) -> c_int { | 460 | pub unsafe extern "C" fn %2_row_count(ptr: *const %1) -> c_int { | ||
416 | (&*ptr).row_count() as c_int | 461 | (&*ptr).row_count() as c_int | ||
417 | } | 462 | } | ||
418 | #[no_mangle] | 463 | #[no_mangle] | ||
419 | pub unsafe extern "C" fn %2_insert_rows(ptr: *mut %1, row: c_int, count: c_int) -> bool { | 464 | pub unsafe extern "C" fn %2_insert_rows(ptr: *mut %1, row: c_int, count: c_int) -> bool { | ||
▲ Show 20 Lines • Show All 496 Lines • Show Last 20 Lines |