Skip to content
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

cling::ForwardDeclPrinter: skip expr tmplt args #7389

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
2 changes: 1 addition & 1 deletion core/clingutils/res/TClingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ namespace AST2SourceTools {
//______________________________________________________________________________
const std::string Decls2FwdDecls(const std::vector<const clang::Decl*> &decls,
bool (*ignoreFiles)(const clang::PresumedLoc&) ,
const cling::Interpreter& interp);
const cling::Interpreter& interp, std::string *logs);

//______________________________________________________________________________
int PrepareArgsForFwdDecl(std::string& templateArgs,
Expand Down
14 changes: 12 additions & 2 deletions core/clingutils/src/TClingUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5105,7 +5105,10 @@ bool ROOT::TMetaUtils::IsHeaderName(const std::string &filename)

////////////////////////////////////////////////////////////////////////////////

const std::string ROOT::TMetaUtils::AST2SourceTools::Decls2FwdDecls(const std::vector<const clang::Decl *> &decls, cling::Interpreter::IgnoreFilesFunc_t ignoreFiles, const cling::Interpreter &interp)
const std::string ROOT::TMetaUtils::AST2SourceTools::Decls2FwdDecls(const std::vector<const clang::Decl *> &decls,
cling::Interpreter::IgnoreFilesFunc_t ignoreFiles,
const cling::Interpreter &interp,
std::string *logs)
{
clang::Sema &sema = interp.getSema();
cling::Transaction theTransaction(sema);
Expand All @@ -5117,8 +5120,15 @@ const std::string ROOT::TMetaUtils::AST2SourceTools::Decls2FwdDecls(const std::v
}
std::string newFwdDecl;
llvm::raw_string_ostream llvmOstr(newFwdDecl);
interp.forwardDeclare(theTransaction, sema.getPreprocessor(), sema.getASTContext(), llvmOstr, true, nullptr, ignoreFiles);

std::string locallogs;
llvm::raw_string_ostream llvmLogStr(locallogs);
interp.forwardDeclare(theTransaction, sema.getPreprocessor(), sema.getASTContext(), llvmOstr, true,
logs ? &llvmLogStr : nullptr, ignoreFiles);
llvmOstr.flush();
llvmLogStr.flush();
if (logs)
logs->swap(locallogs);
return newFwdDecl;
}

Expand Down
8 changes: 7 additions & 1 deletion core/dictgen/src/rootcling_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3308,10 +3308,16 @@ static std::string GenerateFwdDeclString(const RScanner &scan,
// for (auto* VAR: scan.fSelectedVariables)
// selectedDecls.push_back(VAR);

std::string fwdDeclLogs;

// The "R\"DICTFWDDCLS(\n" ")DICTFWDDCLS\"" pieces have been moved to
// TModuleGenerator to be able to make the diagnostics more telling in presence
// of an issue ROOT-6752.
fwdDeclString += Decls2FwdDecls(selectedDecls,IsLinkdefFile,interp);
fwdDeclString += Decls2FwdDecls(selectedDecls,IsLinkdefFile,interp, genreflex::verbose ? &fwdDeclLogs : nullptr);

if (genreflex::verbose && !fwdDeclLogs.empty())
std::cout << "Logs from forward decl printer: \n"
<< fwdDeclLogs;

// Functions
// for (auto const& fcnDeclPtr : scan.fSelectedFunctions){
Expand Down
40 changes: 40 additions & 0 deletions interpreter/cling/lib/Interpreter/ForwardDeclPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ namespace cling {
QT = utils::TypeName::GetFullyQualifiedType(QT, m_Ctx);
Visit(QT.getTypePtr());
}

void ForwardDeclPrinter::Visit(clang::Decl *D) {
auto Insert = m_Visited.insert(std::pair<const clang::Decl*, bool>(
getCanonicalOrNamespace(D), true));
Expand Down Expand Up @@ -971,6 +972,10 @@ namespace cling {
dyn_cast<TemplateTemplateParmDecl>(Param)) {
Visit(TTPD);
// FIXME: print the default argument, if present.
if (m_SkipFlag) {
skipDecl(TTPD, "template template param decl failed");
return;
}
}
}

Expand Down Expand Up @@ -1080,6 +1085,10 @@ namespace cling {
for (const TemplateArgument& TA: iargs.asArray()) {
VisitTemplateArgument(TA);
}
if (m_SkipFlag) {
skipDecl(D, "template arguments failed");
return;
}

// Out() << "template <> ";
// VisitCXXRecordDecl(D->getCanonicalDecl());
Expand All @@ -1098,6 +1107,10 @@ namespace cling {
Visit(D->getSpecializedTemplate());
//Above code doesn't work properly
//Must find better and more general way to print specializations
if (m_SkipFlag) {
skipDecl(D, "template specialization failed");
return;
}
}


Expand All @@ -1107,6 +1120,10 @@ namespace cling {
#define VISIT_DECL(WHAT, HOW) \
case clang::Type::WHAT: \
Visit(static_cast<const clang::WHAT##Type*>(typ)->HOW().getTypePtr()); \
if (m_SkipFlag) { \
skipDecl(nullptr, #WHAT " type failed"); \
return; \
} \
break
VISIT_DECL(ConstantArray, getElementType);
VISIT_DECL(DependentSizedArray, getElementType);
Expand Down Expand Up @@ -1136,6 +1153,10 @@ namespace cling {
const MemberPointerType* MPT
= static_cast<const MemberPointerType*>(typ);
Visit(MPT->getPointeeType().getTypePtr());
if (m_SkipFlag) {
skipDecl(nullptr, "pointee type failed");
return;
}
Visit(MPT->getClass());
}
break;
Expand All @@ -1152,8 +1173,16 @@ namespace cling {
= static_cast<const TemplateSpecializationType*>(typ);
for (const TemplateArgument& TA: *TST) {
VisitTemplateArgument(TA);
if (m_SkipFlag) {
skipDecl(nullptr, "template argument failed");
return;
}
}
VisitTemplateName(TST->getTemplateName());
if (m_SkipFlag) {
skipDecl(nullptr, "template specialization type failed");
return;
}
}
break;

Expand Down Expand Up @@ -1205,11 +1234,22 @@ namespace cling {
return;
}
}
else {
std::string buf;
{
llvm::raw_string_ostream osbuf(buf);
TAExpr->printPretty(osbuf, nullptr, m_Policy);
}
Log() << "Visit(Type*): cannot forward declare template argument expression: "
<< buf;
skipDecl(nullptr, nullptr);
}
}
break;
default:
Log() << "Visit(Type*): Unexpected TemplateSpecializationType "
<< TA.getKind() << '\n';
skipDecl(nullptr, nullptr);
break;
}
}
Expand Down