aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Interpreter/InterpreterTest.cpp
diff options
context:
space:
mode:
authorVassil Vassilev <v.g.vassilev@gmail.com>2025-07-19 09:25:27 +0300
committerGitHub <noreply@github.com>2025-07-19 09:25:27 +0300
commit9bf7d04c4386daf1ef0acf95782a59855c98474a (patch)
tree3230ebe6ebcb7d0240712c8bcc55fa24fe2c244b /clang/unittests/Interpreter/InterpreterTest.cpp
parentc875bb8eef6c60e7cd5814fdbab149abb86efa30 (diff)
downloadllvm-9bf7d04c4386daf1ef0acf95782a59855c98474a.zip
llvm-9bf7d04c4386daf1ef0acf95782a59855c98474a.tar.gz
llvm-9bf7d04c4386daf1ef0acf95782a59855c98474a.tar.bz2
[clang-repl] Lay the basic infrastructure for pretty printing of types (#148701)
The idea is to store a type-value pair in clang::Value which is updated by the interpreter runtime. The class copies builtin types and boxes non-builtin types to provide some lifetime control. The patch enables default printers for C and C++ using a very minimalistic approach. We handle enums, arrays and user types. Once we land this we can focus on enabling user-defined pretty-printers which take control over printing of types The work started as part of https://reviews.llvm.org/D146809, then we created a giant in https://github.com/llvm/llvm-project/pull/84769
Diffstat (limited to 'clang/unittests/Interpreter/InterpreterTest.cpp')
-rw-r--r--clang/unittests/Interpreter/InterpreterTest.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index b97f5ae..8711f66 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -389,6 +389,26 @@ TEST_F(InterpreterTest, Value) {
EXPECT_TRUE(V9.getType()->isMemberFunctionPointerType());
EXPECT_EQ(V9.getKind(), Value::K_PtrOrObj);
EXPECT_TRUE(V9.isManuallyAlloc());
+
+ Value V10;
+ llvm::cantFail(Interp->ParseAndExecute(
+ "enum D : unsigned int {Zero = 0, One}; One", &V10));
+
+ std::string prettyType;
+ llvm::raw_string_ostream OSType(prettyType);
+ V10.printType(OSType);
+ EXPECT_STREQ(prettyType.c_str(), "D");
+
+ // FIXME: We should print only the value or the constant not the type.
+ std::string prettyData;
+ llvm::raw_string_ostream OSData(prettyData);
+ V10.printData(OSData);
+ EXPECT_STREQ(prettyData.c_str(), "(One) : unsigned int 1");
+
+ std::string prettyPrint;
+ llvm::raw_string_ostream OSPrint(prettyPrint);
+ V10.print(OSPrint);
+ EXPECT_STREQ(prettyPrint.c_str(), "(D) (One) : unsigned int 1\n");
}
TEST_F(InterpreterTest, TranslationUnit_CanonicalDecl) {