Skip to content

Commit 8a4c0af

Browse files
authored
Merge branch 'main' into Update-to-llvm-20
2 parents 8c6e593 + 7caf10b commit 8a4c0af

File tree

9 files changed

+148
-14
lines changed

9 files changed

+148
-14
lines changed

.github/workflows/MacOS.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ jobs:
133133
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
134134
run: |
135135
brew update
136-
brew remove [email protected]
137136
# workaround for https://github.com/actions/setup-python/issues/577
138137
for pkg in $(brew list | grep '^python@'); do
139138
brew unlink "$pkg"
@@ -335,7 +334,6 @@ jobs:
335334
- name: Install deps
336335
run: |
337336
brew update --force
338-
brew remove [email protected]
339337
brew remove swiftlint
340338
# workaround for https://github.com/actions/setup-python/issues/577
341339
for pkg in $(brew list | grep '^python@'); do

.github/workflows/emscripten.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ jobs:
241241
export ARCHITECHURE=$(uname -m)
242242
if [[ "$ARCHITECHURE" != "x86_64" ]]; then
243243
brew remove unxip
244-
else
245-
brew remove [email protected]
246244
fi
247245
# workaround for https://github.com/actions/setup-python/issues/577
248246
for pkg in $(brew list | grep '^python@'); do

CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ set(CMAKE_CXX_EXTENSIONS NO)
5959
include(GNUInstallDirs)
6060
option(CPPINTEROP_USE_CLING "Use Cling as backend" OFF)
6161
option(CPPINTEROP_USE_REPL "Use clang-repl as backend" ON)
62+
option(CPPINTEROP_ENABLE_TESTING "Enable the CppInterOp testing infrastructure." ON)
6263

6364
if (CPPINTEROP_USE_CLING AND CPPINTEROP_USE_REPL)
6465
message(FATAL_ERROR "We can only use Cling (CPPINTEROP_USE_CLING=On) or Repl (CPPINTEROP_USE_REPL=On), but not both of them.")
@@ -453,10 +454,7 @@ option(CPPINTEROP_ENABLE_SPHINX "Use sphinx to generage CppInterOp user document
453454

454455
if(EMSCRIPTEN)
455456
message("Build with emscripten")
456-
option(CPPINTEROP_ENABLE_TESTING "Enables the testing infrastructure." OFF)
457-
else()
458-
message("Build with cmake")
459-
option(CPPINTEROP_ENABLE_TESTING "Enables the testing infrastructure." ON)
457+
set(CPPINTEROP_ENABLE_TESTING OFF)
460458
endif()
461459

462460
if(MSVC)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.0;dev
1+
1.7.0;dev

docs/ReleaseNotes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Introduction
22

33
This document contains the release notes for the language interoperability
4-
library CppInterOp, release 1.6.0. CppInterOp is built on top of
4+
library CppInterOp, release 1.7.0. CppInterOp is built on top of
55
[Clang](http://clang.llvm.org) and [LLVM](http://llvm.org%3E) compiler
66
infrastructure. Here we describe the status of CppInterOp in some detail,
77
including major improvements from the previous release and new feature work.
@@ -16,7 +16,7 @@ interoperability on the fly. In such scenarios CppInterOp can be used to provide
1616
the necessary introspection information to the other side helping the language
1717
cross talk.
1818

19-
## What's New in CppInterOp 1.6.0?
19+
## What's New in CppInterOp 1.7.0?
2020

2121
Some of the major new features and improvements to CppInterOp are listed here.
2222
Generic improvements to CppInterOp as a whole or to its underlying
@@ -48,7 +48,7 @@ infrastructure are described first.
4848
[XXX](https://github.com/compiler-research/CppInterOp/issues/XXX)
4949

5050
<!---Get release bugs
51-
git log v1.5.0..main | grep 'Fixes|Closes'
51+
git log v1.6.0..main | grep 'Fixes|Closes'
5252
--->
5353

5454
## Special Kudos
@@ -61,6 +61,6 @@ FirstName LastName (#commits)
6161
A B (N)
6262

6363
<!---Find contributor list for this release
64-
git log --pretty=format:"%an" v1.5.0...main | sort | uniq -c | sort -rn |\
64+
git log --pretty=format:"%an" v1.6.0...main | sort | uniq -c | sort -rn |\
6565
sed -E 's,^ *([0-9]+) (.*)$,\2 \(\1\),'
6666
--->

include/clang/Interpreter/CppInterOp.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,18 @@ namespace Cpp {
504504
/// Checks if the provided parameter is a Plain Old Data Type (POD).
505505
CPPINTEROP_API bool IsPODType(TCppType_t type);
506506

507+
/// Checks if type is a pointer
508+
CPPINTEROP_API bool IsPointerType(TCppType_t type);
509+
510+
/// Get the underlying pointee type
511+
CPPINTEROP_API TCppType_t GetPointeeType(TCppType_t type);
512+
513+
/// Checks if type is a reference
514+
CPPINTEROP_API bool IsReferenceType(TCppType_t type);
515+
516+
/// Get the type that the reference refers to
517+
CPPINTEROP_API TCppType_t GetNonReferenceType(TCppType_t type);
518+
507519
/// Gets the pure, Underlying Type (as opposed to the Using Type).
508520
CPPINTEROP_API TCppType_t GetUnderlyingType(TCppType_t type);
509521

lib/Interpreter/CppInterOp.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,30 @@ namespace Cpp {
14931493
return QT.isPODType(getASTContext());
14941494
}
14951495

1496+
bool IsPointerType(TCppType_t type) {
1497+
QualType QT = QualType::getFromOpaquePtr(type);
1498+
return QT->isPointerType();
1499+
}
1500+
1501+
TCppType_t GetPointeeType(TCppType_t type) {
1502+
if (!IsPointerType(type))
1503+
return nullptr;
1504+
QualType QT = QualType::getFromOpaquePtr(type);
1505+
return QT->getPointeeType().getAsOpaquePtr();
1506+
}
1507+
1508+
bool IsReferenceType(TCppType_t type) {
1509+
QualType QT = QualType::getFromOpaquePtr(type);
1510+
return QT->isReferenceType();
1511+
}
1512+
1513+
TCppType_t GetNonReferenceType(TCppType_t type) {
1514+
if (!IsReferenceType(type))
1515+
return nullptr;
1516+
QualType QT = QualType::getFromOpaquePtr(type);
1517+
return QT.getNonReferenceType().getAsOpaquePtr();
1518+
}
1519+
14961520
TCppType_t GetUnderlyingType(TCppType_t type)
14971521
{
14981522
QualType QT = QualType::getFromOpaquePtr(type);
@@ -1862,10 +1886,22 @@ namespace Cpp {
18621886
{
18631887
std::string name;
18641888
{
1865-
llvm::raw_string_ostream stream(name);
1889+
std::string complete_name;
1890+
llvm::raw_string_ostream stream(complete_name);
18661891
FD->getNameForDiagnostic(stream,
18671892
FD->getASTContext().getPrintingPolicy(),
18681893
/*Qualified=*/false);
1894+
1895+
// insert space between template argument list and the function name
1896+
// this is require if the function is `operator<`
1897+
// `operator<<type1, type2, ...>` is invalid syntax
1898+
// whereas `operator< <type1, type2, ...>` is valid
1899+
std::string simple_name = FD->getNameAsString();
1900+
size_t idx = complete_name.find(simple_name, 0) + simple_name.size();
1901+
std::string name_without_template_args = complete_name.substr(0, idx);
1902+
std::string template_args = complete_name.substr(idx);
1903+
name = name_without_template_args +
1904+
(template_args.empty() ? "" : " " + template_args);
18691905
}
18701906
callbuf << name;
18711907
}

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,34 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
10431043
FCI_f.Invoke(&res, {nullptr, 0});
10441044
EXPECT_TRUE(res);
10451045
#endif
1046+
1047+
// templated operators
1048+
Interp->process(R"(
1049+
class TOperator{
1050+
public:
1051+
template<typename T>
1052+
bool operator<(T t) { return true; }
1053+
};
1054+
)");
1055+
Cpp::TCppScope_t TOperator = Cpp::GetNamed("TOperator");
1056+
1057+
auto* TOperatorCtor = Cpp::GetDefaultConstructor(TOperator);
1058+
auto FCI_TOperatorCtor = Cpp::MakeFunctionCallable(TOperatorCtor);
1059+
void* toperator = nullptr;
1060+
FCI_TOperatorCtor.Invoke((void*)&toperator);
1061+
1062+
EXPECT_TRUE(toperator);
1063+
std::vector<Cpp::TCppScope_t> operators;
1064+
Cpp::GetOperator(TOperator, Cpp::OP_Less, operators);
1065+
EXPECT_EQ(operators.size(), 1);
1066+
1067+
Cpp::TCppScope_t op_templated = operators[0];
1068+
auto TAI = Cpp::TemplateArgInfo(Cpp::GetType("int"));
1069+
Cpp::TCppScope_t op = Cpp::InstantiateTemplate(op_templated, &TAI, 1);
1070+
auto FCI_op = Cpp::MakeFunctionCallable(op);
1071+
bool boolean = false;
1072+
FCI_op.Invoke((void*)&boolean, {args, /*args_size=*/1}, object);
1073+
EXPECT_TRUE(boolean);
10461074
}
10471075

10481076
TEST(FunctionReflectionTest, IsConstMethod) {

unittests/CppInterOp/VariableReflectionTest.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,67 @@ TEST(VariableReflectionTest, GetEnumConstantDatamembers) {
600600
Cpp::GetEnumConstantDatamembers(MyEnumClass, datamembers2, false);
601601
EXPECT_EQ(datamembers2.size(), 6);
602602
}
603+
604+
TEST(VariableReflectionTest, Is_Get_Pointer) {
605+
Cpp::CreateInterpreter();
606+
std::vector<Decl*> Decls;
607+
std::string code = R"(
608+
class A {};
609+
int a;
610+
int *b;
611+
double c;
612+
double *d;
613+
A e;
614+
A *f;
615+
)";
616+
617+
GetAllTopLevelDecls(code, Decls);
618+
619+
EXPECT_FALSE(Cpp::IsPointerType(Cpp::GetVariableType(Decls[1])));
620+
EXPECT_TRUE(Cpp::IsPointerType(Cpp::GetVariableType(Decls[2])));
621+
EXPECT_FALSE(Cpp::IsPointerType(Cpp::GetVariableType(Decls[3])));
622+
EXPECT_TRUE(Cpp::IsPointerType(Cpp::GetVariableType(Decls[4])));
623+
EXPECT_FALSE(Cpp::IsPointerType(Cpp::GetVariableType(Decls[5])));
624+
EXPECT_TRUE(Cpp::IsPointerType(Cpp::GetVariableType(Decls[6])));
625+
626+
EXPECT_EQ(Cpp::GetPointeeType(Cpp::GetVariableType(Decls[2])),
627+
Cpp::GetVariableType(Decls[1]));
628+
EXPECT_EQ(Cpp::GetPointeeType(Cpp::GetVariableType(Decls[4])),
629+
Cpp::GetVariableType(Decls[3]));
630+
EXPECT_EQ(Cpp::GetPointeeType(Cpp::GetVariableType(Decls[6])),
631+
Cpp::GetVariableType(Decls[5]));
632+
633+
EXPECT_FALSE(Cpp::GetPointeeType(Cpp::GetVariableType(Decls[5])));
634+
}
635+
636+
TEST(VariableReflectionTest, Is_Get_Reference) {
637+
Cpp::CreateInterpreter();
638+
std::vector<Decl*> Decls;
639+
std::string code = R"(
640+
class A {};
641+
int a;
642+
int &b = a;
643+
double c;
644+
double &d = c;
645+
A e;
646+
A &f = e;
647+
)";
648+
649+
GetAllTopLevelDecls(code, Decls);
650+
651+
EXPECT_FALSE(Cpp::IsReferenceType(Cpp::GetVariableType(Decls[1])));
652+
EXPECT_TRUE(Cpp::IsReferenceType(Cpp::GetVariableType(Decls[2])));
653+
EXPECT_FALSE(Cpp::IsReferenceType(Cpp::GetVariableType(Decls[3])));
654+
EXPECT_TRUE(Cpp::IsReferenceType(Cpp::GetVariableType(Decls[4])));
655+
EXPECT_FALSE(Cpp::IsReferenceType(Cpp::GetVariableType(Decls[5])));
656+
EXPECT_TRUE(Cpp::IsReferenceType(Cpp::GetVariableType(Decls[6])));
657+
658+
EXPECT_EQ(Cpp::GetNonReferenceType(Cpp::GetVariableType(Decls[2])),
659+
Cpp::GetVariableType(Decls[1]));
660+
EXPECT_EQ(Cpp::GetNonReferenceType(Cpp::GetVariableType(Decls[4])),
661+
Cpp::GetVariableType(Decls[3]));
662+
EXPECT_EQ(Cpp::GetNonReferenceType(Cpp::GetVariableType(Decls[6])),
663+
Cpp::GetVariableType(Decls[5]));
664+
665+
EXPECT_FALSE(Cpp::GetNonReferenceType(Cpp::GetVariableType(Decls[5])));
666+
}

0 commit comments

Comments
 (0)