Skip to content

Commit

Permalink
Fully qualify CXX types without namespace
Browse files Browse the repository at this point in the history
These types are assumed to be within the global namespace.
  • Loading branch information
LeonMatthesKDAB authored and ahayzen-kdab committed Mar 1, 2024
1 parent 7cdefb5 commit a825c29
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 71 deletions.
11 changes: 7 additions & 4 deletions crates/cxx-qt-gen/src/generator/cpp/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,15 @@ mod tests {
} else {
panic!("Expected pair")
};
assert_str_eq!(header, "Q_INVOKABLE B2 trivialInvokable(A1 param) const;");
assert_str_eq!(
header,
"Q_INVOKABLE ::B2 trivialInvokable(::A1 param) const;"
);
assert_str_eq!(
source,
indoc! {r#"
B2
MyObject::trivialInvokable(A1 param) const
::B2
MyObject::trivialInvokable(::A1 param) const
{
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
return trivialInvokableWrapper(param);
Expand All @@ -434,7 +437,7 @@ mod tests {
};
assert_str_eq!(
header,
"B2 trivialInvokableWrapper(A1 param) const noexcept;"
"::B2 trivialInvokableWrapper(::A1 param) const noexcept;"
);
}
}
2 changes: 1 addition & 1 deletion crates/cxx-qt-gen/src/naming/cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ mod tests {
let ty = parse_quote! { A };
let mut type_names = TypeNames::default();
type_names.insert("A", None, Some("A1"), None);
assert_eq!(syn_type_to_cpp_type(&ty, &type_names).unwrap(), "A1");
assert_eq!(syn_type_to_cpp_type(&ty, &type_names).unwrap(), "::A1");
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions crates/cxx-qt-gen/src/naming/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl TypeNames {
if let Some(namespace) = &name.namespace {
format!("::{namespace}::{cxx_name}")
} else {
cxx_name.clone()
format!("::{cxx_name}")
}
}

Expand Down Expand Up @@ -284,7 +284,7 @@ mod tests {

assert_eq!(types.num_types(), 1);
assert_eq!(types.rust_qualified(&ident), parse_quote! { ffi::A });
assert_eq!(types.cxx_qualified(&ident), "A"); // TODO Should this be "::A"?
assert_eq!(types.cxx_qualified(&ident), "::A");
assert!(types.namespace(&ident).is_none());
}

Expand All @@ -302,7 +302,7 @@ mod tests {
.is_ok());

assert_eq!(types.num_types(), 1);
assert_eq!(types.cxx_qualified(&ident), "B");
assert_eq!(types.cxx_qualified(&ident), "::B");
assert!(types.namespace(&ident).is_none());
assert_eq!(types.rust_qualified(&ident), parse_quote! { ffi::A });
}
Expand Down Expand Up @@ -397,7 +397,7 @@ mod tests {
let type_names = parse_cxx_item(item);
let ident = format_ident!("A");
assert_eq!(type_names.num_types(), 1);
assert_eq!(type_names.cxx_qualified(&ident), "B");
assert_eq!(type_names.cxx_qualified(&ident), "::B");

assert_eq!(type_names.rust_qualified(&ident), parse_quote! { ffi::A });
}
Expand Down
6 changes: 3 additions & 3 deletions crates/cxx-qt-gen/test_outputs/inheritance.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "cxx-qt-gen/inheritance.cxxqt.h"

QVariant
MyObject::data(QModelIndex const& _index, ::std::int32_t _role) const
::QVariant
MyObject::data(::QModelIndex const& _index, ::std::int32_t _role) const
{
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
return dataWrapper(_index, _role);
}

bool
MyObject::hasChildren(QModelIndex const& _parent) const
MyObject::hasChildren(::QModelIndex const& _parent) const
{
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
return hasChildrenWrapper(_parent);
Expand Down
12 changes: 6 additions & 6 deletions crates/cxx-qt-gen/test_outputs/inheritance.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class MyObject
virtual ~MyObject() = default;

public:
Q_INVOKABLE QVariant data(QModelIndex const& _index,
::std::int32_t _role) const override;
Q_INVOKABLE bool hasChildren(QModelIndex const& _parent) const override;
Q_INVOKABLE ::QVariant data(::QModelIndex const& _index,
::std::int32_t _role) const override;
Q_INVOKABLE bool hasChildren(::QModelIndex const& _parent) const override;
template<class... Args>
bool hasChildrenCxxQtInherit(Args... args) const
{
Expand All @@ -34,9 +34,9 @@ class MyObject
explicit MyObject(QObject* parent = nullptr);

private:
QVariant dataWrapper(QModelIndex const& _index,
::std::int32_t _role) const noexcept;
bool hasChildrenWrapper(QModelIndex const& _parent) const noexcept;
::QVariant dataWrapper(::QModelIndex const& _index,
::std::int32_t _role) const noexcept;
bool hasChildrenWrapper(::QModelIndex const& _parent) const noexcept;
};

static_assert(::std::is_base_of<QObject, MyObject>::value,
Expand Down
6 changes: 3 additions & 3 deletions crates/cxx-qt-gen/test_outputs/invokables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ MyObject::invokableMutable()
}

void
MyObject::invokableParameters(QColor const& opaque,
QPoint const& trivial,
MyObject::invokableParameters(::QColor const& opaque,
::QPoint const& trivial,
::std::int32_t primitive) const
{
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
Expand All @@ -38,7 +38,7 @@ MyObject::invokableReturnOpaque()
return invokableReturnOpaqueWrapper();
}

QPoint
::QPoint
MyObject::invokableReturnTrivial()
{
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
Expand Down
12 changes: 6 additions & 6 deletions crates/cxx-qt-gen/test_outputs/invokables.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class MyObject
void cppMethod() const;
Q_INVOKABLE void invokable() const;
Q_INVOKABLE void invokableMutable();
Q_INVOKABLE void invokableParameters(QColor const& opaque,
QPoint const& trivial,
Q_INVOKABLE void invokableParameters(::QColor const& opaque,
::QPoint const& trivial,
::std::int32_t primitive) const;
Q_INVOKABLE ::std::unique_ptr<Opaque> invokableReturnOpaque();
Q_INVOKABLE QPoint invokableReturnTrivial();
Q_INVOKABLE ::QPoint invokableReturnTrivial();
Q_INVOKABLE void invokableFinal() const final;
Q_INVOKABLE void invokableOverride() const override;
Q_INVOKABLE virtual void invokableVirtual() const;
Expand All @@ -43,11 +43,11 @@ class MyObject
void cppMethodWrapper() const noexcept;
void invokableWrapper() const noexcept;
void invokableMutableWrapper() noexcept;
void invokableParametersWrapper(QColor const& opaque,
QPoint const& trivial,
void invokableParametersWrapper(::QColor const& opaque,
::QPoint const& trivial,
::std::int32_t primitive) const noexcept;
::std::unique_ptr<Opaque> invokableReturnOpaqueWrapper() noexcept;
QPoint invokableReturnTrivialWrapper() noexcept;
::QPoint invokableReturnTrivialWrapper() noexcept;
void invokableFinalWrapper() const noexcept;
void invokableOverrideWrapper() const noexcept;
void invokableVirtualWrapper() const noexcept;
Expand Down
12 changes: 6 additions & 6 deletions crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ template<>
template<>
void
SignalHandler<::rust::cxxqtgen1::QPushButtonCxxQtSignalParamsclicked*>::
operator()<QPushButton&, bool>(QPushButton& self, bool checked)
operator()<::QPushButton&, bool>(::QPushButton& self, bool checked)
{
call_QPushButton_signal_handler_clicked(*this, self, ::std::move(checked));
}
Expand All @@ -38,18 +38,18 @@ static_assert(
namespace rust::cxxqtgen1 {
::QMetaObject::Connection
QPushButton_clickedConnect(
QPushButton& self,
::QPushButton& self,
::rust::cxxqtgen1::QPushButtonCxxQtSignalHandlerclicked closure,
::Qt::ConnectionType type)
{
return ::QObject::connect(
&self,
&QPushButton::clicked,
&::QPushButton::clicked,
&self,
[&, closure = ::std::move(closure)](bool checked) mutable {
const ::rust::cxxqt1::MaybeLockGuard<QPushButton> guard(self);
closure.template operator()<QPushButton&, bool>(self,
::std::move(checked));
const ::rust::cxxqt1::MaybeLockGuard<::QPushButton> guard(self);
closure.template operator()<::QPushButton&, bool>(self,
::std::move(checked));
},
type);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ using ExternObjectCxxQtSignalHandlererrorOccurred =
namespace rust::cxxqtgen1 {
::QMetaObject::Connection
QPushButton_clickedConnect(
QPushButton& self,
::QPushButton& self,
::rust::cxxqtgen1::QPushButtonCxxQtSignalHandlerclicked closure,
::Qt::ConnectionType type);
} // namespace rust::cxxqtgen1
Expand Down
4 changes: 2 additions & 2 deletions crates/cxx-qt-gen/test_outputs/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ MyObject::setPrimitive(::std::int32_t const& value)
setPrimitiveWrapper(value);
}

QPoint const&
::QPoint const&
MyObject::getTrivial() const
{
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
return getTrivialWrapper();
}

void
MyObject::setTrivial(QPoint const& value)
MyObject::setTrivial(::QPoint const& value)
{
const ::rust::cxxqt1::MaybeLockGuard<MyObject> guard(*this);
setTrivialWrapper(value);
Expand Down
10 changes: 5 additions & 5 deletions crates/cxx-qt-gen/test_outputs/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,24 @@ class MyObject
Q_PROPERTY(::std::int32_t primitive READ getPrimitive WRITE setPrimitive
NOTIFY primitiveChanged)
Q_PROPERTY(
QPoint trivial READ getTrivial WRITE setTrivial NOTIFY trivialChanged)
::QPoint trivial READ getTrivial WRITE setTrivial NOTIFY trivialChanged)

virtual ~MyObject() = default;

public:
::std::int32_t const& getPrimitive() const;
Q_SLOT void setPrimitive(::std::int32_t const& value);
QPoint const& getTrivial() const;
Q_SLOT void setTrivial(QPoint const& value);
::QPoint const& getTrivial() const;
Q_SLOT void setTrivial(::QPoint const& value);
Q_SIGNAL void primitiveChanged();
Q_SIGNAL void trivialChanged();
explicit MyObject(QObject* parent = nullptr);

private:
::std::int32_t const& getPrimitiveWrapper() const noexcept;
void setPrimitiveWrapper(::std::int32_t value) noexcept;
QPoint const& getTrivialWrapper() const noexcept;
void setTrivialWrapper(QPoint value) noexcept;
::QPoint const& getTrivialWrapper() const noexcept;
void setTrivialWrapper(::QPoint value) noexcept;
};

static_assert(::std::is_base_of<QObject, MyObject>::value,
Expand Down
56 changes: 28 additions & 28 deletions crates/cxx-qt-gen/test_outputs/signals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ SignalHandler<
operator()<::cxx_qt::my_object::MyObject&,
::std::int32_t,
::std::unique_ptr<Opaque>,
QPoint,
QPoint const&>(::cxx_qt::my_object::MyObject& self,
::std::int32_t first,
::std::unique_ptr<Opaque> second,
QPoint third,
QPoint const& fourth)
::QPoint,
::QPoint const&>(::cxx_qt::my_object::MyObject& self,
::std::int32_t first,
::std::unique_ptr<Opaque> second,
::QPoint third,
::QPoint const& fourth)
{
call_MyObject_signal_handler_dataChanged(*this,
self,
Expand Down Expand Up @@ -178,19 +178,19 @@ MyObject_dataChangedConnect(
&self,
[&, closure = ::std::move(closure)](::std::int32_t first,
::std::unique_ptr<Opaque> second,
QPoint third,
QPoint const& fourth) mutable {
::QPoint third,
::QPoint const& fourth) mutable {
const ::rust::cxxqt1::MaybeLockGuard<::cxx_qt::my_object::MyObject> guard(
self);
closure.template operator()<::cxx_qt::my_object::MyObject&,
::std::int32_t,
::std::unique_ptr<Opaque>,
QPoint,
QPoint const&>(self,
::std::move(first),
::std::move(second),
::std::move(third),
::std::move(fourth));
::QPoint,
::QPoint const&>(self,
::std::move(first),
::std::move(second),
::std::move(third),
::std::move(fourth));
},
type);
}
Expand Down Expand Up @@ -218,12 +218,12 @@ SignalHandler<
operator()<::cxx_qt::my_object::MyObject&,
::std::int32_t,
::std::unique_ptr<Opaque>,
QPoint,
QPoint const&>(::cxx_qt::my_object::MyObject& self,
::std::int32_t first,
::std::unique_ptr<Opaque> second,
QPoint third,
QPoint const& fourth)
::QPoint,
::QPoint const&>(::cxx_qt::my_object::MyObject& self,
::std::int32_t first,
::std::unique_ptr<Opaque> second,
::QPoint third,
::QPoint const& fourth)
{
call_MyObject_signal_handler_newData(*this,
self,
Expand Down Expand Up @@ -257,19 +257,19 @@ MyObject_newDataConnect(
&self,
[&, closure = ::std::move(closure)](::std::int32_t first,
::std::unique_ptr<Opaque> second,
QPoint third,
QPoint const& fourth) mutable {
::QPoint third,
::QPoint const& fourth) mutable {
const ::rust::cxxqt1::MaybeLockGuard<::cxx_qt::my_object::MyObject> guard(
self);
closure.template operator()<::cxx_qt::my_object::MyObject&,
::std::int32_t,
::std::unique_ptr<Opaque>,
QPoint,
QPoint const&>(self,
::std::move(first),
::std::move(second),
::std::move(third),
::std::move(fourth));
::QPoint,
::QPoint const&>(self,
::std::move(first),
::std::move(second),
::std::move(third),
::std::move(fourth));
},
type);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/cxx-qt-gen/test_outputs/signals.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class MyObject
Q_SIGNAL void ready();
Q_SIGNAL void dataChanged(::std::int32_t first,
::std::unique_ptr<Opaque> second,
QPoint third,
QPoint const& fourth);
::QPoint third,
::QPoint const& fourth);
explicit MyObject(QObject* parent = nullptr);

private:
Expand Down

0 comments on commit a825c29

Please sign in to comment.