Skip to content
Open
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
4 changes: 3 additions & 1 deletion lib/CppInterOp/CppInterOp.td
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ calling dlopen.
}

def ObjToString : CppInterOpAPI {
let Doc = "Tries to load provided objects in a string format (prettyprint).";
let Doc = [{Tries to load provided objects in a string format (prettyprint).
Returns an empty string if the object has no string representation. This is
always the case with clang-repl, which does not implement it yet.}];

let ReturnType = "std::string";
let Args = [
Expand Down
9 changes: 4 additions & 5 deletions lib/CppInterOp/CppInterOpInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,11 +749,10 @@ class Interpreter {
}
}

std::string toString(const char* type, void* obj) {
assert(0 && "toString is not implemented!");
std::string ret;
return ret; // TODO: Implement
}
// FIXME: Implement on top of clang-repl's value printer once it supports
// user-defined types. Until then report "no representation" with an empty
// string, the same way in every build, so callers can fall back.
std::string toString(const char* /*type*/, void* /*obj*/) { return {}; }

CompilationResult undo(unsigned N = 1) {
if (llvm::Error Err = Undo(N)) {
Expand Down
12 changes: 12 additions & 0 deletions unittests/CppInterOp/InterpreterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,18 @@ TYPED_TEST(CPPINTEROP_TEST_MODE, Interpreter_DeclareReportsParseErrors) {
/*silent=*/false));
}

TYPED_TEST(CPPINTEROP_TEST_MODE, Interpreter_ObjToString) {
TestFixture::CreateInterpreter();

int Value = 42;
#ifdef CPPINTEROP_USE_CLING
EXPECT_FALSE(Cpp::ObjToString("int", &Value).empty());
#else
// Not implemented for clang-repl: an empty string, not an abort.
EXPECT_EQ(Cpp::ObjToString("int", &Value), "");
#endif
}

TYPED_TEST(CPPINTEROP_TEST_MODE, Interpreter_EmscriptenExceptionHandling) {
#ifndef EMSCRIPTEN
GTEST_SKIP() << "This test is intended to check exception handling for Emscripten builds.";
Expand Down