Skip to content

Commit a825c29

Browse files
Leon Matthesahayzen-kdab
authored andcommitted
Fully qualify CXX types without namespace
These types are assumed to be within the global namespace.
1 parent 7cdefb5 commit a825c29

13 files changed

Lines changed: 74 additions & 71 deletions

File tree

crates/cxx-qt-gen/src/generator/cpp/method.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,15 @@ mod tests {
411411
} else {
412412
panic!("Expected pair")
413413
};
414-
assert_str_eq!(header, "Q_INVOKABLE B2 trivialInvokable(A1 param) const;");
414+
assert_str_eq!(
415+
header,
416+
"Q_INVOKABLE ::B2 trivialInvokable(::A1 param) const;"
417+
);
415418
assert_str_eq!(
416419
source,
417420
indoc! {r#"
418-
B2
419-
MyObject::trivialInvokable(A1 param) const
421+
::B2
422+
MyObject::trivialInvokable(::A1 param) const
420423
{
421424
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
422425
return trivialInvokableWrapper(param);
@@ -434,7 +437,7 @@ mod tests {
434437
};
435438
assert_str_eq!(
436439
header,
437-
"B2 trivialInvokableWrapper(A1 param) const noexcept;"
440+
"::B2 trivialInvokableWrapper(::A1 param) const noexcept;"
438441
);
439442
}
440443
}

crates/cxx-qt-gen/src/naming/cpp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ mod tests {
373373
let ty = parse_quote! { A };
374374
let mut type_names = TypeNames::default();
375375
type_names.insert("A", None, Some("A1"), None);
376-
assert_eq!(syn_type_to_cpp_type(&ty, &type_names).unwrap(), "A1");
376+
assert_eq!(syn_type_to_cpp_type(&ty, &type_names).unwrap(), "::A1");
377377
}
378378

379379
#[test]

crates/cxx-qt-gen/src/naming/type_names.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl TypeNames {
192192
if let Some(namespace) = &name.namespace {
193193
format!("::{namespace}::{cxx_name}")
194194
} else {
195-
cxx_name.clone()
195+
format!("::{cxx_name}")
196196
}
197197
}
198198

@@ -284,7 +284,7 @@ mod tests {
284284

285285
assert_eq!(types.num_types(), 1);
286286
assert_eq!(types.rust_qualified(&ident), parse_quote! { ffi::A });
287-
assert_eq!(types.cxx_qualified(&ident), "A"); // TODO Should this be "::A"?
287+
assert_eq!(types.cxx_qualified(&ident), "::A");
288288
assert!(types.namespace(&ident).is_none());
289289
}
290290

@@ -302,7 +302,7 @@ mod tests {
302302
.is_ok());
303303

304304
assert_eq!(types.num_types(), 1);
305-
assert_eq!(types.cxx_qualified(&ident), "B");
305+
assert_eq!(types.cxx_qualified(&ident), "::B");
306306
assert!(types.namespace(&ident).is_none());
307307
assert_eq!(types.rust_qualified(&ident), parse_quote! { ffi::A });
308308
}
@@ -397,7 +397,7 @@ mod tests {
397397
let type_names = parse_cxx_item(item);
398398
let ident = format_ident!("A");
399399
assert_eq!(type_names.num_types(), 1);
400-
assert_eq!(type_names.cxx_qualified(&ident), "B");
400+
assert_eq!(type_names.cxx_qualified(&ident), "::B");
401401

402402
assert_eq!(type_names.rust_qualified(&ident), parse_quote! { ffi::A });
403403
}

crates/cxx-qt-gen/test_outputs/inheritance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include "cxx-qt-gen/inheritance.cxxqt.h"
22

3-
QVariant
4-
MyObject::data(QModelIndex const& _index, ::std::int32_t _role) const
3+
::QVariant
4+
MyObject::data(::QModelIndex const& _index, ::std::int32_t _role) const
55
{
66
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
77
return dataWrapper(_index, _role);
88
}
99

1010
bool
11-
MyObject::hasChildren(QModelIndex const& _parent) const
11+
MyObject::hasChildren(::QModelIndex const& _parent) const
1212
{
1313
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
1414
return hasChildrenWrapper(_parent);

crates/cxx-qt-gen/test_outputs/inheritance.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class MyObject
1818
virtual ~MyObject() = default;
1919

2020
public:
21-
Q_INVOKABLE QVariant data(QModelIndex const& _index,
22-
::std::int32_t _role) const override;
23-
Q_INVOKABLE bool hasChildren(QModelIndex const& _parent) const override;
21+
Q_INVOKABLE ::QVariant data(::QModelIndex const& _index,
22+
::std::int32_t _role) const override;
23+
Q_INVOKABLE bool hasChildren(::QModelIndex const& _parent) const override;
2424
template<class... Args>
2525
bool hasChildrenCxxQtInherit(Args... args) const
2626
{
@@ -34,9 +34,9 @@ class MyObject
3434
explicit MyObject(QObject* parent = nullptr);
3535

3636
private:
37-
QVariant dataWrapper(QModelIndex const& _index,
38-
::std::int32_t _role) const noexcept;
39-
bool hasChildrenWrapper(QModelIndex const& _parent) const noexcept;
37+
::QVariant dataWrapper(::QModelIndex const& _index,
38+
::std::int32_t _role) const noexcept;
39+
bool hasChildrenWrapper(::QModelIndex const& _parent) const noexcept;
4040
};
4141

4242
static_assert(::std::is_base_of<QObject, MyObject>::value,

crates/cxx-qt-gen/test_outputs/invokables.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ MyObject::invokableMutable()
2323
}
2424

2525
void
26-
MyObject::invokableParameters(QColor const& opaque,
27-
QPoint const& trivial,
26+
MyObject::invokableParameters(::QColor const& opaque,
27+
::QPoint const& trivial,
2828
::std::int32_t primitive) const
2929
{
3030
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
@@ -38,7 +38,7 @@ MyObject::invokableReturnOpaque()
3838
return invokableReturnOpaqueWrapper();
3939
}
4040

41-
QPoint
41+
::QPoint
4242
MyObject::invokableReturnTrivial()
4343
{
4444
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);

crates/cxx-qt-gen/test_outputs/invokables.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class MyObject
2626
void cppMethod() const;
2727
Q_INVOKABLE void invokable() const;
2828
Q_INVOKABLE void invokableMutable();
29-
Q_INVOKABLE void invokableParameters(QColor const& opaque,
30-
QPoint const& trivial,
29+
Q_INVOKABLE void invokableParameters(::QColor const& opaque,
30+
::QPoint const& trivial,
3131
::std::int32_t primitive) const;
3232
Q_INVOKABLE ::std::unique_ptr<Opaque> invokableReturnOpaque();
33-
Q_INVOKABLE QPoint invokableReturnTrivial();
33+
Q_INVOKABLE ::QPoint invokableReturnTrivial();
3434
Q_INVOKABLE void invokableFinal() const final;
3535
Q_INVOKABLE void invokableOverride() const override;
3636
Q_INVOKABLE virtual void invokableVirtual() const;
@@ -43,11 +43,11 @@ class MyObject
4343
void cppMethodWrapper() const noexcept;
4444
void invokableWrapper() const noexcept;
4545
void invokableMutableWrapper() noexcept;
46-
void invokableParametersWrapper(QColor const& opaque,
47-
QPoint const& trivial,
46+
void invokableParametersWrapper(::QColor const& opaque,
47+
::QPoint const& trivial,
4848
::std::int32_t primitive) const noexcept;
4949
::std::unique_ptr<Opaque> invokableReturnOpaqueWrapper() noexcept;
50-
QPoint invokableReturnTrivialWrapper() noexcept;
50+
::QPoint invokableReturnTrivialWrapper() noexcept;
5151
void invokableFinalWrapper() const noexcept;
5252
void invokableOverrideWrapper() const noexcept;
5353
void invokableVirtualWrapper() const noexcept;

crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ template<>
1818
template<>
1919
void
2020
SignalHandler<::rust::cxxqtgen1::QPushButtonCxxQtSignalParamsclicked*>::
21-
operator()<QPushButton&, bool>(QPushButton& self, bool checked)
21+
operator()<::QPushButton&, bool>(::QPushButton& self, bool checked)
2222
{
2323
call_QPushButton_signal_handler_clicked(*this, self, ::std::move(checked));
2424
}
@@ -38,18 +38,18 @@ static_assert(
3838
namespace rust::cxxqtgen1 {
3939
::QMetaObject::Connection
4040
QPushButton_clickedConnect(
41-
QPushButton& self,
41+
::QPushButton& self,
4242
::rust::cxxqtgen1::QPushButtonCxxQtSignalHandlerclicked closure,
4343
::Qt::ConnectionType type)
4444
{
4545
return ::QObject::connect(
4646
&self,
47-
&QPushButton::clicked,
47+
&::QPushButton::clicked,
4848
&self,
4949
[&, closure = ::std::move(closure)](bool checked) mutable {
50-
const ::rust::cxxqt1::MaybeLockGuard<QPushButton> guard(self);
51-
closure.template operator()<QPushButton&, bool>(self,
52-
::std::move(checked));
50+
const ::rust::cxxqt1::MaybeLockGuard<::QPushButton> guard(self);
51+
closure.template operator()<::QPushButton&, bool>(self,
52+
::std::move(checked));
5353
},
5454
type);
5555
}

crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ using ExternObjectCxxQtSignalHandlererrorOccurred =
5858
namespace rust::cxxqtgen1 {
5959
::QMetaObject::Connection
6060
QPushButton_clickedConnect(
61-
QPushButton& self,
61+
::QPushButton& self,
6262
::rust::cxxqtgen1::QPushButtonCxxQtSignalHandlerclicked closure,
6363
::Qt::ConnectionType type);
6464
} // namespace rust::cxxqtgen1

crates/cxx-qt-gen/test_outputs/properties.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ MyObject::setPrimitive(::std::int32_t const& value)
131131
setPrimitiveWrapper(value);
132132
}
133133

134-
QPoint const&
134+
::QPoint const&
135135
MyObject::getTrivial() const
136136
{
137137
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
138138
return getTrivialWrapper();
139139
}
140140

141141
void
142-
MyObject::setTrivial(QPoint const& value)
142+
MyObject::setTrivial(::QPoint const& value)
143143
{
144144
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
145145
setTrivialWrapper(value);

0 commit comments

Comments
 (0)