Skip to content

[cling] Deduplicate cling::utils::TypeName::GetFullyQualifiedName #19293

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion core/clingutils/src/TClingUtils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaDiagnostic.h"
#include "clang/AST/QualTypeNames.h"

#include "cling/Interpreter/LookupHelper.h"
#include "cling/Interpreter/Transaction.h"
Expand Down Expand Up @@ -3605,7 +3606,10 @@ void ROOT::TMetaUtils::GetFullyQualifiedTypeName(std::string &typenamestr,
const clang::QualType &qtype,
const clang::ASTContext &astContext)
{
std::string fqname = cling::utils::TypeName::GetFullyQualifiedName(qtype, astContext);
clang::PrintingPolicy Policy(astContext.getPrintingPolicy());
Policy.SuppressScope = false;
Policy.AnonymousTagLocations = true;
std::string fqname = clang::TypeName::getFullyQualifiedName(qtype, astContext, Policy, /*WithGlobalNsPrefix=*/false);
TClassEdit::TSplitType splitname(fqname.c_str(),
(TClassEdit::EModType)(TClassEdit::kLong64 | TClassEdit::kDropStd | TClassEdit::kDropStlDefault | TClassEdit::kKeepOuterConst));
splitname.ShortType(typenamestr,TClassEdit::kDropStd | TClassEdit::kDropStlDefault | TClassEdit::kKeepOuterConst);
Expand Down
9 changes: 0 additions & 9 deletions interpreter/cling/include/cling/Utils/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,6 @@ namespace utils {
clang::QualType GetFullyQualifiedType(clang::QualType QT,
const clang::ASTContext& Ctx);

///\brief Get the fully qualified name for a type. This includes full
/// qualification of all template parameters etc.
///
///\param[in] QT - the type for which the fully qualified name will be
/// returned.
///\param[in] Ctx - the ASTContext to be used.
std::string GetFullyQualifiedName(clang::QualType QT,
const clang::ASTContext &Ctx);

///\brief Create a NestedNameSpecifier for Namesp and its enclosing
/// scopes.
///
Expand Down
9 changes: 7 additions & 2 deletions interpreter/cling/lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

#include "clang/AST/ASTContext.h"
#include "clang/AST/GlobalDecl.h"
#include "clang/AST/QualTypeNames.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/CodeGen/ModuleBuilder.h"
Expand Down Expand Up @@ -1349,9 +1350,13 @@ namespace cling {
funcname << "__cling_Destruct_" << RD;

largestream code;
const clang::ASTContext &Context = RD->getASTContext();
clang::PrintingPolicy Policy(Context.getPrintingPolicy());
Policy.SuppressScope = false;
Policy.AnonymousTagLocations = true;
code << "extern \"C\" void " << funcname.str() << "(void* obj){(("
<< utils::TypeName::GetFullyQualifiedName(
clang::QualType(RD->getTypeForDecl(), 0), RD->getASTContext())
<< clang::TypeName::getFullyQualifiedName(
clang::QualType(RD->getTypeForDecl(), 0), Context, Policy, /*WithGlobalNsPrefix=*/false)
<< "*)obj)->~" << RD->getNameAsString() << "();}";

// ifUniq = false: we know it's unique, no need to check.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaDiagnostic.h"
#include "clang/AST/QualTypeNames.h"

using namespace clang;

Expand Down Expand Up @@ -394,8 +395,11 @@ namespace {
locStart, CallArgs, locEnd);
}
else {
clang::PrintingPolicy Policy(m_Context->getPrintingPolicy());
Policy.SuppressScope = false;
Policy.AnonymousTagLocations = true;
m_Sema->Diag(locStart, diag::err_unsupported_unknown_any_decl) <<
utils::TypeName::GetFullyQualifiedName(desugaredTy, *m_Context) <<
clang::TypeName::getFullyQualifiedName(desugaredTy, *m_Context, Policy, /*WithGlobalNsPrefix=*/false) <<
SourceRange(locStart, locEnd);
}
}
Expand Down
22 changes: 17 additions & 5 deletions interpreter/cling/lib/Interpreter/ValuePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "clang/Parse/Parser.h"
#include "clang/Sema/Lookup.h"
#include "clang/Sema/Sema.h"
#include "clang/AST/QualTypeNames.h"

#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/ConvertUTF.h"
Expand Down Expand Up @@ -97,7 +98,10 @@ static std::string enclose(std::string Mid, const char* Begin,
static std::string enclose(const clang::QualType& Ty, clang::ASTContext& C,
const char* Begin = "(", const char* End = "*)",
size_t Hint = 3) {
return enclose(cling::utils::TypeName::GetFullyQualifiedName(Ty, C),
clang::PrintingPolicy Policy(C.getPrintingPolicy());
Policy.SuppressScope = false;
Policy.AnonymousTagLocations = true;
return enclose(clang::TypeName::getFullyQualifiedName(Ty, C, Policy, /*WithGlobalNsPrefix=*/false),
Begin, End, Hint);
}

Expand Down Expand Up @@ -148,16 +152,24 @@ static std::string printQualType(clang::ASTContext& Ctx, clang::QualType QT) {
// std::vector<Type>::iterator is a TemplateSpecializationType
// std::vector<Type>::value_type is a SubstTemplateTypeParmType
//
clang::PrintingPolicy Policy(Ctx.getPrintingPolicy());
Policy.SuppressScope = false;
Policy.AnonymousTagLocations = true;

QualType SSDesugar = TDTy->getLocallyUnqualifiedSingleStepDesugaredType();
if (dyn_cast<SubstTemplateTypeParmType>(SSDesugar))
ValueTyStr += utils::TypeName::GetFullyQualifiedName(QTCanon, Ctx);
ValueTyStr += clang::TypeName::getFullyQualifiedName(QTCanon, Ctx, Policy, /*WithGlobalNsPrefix=*/false);
else if (dyn_cast<TemplateSpecializationType>(SSDesugar))
ValueTyStr += utils::TypeName::GetFullyQualifiedName(QTNonRef, Ctx);
ValueTyStr += clang::TypeName::getFullyQualifiedName(QTNonRef, Ctx, Policy, /*WithGlobalNsPrefix=*/false);
else
ValueTyStr += printDeclType(QTNonRef, TDTy->getDecl());
}
else
ValueTyStr += utils::TypeName::GetFullyQualifiedName(QTNonRef, Ctx);
else {
clang::PrintingPolicy Policy(Ctx.getPrintingPolicy());
Policy.SuppressScope = false;
Policy.AnonymousTagLocations = true;
ValueTyStr += clang::TypeName::getFullyQualifiedName(QTNonRef, Ctx, Policy, /*WithGlobalNsPrefix=*/false);
}
}

if (QT->isReferenceType())
Expand Down
9 changes: 0 additions & 9 deletions interpreter/cling/lib/Utils/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1754,14 +1754,5 @@ namespace utils {
return QT;
}

std::string TypeName::GetFullyQualifiedName(QualType QT,
const ASTContext &Ctx) {
QualType FQQT = GetFullyQualifiedType(QT, Ctx);
PrintingPolicy Policy(Ctx.getPrintingPolicy());
Policy.SuppressScope = false;
Policy.AnonymousTagLocations = false;
return FQQT.getAsString(Policy);
}

} // end namespace utils
} // end namespace cling
Loading