24#include <unordered_set>
26#include "RConfigure.h"
34#include "clang/AST/ASTContext.h"
35#include "clang/AST/Attr.h"
36#include "clang/AST/CXXInheritance.h"
37#include "clang/AST/Decl.h"
38#include "clang/AST/DeclTemplate.h"
39#include "clang/AST/Mangle.h"
40#include "clang/AST/Type.h"
41#include "clang/AST/TypeVisitor.h"
42#include "clang/Frontend/CompilerInstance.h"
43#include "clang/Lex/HeaderSearch.h"
44#include "clang/Lex/ModuleMap.h"
45#include "clang/Lex/Preprocessor.h"
46#include "clang/Lex/PreprocessorOptions.h"
48#include "clang/Sema/Sema.h"
49#include "clang/Sema/SemaDiagnostic.h"
51#include "cling/Interpreter/LookupHelper.h"
52#include "cling/Interpreter/Transaction.h"
53#include "cling/Interpreter/Interpreter.h"
54#include "cling/Utils/AST.h"
56#include "llvm/Support/Path.h"
57#include "llvm/Support/FileSystem.h"
60#include "../../../interpreter/llvm/src/tools/clang/lib/Sema/HackForDefaultTemplateArg.h"
65#define strncasecmp _strnicmp
76 llvm::SmallString<256> result_path;
77 llvm::sys::fs::real_path(path, result_path,
true);
78 return result_path.str().str();
85 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
102 bool replace =
false);
112static clang::NestedNameSpecifier *AddDefaultParametersNNS(
const clang::ASTContext& Ctx,
113 clang::NestedNameSpecifier* scope,
114 const cling::Interpreter &interpreter,
116 if (!scope)
return nullptr;
118 const clang::Type* scope_type = scope->getAsType();
121 clang::NestedNameSpecifier* outer_scope = scope->getPrefix();
123 outer_scope = AddDefaultParametersNNS(Ctx, outer_scope, interpreter, normCtxt);
126 clang::QualType addDefault =
129 if (addDefault.getTypePtr() != scope_type)
130 return clang::NestedNameSpecifier::Create(Ctx,outer_scope,
132 addDefault.getTypePtr());
139static bool CheckDefinition(
const clang::CXXRecordDecl *cl,
const clang::CXXRecordDecl *context)
141 if (!cl->hasDefinition()) {
144 "Missing definition for class %s, please #include its header in the header of %s\n",
145 cl->getName().str().c_str(), context->getName().str().c_str());
148 "Missing definition for class %s\n",
149 cl->getName().str().c_str());
161static clang::NestedNameSpecifier *ReSubstTemplateArgNNS(
const clang::ASTContext &Ctxt,
162 clang::NestedNameSpecifier *scope,
163 const clang::Type *instance)
165 if (!scope)
return nullptr;
167 const clang::Type* scope_type = scope->getAsType();
169 clang::NestedNameSpecifier* outer_scope = scope->getPrefix();
171 outer_scope = ReSubstTemplateArgNNS(Ctxt, outer_scope, instance);
173 clang::QualType substScope =
176 scope = clang::NestedNameSpecifier::Create(Ctxt,outer_scope,
178 substScope.getTypePtr());
185static bool IsTypeInt(
const clang::Type *
type)
187 const clang::BuiltinType * builtin = llvm::dyn_cast<clang::BuiltinType>(
type->getCanonicalTypeInternal().getTypePtr());
189 return builtin->isInteger();
197static bool IsFieldDeclInt(
const clang::FieldDecl *field)
199 return IsTypeInt(field->getType().getTypePtr());
205static const clang::FieldDecl *GetDataMemberFromAll(
const clang::CXXRecordDecl &cl, llvm::StringRef
what)
207 for(clang::RecordDecl::field_iterator field_iter = cl.field_begin(), end = cl.field_end();
210 if (field_iter->getName() ==
what) {
219static bool CXXRecordDecl__FindOrdinaryMember(
const clang::CXXBaseSpecifier *Specifier,
220 clang::CXXBasePath &Path,
223 if (!Specifier)
return false;
224 clang::RecordDecl *BaseRecord = Specifier->getType()->getAs<clang::RecordType>()->getDecl();
226 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(BaseRecord);
227 if (!clxx)
return false;
229 const clang::FieldDecl *found = GetDataMemberFromAll(*clxx,(
const char*)Name);
233 clang::NamedDecl* NonConstFD =
const_cast<clang::FieldDecl*
>(found);
234 clang::NamedDecl** BaseSpecFirstHack
235 =
reinterpret_cast<clang::NamedDecl**
>(NonConstFD);
236 Path.Decls = clang::DeclContextLookupResult(llvm::ArrayRef<clang::NamedDecl*>(BaseSpecFirstHack, 1));
261static const clang::FieldDecl *GetDataMemberFromAllParents(
const clang::CXXRecordDecl &cl,
const char *
what)
263 clang::CXXBasePaths Paths;
264 Paths.setOrigin(
const_cast<clang::CXXRecordDecl*
>(&cl));
265 if (cl.lookupInBases([=](
const clang::CXXBaseSpecifier *Specifier, clang::CXXBasePath &Path) {
266 return CXXRecordDecl__FindOrdinaryMember(Specifier, Path, what);}, Paths))
268 clang::CXXBasePaths::paths_iterator iter = Paths.begin();
269 if (iter != Paths.end()) {
271 const clang::FieldDecl *found = (clang::FieldDecl *)iter->Decls.data();
279cling::LookupHelper::DiagSetting ToLHDS(
bool wantDiags) {
281 ? cling::LookupHelper::WithDiagnostics
282 : cling::LookupHelper::NoDiagnostics;
289namespace TMetaUtils {
298 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
299 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
303 const clang::ClassTemplateDecl* canTempl = templ->getCanonicalDecl();
307 const std::string templateName (canTempl->getNameAsString());
308 const std::string i_str (std::to_string(i));
310 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
311 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
312 canTempl->getNameAsString().c_str(),
314 previousArgsToKeep.c_str());
325 const clang::ClassTemplateDecl* constTempl = templ->getCanonicalDecl();
369 const std::string &normalizedName)
373 if (normalizedName.find(
"Double32_t") != std::string::npos
374 || normalizedName.find(
"Float16_t") != std::string::npos)
376 std::unique_ptr<clang::MangleContext> mangleCtx(rDecl->getASTContext().createMangleContext());
377 std::string mangledName;
379 llvm::raw_string_ostream sstr(mangledName);
380 if (
const clang::TypeDecl* TD = llvm::dyn_cast<clang::TypeDecl>(rDecl)) {
381 mangleCtx->mangleCXXRTTI(clang::QualType(TD->getTypeForDecl(), 0), sstr);
384 if (!mangledName.empty()) {
387 if (mangledName[0] ==
'\01')
388 mangledName.erase(0, 1);
390 if (!errDemangle && demangledTIName) {
391 static const char typeinfoNameFor[] =
" `RTTI Type Descriptor'";
392 if (strstr(demangledTIName, typeinfoNameFor)) {
393 std::string demangledName = demangledTIName;
394 demangledName.erase(demangledName.end() - strlen(typeinfoNameFor), demangledName.end());
397 if (!errDemangle && demangledTIName) {
398 static const char typeinfoNameFor[] =
"typeinfo for ";
399 if (!strncmp(demangledTIName, typeinfoNameFor, strlen(typeinfoNameFor))) {
400 std::string demangledName = demangledTIName + strlen(typeinfoNameFor);
402 free(demangledTIName);
403 return demangledName;
407 "Demangled typeinfo name '%s' does not contain `RTTI Type Descriptor'\n",
411 "Demangled typeinfo name '%s' does not start with 'typeinfo for'\n",
416 free(demangledTIName);
427 const clang::RecordDecl *decl,
430 bool rRequestNoInputOperator,
431 bool rRequestOnlyTClass,
432 int rRequestedVersionNumber,
433 const cling::Interpreter &interpreter,
446 const clang::Type *requestedType,
447 const clang::RecordDecl *decl,
448 const char *requestName,
449 unsigned int nTemplateArgsToSkip,
452 bool rRequestNoInputOperator,
453 bool rRequestOnlyTClass,
454 int rRequestVersionNumber,
455 const cling::Interpreter &interpreter,
457 fRuleIndex(index), fDecl(decl), fRequestedName(
""), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer),
458 fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestVersionNumber)
467 "Could not remove the requested template arguments.\n");
476 const clang::Type *requestedType,
477 const clang::RecordDecl *decl,
478 const char *requestName,
481 bool rRequestNoInputOperator,
482 bool rRequestOnlyTClass,
483 int rRequestVersionNumber,
484 const cling::Interpreter &interpreter,
486 fRuleIndex(index), fDecl(decl), fRequestedName(
""), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer),
487 fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestVersionNumber)
501 const clang::RecordDecl *decl,
502 const char *requestName,
505 bool rRequestNoInputOperator,
506 bool rRequestOnlyTClass,
507 int rRequestVersionNumber,
508 const cling::Interpreter &interpreter,
510 fRuleIndex(index), fDecl(decl), fRequestedName(
""), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer), fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestVersionNumber)
519 if (requestName && requestName[0]) {
534 ExistingTypeCheck_t existingTypeCheck,
535 AutoParse_t autoParse,
536 bool *shuttingDownPtr,
537 const int* pgDebug ):
538 fInterpreter(&interpreter),fNormalizedCtxt(&normCtxt),
539 fExistingTypeCheck(existingTypeCheck),
540 fAutoParse(autoParse),
541 fInterpreterIsShuttingDownPtr(shuttingDownPtr),
553 if (tname.empty())
return false;
563 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
564 clang::QualType t = lh.findType(nameLong, ToLHDS(
WantDiags()));
567 if (!
dest.isNull() && (
dest != t)) {
570 dest.getAsStringInternal(nameLong,
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
578 const std::string &nameLong)
580 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
581 clang::QualType t = lh.findType(nondef.c_str(), ToLHDS(
WantDiags()));
584 if (!
dest.isNull() && (
dest != t) &&
585 nameLong == t.getAsString(
fInterpreter->getCI()->getASTContext().getPrintingPolicy()))
595 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
596 const clang::Decl *scope = lh.findScope(base.c_str(), ToLHDS(
WantDiags()), 0);
603 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(scope);
604 isInlined = nsdecl && nsdecl->isInline();
616 if (tname.empty())
return false;
624 return ! result.empty();
633 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
634 clang::QualType t = lh.findType(tname.c_str(), ToLHDS(
WantDiags()));
645 clang::PrintingPolicy policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
646 policy.SuppressTagKeyword =
true;
647 policy.SuppressScope =
true;
653 dest.getAsStringInternal(result, policy);
655 unsigned long offset = 0;
656 if (strncmp(result.c_str(),
"const ", 6) == 0) {
659 if (dropstd && strncmp(result.c_str()+offset,
"std::", 5) == 0) {
660 result.erase(offset,5);
662 for(
unsigned int i = 1; i<result.length(); ++i) {
663 if (result[i]==
's') {
664 if (result[i-1]==
'<' || result[i-1]==
',' || result[i-1]==
' ') {
665 if (dropstd && result.compare(i,5,
"std::",5) == 0) {
670 if (result[i]==
' ') {
671 if (result[i-1] ==
',') {
674 }
else if ( (i+1) < result.length() &&
675 (result[i+1]==
'*' || result[i+1]==
'&' || result[i+1]==
'[') ) {
712 clang::QualType toSkip = lh.findType(
name, cling::LookupHelper::WithDiagnostics);
713 if (
const clang::Type* T = toSkip.getTypePtr()) {
714 const clang::TypedefType *
tt = llvm::dyn_cast<clang::TypedefType>(T);
716 clang::Decl* D =
tt->getDecl();
717 fConfig.m_toSkip.insert(D);
719 clang::QualType canon = toSkip->getCanonicalTypeInternal();
720 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),T));
722 fTypeWithAlternative.insert(T);
735 keepTypedef(lh,
"Double32_t");
736 keepTypedef(lh,
"Float16_t");
737 keepTypedef(lh,
"Long64_t",
true);
738 keepTypedef(lh,
"ULong64_t",
true);
740 clang::QualType toSkip = lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
741 if (!toSkip.isNull()) {
742 if (
const clang::TypedefType* TT
743 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
744 fConfig.m_toSkip.insert(TT->getDecl());
746 toSkip = lh.findType(
"std::string", cling::LookupHelper::WithDiagnostics);
747 if (!toSkip.isNull()) {
748 if (
const clang::TypedefType* TT
749 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
750 fConfig.m_toSkip.insert(TT->getDecl());
752 clang::QualType canon = toSkip->getCanonicalTypeInternal();
753 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),toSkip.getTypePtr()));
764 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
765 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
772 const cling::Interpreter& interp)
774 clang::Sema* S = &interp.getSema();
775 const clang::NamedDecl* ND = cling::utils::Lookup::Named(S,
name, cl);
776 if (ND == (clang::NamedDecl*)-1)
777 return (clang::FunctionDecl*)-1;
778 return llvm::dyn_cast_or_null<clang::FunctionDecl>(ND);
784const clang::CXXRecordDecl *
786 bool ,
const clang::Type** resultType)
788 const cling::LookupHelper& lh = interp.getLookupHelper();
791 const clang::CXXRecordDecl *result
792 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
793 (lh.findScope(
name, cling::LookupHelper::NoDiagnostics, resultType));
795 std::string std_name(
"std::");
799 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
800 (lh.findScope(std_name, cling::LookupHelper::NoDiagnostics, resultType));
810 clang::QualType qType(cl->getTypeForDecl(),0);
818 clang::Sema& S = interp.getCI()->getSema();
821 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interp));
822 return S.RequireCompleteType(Loc, Type, clang::diag::err_incomplete_type);
828 const clang::CXXRecordDecl *context,
const cling::Interpreter &interp)
834 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
838 if (!CheckDefinition(cl, context) || !CheckDefinition(base, context)) {
842 if (!base->hasDefinition()) {
846 return cl->isDerivedFrom(base);
858 const clang::NamedDecl *base
862 return IsBase(CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
863 llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext()),interp);
871 const clang::NamedDecl &forcontext,
872 const clang::QualType &qti,
873 const char *R__t,
int rwmode,
874 const cling::Interpreter &interp,
877 static const clang::CXXRecordDecl *TObject_decl
880 kBIT_ISTOBJECT = 0x10000000,
881 kBIT_HASSTREAMER = 0x20000000,
882 kBIT_ISSTRING = 0x40000000,
884 kBIT_ISPOINTER = 0x00001000,
885 kBIT_ISFUNDAMENTAL = 0x00000020,
886 kBIT_ISENUM = 0x00000008
889 const clang::Type &ti( * qti.getTypePtr() );
899 clang::CXXRecordDecl *cxxtype = rawtype->getAsCXXRecordDecl() ;
901 int isTObj = cxxtype && (
IsBase(cxxtype,TObject_decl,
nullptr,interp) || rawname ==
"TObject");
905 if (ti.isPointerType()) kase |= kBIT_ISPOINTER;
906 if (rawtype->isFundamentalType()) kase |= kBIT_ISFUNDAMENTAL;
907 if (rawtype->isEnumeralType()) kase |= kBIT_ISENUM;
910 if (isTObj) kase |= kBIT_ISTOBJECT;
911 if (isStre) kase |= kBIT_HASSTREAMER;
912 if (tiName ==
"string") kase |= kBIT_ISSTRING;
913 if (tiName ==
"string*") kase |= kBIT_ISSTRING;
917 tcl =
" internal error in rootcling ";
923 if (R__t) finalString <<
" " << tiName <<
" " << R__t <<
";" << std::endl;
926 case kBIT_ISFUNDAMENTAL:
928 finalString <<
" R__b >> " << R__t <<
";" << std::endl;
931 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
933 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
942 finalString <<
" Int_t readtemp;" << std::endl
943 <<
" R__b >> readtemp;" << std::endl
944 <<
" " << R__t <<
" = static_cast<" << tiName <<
">(readtemp);" << std::endl;
947 case kBIT_HASSTREAMER:
948 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
950 finalString <<
" " << R__t <<
".Streamer(R__b);" << std::endl;
953 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
956 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
957 if (cxxtype && cxxtype->isAbstract()) {
958 finalString <<
" R__ASSERT(0);// " << objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
960 finalString <<
" " << R__t <<
" = new " << objType <<
";" << std::endl
961 <<
" " << R__t <<
"->Streamer(R__b);" << std::endl;
963 finalString <<
" } else {" << std::endl
964 <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl
965 <<
" }" << std::endl;
970 finalString <<
" {TString R__str;" << std::endl
971 <<
" R__str.Streamer(R__b);" << std::endl
972 <<
" " << R__t <<
" = R__str.Data();}" << std::endl;
975 case kBIT_ISSTRING|kBIT_ISPOINTER:
977 finalString <<
" {TString R__str;" << std::endl
978 <<
" R__str.Streamer(R__b);" << std::endl
979 <<
" " << R__t <<
" = new string(R__str.Data());}" << std::endl;
984 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
989 finalString <<
" R__b.StreamObject(&" << R__t <<
"," << tcl <<
");" << std::endl;
997 case kBIT_ISFUNDAMENTAL:
998 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
1000 finalString <<
" R__b << " << R__t <<
";" << std::endl;
1004 if (!R__t)
return 0;
1005 finalString <<
" { void *ptr_enum = (void*)&" << R__t <<
";\n";
1006 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
1009 case kBIT_HASSTREAMER:
1010 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
1011 if (!R__t)
return 0;
1012 finalString <<
" ((" << objType <<
"&)" << R__t <<
").Streamer(R__b);" << std::endl;
1015 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
1016 if (!R__t)
return 1;
1017 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
1021 if (!R__t)
return 0;
1022 finalString <<
" {TString R__str(" << R__t <<
".c_str());" << std::endl
1023 <<
" R__str.Streamer(R__b);};" << std::endl;
1026 case kBIT_ISSTRING|kBIT_ISPOINTER:
1027 if (!R__t)
return 0;
1028 finalString <<
" {TString R__str(" << R__t <<
"->c_str());" << std::endl
1029 <<
" R__str.Streamer(R__b);}" << std::endl;
1032 case kBIT_ISPOINTER:
1033 if (!R__t)
return 1;
1034 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
1038 if (!R__t)
return 1;
1039 finalString <<
" R__b.StreamObject((" << objType <<
"*)&" << R__t <<
"," << tcl <<
");" << std::endl;
1051 clang::CXXRecordDecl* ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
1054 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
1056 if (
auto* Ctor = interpreter.getCI()->getSema().LookupDefaultConstructor(ncCl)) {
1057 if (Ctor->getAccess() == clang::AS_public && !Ctor->isDeleted()) {
1070 const char *typeOfArg,
1071 const clang::CXXRecordDecl *expectedArgType,
1072 const cling::Interpreter& interpreter)
1074 if (typeOfArg && !expectedArgType) {
1075 const cling::LookupHelper& lh = interpreter.getLookupHelper();
1078 clang::QualType instanceType = lh.findType(typeOfArg, cling::LookupHelper::WithDiagnostics);
1079 if (!instanceType.isNull())
1080 expectedArgType = instanceType->getAsCXXRecordDecl();
1083 if (!expectedArgType)
1084 return EIOCtorCategory::kAbsent;
1087 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
1088 for (
auto iter = cl->ctor_begin(), end = cl->ctor_end(); iter != end; ++iter)
1090 if ((iter->getAccess() != clang::AS_public) || (iter->getNumParams() != 1))
1094 clang::QualType argType((*iter->param_begin())->getType());
1095 argType = argType.getDesugaredType(cl->getASTContext());
1097 auto ioCtorCategory = EIOCtorCategory::kAbsent;
1098 if (argType->isPointerType()) {
1099 ioCtorCategory = EIOCtorCategory::kIOPtrType;
1100 argType = argType->getPointeeType();
1101 }
else if (argType->isReferenceType()) {
1102 ioCtorCategory = EIOCtorCategory::kIORefType;
1103 argType = argType.getNonReferenceType();
1107 argType = argType.getDesugaredType(cl->getASTContext());
1108 const clang::CXXRecordDecl *argDecl = argType->getAsCXXRecordDecl();
1110 if (argDecl->getCanonicalDecl() == expectedArgType->getCanonicalDecl()) {
1111 return ioCtorCategory;
1114 std::string realArg = argType.getAsString();
1115 std::string clarg(
"class ");
1117 if (realArg == clarg)
1118 return ioCtorCategory;
1122 return EIOCtorCategory::kAbsent;
1131 const cling::Interpreter& interpreter)
1133 const char *arg = ioctortype.
GetName();
1135 if (!ioctortype.
GetType() && (!arg || !arg[0])) {
1148 const char *method,
const char *
proto,
1149 const cling::Interpreter &interp,
1152 const clang::FunctionDecl* funcD
1153 = interp.getLookupHelper().findFunctionProto(cinfo, method,
proto,
1154 diagnose ? cling::LookupHelper::WithDiagnostics
1155 : cling::LookupHelper::NoDiagnostics);
1157 return llvm::dyn_cast<const clang::CXXMethodDecl>(funcD);
1166 namespace TMetaUtils {
1169 const cling::LookupHelper& lh = interp.getLookupHelper();
1172 clang::QualType instanceType = lh.findType(type_of_arg, cling::LookupHelper::WithDiagnostics);
1173 if (!instanceType.isNull())
1174 fArgType = instanceType->getAsCXXRecordDecl();
1188 const cling::Interpreter &interp)
1190 if (cl->isAbstract())
return false;
1192 for (
auto & ctorType : ctorTypes) {
1196 if (EIOCtorCategory::kAbsent == ioCtorCat)
1199 std::string
proto( ctorType.GetName() );
1200 bool defaultCtor =
proto.empty();
1206 if (EIOCtorCategory::kIOPtrType == ioCtorCat) {
1208 }
else if (EIOCtorCategory::kIORefType == ioCtorCat) {
1212 arg +=
")nullptr )";
1215 const clang::CXXMethodDecl *method
1217 cling::LookupHelper::NoDiagnostics);
1218 if (method && method->getAccess() != clang::AS_public) {
1232 const cling::Interpreter& interp)
1234 if (!cl)
return false;
1236 if (cl->hasUserDeclaredDestructor()) {
1238 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interp));
1239 clang::CXXDestructorDecl *
dest = cl->getDestructor();
1241 return (
dest->getAccess() == clang::AS_public);
1253 const char *methodname,
1255 const cling::Interpreter &interp,
1258 const clang::CXXMethodDecl *method
1260 diagnose ? cling::LookupHelper::WithDiagnostics
1261 : cling::LookupHelper::NoDiagnostics);
1262 return (method && method->getAccess() == clang::AS_public);
1273 const char *
proto =
"TDirectory*";
1274 const char *
name =
"DirectoryAutoAdd";
1288 const char *
proto =
"TCollection*,TFileMergeInfo*";
1289 const char *
name =
"Merge";
1302 const char *
proto =
"TCollection*";
1303 const char *
name =
"Merge";
1318 const char *
proto =
"TFileMergeInfo*";
1319 const char *
name =
"ResetAfterMerge";
1329 const clang::CXXRecordDecl* clxx,
1330 const cling::Interpreter &interp,
1333 static const char *
proto =
"TBuffer&";
1335 const clang::CXXMethodDecl *method
1337 cling::LookupHelper::NoDiagnostics);
1338 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1340 return (method && method->getDeclContext() == clxx_as_context
1348 const clang::CXXRecordDecl* clxx,
1349 const cling::Interpreter &interp,
1352 static const char *
proto =
"TBuffer&,TClass*";
1354 const clang::CXXMethodDecl *method
1356 cling::LookupHelper::NoDiagnostics);
1357 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1359 return (method && method->getDeclContext() == clxx_as_context
1389 clang::QualType qualType(&
type,0);
1421 llvm::raw_string_ostream stream(qual_name);
1422 clang::PrintingPolicy policy( cl.getASTContext().getPrintingPolicy() );
1423 policy.SuppressTagKeyword =
true;
1424 policy.SuppressUnwrittenScope =
true;
1426 cl.getNameForDiagnostic(stream,policy,
true);
1429 if ( qual_name ==
"(anonymous " ) {
1430 size_t pos = qual_name.find(
':');
1431 qual_name.erase(0,pos+2);
1447 const clang::Type* declType ( recordDecl.getTypeForDecl() );
1448 clang::QualType qualType(declType,0);
1482 std::stringstream dims;
1483 std::string typenameStr;
1485 const clang::ASTContext& astContext = cl.getASTContext();
1488 for(clang::RecordDecl::field_iterator field_iter = cl.field_begin(), end = cl.field_end();
1496 typenameStr.clear();
1500 clang::QualType fieldType(field_iter->getType());
1501 if (fieldType->isConstantArrayType()) {
1502 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(fieldType.getTypePtr());
1504 dims <<
"[" << arrayType->getSize().getLimitedValue() <<
"]";
1505 fieldType = arrayType->getElementType();
1506 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual());
1516 for(clang::CXXRecordDecl::base_class_const_iterator iter = cl.bases_begin(), end = cl.bases_end();
1519 std::string basename( iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1529 const cling::Interpreter &interp,
1532 return interp.getLookupHelper().findFunctionProto(cinfo, method,
proto,
1533 diagnose ? cling::LookupHelper::WithDiagnostics
1534 : cling::LookupHelper::NoDiagnostics);
1568 clang::SourceLocation sourceLocation = decl->getLocation();
1569 clang::SourceManager& sourceManager = decl->getASTContext().getSourceManager();
1571 if (!sourceLocation.isValid() ) {
1575 if (!sourceLocation.isFileID()) {
1576 sourceLocation = sourceManager.getExpansionRange(sourceLocation).getEnd();
1579 if (sourceLocation.isValid() && sourceLocation.isFileID()) {
1580 return sourceManager.getLineNumber(sourceManager.getFileID(sourceLocation),sourceManager.getFileOffset(sourceLocation));
1593 while (llvm::isa<clang::PointerType>(instanceType.getTypePtr())
1594 || llvm::isa<clang::ReferenceType>(instanceType.getTypePtr()))
1596 instanceType = instanceType->getPointeeType();
1599 const clang::ElaboratedType* etype
1600 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
1602 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
1614 bool result =
false;
1615 const clang::CXXRecordDecl* clxx = instanceType->getAsCXXRecordDecl();
1616 if (clxx && clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1618 const clang::TemplateSpecializationType* TST
1619 = llvm::dyn_cast<const clang::TemplateSpecializationType>(instanceType.getTypePtr());
1626 for(clang::TemplateSpecializationType::iterator
1627 I = TST->begin(), E = TST->end();
1630 if (
I->getKind() == clang::TemplateArgument::Type) {
1645 const cling::Interpreter &interp,
1648 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1649 if (!clxx || clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return false;
1651 clang::QualType instanceType = interp.getLookupHelper().findType(cl.
GetNormalizedName(),
1652 cling::LookupHelper::WithDiagnostics);
1653 if (instanceType.isNull()) {
1666 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(attribute);
1671 attrString = annAttr->getAnnotation();
1680 size_t substrFound (attributeStr.find(propNames::separator));
1681 if (substrFound==std::string::npos) {
1685 size_t EndPart1 = attributeStr.find_first_of(propNames::separator) ;
1686 attrName = attributeStr.substr(0, EndPart1);
1687 const int separatorLength(propNames::separator.
size());
1688 attrValue = attributeStr.substr(EndPart1 + separatorLength);
1696 std::string attrString;
1698 if (0!=ret)
return ret;
1706 const std::string& propName,
1707 std::string& propValue)
1709 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1710 attrIt!=decl.attr_end();++attrIt){
1711 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1712 if (!annAttr)
continue;
1714 llvm::StringRef attribute = annAttr->getAnnotation();
1715 std::pair<llvm::StringRef,llvm::StringRef> split = attribute.split(propNames::separator.c_str());
1716 if (split.first != propName.c_str())
continue;
1718 propValue = split.second;
1729 const std::string& propName,
1732 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1733 attrIt!=decl.attr_end();++attrIt){
1734 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1735 if (!annAttr)
continue;
1737 llvm::StringRef attribute = annAttr->getAnnotation();
1738 std::pair<llvm::StringRef,llvm::StringRef> split = attribute.split(propNames::separator.c_str());
1739 if (split.first != propName.c_str())
continue;
1741 return split.second.getAsInteger(10,propValue);
1752 const clang::CXXRecordDecl *decl,
1753 const cling::Interpreter &interp,
1756 bool& needCollectionProxy)
1760 std::string mappedname;
1762 std::string csymbol = classname;
1770 csymbol.insert(0,
"::");
1776 bool isStd = TMetaUtils::IsStdClass(*decl);
1777 const cling::LookupHelper& lh = interp.getLookupHelper();
1778 bool isString = TMetaUtils::IsOfType(*decl,
"std::string",lh);
1780 bool isStdNotString = isStd && !isString;
1782 finalString <<
"namespace ROOT {" <<
"\n";
1786 finalString <<
" static TClass *" << mappedname.c_str() <<
"_Dictionary();\n"
1787 <<
" static void " << mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1793 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p = nullptr);" <<
"\n";
1797 finalString <<
" static void *newArray_";
1798 finalString << mappedname.c_str();
1799 finalString <<
"(Long_t size, void *p);";
1800 finalString <<
"\n";
1805 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";
1808 finalString <<
" static void directoryAutoAdd_" << mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1811 finalString <<
" static void streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1814 finalString <<
" static void conv_streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1817 finalString <<
" static Long64_t merge_" << mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1820 finalString <<
" static void reset_" << mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1827 ROOT::SchemaRuleClassMap_t::iterator rulesIt1 =
ROOT::gReadRules.find( classname.c_str() );
1828 ROOT::SchemaRuleClassMap_t::iterator rulesIt2 =
ROOT::gReadRawRules.find( classname.c_str() );
1839 finalString <<
"\n // Schema evolution read functions\n";
1840 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt1->second.begin();
1841 while( rIt != rulesIt1->second.end() ) {
1847 std::string error_string;
1849 Warning(0,
"%s", error_string.c_str());
1850 rIt = rulesIt1->second.erase(rIt);
1858 if( rIt->find(
"code" ) != rIt->end() ) {
1874 finalString <<
"\n // Schema evolution read raw functions\n";
1875 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt2->second.begin();
1876 while( rIt != rulesIt2->second.end() ) {
1882 std::string error_string;
1884 Warning(0,
"%s", error_string.c_str());
1885 rIt = rulesIt2->second.erase(rIt);
1893 if( rIt->find(
"code" ) == rIt->end() )
1901 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1903 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " << csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1905 finalString <<
" " << csymbol <<
" *ptr = nullptr;" <<
"\n";
1909 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " << csymbol <<
" >(nullptr);" <<
"\n";
1912 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" << csymbol <<
"));" <<
"\n";
1914 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1917 finalString << csymbol <<
"::Class_Version(), ";
1919 finalString <<
"2, ";
1921 finalString <<
"-2, ";
1927 static const char *versionFunc =
"GetClassVersion";
1931 std::string
proto = classname +
"*";
1932 const clang::Decl* ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1933 const clang::FunctionDecl *methodinfo
1935 interp, cling::LookupHelper::NoDiagnostics);
1943 finalString <<
"GetClassVersion< ";
1944 finalString << classname.c_str();
1945 finalString <<
" >(), ";
1953 if (filename.length() > 0) {
1954 for (
unsigned int i=0; i<filename.length(); i++) {
1955 if (filename[i]==
'\\') filename[i]=
'/';
1959 <<
"," <<
"\n" <<
" typeid(" << csymbol
1960 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1963 finalString <<
"&" << csymbol <<
"::Dictionary, ";
1965 finalString <<
"&" << mappedname <<
"_Dictionary, ";
1969 TClassTable__kHasCustomStreamerMember = 0x10
1974 rootflag = rootflag | TClassTable__kHasCustomStreamerMember;
1976 finalString <<
"isa_proxy, " << rootflag <<
"," <<
"\n" <<
" sizeof(" << csymbol <<
") );" <<
"\n";
1978 finalString <<
" instance.SetNew(&new_" << mappedname.c_str() <<
");" <<
"\n";
1980 finalString <<
" instance.SetNewArray(&newArray_" << mappedname.c_str() <<
");" <<
"\n";
1983 finalString <<
" instance.SetDelete(&delete_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" << mappedname.c_str() <<
");" <<
"\n";
1986 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" << mappedname.c_str() <<
");" <<
"\n";
1990 finalString <<
" instance.SetStreamerFunc(&streamer_" << mappedname.c_str() <<
");" <<
"\n";
1994 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" << mappedname.c_str() <<
");" <<
"\n";
1997 finalString <<
" instance.SetMerge(&merge_" << mappedname.c_str() <<
");" <<
"\n";
2000 finalString <<
" instance.SetResetAfterMerge(&reset_" << mappedname.c_str() <<
");" <<
"\n";
2003 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
2005 needCollectionProxy =
true;
2006 }
else if (stl != 0 &&
2009 int idx = classname.find(
"<");
2011 const char* methodTCP=0;
2017 methodTCP=
"Pushback";
2020 methodTCP=
"Pushfront";
2026 methodTCP=
"MapInsert";
2038 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" << methodTCP <<
"< " << classNameForIO.c_str() <<
" >()));" <<
"\n";
2040 needCollectionProxy =
true;
2048 finalString <<
"\n" <<
" ::ROOT::AddClassAlternate(\""
2055 finalString <<
"\n" <<
" ::ROOT::AddClassAlternate(\""
2065 finalString <<
"\n" <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2069 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" << rulesIt1->second.size() <<
");" <<
"\n";
2071 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
2075 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" << rulesIt2->second.size() <<
");" <<
"\n";
2077 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
2080 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
2084 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " << csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal((" << csymbol <<
"*)nullptr);\n }" <<
"\n";
2087 finalString <<
" // Static variable to force the class initialization" <<
"\n";
2091 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal((const " << csymbol <<
"*)nullptr); R__UseDummy(_R__UNIQUE_DICT_(Init));" <<
"\n";
2094 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n"
2095 <<
" static TClass *" << mappedname <<
"_Dictionary() {\n"
2096 <<
" TClass* theClass ="
2097 <<
"::ROOT::GenerateInitInstanceLocal((const " << csymbol <<
"*)nullptr)->GetClass();\n"
2098 <<
" " << mappedname <<
"_TClassManip(theClass);\n";
2099 finalString <<
" return theClass;\n";
2100 finalString <<
" }\n\n";
2104 std::string manipString;
2105 std::string attribute_s;
2106 std::string attrName, attrValue;
2108 bool attrMapExtracted =
false;
2109 if (decl->hasAttrs()){
2111 for (clang::Decl::attr_iterator attrIt = decl->attr_begin();
2112 attrIt!=decl->attr_end();++attrIt){
2119 if (attrName ==
"name" ||
2120 attrName ==
"pattern" ||
2121 attrName ==
"rootmap")
continue;
2127 if (!attrMapExtracted){
2128 manipString+=
" theClass->CreateAttributeMap();\n";
2129 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
2130 attrMapExtracted=
true;
2132 manipString+=
" attrMap->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2138 for(clang::CXXRecordDecl::decl_iterator internalDeclIt = decl->decls_begin();
2139 internalDeclIt != decl->decls_end(); ++internalDeclIt){
2140 if (!(!(*internalDeclIt)->isImplicit()
2141 && (clang::isa<clang::FieldDecl>(*internalDeclIt) ||
2142 clang::isa<clang::VarDecl>(*internalDeclIt))))
continue;
2145 if (!internalDeclIt->hasAttrs())
continue;
2147 attrMapExtracted =
false;
2148 bool memberPtrCreated =
false;
2150 for (clang::Decl::attr_iterator attrIt = internalDeclIt->attr_begin();
2151 attrIt!=internalDeclIt->attr_end();++attrIt){
2159 clang::NamedDecl* namedInternalDecl = clang::dyn_cast<clang::NamedDecl> (*internalDeclIt);
2160 if (!namedInternalDecl) {
2161 TMetaUtils::Error(0,
"Cannot convert field declaration to clang::NamedDecl");
2164 const std::string memberName(namedInternalDecl->getName());
2165 const std::string cppMemberName=
"theMember_"+memberName;
2168 const std::string dataMemberCreation=
" TDataMember* "+cppMemberName+
" = theClass->GetDataMember(\""+memberName+
"\");\n";
2177 if (attrName == propNames::comment ||
2178 attrName == propNames::iotype ||
2179 attrName == propNames::ioname )
continue;
2181 if (!memberPtrCreated){
2182 manipString+=dataMemberCreation;
2183 memberPtrCreated=
true;
2186 if (!attrMapExtracted){
2187 manipString+=
" "+cppMemberName+
"->CreateAttributeMap();\n";
2188 manipString+=
" TDictAttributeMap* memberAttrMap_"+memberName+
"( theMember_"+memberName+
"->GetAttributeMap() );\n";
2189 attrMapExtracted=
true;
2192 manipString+=
" memberAttrMap_"+memberName+
"->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2199 finalString <<
" static void " << mappedname <<
"_TClassManip(TClass* " << (manipString.empty() ?
"":
"theClass") <<
"){\n"
2204 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2214 std::string &clsname,
2215 std::string &nsname,
2216 const clang::CXXRecordDecl *cl)
2226 auto ctxt = cl->getEnclosingNamespaceContext();
2227 while(ctxt && ctxt!=cl && ctxt->isInlineNamespace()) {
2228 ctxt = ctxt->getParent();
2231 const clang::NamedDecl *namedCtxt = llvm::dyn_cast<clang::NamedDecl>(ctxt);
2232 if (namedCtxt && namedCtxt!=cl) {
2233 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(namedCtxt);
2234 if (nsdecl != 0 && !nsdecl->isAnonymousNamespace()) {
2236 clsname.erase (0, nsname.size() + 2);
2248 const clang::DeclContext *ctxt = cl.getDeclContext();
2249 while(ctxt && !ctxt->isNamespace()) {
2250 ctxt = ctxt->getParent();
2264 int closing_brackets = 0;
2268 if (ctxt && ctxt->isNamespace()) {
2270 const clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(ctxt);
2276 out <<
"namespace " << ns->getNameAsString() <<
" {" << std::endl;
2281 return closing_brackets;
2295 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2296 if (kind == clang::TSK_Undeclared ) {
2299 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2313 const char *
name = which;
2314 const char *
proto =
"size_t";
2315 const char *protoPlacement =
"size_t,void*";
2318 const clang::FunctionDecl *operatornew
2321 cling::LookupHelper::NoDiagnostics);
2322 const clang::FunctionDecl *operatornewPlacement
2324 name, protoPlacement, interp,
2325 cling::LookupHelper::NoDiagnostics);
2327 const clang::DeclContext *ctxtnew = 0;
2328 const clang::DeclContext *ctxtnewPlacement = 0;
2331 ctxtnew = operatornew->getParent();
2333 if (operatornewPlacement) {
2334 ctxtnewPlacement = operatornewPlacement->getParent();
2340 operatornewPlacement
2345 ctxtnew = operatornew->getParent();
2347 if (operatornewPlacement) {
2348 ctxtnewPlacement = operatornewPlacement->getParent();
2351 if (ctxtnewPlacement == 0) {
2359 if (ctxtnew == ctxtnewPlacement) {
2363 const clang::CXXRecordDecl* clnew = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnew);
2364 const clang::CXXRecordDecl* clnewPlacement = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnewPlacement);
2365 if (clnew == 0 && clnewPlacement == 0) {
2371 if (clnew != 0 && clnewPlacement == 0) {
2375 if (clnew == 0 && clnewPlacement != 0) {
2380 if (clnew->isDerivedFrom(clnewPlacement)) {
2410 const clang::CXXRecordDecl *decl,
2411 const cling::Interpreter &interp,
2417 std::string mappedname;
2435 classname.insert(0,
"::");
2438 finalString <<
"namespace ROOT {" <<
"\n";
2443 finalString <<
" // Wrappers around operator new" <<
"\n";
2444 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2446 finalString <<
"new(p) ";
2447 finalString << classname.c_str();
2448 finalString << args;
2449 finalString <<
" : ";
2451 finalString <<
"::new((::ROOT::Internal::TOperatorNewHelper*)p) ";
2452 finalString << classname.c_str();
2453 finalString << args;
2454 finalString <<
" : ";
2456 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2457 finalString <<
" }" <<
"\n";
2461 finalString <<
" static void *newArray_";
2462 finalString << mappedname.c_str();
2463 finalString <<
"(Long_t nElements, void *p) {";
2464 finalString <<
"\n";
2465 finalString <<
" return p ? ";
2467 finalString <<
"new(p) ";
2468 finalString << classname.c_str();
2469 finalString <<
"[nElements] : ";
2471 finalString <<
"::new((::ROOT::Internal::TOperatorNewHelper*)p) ";
2472 finalString << classname.c_str();
2473 finalString <<
"[nElements] : ";
2475 finalString <<
"new ";
2476 finalString << classname.c_str();
2477 finalString <<
"[nElements];";
2478 finalString <<
"\n";
2479 finalString <<
" }";
2480 finalString <<
"\n";
2485 finalString <<
" // Wrapper around operator delete" <<
"\n" <<
" static void delete_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" delete ((" << classname.c_str() <<
"*)p);" <<
"\n" <<
" }" <<
"\n" <<
" static void deleteArray_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" delete [] ((" << classname.c_str() <<
"*)p);" <<
"\n" <<
" }" <<
"\n" <<
" static void destruct_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" typedef " << classname.c_str() <<
" current_t;" <<
"\n" <<
" ((current_t*)p)->~current_t();" <<
"\n" <<
" }" <<
"\n";
2489 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";
2493 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";
2497 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";
2501 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";
2503 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";
2507 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";
2509 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2516 const cling::Interpreter &interp,
2523 if (version == 0)
return;
2527 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2528 if (clxx == 0)
return;
2531 for(clang::CXXRecordDecl::base_class_const_iterator iter = clxx->bases_begin(), end = clxx->bases_end();
2537 Internal::RStl::Instance().GenerateTClassFor( iter->getType(), interp, normCtxt);
2542 for(clang::RecordDecl::field_iterator field_iter = clxx->field_begin(), end = clxx->field_end();
2546 std::string mTypename;
2552 if (!strcmp(shortTypeName,
"string")) {
2564 Internal::RStl::Instance().GenerateTClassFor(utype, interp, normCtxt);
2574 const clang::Type *rawtype =
m.getType()->getCanonicalTypeInternal().getTypePtr();
2575 if (rawtype->isArrayType()) {
2576 rawtype = rawtype->getBaseElementTypeUnsafe ();
2590 const clang::CXXRecordDecl* CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2599 if (!funcCV)
return -1;
2602 if (funcCV == (clang::FunctionDecl*)-1)
return 1;
2617 using res_t = std::pair<bool, int>;
2619 const clang::CompoundStmt* FuncBody
2620 = llvm::dyn_cast_or_null<clang::CompoundStmt>(funcCV->getBody());
2622 return res_t{
false, -1};
2623 if (FuncBody->size() != 1) {
2627 return res_t{
false, -1};
2629 const clang::ReturnStmt* RetStmt
2630 = llvm::dyn_cast<clang::ReturnStmt>(FuncBody->body_back());
2632 return res_t{
false, -1};
2633 const clang::Expr* RetExpr = RetStmt->getRetValue();
2639 llvm::APSInt RetRes;
2640 if (!RetExpr->isIntegerConstantExpr(RetRes, funcCV->getASTContext()))
2641 return res_t{
false, -1};
2642 if (RetRes.isSigned()) {
2643 return res_t{
true, (
Version_t)RetRes.getSExtValue()};
2646 return res_t{
true, (
Version_t)RetRes.getZExtValue()};
2662 clang::QualType
type =
m.getType();
2665 if (decl)
return TMetaUtils::IsSTLCont(*decl);
2674 clang::QualType
type = base.getType();
2677 if (decl)
return TMetaUtils::IsSTLCont(*decl);
2687 const std::function<
void(
const clang::Module::Header &)> &closure,
2688 bool includeDirectlyUsedModules)
2697 const std::size_t publicHeaderIndex = 4;
2700 const std::size_t maxArrayLength = ((
sizeof module.Headers) / (
sizeof *module.Headers));
2701 static_assert(publicHeaderIndex + 1 == maxArrayLength,
2702 "'Headers' has changed it's size, we need to update publicHeaderIndex");
2707 llvm::SetVector<const clang::Module *> modules;
2708 modules.insert(&module);
2709 for (
size_t i = 0; i < modules.size(); ++i) {
2710 const clang::Module *M = modules[i];
2711 for (
const clang::Module *subModule : M->submodules())
2712 modules.insert(subModule);
2715 for (
const clang::Module *
m : modules) {
2716 if (includeDirectlyUsedModules) {
2717 for (clang::Module *used :
m->DirectUses) {
2722 for (std::size_t i = 0; i < publicHeaderIndex; i++) {
2723 auto &headerList =
m->Headers[i];
2724 for (
const clang::Module::Header &moduleHeader : headerList) {
2725 closure(moduleHeader);
2739 static char t[4096];
2740 static const char* constwd =
"const ";
2741 static const char* constwdend =
"const";
2746 for (s=typeDesc;*s;s++) {
2749 if (lev==0 && *s==
'*')
continue;
2750 if (lev==0 && (strncmp(constwd,s,strlen(constwd))==0
2751 ||strcmp(constwdend,s)==0 ) ) {
2752 s+=strlen(constwd)-1;
2755 if (lev==0 && *s==
' ' && *(s+1)!=
'*') { p = t;
continue;}
2756 if (p - t > (
long)
sizeof(t)) {
2757 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2770 const cling::Interpreter& interp)
2775 if (comment[0] ==
'!')
return false;
2777 clang::QualType
type =
m.getType();
2779 if (
type->isReferenceType()) {
2784 std::string mTypeName =
type.getAsString(
m.getASTContext().getPrintingPolicy());
2785 if (!strcmp(mTypeName.c_str(),
"string") || !strcmp(mTypeName.c_str(),
"string*")) {
2788 if (!strcmp(mTypeName.c_str(),
"std::string") || !strcmp(mTypeName.c_str(),
"std::string*")) {
2796 const clang::Type *rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
2798 if (rawtype->isPointerType()) {
2800 clang::QualType pointee;
2801 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
2803 rawtype = pointee.getTypePtr();
2807 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2812 const clang::CXXRecordDecl *cxxdecl = rawtype->getAsCXXRecordDecl();
2816 if (version > 0)
return true;
2829 const clang::Type *rawtype =
m.getType().getTypePtr();
2832 clang::QualType pointee;
2833 while ( rawtype->isPointerType() && ((pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull()) && pointee.getTypePtr() != rawtype)
2835 rawtype = pointee.getTypePtr();
2849 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2853 return rawtype->getAsCXXRecordDecl();
2862 const cling::Interpreter &interp,
2864 std::ostream& dictStream,
2866 bool isGenreflex=
false)
2868 const clang::CXXRecordDecl* decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2870 if (!decl || !decl->isCompleteDefinition()) {
2874 std::string fullname;
2877 Internal::RStl::Instance().GenerateTClassFor(cl.
GetNormalizedName(), llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl()), interp, normCtxt);
2886 (*WriteStreamerFunc)(cl, interp, normCtxt, dictStream, isGenreflex || cl.RequestStreamerInfo());
2888 ROOT::TMetaUtils::Info(0,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
2910 const cling::Interpreter &interpreter,
2913 const clang::ASTContext& Ctx = interpreter.getCI()->getASTContext();
2915 clang::QualType originalType = instanceType;
2919 if (llvm::isa<clang::PointerType>(instanceType.getTypePtr())) {
2921 clang::Qualifiers quals = instanceType.getQualifiers();
2922 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
2923 if (newPointee != instanceType->getPointeeType()) {
2924 instanceType = Ctx.getPointerType(newPointee);
2926 instanceType = Ctx.getQualifiedType(instanceType, quals);
2928 return instanceType;
2933 if (llvm::isa<clang::ReferenceType>(instanceType.getTypePtr())) {
2935 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(instanceType.getTypePtr());
2936 clang::Qualifiers quals = instanceType.getQualifiers();
2937 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
2939 if (newPointee != instanceType->getPointeeType()) {
2942 instanceType = Ctx.getLValueReferenceType(newPointee);
2944 instanceType = Ctx.getRValueReferenceType(newPointee);
2946 instanceType = Ctx.getQualifiedType(instanceType, quals);
2948 return instanceType;
2952 bool prefix_changed =
false;
2953 clang::NestedNameSpecifier* prefix = 0;
2954 clang::Qualifiers prefix_qualifiers = instanceType.getLocalQualifiers();
2955 const clang::ElaboratedType* etype
2956 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
2959 prefix = AddDefaultParametersNNS(Ctx, etype->getQualifier(), interpreter, normCtxt);
2960 prefix_changed = prefix != etype->getQualifier();
2961 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
2967 const clang::TemplateSpecializationType* TST
2968 = llvm::dyn_cast<const clang::TemplateSpecializationType>(instanceType.getTypePtr());
2970 const clang::ClassTemplateSpecializationDecl* TSTdecl
2971 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(instanceType.getTypePtr()->getAsCXXRecordDecl());
2983 bool mightHaveChanged =
false;
2984 if (TST && TSTdecl) {
2986 clang::Sema& S = interpreter.getCI()->getSema();
2987 clang::TemplateDecl *Template = TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
2988 clang::TemplateParameterList *Params = Template->getTemplateParameters();
2989 clang::TemplateParameterList::iterator Param = Params->
begin();
2993 unsigned int dropDefault = normCtxt.
GetConfig().DropDefaultArg(*Template);
2995 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
2996 unsigned int Idecl = 0, Edecl = TSTdecl->getTemplateArgs().size();
2997 unsigned int maxAddArg = TSTdecl->getTemplateArgs().size() - dropDefault;
2998 for(clang::TemplateSpecializationType::iterator
2999 I = TST->begin(), E = TST->end();
3001 I!=E ? ++
I : 0, ++Idecl, ++Param) {
3005 if (
I->getKind() == clang::TemplateArgument::Template) {
3006 clang::TemplateName templateName =
I->getAsTemplate();
3007 clang::TemplateDecl* templateDecl = templateName.getAsTemplateDecl();
3009 clang::DeclContext* declCtxt = templateDecl->getDeclContext();
3011 if (declCtxt && !templateName.getAsQualifiedTemplateName()){
3012 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(declCtxt);
3013 clang::NestedNameSpecifier* nns;
3015 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx, ns);
3016 }
else if (clang::TagDecl* TD = llvm::dyn_cast<clang::TagDecl>(declCtxt)) {
3017 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx,TD,
false );
3020 desArgs.push_back(*
I);
3023 clang::TemplateName templateNameWithNSS ( Ctx.getQualifiedTemplateName(nns,
false, templateDecl) );
3024 desArgs.push_back(clang::TemplateArgument(templateNameWithNSS));
3025 mightHaveChanged =
true;
3031 if (
I->getKind() != clang::TemplateArgument::Type) {
3032 desArgs.push_back(*
I);
3036 clang::QualType SubTy =
I->getAsType();
3045 if (SubTy != newSubTy) {
3046 mightHaveChanged =
true;
3047 desArgs.push_back(clang::TemplateArgument(newSubTy));
3049 desArgs.push_back(*
I);
3052 }
else if (!isStdDropDefault && Idecl < maxAddArg) {
3054 mightHaveChanged =
true;
3056 const clang::TemplateArgument& templateArg
3057 = TSTdecl->getTemplateArgs().get(Idecl);
3058 if (templateArg.getKind() != clang::TemplateArgument::Type) {
3059 desArgs.push_back(templateArg);
3062 clang::QualType SubTy = templateArg.getAsType();
3064 clang::SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3065 clang::SourceLocation RAngleLoc = TSTdecl->getSourceRange().getBegin();
3067 clang::TemplateTypeParmDecl *TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*Param);
3070 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
3071 clang::sema::HackForDefaultTemplateArg raii;
3072 bool HasDefaultArgs;
3073 clang::TemplateArgumentLoc ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
3082 if (ArgType.getArgument().isNull()
3083 || ArgType.getArgument().getKind() != clang::TemplateArgument::Type) {
3085 "Template parameter substitution failed for %s around %s\n",
3086 instanceType.getAsString().c_str(), SubTy.getAsString().c_str());
3089 clang::QualType BetterSubTy = ArgType.getArgument().getAsType();
3090 SubTy = cling::utils::Transform::GetPartiallyDesugaredType(Ctx,BetterSubTy,normCtxt.
GetConfig(),
true);
3093 desArgs.push_back(clang::TemplateArgument(SubTy));
3102 if (mightHaveChanged) {
3103 instanceType = Ctx.getTemplateSpecializationType(TST->getTemplateName(),
3105 TST->getCanonicalTypeInternal());
3109 if (!prefix_changed && !mightHaveChanged)
return originalType;
3111 instanceType = Ctx.getElaboratedType(clang::ETK_None,prefix,instanceType);
3112 instanceType = Ctx.getQualifiedType(instanceType,prefix_qualifiers);
3114 return instanceType;
3134 llvm::StringRef title;
3137 if (clang::AnnotateAttr *A =
m.getAttr<clang::AnnotateAttr>())
3138 title = A->getAnnotation();
3150 if (errnum) *errnum =
VALID;
3152 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3153 size_t rightbracket = title.find(
']');
3154 if (rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3156 std::string working;
3157 llvm::StringRef indexvar(title.data()+1,rightbracket-1);
3164 size_t indexvarlen = indexvar.size();
3165 for ( i=0; i<indexvarlen; i++) {
3166 if (!isspace(indexvar[i])) {
3167 working += indexvar[i];
3172 const char *tokenlist =
"*+-";
3173 char *current =
const_cast<char*
>(working.c_str());
3174 current = strtok(current,tokenlist);
3176 while (current!=0) {
3178 if (isdigit(current[0])) {
3179 for(i=0;i<strlen(current);i++) {
3180 if (!isdigit(current[i])) {
3185 if (errstr) *errstr = current;
3186 if (errnum) *errnum =
NOT_INT;
3187 return llvm::StringRef();
3192 const clang::CXXRecordDecl *parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext());
3193 const clang::FieldDecl *index1 =
nullptr;
3195 index1 = GetDataMemberFromAll(*parent_clxx, current );
3197 if ( IsFieldDeclInt(index1) ) {
3202 for(clang::RecordDecl::field_iterator field_iter = parent_clxx->field_begin(), end = parent_clxx->field_end();
3206 if ( field_iter->getNameAsString() ==
m.getNameAsString() ) {
3212 if (errstr) *errstr = current;
3213 if (errnum) *errnum =
NOT_DEF;
3214 return llvm::StringRef();
3216 if ( field_iter->getNameAsString() == index1->getNameAsString() ) {
3224 if (errstr) *errstr = current;
3225 if (errnum) *errnum =
NOT_INT;
3226 return llvm::StringRef();
3233 index1 = GetDataMemberFromAllParents( *parent_clxx, current );
3235 if ( IsFieldDeclInt(index1) ) {
3242 if (errnum) *errnum =
NOT_INT;
3243 if (errstr) *errstr = current;
3247 if (errnum) *errnum =
NOT_INT;
3248 if (errstr) *errstr = current;
3249 return llvm::StringRef();
3251 if ( found && (index1->getAccess() == clang::AS_private) ) {
3254 if (errstr) *errstr = current;
3256 return llvm::StringRef();
3263 if (errstr) *errstr = indexvar;
3264 if (errnum) *errnum =
UNKNOWN;
3265 return llvm::StringRef();
3270 current = strtok(0,tokenlist);
3286 while((
c = in[i++])) {
3287 const char *repl =
nullptr;
3289 case '+': repl =
"pL";
break;
3290 case '-': repl =
"mI";
break;
3291 case '*': repl =
"mU";
break;
3292 case '/': repl =
"dI";
break;
3293 case '&': repl =
"aN";
break;
3294 case '%': repl =
"pE";
break;
3295 case '|': repl =
"oR";
break;
3296 case '^': repl =
"hA";
break;
3297 case '>': repl =
"gR";
break;
3298 case '<': repl =
"lE";
break;
3299 case '=': repl =
"eQ";
break;
3300 case '~': repl =
"wA";
break;
3301 case '.': repl =
"dO";
break;
3302 case '(': repl =
"oP";
break;
3303 case ')': repl =
"cP";
break;
3304 case '[': repl =
"oB";
break;
3305 case ']': repl =
"cB";
break;
3306 case '!': repl =
"nO";
break;
3307 case ',': repl =
"cO";
break;
3308 case '$': repl =
"dA";
break;
3309 case ' ': repl =
"sP";
break;
3310 case ':': repl =
"cL";
break;
3311 case '"': repl =
"dQ";
break;
3312 case '@': repl =
"aT";
break;
3313 case '\'': repl =
"sQ";
break;
3314 case '\\': repl =
"fI";
break;
3323 auto firstNonNumber = out.find_first_not_of(
"0123456789");
3324 if (firstNonNumber != std::string::npos)
3325 out.replace(0,firstNonNumber,
"");
3328static clang::SourceLocation
3330 clang::SourceLocation sourceLoc) {
3332 if (!sourceLoc.isFileID()) {
3333 return sourceManager.getExpansionRange(sourceLoc).getEnd();
3342 const cling::Interpreter& interp)
3372 using namespace clang;
3373 SourceLocation headerLoc = decl.getLocation();
3375 static const char invalidFilename[] =
"";
3376 if (!headerLoc.isValid())
return invalidFilename;
3378 HeaderSearch& HdrSearch = interp.getCI()->getPreprocessor().getHeaderSearchInfo();
3380 SourceManager& sourceManager = decl.getASTContext().getSourceManager();
3382 FileID headerFID = sourceManager.getFileID(headerLoc);
3383 SourceLocation includeLoc
3385 sourceManager.getIncludeLoc(headerFID));
3387 const FileEntry *headerFE = sourceManager.getFileEntryForID(headerFID);
3388 while (includeLoc.isValid() && sourceManager.isInSystemHeader(includeLoc)) {
3389 const DirectoryLookup *foundDir = 0;
3392 assert(headerFE &&
"Couldn't find FileEntry from FID!");
3393 const FileEntry *FEhdr
3394 = HdrSearch.LookupFile(llvm::sys::path::filename(headerFE->getName()),
3397 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3405 headerFID = sourceManager.getFileID(includeLoc);
3406 headerFE = sourceManager.getFileEntryForID(headerFID);
3411 if (interp.getCI()->getLangOpts().Modules && !headerFE) {
3412 assert(decl.isFirstDecl() &&
"Couldn't trace back include from a decl"
3413 " that is not from an AST file");
3414 assert(StringRef(includeLoc.printToString(sourceManager)).startswith(
"<module-includes>"));
3418 sourceManager.getIncludeLoc(headerFID));
3421 if (!headerFE)
return invalidFilename;
3422 llvm::StringRef headerFileName = headerFE->getName();
3433 bool isAbsolute = llvm::sys::path::is_absolute(headerFileName);
3434 const FileEntry* FELong = 0;
3436 for (llvm::sys::path::const_iterator
3437 IDir = llvm::sys::path::begin(headerFileName),
3438 EDir = llvm::sys::path::end(headerFileName);
3439 !FELong && IDir != EDir; ++IDir) {
3445 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3446 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3447 assert(trailingPart.data() + trailingPart.size()
3448 == headerFileName.data() + headerFileName.size()
3449 &&
"Mismatched partitioning of file name!");
3450 const DirectoryLookup* FoundDir = 0;
3451 FELong = HdrSearch.LookupFile(trailingPart, SourceLocation(),
3453 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3461 return invalidFilename;
3465 for (llvm::sys::path::reverse_iterator
3466 IDir = llvm::sys::path::rbegin(headerFileName),
3467 EDir = llvm::sys::path::rend(headerFileName);
3468 IDir != EDir; ++IDir) {
3469 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3470 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3471 assert(trailingPart.data() + trailingPart.size()
3472 == headerFileName.data() + headerFileName.size()
3473 &&
"Mismatched partitioning of file name!");
3474 const DirectoryLookup* FoundDir = 0;
3477 if (HdrSearch.LookupFile(trailingPart, SourceLocation(),
3479 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3482 0,
nullptr ) == FELong) {
3483 return trailingPart;
3487 return invalidFilename;
3493 const clang::QualType &qtype,
3494 const clang::ASTContext &astContext)
3496 std::string fqname = cling::utils::TypeName::GetFullyQualifiedName(qtype, astContext);
3505 const clang::QualType &qtype,
3506 const cling::Interpreter &interpreter)
3511 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interpreter));
3515 interpreter.getCI()->getASTContext());
3523 clang::ClassTemplateDecl*& ctd,
3524 clang::ClassTemplateSpecializationDecl*& ctsd)
3526 using namespace clang;
3527 const Type* theType = qt.getTypePtr();
3534 if (theType->isPointerType()) {
3538 if (
const RecordType* rType = llvm::dyn_cast<RecordType>(theType)) {
3539 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(rType->getDecl());
3541 ctd = ctsd->getSpecializedTemplate();
3546 if (
const SubstTemplateTypeParmType* sttpType = llvm::dyn_cast<SubstTemplateTypeParmType>(theType)){
3551 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(qt->getAsCXXRecordDecl());
3553 ctd = ctsd->getSpecializedTemplate();
3568 using namespace clang;
3569 ClassTemplateSpecializationDecl* ctsd;
3570 ClassTemplateDecl* ctd;
3584 using namespace clang;
3585 TemplateName theTemplateName;
3587 const Type* theType = qt.getTypePtr();
3589 if (
const TemplateSpecializationType* tst = llvm::dyn_cast_or_null<const TemplateSpecializationType>(theType)) {
3590 theTemplateName = tst->getTemplateName();
3593 theTemplateName = TemplateName(ctd);
3596 return theTemplateName;
3602 llvm::SmallVectorImpl<clang::TemplateArgument>& preceedingTArgs,
3603 const clang::NamedDecl& tPar,
3604 const cling::Interpreter& interp,
3608 using namespace clang;
3611 TemplateTypeParmDecl* ttpdPtr =
const_cast<TemplateTypeParmDecl*
>(llvm::dyn_cast<TemplateTypeParmDecl>(&tPar));
3612 if (!ttpdPtr)
return false;
3613 if (!ttpdPtr->hasDefaultArgument())
return false;
3616 QualType tParQualType = ttpdPtr->getDefaultArgument();
3617 const QualType tArgQualType = tArg.getAsType();
3624 if (tParQualType.getTypePtr() == tArgQualType.getTypePtr())
return true;
3635 const clang::ElaboratedType* etype
3636 = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3638 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3639 etype = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3642 const TemplateSpecializationType* tst =
3643 llvm::dyn_cast<TemplateSpecializationType>(tParQualType.getTypePtr());
3648 ClassTemplateSpecializationDecl* TSTdecl
3649 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(tArgQualType->getAsCXXRecordDecl());
3654 TemplateDecl *Template = tst->getTemplateName().getAsTemplateDecl();
3657 SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3660 SourceLocation LAngleLoc = TSTdecl->getSourceRange().getBegin();
3665 TemplateArgument newArg = tArg;
3667 clang::Sema& S = interp.getCI()->getSema();
3668 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interp));
3669 clang::sema::HackForDefaultTemplateArg raii;
3670 bool HasDefaultArgs;
3671 TemplateArgumentLoc defTArgLoc = S.SubstDefaultTemplateArgumentIfAvailable(Template,
3679 newArg = defTArgLoc.getArgument();
3680 if (newArg.isNull() ||
3681 newArg.getKind() != clang::TemplateArgument::Type) {
3683 "Template parameter substitution failed!");
3686 ClassTemplateSpecializationDecl* nTSTdecl
3687 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(newArg.getAsType()->getAsCXXRecordDecl());
3690 isEqual = (nTSTdecl && nTSTdecl->getMostRecentDecl() == TSTdecl->getMostRecentDecl()) ||
3691 (tParQualType.getTypePtr() == newArg.getAsType().getTypePtr());
3703 const clang::NamedDecl& tPar)
3705 using namespace clang;
3706 const NonTypeTemplateParmDecl* nttpdPtr = llvm::dyn_cast<NonTypeTemplateParmDecl>(&tPar);
3707 if (!nttpdPtr)
return false;
3708 const NonTypeTemplateParmDecl& nttpd = *nttpdPtr;
3710 if (!nttpd.hasDefaultArgument())
3714 llvm::APSInt defaultValueAPSInt(64,
false);
3715 if (Expr* defArgExpr = nttpd.getDefaultArgument()) {
3716 const ASTContext& astCtxt = nttpdPtr->getASTContext();
3717 defArgExpr->isIntegerConstantExpr(defaultValueAPSInt, astCtxt);
3720 const int value = tArg.getAsIntegral().getLimitedValue();
3723 return value == defaultValueAPSInt;
3733 using namespace clang;
3734 if (!nDecl)
return false;
3735 if (
const TemplateTypeParmDecl* ttpd = llvm::dyn_cast<TemplateTypeParmDecl>(nDecl))
3736 return ttpd->hasDefaultArgument();
3737 if (
const NonTypeTemplateParmDecl* nttpd = llvm::dyn_cast<NonTypeTemplateParmDecl>(nDecl))
3738 return nttpd->hasDefaultArgument();
3743static void KeepNParams(clang::QualType& normalizedType,
3744 const clang::QualType& vanillaType,
3745 const cling::Interpreter& interp,
3750 const clang::TemplateArgument &tArg,
3751 const cling::Interpreter& interp,
3753 const clang::ASTContext& astCtxt)
3756 using namespace clang;
3763 if (tArg.getKind() == clang::TemplateArgument::Type) {
3764 QualType thisNormQualType = normTArg.getAsType();
3765 QualType thisArgQualType = tArg.getAsType();
3770 normTArg = TemplateArgument(thisNormQualType);
3771 return (thisNormQualType != thisArgQualType);
3772 }
else if (normTArg.getKind() == clang::TemplateArgument::Pack) {
3773 assert( tArg.getKind() == clang::TemplateArgument::Pack );
3775 SmallVector<TemplateArgument, 2> desArgs;
3776 bool mightHaveChanged =
true;
3777 for (
auto I = normTArg.pack_begin(), E = normTArg.pack_end(),
3778 FI = tArg.pack_begin(), FE = tArg.pack_end();
3779 I != E && FI != FE; ++
I, ++FI)
3781 TemplateArgument pack_arg(*
I);
3783 desArgs.push_back(pack_arg);
3785 if (mightHaveChanged) {
3786 ASTContext &mutableCtx(
const_cast<ASTContext&
>(astCtxt) );
3787 normTArg = TemplateArgument::CreatePackCopy(mutableCtx, desArgs);
3789 return mightHaveChanged;
3800 const clang::QualType& vanillaType,
3801 const cling::Interpreter& interp,
3805 using namespace clang;
3809 ClassTemplateSpecializationDecl* ctsd;
3810 ClassTemplateDecl* ctd;
3811 if (! QualType2Template(vanillaType, ctd, ctsd)) return ;
3817 QualType originalNormalizedType = normalizedType;
3819 const ASTContext& astCtxt = ctsd->getASTContext();
3824 if (llvm::isa<clang::PointerType>(normalizedType.getTypePtr())) {
3826 clang::Qualifiers quals = normalizedType.getQualifiers();
3827 auto valNormalizedType = normalizedType->getPointeeType();
3828 KeepNParams(valNormalizedType,vanillaType, interp, normCtxt);
3829 normalizedType = astCtxt.getPointerType(valNormalizedType);
3831 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3837 if (llvm::isa<clang::ReferenceType>(normalizedType.getTypePtr())) {
3839 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(normalizedType.getTypePtr());
3840 clang::Qualifiers quals = normalizedType.getQualifiers();
3841 auto valNormType = normalizedType->getPointeeType();
3842 KeepNParams(valNormType, vanillaType, interp, normCtxt);
3846 normalizedType = astCtxt.getLValueReferenceType(valNormType);
3848 normalizedType = astCtxt.getRValueReferenceType(valNormType);
3850 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3855 bool prefix_changed =
false;
3856 clang::NestedNameSpecifier* prefix =
nullptr;
3857 clang::Qualifiers prefix_qualifiers = normalizedType.getLocalQualifiers();
3858 const clang::ElaboratedType* etype
3859 = llvm::dyn_cast<clang::ElaboratedType>(normalizedType.getTypePtr());
3863 prefix = AddDefaultParametersNNS(astCtxt, etype->getQualifier(), interp, normCtxt);
3864 prefix_changed = prefix != etype->getQualifier();
3865 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3871 const clang::ClassTemplateDecl* ctdWithDefaultArgs = ctd;
3872 for (
const RedeclarableTemplateDecl* rd: ctdWithDefaultArgs->redecls()) {
3873 clang::TemplateParameterList* tpl = rd->getTemplateParameters();
3874 if (tpl->getMinRequiredArguments () < tpl->size()) {
3875 ctdWithDefaultArgs = llvm::dyn_cast<clang::ClassTemplateDecl>(rd);
3880 if (!ctdWithDefaultArgs) {
3881 Error(
"KeepNParams",
"Not found template default arguments\n");
3882 normalizedType=originalNormalizedType;
3886 TemplateParameterList* tParsPtr = ctdWithDefaultArgs->getTemplateParameters();
3887 const TemplateParameterList& tPars = *tParsPtr;
3888 const TemplateArgumentList& tArgs = ctsd->getTemplateArgs();
3891 TemplateName theTemplateName = ExtractTemplateNameFromQualType(normalizedType);
3892 if (theTemplateName.isNull()) {
3893 normalizedType=originalNormalizedType;
3897 const TemplateSpecializationType* normalizedTst =
3898 llvm::dyn_cast<TemplateSpecializationType>(normalizedType.getTypePtr());
3899 if (!normalizedTst) {
3900 normalizedType=originalNormalizedType;
3904 const clang::ClassTemplateSpecializationDecl* TSTdecl
3905 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(normalizedType.getTypePtr()->getAsCXXRecordDecl());
3906 bool isStdDropDefault = TSTdecl && IsStdDropDefaultClass(*TSTdecl);
3913 llvm::SmallVector<TemplateArgument, 4> argsToKeep;
3915 const int nArgs = tArgs.size();
3916 const int nNormArgs = normalizedTst->getNumArgs();
3918 bool mightHaveChanged =
false;
3921 for (
int formal = 0, inst = 0; formal != nArgs; ++formal, ++inst) {
3922 const NamedDecl* tParPtr = tPars.getParam(formal);
3924 Error(
"KeepNParams",
"The parameter number %s is null.\n", formal);
3931 if (formal == nNormArgs || inst == nNormArgs)
break;
3933 const TemplateArgument& tArg = tArgs.get(formal);
3934 TemplateArgument normTArg(normalizedTst->getArgs()[inst]);
3936 bool shouldKeepArg = nArgsToKeep < 0 || inst < nArgsToKeep;
3937 if (isStdDropDefault) shouldKeepArg =
false;
3946 if ( tParPtr->isTemplateParameterPack() ) {
3951 for( ; inst != nNormArgs; ++inst) {
3952 normTArg = normalizedTst->getArgs()[inst];
3954 argsToKeep.push_back(normTArg);
3960 argsToKeep.push_back(normTArg);
3963 if (!isStdDropDefault) {
3965 mightHaveChanged =
true;
3975 auto argKind = tArg.getKind();
3976 if (argKind == clang::TemplateArgument::Type){
3978 equal =
areEqualTypes(tArg, argsToKeep, *tParPtr, interp, normCtxt);
3979 }
else if (argKind == clang::TemplateArgument::Integral){
3984 argsToKeep.push_back(normTArg);
3986 mightHaveChanged =
true;
3992 if (!prefix_changed && !mightHaveChanged) {
3993 normalizedType = originalNormalizedType;
3998 if (mightHaveChanged) {
3999 Qualifiers qualifiers = normalizedType.getLocalQualifiers();
4000 normalizedType = astCtxt.getTemplateSpecializationType(theTemplateName,
4002 normalizedType.getTypePtr()->getCanonicalTypeInternal());
4003 normalizedType = astCtxt.getQualifiedType(normalizedType, qualifiers);
4009 normalizedType = astCtxt.getElaboratedType(clang::ETK_None,prefix,normalizedType);
4010 normalizedType = astCtxt.getQualifiedType(normalizedType,prefix_qualifiers);
4024 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
4027 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interpreter));
4028 clang::QualType normalizedType = cling::utils::Transform::GetPartiallyDesugaredType(ctxt,
type, normCtxt.
GetConfig(),
true );
4036 return normalizedType;
4050 if (
type.isNull()) {
4057 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
4058 clang::PrintingPolicy policy(ctxt.getPrintingPolicy());
4059 policy.SuppressTagKeyword =
true;
4060 policy.SuppressScope =
true;
4061 policy.AnonymousTagLocations =
false;
4066 std::string normalizedNameStep1;
4069 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
4070 normalizedType.getAsStringInternal(normalizedNameStep1,policy);
4080 if (norm_name.length()>2 && norm_name[0]==
':' && norm_name[1]==
':') {
4081 norm_name.erase(0,2);
4089 const clang::TypeDecl* typeDecl,
4090 const cling::Interpreter &interpreter)
4093 const clang::Sema &sema = interpreter.getSema();
4094 clang::ASTContext& astCtxt = sema.getASTContext();
4095 clang::QualType qualType = astCtxt.getTypeDeclType(typeDecl);
4104std::pair<std::string,clang::QualType>
4106 const cling::Interpreter &interpreter,
4110 std::string thisTypeName;
4111 GetNormalizedName(thisTypeName, thisType, interpreter, normCtxt );
4114 if (!hasChanged)
return std::make_pair(thisTypeName,thisType);
4118 "Name changed from %s to %s\n", thisTypeName.c_str(), thisTypeNameForIO.c_str());
4121 auto& lookupHelper = interpreter.getLookupHelper();
4123 const clang::Type* typePtrForIO;
4124 lookupHelper.findScope(thisTypeNameForIO,
4125 cling::LookupHelper::DiagSetting::NoDiagnostics,
4129 if (!typePtrForIO) {
4131 "Type not found: %s.",thisTypeNameForIO.c_str());
4134 clang::QualType typeForIO(typePtrForIO,0);
4137 if (!typeForIO->isRecordType()) {
4138 return std::make_pair(thisTypeNameForIO,typeForIO);
4141 auto thisDeclForIO = typeForIO->getAsCXXRecordDecl();
4142 if (!thisDeclForIO) {
4144 "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());
4145 return std::make_pair(thisTypeName,thisType);
4148 return std::make_pair(thisTypeNameForIO,typeForIO);
4154 const cling::Interpreter &interpreter,
4166 std::string dictFileName(moduleName);
4167 dictFileName +=
"_rdict.pcm";
4168 return dictFileName;
4172 llvm::errs() << llvm::StringRef(commentStart, 80) <<
'\n';
4198 clang::SourceManager& sourceManager = decl.getASTContext().getSourceManager();
4199 clang::SourceLocation sourceLocation = decl.getEndLoc();
4202 sourceLocation = sourceManager.getExpansionRange(sourceLocation).getEnd();
4210 if (!decl.hasOwningModule() && sourceManager.isLoadedSourceLocation(sourceLocation)) {
4216 const char *commentStart = sourceManager.getCharacterData(sourceLocation, &invalid);
4220 bool skipToSemi =
true;
4221 if (
const clang::FunctionDecl* FD = clang::dyn_cast<clang::FunctionDecl>(&decl)) {
4222 if (FD->isImplicit()) {
4226 if (FD->isExplicitlyDefaulted() || FD->isDeletedAsWritten()) {
4230 }
else if (FD->doesThisDeclarationHaveABody()) {
4233 assert((decl.getEndLoc() != sourceLocation || *commentStart ==
'}'
4235 &&
"Expected macro or end of body at '}'");
4236 if (*commentStart) ++commentStart;
4239 while (*commentStart && isspace(*commentStart)
4240 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4243 if (*commentStart ==
';') ++commentStart;
4247 }
else if (
const clang::EnumConstantDecl* ECD
4248 = clang::dyn_cast<clang::EnumConstantDecl>(&decl)) {
4250 if (ECD->getNextDeclInContext())
4251 while (*commentStart && *commentStart !=
',' && *commentStart !=
'\r' && *commentStart !=
'\n')
4259 while (*commentStart && *commentStart !=
';' && *commentStart !=
'\r' && *commentStart !=
'\n')
4261 if (*commentStart ==
';') ++commentStart;
4265 while ( *commentStart && isspace(*commentStart)
4266 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4270 if (commentStart[0] !=
'/' ||
4271 (commentStart[1] !=
'/' && commentStart[1] !=
'*')) {
4281 unsigned int skipChars = 2;
4282 if (commentStart[0] ==
'/' &&
4283 commentStart[1] ==
'/' &&
4284 (commentStart[2] ==
'/' || commentStart[2] ==
'!') &&
4285 commentStart[3] ==
'<') {
4287 }
else if (commentStart[0] ==
'/' &&
4288 commentStart[1] ==
'*' &&
4289 (commentStart[2] ==
'*' || commentStart[2] ==
'!') &&
4290 commentStart[3] ==
'<') {
4294 commentStart += skipChars;
4297 while ( *commentStart && isspace(*commentStart)
4298 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4301 const char* commentEnd = commentStart;
4303 while (*commentEnd && *commentEnd !=
'\n' && *commentEnd !=
'\r') {
4309 while (commentEnd > commentStart && isspace(commentEnd[-1])) {
4315 unsigned offset = commentStart - sourceManager.getCharacterData(sourceLocation);
4316 *loc = sourceLocation.getLocWithOffset(offset - 1);
4319 return llvm::StringRef(commentStart, commentEnd - commentStart);
4330 clang::SourceLocation *loc,
4331 const cling::Interpreter &interpreter)
4333 using namespace clang;
4334 SourceLocation commentSLoc;
4335 llvm::StringRef comment;
4337 Sema& sema = interpreter.getCI()->getSema();
4339 const Decl* DeclFileLineDecl
4340 = interpreter.getLookupHelper().findFunctionProto(&decl,
"DeclFileLine",
"",
4341 cling::LookupHelper::NoDiagnostics);
4342 if (!DeclFileLineDecl)
return llvm::StringRef();
4345 SourceLocation maybeMacroLoc = DeclFileLineDecl->getLocation();
4346 bool isClassDefMacro = maybeMacroLoc.isMacroID() && sema.findMacroSpelling(maybeMacroLoc,
"ClassDef");
4347 if (isClassDefMacro) {
4349 if (comment.size()) {
4356 return llvm::StringRef();
4365 const clang::Type *rawtype =
type.getTypePtr();
4368 if (rawtype->isElaboratedTypeSpecifier() ) {
4369 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4371 if (rawtype->isArrayType()) {
4372 rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
4374 if (rawtype->isPointerType() || rawtype->isReferenceType() ) {
4376 clang::QualType pointee;
4377 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
4379 rawtype = pointee.getTypePtr();
4381 if (rawtype->isElaboratedTypeSpecifier() ) {
4382 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4384 if (rawtype->isArrayType()) {
4385 rawtype = rawtype->getBaseElementTypeUnsafe ();
4389 if (rawtype->isArrayType()) {
4390 rawtype = rawtype->getBaseElementTypeUnsafe ();
4400 return cling::utils::Analyze::IsStdClass(cl);
4410 if (cling::utils::Analyze::IsStdClass(cl)) {
4411 static const char *names[] =
4412 {
"shared_ptr",
"__shared_ptr",
4413 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4414 llvm::StringRef clname(cl.getName());
4415 for(
auto &&
name : names) {
4416 if (clname ==
name)
return true;
4426 const clang::CXXRecordDecl ¤tCl)
4429 if (&cl == ¤tCl)
return true;
4431 const clang::CXXRecordDecl* previous = currentCl.getPreviousDecl();
4434 if (NULL == previous){
4453 const clang::CXXRecordDecl *thisDecl =
4454 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(lh.findScope(typ, cling::LookupHelper::WithDiagnostics));
4458 Error(
"IsOfType",
"Record decl of type %s not found in the AST.", typ.c_str());
4463 const clang::CXXRecordDecl *mostRecentDecl = thisDecl->getMostRecentDecl();
4488 if (!IsStdClass(cl)) {
4489 auto *nsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext());
4490 if (cl.getName() !=
"RVec" || nsDecl ==
nullptr || nsDecl->getName() !=
"VecOps")
4493 auto *parentNsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext()->getParent());
4494 if (parentNsDecl ==
nullptr || parentNsDecl->getName() !=
"ROOT")
4498 return STLKind(cl.getName());
4502 using namespace clang;
4503 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4504 bool VisitTypedefType(
const TypedefType* TD) {
4507 bool VisitArrayType(
const ArrayType* AT) {
4508 return Visit(AT->getElementType().getTypePtr());
4510 bool VisitDecltypeType(
const DecltypeType* DT) {
4511 return Visit(DT->getUnderlyingType().getTypePtr());
4513 bool VisitPointerType(
const PointerType* PT) {
4514 return Visit(PT->getPointeeType().getTypePtr());
4516 bool VisitReferenceType(
const ReferenceType* RT) {
4517 return Visit(RT->getPointeeType().getTypePtr());
4519 bool VisitSubstTemplateTypeParmType(
const SubstTemplateTypeParmType* STST) {
4520 return Visit(STST->getReplacementType().getTypePtr());
4522 bool VisitTemplateSpecializationType(
const TemplateSpecializationType* TST) {
4523 for (
int I = 0,
N = TST->getNumArgs();
I <
N; ++
I) {
4524 const TemplateArgument&
TA = TST->getArg(
I);
4525 if (
TA.getKind() == TemplateArgument::Type
4526 && Visit(
TA.getAsType().getTypePtr()))
4531 bool VisitTemplateTypeParmType(
const TemplateTypeParmType* TTPT) {
4534 bool VisitTypeOfType(
const TypeOfType* TOT) {
4535 return TOT->getUnderlyingType().getTypePtr();
4537 bool VisitElaboratedType(
const ElaboratedType* ET) {
4538 NestedNameSpecifier* NNS = ET->getQualifier();
4540 if (NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4541 if (Visit(NNS->getAsType()))
4544 NNS = NNS->getPrefix();
4546 return Visit(ET->getNamedType().getTypePtr());
4561 if (!instance)
return input;
4567 using namespace llvm;
4568 using namespace clang;
4569 const clang::ASTContext &Ctxt = instance->getAsCXXRecordDecl()->getASTContext();
4572 const clang::ElaboratedType* etype
4573 = llvm::dyn_cast<clang::ElaboratedType>(input.getTypePtr());
4577 clang::Qualifiers scope_qualifiers = input.getLocalQualifiers();
4578 assert(instance->getAsCXXRecordDecl()!=0 &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4580 clang::NestedNameSpecifier *scope = ReSubstTemplateArgNNS(Ctxt,etype->getQualifier(),instance);
4581 clang::QualType subTy =
ReSubstTemplateArg(clang::QualType(etype->getNamedType().getTypePtr(),0),instance);
4583 if (scope) subTy = Ctxt.getElaboratedType(clang::ETK_None,scope,subTy);
4584 subTy = Ctxt.getQualifiedType(subTy,scope_qualifiers);
4588 QualType QT = input;
4592 if (isa<clang::PointerType>(QT.getTypePtr())) {
4594 Qualifiers quals = QT.getQualifiers();
4597 if (nQT == QT->getPointeeType())
return QT;
4599 QT = Ctxt.getPointerType(nQT);
4601 QT = Ctxt.getQualifiedType(QT, quals);
4607 if (isa<ReferenceType>(QT.getTypePtr())) {
4609 bool isLValueRefTy = isa<LValueReferenceType>(QT.getTypePtr());
4610 Qualifiers quals = QT.getQualifiers();
4613 if (nQT == QT->getPointeeType())
return QT;
4617 QT = Ctxt.getLValueReferenceType(nQT);
4619 QT = Ctxt.getRValueReferenceType(nQT);
4621 QT = Ctxt.getQualifiedType(QT, quals);
4627 if (isa<clang::ArrayType>(QT.getTypePtr())) {
4629 Qualifiers quals = QT.getQualifiers();
4631 if (
const auto arr = dyn_cast<ConstantArrayType>(QT.getTypePtr())) {
4634 if (newQT == arr->getElementType())
return QT;
4635 QT = Ctxt.getConstantArrayType (newQT,
4637 arr->getSizeModifier(),
4638 arr->getIndexTypeCVRQualifiers());
4640 }
else if (
const auto arr = dyn_cast<DependentSizedArrayType>(QT.getTypePtr())) {
4643 if (newQT == QT)
return QT;
4644 QT = Ctxt.getDependentSizedArrayType (newQT,
4646 arr->getSizeModifier(),
4647 arr->getIndexTypeCVRQualifiers(),
4648 arr->getBracketsRange());
4650 }
else if (
const auto arr = dyn_cast<IncompleteArrayType>(QT.getTypePtr())) {
4653 if (newQT == arr->getElementType())
return QT;
4654 QT = Ctxt.getIncompleteArrayType (newQT,
4655 arr->getSizeModifier(),
4656 arr->getIndexTypeCVRQualifiers());
4658 }
else if (
const auto arr = dyn_cast<VariableArrayType>(QT.getTypePtr())) {
4661 if (newQT == arr->getElementType())
return QT;
4662 QT = Ctxt.getVariableArrayType (newQT,
4664 arr->getSizeModifier(),
4665 arr->getIndexTypeCVRQualifiers(),
4666 arr->getBracketsRange());
4670 QT = Ctxt.getQualifiedType(QT, quals);
4675 etype = llvm::dyn_cast<clang::ElaboratedType>(instance);
4677 instance = etype->getNamedType().getTypePtr();
4678 if (!instance)
return input;
4681 const clang::TemplateSpecializationType* TST
4682 = llvm::dyn_cast<const clang::TemplateSpecializationType>(instance);
4684 if (!TST)
return input;
4686 const clang::ClassTemplateSpecializationDecl* TSTdecl
4687 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(instance->getAsCXXRecordDecl());
4689 if (!TSTdecl)
return input;
4691 const clang::SubstTemplateTypeParmType *substType
4692 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(input.getTypePtr());
4696 const clang::ClassTemplateDecl *replacedCtxt = 0;
4698 const clang::DeclContext *replacedDeclCtxt = substType->getReplacedParameter()->getDecl()->getDeclContext();
4699 const clang::CXXRecordDecl *decl = llvm::dyn_cast<clang::CXXRecordDecl>(replacedDeclCtxt);
4700 unsigned int index = substType->getReplacedParameter()->getIndex();
4703 if (decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4704 const clang::ClassTemplatePartialSpecializationDecl *spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(decl);
4706 unsigned int depth = substType->getReplacedParameter()->getDepth();
4708 const TemplateArgument *instanceArgs = spec->getTemplateArgs().data();
4709 unsigned int instanceNArgs = spec->getTemplateArgs().size();
4713 for(
unsigned int A = 0; A < instanceNArgs; ++A) {
4714 if (instanceArgs[A].getKind() == clang::TemplateArgument::Type) {
4715 clang::QualType argQualType = instanceArgs[A].getAsType();
4717 const clang::TemplateTypeParmType *replacementType;
4719 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(argQualType);
4721 if (!replacementType) {
4722 const clang::SubstTemplateTypeParmType *argType
4723 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(argQualType);
4725 clang::QualType replacementQT = argType->getReplacementType();
4726 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(replacementQT);
4729 if (replacementType &&
4730 depth == replacementType->getDepth() &&
4731 index == replacementType->getIndex() )
4738 replacedCtxt = spec->getSpecializedTemplate();
4740 replacedCtxt = decl->getDescribedClassTemplate();
4742 }
else if (
auto const declguide = llvm::dyn_cast<clang::CXXDeductionGuideDecl>(replacedDeclCtxt)) {
4743 replacedCtxt = llvm::dyn_cast<clang::ClassTemplateDecl>(declguide->getDeducedTemplate());
4744 }
else if (
auto const ctdecl = llvm::dyn_cast<clang::ClassTemplateDecl>(replacedDeclCtxt)) {
4745 replacedCtxt = ctdecl;
4747 std::string astDump;
4748 llvm::raw_string_ostream ostream(astDump);
4749 instance->dump(ostream);
4751 ROOT::TMetaUtils::Warning(
"ReSubstTemplateArg",
"Unexpected type of declaration context for template parameter: %s.\n\tThe responsible class is:\n\t%s\n",
4752 replacedDeclCtxt->getDeclKindName(), astDump.c_str());
4753 replacedCtxt =
nullptr;
4756 if ((replacedCtxt && replacedCtxt->getCanonicalDecl() == TSTdecl->getSpecializedTemplate()->getCanonicalDecl())
4758 substType->getReplacedParameter()->getDecl()
4759 == TSTdecl->getSpecializedTemplate ()->getTemplateParameters()->getParam(index))
4761 if ( index >= TST->getNumArgs() ) {
4767 }
else if (TST->getArg(index).getKind() == clang::TemplateArgument::Type) {
4768 return TST->getArg(index).getAsType();
4777 const clang::TemplateSpecializationType* inputTST
4778 = llvm::dyn_cast<const clang::TemplateSpecializationType>(input.getTypePtr());
4779 const clang::ASTContext& astCtxt = TSTdecl->getASTContext();
4782 bool mightHaveChanged =
false;
4783 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
4784 for(clang::TemplateSpecializationType::iterator
I = inputTST->begin(), E = inputTST->end();
4786 if (
I->getKind() != clang::TemplateArgument::Type) {
4787 desArgs.push_back(*
I);
4791 clang::QualType SubTy =
I->getAsType();
4793 if (llvm::isa<clang::SubstTemplateTypeParmType>(SubTy)
4794 || llvm::isa<clang::TemplateSpecializationType>(SubTy)) {
4796 mightHaveChanged = SubTy != newSubTy;
4797 if (!newSubTy.isNull()) {
4798 desArgs.push_back(clang::TemplateArgument(newSubTy));
4801 desArgs.push_back(*
I);
4805 if (mightHaveChanged) {
4806 clang::Qualifiers qualifiers = input.getLocalQualifiers();
4807 input = astCtxt.getTemplateSpecializationType(inputTST->getTemplateName(),
4809 inputTST->getCanonicalTypeInternal());
4810 input = astCtxt.getQualifiedType(input, qualifiers);
4822 if ( nArgsToRemove == 0 ||
name ==
"")
4827 const unsigned int length =
name.length();
4829 unsigned int nArgsRemoved=0;
4830 unsigned int nBraces=0;
4832 while (nArgsRemoved!=nArgsToRemove && cur<length){
4834 if (
c ==
'<') nBraces++;
4835 if (
c ==
'>') nBraces--;
4836 if (
c ==
',' && nBraces==1 ) nArgsRemoved++;
4850 static const char *stls[] =
4851 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
4852 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",
"RVec", 0};
4866 for(
int k=1;stls[k];k++) {
if (
type.equals(stls[k]))
return values[k];}
4877 TND = TND->getMostRecentDecl();
4878 while (TND && !(TND->hasAttrs()))
4879 TND = TND->getPreviousDecl();
4891 TD = TD->getMostRecentDecl();
4892 while (TD && !(TD->hasAttrs() && TD->isThisDeclarationADefinition()))
4893 TD = TD->getPreviousDecl();
4902 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4904 const clang::DeclContext* enclosingNamespaceDeclCtxt = decl.getDeclContext();
4905 if (!enclosingNamespaceDeclCtxt)
return;
4907 const clang::NamespaceDecl* enclosingNamespace =
4908 clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4909 if (!enclosingNamespace)
return;
4911 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4912 enclosingNamespace->isInline()));
4922 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4924 const clang::DeclContext* enclosingNamespaceDeclCtxt = ctxt.getParent ();
4927 if (!enclosingNamespaceDeclCtxt) {
4933 const clang::NamespaceDecl* enclosingNamespace = clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4934 if (!enclosingNamespace)
return;
4937 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4938 enclosingNamespace->isInline()));
4949 std::list<std::pair<std::string,unsigned int> >& enclosingSc)
4951 const clang::DeclContext* enclosingDeclCtxt = decl.getDeclContext();
4952 if (!enclosingDeclCtxt)
return nullptr;
4954 unsigned int scopeType;
4956 if (
auto enclosingNamespacePtr =
4957 clang::dyn_cast<clang::NamespaceDecl>(enclosingDeclCtxt)){
4958 scopeType= enclosingNamespacePtr->isInline() ? 1 : 0;
4959 enclosingSc.push_back(std::make_pair(enclosingNamespacePtr->getNameAsString(),scopeType));
4963 if (
auto enclosingClassPtr =
4964 clang::dyn_cast<clang::RecordDecl>(enclosingDeclCtxt)){
4965 return enclosingClassPtr;
4977 std::string::size_type beginVar = 0;
4978 std::string::size_type endVar = 0;
4979 while ((beginVar = txt.find(
'$', beginVar)) != std::string::npos
4980 && beginVar + 1 < txt.length()) {
4981 std::string::size_type beginVarName = beginVar + 1;
4982 std::string::size_type endVarName = std::string::npos;
4983 if (txt[beginVarName] ==
'(') {
4985 endVarName = txt.find(
')', beginVarName);
4987 if (endVarName == std::string::npos) {
4989 varname, txt.c_str() + beginVar);
4992 endVar = endVarName + 1;
4995 beginVarName = beginVar + 1;
4996 endVarName = beginVarName;
4997 while (isalnum(txt[endVarName]) || txt[endVarName] ==
'_')
4999 endVar = endVarName;
5002 const char* val = getenv(txt.substr(beginVarName,
5003 endVarName - beginVarName).c_str());
5006 txt.replace(beginVar, endVar - beginVar, val);
5007 int lenval = strlen(val);
5008 int delta = lenval - (endVar - beginVar);
5012 beginVar = endVar + 1;
5024 const char* envInclPath = getenv(
"ROOT_INCLUDE_PATH");
5028 std::istringstream envInclPathsStream(envInclPath);
5029 std::string inclPath;
5030 while (std::getline(envInclPathsStream, inclPath,
':')) {
5033 if (!inclPath.empty()) {
5034 clingArgs.push_back(
"-I");
5035 clingArgs.push_back(inclPath);
5046 size_t start_pos = 0;
5051 while((start_pos = str.find(from, start_pos)) != std::string::npos) {
5052 str.replace(start_pos, from.length(), to);
5053 start_pos += to.length();
5054 if (recurse) changed =
true;
5070 if (theString.size() < theSubstring.size())
return false;
5071 const unsigned int theSubstringSize = theSubstring.size();
5072 return 0 == theString.compare(theString.size() - theSubstringSize,
5081 if (theString.size() < theSubstring.size())
return false;
5082 const unsigned int theSubstringSize = theSubstring.size();
5083 return 0 == theString.compare(0,
5096 if ((strstr(filename,
"LinkDef") || strstr(filename,
"Linkdef") ||
5097 strstr(filename,
"linkdef")) && strstr(filename,
".h")) {
5100 size_t len = strlen(filename);
5101 size_t linkdeflen = 9;
5103 if (0 == strncasecmp(filename + (len - linkdeflen),
"linkdef", linkdeflen - 2)
5104 && 0 == strcmp(filename + (len - 2),
".h")
5119 return llvm::sys::path::extension(filename) ==
".h" ||
5120 llvm::sys::path::extension(filename) ==
".hh" ||
5121 llvm::sys::path::extension(filename) ==
".hpp" ||
5122 llvm::sys::path::extension(filename) ==
".H" ||
5123 llvm::sys::path::extension(filename) ==
".h++" ||
5124 llvm::sys::path::extension(filename) ==
"hxx" ||
5125 llvm::sys::path::extension(filename) ==
"Hxx" ||
5126 llvm::sys::path::extension(filename) ==
"HXX";
5132 cling::Interpreter::IgnoreFilesFunc_t ignoreFiles,
5133 const cling::Interpreter &interp,
5136 clang::Sema &sema = interp.getSema();
5137 cling::Transaction theTransaction(sema);
5138 std::set<clang::Decl *> addedDecls;
5139 for (
auto decl : decls) {
5141 clang::Decl *ncDecl =
const_cast<clang::Decl *
>(decl);
5142 theTransaction.append(ncDecl);
5144 std::string newFwdDecl;
5145 llvm::raw_string_ostream llvmOstr(newFwdDecl);
5147 std::string locallogs;
5148 llvm::raw_string_ostream llvmLogStr(locallogs);
5149 interp.forwardDeclare(theTransaction, sema.getPreprocessor(), sema.getASTContext(), llvmOstr,
true,
5150 logs ? &llvmLogStr : nullptr, ignoreFiles);
5154 logs->swap(locallogs);
5166 std::string& defString)
5178 std::string& defString)
5180 std::list<std::pair<std::string,unsigned int> > enclosingNamespaces;
5183 if (rcdPtr)
return rcdPtr;
5186 static const std::string scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5188 std::string scopeName;
5189 std::string scopeContent;
5190 unsigned int scopeIndex;
5191 for (
auto const & encScope : enclosingNamespaces){
5192 scopeIndex = encScope.second;
5193 scopeName = encScope.first;
5194 scopeContent =
" { " + defString +
" }";
5195 defString = scopeType[scopeIndex] +
5217 const clang::TemplateParameterList& tmplParamList,
5218 const cling::Interpreter& interpreter)
5221 for (
auto prmIt = tmplParamList.begin();
5222 prmIt != tmplParamList.end(); prmIt++){
5224 if (prmIt != tmplParamList.begin())
5225 templateArgs +=
", ";
5227 auto nDecl = *prmIt;
5228 std::string typeName;
5231 if (llvm::isa<clang::TemplateTypeParmDecl>(nDecl)){
5232 typeName =
"typename ";
5233 if (nDecl->isParameterPack())
5235 typeName += (*prmIt)->getNameAsString();
5238 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(nDecl)){
5239 auto theType = nttpd->getType();
5242 if (theType.getAsString().find(
"enum") != std::string::npos){
5243 std::string astDump;
5244 llvm::raw_string_ostream ostream(astDump);
5245 nttpd->dump(ostream);
5247 ROOT::TMetaUtils::Warning(0,
"Forward declarations of templates with enums as template parameters. The responsible class is: %s\n", astDump.c_str());
5256 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(nDecl)){
5259 std::string astDump;
5260 llvm::raw_string_ostream ostream(astDump);
5261 ttpd->dump(ostream);
5263 ROOT::TMetaUtils::Error(0,
"Cannot reconstruct template template parameter forward declaration for %s\n", astDump.c_str());
5268 templateArgs += typeName;
5279 const cling::Interpreter& interpreter,
5280 std::string& defString)
5282 std::string templatePrefixString;
5283 auto tmplParamList= templDecl.getTemplateParameters();
5284 if (!tmplParamList){
5286 "Cannot extract template parameter list for %s",
5287 templDecl.getNameAsString().c_str());
5294 "Problems with arguments for forward declaration of class %s\n",
5295 templDecl.getNameAsString().c_str());
5298 templatePrefixString =
"template " + templatePrefixString +
" ";
5300 defString = templatePrefixString +
"class ";
5301 if (templDecl.isParameterPack())
5302 defString +=
"... ";
5303 defString += templDecl.getNameAsString();
5304 if (llvm::isa<clang::TemplateTemplateParmDecl>(&templDecl)) {
5318 std::string& argFwdDecl,
5319 const cling::Interpreter& interpreter,
5320 bool acceptStl=
false)
5326 if (clang::TemplateArgument::Type != arg.getKind())
return 0;
5328 auto argQualType = arg.getAsType();
5331 while (llvm::isa<clang::PointerType>(argQualType.getTypePtr())) argQualType = argQualType->getPointeeType();
5333 auto argTypePtr = argQualType.getTypePtr();
5336 if (llvm::isa<clang::EnumType>(argTypePtr)){
5341 if (llvm::isa<clang::BuiltinType>(argTypePtr)){
5346 if (
auto tdTypePtr = llvm::dyn_cast<clang::TypedefType>(argTypePtr)) {
5347 FwdDeclFromTypeDefNameDecl(*tdTypePtr->getDecl(), interpreter, argFwdDecl);
5351 if (
auto argRecTypePtr = llvm::dyn_cast<clang::RecordType>(argTypePtr)){
5353 if (
auto argRecDeclPtr = argRecTypePtr->getDecl()){
5354 FwdDeclFromRcdDecl(*argRecDeclPtr,interpreter,argFwdDecl,acceptStl);
5366 const cling::Interpreter& interpreter,
5367 std::string& defString,
5368 const std::string &normalizedName)
5372 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)) {
5373 if (
const auto *specDef = tmplSpecDeclPtr->getDefinition()) {
5374 if (specDef->getTemplateSpecializationKind() != clang::TSK_ExplicitSpecialization)
5378 std::cout <<
" Forward declaring template spec " << normalizedName <<
":\n";
5379 for (
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()) {
5380 std::string argFwdDecl;
5383 std::cout <<
" o Template argument ";
5385 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5387 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5394 defString += argFwdDecl +
'\n';
5396 defString +=
"template <> class " + normalizedName +
';';
5410 const cling::Interpreter& interpreter,
5411 std::string& defString,
5419 if (!recordDecl.getIdentifier())
5423 std::string argsFwdDecl;
5425 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)){
5426 std::string argFwdDecl;
5428 std::cout <<
"Class " << recordDecl.getNameAsString()
5429 <<
" is a template specialisation. Treating its arguments.\n";
5430 for(
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()){
5433 std::cout <<
" o Template argument ";
5435 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5437 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5444 argsFwdDecl+=argFwdDecl;
5448 defString=argsFwdDecl;
5453 if (
auto tmplDeclPtr = tmplSpecDeclPtr->getSpecializedTemplate()){
5456 defString = argsFwdDecl +
"\n" + defString;
5461 defString =
"class " + recordDecl.getNameAsString() +
";";
5462 const clang::RecordDecl* rcd =
EncloseInScopes(recordDecl, defString);
5470 defString = argsFwdDecl +
"\n" + defString;
5481 const cling::Interpreter& interpreter,
5482 std::string& fwdDeclString,
5483 std::unordered_set<std::string>* fwdDeclSetPtr)
5485 std::string buffer = tdnDecl.getNameAsString();
5486 std::string underlyingName;
5487 auto underlyingType = tdnDecl.getUnderlyingType().getCanonicalType();
5488 if (
const clang::TagType* TT
5489 = llvm::dyn_cast<clang::TagType>(underlyingType.getTypePtr())) {
5490 if (clang::NamedDecl* ND = TT->getDecl()) {
5491 if (!ND->getIdentifier()) {
5505 if (underlyingName.find(
">::") != std::string::npos)
5508 buffer=
"typedef "+underlyingName+
" "+buffer+
";";
5520 auto& ctxt = tdnDecl.getASTContext();
5521 auto immediatelyUnderlyingType = underlyingType.getSingleStepDesugaredType(ctxt);
5523 if (
auto underlyingTdnTypePtr = llvm::dyn_cast<clang::TypedefType>(immediatelyUnderlyingType.getTypePtr())){
5524 std::string tdnFwdDecl;
5525 auto underlyingTdnDeclPtr = underlyingTdnTypePtr->getDecl();
5530 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(tdnFwdDecl).second)
5531 fwdDeclString+=tdnFwdDecl;
5532 }
else if (
auto CXXRcdDeclPtr = immediatelyUnderlyingType->getAsCXXRecordDecl()){
5533 std::string classFwdDecl;
5535 std::cout <<
"Typedef " << tdnDecl.getNameAsString() <<
" hides a class: "
5536 << CXXRcdDeclPtr->getNameAsString() << std::endl;
5545 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(classFwdDecl).second)
5546 fwdDeclString+=classFwdDecl;
5549 fwdDeclString+=buffer;
5561 std::string& valAsString,
5562 const clang::PrintingPolicy& ppolicy)
5564 auto defArgExprPtr = par.getDefaultArg();
5565 auto& ctxt = par.getASTContext();
5566 if(!defArgExprPtr->isEvaluatable(ctxt)){
5570 auto defArgType = par.getType();
5573 if (defArgType->isBooleanType()){
5575 defArgExprPtr->EvaluateAsBooleanCondition (result,ctxt);
5576 valAsString=std::to_string(result);
5581 if (defArgType->isIntegerType()){
5582 clang::Expr::EvalResult evalResult;
5583 defArgExprPtr->EvaluateAsInt(evalResult, ctxt);
5584 llvm::APSInt result = evalResult.Val.getInt();
5585 auto uintVal = *result.getRawData();
5586 if (result.isNegative()){
5587 long long int intVal=uintVal*-1;
5588 valAsString=std::to_string(intVal);
5590 valAsString=std::to_string(uintVal);
5597 llvm::raw_string_ostream rso(valAsString);
5598 defArgExprPtr->printPretty(rso,
nullptr,ppolicy);
5599 valAsString = rso.str();
The file contains utilities which are foundational and could be used across the core component of ROO...
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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.
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";
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)
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
const_iterator begin() const
const std::string & GetPathSeparator()
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
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)
bool IsSTLBitset(const char *type)
Return true is the name is std::bitset<number> or bitset<number>
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.
#define dest(otri, vertexptr)