Skip to content

fix: codegen for nested namespace with using #612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/CppInterOp/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,13 @@
if (auto* TD = llvm::dyn_cast<TagDecl>(ND)) {
std::string type_name;
QualType QT = C.getTagDeclType(TD);
QT.getAsStringInternal(type_name, C.getPrintingPolicy());
PrintingPolicy PP = C.getPrintingPolicy();
PP.FullyQualifiedName = true;

Check warning on line 522 in lib/CppInterOp/CppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/CppInterOp/CppInterOp.cpp#L522

Added line #L522 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make sure codecov is covered?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a problem with codecov, because the line above and below is covered, and there is no conditional either.

PP.SuppressUnwrittenScope = true;
#if CLANG_VERSION_MAJOR > 16
PP.SuppressElaboration = true;
#endif
QT.getAsStringInternal(type_name, PP);

return type_name;
}
Expand Down Expand Up @@ -601,7 +607,8 @@
return 0;

if (llvm::isa<NamespaceDecl>(ND) || llvm::isa<RecordDecl>(ND) ||
llvm::isa<ClassTemplateDecl>(ND) || llvm::isa<TypedefNameDecl>(ND))
llvm::isa<ClassTemplateDecl>(ND) || llvm::isa<TypedefNameDecl>(ND) ||
llvm::isa<TypeAliasTemplateDecl>(ND) || llvm::isa<TypeAliasDecl>(ND))
return (TCppScope_t)(ND->getCanonicalDecl());

return 0;
Expand Down Expand Up @@ -1983,7 +1990,13 @@
{
std::string complete_name;
llvm::raw_string_ostream stream(complete_name);
FD->getNameForDiagnostic(stream, FD->getASTContext().getPrintingPolicy(),
PrintingPolicy PP = FD->getASTContext().getPrintingPolicy();
PP.FullyQualifiedName = true;
PP.SuppressUnwrittenScope = true;

Check warning on line 1995 in lib/CppInterOp/CppInterOp.cpp

View check run for this annotation

Codecov / codecov/patch

lib/CppInterOp/CppInterOp.cpp#L1995

Added line #L1995 was not covered by tests
#if CLANG_VERSION_MAJOR > 16
PP.SuppressElaboration = true;
#endif
FD->getNameForDiagnostic(stream, PP,
/*Qualified=*/false);

// insert space between template argument list and the function name
Expand Down
81 changes: 81 additions & 0 deletions unittests/CppInterOp/FunctionReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,87 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
Cpp::BestOverloadFunctionMatch(operators, {}, {K1, K2});
auto chrono_op_fn_callable = Cpp::MakeFunctionCallable(kop);
EXPECT_EQ(chrono_op_fn_callable.getKind(), Cpp::JitCall::kGenericCall);

Interp->process(R"(
namespace my_std {
template <typename T1, typename T2>
struct pair {
T1 first;
T2 second;
pair(T1 fst, T2 snd) : first(fst), second(snd) {}
};

template <typename T1, typename T2>
pair<T1, T2> make_pair(T1 x, T2 y) {
return pair<T1, T2>(x, y);
}

template <int _Int>
struct __pair_get;

template <>
struct __pair_get<0> {
template <typename T1, typename T2>
static constexpr T1 __get(pair<T1, T2> __pair) noexcept {
return __pair.first;
}
};

template <>
struct __pair_get<1> {
template <typename T1, typename T2>
constexpr T2 __get(pair<T1, T2> __pair) noexcept {
return __pair.second;
}
};

template <int N, typename T1, typename T2>
static constexpr auto get(pair<T1, T2> __t) noexcept {
return __pair_get<N>::__get(__t);
}
} // namespace my_std

namespace libchemist {
namespace type {
template <typename T>
class tensor {};
} // namespace type

template <typename element_type = double,
typename tensor_type = type::tensor<element_type>>
class CanonicalMO {};

template class CanonicalMO<double, type::tensor<double>>;

auto produce() { return my_std::make_pair(10., type::tensor<double>{}); }

} // namespace libchemist

namespace property_types {
namespace type {
template <typename T>
using canonical_mos = libchemist::CanonicalMO<T>;
}

auto produce() { return my_std::make_pair(5., type::canonical_mos<double>{}); }
} // namespace property_types

auto tmp = property_types::produce();
auto &p = tmp;
)");

std::vector<Cpp::TCppFunction_t> unresolved_candidate_methods;
Cpp::GetClassTemplatedMethods("get", Cpp::GetScope("my_std"),
unresolved_candidate_methods);
Cpp::TCppType_t p = Cpp::GetTypeFromScope(Cpp::GetNamed("p"));
EXPECT_TRUE(p);

Cpp::TCppScope_t fn = Cpp::BestOverloadFunctionMatch(
unresolved_candidate_methods, {{Cpp::GetType("int"), "0"}}, {p});
EXPECT_TRUE(fn);

auto fn_callable = Cpp::MakeFunctionCallable(fn);
EXPECT_EQ(fn_callable.getKind(), Cpp::JitCall::kGenericCall);
}

TEST(FunctionReflectionTest, IsConstMethod) {
Expand Down
Loading