24#include <unordered_set>
27#include "RConfigure.h"
36#include "clang/AST/ASTContext.h"
37#include "clang/AST/Attr.h"
38#include "clang/AST/CXXInheritance.h"
39#include "clang/AST/Decl.h"
40#include "clang/AST/DeclTemplate.h"
41#include "clang/AST/Mangle.h"
42#include "clang/AST/Type.h"
43#include "clang/AST/TypeVisitor.h"
44#include "clang/Frontend/CompilerInstance.h"
45#include "clang/Lex/HeaderSearch.h"
46#include "clang/Lex/ModuleMap.h"
47#include "clang/Lex/Preprocessor.h"
48#include "clang/Lex/PreprocessorOptions.h"
50#include "clang/Sema/Lookup.h"
51#include "clang/Sema/Sema.h"
52#include "clang/Sema/SemaDiagnostic.h"
54#include "cling/Interpreter/LookupHelper.h"
55#include "cling/Interpreter/Transaction.h"
56#include "cling/Interpreter/Interpreter.h"
57#include "cling/Utils/AST.h"
58#include "cling/Interpreter/InterpreterAccessRAII.h"
60#include "llvm/Support/Path.h"
61#include "llvm/Support/FileSystem.h"
66#define strncasecmp _strnicmp
77 llvm::SmallString<256> result_path;
78 llvm::sys::fs::real_path(path, result_path,
true);
79 return result_path.str().str();
86 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
103 bool replace =
false);
113static clang::NestedNameSpecifier *AddDefaultParametersNNS(
const clang::ASTContext& Ctx,
114 clang::NestedNameSpecifier* scope,
115 const cling::Interpreter &interpreter,
117 if (!scope)
return nullptr;
119 const clang::Type* scope_type = scope->getAsType();
122 clang::NestedNameSpecifier* outer_scope = scope->getPrefix();
124 outer_scope = AddDefaultParametersNNS(Ctx, outer_scope, interpreter, normCtxt);
127 clang::QualType addDefault =
130 if (addDefault.getTypePtr() != scope_type)
131 return clang::NestedNameSpecifier::Create(Ctx,outer_scope,
133 addDefault.getTypePtr());
140static bool CheckDefinition(
const clang::CXXRecordDecl *cl,
const clang::CXXRecordDecl *context)
142 if (!cl->hasDefinition()) {
145 "Missing definition for class %s, please #include its header in the header of %s\n",
146 cl->getName().str().c_str(), context->getName().str().c_str());
149 "Missing definition for class %s\n",
150 cl->getName().str().c_str());
162static clang::NestedNameSpecifier *ReSubstTemplateArgNNS(
const clang::ASTContext &Ctxt,
163 clang::NestedNameSpecifier *scope,
166 if (!scope)
return nullptr;
168 const clang::Type* scope_type = scope->getAsType();
170 clang::NestedNameSpecifier* outer_scope = scope->getPrefix();
172 outer_scope = ReSubstTemplateArgNNS(Ctxt, outer_scope,
instance);
174 clang::QualType substScope =
177 scope = clang::NestedNameSpecifier::Create(Ctxt,outer_scope,
179 substScope.getTypePtr());
186static bool IsTypeInt(
const clang::Type *type)
188 const clang::BuiltinType * builtin = llvm::dyn_cast<clang::BuiltinType>(
type->getCanonicalTypeInternal().getTypePtr());
190 return builtin->isInteger();
198static bool IsFieldDeclInt(
const clang::FieldDecl *field)
200 return IsTypeInt(field->getType().getTypePtr());
206static const clang::FieldDecl *GetDataMemberFromAll(
const clang::CXXRecordDecl &cl, llvm::StringRef
what)
208 clang::ASTContext &
C = cl.getASTContext();
209 clang::DeclarationName DName = &
C.Idents.get(
what);
210 auto R = cl.lookup(DName);
211 for (
const clang::NamedDecl *D :
R)
212 if (
auto FD = llvm::dyn_cast<const clang::FieldDecl>(D))
220static const clang::FieldDecl *GetDataMemberFromAllParents(clang::Sema &SemaR,
const clang::CXXRecordDecl &cl,
const char *
what)
222 clang::DeclarationName DName = &SemaR.Context.Idents.get(
what);
223 clang::LookupResult
R(SemaR, DName, clang::SourceLocation(),
224 clang::Sema::LookupOrdinaryName,
225 RedeclarationKind::ForExternalRedeclaration);
226 SemaR.LookupInSuper(
R, &
const_cast<clang::CXXRecordDecl&
>(cl));
229 return llvm::dyn_cast<const clang::FieldDecl>(
R.getFoundDecl());
233cling::LookupHelper::DiagSetting ToLHDS(
bool wantDiags) {
235 ? cling::LookupHelper::WithDiagnostics
236 : cling::LookupHelper::NoDiagnostics;
252 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
253 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
257 const clang::ClassTemplateDecl* canTempl = templ->getCanonicalDecl();
261 const std::string templateName (canTempl->getNameAsString());
262 const std::string i_str (std::to_string(i));
264 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
265 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
266 canTempl->getNameAsString().c_str(),
268 previousArgsToKeep.c_str());
279 const clang::ClassTemplateDecl* constTempl = templ->getCanonicalDecl();
300 return fImpl->GetConfig();
303 return fImpl->GetTypeWithAlternative();
307 return fImpl->AddTemplAndNargsToKeep(templ, i);
311 return fImpl->GetNargsToKeep(templ);
314 return fImpl->GetTemplNargsToKeepMap();
319 return fImpl->keepTypedef(lh,
name, replace);
323 const std::string &normalizedName)
327 if (normalizedName.find(
"Double32_t") != std::string::npos
328 || normalizedName.find(
"Float16_t") != std::string::npos)
330 std::unique_ptr<clang::MangleContext> mangleCtx(rDecl->getASTContext().createMangleContext());
331 std::string mangledName;
333 llvm::raw_string_ostream sstr(mangledName);
334 if (
const clang::TypeDecl* TD = llvm::dyn_cast<clang::TypeDecl>(rDecl)) {
335 mangleCtx->mangleCXXRTTI(clang::QualType(TD->getTypeForDecl(), 0), sstr);
338 if (!mangledName.empty()) {
341 if (mangledName[0] ==
'\01')
342 mangledName.erase(0, 1);
344 if (!errDemangle && demangledTIName) {
345 static const char typeinfoNameFor[] =
" `RTTI Type Descriptor'";
346 if (strstr(demangledTIName, typeinfoNameFor)) {
347 std::string demangledName = demangledTIName;
348 demangledName.erase(demangledName.end() - strlen(typeinfoNameFor), demangledName.end());
351 if (!errDemangle && demangledTIName) {
352 static const char typeinfoNameFor[] =
"typeinfo for ";
353 if (!strncmp(demangledTIName, typeinfoNameFor, strlen(typeinfoNameFor))) {
354 std::string demangledName = demangledTIName + strlen(typeinfoNameFor);
356 free(demangledTIName);
357 return demangledName;
361 "Demangled typeinfo name '%s' does not contain `RTTI Type Descriptor'\n",
365 "Demangled typeinfo name '%s' does not start with 'typeinfo for'\n",
370 free(demangledTIName);
382 const clang::RecordDecl *decl,
385 bool rRequestNoInputOperator,
386 bool rRequestOnlyTClass,
387 int rRequestedVersionNumber,
388 int rRequestedRNTupleSerializationMode,
389 const std::string &rRequestedRNTupleSoARecord,
390 const cling::Interpreter &interpreter,
412 const clang::Type *requestedType,
413 const clang::RecordDecl *decl,
414 const char *requestName,
415 unsigned int nTemplateArgsToSkip,
418 bool rRequestNoInputOperator,
419 bool rRequestOnlyTClass,
420 int rRequestVersionNumber,
421 int rRequestedRNTupleSerializationMode,
422 const std::string &rRequestedRNTupleSoARecord,
423 const cling::Interpreter &interpreter,
444 "Could not remove the requested template arguments.\n");
454 const clang::Type *requestedType,
455 const clang::RecordDecl *decl,
456 const char *requestName,
459 bool rRequestNoInputOperator,
460 bool rRequestOnlyTClass,
461 int rRequestVersionNumber,
462 int rRequestedRNTupleSerializationMode,
463 const std::string &rRequestedRNTupleSoARecord,
464 const cling::Interpreter &interpreter,
491 const clang::RecordDecl *decl,
492 const char *requestName,
495 bool rRequestNoInputOperator,
496 bool rRequestOnlyTClass,
497 int rRequestVersionNumber,
498 int rRequestedRNTupleSerializationMode,
499 const std::string &rRequestedRNTupleSoARecord,
500 const cling::Interpreter &interpreter,
521 if (requestName && requestName[0]) {
536 AutoParse_t autoParse,
bool *shuttingDownPtr,
const int *pgDebug )
554 if (tname.empty())
return false;
575 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
576 clang::QualType t = lh.findType(nameLong, ToLHDS(
WantDiags()));
578 clang::QualType dest = cling::utils::Transform::GetPartiallyDesugaredType(
fInterpreter->getCI()->getASTContext(), t,
fNormalizedCtxt->GetConfig(),
true );
579 if (!dest.isNull() && (dest != t)) {
582 dest.getAsStringInternal(nameLong,
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
590 const std::string &nameLong)
595 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
596 clang::QualType t = lh.findType(nondef.c_str(), ToLHDS(
WantDiags()));
598 clang::QualType dest = cling::utils::Transform::GetPartiallyDesugaredType(
fInterpreter->getCI()->getASTContext(), t,
fNormalizedCtxt->GetConfig(),
true );
599 if (!dest.isNull() && (dest != t) &&
600 nameLong == t.getAsString(
fInterpreter->getCI()->getASTContext().getPrintingPolicy()))
613 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
614 const clang::Decl *scope = lh.findScope(base.c_str(), ToLHDS(
WantDiags()),
nullptr);
621 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(scope);
622 isInlined = nsdecl && nsdecl->isInline();
634 if (tname.empty())
return false;
642 return ! result.empty();
654 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
655 clang::QualType t = lh.findType(tname.c_str(), ToLHDS(
WantDiags()));
662 if (!dest.isNull() && dest != t) {
666 clang::PrintingPolicy policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
667 policy.SuppressTagKeyword =
true;
668 policy.SuppressScope =
true;
674 dest.getAsStringInternal(result, policy);
676 unsigned long offset = 0;
677 if (strncmp(result.c_str(),
"const ", 6) == 0) {
680 if (dropstd && strncmp(result.c_str()+offset,
"std::", 5) == 0) {
681 result.erase(offset,5);
683 for(
unsigned int i = 1; i<result.length(); ++i) {
684 if (result[i]==
's') {
685 if (result[i-1]==
'<' || result[i-1]==
',' || result[i-1]==
' ') {
686 if (dropstd && result.compare(i,5,
"std::",5) == 0) {
691 if (result[i]==
' ') {
692 if (result[i-1] ==
',') {
695 }
else if ( (i+1) < result.length() &&
696 (result[i+1]==
'*' || result[i+1]==
'&' || result[i+1]==
'[') ) {
733 clang::QualType toSkip = lh.findType(
name, cling::LookupHelper::WithDiagnostics);
734 if (
const clang::Type* T = toSkip.getTypePtr()) {
735 const clang::TypedefType *
tt = llvm::dyn_cast<clang::TypedefType>(T);
737 clang::Decl* D =
tt->getDecl();
740 clang::QualType canon = toSkip->getCanonicalTypeInternal();
741 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),T));
761 clang::QualType toSkip = lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
762 if (!toSkip.isNull()) {
763 if (
const clang::TypedefType* TT
764 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
765 fConfig.m_toSkip.insert(TT->getDecl());
767 toSkip = lh.findType(
"std::string", cling::LookupHelper::WithDiagnostics);
768 if (!toSkip.isNull()) {
769 if (
const clang::TypedefType* TT
770 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
771 fConfig.m_toSkip.insert(TT->getDecl());
773 clang::QualType canon = toSkip->getCanonicalTypeInternal();
774 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),toSkip.getTypePtr()));
785 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
786 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
793 const cling::Interpreter& interp)
795 clang::Sema* S = &interp.getSema();
796 const clang::NamedDecl* ND = cling::utils::Lookup::Named(S,
name, cl);
797 if (ND == (clang::NamedDecl*)-1)
798 return (clang::FunctionDecl*)-1;
799 return llvm::dyn_cast_or_null<clang::FunctionDecl>(ND);
805const clang::CXXRecordDecl *
807 bool ,
const clang::Type** resultType)
809 const cling::LookupHelper& lh = interp.getLookupHelper();
812 const clang::CXXRecordDecl *result
813 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
814 (lh.findScope(
name, cling::LookupHelper::NoDiagnostics, resultType));
816 std::string std_name(
"std::");
820 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
821 (lh.findScope(std_name, cling::LookupHelper::NoDiagnostics, resultType));
831 clang::QualType qType(cl->getTypeForDecl(),0);
839 clang::Sema& S = interp.getCI()->getSema();
842 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interp));
843 return S.RequireCompleteType(Loc, Type, clang::diag::err_incomplete_type);
849 const clang::CXXRecordDecl *context,
const cling::Interpreter &interp)
855 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
859 if (!CheckDefinition(cl, context) || !CheckDefinition(base, context)) {
863 if (!base->hasDefinition()) {
867 return cl->isDerivedFrom(base);
879 const clang::NamedDecl *base
883 return IsBase(CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
884 llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext()),interp);
892 const clang::NamedDecl &forcontext,
893 const clang::QualType &qti,
894 const char *R__t,
int rwmode,
895 const cling::Interpreter &interp,
898 static const clang::CXXRecordDecl *TObject_decl
901 kBIT_ISTOBJECT = 0x10000000,
902 kBIT_HASSTREAMER = 0x20000000,
903 kBIT_ISSTRING = 0x40000000,
905 kBIT_ISPOINTER = 0x00001000,
906 kBIT_ISFUNDAMENTAL = 0x00000020,
907 kBIT_ISENUM = 0x00000008
910 const clang::Type &ti( * qti.getTypePtr() );
920 clang::CXXRecordDecl *cxxtype = rawtype->getAsCXXRecordDecl() ;
922 int isTObj = cxxtype && (
IsBase(cxxtype,TObject_decl,
nullptr,interp) || rawname ==
"TObject");
926 if (ti.isPointerType()) kase |= kBIT_ISPOINTER;
927 if (rawtype->isFundamentalType()) kase |= kBIT_ISFUNDAMENTAL;
928 if (rawtype->isEnumeralType()) kase |= kBIT_ISENUM;
931 if (isTObj) kase |= kBIT_ISTOBJECT;
932 if (isStre) kase |= kBIT_HASSTREAMER;
933 if (tiName ==
"string") kase |= kBIT_ISSTRING;
934 if (tiName ==
"string*") kase |= kBIT_ISSTRING;
938 tcl =
" internal error in rootcling ";
943 if (R__t) finalString <<
" " << tiName <<
" " << R__t <<
";" << std::endl;
946 case kBIT_ISFUNDAMENTAL:
948 finalString <<
" R__b >> " << R__t <<
";" << std::endl;
951 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
953 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
962 finalString <<
" Int_t readtemp;" << std::endl
963 <<
" R__b >> readtemp;" << std::endl
964 <<
" " << R__t <<
" = static_cast<" << tiName <<
">(readtemp);" << std::endl;
967 case kBIT_HASSTREAMER:
968 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
970 finalString <<
" " << R__t <<
".Streamer(R__b);" << std::endl;
973 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
976 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
977 if (cxxtype && cxxtype->isAbstract()) {
978 finalString <<
" R__ASSERT(0);// " << objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
980 finalString <<
" " << R__t <<
" = new " << objType <<
";" << std::endl
981 <<
" " << R__t <<
"->Streamer(R__b);" << std::endl;
983 finalString <<
" } else {" << std::endl
984 <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl
985 <<
" }" << std::endl;
990 finalString <<
" {TString R__str;" << std::endl
991 <<
" R__str.Streamer(R__b);" << std::endl
992 <<
" " << R__t <<
" = R__str.Data();}" << std::endl;
995 case kBIT_ISSTRING|kBIT_ISPOINTER:
997 finalString <<
" {TString R__str;" << std::endl
998 <<
" R__str.Streamer(R__b);" << std::endl
999 <<
" " << R__t <<
" = new string(R__str.Data());}" << std::endl;
1002 case kBIT_ISPOINTER:
1003 if (!R__t)
return 1;
1004 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
1008 if (!R__t)
return 1;
1009 finalString <<
" R__b.StreamObject(&" << R__t <<
"," << tcl <<
");" << std::endl;
1017 case kBIT_ISFUNDAMENTAL:
1018 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
1019 if (!R__t)
return 0;
1020 finalString <<
" R__b << " << R__t <<
";" << std::endl;
1024 if (!R__t)
return 0;
1025 finalString <<
" { void *ptr_enum = (void*)&" << R__t <<
";\n";
1026 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
1029 case kBIT_HASSTREAMER:
1030 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
1031 if (!R__t)
return 0;
1032 finalString <<
" ((" << objType <<
"&)" << R__t <<
").Streamer(R__b);" << std::endl;
1035 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
1036 if (!R__t)
return 1;
1037 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
1041 if (!R__t)
return 0;
1042 finalString <<
" {TString R__str(" << R__t <<
".c_str());" << std::endl
1043 <<
" R__str.Streamer(R__b);};" << std::endl;
1046 case kBIT_ISSTRING|kBIT_ISPOINTER:
1047 if (!R__t)
return 0;
1048 finalString <<
" {TString R__str(" << R__t <<
"->c_str());" << std::endl
1049 <<
" R__str.Streamer(R__b);}" << std::endl;
1052 case kBIT_ISPOINTER:
1053 if (!R__t)
return 1;
1054 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
1058 if (!R__t)
return 1;
1059 finalString <<
" R__b.StreamObject((" << objType <<
"*)&" << R__t <<
"," << tcl <<
");" << std::endl;
1071 clang::CXXRecordDecl* ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
1074 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
1076 if (
auto* Ctor = interpreter.getCI()->getSema().LookupDefaultConstructor(ncCl)) {
1077 if (Ctor->getAccess() == clang::AS_public && !Ctor->isDeleted()) {
1090 const char *typeOfArg,
1091 const clang::CXXRecordDecl *expectedArgType,
1092 const cling::Interpreter& interpreter)
1094 if (typeOfArg && !expectedArgType) {
1095 const cling::LookupHelper& lh = interpreter.getLookupHelper();
1098 clang::QualType instanceType = lh.findType(typeOfArg, cling::LookupHelper::WithDiagnostics);
1099 if (!instanceType.isNull())
1100 expectedArgType = instanceType->getAsCXXRecordDecl();
1103 if (!expectedArgType)
1107 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
1108 for (
auto iter = cl->ctor_begin(), end = cl->ctor_end(); iter != end; ++iter)
1110 if ((iter->getAccess() != clang::AS_public) || (iter->getNumParams() != 1))
1114 clang::QualType argType((*iter->param_begin())->getType());
1115 argType = argType.getDesugaredType(cl->getASTContext());
1118 if (argType->isPointerType()) {
1120 argType = argType->getPointeeType();
1121 }
else if (argType->isReferenceType()) {
1123 argType = argType.getNonReferenceType();
1127 argType = argType.getDesugaredType(cl->getASTContext());
1128 const clang::CXXRecordDecl *argDecl = argType->getAsCXXRecordDecl();
1130 if (argDecl->getCanonicalDecl() == expectedArgType->getCanonicalDecl()) {
1131 return ioCtorCategory;
1134 std::string realArg = argType.getAsString();
1135 std::string clarg(
"class ");
1137 if (realArg == clarg)
1138 return ioCtorCategory;
1151 const cling::Interpreter& interpreter)
1153 const char *arg = ioctortype.
GetName();
1155 if (!ioctortype.
GetType() && (!arg || !arg[0])) {
1168 const char *method,
const char *
proto,
1169 const cling::Interpreter &interp,
1172 const clang::FunctionDecl* funcD
1173 = interp.getLookupHelper().findFunctionProto(cinfo, method,
proto,
1174 diagnose ? cling::LookupHelper::WithDiagnostics
1175 : cling::LookupHelper::NoDiagnostics);
1177 return llvm::dyn_cast<const clang::CXXMethodDecl>(funcD);
1189 const cling::LookupHelper& lh = interp.getLookupHelper();
1192 clang::QualType instanceType = lh.findType(type_of_arg, cling::LookupHelper::WithDiagnostics);
1193 if (!instanceType.isNull())
1194 fArgType = instanceType->getAsCXXRecordDecl();
1208 const cling::Interpreter &interp)
1210 if (cl->isAbstract())
return false;
1212 for (
auto & ctorType : ctorTypes) {
1219 std::string
proto( ctorType.GetName() );
1220 bool defaultCtor =
proto.empty();
1232 arg +=
")nullptr )";
1235 const clang::CXXMethodDecl *method
1237 cling::LookupHelper::NoDiagnostics);
1238 if (method && method->getAccess() != clang::AS_public) {
1252 const cling::Interpreter& interp)
1254 if (!cl)
return false;
1256 if (cl->hasUserDeclaredDestructor()) {
1258 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interp));
1259 clang::CXXDestructorDecl *dest = cl->getDestructor();
1261 return (dest->getAccess() == clang::AS_public);
1273 const char *methodname,
1275 const cling::Interpreter &interp,
1278 const clang::CXXMethodDecl *method
1280 diagnose ? cling::LookupHelper::WithDiagnostics
1281 : cling::LookupHelper::NoDiagnostics);
1282 return (method && method->getAccess() == clang::AS_public);
1293 const char *
proto =
"TDirectory*";
1294 const char *
name =
"DirectoryAutoAdd";
1308 const char *
proto =
"TCollection*,TFileMergeInfo*";
1309 const char *
name =
"Merge";
1322 const char *
proto =
"TCollection*";
1323 const char *
name =
"Merge";
1338 const char *
proto =
"TFileMergeInfo*";
1339 const char *
name =
"ResetAfterMerge";
1349 const clang::CXXRecordDecl* clxx,
1350 const cling::Interpreter &interp,
1353 static const char *
proto =
"TBuffer&";
1355 const clang::CXXMethodDecl *method
1357 cling::LookupHelper::NoDiagnostics);
1358 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1360 return (method && method->getDeclContext() == clxx_as_context
1368 const clang::CXXRecordDecl* clxx,
1369 const cling::Interpreter &interp,
1372 static const char *
proto =
"TBuffer&,TClass*";
1374 const clang::CXXMethodDecl *method
1376 cling::LookupHelper::NoDiagnostics);
1377 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1379 return (method && method->getDeclContext() == clxx_as_context
1409 clang::QualType qualType(&
type,0);
1441 llvm::raw_string_ostream stream(qual_name);
1442 clang::PrintingPolicy policy( cl.getASTContext().getPrintingPolicy() );
1443 policy.SuppressTagKeyword =
true;
1444 policy.SuppressUnwrittenScope =
true;
1446 cl.getNameForDiagnostic(stream,policy,
true);
1449 if ( qual_name ==
"(anonymous " || qual_name ==
"(unnamed" ) {
1450 size_t pos = qual_name.find(
':');
1451 qual_name.erase(0,
pos+2);
1467 const clang::Type* declType ( recordDecl.getTypeForDecl() );
1468 clang::QualType qualType(declType,0);
1502 std::stringstream dims;
1503 std::string typenameStr;
1505 const clang::ASTContext& astContext = cl.getASTContext();
1508 for(clang::RecordDecl::field_iterator field_iter = cl.field_begin(), end = cl.field_end();
1516 typenameStr.clear();
1520 clang::QualType fieldType(field_iter->getType());
1521 if (fieldType->isConstantArrayType()) {
1522 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(fieldType.getTypePtr());
1524 dims <<
"[" << arrayType->getSize().getLimitedValue() <<
"]";
1525 fieldType = arrayType->getElementType();
1526 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual());
1536 for(clang::CXXRecordDecl::base_class_const_iterator iter = cl.bases_begin(), end = cl.bases_end();
1539 std::string basename( iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1549 const cling::Interpreter &interp,
1552 return interp.getLookupHelper().findFunctionProto(cinfo, method,
proto,
1553 diagnose ? cling::LookupHelper::WithDiagnostics
1554 : cling::LookupHelper::NoDiagnostics);
1588 clang::SourceLocation sourceLocation = decl->getLocation();
1589 clang::SourceManager& sourceManager = decl->getASTContext().getSourceManager();
1591 if (!sourceLocation.isValid() ) {
1595 if (!sourceLocation.isFileID()) {
1596 sourceLocation = sourceManager.getExpansionRange(sourceLocation).getEnd();
1599 if (sourceLocation.isValid() && sourceLocation.isFileID()) {
1600 return sourceManager.getLineNumber(sourceManager.getFileID(sourceLocation),sourceManager.getFileOffset(sourceLocation));
1613 while (llvm::isa<clang::PointerType>(instanceType.getTypePtr())
1614 || llvm::isa<clang::ReferenceType>(instanceType.getTypePtr()))
1616 instanceType = instanceType->getPointeeType();
1619 const clang::ElaboratedType* etype
1620 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
1622 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
1634 bool result =
false;
1635 const clang::CXXRecordDecl* clxx = instanceType->getAsCXXRecordDecl();
1636 if (clxx && clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1638 const clang::TemplateSpecializationType* TST
1639 = llvm::dyn_cast<const clang::TemplateSpecializationType>(instanceType.getTypePtr());
1646 for (
const clang::TemplateArgument &
TA : TST->template_arguments()) {
1647 if (
TA.getKind() == clang::TemplateArgument::Type) {
1659 const cling::Interpreter &interp,
1662 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1663 if (!clxx || clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return false;
1665 clang::QualType instanceType = interp.getLookupHelper().findType(cl.
GetNormalizedName(),
1666 cling::LookupHelper::WithDiagnostics);
1667 if (instanceType.isNull()) {
1680 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(attribute);
1685 attrString = annAttr->getAnnotation().str();
1695 if (substrFound==std::string::npos) {
1700 attrName = attributeStr.substr(0, EndPart1);
1702 attrValue = attributeStr.substr(EndPart1 + separatorLength);
1710 std::string attrString;
1720 const std::string& propName,
1721 std::string& propValue)
1723 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1724 attrIt!=decl.attr_end();++attrIt){
1725 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1726 if (!annAttr)
continue;
1728 llvm::StringRef attribute = annAttr->getAnnotation();
1729 std::pair<llvm::StringRef,llvm::StringRef> split = attribute.split(
propNames::separator.c_str());
1730 if (split.first != propName.c_str())
continue;
1732 propValue = split.second.str();
1743 const std::string& propName,
1746 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1747 attrIt!=decl.attr_end();++attrIt){
1748 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1749 if (!annAttr)
continue;
1751 llvm::StringRef attribute = annAttr->getAnnotation();
1752 std::pair<llvm::StringRef,llvm::StringRef> split = attribute.split(
propNames::separator.c_str());
1753 if (split.first != propName.c_str())
continue;
1755 return split.second.getAsInteger(10,propValue);
1766 const clang::CXXRecordDecl *decl,
1767 const cling::Interpreter &interp,
1770 bool& needCollectionProxy)
1774 std::string mappedname;
1776 std::string csymbol = classname;
1784 csymbol.insert(0,
"::");
1791 const cling::LookupHelper& lh = interp.getLookupHelper();
1794 bool isStdNotString = isStd && !isString;
1796 finalString <<
"namespace ROOT {" <<
"\n";
1800 finalString <<
" static TClass *" << mappedname.c_str() <<
"_Dictionary();\n"
1801 <<
" static void " << mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1807 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p = nullptr);" <<
"\n";
1811 finalString <<
" static void *newArray_";
1812 finalString << mappedname.c_str();
1813 finalString <<
"(Long_t size, void *p);";
1814 finalString <<
"\n";
1819 finalString <<
" static void delete_" << mappedname.c_str() <<
"(void *p);" <<
"\n" <<
" static void deleteArray_" << mappedname.c_str() <<
"(void *p);" <<
"\n" <<
" static void destruct_" << mappedname.c_str() <<
"(void *p);" <<
"\n";
1822 finalString <<
" static void directoryAutoAdd_" << mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1825 finalString <<
" static void streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1828 finalString <<
" static void conv_streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1831 finalString <<
" static Long64_t merge_" << mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1834 finalString <<
" static void reset_" << mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1841 ROOT::SchemaRuleClassMap_t::iterator rulesIt1 =
ROOT::gReadRules.find( classname.c_str() );
1842 ROOT::SchemaRuleClassMap_t::iterator rulesIt2 =
ROOT::gReadRawRules.find( classname.c_str() );
1853 finalString <<
"\n // Schema evolution read functions\n";
1854 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt1->second.fRules.begin();
1855 while (rIt != rulesIt1->second.fRules.end()) {
1861 std::string error_string;
1863 Warning(
nullptr,
"%s", error_string.c_str());
1864 rIt = rulesIt1->second.fRules.erase(rIt);
1872 if( rIt->find(
"code" ) != rIt->end() ) {
1888 finalString <<
"\n // Schema evolution read raw functions\n";
1889 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt2->second.fRules.begin();
1890 while (rIt != rulesIt2->second.fRules.end()) {
1896 std::string error_string;
1898 Warning(
nullptr,
"%s", error_string.c_str());
1899 rIt = rulesIt2->second.fRules.erase(rIt);
1907 if( rIt->find(
"code" ) == rIt->end() )
1915 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1917 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " << csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1919 finalString <<
" " << csymbol <<
" *ptr = nullptr;" <<
"\n";
1923 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " << csymbol <<
" >(nullptr);" <<
"\n";
1926 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" << csymbol <<
"));" <<
"\n";
1928 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1931 finalString << csymbol <<
"::Class_Version(), ";
1933 finalString <<
"2, ";
1935 finalString <<
"-2, ";
1941 static const char *versionFunc =
"GetClassVersion";
1945 std::string
proto = classname +
"*";
1946 const clang::Decl* ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1947 const clang::FunctionDecl *methodinfo
1949 interp, cling::LookupHelper::NoDiagnostics);
1957 finalString <<
"GetClassVersion< ";
1958 finalString << classname.c_str();
1959 finalString <<
" >(), ";
1967 if (filename.length() > 0) {
1968 for (
unsigned int i=0; i<filename.length(); i++) {
1969 if (filename[i]==
'\\') filename[i]=
'/';
1973 <<
"," <<
"\n" <<
" typeid(" << csymbol
1974 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1977 finalString <<
"&" << csymbol <<
"::Dictionary, ";
1979 finalString <<
"&" << mappedname <<
"_Dictionary, ";
1983 TClassTable__kHasCustomStreamerMember = 0x10
1988 rootflag = rootflag | TClassTable__kHasCustomStreamerMember;
1990 finalString <<
"isa_proxy, " << rootflag <<
"," <<
"\n"
1991 <<
" sizeof(" << csymbol <<
"), alignof(" << csymbol <<
") );" <<
"\n";
1993 finalString <<
" instance.SetNew(&new_" << mappedname.c_str() <<
");" <<
"\n";
1995 finalString <<
" instance.SetNewArray(&newArray_" << mappedname.c_str() <<
");" <<
"\n";
1998 finalString <<
" instance.SetDelete(&delete_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" << mappedname.c_str() <<
");" <<
"\n";
2001 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" << mappedname.c_str() <<
");" <<
"\n";
2005 finalString <<
" instance.SetStreamerFunc(&streamer_" << mappedname.c_str() <<
");" <<
"\n";
2009 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" << mappedname.c_str() <<
");" <<
"\n";
2012 finalString <<
" instance.SetMerge(&merge_" << mappedname.c_str() <<
");" <<
"\n";
2015 finalString <<
" instance.SetResetAfterMerge(&reset_" << mappedname.c_str() <<
");" <<
"\n";
2018 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
2020 needCollectionProxy =
true;
2021 }
else if (stl != 0 &&
2024 int idx = classname.find(
"<");
2026 const char* methodTCP =
nullptr;
2032 methodTCP=
"Pushback";
2035 methodTCP=
"Pushfront";
2041 methodTCP=
"MapInsert";
2054 finalString <<
" static_assert(alignof(" << csymbol <<
"::value_type) <= 4096,\n";
2055 finalString <<
" \"Class with alignment strictly greater than 4096 are currently not supported in "
2056 "CollectionProxy. \"\n";
2057 finalString <<
" \"Please report this case to the developers\");\n";
2058 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" << methodTCP <<
"< " << classNameForIO.c_str() <<
" >()));" <<
"\n";
2060 needCollectionProxy =
true;
2068 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2075 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2093 finalString <<
"\n" <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2097 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" << rulesIt1->second.size() <<
");" <<
"\n";
2099 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
2100 rulesIt1->second.fGenerated =
true;
2104 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" << rulesIt2->second.size() <<
");" <<
"\n";
2106 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
2107 rulesIt2->second.fGenerated =
true;
2110 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
2114 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " << csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal(static_cast<" << csymbol <<
"*>(nullptr));\n }" <<
"\n";
2117 finalString <<
" // Static variable to force the class initialization" <<
"\n";
2121 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal(static_cast<const " << csymbol <<
"*>(nullptr)); R__UseDummy(_R__UNIQUE_DICT_(Init));" <<
"\n";
2124 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n"
2125 <<
" static TClass *" << mappedname <<
"_Dictionary() {\n"
2126 <<
" TClass* theClass ="
2127 <<
"::ROOT::GenerateInitInstanceLocal(static_cast<const " << csymbol <<
"*>(nullptr))->GetClass();\n"
2128 <<
" " << mappedname <<
"_TClassManip(theClass);\n";
2129 finalString <<
" return theClass;\n";
2130 finalString <<
" }\n\n";
2134 std::string manipString;
2135 std::string attribute_s;
2136 std::string attrName, attrValue;
2138 bool attrMapExtracted =
false;
2139 if (decl->hasAttrs()){
2141 for (clang::Decl::attr_iterator attrIt = decl->attr_begin();
2142 attrIt!=decl->attr_end();++attrIt){
2149 if (attrName ==
"name" ||
2150 attrName ==
"pattern" ||
2151 attrName ==
"rootmap")
continue;
2157 if (!attrMapExtracted){
2158 manipString+=
" theClass->CreateAttributeMap();\n";
2159 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
2160 attrMapExtracted=
true;
2162 manipString+=
" attrMap->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2168 for(clang::CXXRecordDecl::decl_iterator internalDeclIt = decl->decls_begin();
2169 internalDeclIt != decl->decls_end(); ++internalDeclIt){
2170 if (!(!(*internalDeclIt)->isImplicit()
2171 && (clang::isa<clang::FieldDecl>(*internalDeclIt) ||
2172 clang::isa<clang::VarDecl>(*internalDeclIt))))
continue;
2175 if (!internalDeclIt->hasAttrs())
continue;
2177 attrMapExtracted =
false;
2178 bool memberPtrCreated =
false;
2180 for (clang::Decl::attr_iterator attrIt = internalDeclIt->attr_begin();
2181 attrIt!=internalDeclIt->attr_end();++attrIt){
2189 clang::NamedDecl* namedInternalDecl = clang::dyn_cast<clang::NamedDecl> (*internalDeclIt);
2190 if (!namedInternalDecl) {
2191 TMetaUtils::Error(
nullptr,
"Cannot convert field declaration to clang::NamedDecl");
2194 const std::string memberName(namedInternalDecl->getName());
2195 const std::string cppMemberName =
"theMember_"+memberName;
2198 const std::string dataMemberCreation=
" TDataMember* "+cppMemberName+
" = theClass->GetDataMember(\""+memberName+
"\");\n";
2211 if (!memberPtrCreated){
2212 manipString+=dataMemberCreation;
2213 memberPtrCreated=
true;
2216 if (!attrMapExtracted){
2217 manipString+=
" "+cppMemberName+
"->CreateAttributeMap();\n";
2218 manipString+=
" TDictAttributeMap* memberAttrMap_"+memberName+
"( theMember_"+memberName+
"->GetAttributeMap() );\n";
2219 attrMapExtracted=
true;
2222 manipString+=
" memberAttrMap_"+memberName+
"->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2229 finalString <<
" static void " << mappedname <<
"_TClassManip(TClass* " << (manipString.empty() ?
"":
"theClass") <<
"){\n"
2234 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2238 std::vector<std::string> &standaloneTargets,
2239 const cling::Interpreter &interp)
2242 if (!rulesIt1.second.fGenerated) {
2243 const clang::Type *typeptr =
nullptr;
2244 const clang::CXXRecordDecl *target =
2247 if (!target && !rulesIt1.second.fTargetDecl) {
2248 auto &&nRules = rulesIt1.second.size();
2249 std::string rule{nRules > 1 ?
"rules" :
"rule"};
2250 std::string verb{nRules > 1 ?
"were" :
"was"};
2252 rulesIt1.first.c_str(), verb.c_str());
2262 std::string mappedname;
2265 finalString <<
"namespace ROOT {" <<
"\n";
2268 finalString <<
"\n // Schema evolution read functions\n";
2269 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt1.second.fRules.begin();
2270 while (rIt != rulesIt1.second.fRules.end()) {
2276 std::string error_string;
2279 rIt = rulesIt1.second.fRules.erase(rIt);
2287 if (rIt->find(
"code") != rIt->end()) {
2295 finalString <<
"} // namespace ROOT" <<
"\n";
2297 standaloneTargets.push_back(rulesIt1.first);
2298 rulesIt1.second.fGenerated =
true;
2304 const std::vector<std::string> &standaloneTargets)
2306 std::string functionname(
"RecordReadRules_");
2307 functionname += dictName;
2309 finalString <<
"namespace ROOT {" <<
"\n";
2310 finalString <<
" // Registration Schema evolution read functions\n";
2311 finalString <<
" int " << functionname <<
"() {" <<
"\n";
2312 if (!standaloneTargets.empty())
2314 <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2315 for (
const auto &target : standaloneTargets) {
2319 ROOT::SchemaRuleClassMap_t::iterator rulesIt1 =
ROOT::gReadRules.find(target.c_str());
2320 finalString <<
" {\n";
2322 finalString <<
" // the io read rules for " << target <<
"\n";
2323 finalString <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" << rulesIt1->second.size()
2326 finalString <<
" TClass::RegisterReadRules(TSchemaRule::kReadRule, \"" <<
name
2327 <<
"\", std::move(readrules));\n";
2328 rulesIt1->second.fGenerated =
true;
2332 finalString <<
"\n // the io read raw rules for " << target <<
"\n";
2333 finalString <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" << rulesIt2->second.size()
2336 finalString <<
" TClass::RegisterReadRules(TSchemaRule::kReadRawRule, \"" <<
name
2337 <<
"\", std::move(readrawrules));\n";
2338 rulesIt2->second.fGenerated =
true;
2340 finalString <<
" }\n";
2342 finalString <<
" return 0;\n";
2343 finalString <<
" }\n";
2344 finalString <<
" static int _R__UNIQUE_DICT_(ReadRules_" << dictName <<
") = " << functionname <<
"();";
2345 finalString <<
"R__UseDummy(_R__UNIQUE_DICT_(ReadRules_" << dictName <<
"));" <<
"\n";
2346 finalString <<
"} // namespace ROOT" <<
"\n";
2356 std::string &clsname,
2357 std::string &nsname,
2358 const clang::CXXRecordDecl *cl)
2368 auto ctxt = cl->getEnclosingNamespaceContext();
2369 while(ctxt && ctxt!=cl && ctxt->isInlineNamespace()) {
2370 ctxt = ctxt->getParent();
2373 const clang::NamedDecl *namedCtxt = llvm::dyn_cast<clang::NamedDecl>(ctxt);
2374 if (namedCtxt && namedCtxt!=cl) {
2375 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(namedCtxt);
2376 if (nsdecl && !nsdecl->isAnonymousNamespace()) {
2378 clsname.erase (0, nsname.size() + 2);
2390 const clang::DeclContext *ctxt = cl.getDeclContext();
2391 while(ctxt && !ctxt->isNamespace()) {
2392 ctxt = ctxt->getParent();
2406 int closing_brackets = 0;
2410 if (ctxt && ctxt->isNamespace()) {
2412 const clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(ctxt);
2418 out <<
"namespace " << ns->getNameAsString() <<
" {" << std::endl;
2423 return closing_brackets;
2437 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2438 if (kind == clang::TSK_Undeclared ) {
2441 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2455 const char *
name = which;
2456 const char *
proto =
"size_t";
2457 const char *protoPlacement =
"size_t,void*";
2460 const clang::FunctionDecl *operatornew
2463 cling::LookupHelper::NoDiagnostics);
2464 const clang::FunctionDecl *operatornewPlacement
2466 name, protoPlacement, interp,
2467 cling::LookupHelper::NoDiagnostics);
2469 const clang::DeclContext *ctxtnew =
nullptr;
2470 const clang::DeclContext *ctxtnewPlacement =
nullptr;
2473 ctxtnew = operatornew->getParent();
2475 if (operatornewPlacement) {
2476 ctxtnewPlacement = operatornewPlacement->getParent();
2482 operatornewPlacement
2487 ctxtnew = operatornew->getParent();
2489 if (operatornewPlacement) {
2490 ctxtnewPlacement = operatornewPlacement->getParent();
2493 if (!ctxtnewPlacement) {
2501 if (ctxtnew == ctxtnewPlacement) {
2505 const clang::CXXRecordDecl* clnew = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnew);
2506 const clang::CXXRecordDecl* clnewPlacement = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnewPlacement);
2507 if (!clnew && !clnewPlacement) {
2513 if (clnew && !clnewPlacement) {
2517 if (!clnew && clnewPlacement) {
2522 if (clnew->isDerivedFrom(clnewPlacement)) {
2552 const clang::CXXRecordDecl *decl,
2553 const cling::Interpreter &interp,
2559 std::string mappedname;
2577 classname.insert(0,
"::");
2580 finalString <<
"namespace ROOT {" <<
"\n";
2585 finalString <<
" // Wrappers around operator new" <<
"\n";
2586 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2588 finalString <<
"new(p) ";
2589 finalString << classname.c_str();
2590 finalString << args;
2591 finalString <<
" : ";
2593 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2594 finalString << classname.c_str();
2595 finalString << args;
2596 finalString <<
" : ";
2598 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2599 finalString <<
" }" <<
"\n";
2603 finalString <<
" static void *newArray_";
2604 finalString << mappedname.c_str();
2605 finalString <<
"(Long_t nElements, void *p) {";
2606 finalString <<
"\n";
2607 finalString <<
" return p ? ";
2609 finalString <<
"new(p) ";
2610 finalString << classname.c_str();
2611 finalString <<
"[nElements] : ";
2613 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2614 finalString << classname.c_str();
2615 finalString <<
"[nElements] : ";
2617 finalString <<
"new ";
2618 finalString << classname.c_str();
2619 finalString <<
"[nElements];";
2620 finalString <<
"\n";
2621 finalString <<
" }";
2622 finalString <<
"\n";
2627 finalString <<
" // Wrapper around operator delete" <<
"\n" <<
" static void delete_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" delete (static_cast<" << classname.c_str() <<
"*>(p));" <<
"\n" <<
" }" <<
"\n" <<
" static void deleteArray_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" delete [] (static_cast<" << classname.c_str() <<
"*>(p));" <<
"\n" <<
" }" <<
"\n" <<
" static void destruct_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" typedef " << classname.c_str() <<
" current_t;" <<
"\n" <<
" (static_cast<current_t*>(p))->~current_t();" <<
"\n" <<
" }" <<
"\n";
2631 finalString <<
" // Wrapper around the directory auto add." <<
"\n" <<
" static void directoryAutoAdd_" << mappedname.c_str() <<
"(void *p, TDirectory *dir) {" <<
"\n" <<
" ((" << classname.c_str() <<
"*)p)->DirectoryAutoAdd(dir);" <<
"\n" <<
" }" <<
"\n";
2635 finalString <<
" // Wrapper around a custom streamer member function." <<
"\n" <<
" static void streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj) {" <<
"\n" <<
" ((" << classname.c_str() <<
"*)obj)->" << classname.c_str() <<
"::Streamer(buf);" <<
"\n" <<
" }" <<
"\n";
2639 finalString <<
" // Wrapper around a custom streamer member function." <<
"\n" <<
" static void conv_streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass *onfile_class) {" <<
"\n" <<
" ((" << classname.c_str() <<
"*)obj)->" << classname.c_str() <<
"::Streamer(buf,onfile_class);" <<
"\n" <<
" }" <<
"\n";
2643 finalString <<
" // Wrapper around the merge function." <<
"\n" <<
" static Long64_t merge_" << mappedname.c_str() <<
"(void *obj,TCollection *coll,TFileMergeInfo *info) {" <<
"\n" <<
" return ((" << classname.c_str() <<
"*)obj)->Merge(coll,info);" <<
"\n" <<
" }" <<
"\n";
2645 finalString <<
" // Wrapper around the merge function." <<
"\n" <<
" static Long64_t merge_" << mappedname.c_str() <<
"(void *obj,TCollection *coll,TFileMergeInfo *) {" <<
"\n" <<
" return ((" << classname.c_str() <<
"*)obj)->Merge(coll);" <<
"\n" <<
" }" <<
"\n";
2649 finalString <<
" // Wrapper around the Reset function." <<
"\n" <<
" static void reset_" << mappedname.c_str() <<
"(void *obj,TFileMergeInfo *info) {" <<
"\n" <<
" ((" << classname.c_str() <<
"*)obj)->ResetAfterMerge(info);" <<
"\n" <<
" }" <<
"\n";
2651 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2658 const cling::Interpreter &interp,
2665 if (version == 0)
return;
2669 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2673 for(clang::CXXRecordDecl::base_class_const_iterator iter = clxx->bases_begin(), end = clxx->bases_end();
2684 for(clang::RecordDecl::field_iterator field_iter = clxx->field_begin(), end = clxx->field_end();
2688 std::string mTypename;
2694 if (!strcmp(shortTypeName,
"string")) {
2716 const clang::Type *rawtype =
m.getType()->getCanonicalTypeInternal().getTypePtr();
2717 if (rawtype->isArrayType()) {
2718 rawtype = rawtype->getBaseElementTypeUnsafe ();
2732 const clang::CXXRecordDecl* CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2741 if (!funcCV)
return -1;
2744 if (funcCV == (clang::FunctionDecl*)-1)
return 1;
2759 using res_t = std::pair<bool, int>;
2761 const clang::CompoundStmt* FuncBody
2762 = llvm::dyn_cast_or_null<clang::CompoundStmt>(funcCV->getBody());
2764 return res_t{
false, -1};
2765 if (FuncBody->size() != 1) {
2769 return res_t{
false, -1};
2771 const clang::ReturnStmt* RetStmt
2772 = llvm::dyn_cast<clang::ReturnStmt>(FuncBody->body_back());
2774 return res_t{
false, -1};
2775 const clang::Expr* RetExpr = RetStmt->getRetValue();
2781 if (
auto RetRes = RetExpr->getIntegerConstantExpr(funcCV->getASTContext())) {
2782 if (RetRes->isSigned())
2783 return res_t{
true, (
Version_t)RetRes->getSExtValue()};
2784 return res_t{
true, (
Version_t)RetRes->getZExtValue()};
2786 return res_t{
false, -1};
2802 clang::QualType
type =
m.getType();
2814 clang::QualType
type = base.getType();
2827 const std::function<
void(
const clang::Module::Header &)> &closure,
2828 bool includeDirectlyUsedModules)
2835 llvm::SetVector<const clang::Module *> modules;
2836 modules.insert(&module);
2837 for (
size_t i = 0; i < modules.size(); ++i) {
2838 const clang::Module *M = modules[i];
2839 for (
const clang::Module *subModule : M->submodules())
2840 modules.insert(subModule);
2843 for (
const clang::Module *
m : modules) {
2844 if (includeDirectlyUsedModules) {
2845 for (clang::Module *used :
m->DirectUses) {
2851 for (
auto HK : {clang::Module::HK_Normal, clang::Module::HK_Textual, clang::Module::HK_Private,
2852 clang::Module::HK_PrivateTextual}) {
2853 const auto &headerList =
m->getHeaders(HK);
2854 for (
const clang::Module::Header &moduleHeader : headerList) {
2855 closure(moduleHeader);
2869 static char t[4096];
2870 static const char* constwd =
"const ";
2871 static const char* constwdend =
"const";
2876 for (s=typeDesc;*s;s++) {
2879 if (lev==0 && *s==
'*')
continue;
2880 if (lev==0 && (strncmp(constwd,s,strlen(constwd))==0
2881 ||strcmp(constwdend,s)==0 ) ) {
2882 s+=strlen(constwd)-1;
2885 if (lev==0 && *s==
' ' && *(s+1)!=
'*') { p = t;
continue;}
2886 if (p - t > (
long)
sizeof(t)) {
2887 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2900 const cling::Interpreter& interp)
2905 if (!comment.empty() && comment[0] ==
'!')
2908 clang::QualType
type =
m.getType();
2910 if (
type->isReferenceType()) {
2915 std::string mTypeName =
type.getAsString(
m.getASTContext().getPrintingPolicy());
2916 if (!strcmp(mTypeName.c_str(),
"string") || !strcmp(mTypeName.c_str(),
"string*")) {
2919 if (!strcmp(mTypeName.c_str(),
"std::string") || !strcmp(mTypeName.c_str(),
"std::string*")) {
2927 const clang::Type *rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
2929 if (rawtype->isPointerType()) {
2931 clang::QualType pointee;
2932 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
2934 rawtype = pointee.getTypePtr();
2938 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2943 const clang::CXXRecordDecl *cxxdecl = rawtype->getAsCXXRecordDecl();
2947 if (version > 0)
return true;
2960 const clang::Type *rawtype =
m.getType().getTypePtr();
2963 clang::QualType pointee;
2964 while ( rawtype->isPointerType() && ((pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull()) && pointee.getTypePtr() != rawtype)
2966 rawtype = pointee.getTypePtr();
2980 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2984 return rawtype->getAsCXXRecordDecl();
2993 const cling::Interpreter &interp,
2995 std::ostream& dictStream,
2997 bool isGenreflex=
false)
2999 const clang::CXXRecordDecl* decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
3001 if (!decl || !decl->isCompleteDefinition()) {
3005 std::string fullname;
3017 (*WriteStreamerFunc)(cl, interp, normCtxt, dictStream, isGenreflex || cl.RequestStreamerInfo());
3019 ROOT::TMetaUtils::Info(
nullptr,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
3041 const cling::Interpreter &interpreter,
3044 const clang::ASTContext& Ctx = interpreter.getCI()->getASTContext();
3046 clang::QualType originalType = instanceType;
3050 if (llvm::isa<clang::PointerType>(instanceType.getTypePtr())) {
3052 clang::Qualifiers quals = instanceType.getQualifiers();
3053 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
3054 if (newPointee != instanceType->getPointeeType()) {
3055 instanceType = Ctx.getPointerType(newPointee);
3057 instanceType = Ctx.getQualifiedType(instanceType, quals);
3059 return instanceType;
3064 if (llvm::isa<clang::ReferenceType>(instanceType.getTypePtr())) {
3066 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(instanceType.getTypePtr());
3067 clang::Qualifiers quals = instanceType.getQualifiers();
3068 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
3070 if (newPointee != instanceType->getPointeeType()) {
3073 instanceType = Ctx.getLValueReferenceType(newPointee);
3075 instanceType = Ctx.getRValueReferenceType(newPointee);
3077 instanceType = Ctx.getQualifiedType(instanceType, quals);
3079 return instanceType;
3083 bool prefix_changed =
false;
3084 clang::NestedNameSpecifier *prefix =
nullptr;
3085 clang::Qualifiers prefix_qualifiers = instanceType.getLocalQualifiers();
3086 const clang::ElaboratedType* etype
3087 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
3090 prefix = AddDefaultParametersNNS(Ctx, etype->getQualifier(), interpreter, normCtxt);
3091 prefix_changed = prefix != etype->getQualifier();
3092 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3098 const clang::TemplateSpecializationType* TST
3099 = llvm::dyn_cast<const clang::TemplateSpecializationType>(instanceType.getTypePtr());
3101 const clang::ClassTemplateSpecializationDecl* TSTdecl
3102 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(instanceType.getTypePtr()->getAsCXXRecordDecl());
3114 bool mightHaveChanged =
false;
3115 if (TST && TSTdecl) {
3117 clang::Sema& S = interpreter.getCI()->getSema();
3118 clang::TemplateDecl *Template = TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
3119 clang::TemplateParameterList *Params = Template->getTemplateParameters();
3120 clang::TemplateParameterList::iterator Param = Params->
begin();
3124 unsigned int dropDefault = normCtxt.
GetConfig().DropDefaultArg(*Template);
3126 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
3127 llvm::SmallVector<clang::TemplateArgument, 4> canonArgs;
3128 llvm::ArrayRef<clang::TemplateArgument> template_arguments = TST->template_arguments();
3129 unsigned int Idecl = 0, Edecl = TSTdecl->getTemplateArgs().size();
3132 if (template_arguments.size() > Edecl) {
3133 Edecl = template_arguments.size();
3135 unsigned int maxAddArg = Edecl - dropDefault;
3136 for (
const clang::TemplateArgument *
I = template_arguments.begin(), *E = template_arguments.end(); Idecl != Edecl;
3137 I != E ? ++
I :
nullptr, ++Idecl, ++Param) {
3141 if (
I->getKind() == clang::TemplateArgument::Template) {
3142 clang::TemplateName templateName =
I->getAsTemplate();
3143 clang::TemplateDecl* templateDecl = templateName.getAsTemplateDecl();
3145 clang::DeclContext* declCtxt = templateDecl->getDeclContext();
3147 if (declCtxt && !templateName.getAsQualifiedTemplateName()){
3148 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(declCtxt);
3149 clang::NestedNameSpecifier* nns;
3151 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx, ns);
3152 }
else if (clang::TagDecl* TD = llvm::dyn_cast<clang::TagDecl>(declCtxt)) {
3153 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx,TD,
false );
3156 desArgs.push_back(*
I);
3159 clang::TemplateName UnderlyingTN(templateDecl);
3160 if (clang::UsingShadowDecl *USD = templateName.getAsUsingShadowDecl())
3161 UnderlyingTN = clang::TemplateName(USD);
3162 clang::TemplateName templateNameWithNSS ( Ctx.getQualifiedTemplateName(nns,
false, UnderlyingTN) );
3163 desArgs.push_back(clang::TemplateArgument(templateNameWithNSS));
3164 mightHaveChanged =
true;
3170 if (
I->getKind() != clang::TemplateArgument::Type) {
3171 desArgs.push_back(*
I);
3175 clang::QualType SubTy =
I->getAsType();
3184 if (SubTy != newSubTy) {
3185 mightHaveChanged =
true;
3186 desArgs.push_back(clang::TemplateArgument(newSubTy));
3188 desArgs.push_back(*
I);
3191 }
else if (!isStdDropDefault && Idecl < maxAddArg) {
3193 mightHaveChanged =
true;
3195 const clang::TemplateArgument& templateArg
3196 = TSTdecl->getTemplateArgs().get(Idecl);
3197 if (templateArg.getKind() != clang::TemplateArgument::Type) {
3198 desArgs.push_back(templateArg);
3201 clang::QualType SubTy = templateArg.getAsType();
3203 clang::SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3204 clang::SourceLocation RAngleLoc = TSTdecl->getSourceRange().getBegin();
3206 clang::TemplateTypeParmDecl *TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*Param);
3209 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
3210 bool HasDefaultArgs;
3211 clang::TemplateArgumentLoc ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
3221 if (ArgType.getArgument().isNull()
3222 || ArgType.getArgument().getKind() != clang::TemplateArgument::Type) {
3224 "Template parameter substitution failed for %s around %s\n",
3225 instanceType.getAsString().c_str(), SubTy.getAsString().c_str());
3228 clang::QualType BetterSubTy = ArgType.getArgument().getAsType();
3229 SubTy = cling::utils::Transform::GetPartiallyDesugaredType(Ctx,BetterSubTy,normCtxt.
GetConfig(),
true);
3232 desArgs.push_back(clang::TemplateArgument(SubTy));
3241 if (mightHaveChanged) {
3242 instanceType = Ctx.getTemplateSpecializationType(TST->getTemplateName(),
3244 TST->getCanonicalTypeInternal());
3248 if (!prefix_changed && !mightHaveChanged)
return originalType;
3250 instanceType = Ctx.getElaboratedType(clang::ElaboratedTypeKeyword::None, prefix, instanceType);
3251 instanceType = Ctx.getQualifiedType(instanceType,prefix_qualifiers);
3253 return instanceType;
3273 llvm::StringRef title;
3276 if (clang::AnnotateAttr *A =
m.getAttr<clang::AnnotateAttr>())
3277 title = A->getAnnotation();
3289 if (errnum) *errnum =
VALID;
3291 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3292 size_t rightbracket = title.find(
']');
3293 if (rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3295 std::string working;
3296 llvm::StringRef indexvar(title.data()+1,rightbracket-1);
3303 size_t indexvarlen = indexvar.size();
3304 for ( i=0; i<indexvarlen; i++) {
3305 if (!isspace(indexvar[i])) {
3306 working += indexvar[i];
3311 const char *tokenlist =
"*+-";
3312 char *current =
const_cast<char*
>(working.c_str());
3313 current = strtok(current,tokenlist);
3317 if (isdigit(current[0])) {
3318 for(i=0;i<strlen(current);i++) {
3319 if (!isdigit(current[i])) {
3324 if (errstr) *errstr = current;
3325 if (errnum) *errnum =
NOT_INT;
3326 return llvm::StringRef();
3331 const clang::CXXRecordDecl *parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext());
3332 const clang::FieldDecl *index1 =
nullptr;
3334 index1 = GetDataMemberFromAll(*parent_clxx, current );
3336 if ( IsFieldDeclInt(index1) ) {
3341 for(clang::RecordDecl::field_iterator field_iter = parent_clxx->field_begin(), end = parent_clxx->field_end();
3345 if ( field_iter->getNameAsString() ==
m.getNameAsString() ) {
3351 if (errstr) *errstr = current;
3352 if (errnum) *errnum =
NOT_DEF;
3353 return llvm::StringRef();
3355 if ( field_iter->getNameAsString() == index1->getNameAsString() ) {
3363 if (errstr) *errstr = current;
3364 if (errnum) *errnum =
NOT_INT;
3365 return llvm::StringRef();
3372 clang::Sema& SemaR =
const_cast<cling::Interpreter&
>(interp).getSema();
3373 index1 = GetDataMemberFromAllParents(SemaR, *parent_clxx, current);
3376 if ( IsFieldDeclInt(index1) ) {
3383 if (errnum) *errnum =
NOT_INT;
3384 if (errstr) *errstr = current;
3388 if (errnum) *errnum =
NOT_INT;
3389 if (errstr) *errstr = current;
3390 return llvm::StringRef();
3392 if ( found && (index1->getAccess() == clang::AS_private) ) {
3395 if (errstr) *errstr = current;
3397 return llvm::StringRef();
3404 if (errstr) *errstr = indexvar;
3405 if (errnum) *errnum =
UNKNOWN;
3406 return llvm::StringRef();
3411 current = strtok(
nullptr, tokenlist);
3427 while((
c = in[i++])) {
3428 const char *repl =
nullptr;
3430 case '+': repl =
"pL";
break;
3431 case '-': repl =
"mI";
break;
3432 case '*': repl =
"mU";
break;
3433 case '/': repl =
"dI";
break;
3434 case '&': repl =
"aN";
break;
3435 case '%': repl =
"pE";
break;
3436 case '|': repl =
"oR";
break;
3437 case '^': repl =
"hA";
break;
3438 case '>': repl =
"gR";
break;
3439 case '<': repl =
"lE";
break;
3440 case '=': repl =
"eQ";
break;
3441 case '~': repl =
"wA";
break;
3442 case '.': repl =
"dO";
break;
3443 case '(': repl =
"oP";
break;
3444 case ')': repl =
"cP";
break;
3445 case '[': repl =
"oB";
break;
3446 case ']': repl =
"cB";
break;
3447 case '{': repl =
"lB";
break;
3448 case '}': repl =
"rB";
break;
3449 case ';': repl =
"sC";
break;
3450 case '#': repl =
"hS";
break;
3451 case '?': repl =
"qM";
break;
3452 case '`': repl =
"bT";
break;
3453 case '!': repl =
"nO";
break;
3454 case ',': repl =
"cO";
break;
3455 case '$': repl =
"dA";
break;
3456 case ' ': repl =
"sP";
break;
3457 case ':': repl =
"cL";
break;
3458 case '"': repl =
"dQ";
break;
3459 case '@': repl =
"aT";
break;
3460 case '\'': repl =
"sQ";
break;
3461 case '\\': repl =
"fI";
break;
3470 if (out.empty() || isdigit(out[0]))
3471 out.insert(out.begin(),
'_');
3474static clang::SourceLocation
3476 clang::SourceLocation sourceLoc) {
3478 if (!sourceLoc.isFileID()) {
3479 return sourceManager.getExpansionRange(sourceLoc).getEnd();
3488 const cling::Interpreter& interp)
3518 using namespace clang;
3519 SourceLocation headerLoc = decl.getLocation();
3521 static const char invalidFilename[] =
"";
3522 if (!headerLoc.isValid())
return invalidFilename;
3524 HeaderSearch& HdrSearch = interp.getCI()->getPreprocessor().getHeaderSearchInfo();
3526 SourceManager& sourceManager = decl.getASTContext().getSourceManager();
3528 FileID headerFID = sourceManager.getFileID(headerLoc);
3529 SourceLocation includeLoc
3531 sourceManager.getIncludeLoc(headerFID));
3533 OptionalFileEntryRef headerFE = sourceManager.getFileEntryRefForID(headerFID);
3534 while (includeLoc.isValid() && sourceManager.isInSystemHeader(includeLoc)) {
3535 ConstSearchDirIterator *foundDir =
nullptr;
3538 assert(headerFE &&
"Couldn't find FileEntry from FID!");
3540 = HdrSearch.LookupFile(llvm::sys::path::filename(headerFE->getName()),
3542 true ,
nullptr, foundDir,
3543 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3551 headerFID = sourceManager.getFileID(includeLoc);
3552 headerFE = sourceManager.getFileEntryRefForID(headerFID);
3557 if (interp.getCI()->getLangOpts().Modules && !headerFE) {
3558 assert(decl.isFirstDecl() &&
"Couldn't trace back include from a decl"
3559 " that is not from an AST file");
3560 assert(StringRef(includeLoc.printToString(sourceManager)).starts_with(
"<module-includes>"));
3564 sourceManager.getIncludeLoc(headerFID));
3567 if (!headerFE)
return invalidFilename;
3569 llvm::SmallString<256> headerFileName(headerFE->getName());
3572 llvm::sys::path::remove_dots(headerFileName,
true);
3583 bool isAbsolute = llvm::sys::path::is_absolute(headerFileName);
3584 clang::OptionalFileEntryRef FELong;
3586 for (llvm::sys::path::const_iterator
3587 IDir = llvm::sys::path::begin(headerFileName),
3588 EDir = llvm::sys::path::end(headerFileName);
3589 !FELong && IDir != EDir; ++IDir) {
3595 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3596 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3597 assert(trailingPart.data() + trailingPart.size()
3598 == headerFileName.data() + headerFileName.size()
3599 &&
"Mismatched partitioning of file name!");
3600 ConstSearchDirIterator* FoundDir =
nullptr;
3601 FELong = HdrSearch.LookupFile(trailingPart, SourceLocation(),
3602 true ,
nullptr, FoundDir,
3603 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3611 return invalidFilename;
3615 for (llvm::sys::path::reverse_iterator
3616 IDir = llvm::sys::path::rbegin(headerFileName),
3617 EDir = llvm::sys::path::rend(headerFileName);
3618 IDir != EDir; ++IDir) {
3619 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3620 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3621 assert(trailingPart.data() + trailingPart.size()
3622 == headerFileName.data() + headerFileName.size()
3623 &&
"Mismatched partitioning of file name!");
3624 ConstSearchDirIterator* FoundDir =
nullptr;
3627 if (HdrSearch.LookupFile(trailingPart, SourceLocation(),
3628 true ,
nullptr, FoundDir,
3629 ArrayRef<std::pair<OptionalFileEntryRef, DirectoryEntryRef>>(),
3632 nullptr,
nullptr ) == FELong) {
3633 return trailingPart.str();
3637 return invalidFilename;
3643 const clang::QualType &qtype,
3644 const clang::ASTContext &astContext)
3646 std::string fqname = cling::utils::TypeName::GetFullyQualifiedName(qtype, astContext);
3655 const clang::QualType &qtype,
3656 const cling::Interpreter &interpreter)
3661 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interpreter));
3665 interpreter.getCI()->getASTContext());
3673 clang::ClassTemplateDecl*& ctd,
3674 clang::ClassTemplateSpecializationDecl*& ctsd)
3676 using namespace clang;
3677 const Type* theType = qt.getTypePtr();
3684 if (theType->isPointerType()) {
3688 if (
const RecordType* rType = llvm::dyn_cast<RecordType>(theType)) {
3689 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(rType->getDecl());
3691 ctd = ctsd->getSpecializedTemplate();
3696 if (
const SubstTemplateTypeParmType* sttpType = llvm::dyn_cast<SubstTemplateTypeParmType>(theType)){
3701 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(qt->getAsCXXRecordDecl());
3703 ctd = ctsd->getSpecializedTemplate();
3718 using namespace clang;
3719 ClassTemplateSpecializationDecl* ctsd;
3720 ClassTemplateDecl* ctd;
3734 using namespace clang;
3735 TemplateName theTemplateName;
3737 const Type* theType = qt.getTypePtr();
3739 if (
const TemplateSpecializationType* tst = llvm::dyn_cast_or_null<const TemplateSpecializationType>(theType)) {
3740 theTemplateName = tst->getTemplateName();
3743 theTemplateName = TemplateName(ctd);
3746 return theTemplateName;
3752 llvm::SmallVectorImpl<clang::TemplateArgument>& preceedingTArgs,
3753 const clang::NamedDecl& tPar,
3754 const cling::Interpreter& interp,
3758 using namespace clang;
3761 TemplateTypeParmDecl* ttpdPtr =
const_cast<TemplateTypeParmDecl*
>(llvm::dyn_cast<TemplateTypeParmDecl>(&tPar));
3762 if (!ttpdPtr)
return false;
3763 if (!ttpdPtr->hasDefaultArgument())
return false;
3766 QualType tParQualType = ttpdPtr->getDefaultArgument().getArgument().getAsType();
3767 const QualType tArgQualType = tArg.getAsType();
3774 if (tParQualType.getTypePtr() == tArgQualType.getTypePtr())
return true;
3785 const clang::ElaboratedType* etype
3786 = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3788 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3789 etype = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3792 const TemplateSpecializationType* tst =
3793 llvm::dyn_cast<TemplateSpecializationType>(tParQualType.getTypePtr());
3798 ClassTemplateSpecializationDecl* TSTdecl
3799 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(tArgQualType->getAsCXXRecordDecl());
3804 TemplateDecl *Template = tst->getTemplateName().getAsTemplateDecl();
3807 SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3810 SourceLocation LAngleLoc = TSTdecl->getSourceRange().getBegin();
3815 TemplateArgument newArg = tArg;
3817 clang::Sema& S = interp.getCI()->getSema();
3818 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interp));
3819 llvm::SmallVector<clang::TemplateArgument, 4> canonArgs;
3820 bool HasDefaultArgs;
3821 TemplateArgumentLoc defTArgLoc = S.SubstDefaultTemplateArgumentIfAvailable(Template,
3830 newArg = defTArgLoc.getArgument();
3831 if (newArg.isNull() ||
3832 newArg.getKind() != clang::TemplateArgument::Type) {
3834 "Template parameter substitution failed!");
3837 ClassTemplateSpecializationDecl* nTSTdecl
3838 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(newArg.getAsType()->getAsCXXRecordDecl());
3841 isEqual = (nTSTdecl && nTSTdecl->getMostRecentDecl() == TSTdecl->getMostRecentDecl()) ||
3842 (tParQualType.getTypePtr() == newArg.getAsType().getTypePtr());
3854 const clang::NamedDecl& tPar)
3856 using namespace clang;
3857 const NonTypeTemplateParmDecl* nttpdPtr = llvm::dyn_cast<NonTypeTemplateParmDecl>(&tPar);
3858 if (!nttpdPtr)
return false;
3859 const NonTypeTemplateParmDecl& nttpd = *nttpdPtr;
3861 if (!nttpd.hasDefaultArgument())
3865 llvm::APSInt defaultValueAPSInt(64,
false);
3866 if (Expr* defArgExpr = nttpd.getDefaultArgument().getArgument().getAsExpr()) {
3867 const ASTContext& astCtxt = nttpdPtr->getASTContext();
3868 if (
auto Value = defArgExpr->getIntegerConstantExpr(astCtxt))
3869 defaultValueAPSInt = *
Value;
3872 const int value = tArg.getAsIntegral().getLimitedValue();
3875 return value == defaultValueAPSInt;
3885 using namespace clang;
3886 if (!nDecl)
return false;
3887 if (
const TemplateTypeParmDecl* ttpd = llvm::dyn_cast<TemplateTypeParmDecl>(nDecl))
3888 return ttpd->hasDefaultArgument();
3889 if (
const NonTypeTemplateParmDecl* nttpd = llvm::dyn_cast<NonTypeTemplateParmDecl>(nDecl))
3890 return nttpd->hasDefaultArgument();
3895static void KeepNParams(clang::QualType& normalizedType,
3896 const clang::QualType& vanillaType,
3897 const cling::Interpreter& interp,
3902 const clang::TemplateArgument &tArg,
3903 const cling::Interpreter& interp,
3905 const clang::ASTContext& astCtxt)
3908 using namespace clang;
3915 if (tArg.getKind() == clang::TemplateArgument::Type) {
3916 QualType thisNormQualType = normTArg.getAsType();
3917 QualType thisArgQualType = tArg.getAsType();
3922 normTArg = TemplateArgument(thisNormQualType);
3923 return (thisNormQualType != thisArgQualType);
3924 }
else if (normTArg.getKind() == clang::TemplateArgument::Pack) {
3925 assert( tArg.getKind() == clang::TemplateArgument::Pack );
3927 SmallVector<TemplateArgument, 2> desArgs;
3928 bool mightHaveChanged =
true;
3929 for (
auto I = normTArg.pack_begin(), E = normTArg.pack_end(),
3930 FI = tArg.pack_begin(), FE = tArg.pack_end();
3931 I != E && FI != FE; ++
I, ++FI)
3933 TemplateArgument pack_arg(*
I);
3935 desArgs.push_back(pack_arg);
3937 if (mightHaveChanged) {
3938 ASTContext &mutableCtx(
const_cast<ASTContext&
>(astCtxt) );
3939 normTArg = TemplateArgument::CreatePackCopy(mutableCtx, desArgs);
3941 return mightHaveChanged;
3952 const clang::QualType& vanillaType,
3953 const cling::Interpreter& interp,
3957 using namespace clang;
3961 ClassTemplateSpecializationDecl* ctsd;
3962 ClassTemplateDecl* ctd;
3969 QualType originalNormalizedType = normalizedType;
3971 const ASTContext& astCtxt = ctsd->getASTContext();
3976 if (llvm::isa<clang::PointerType>(normalizedType.getTypePtr())) {
3978 clang::Qualifiers quals = normalizedType.getQualifiers();
3979 auto valNormalizedType = normalizedType->getPointeeType();
3980 KeepNParams(valNormalizedType,vanillaType, interp, normCtxt);
3981 normalizedType = astCtxt.getPointerType(valNormalizedType);
3983 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3989 if (llvm::isa<clang::ReferenceType>(normalizedType.getTypePtr())) {
3991 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(normalizedType.getTypePtr());
3992 clang::Qualifiers quals = normalizedType.getQualifiers();
3993 auto valNormType = normalizedType->getPointeeType();
3994 KeepNParams(valNormType, vanillaType, interp, normCtxt);
3998 normalizedType = astCtxt.getLValueReferenceType(valNormType);
4000 normalizedType = astCtxt.getRValueReferenceType(valNormType);
4002 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
4007 bool prefix_changed =
false;
4008 clang::NestedNameSpecifier* prefix =
nullptr;
4009 clang::Qualifiers prefix_qualifiers = normalizedType.getLocalQualifiers();
4010 const clang::ElaboratedType* etype
4011 = llvm::dyn_cast<clang::ElaboratedType>(normalizedType.getTypePtr());
4015 prefix = AddDefaultParametersNNS(astCtxt, etype->getQualifier(), interp, normCtxt);
4016 prefix_changed = prefix != etype->getQualifier();
4017 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
4023 const clang::ClassTemplateDecl* ctdWithDefaultArgs = ctd;
4024 for (
const RedeclarableTemplateDecl* rd: ctdWithDefaultArgs->redecls()) {
4025 clang::TemplateParameterList* tpl = rd->getTemplateParameters();
4026 if (tpl->getMinRequiredArguments () < tpl->size()) {
4027 ctdWithDefaultArgs = llvm::dyn_cast<clang::ClassTemplateDecl>(rd);
4032 if (!ctdWithDefaultArgs) {
4033 Error(
"KeepNParams",
"Not found template default arguments\n");
4034 normalizedType=originalNormalizedType;
4038 TemplateParameterList* tParsPtr = ctdWithDefaultArgs->getTemplateParameters();
4039 const TemplateParameterList& tPars = *tParsPtr;
4040 const TemplateArgumentList& tArgs = ctsd->getTemplateArgs();
4044 if (theTemplateName.isNull()) {
4045 normalizedType=originalNormalizedType;
4049 const TemplateSpecializationType* normalizedTst =
4050 llvm::dyn_cast<TemplateSpecializationType>(normalizedType.getTypePtr());
4051 if (!normalizedTst) {
4052 normalizedType=originalNormalizedType;
4056 const clang::ClassTemplateSpecializationDecl* TSTdecl
4057 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(normalizedType.getTypePtr()->getAsCXXRecordDecl());
4065 llvm::SmallVector<TemplateArgument, 4> argsToKeep;
4067 const int nArgs = tArgs.size();
4068 const auto &normArgs = normalizedTst->template_arguments();
4069 const int nNormArgs = normArgs.size();
4071 bool mightHaveChanged =
false;
4072 int latestNonDefaultArg = -1;
4075 for (
int formal = 0, inst = 0; formal != nArgs; ++formal, ++inst) {
4076 const NamedDecl* tParPtr = tPars.getParam(formal);
4078 Error(
"KeepNParams",
"The parameter number %s is null.\n", formal);
4085 if (formal == nNormArgs || inst == nNormArgs)
break;
4087 const TemplateArgument& tArg = tArgs.get(formal);
4088 TemplateArgument normTArg(normArgs[inst]);
4090 bool shouldKeepArg = nArgsToKeep < 0 || inst < nArgsToKeep;
4091 if (isStdDropDefault) shouldKeepArg =
false;
4100 if ( tParPtr->isTemplateParameterPack() ) {
4105 for( ; inst != nNormArgs; ++inst) {
4106 normTArg = normArgs[inst];
4108 argsToKeep.push_back(normTArg);
4111 latestNonDefaultArg = -1;
4115 argsToKeep.push_back(normTArg);
4116 latestNonDefaultArg = formal;
4119 if (!isStdDropDefault) {
4121 mightHaveChanged =
true;
4131 auto argKind = tArg.getKind();
4132 if (argKind == clang::TemplateArgument::Type){
4134 equal =
areEqualTypes(tArg, argsToKeep, *tParPtr, interp, normCtxt);
4135 }
else if (argKind == clang::TemplateArgument::Integral){
4139 argsToKeep.push_back(normTArg);
4141 latestNonDefaultArg = formal;
4144 mightHaveChanged =
true;
4150 if (latestNonDefaultArg >= 0)
4151 argsToKeep.resize(latestNonDefaultArg + 1);
4153 if (!prefix_changed && !mightHaveChanged) {
4154 normalizedType = originalNormalizedType;
4159 if (mightHaveChanged) {
4160 Qualifiers qualifiers = normalizedType.getLocalQualifiers();
4161 normalizedType = astCtxt.getTemplateSpecializationType(theTemplateName,
4163 normalizedType.getTypePtr()->getCanonicalTypeInternal());
4164 normalizedType = astCtxt.getQualifiedType(normalizedType, qualifiers);
4170 normalizedType = astCtxt.getElaboratedType(clang::ElaboratedTypeKeyword::None, prefix, normalizedType);
4171 normalizedType = astCtxt.getQualifiedType(normalizedType,prefix_qualifiers);
4184 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
4187 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interpreter));
4188 clang::QualType normalizedType = cling::utils::Transform::GetPartiallyDesugaredType(ctxt,
type, normCtxt.
GetConfig(),
true );
4196 return normalizedType;
4210 if (
type.isNull()) {
4217 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
4218 clang::PrintingPolicy policy(ctxt.getPrintingPolicy());
4219 policy.SuppressTagKeyword =
true;
4220 policy.SuppressScope =
true;
4221 policy.AnonymousTagLocations =
false;
4226 std::string normalizedNameStep1;
4229 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
4230 normalizedType.getAsStringInternal(normalizedNameStep1,policy);
4248 if (norm_name.length()>2 && norm_name[0]==
':' && norm_name[1]==
':') {
4249 norm_name.erase(0,2);
4257 const clang::TypeDecl* typeDecl,
4258 const cling::Interpreter &interpreter)
4261 const clang::Sema &sema = interpreter.getSema();
4262 clang::ASTContext& astCtxt = sema.getASTContext();
4263 clang::QualType qualType = astCtxt.getTypeDeclType(typeDecl);
4272std::pair<std::string,clang::QualType>
4274 const cling::Interpreter &interpreter,
4278 std::string thisTypeName;
4282 if (!hasChanged)
return std::make_pair(thisTypeName,thisType);
4286 "Name changed from %s to %s\n", thisTypeName.c_str(), thisTypeNameForIO.c_str());
4289 auto& lookupHelper = interpreter.getLookupHelper();
4291 const clang::Type* typePtrForIO;
4292 lookupHelper.findScope(thisTypeNameForIO,
4293 cling::LookupHelper::DiagSetting::NoDiagnostics,
4297 if (!typePtrForIO) {
4299 "Type not found: %s.",thisTypeNameForIO.c_str());
4302 clang::QualType typeForIO(typePtrForIO,0);
4305 if (!typeForIO->isRecordType()) {
4306 return std::make_pair(thisTypeNameForIO,typeForIO);
4309 auto thisDeclForIO = typeForIO->getAsCXXRecordDecl();
4310 if (!thisDeclForIO) {
4312 "The type for IO corresponding to %s is %s and it could not be found in the AST as class.\n", thisTypeName.c_str(), thisTypeNameForIO.c_str());
4313 return std::make_pair(thisTypeName,thisType);
4316 return std::make_pair(thisTypeNameForIO,typeForIO);
4322 const cling::Interpreter &interpreter,
4334 std::string dictFileName(moduleName);
4335 dictFileName +=
"_rdict.pcm";
4336 return dictFileName;
4340 llvm::errs() << llvm::StringRef(commentStart, 80) <<
'\n';
4366 clang::SourceManager& sourceManager = decl.getASTContext().getSourceManager();
4367 clang::SourceLocation sourceLocation = decl.getEndLoc();
4370 sourceLocation = sourceManager.getExpansionRange(sourceLocation).getEnd();
4378 if (!decl.hasOwningModule() && sourceManager.isLoadedSourceLocation(sourceLocation)) {
4384 const char *commentStart = sourceManager.getCharacterData(sourceLocation, &invalid);
4388 bool skipToSemi =
true;
4389 if (
const clang::FunctionDecl* FD = clang::dyn_cast<clang::FunctionDecl>(&decl)) {
4390 if (FD->isImplicit()) {
4394 if (FD->isExplicitlyDefaulted() || FD->isDeletedAsWritten()) {
4398 }
else if (FD->doesThisDeclarationHaveABody()) {
4401 assert((decl.getEndLoc() != sourceLocation || *commentStart ==
'}'
4403 &&
"Expected macro or end of body at '}'");
4404 if (*commentStart) ++commentStart;
4407 while (*commentStart && isspace(*commentStart)
4408 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4411 if (*commentStart ==
';') ++commentStart;
4415 }
else if (
const clang::EnumConstantDecl* ECD
4416 = clang::dyn_cast<clang::EnumConstantDecl>(&decl)) {
4418 if (ECD->getNextDeclInContext())
4419 while (*commentStart && *commentStart !=
',' && *commentStart !=
'\r' && *commentStart !=
'\n')
4427 while (*commentStart && *commentStart !=
';' && *commentStart !=
'\r' && *commentStart !=
'\n')
4429 if (*commentStart ==
';') ++commentStart;
4433 while ( *commentStart && isspace(*commentStart)
4434 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4438 if (commentStart[0] !=
'/' ||
4439 (commentStart[1] !=
'/' && commentStart[1] !=
'*')) {
4449 unsigned int skipChars = 2;
4450 if (commentStart[0] ==
'/' &&
4451 commentStart[1] ==
'/' &&
4452 (commentStart[2] ==
'/' || commentStart[2] ==
'!') &&
4453 commentStart[3] ==
'<') {
4455 }
else if (commentStart[0] ==
'/' &&
4456 commentStart[1] ==
'*' &&
4457 (commentStart[2] ==
'*' || commentStart[2] ==
'!') &&
4458 commentStart[3] ==
'<') {
4462 commentStart += skipChars;
4465 while ( *commentStart && isspace(*commentStart)
4466 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4469 const char* commentEnd = commentStart;
4471 while (*commentEnd && *commentEnd !=
'\n' && *commentEnd !=
'\r') {
4477 while (commentEnd > commentStart && isspace(commentEnd[-1])) {
4483 unsigned offset = commentStart - sourceManager.getCharacterData(sourceLocation);
4484 *loc = sourceLocation.getLocWithOffset(offset - 1);
4487 return llvm::StringRef(commentStart, commentEnd - commentStart);
4495 if (!decl)
return false;
4497 auto& sema = interpreter.getCI()->getSema();
4498 auto maybeMacroLoc = decl->getLocation();
4500 if (!maybeMacroLoc.isMacroID())
return false;
4502 static const std::vector<std::string> signatures =
4503 {
"ClassDef",
"ClassDefOverride",
"ClassDefNV",
"ClassDefInline",
"ClassDefInlineOverride",
"ClassDefInlineNV" };
4505 for (
auto &
name : signatures)
4506 if (sema.findMacroSpelling(maybeMacroLoc,
name))
4520 clang::SourceLocation *loc,
4521 const cling::Interpreter &interpreter)
4523 using namespace clang;
4525 const Decl* DeclFileLineDecl
4526 = interpreter.getLookupHelper().findFunctionProto(&decl,
"DeclFileLine",
"",
4527 cling::LookupHelper::NoDiagnostics);
4531 SourceLocation commentSLoc;
4533 if (comment.size()) {
4540 return llvm::StringRef();
4549 const clang::Type *rawtype =
type.getTypePtr();
4552 if (rawtype->isElaboratedTypeSpecifier() ) {
4553 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4555 if (rawtype->isArrayType()) {
4556 rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
4558 if (rawtype->isPointerType() || rawtype->isReferenceType() ) {
4560 clang::QualType pointee;
4561 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
4563 rawtype = pointee.getTypePtr();
4565 if (rawtype->isElaboratedTypeSpecifier() ) {
4566 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4568 if (rawtype->isArrayType()) {
4569 rawtype = rawtype->getBaseElementTypeUnsafe ();
4573 if (rawtype->isArrayType()) {
4574 rawtype = rawtype->getBaseElementTypeUnsafe ();
4585 if (ctxt.isNamespace() || ctxt.isTranslationUnit())
4587 else if(
const auto parentdecl = llvm::dyn_cast<clang::CXXRecordDecl>(&ctxt))
4600 const clang::DeclContext *ctxt = decl.getDeclContext();
4601 switch (decl.getAccess()) {
4602 case clang::AS_public:
4604 case clang::AS_protected:
4606 case clang::AS_private:
4608 case clang::AS_none:
4612 assert(
false &&
"Unexpected value for the access property value in Clang");
4622 return cling::utils::Analyze::IsStdClass(cl);
4632 if (cling::utils::Analyze::IsStdClass(cl)) {
4633 static const char *names[] =
4634 {
"shared_ptr",
"__shared_ptr",
4635 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4636 llvm::StringRef clname(cl.getName());
4637 for(
auto &&
name : names) {
4638 if (clname ==
name)
return true;
4648 const clang::CXXRecordDecl ¤tCl)
4651 if (&cl == ¤tCl)
return true;
4653 const clang::CXXRecordDecl* previous = currentCl.getPreviousDecl();
4656 if (
nullptr == previous){
4675 const clang::CXXRecordDecl *thisDecl =
4676 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(lh.findScope(typ, cling::LookupHelper::WithDiagnostics));
4680 Error(
"IsOfType",
"Record decl of type %s not found in the AST.", typ.c_str());
4685 const clang::CXXRecordDecl *mostRecentDecl = thisDecl->getMostRecentDecl();
4711 auto *nsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext());
4712 if (cl.getName() !=
"RVec" || nsDecl ==
nullptr || nsDecl->getName() !=
"VecOps")
4715 auto *parentNsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext()->getParent());
4716 if (parentNsDecl ==
nullptr || parentNsDecl->getName() !=
"ROOT")
4724 using namespace clang;
4725 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4726 bool VisitTypedefType(
const TypedefType* TD) {
4729 bool VisitArrayType(
const ArrayType* AT) {
4730 return Visit(AT->getElementType().getTypePtr());
4732 bool VisitDecltypeType(
const DecltypeType* DT) {
4733 return Visit(DT->getUnderlyingType().getTypePtr());
4735 bool VisitPointerType(
const PointerType* PT) {
4736 return Visit(PT->getPointeeType().getTypePtr());
4738 bool VisitReferenceType(
const ReferenceType* RT) {
4739 return Visit(RT->getPointeeType().getTypePtr());
4741 bool VisitSubstTemplateTypeParmType(
const SubstTemplateTypeParmType* STST) {
4742 return Visit(STST->getReplacementType().getTypePtr());
4744 bool VisitTemplateSpecializationType(
const TemplateSpecializationType* TST) {
4745 for (
const TemplateArgument &
TA : TST->template_arguments()) {
4746 if (
TA.getKind() == TemplateArgument::Type && Visit(
TA.getAsType().getTypePtr()))
4751 bool VisitTemplateTypeParmType(
const TemplateTypeParmType* TTPT) {
4754 bool VisitTypeOfType(
const TypeOfType* TOT) {
4755 return TOT->getUnmodifiedType().getTypePtr();
4757 bool VisitElaboratedType(
const ElaboratedType* ET) {
4758 NestedNameSpecifier* NNS = ET->getQualifier();
4760 if (NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4761 if (Visit(NNS->getAsType()))
4764 NNS = NNS->getPrefix();
4766 return Visit(ET->getNamedType().getTypePtr());
4787 using namespace llvm;
4788 using namespace clang;
4789 const clang::ASTContext &Ctxt =
instance->getAsCXXRecordDecl()->getASTContext();
4792 const clang::ElaboratedType* etype
4793 = llvm::dyn_cast<clang::ElaboratedType>(input.getTypePtr());
4797 clang::Qualifiers scope_qualifiers = input.getLocalQualifiers();
4798 assert(
instance->getAsCXXRecordDecl() !=
nullptr &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4800 clang::NestedNameSpecifier *scope = ReSubstTemplateArgNNS(Ctxt,etype->getQualifier(),
instance);
4804 subTy = Ctxt.getElaboratedType(clang::ElaboratedTypeKeyword::None, scope, subTy);
4805 subTy = Ctxt.getQualifiedType(subTy,scope_qualifiers);
4809 QualType QT = input;
4813 if (isa<clang::PointerType>(QT.getTypePtr())) {
4815 Qualifiers quals = QT.getQualifiers();
4818 if (nQT == QT->getPointeeType())
return QT;
4820 QT = Ctxt.getPointerType(nQT);
4822 QT = Ctxt.getQualifiedType(QT, quals);
4828 if (isa<ReferenceType>(QT.getTypePtr())) {
4830 bool isLValueRefTy = isa<LValueReferenceType>(QT.getTypePtr());
4831 Qualifiers quals = QT.getQualifiers();
4834 if (nQT == QT->getPointeeType())
return QT;
4838 QT = Ctxt.getLValueReferenceType(nQT);
4840 QT = Ctxt.getRValueReferenceType(nQT);
4842 QT = Ctxt.getQualifiedType(QT, quals);
4848 if (isa<clang::ArrayType>(QT.getTypePtr())) {
4850 Qualifiers quals = QT.getQualifiers();
4852 if (
const auto arr = dyn_cast<ConstantArrayType>(QT.getTypePtr())) {
4855 if (newQT == arr->getElementType())
return QT;
4856 QT = Ctxt.getConstantArrayType(newQT,
4859 arr->getSizeModifier(),
4860 arr->getIndexTypeCVRQualifiers());
4862 }
else if (
const auto arr = dyn_cast<DependentSizedArrayType>(QT.getTypePtr())) {
4865 if (newQT == QT)
return QT;
4866 QT = Ctxt.getDependentSizedArrayType (newQT,
4868 arr->getSizeModifier(),
4869 arr->getIndexTypeCVRQualifiers(),
4870 arr->getBracketsRange());
4872 }
else if (
const auto arr = dyn_cast<IncompleteArrayType>(QT.getTypePtr())) {
4875 if (newQT == arr->getElementType())
return QT;
4876 QT = Ctxt.getIncompleteArrayType (newQT,
4877 arr->getSizeModifier(),
4878 arr->getIndexTypeCVRQualifiers());
4880 }
else if (
const auto arr = dyn_cast<VariableArrayType>(QT.getTypePtr())) {
4883 if (newQT == arr->getElementType())
return QT;
4884 QT = Ctxt.getVariableArrayType (newQT,
4886 arr->getSizeModifier(),
4887 arr->getIndexTypeCVRQualifiers(),
4888 arr->getBracketsRange());
4892 QT = Ctxt.getQualifiedType(QT, quals);
4897 etype = llvm::dyn_cast<clang::ElaboratedType>(
instance);
4899 instance = etype->getNamedType().getTypePtr();
4903 const clang::TemplateSpecializationType* TST
4904 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instance);
4906 if (!TST)
return input;
4908 const clang::ClassTemplateSpecializationDecl* TSTdecl
4909 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instance->getAsCXXRecordDecl());
4911 if (!TSTdecl)
return input;
4913 const clang::SubstTemplateTypeParmType *substType
4914 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(input.getTypePtr());
4918 const clang::ClassTemplateDecl *replacedCtxt =
nullptr;
4920 const clang::DeclContext *replacedDeclCtxt = substType->getReplacedParameter()->getDeclContext();
4921 const clang::CXXRecordDecl *decl = llvm::dyn_cast<clang::CXXRecordDecl>(replacedDeclCtxt);
4922 unsigned int index = substType->getReplacedParameter()->getIndex();
4925 if (decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4926 const clang::ClassTemplatePartialSpecializationDecl *spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(decl);
4928 unsigned int depth = substType->getReplacedParameter()->getDepth();
4930 const TemplateArgument *instanceArgs = spec->getTemplateArgs().data();
4931 unsigned int instanceNArgs = spec->getTemplateArgs().size();
4935 for(
unsigned int A = 0; A < instanceNArgs; ++A) {
4936 if (instanceArgs[A].getKind() == clang::TemplateArgument::Type) {
4937 clang::QualType argQualType = instanceArgs[A].getAsType();
4939 const clang::TemplateTypeParmType *replacementType;
4941 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(argQualType);
4943 if (!replacementType) {
4944 const clang::SubstTemplateTypeParmType *argType
4945 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(argQualType);
4947 clang::QualType replacementQT = argType->getReplacementType();
4948 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(replacementQT);
4951 if (replacementType &&
4952 depth == replacementType->getDepth() &&
4953 index == replacementType->getIndex() )
4960 replacedCtxt = spec->getSpecializedTemplate();
4962 replacedCtxt = decl->getDescribedClassTemplate();
4964 }
else if (
auto const declguide = llvm::dyn_cast<clang::CXXDeductionGuideDecl>(replacedDeclCtxt)) {
4965 replacedCtxt = llvm::dyn_cast<clang::ClassTemplateDecl>(declguide->getDeducedTemplate());
4966 }
else if (
auto const ctdecl = llvm::dyn_cast<clang::ClassTemplateDecl>(replacedDeclCtxt)) {
4967 replacedCtxt = ctdecl;
4969 std::string astDump;
4970 llvm::raw_string_ostream
ostream(astDump);
4973 ROOT::TMetaUtils::Warning(
"ReSubstTemplateArg",
"Unexpected type of declaration context for template parameter: %s.\n\tThe responsible class is:\n\t%s\n",
4974 replacedDeclCtxt->getDeclKindName(), astDump.c_str());
4975 replacedCtxt =
nullptr;
4978 if (replacedCtxt && replacedCtxt->getCanonicalDecl() == TSTdecl->getSpecializedTemplate()->getCanonicalDecl())
4980 const auto &TAs = TST->template_arguments();
4981 if (index >= TAs.size()) {
4987 }
else if (TAs[index].getKind() == clang::TemplateArgument::Type) {
4988 return TAs[index].getAsType();
4997 const clang::TemplateSpecializationType* inputTST
4998 = llvm::dyn_cast<const clang::TemplateSpecializationType>(input.getTypePtr());
4999 const clang::ASTContext& astCtxt = TSTdecl->getASTContext();
5002 bool mightHaveChanged =
false;
5003 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
5004 for (
const clang::TemplateArgument &
TA : inputTST->template_arguments()) {
5005 if (
TA.getKind() != clang::TemplateArgument::Type) {
5006 desArgs.push_back(
TA);
5010 clang::QualType SubTy =
TA.getAsType();
5012 if (llvm::isa<clang::ElaboratedType>(SubTy)
5013 || llvm::isa<clang::SubstTemplateTypeParmType>(SubTy)
5014 || llvm::isa<clang::TemplateSpecializationType>(SubTy)) {
5016 mightHaveChanged = SubTy != newSubTy;
5017 if (!newSubTy.isNull()) {
5018 desArgs.push_back(clang::TemplateArgument(newSubTy));
5021 desArgs.push_back(
TA);
5025 if (mightHaveChanged) {
5026 clang::Qualifiers qualifiers = input.getLocalQualifiers();
5027 input = astCtxt.getTemplateSpecializationType(inputTST->getTemplateName(),
5029 inputTST->getCanonicalTypeInternal());
5030 input = astCtxt.getQualifiedType(input, qualifiers);
5042 if ( nArgsToRemove == 0 ||
name ==
"")
5047 const unsigned int length =
name.length();
5049 unsigned int nArgsRemoved=0;
5050 unsigned int nBraces=0;
5052 while (nArgsRemoved!=nArgsToRemove && cur<length){
5054 if (
c ==
'<') nBraces++;
5055 if (
c ==
'>') nBraces--;
5056 if (
c ==
',' && nBraces==1 ) nArgsRemoved++;
5070 static const char *stls[] =
5071 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
5072 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",
"RVec",
nullptr};
5086 for (
int k = 1; stls[k]; k++) {
5087 if (
type == stls[k])
5100 TND = TND->getMostRecentDecl();
5101 while (TND && !(TND->hasAttrs()))
5102 TND = TND->getPreviousDecl();
5114 TD = TD->getMostRecentDecl();
5115 while (TD && !(TD->hasAttrs() && TD->isThisDeclarationADefinition()))
5116 TD = TD->getPreviousDecl();
5125 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
5127 const clang::DeclContext* enclosingNamespaceDeclCtxt = decl.getDeclContext();
5128 if (!enclosingNamespaceDeclCtxt)
return;
5130 const clang::NamespaceDecl* enclosingNamespace =
5131 clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
5132 if (!enclosingNamespace)
return;
5134 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
5135 enclosingNamespace->isInline()));
5145 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
5147 const clang::DeclContext* enclosingNamespaceDeclCtxt = ctxt.getParent ();
5150 if (!enclosingNamespaceDeclCtxt) {
5156 const clang::NamespaceDecl* enclosingNamespace = clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
5157 if (!enclosingNamespace)
return;
5160 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
5161 enclosingNamespace->isInline()));
5172 std::list<std::pair<std::string,unsigned int> >& enclosingSc)
5174 const clang::DeclContext* enclosingDeclCtxt = decl.getDeclContext();
5175 if (!enclosingDeclCtxt)
return nullptr;
5177 unsigned int scopeType;
5179 if (
auto enclosingNamespacePtr =
5180 clang::dyn_cast<clang::NamespaceDecl>(enclosingDeclCtxt)){
5181 scopeType= enclosingNamespacePtr->isInline() ? 1 : 0;
5182 enclosingSc.push_back(std::make_pair(enclosingNamespacePtr->getNameAsString(),scopeType));
5186 if (
auto enclosingClassPtr =
5187 clang::dyn_cast<clang::RecordDecl>(enclosingDeclCtxt)){
5188 return enclosingClassPtr;
5200 std::string::size_type beginVar = 0;
5201 std::string::size_type endVar = 0;
5202 while ((beginVar = txt.find(
'$', beginVar)) != std::string::npos
5203 && beginVar + 1 < txt.length()) {
5204 std::string::size_type beginVarName = beginVar + 1;
5205 std::string::size_type endVarName = std::string::npos;
5206 if (txt[beginVarName] ==
'(') {
5208 endVarName = txt.find(
')', beginVarName);
5210 if (endVarName == std::string::npos) {
5212 varname, txt.c_str() + beginVar);
5215 endVar = endVarName + 1;
5218 beginVarName = beginVar + 1;
5219 endVarName = beginVarName;
5220 while (isalnum(txt[endVarName]) || txt[endVarName] ==
'_')
5222 endVar = endVarName;
5225 const char* val = std::getenv(txt.substr(beginVarName,
5226 endVarName - beginVarName).c_str());
5229 txt.replace(beginVar, endVar - beginVar, val);
5230 int lenval = strlen(val);
5231 int delta = lenval - (endVar - beginVar);
5235 beginVar = endVar + 1;
5247 const char* envInclPath = std::getenv(
"ROOT_INCLUDE_PATH");
5253 constexpr char kPathSep =
';';
5255 constexpr char kPathSep =
':';
5258 std::istringstream envInclPathsStream(envInclPath);
5259 std::string inclPath;
5260 while (std::getline(envInclPathsStream, inclPath, kPathSep)) {
5263 if (!inclPath.empty()) {
5264 clingArgs.push_back(
"-I");
5265 clingArgs.push_back(inclPath);
5276 size_t start_pos = 0;
5281 while((start_pos = str.find(from, start_pos)) != std::string::npos) {
5282 str.replace(start_pos, from.length(), to);
5283 start_pos += to.length();
5284 if (recurse) changed =
true;
5300 if (theString.size() < theSubstring.size())
return false;
5301 const unsigned int theSubstringSize = theSubstring.size();
5302 return 0 == theString.compare(theString.size() - theSubstringSize,
5311 if (theString.size() < theSubstring.size())
return false;
5312 const unsigned int theSubstringSize = theSubstring.size();
5313 return 0 == theString.compare(0,
5326 if ((strstr(filename,
"LinkDef") || strstr(filename,
"Linkdef") ||
5327 strstr(filename,
"linkdef")) && strstr(filename,
".h")) {
5330 size_t len = strlen(filename);
5331 size_t linkdeflen = 9;
5333 if (0 == strncasecmp(filename + (len - linkdeflen),
"linkdef", linkdeflen - 2)
5334 && 0 == strcmp(filename + (len - 2),
".h")
5349 return llvm::sys::path::extension(filename) ==
".h" ||
5350 llvm::sys::path::extension(filename) ==
".hh" ||
5351 llvm::sys::path::extension(filename) ==
".hpp" ||
5352 llvm::sys::path::extension(filename) ==
".H" ||
5353 llvm::sys::path::extension(filename) ==
".h++" ||
5354 llvm::sys::path::extension(filename) ==
"hxx" ||
5355 llvm::sys::path::extension(filename) ==
"Hxx" ||
5356 llvm::sys::path::extension(filename) ==
"HXX";
5362 cling::Interpreter::IgnoreFilesFunc_t ignoreFiles,
5363 const cling::Interpreter &interp,
5366 clang::Sema &sema = interp.getSema();
5367 cling::Transaction theTransaction(sema);
5368 std::set<clang::Decl *> addedDecls;
5369 for (
auto decl : decls) {
5371 clang::Decl *ncDecl =
const_cast<clang::Decl *
>(decl);
5372 theTransaction.append(ncDecl);
5374 std::string newFwdDecl;
5375 llvm::raw_string_ostream llvmOstr(newFwdDecl);
5377 std::string locallogs;
5378 llvm::raw_string_ostream llvmLogStr(locallogs);
5379 interp.forwardDeclare(theTransaction, sema.getPreprocessor(), sema.getASTContext(), llvmOstr,
true,
5380 logs ? &llvmLogStr :
nullptr, ignoreFiles);
5384 logs->swap(locallogs);
5396 std::string& defString)
5408 std::string& defString)
5410 std::list<std::pair<std::string,unsigned int> > enclosingNamespaces;
5413 if (rcdPtr)
return rcdPtr;
5416 static const std::string scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5418 std::string scopeName;
5419 std::string scopeContent;
5420 unsigned int scopeIndex;
5421 for (
auto const & encScope : enclosingNamespaces){
5422 scopeIndex = encScope.second;
5423 scopeName = encScope.first;
5424 scopeContent =
" { " + defString +
" }";
5425 defString = scopeType[scopeIndex] +
5447 const clang::TemplateParameterList& tmplParamList,
5448 const cling::Interpreter& interpreter)
5451 for (
auto prmIt = tmplParamList.begin();
5452 prmIt != tmplParamList.end(); prmIt++){
5454 if (prmIt != tmplParamList.begin())
5455 templateArgs +=
", ";
5457 auto nDecl = *prmIt;
5458 std::string typeName;
5461 if (llvm::isa<clang::TemplateTypeParmDecl>(nDecl)){
5462 typeName =
"typename ";
5463 if (nDecl->isParameterPack())
5465 typeName += (*prmIt)->getNameAsString();
5468 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(nDecl)){
5469 auto theType = nttpd->getType();
5472 if (theType.getAsString().find(
"enum") != std::string::npos){
5473 std::string astDump;
5474 llvm::raw_string_ostream
ostream(astDump);
5477 ROOT::TMetaUtils::Warning(
nullptr,
"Forward declarations of templates with enums as template parameters. The responsible class is: %s\n", astDump.c_str());
5486 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(nDecl)){
5489 std::string astDump;
5490 llvm::raw_string_ostream
ostream(astDump);
5493 ROOT::TMetaUtils::Error(
nullptr,
"Cannot reconstruct template template parameter forward declaration for %s\n", astDump.c_str());
5498 templateArgs += typeName;
5509 const cling::Interpreter& interpreter,
5510 std::string& defString)
5512 std::string templatePrefixString;
5513 auto tmplParamList= templDecl.getTemplateParameters();
5514 if (!tmplParamList){
5516 "Cannot extract template parameter list for %s",
5517 templDecl.getNameAsString().c_str());
5524 "Problems with arguments for forward declaration of class %s\n",
5525 templDecl.getNameAsString().c_str());
5528 templatePrefixString =
"template " + templatePrefixString +
" ";
5530 defString = templatePrefixString +
"class ";
5531 if (templDecl.isParameterPack())
5532 defString +=
"... ";
5533 defString += templDecl.getNameAsString();
5534 if (llvm::isa<clang::TemplateTemplateParmDecl>(&templDecl)) {
5548 std::string& argFwdDecl,
5549 const cling::Interpreter& interpreter,
5550 bool acceptStl=
false)
5556 if (clang::TemplateArgument::Type != arg.getKind())
return 0;
5558 auto argQualType = arg.getAsType();
5561 while (llvm::isa<clang::PointerType>(argQualType.getTypePtr())) argQualType = argQualType->getPointeeType();
5563 auto argTypePtr = argQualType.getTypePtr();
5566 if (llvm::isa<clang::EnumType>(argTypePtr)){
5571 if (llvm::isa<clang::BuiltinType>(argTypePtr)){
5576 if (
auto tdTypePtr = llvm::dyn_cast<clang::TypedefType>(argTypePtr)) {
5581 if (
auto argRecTypePtr = llvm::dyn_cast<clang::RecordType>(argTypePtr)){
5583 if (
auto argRecDeclPtr = argRecTypePtr->getDecl()){
5596 const cling::Interpreter& interpreter,
5597 std::string& defString,
5598 const std::string &normalizedName)
5602 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)) {
5603 if (
const auto *specDef = tmplSpecDeclPtr->getDefinition()) {
5604 if (specDef->getTemplateSpecializationKind() != clang::TSK_ExplicitSpecialization)
5608 std::cout <<
" Forward declaring template spec " << normalizedName <<
":\n";
5609 for (
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()) {
5610 std::string argFwdDecl;
5613 std::cout <<
" o Template argument ";
5615 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5617 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5624 defString += argFwdDecl +
'\n';
5626 defString +=
"template <> class " + normalizedName +
';';
5640 const cling::Interpreter& interpreter,
5641 std::string& defString,
5649 if (!recordDecl.getIdentifier())
5653 std::string argsFwdDecl;
5655 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)){
5656 std::string argFwdDecl;
5658 std::cout <<
"Class " << recordDecl.getNameAsString()
5659 <<
" is a template specialisation. Treating its arguments.\n";
5660 for(
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()){
5663 std::cout <<
" o Template argument ";
5665 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5667 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5674 argsFwdDecl+=argFwdDecl;
5678 defString=argsFwdDecl;
5683 if (
auto tmplDeclPtr = tmplSpecDeclPtr->getSpecializedTemplate()){
5686 defString = argsFwdDecl +
"\n" + defString;
5691 defString =
"class " + recordDecl.getNameAsString() +
";";
5692 const clang::RecordDecl* rcd =
EncloseInScopes(recordDecl, defString);
5700 defString = argsFwdDecl +
"\n" + defString;
5711 const cling::Interpreter& interpreter,
5712 std::string& fwdDeclString,
5713 std::unordered_set<std::string>* fwdDeclSetPtr)
5715 std::string buffer = tdnDecl.getNameAsString();
5716 std::string underlyingName;
5717 auto underlyingType = tdnDecl.getUnderlyingType().getCanonicalType();
5718 if (
const clang::TagType* TT
5719 = llvm::dyn_cast<clang::TagType>(underlyingType.getTypePtr())) {
5720 if (clang::NamedDecl* ND = TT->getDecl()) {
5721 if (!ND->getIdentifier()) {
5735 if (underlyingName.find(
">::") != std::string::npos)
5738 buffer=
"typedef "+underlyingName+
" "+buffer+
";";
5750 auto& ctxt = tdnDecl.getASTContext();
5751 auto immediatelyUnderlyingType = underlyingType.getSingleStepDesugaredType(ctxt);
5753 if (
auto underlyingTdnTypePtr = llvm::dyn_cast<clang::TypedefType>(immediatelyUnderlyingType.getTypePtr())){
5754 std::string tdnFwdDecl;
5755 auto underlyingTdnDeclPtr = underlyingTdnTypePtr->getDecl();
5760 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(tdnFwdDecl).second)
5761 fwdDeclString+=tdnFwdDecl;
5762 }
else if (
auto CXXRcdDeclPtr = immediatelyUnderlyingType->getAsCXXRecordDecl()){
5763 std::string classFwdDecl;
5765 std::cout <<
"Typedef " << tdnDecl.getNameAsString() <<
" hides a class: "
5766 << CXXRcdDeclPtr->getNameAsString() << std::endl;
5775 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(classFwdDecl).second)
5776 fwdDeclString+=classFwdDecl;
5779 fwdDeclString+=buffer;
5791 std::string& valAsString,
5792 const clang::PrintingPolicy& ppolicy)
5794 auto defArgExprPtr = par.getDefaultArg();
5795 auto& ctxt = par.getASTContext();
5796 if(!defArgExprPtr->isEvaluatable(ctxt)){
5800 auto defArgType = par.getType();
5803 if (defArgType->isBooleanType()){
5805 defArgExprPtr->EvaluateAsBooleanCondition (result,ctxt);
5806 valAsString=std::to_string(result);
5811 if (defArgType->isIntegerType()){
5812 clang::Expr::EvalResult evalResult;
5813 defArgExprPtr->EvaluateAsInt(evalResult, ctxt);
5814 llvm::APSInt result = evalResult.Val.getInt();
5815 auto uintVal = *result.getRawData();
5816 if (result.isNegative()){
5817 long long int intVal=uintVal*-1;
5818 valAsString=std::to_string(intVal);
5820 valAsString=std::to_string(uintVal);
5827 llvm::raw_string_ostream rso(valAsString);
5828 defArgExprPtr->printPretty(rso,
nullptr,ppolicy);
5829 valAsString = rso.str();
The file contains utilities which are foundational and could be used across the core component of ROO...
#define R(a, b, c, d, e, f, g, h, i)
static Roo_reg_AGKInteg1D instance
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
short Version_t
Class version identifier (short).
static void indent(ostringstream &buf, int indent_level)
static bool RecurseKeepNParams(clang::TemplateArgument &normTArg, const clang::TemplateArgument &tArg, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt, const clang::ASTContext &astCtxt)
static clang::SourceLocation getFinalSpellingLoc(clang::SourceManager &sourceManager, clang::SourceLocation sourceLoc)
const clang::DeclContext * GetEnclosingSpace(const clang::RecordDecl &cl)
bool IsTemplate(const clang::Decl &cl)
static void KeepNParams(clang::QualType &normalizedType, const clang::QualType &vanillaType, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
This function allows to manipulate the number of arguments in the type of a template specialisation.
static void CreateNameTypeMap(const clang::CXXRecordDecl &cl, ROOT::MembersTypeMap_t &nameType)
Create the data member name-type map for given class.
const clang::CXXMethodDecl * GetMethodWithProto(const clang::Decl *cinfo, const char *method, const char *proto, const cling::Interpreter &interp, bool diagnose)
int dumpDeclForAssert(const clang::Decl &D, const char *commentStart)
static void replaceEnvVars(const char *varname, std::string &txt)
Reimplementation of TSystem::ExpandPathName() that cannot be used from TMetaUtils.
static bool areEqualValues(const clang::TemplateArgument &tArg, const clang::NamedDecl &tPar)
std::cout << "Are equal values?\n";
ROOT::TMetaUtils::TNormalizedCtxtImpl TNCtxtFullQual
static bool isTypeWithDefault(const clang::NamedDecl *nDecl)
Check if this NamedDecl is a template parameter with a default argument.
static int TreatSingleTemplateArg(const clang::TemplateArgument &arg, std::string &argFwdDecl, const cling::Interpreter &interpreter, bool acceptStl=false)
static bool areEqualTypes(const clang::TemplateArgument &tArg, llvm::SmallVectorImpl< clang::TemplateArgument > &preceedingTArgs, const clang::NamedDecl &tPar, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
static bool hasSomeTypedefSomewhere(const clang::Type *T)
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
const_iterator begin() const
A RAII helper to remove and readd enclosing _Atomic() It expects no spaces at the beginning or end of...
const std::string & GetPathSeparator()
void WriteSchemaList(std::list< SchemaRuleMap_t > &rules, const std::string &listName, std::ostream &output)
Write schema rules.
std::map< std::string, ROOT::Internal::TSchemaType > MembersTypeMap_t
void WriteReadRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for Read rule, the function name is being written to rule["funcname"].
R__EXTERN SchemaRuleClassMap_t gReadRules
bool HasValidDataMembers(SchemaRuleMap_t &rule, MembersTypeMap_t &members, std::string &error_string)
Check if given rule contains references to valid data members.
void WriteReadRawRuleFunc(SchemaRuleMap_t &rule, int index, std::string &mappedName, MembersTypeMap_t &members, std::ostream &output)
Write the conversion function for ReadRaw rule, the function name is being written to rule["funcname"...
R__EXTERN SchemaRuleClassMap_t gReadRawRules
ROOT::ESTLType STLKind(std::string_view type)
Converts STL container name to number.
bool IsStdClass(const char *type)
return true if the class belongs to the std namespace
std::string GetLong64_Name(const char *original)
Replace 'long long' and 'unsigned long long' by 'Long64_t' and 'ULong64_t'.
ROOT::ESTLType IsSTLCont(std::string_view type)
type : type name: vector<list<classA,allocator>,allocator> result: 0 : not stl container code of cont...
char * DemangleName(const char *mangled_name, int &errorCode)
std::string GetNameForIO(const std::string &templateInstanceName, TClassEdit::EModType mode=TClassEdit::kNone, bool *hasChanged=nullptr)
void GetNormalizedName(std::string &norm_name, std::string_view name)
Return the normalized name.
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset<number> or bitset<number>.
constexpr Double_t C()
Velocity of light in .
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.