From 42fc34de4919b830d51656766521bafbdd7d03f1 Mon Sep 17 00:00:00 2001 From: Joy Vardhan Yalla Date: Sat, 7 Mar 2026 00:11:56 +0530 Subject: [PATCH 1/2] Initialize default PrintingPolicy in CreateInterpreter and reuse ASTContext policy --- lib/CppInterOp/CppInterOp.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index bdeeb5c43..cb0934a56 100644 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -1822,9 +1822,7 @@ TCppType_t GetUnderlyingType(TCppType_t type) { std::string GetTypeAsString(TCppType_t var) { QualType QT = QualType::getFromOpaquePtr(var); // FIXME: Get the default printing policy from the ASTContext. - PrintingPolicy Policy((LangOptions())); - Policy.Bool = true; // Print bool instead of _Bool. - Policy.SuppressTagKeyword = true; // Do not print `class std::string`. + PrintingPolicy Policy = getASTContext().getPrintingPolicy(); Policy.SuppressElaboration = true; Policy.FullyQualifiedName = true; return QT.getAsString(Policy); @@ -2035,9 +2033,8 @@ static void GetDeclName(const clang::Decl* D, ASTContext& Context, std::string& name) { // Helper to extract a fully qualified name from a Decl PrintingPolicy Policy(Context.getPrintingPolicy()); - Policy.SuppressTagKeyword = true; - Policy.SuppressUnwrittenScope = true; Policy.Print_Canonical_Types = true; + if (const TypeDecl* TD = dyn_cast(D)) { // This is a class, struct, or union member. QualType QT; @@ -2054,7 +2051,6 @@ static void GetDeclName(const clang::Decl* D, ASTContext& Context, stream.flush(); } } - void collect_type_info(const FunctionDecl* FD, QualType& QT, std::ostringstream& typedefbuf, std::ostringstream& callbuf, std::string& type_name, @@ -3427,6 +3423,16 @@ TInterp_t CreateInterpreter(const std::vector& Args /*={}*/, )"); sInterpreters->emplace_back(I, /*Owned=*/true); + clang::ASTContext& C = I->getCI()->getASTContext(); + clang::PrintingPolicy Policy = C.getPrintingPolicy(); + + Policy.Bool = true; + Policy.SuppressTagKeyword = true; + Policy.SuppressUnwrittenScope = true; + Policy.AnonymousTagLocations = false; + Policy.SuppressTemplateArgsInCXXConstructors = false; + + C.setPrintingPolicy(Policy); // Define runtime symbols in the JIT dylib for clang-repl #if !defined(CPPINTEROP_USE_CLING) && !defined(EMSCRIPTEN) From 446c49a13385025def61c5ab584624051c34433a Mon Sep 17 00:00:00 2001 From: Joy Vardhan Yalla Date: Sat, 7 Mar 2026 03:52:52 +0530 Subject: [PATCH 2/2] Adjust PrintingPolicy handling after CI failures --- lib/CppInterOp/CppInterOp.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index cb0934a56..04dec3aeb 100644 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -1141,6 +1141,9 @@ std::string GetFunctionSignature(TCppFunction_t func) { std::string Signature; raw_string_ostream SS(Signature); PrintingPolicy Policy = getASTContext().getPrintingPolicy(); + Policy.SuppressUnwrittenScope = false; + Policy.AnonymousTagLocations = true; + Policy.SuppressTemplateArgsInCXXConstructors = true; // Skip printing the body Policy.TerseOutput = true; Policy.FullyQualifiedName = true; @@ -1823,6 +1826,9 @@ std::string GetTypeAsString(TCppType_t var) { QualType QT = QualType::getFromOpaquePtr(var); // FIXME: Get the default printing policy from the ASTContext. PrintingPolicy Policy = getASTContext().getPrintingPolicy(); + Policy.SuppressUnwrittenScope = false; + Policy.AnonymousTagLocations = true; + Policy.SuppressTemplateArgsInCXXConstructors = true; Policy.SuppressElaboration = true; Policy.FullyQualifiedName = true; return QT.getAsString(Policy);