Skip to content

Commit

Permalink
cxx-qt-gen: remove qobject:: from parameters in methods in a bridge
Browse files Browse the repository at this point in the history
Related to KDAB#559
  • Loading branch information
ahayzen-kdab committed Jul 18, 2023
1 parent 8d2abcb commit 654af1d
Show file tree
Hide file tree
Showing 34 changed files with 182 additions and 175 deletions.
6 changes: 3 additions & 3 deletions crates/cxx-qt-gen/src/generator/cpp/inherit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mod tests {
fn test_immutable() {
let generated = generate_from_foreign(
parse_quote! {
fn test(self: &qobject::T, a: B, b: C);
fn test(self: &T, a: B, b: C);
},
Some("TestBaseClass"),
)
Expand All @@ -104,7 +104,7 @@ mod tests {
fn test_mutable() {
let generated = generate_from_foreign(
parse_quote! {
fn test(self: Pin<&mut qobject::T>);
fn test(self: Pin<&mut T>);
},
Some("TestBaseClass"),
)
Expand All @@ -126,7 +126,7 @@ mod tests {
fn test_default_base_class() {
let generated = generate_from_foreign(
parse_quote! {
fn test(self: &qobject::T);
fn test(self: &T);
},
None,
)
Expand Down
10 changes: 5 additions & 5 deletions crates/cxx-qt-gen/src/generator/cpp/invokable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ mod tests {
fn test_generate_cpp_invokables() {
let invokables = vec![
ParsedQInvokable {
method: parse_quote! { fn void_invokable(self: &qobject::MyObject); },
method: parse_quote! { fn void_invokable(self: &MyObject); },
qobject_ident: format_ident!("MyObject"),
mutable: false,
safe: true,
parameters: vec![],
specifiers: HashSet::new(),
},
ParsedQInvokable {
method: parse_quote! { fn trivial_invokable(self: &qobject::MyObject, param: i32) -> i32; },
method: parse_quote! { fn trivial_invokable(self: &MyObject, param: i32) -> i32; },
qobject_ident: format_ident!("MyObject"),
mutable: false,
safe: true,
Expand All @@ -180,7 +180,7 @@ mod tests {
specifiers: HashSet::new(),
},
ParsedQInvokable {
method: parse_quote! { fn opaque_invokable(self: Pin<&mut qobject::MyObject>, param: &QColor) -> UniquePtr<QColor>; },
method: parse_quote! { fn opaque_invokable(self: Pin<&mut MyObject>, param: &QColor) -> UniquePtr<QColor>; },
qobject_ident: format_ident!("MyObject"),
mutable: true,
safe: true,
Expand All @@ -191,7 +191,7 @@ mod tests {
specifiers: HashSet::new(),
},
ParsedQInvokable {
method: parse_quote! { fn specifiers_invokable(self: &qobject::MyObject, param: i32) -> i32; },
method: parse_quote! { fn specifiers_invokable(self: &MyObject, param: i32) -> i32; },
qobject_ident: format_ident!("MyObject"),
mutable: false,
safe: true,
Expand Down Expand Up @@ -306,7 +306,7 @@ mod tests {
#[test]
fn test_generate_cpp_invokables_mapped_cxx_name() {
let invokables = vec![ParsedQInvokable {
method: parse_quote! { fn trivial_invokable(self: &qobject::MyObject, param: A) -> B; },
method: parse_quote! { fn trivial_invokable(self: &MyObject, param: A) -> B; },
qobject_ident: format_ident!("MyObject"),
mutable: false,
safe: true,
Expand Down
2 changes: 1 addition & 1 deletion crates/cxx-qt-gen/src/generator/naming/invokable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mod tests {
fn test_from_impl_method() {
let parsed = ParsedQInvokable {
method: parse_quote! {
fn my_invokable(self: &qobject::MyObject);
fn my_invokable(self: &MyObject);
},
qobject_ident: format_ident!("MyObject"),
mutable: false,
Expand Down
6 changes: 3 additions & 3 deletions crates/cxx-qt-gen/src/generator/rust/inherit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod tests {
fn test_mutable() {
let generated = generate_from_foreign(
parse_quote! {
fn test(self: Pin<&mut qobject::MyObject>, a: B, b: C);
fn test(self: Pin<&mut MyObject>, a: B, b: C);
},
Safety::Safe,
)
Expand All @@ -104,7 +104,7 @@ mod tests {
fn test_immutable() {
let generated = generate_from_foreign(
parse_quote! {
fn test(self: &qobject::MyObject, a: B, b: C);
fn test(self: &MyObject, a: B, b: C);
},
Safety::Safe,
)
Expand All @@ -128,7 +128,7 @@ mod tests {
fn test_unsafe() {
let generated = generate_from_foreign(
parse_quote! {
unsafe fn test(self: &qobject::MyObject);
unsafe fn test(self: &MyObject);
},
Safety::Unsafe,
)
Expand Down
8 changes: 4 additions & 4 deletions crates/cxx-qt-gen/src/generator/rust/invokable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ mod tests {
fn test_generate_rust_invokables() {
let invokables = vec![
ParsedQInvokable {
method: parse_quote! { fn void_invokable(self: &qobject::MyObject); },
method: parse_quote! { fn void_invokable(self: &MyObject); },
qobject_ident: format_ident!("MyObject"),
mutable: false,
safe: true,
parameters: vec![],
specifiers: HashSet::new(),
},
ParsedQInvokable {
method: parse_quote! { fn trivial_invokable(self: &qobject::MyObject, param: i32) -> i32; },
method: parse_quote! { fn trivial_invokable(self: &MyObject, param: i32) -> i32; },
qobject_ident: format_ident!("MyObject"),
mutable: false,
safe: true,
Expand All @@ -137,7 +137,7 @@ mod tests {
specifiers: HashSet::new(),
},
ParsedQInvokable {
method: parse_quote! { fn opaque_invokable(self: Pin<&mut qobject::MyObject>, param: &QColor) -> UniquePtr<QColor>; },
method: parse_quote! { fn opaque_invokable(self: Pin<&mut MyObject>, param: &QColor) -> UniquePtr<QColor>; },
qobject_ident: format_ident!("MyObject"),
mutable: true,
safe: true,
Expand All @@ -148,7 +148,7 @@ mod tests {
specifiers: HashSet::new(),
},
ParsedQInvokable {
method: parse_quote! { unsafe fn unsafe_invokable(self: &qobject::MyObject, param: *mut T) -> *mut T; },
method: parse_quote! { unsafe fn unsafe_invokable(self: &MyObject, param: *mut T) -> *mut T; },
qobject_ident: format_ident!("MyObject"),
mutable: false,
safe: false,
Expand Down
18 changes: 9 additions & 9 deletions crates/cxx-qt-gen/src/parser/cxxqtdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ mod tests {
let item: Item = parse_quote! {
unsafe extern "RustQt" {
#[qinvokable]
fn invokable(self: &qobject::MyObject);
fn invokable(self: &MyObject);

fn cpp_context();
}
Expand All @@ -466,7 +466,7 @@ mod tests {
let item: Item = parse_quote! {
unsafe extern "RustQt" {
#[qinvokable]
fn invokable(self: &qobject::MyObject::Bad);
fn invokable(self: &MyObject::Bad);
}
};
let result = cxx_qt_data.parse_cxx_qt_item(item);
Expand Down Expand Up @@ -743,17 +743,17 @@ mod tests {
let unsafe_block: Item = parse_quote! {
unsafe extern "RustQt" {
#[inherit]
fn test(self: &qobject::MyObject);
fn test(self: &MyObject);

#[inherit]
fn with_args(self: &qobject::MyObject, arg: i32);
fn with_args(self: &MyObject, arg: i32);
}
};
let safe_block: Item = parse_quote! {
extern "RustQt" {
#[cxx_name="withRename"]
#[inherit]
unsafe fn with_rename(self: Pin<&mut qobject::MyObject>, arg: i32);
unsafe fn with_rename(self: Pin<&mut MyObject>, arg: i32);
}
};

Expand Down Expand Up @@ -783,12 +783,12 @@ mod tests {
let block: Item = parse_quote! {
unsafe extern "RustQt" {
#[qsignal]
fn ready(self: Pin<&mut qobject::MyObject>);
fn ready(self: Pin<&mut MyObject>);

#[cxx_name="cppDataChanged"]
#[inherit]
#[qsignal]
fn data_changed(self: Pin<&mut qobject::MyObject>, data: i32);
fn data_changed(self: Pin<&mut MyObject>, data: i32);
}
};
cxxqtdata.parse_cxx_qt_item(block).unwrap();
Expand Down Expand Up @@ -828,7 +828,7 @@ mod tests {
let block: Item = parse_quote! {
unsafe extern "RustQt" {
#[qsignal]
fn ready(self: Pin<&mut qobject::UnknownObj>);
fn ready(self: Pin<&mut UnknownObj>);
}
};
assert!(cxxqtdata.parse_cxx_qt_item(block).is_err());
Expand All @@ -840,7 +840,7 @@ mod tests {
let block: Item = parse_quote! {
extern "RustQt" {
#[qsignal]
unsafe fn unsafe_signal(self: Pin<&mut qobject::MyObject>, arg: *mut T);
unsafe fn unsafe_signal(self: Pin<&mut MyObject>, arg: *mut T);
}
};
cxxqtdata.parse_cxx_qt_item(block).unwrap();
Expand Down
33 changes: 23 additions & 10 deletions crates/cxx-qt-gen/src/parser/inherit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,9 @@ mod tests {
assert_parse_error(parse_quote! {
fn test(&self);
});
// Missing qobject::
assert_parse_error(parse_quote! {
fn test(self: &T);
});
assert_parse_error(parse_quote! {
fn test(self: &mut T);
});
assert_parse_error(parse_quote! {
fn test(self: Pin<&mut T>);
});
// Pointer types
assert_parse_error(parse_quote! {
fn test(self: *const T);
Expand All @@ -116,20 +109,40 @@ mod tests {
});
// Attributes
assert_parse_error(parse_quote! {
fn test(#[test] self: &qobject::T);
fn test(#[test] self: &T);
});
// Missing "unsafe"
let function: ForeignItemFn = parse_quote! {
fn test(self: &qobject::T);
fn test(self: &T);
};
assert!(ParsedInheritedMethod::parse(function, Safety::Unsafe).is_err());
}

#[test]
fn test_parse_ok() {
// T by ref
assert!(ParsedInheritedMethod::parse(
parse_quote! {
fn test(self: &T);
},
Safety::Safe
)
.is_ok());
// T by Pin
assert!(ParsedInheritedMethod::parse(
parse_quote! {
fn test(self: Pin<&mut T>);
},
Safety::Safe
)
.is_ok());
}

#[test]
fn test_parse_safe() {
let function: ForeignItemFn = parse_quote! {
#[cxx_name="testFunction"]
fn test(self: Pin<&mut qobject::T>, a: i32, b: &str);
fn test(self: Pin<&mut T>, a: i32, b: &str);
};

let parsed = ParsedInheritedMethod::parse(function, Safety::Safe).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions crates/cxx-qt-gen/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ mod tests {

unsafe extern "RustQt" {
#[qsignal]
fn ready(self: Pin<&mut qobject::MyObject>);
fn ready(self: Pin<&mut MyObject>);
}
}
};
Expand All @@ -194,7 +194,7 @@ mod tests {

unsafe extern "RustQt" {
#[qsignal]
fn ready(self: Pin<&mut qobject::MyObject>);
fn ready(self: Pin<&mut MyObject>);
}

extern "Rust" {
Expand Down Expand Up @@ -225,7 +225,7 @@ mod tests {

unsafe extern "RustQt" {
#[qsignal]
fn ready(self: Pin<&mut qobject::UnknownObject>);
fn ready(self: Pin<&mut UnknownObject>);
}
}
};
Expand Down
18 changes: 9 additions & 9 deletions crates/cxx-qt-gen/src/parser/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mod tests {
#[test]
fn test_parse_signal() {
let method: ForeignItemFn = parse_quote! {
fn ready(self: Pin<&mut qobject::MyObject>);
fn ready(self: Pin<&mut MyObject>);
};
let signal = ParsedSignal::parse(method.clone(), Safety::Safe).unwrap();
assert_eq!(signal.method, method);
Expand All @@ -134,12 +134,12 @@ mod tests {
fn test_parse_signal_cxx_name() {
let method: ForeignItemFn = parse_quote! {
#[cxx_name = "cppReady"]
fn ready(self: Pin<&mut qobject::MyObject>);
fn ready(self: Pin<&mut MyObject>);
};
let signal = ParsedSignal::parse(method, Safety::Safe).unwrap();

let expected_method: ForeignItemFn = parse_quote! {
fn ready(self: Pin<&mut qobject::MyObject>);
fn ready(self: Pin<&mut MyObject>);
};
assert_eq!(signal.method, expected_method);
assert_eq!(signal.qobject_ident, format_ident!("MyObject"));
Expand All @@ -160,12 +160,12 @@ mod tests {
fn test_parse_signal_inherit() {
let method: ForeignItemFn = parse_quote! {
#[inherit]
fn ready(self: Pin<&mut qobject::MyObject>);
fn ready(self: Pin<&mut MyObject>);
};
let signal = ParsedSignal::parse(method, Safety::Safe).unwrap();

let expected_method: ForeignItemFn = parse_quote! {
fn ready(self: Pin<&mut qobject::MyObject>);
fn ready(self: Pin<&mut MyObject>);
};
assert_eq!(signal.method, expected_method);
assert_eq!(signal.qobject_ident, format_ident!("MyObject"));
Expand All @@ -185,7 +185,7 @@ mod tests {
#[test]
fn test_parse_signal_mutable_err() {
let method: ForeignItemFn = parse_quote! {
fn ready(self: &qobject::MyObject);
fn ready(self: &MyObject);
};
// Can't be immutable
assert!(ParsedSignal::parse(method, Safety::Safe).is_err());
Expand All @@ -194,7 +194,7 @@ mod tests {
#[test]
fn test_parse_signal_parameters() {
let method: ForeignItemFn = parse_quote! {
fn ready(self: Pin<&mut qobject::MyObject>, x: f64, y: f64);
fn ready(self: Pin<&mut MyObject>, x: f64, y: f64);
};
let signal = ParsedSignal::parse(method.clone(), Safety::Safe).unwrap();
assert_eq!(signal.method, method);
Expand Down Expand Up @@ -237,7 +237,7 @@ mod tests {
#[test]
fn test_parse_signal_unsafe() {
let method: ForeignItemFn = parse_quote! {
unsafe fn ready(self: Pin<&mut qobject::MyObject>);
unsafe fn ready(self: Pin<&mut MyObject>);
};
let signal = ParsedSignal::parse(method.clone(), Safety::Unsafe).unwrap();
assert_eq!(signal.method, method);
Expand All @@ -258,7 +258,7 @@ mod tests {
#[test]
fn test_parse_signal_unsafe_error() {
let method: ForeignItemFn = parse_quote! {
fn ready(self: Pin<&mut qobject::MyObject>);
fn ready(self: Pin<&mut MyObject>);
};
// Can't be safe on the block and the method
assert!(ParsedSignal::parse(method, Safety::Unsafe).is_err());
Expand Down
4 changes: 2 additions & 2 deletions crates/cxx-qt-gen/src/syntax/foreignmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ mod tests {
#[test]
fn test_foreign_fn_self() {
let foreign_fn: ForeignItemFn = parse_quote! {
fn foo(self: &qobject::T, a: A) -> B;
fn foo(self: &T, a: A) -> B;
};
let result = self_type_from_foreign_fn(&foreign_fn.sig).unwrap();
assert_eq!(result.ty.to_token_stream().to_string(), "& qobject :: T");
assert_eq!(result.ty.to_token_stream().to_string(), "& T");
}

#[test]
Expand Down
Loading

0 comments on commit 654af1d

Please sign in to comment.