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/Lookup.h"
49#include "clang/Sema/Sema.h"
50#include "clang/Sema/SemaDiagnostic.h"
52#include "cling/Interpreter/LookupHelper.h"
53#include "cling/Interpreter/Transaction.h"
54#include "cling/Interpreter/Interpreter.h"
55#include "cling/Utils/AST.h"
57#include "llvm/Support/Path.h"
58#include "llvm/Support/FileSystem.h"
63#define strncasecmp _strnicmp
74 llvm::SmallString<256> result_path;
75 llvm::sys::fs::real_path(path, result_path,
true);
76 return result_path.str().str();
83 using DeclsCont_t = TNormalizedCtxt::Config_t::SkipCollection;
100 bool replace =
false);
110static clang::NestedNameSpecifier *AddDefaultParametersNNS(
const clang::ASTContext& Ctx,
111 clang::NestedNameSpecifier* scope,
112 const cling::Interpreter &interpreter,
114 if (!scope)
return nullptr;
116 const clang::Type* scope_type = scope->getAsType();
119 clang::NestedNameSpecifier* outer_scope = scope->getPrefix();
121 outer_scope = AddDefaultParametersNNS(Ctx, outer_scope, interpreter, normCtxt);
124 clang::QualType addDefault =
127 if (addDefault.getTypePtr() != scope_type)
128 return clang::NestedNameSpecifier::Create(Ctx,outer_scope,
130 addDefault.getTypePtr());
137static bool CheckDefinition(
const clang::CXXRecordDecl *cl,
const clang::CXXRecordDecl *context)
139 if (!cl->hasDefinition()) {
142 "Missing definition for class %s, please #include its header in the header of %s\n",
143 cl->getName().str().c_str(), context->getName().str().c_str());
146 "Missing definition for class %s\n",
147 cl->getName().str().c_str());
159static clang::NestedNameSpecifier *ReSubstTemplateArgNNS(
const clang::ASTContext &Ctxt,
160 clang::NestedNameSpecifier *scope,
163 if (!scope)
return nullptr;
165 const clang::Type* scope_type = scope->getAsType();
167 clang::NestedNameSpecifier* outer_scope = scope->getPrefix();
169 outer_scope = ReSubstTemplateArgNNS(Ctxt, outer_scope,
instance);
171 clang::QualType substScope =
174 scope = clang::NestedNameSpecifier::Create(Ctxt,outer_scope,
176 substScope.getTypePtr());
183static bool IsTypeInt(
const clang::Type *
type)
185 const clang::BuiltinType * builtin = llvm::dyn_cast<clang::BuiltinType>(
type->getCanonicalTypeInternal().getTypePtr());
187 return builtin->isInteger();
195static bool IsFieldDeclInt(
const clang::FieldDecl *field)
197 return IsTypeInt(field->getType().getTypePtr());
203static const clang::FieldDecl *GetDataMemberFromAll(
const clang::CXXRecordDecl &cl, llvm::StringRef
what)
205 clang::ASTContext &
C = cl.getASTContext();
206 clang::DeclarationName DName = &
C.Idents.get(
what);
207 auto R = cl.lookup(DName);
208 for (
const clang::NamedDecl *D :
R)
209 if (auto FD =
llvm::dyn_cast<const
clang::FieldDecl>(D))
217static const clang::FieldDecl *GetDataMemberFromAllParents(clang::Sema &SemaR,
const clang::CXXRecordDecl &cl,
const char *
what)
219 clang::DeclarationName DName = &SemaR.Context.Idents.get(
what);
220 clang::LookupResult
R(SemaR, DName, clang::SourceLocation(),
221 clang::Sema::LookupOrdinaryName,
222 clang::Sema::ForExternalRedeclaration);
223 SemaR.LookupInSuper(
R, &
const_cast<clang::CXXRecordDecl&
>(cl));
226 return llvm::dyn_cast<const clang::FieldDecl>(
R.getFoundDecl());
230cling::LookupHelper::DiagSetting ToLHDS(
bool wantDiags) {
232 ? cling::LookupHelper::WithDiagnostics
233 : cling::LookupHelper::NoDiagnostics;
240namespace TMetaUtils {
249 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
250 "Tring to specify a number of template arguments to keep for a null pointer. Exiting without assigning any value.\n");
254 const clang::ClassTemplateDecl* canTempl = templ->getCanonicalDecl();
258 const std::string templateName (canTempl->getNameAsString());
259 const std::string i_str (std::to_string(i));
261 Error(
"TNormalizedCtxt::AddTemplAndNargsToKeep",
262 "Tring to specify for template %s %s arguments to keep, while before this number was %s\n",
263 canTempl->getNameAsString().c_str(),
265 previousArgsToKeep.c_str());
276 const clang::ClassTemplateDecl* constTempl = templ->getCanonicalDecl();
320 const std::string &normalizedName)
324 if (normalizedName.find(
"Double32_t") != std::string::npos
325 || normalizedName.find(
"Float16_t") != std::string::npos)
327 std::unique_ptr<clang::MangleContext> mangleCtx(rDecl->getASTContext().createMangleContext());
328 std::string mangledName;
330 llvm::raw_string_ostream sstr(mangledName);
331 if (
const clang::TypeDecl* TD = llvm::dyn_cast<clang::TypeDecl>(rDecl)) {
332 mangleCtx->mangleCXXRTTI(clang::QualType(TD->getTypeForDecl(), 0), sstr);
335 if (!mangledName.empty()) {
338 if (mangledName[0] ==
'\01')
339 mangledName.erase(0, 1);
341 if (!errDemangle && demangledTIName) {
342 static const char typeinfoNameFor[] =
" `RTTI Type Descriptor'";
343 if (strstr(demangledTIName, typeinfoNameFor)) {
344 std::string demangledName = demangledTIName;
345 demangledName.erase(demangledName.end() - strlen(typeinfoNameFor), demangledName.end());
348 if (!errDemangle && demangledTIName) {
349 static const char typeinfoNameFor[] =
"typeinfo for ";
350 if (!strncmp(demangledTIName, typeinfoNameFor, strlen(typeinfoNameFor))) {
351 std::string demangledName = demangledTIName + strlen(typeinfoNameFor);
353 free(demangledTIName);
354 return demangledName;
358 "Demangled typeinfo name '%s' does not contain `RTTI Type Descriptor'\n",
362 "Demangled typeinfo name '%s' does not start with 'typeinfo for'\n",
367 free(demangledTIName);
378 const clang::RecordDecl *decl,
381 bool rRequestNoInputOperator,
382 bool rRequestOnlyTClass,
383 int rRequestedVersionNumber,
384 const cling::Interpreter &interpreter,
397 const clang::Type *requestedType,
398 const clang::RecordDecl *decl,
399 const char *requestName,
400 unsigned int nTemplateArgsToSkip,
403 bool rRequestNoInputOperator,
404 bool rRequestOnlyTClass,
405 int rRequestVersionNumber,
406 const cling::Interpreter &interpreter,
408 fRuleIndex(
index), fDecl(decl), fRequestedName(
""), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer),
409 fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestVersionNumber)
418 "Could not remove the requested template arguments.\n");
427 const clang::Type *requestedType,
428 const clang::RecordDecl *decl,
429 const char *requestName,
432 bool rRequestNoInputOperator,
433 bool rRequestOnlyTClass,
434 int rRequestVersionNumber,
435 const cling::Interpreter &interpreter,
437 fRuleIndex(
index), fDecl(decl), fRequestedName(
""), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer),
438 fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestVersionNumber)
452 const clang::RecordDecl *decl,
453 const char *requestName,
456 bool rRequestNoInputOperator,
457 bool rRequestOnlyTClass,
458 int rRequestVersionNumber,
459 const cling::Interpreter &interpreter,
461 fRuleIndex(
index), fDecl(decl), fRequestedName(
""), fRequestStreamerInfo(rStreamerInfo), fRequestNoStreamer(rNoStreamer), fRequestNoInputOperator(rRequestNoInputOperator), fRequestOnlyTClass(rRequestOnlyTClass), fRequestedVersionNumber(rRequestVersionNumber)
470 if (requestName && requestName[0]) {
485 ExistingTypeCheck_t existingTypeCheck,
486 AutoParse_t autoParse,
487 bool *shuttingDownPtr,
488 const int* pgDebug ):
489 fInterpreter(&interpreter),fNormalizedCtxt(&normCtxt),
490 fExistingTypeCheck(existingTypeCheck),
491 fAutoParse(autoParse),
492 fInterpreterIsShuttingDownPtr(shuttingDownPtr),
504 if (tname.empty())
return false;
514 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
515 clang::QualType t = lh.findType(nameLong, ToLHDS(
WantDiags()));
518 if (!
dest.isNull() && (
dest != t)) {
521 dest.getAsStringInternal(nameLong,
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
529 const std::string &nameLong)
531 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
532 clang::QualType t = lh.findType(nondef.c_str(), ToLHDS(
WantDiags()));
535 if (!
dest.isNull() && (
dest != t) &&
536 nameLong == t.getAsString(
fInterpreter->getCI()->getASTContext().getPrintingPolicy()))
546 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
547 const clang::Decl *scope = lh.findScope(base.c_str(), ToLHDS(
WantDiags()),
nullptr);
554 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(scope);
555 isInlined = nsdecl && nsdecl->isInline();
567 if (tname.empty())
return false;
584 const cling::LookupHelper& lh =
fInterpreter->getLookupHelper();
585 clang::QualType t = lh.findType(tname.c_str(), ToLHDS(
WantDiags()));
596 clang::PrintingPolicy policy(
fInterpreter->getCI()->getASTContext().getPrintingPolicy());
597 policy.SuppressTagKeyword =
true;
598 policy.SuppressScope =
true;
607 if (strncmp(
result.c_str(),
"const ", 6) == 0) {
610 if (dropstd && strncmp(
result.c_str()+
offset,
"std::", 5) == 0) {
613 for(
unsigned int i = 1; i<
result.length(); ++i) {
616 if (dropstd &&
result.compare(i,5,
"std::",5) == 0) {
625 }
else if ( (i+1) <
result.length() &&
663 clang::QualType toSkip = lh.findType(
name, cling::LookupHelper::WithDiagnostics);
664 if (
const clang::Type* T = toSkip.getTypePtr()) {
665 const clang::TypedefType *
tt = llvm::dyn_cast<clang::TypedefType>(T);
667 clang::Decl* D =
tt->getDecl();
668 fConfig.m_toSkip.insert(D);
670 clang::QualType canon = toSkip->getCanonicalTypeInternal();
671 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),T));
673 fTypeWithAlternative.insert(T);
686 keepTypedef(lh,
"Double32_t");
687 keepTypedef(lh,
"Float16_t");
688 keepTypedef(lh,
"Long64_t",
true);
689 keepTypedef(lh,
"ULong64_t",
true);
691 clang::QualType toSkip = lh.findType(
"string", cling::LookupHelper::WithDiagnostics);
692 if (!toSkip.isNull()) {
693 if (
const clang::TypedefType* TT
694 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
695 fConfig.m_toSkip.insert(TT->getDecl());
697 toSkip = lh.findType(
"std::string", cling::LookupHelper::WithDiagnostics);
698 if (!toSkip.isNull()) {
699 if (
const clang::TypedefType* TT
700 = llvm::dyn_cast_or_null<clang::TypedefType>(toSkip.getTypePtr()))
701 fConfig.m_toSkip.insert(TT->getDecl());
703 clang::QualType canon = toSkip->getCanonicalTypeInternal();
704 fConfig.m_toReplace.insert(std::make_pair(canon.getTypePtr(),toSkip.getTypePtr()));
715 return (cl.getKind() == clang::Decl::ClassTemplatePartialSpecialization
716 || cl.getKind() == clang::Decl::ClassTemplateSpecialization);
723 const cling::Interpreter& interp)
725 clang::Sema* S = &interp.getSema();
726 const clang::NamedDecl* ND = cling::utils::Lookup::Named(S,
name, cl);
727 if (ND == (clang::NamedDecl*)-1)
728 return (clang::FunctionDecl*)-1;
729 return llvm::dyn_cast_or_null<clang::FunctionDecl>(ND);
735const clang::CXXRecordDecl *
737 bool ,
const clang::Type** resultType)
739 const cling::LookupHelper& lh = interp.getLookupHelper();
742 const clang::CXXRecordDecl *
result
743 = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
744 (lh.findScope(
name, cling::LookupHelper::NoDiagnostics, resultType));
746 std::string std_name(
"std::");
750 result = llvm::dyn_cast_or_null<clang::CXXRecordDecl>
751 (lh.findScope(std_name, cling::LookupHelper::NoDiagnostics, resultType));
761 clang::QualType qType(cl->getTypeForDecl(),0);
769 clang::Sema& S = interp.getCI()->getSema();
772 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interp));
773 return S.RequireCompleteType(Loc, Type, clang::diag::err_incomplete_type);
779 const clang::CXXRecordDecl *context,
const cling::Interpreter &interp)
785 if (!cl->getDefinition() || !cl->isCompleteDefinition()) {
789 if (!CheckDefinition(cl, context) || !CheckDefinition(base, context)) {
793 if (!base->hasDefinition()) {
797 return cl->isDerivedFrom(base);
809 const clang::NamedDecl *base
813 return IsBase(CRD, llvm::dyn_cast<clang::CXXRecordDecl>( base ),
814 llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext()),interp);
822 const clang::NamedDecl &forcontext,
823 const clang::QualType &qti,
824 const char *R__t,
int rwmode,
825 const cling::Interpreter &interp,
828 static const clang::CXXRecordDecl *TObject_decl
831 kBIT_ISTOBJECT = 0x10000000,
832 kBIT_HASSTREAMER = 0x20000000,
833 kBIT_ISSTRING = 0x40000000,
835 kBIT_ISPOINTER = 0x00001000,
836 kBIT_ISFUNDAMENTAL = 0x00000020,
837 kBIT_ISENUM = 0x00000008
840 const clang::Type &ti( * qti.getTypePtr() );
850 clang::CXXRecordDecl *cxxtype = rawtype->getAsCXXRecordDecl() ;
852 int isTObj = cxxtype && (
IsBase(cxxtype,TObject_decl,
nullptr,interp) || rawname ==
"TObject");
856 if (ti.isPointerType()) kase |= kBIT_ISPOINTER;
857 if (rawtype->isFundamentalType()) kase |= kBIT_ISFUNDAMENTAL;
858 if (rawtype->isEnumeralType()) kase |= kBIT_ISENUM;
861 if (isTObj) kase |= kBIT_ISTOBJECT;
862 if (isStre) kase |= kBIT_HASSTREAMER;
863 if (tiName ==
"string") kase |= kBIT_ISSTRING;
864 if (tiName ==
"string*") kase |= kBIT_ISSTRING;
868 tcl =
" internal error in rootcling ";
873 if (R__t) finalString <<
" " << tiName <<
" " << R__t <<
";" << std::endl;
876 case kBIT_ISFUNDAMENTAL:
878 finalString <<
" R__b >> " << R__t <<
";" << std::endl;
881 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
883 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
892 finalString <<
" Int_t readtemp;" << std::endl
893 <<
" R__b >> readtemp;" << std::endl
894 <<
" " << R__t <<
" = static_cast<" << tiName <<
">(readtemp);" << std::endl;
897 case kBIT_HASSTREAMER:
898 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
900 finalString <<
" " << R__t <<
".Streamer(R__b);" << std::endl;
903 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
906 finalString <<
" if (R__b.GetInfo() && R__b.GetInfo()->GetOldVersion()<=3) {" << std::endl;
907 if (cxxtype && cxxtype->isAbstract()) {
908 finalString <<
" R__ASSERT(0);// " << objType <<
" is abstract. We assume that older file could not be produced using this streaming method." << std::endl;
910 finalString <<
" " << R__t <<
" = new " << objType <<
";" << std::endl
911 <<
" " << R__t <<
"->Streamer(R__b);" << std::endl;
913 finalString <<
" } else {" << std::endl
914 <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl
915 <<
" }" << std::endl;
920 finalString <<
" {TString R__str;" << std::endl
921 <<
" R__str.Streamer(R__b);" << std::endl
922 <<
" " << R__t <<
" = R__str.Data();}" << std::endl;
925 case kBIT_ISSTRING|kBIT_ISPOINTER:
927 finalString <<
" {TString R__str;" << std::endl
928 <<
" R__str.Streamer(R__b);" << std::endl
929 <<
" " << R__t <<
" = new string(R__str.Data());}" << std::endl;
934 finalString <<
" " << R__t <<
" = (" << tiName <<
")R__b.ReadObjectAny(" << tcl <<
");" << std::endl;
939 finalString <<
" R__b.StreamObject(&" << R__t <<
"," << tcl <<
");" << std::endl;
947 case kBIT_ISFUNDAMENTAL:
948 case kBIT_ISPOINTER|kBIT_ISTOBJECT|kBIT_HASSTREAMER:
950 finalString <<
" R__b << " << R__t <<
";" << std::endl;
955 finalString <<
" { void *ptr_enum = (void*)&" << R__t <<
";\n";
956 finalString <<
" R__b >> *reinterpret_cast<Int_t*>(ptr_enum); }" << std::endl;
959 case kBIT_HASSTREAMER:
960 case kBIT_HASSTREAMER|kBIT_ISTOBJECT:
962 finalString <<
" ((" << objType <<
"&)" << R__t <<
").Streamer(R__b);" << std::endl;
965 case kBIT_HASSTREAMER|kBIT_ISPOINTER:
967 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
972 finalString <<
" {TString R__str(" << R__t <<
".c_str());" << std::endl
973 <<
" R__str.Streamer(R__b);};" << std::endl;
976 case kBIT_ISSTRING|kBIT_ISPOINTER:
978 finalString <<
" {TString R__str(" << R__t <<
"->c_str());" << std::endl
979 <<
" R__str.Streamer(R__b);}" << std::endl;
984 finalString <<
" R__b.WriteObjectAny(" << R__t <<
"," << tcl <<
");" << std::endl;
989 finalString <<
" R__b.StreamObject((" << objType <<
"*)&" << R__t <<
"," << tcl <<
");" << std::endl;
1001 clang::CXXRecordDecl* ncCl =
const_cast<clang::CXXRecordDecl*
>(cl);
1004 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
1006 if (
auto* Ctor = interpreter.getCI()->getSema().LookupDefaultConstructor(ncCl)) {
1007 if (Ctor->getAccess() == clang::AS_public && !Ctor->isDeleted()) {
1020 const char *typeOfArg,
1021 const clang::CXXRecordDecl *expectedArgType,
1022 const cling::Interpreter& interpreter)
1024 if (typeOfArg && !expectedArgType) {
1025 const cling::LookupHelper& lh = interpreter.getLookupHelper();
1028 clang::QualType instanceType = lh.findType(typeOfArg, cling::LookupHelper::WithDiagnostics);
1029 if (!instanceType.isNull())
1030 expectedArgType = instanceType->getAsCXXRecordDecl();
1033 if (!expectedArgType)
1034 return EIOCtorCategory::kAbsent;
1037 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
1038 for (
auto iter = cl->ctor_begin(), end = cl->ctor_end(); iter != end; ++iter)
1040 if ((iter->getAccess() != clang::AS_public) || (iter->getNumParams() != 1))
1044 clang::QualType argType((*iter->param_begin())->getType());
1045 argType = argType.getDesugaredType(cl->getASTContext());
1047 auto ioCtorCategory = EIOCtorCategory::kAbsent;
1048 if (argType->isPointerType()) {
1049 ioCtorCategory = EIOCtorCategory::kIOPtrType;
1050 argType = argType->getPointeeType();
1051 }
else if (argType->isReferenceType()) {
1052 ioCtorCategory = EIOCtorCategory::kIORefType;
1053 argType = argType.getNonReferenceType();
1057 argType = argType.getDesugaredType(cl->getASTContext());
1058 const clang::CXXRecordDecl *argDecl = argType->getAsCXXRecordDecl();
1060 if (argDecl->getCanonicalDecl() == expectedArgType->getCanonicalDecl()) {
1061 return ioCtorCategory;
1064 std::string realArg = argType.getAsString();
1065 std::string clarg(
"class ");
1067 if (realArg == clarg)
1068 return ioCtorCategory;
1072 return EIOCtorCategory::kAbsent;
1081 const cling::Interpreter& interpreter)
1083 const char *arg = ioctortype.
GetName();
1085 if (!ioctortype.
GetType() && (!arg || !arg[0])) {
1098 const char *method,
const char *
proto,
1099 const cling::Interpreter &interp,
1102 const clang::FunctionDecl* funcD
1103 = interp.getLookupHelper().findFunctionProto(cinfo, method,
proto,
1104 diagnose ? cling::LookupHelper::WithDiagnostics
1105 : cling::LookupHelper::NoDiagnostics);
1107 return llvm::dyn_cast<const clang::CXXMethodDecl>(funcD);
1116 namespace TMetaUtils {
1119 const cling::LookupHelper& lh = interp.getLookupHelper();
1122 clang::QualType instanceType = lh.findType(type_of_arg, cling::LookupHelper::WithDiagnostics);
1123 if (!instanceType.isNull())
1124 fArgType = instanceType->getAsCXXRecordDecl();
1138 const cling::Interpreter &interp)
1140 if (cl->isAbstract())
return false;
1142 for (
auto & ctorType : ctorTypes) {
1146 if (EIOCtorCategory::kAbsent == ioCtorCat)
1149 std::string
proto( ctorType.GetName() );
1150 bool defaultCtor =
proto.empty();
1156 if (EIOCtorCategory::kIOPtrType == ioCtorCat) {
1158 }
else if (EIOCtorCategory::kIORefType == ioCtorCat) {
1162 arg +=
")nullptr )";
1165 const clang::CXXMethodDecl *method
1167 cling::LookupHelper::NoDiagnostics);
1168 if (method && method->getAccess() != clang::AS_public) {
1182 const cling::Interpreter& interp)
1184 if (!cl)
return false;
1186 if (cl->hasUserDeclaredDestructor()) {
1188 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interp));
1189 clang::CXXDestructorDecl *
dest = cl->getDestructor();
1191 return (
dest->getAccess() == clang::AS_public);
1203 const char *methodname,
1205 const cling::Interpreter &interp,
1208 const clang::CXXMethodDecl *method
1210 diagnose ? cling::LookupHelper::WithDiagnostics
1211 : cling::LookupHelper::NoDiagnostics);
1212 return (method && method->getAccess() == clang::AS_public);
1223 const char *
proto =
"TDirectory*";
1224 const char *
name =
"DirectoryAutoAdd";
1238 const char *
proto =
"TCollection*,TFileMergeInfo*";
1239 const char *
name =
"Merge";
1252 const char *
proto =
"TCollection*";
1253 const char *
name =
"Merge";
1268 const char *
proto =
"TFileMergeInfo*";
1269 const char *
name =
"ResetAfterMerge";
1279 const clang::CXXRecordDecl* clxx,
1280 const cling::Interpreter &interp,
1283 static const char *
proto =
"TBuffer&";
1285 const clang::CXXMethodDecl *method
1287 cling::LookupHelper::NoDiagnostics);
1288 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1290 return (method && method->getDeclContext() == clxx_as_context
1298 const clang::CXXRecordDecl* clxx,
1299 const cling::Interpreter &interp,
1302 static const char *
proto =
"TBuffer&,TClass*";
1304 const clang::CXXMethodDecl *method
1306 cling::LookupHelper::NoDiagnostics);
1307 const clang::DeclContext *clxx_as_context = llvm::dyn_cast<clang::DeclContext>(clxx);
1309 return (method && method->getDeclContext() == clxx_as_context
1339 clang::QualType qualType(&
type,0);
1371 llvm::raw_string_ostream stream(qual_name);
1372 clang::PrintingPolicy policy( cl.getASTContext().getPrintingPolicy() );
1373 policy.SuppressTagKeyword =
true;
1374 policy.SuppressUnwrittenScope =
true;
1376 cl.getNameForDiagnostic(stream,policy,
true);
1379 if ( qual_name ==
"(anonymous " || qual_name ==
"(unnamed" ) {
1380 size_t pos = qual_name.find(
':');
1381 qual_name.erase(0,pos+2);
1397 const clang::Type* declType ( recordDecl.getTypeForDecl() );
1398 clang::QualType qualType(declType,0);
1432 std::stringstream dims;
1433 std::string typenameStr;
1435 const clang::ASTContext& astContext = cl.getASTContext();
1438 for(clang::RecordDecl::field_iterator field_iter = cl.field_begin(), end = cl.field_end();
1446 typenameStr.clear();
1450 clang::QualType fieldType(field_iter->getType());
1451 if (fieldType->isConstantArrayType()) {
1452 const clang::ConstantArrayType *arrayType = llvm::dyn_cast<clang::ConstantArrayType>(fieldType.getTypePtr());
1454 dims <<
"[" << arrayType->getSize().getLimitedValue() <<
"]";
1455 fieldType = arrayType->getElementType();
1456 arrayType = llvm::dyn_cast<clang::ConstantArrayType>(arrayType->getArrayElementTypeNoTypeQual());
1466 for(clang::CXXRecordDecl::base_class_const_iterator iter = cl.bases_begin(), end = cl.bases_end();
1469 std::string basename( iter->getType()->getAsCXXRecordDecl()->getNameAsString() );
1479 const cling::Interpreter &interp,
1482 return interp.getLookupHelper().findFunctionProto(cinfo, method,
proto,
1483 diagnose ? cling::LookupHelper::WithDiagnostics
1484 : cling::LookupHelper::NoDiagnostics);
1518 clang::SourceLocation sourceLocation = decl->getLocation();
1519 clang::SourceManager& sourceManager = decl->getASTContext().getSourceManager();
1521 if (!sourceLocation.isValid() ) {
1525 if (!sourceLocation.isFileID()) {
1526 sourceLocation = sourceManager.getExpansionRange(sourceLocation).getEnd();
1529 if (sourceLocation.isValid() && sourceLocation.isFileID()) {
1530 return sourceManager.getLineNumber(sourceManager.getFileID(sourceLocation),sourceManager.getFileOffset(sourceLocation));
1543 while (llvm::isa<clang::PointerType>(instanceType.getTypePtr())
1544 || llvm::isa<clang::ReferenceType>(instanceType.getTypePtr()))
1546 instanceType = instanceType->getPointeeType();
1549 const clang::ElaboratedType* etype
1550 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
1552 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
1565 const clang::CXXRecordDecl* clxx = instanceType->getAsCXXRecordDecl();
1566 if (clxx && clxx->getTemplateSpecializationKind() != clang::TSK_Undeclared) {
1568 const clang::TemplateSpecializationType* TST
1569 = llvm::dyn_cast<const clang::TemplateSpecializationType>(instanceType.getTypePtr());
1576 for (
const clang::TemplateArgument &
TA : TST->template_arguments()) {
1577 if (
TA.getKind() == clang::TemplateArgument::Type) {
1589 const cling::Interpreter &interp,
1592 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
1593 if (!clxx || clxx->getTemplateSpecializationKind() == clang::TSK_Undeclared)
return false;
1595 clang::QualType instanceType = interp.getLookupHelper().findType(cl.
GetNormalizedName(),
1596 cling::LookupHelper::WithDiagnostics);
1597 if (instanceType.isNull()) {
1610 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(attribute);
1615 attrString = annAttr->getAnnotation().str();
1624 size_t substrFound (attributeStr.find(propNames::separator));
1625 if (substrFound==std::string::npos) {
1629 size_t EndPart1 = attributeStr.find_first_of(propNames::separator) ;
1630 attrName = attributeStr.substr(0, EndPart1);
1631 const int separatorLength(propNames::separator.
size());
1632 attrValue = attributeStr.substr(EndPart1 + separatorLength);
1640 std::string attrString;
1642 if (0!=ret)
return ret;
1650 const std::string& propName,
1651 std::string& propValue)
1653 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1654 attrIt!=decl.attr_end();++attrIt){
1655 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1656 if (!annAttr)
continue;
1658 llvm::StringRef attribute = annAttr->getAnnotation();
1659 std::pair<llvm::StringRef,llvm::StringRef> split = attribute.split(propNames::separator.c_str());
1660 if (split.first != propName.c_str())
continue;
1662 propValue = split.second.str();
1673 const std::string& propName,
1676 for (clang::Decl::attr_iterator attrIt = decl.attr_begin();
1677 attrIt!=decl.attr_end();++attrIt){
1678 clang::AnnotateAttr* annAttr = clang::dyn_cast<clang::AnnotateAttr>(*attrIt);
1679 if (!annAttr)
continue;
1681 llvm::StringRef attribute = annAttr->getAnnotation();
1682 std::pair<llvm::StringRef,llvm::StringRef> split = attribute.split(propNames::separator.c_str());
1683 if (split.first != propName.c_str())
continue;
1685 return split.second.getAsInteger(10,propValue);
1696 const clang::CXXRecordDecl *decl,
1697 const cling::Interpreter &interp,
1700 bool& needCollectionProxy)
1704 std::string mappedname;
1706 std::string csymbol = classname;
1714 csymbol.insert(0,
"::");
1720 bool isStd = TMetaUtils::IsStdClass(*decl);
1721 const cling::LookupHelper& lh = interp.getLookupHelper();
1722 bool isString = TMetaUtils::IsOfType(*decl,
"std::string",lh);
1724 bool isStdNotString = isStd && !isString;
1726 finalString <<
"namespace ROOT {" <<
"\n";
1730 finalString <<
" static TClass *" << mappedname.c_str() <<
"_Dictionary();\n"
1731 <<
" static void " << mappedname.c_str() <<
"_TClassManip(TClass*);\n";
1737 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p = nullptr);" <<
"\n";
1741 finalString <<
" static void *newArray_";
1742 finalString << mappedname.c_str();
1743 finalString <<
"(Long_t size, void *p);";
1744 finalString <<
"\n";
1749 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";
1752 finalString <<
" static void directoryAutoAdd_" << mappedname.c_str() <<
"(void *obj, TDirectory *dir);" <<
"\n";
1755 finalString <<
" static void streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj);" <<
"\n";
1758 finalString <<
" static void conv_streamer_" << mappedname.c_str() <<
"(TBuffer &buf, void *obj, const TClass*);" <<
"\n";
1761 finalString <<
" static Long64_t merge_" << mappedname.c_str() <<
"(void *obj, TCollection *coll,TFileMergeInfo *info);" <<
"\n";
1764 finalString <<
" static void reset_" << mappedname.c_str() <<
"(void *obj, TFileMergeInfo *info);" <<
"\n";
1771 ROOT::SchemaRuleClassMap_t::iterator rulesIt1 =
ROOT::gReadRules.find( classname.c_str() );
1772 ROOT::SchemaRuleClassMap_t::iterator rulesIt2 =
ROOT::gReadRawRules.find( classname.c_str() );
1783 finalString <<
"\n // Schema evolution read functions\n";
1784 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt1->second.begin();
1785 while( rIt != rulesIt1->second.end() ) {
1791 std::string error_string;
1793 Warning(
nullptr,
"%s", error_string.c_str());
1794 rIt = rulesIt1->second.erase(rIt);
1802 if( rIt->find(
"code" ) != rIt->end() ) {
1818 finalString <<
"\n // Schema evolution read raw functions\n";
1819 std::list<ROOT::SchemaRuleMap_t>::iterator rIt = rulesIt2->second.begin();
1820 while( rIt != rulesIt2->second.end() ) {
1826 std::string error_string;
1828 Warning(
nullptr,
"%s", error_string.c_str());
1829 rIt = rulesIt2->second.erase(rIt);
1837 if( rIt->find(
"code" ) == rIt->end() )
1845 finalString <<
"\n" <<
" // Function generating the singleton type initializer" <<
"\n";
1847 finalString <<
" static TGenericClassInfo *GenerateInitInstanceLocal(const " << csymbol <<
"*)" <<
"\n" <<
" {" <<
"\n";
1849 finalString <<
" " << csymbol <<
" *ptr = nullptr;" <<
"\n";
1853 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< " << csymbol <<
" >(nullptr);" <<
"\n";
1856 finalString <<
" static ::TVirtualIsAProxy* isa_proxy = new ::TIsAProxy(typeid(" << csymbol <<
"));" <<
"\n";
1858 finalString <<
" static ::ROOT::TGenericClassInfo " <<
"\n" <<
" instance(\"" << classname.c_str() <<
"\", ";
1861 finalString << csymbol <<
"::Class_Version(), ";
1863 finalString <<
"2, ";
1865 finalString <<
"-2, ";
1871 static const char *versionFunc =
"GetClassVersion";
1875 std::string
proto = classname +
"*";
1876 const clang::Decl* ctxt = llvm::dyn_cast<clang::Decl>((*cl).getDeclContext());
1877 const clang::FunctionDecl *methodinfo
1879 interp, cling::LookupHelper::NoDiagnostics);
1887 finalString <<
"GetClassVersion< ";
1888 finalString << classname.c_str();
1889 finalString <<
" >(), ";
1898 for (
unsigned int i=0; i<
filename.length(); i++) {
1903 <<
"," <<
"\n" <<
" typeid(" << csymbol
1904 <<
"), ::ROOT::Internal::DefineBehavior(ptr, ptr)," <<
"\n" <<
" ";
1907 finalString <<
"&" << csymbol <<
"::Dictionary, ";
1909 finalString <<
"&" << mappedname <<
"_Dictionary, ";
1913 TClassTable__kHasCustomStreamerMember = 0x10
1918 rootflag = rootflag | TClassTable__kHasCustomStreamerMember;
1920 finalString <<
"isa_proxy, " << rootflag <<
"," <<
"\n" <<
" sizeof(" << csymbol <<
") );" <<
"\n";
1922 finalString <<
" instance.SetNew(&new_" << mappedname.c_str() <<
");" <<
"\n";
1924 finalString <<
" instance.SetNewArray(&newArray_" << mappedname.c_str() <<
");" <<
"\n";
1927 finalString <<
" instance.SetDelete(&delete_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDeleteArray(&deleteArray_" << mappedname.c_str() <<
");" <<
"\n" <<
" instance.SetDestructor(&destruct_" << mappedname.c_str() <<
");" <<
"\n";
1930 finalString <<
" instance.SetDirectoryAutoAdd(&directoryAutoAdd_" << mappedname.c_str() <<
");" <<
"\n";
1934 finalString <<
" instance.SetStreamerFunc(&streamer_" << mappedname.c_str() <<
");" <<
"\n";
1938 finalString <<
" instance.SetConvStreamerFunc(&conv_streamer_" << mappedname.c_str() <<
");" <<
"\n";
1941 finalString <<
" instance.SetMerge(&merge_" << mappedname.c_str() <<
");" <<
"\n";
1944 finalString <<
" instance.SetResetAfterMerge(&reset_" << mappedname.c_str() <<
");" <<
"\n";
1947 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" <<
"Pushback" <<
"<Internal::TStdBitsetHelper< " << classname.c_str() <<
" > >()));" <<
"\n";
1949 needCollectionProxy =
true;
1950 }
else if (stl != 0 &&
1953 int idx = classname.find(
"<");
1955 const char* methodTCP =
nullptr;
1961 methodTCP=
"Pushback";
1964 methodTCP=
"Pushfront";
1970 methodTCP=
"MapInsert";
1982 finalString <<
" instance.AdoptCollectionProxyInfo(TCollectionProxyInfo::Generate(TCollectionProxyInfo::" << methodTCP <<
"< " << classNameForIO.c_str() <<
" >()));" <<
"\n";
1984 needCollectionProxy =
true;
1992 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
1999 finalString <<
"\n" <<
" instance.AdoptAlternate(::ROOT::AddClassAlternate(\""
2009 finalString <<
"\n" <<
" ::ROOT::Internal::TSchemaHelper* rule;" <<
"\n";
2013 finalString <<
"\n" <<
" // the io read rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrules(" << rulesIt1->second.size() <<
");" <<
"\n";
2015 finalString <<
" instance.SetReadRules( readrules );" <<
"\n";
2019 finalString <<
"\n" <<
" // the io read raw rules" <<
"\n" <<
" std::vector<::ROOT::Internal::TSchemaHelper> readrawrules(" << rulesIt2->second.size() <<
");" <<
"\n";
2021 finalString <<
" instance.SetReadRawRules( readrawrules );" <<
"\n";
2024 finalString <<
" return &instance;" <<
"\n" <<
" }" <<
"\n";
2028 finalString <<
" TGenericClassInfo *GenerateInitInstance(const " << csymbol <<
"*)" <<
"\n" <<
" {\n return GenerateInitInstanceLocal(static_cast<" << csymbol <<
"*>(nullptr));\n }" <<
"\n";
2031 finalString <<
" // Static variable to force the class initialization" <<
"\n";
2035 finalString <<
" static ::ROOT::TGenericClassInfo *_R__UNIQUE_DICT_(Init) = GenerateInitInstanceLocal(static_cast<const " << csymbol <<
"*>(nullptr)); R__UseDummy(_R__UNIQUE_DICT_(Init));" <<
"\n";
2038 finalString <<
"\n" <<
" // Dictionary for non-ClassDef classes" <<
"\n"
2039 <<
" static TClass *" << mappedname <<
"_Dictionary() {\n"
2040 <<
" TClass* theClass ="
2041 <<
"::ROOT::GenerateInitInstanceLocal(static_cast<const " << csymbol <<
"*>(nullptr))->GetClass();\n"
2042 <<
" " << mappedname <<
"_TClassManip(theClass);\n";
2043 finalString <<
" return theClass;\n";
2044 finalString <<
" }\n\n";
2048 std::string manipString;
2049 std::string attribute_s;
2050 std::string attrName, attrValue;
2052 bool attrMapExtracted =
false;
2053 if (decl->hasAttrs()){
2055 for (clang::Decl::attr_iterator attrIt = decl->attr_begin();
2056 attrIt!=decl->attr_end();++attrIt){
2063 if (attrName ==
"name" ||
2064 attrName ==
"pattern" ||
2065 attrName ==
"rootmap")
continue;
2071 if (!attrMapExtracted){
2072 manipString+=
" theClass->CreateAttributeMap();\n";
2073 manipString+=
" TDictAttributeMap* attrMap( theClass->GetAttributeMap() );\n";
2074 attrMapExtracted=
true;
2076 manipString+=
" attrMap->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2082 for(clang::CXXRecordDecl::decl_iterator internalDeclIt = decl->decls_begin();
2083 internalDeclIt != decl->decls_end(); ++internalDeclIt){
2084 if (!(!(*internalDeclIt)->isImplicit()
2085 && (clang::isa<clang::FieldDecl>(*internalDeclIt) ||
2086 clang::isa<clang::VarDecl>(*internalDeclIt))))
continue;
2089 if (!internalDeclIt->hasAttrs())
continue;
2091 attrMapExtracted =
false;
2092 bool memberPtrCreated =
false;
2094 for (clang::Decl::attr_iterator attrIt = internalDeclIt->attr_begin();
2095 attrIt!=internalDeclIt->attr_end();++attrIt){
2103 clang::NamedDecl* namedInternalDecl = clang::dyn_cast<clang::NamedDecl> (*internalDeclIt);
2104 if (!namedInternalDecl) {
2105 TMetaUtils::Error(
nullptr,
"Cannot convert field declaration to clang::NamedDecl");
2108 const std::string memberName(namedInternalDecl->getName());
2109 const std::string cppMemberName =
"theMember_"+memberName;
2112 const std::string dataMemberCreation=
" TDataMember* "+cppMemberName+
" = theClass->GetDataMember(\""+memberName+
"\");\n";
2121 if (attrName == propNames::comment ||
2122 attrName == propNames::iotype ||
2123 attrName == propNames::ioname )
continue;
2125 if (!memberPtrCreated){
2126 manipString+=dataMemberCreation;
2127 memberPtrCreated=
true;
2130 if (!attrMapExtracted){
2131 manipString+=
" "+cppMemberName+
"->CreateAttributeMap();\n";
2132 manipString+=
" TDictAttributeMap* memberAttrMap_"+memberName+
"( theMember_"+memberName+
"->GetAttributeMap() );\n";
2133 attrMapExtracted=
true;
2136 manipString+=
" memberAttrMap_"+memberName+
"->AddProperty(\""+attrName +
"\",\""+attrValue+
"\");\n";
2143 finalString <<
" static void " << mappedname <<
"_TClassManip(TClass* " << (manipString.empty() ?
"":
"theClass") <<
"){\n"
2148 finalString <<
"} // end of namespace ROOT" <<
"\n" <<
"\n";
2158 std::string &clsname,
2159 std::string &nsname,
2160 const clang::CXXRecordDecl *cl)
2170 auto ctxt = cl->getEnclosingNamespaceContext();
2171 while(ctxt && ctxt!=cl && ctxt->isInlineNamespace()) {
2172 ctxt = ctxt->getParent();
2175 const clang::NamedDecl *namedCtxt = llvm::dyn_cast<clang::NamedDecl>(ctxt);
2176 if (namedCtxt && namedCtxt!=cl) {
2177 const clang::NamespaceDecl *nsdecl = llvm::dyn_cast<clang::NamespaceDecl>(namedCtxt);
2178 if (nsdecl && !nsdecl->isAnonymousNamespace()) {
2180 clsname.erase (0, nsname.size() + 2);
2192 const clang::DeclContext *ctxt = cl.getDeclContext();
2193 while(ctxt && !ctxt->isNamespace()) {
2194 ctxt = ctxt->getParent();
2208 int closing_brackets = 0;
2212 if (ctxt && ctxt->isNamespace()) {
2214 const clang::NamespaceDecl *ns = llvm::dyn_cast<clang::NamespaceDecl>(ctxt);
2220 out <<
"namespace " << ns->getNameAsString() <<
" {" << std::endl;
2225 return closing_brackets;
2239 clang::TemplateSpecializationKind kind = cl->getTemplateSpecializationKind();
2240 if (kind == clang::TSK_Undeclared ) {
2243 }
else if (kind == clang::TSK_ExplicitSpecialization) {
2257 const char *
name = which;
2258 const char *
proto =
"size_t";
2259 const char *protoPlacement =
"size_t,void*";
2262 const clang::FunctionDecl *operatornew
2265 cling::LookupHelper::NoDiagnostics);
2266 const clang::FunctionDecl *operatornewPlacement
2268 name, protoPlacement, interp,
2269 cling::LookupHelper::NoDiagnostics);
2271 const clang::DeclContext *ctxtnew =
nullptr;
2272 const clang::DeclContext *ctxtnewPlacement =
nullptr;
2275 ctxtnew = operatornew->getParent();
2277 if (operatornewPlacement) {
2278 ctxtnewPlacement = operatornewPlacement->getParent();
2284 operatornewPlacement
2289 ctxtnew = operatornew->getParent();
2291 if (operatornewPlacement) {
2292 ctxtnewPlacement = operatornewPlacement->getParent();
2295 if (!ctxtnewPlacement) {
2303 if (ctxtnew == ctxtnewPlacement) {
2307 const clang::CXXRecordDecl* clnew = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnew);
2308 const clang::CXXRecordDecl* clnewPlacement = llvm::dyn_cast<clang::CXXRecordDecl>(ctxtnewPlacement);
2309 if (!clnew && !clnewPlacement) {
2315 if (clnew && !clnewPlacement) {
2319 if (!clnew && clnewPlacement) {
2324 if (clnew->isDerivedFrom(clnewPlacement)) {
2354 const clang::CXXRecordDecl *decl,
2355 const cling::Interpreter &interp,
2361 std::string mappedname;
2379 classname.insert(0,
"::");
2382 finalString <<
"namespace ROOT {" <<
"\n";
2387 finalString <<
" // Wrappers around operator new" <<
"\n";
2388 finalString <<
" static void *new_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" return p ? ";
2390 finalString <<
"new(p) ";
2391 finalString << classname.c_str();
2392 finalString << args;
2393 finalString <<
" : ";
2395 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2396 finalString << classname.c_str();
2397 finalString << args;
2398 finalString <<
" : ";
2400 finalString <<
"new " << classname.c_str() << args <<
";" <<
"\n";
2401 finalString <<
" }" <<
"\n";
2405 finalString <<
" static void *newArray_";
2406 finalString << mappedname.c_str();
2407 finalString <<
"(Long_t nElements, void *p) {";
2408 finalString <<
"\n";
2409 finalString <<
" return p ? ";
2411 finalString <<
"new(p) ";
2412 finalString << classname.c_str();
2413 finalString <<
"[nElements] : ";
2415 finalString <<
"::new(static_cast<::ROOT::Internal::TOperatorNewHelper*>(p)) ";
2416 finalString << classname.c_str();
2417 finalString <<
"[nElements] : ";
2419 finalString <<
"new ";
2420 finalString << classname.c_str();
2421 finalString <<
"[nElements];";
2422 finalString <<
"\n";
2423 finalString <<
" }";
2424 finalString <<
"\n";
2429 finalString <<
" // Wrapper around operator delete" <<
"\n" <<
" static void delete_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" delete (static_cast<" << classname.c_str() <<
"*>(p));" <<
"\n" <<
" }" <<
"\n" <<
" static void deleteArray_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" delete [] (static_cast<" << classname.c_str() <<
"*>(p));" <<
"\n" <<
" }" <<
"\n" <<
" static void destruct_" << mappedname.c_str() <<
"(void *p) {" <<
"\n" <<
" typedef " << classname.c_str() <<
" current_t;" <<
"\n" <<
" (static_cast<current_t*>(p))->~current_t();" <<
"\n" <<
" }" <<
"\n";
2433 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";
2437 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";
2441 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";
2445 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";
2447 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";
2451 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";
2453 finalString <<
"} // end of namespace ROOT for class " << classname.c_str() <<
"\n" <<
"\n";
2460 const cling::Interpreter &interp,
2467 if (version == 0)
return;
2471 const clang::CXXRecordDecl *clxx = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2475 for(clang::CXXRecordDecl::base_class_const_iterator iter = clxx->bases_begin(), end = clxx->bases_end();
2481 Internal::RStl::Instance().GenerateTClassFor( iter->getType(), interp, normCtxt);
2486 for(clang::RecordDecl::field_iterator field_iter = clxx->field_begin(), end = clxx->field_end();
2490 std::string mTypename;
2496 if (!strcmp(shortTypeName,
"string")) {
2508 Internal::RStl::Instance().GenerateTClassFor(utype, interp, normCtxt);
2518 const clang::Type *rawtype =
m.getType()->getCanonicalTypeInternal().getTypePtr();
2519 if (rawtype->isArrayType()) {
2520 rawtype = rawtype->getBaseElementTypeUnsafe ();
2534 const clang::CXXRecordDecl* CRD = llvm::dyn_cast<clang::CXXRecordDecl>(cl);
2543 if (!funcCV)
return -1;
2546 if (funcCV == (clang::FunctionDecl*)-1)
return 1;
2561 using res_t = std::pair<bool, int>;
2563 const clang::CompoundStmt* FuncBody
2564 = llvm::dyn_cast_or_null<clang::CompoundStmt>(funcCV->getBody());
2566 return res_t{
false, -1};
2567 if (FuncBody->size() != 1) {
2571 return res_t{
false, -1};
2573 const clang::ReturnStmt* RetStmt
2574 = llvm::dyn_cast<clang::ReturnStmt>(FuncBody->body_back());
2576 return res_t{
false, -1};
2577 const clang::Expr* RetExpr = RetStmt->getRetValue();
2583 if (
auto RetRes = RetExpr->getIntegerConstantExpr(funcCV->getASTContext())) {
2584 if (RetRes->isSigned())
2585 return res_t{
true, (
Version_t)RetRes->getSExtValue()};
2586 return res_t{
true, (
Version_t)RetRes->getZExtValue()};
2588 return res_t{
false, -1};
2604 clang::QualType
type =
m.getType();
2607 if (decl)
return TMetaUtils::IsSTLCont(*decl);
2616 clang::QualType
type = base.getType();
2619 if (decl)
return TMetaUtils::IsSTLCont(*decl);
2629 const std::function<
void(
const clang::Module::Header &)> &closure,
2630 bool includeDirectlyUsedModules)
2639 const std::size_t publicHeaderIndex = 4;
2642 const std::size_t maxArrayLength = ((
sizeof module.Headers) / (
sizeof *module.Headers));
2643 static_assert(publicHeaderIndex + 1 == maxArrayLength,
2644 "'Headers' has changed it's size, we need to update publicHeaderIndex");
2649 llvm::SetVector<const clang::Module *> modules;
2650 modules.insert(&module);
2651 for (
size_t i = 0; i < modules.size(); ++i) {
2652 const clang::Module *M = modules[i];
2653 for (
const clang::Module *subModule : M->submodules())
2654 modules.insert(subModule);
2657 for (
const clang::Module *
m : modules) {
2658 if (includeDirectlyUsedModules) {
2659 for (clang::Module *used :
m->DirectUses) {
2664 for (std::size_t i = 0; i < publicHeaderIndex; i++) {
2665 auto &headerList =
m->Headers[i];
2666 for (
const clang::Module::Header &moduleHeader : headerList) {
2667 closure(moduleHeader);
2681 static char t[4096];
2682 static const char* constwd =
"const ";
2683 static const char* constwdend =
"const";
2688 for (s=typeDesc;*s;s++) {
2691 if (lev==0 && *s==
'*')
continue;
2692 if (lev==0 && (strncmp(constwd,s,strlen(constwd))==0
2693 ||strcmp(constwdend,s)==0 ) ) {
2694 s+=strlen(constwd)-1;
2697 if (lev==0 && *s==
' ' && *(s+1)!=
'*') {
p = t;
continue;}
2698 if (
p - t > (
long)
sizeof(t)) {
2699 printf(
"ERROR (rootcling): type name too long for StortTypeName: %s\n",
2712 const cling::Interpreter& interp)
2717 if (!comment.empty() && comment[0] ==
'!')
2720 clang::QualType
type =
m.getType();
2722 if (
type->isReferenceType()) {
2727 std::string mTypeName =
type.getAsString(
m.getASTContext().getPrintingPolicy());
2728 if (!strcmp(mTypeName.c_str(),
"string") || !strcmp(mTypeName.c_str(),
"string*")) {
2731 if (!strcmp(mTypeName.c_str(),
"std::string") || !strcmp(mTypeName.c_str(),
"std::string*")) {
2739 const clang::Type *rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
2741 if (rawtype->isPointerType()) {
2743 clang::QualType pointee;
2744 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
2746 rawtype = pointee.getTypePtr();
2750 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2755 const clang::CXXRecordDecl *cxxdecl = rawtype->getAsCXXRecordDecl();
2759 if (version > 0)
return true;
2772 const clang::Type *rawtype =
m.getType().getTypePtr();
2775 clang::QualType pointee;
2776 while ( rawtype->isPointerType() && ((pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull()) && pointee.getTypePtr() != rawtype)
2778 rawtype = pointee.getTypePtr();
2792 if (rawtype->isFundamentalType() || rawtype->isEnumeralType()) {
2796 return rawtype->getAsCXXRecordDecl();
2805 const cling::Interpreter &interp,
2807 std::ostream& dictStream,
2809 bool isGenreflex=
false)
2811 const clang::CXXRecordDecl* decl = llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl());
2813 if (!decl || !decl->isCompleteDefinition()) {
2817 std::string fullname;
2820 Internal::RStl::Instance().GenerateTClassFor(cl.
GetNormalizedName(), llvm::dyn_cast<clang::CXXRecordDecl>(cl.
GetRecordDecl()), interp, normCtxt);
2829 (*WriteStreamerFunc)(cl, interp, normCtxt, dictStream, isGenreflex || cl.RequestStreamerInfo());
2831 ROOT::TMetaUtils::Info(
nullptr,
"Class %s: Do not generate Streamer() [*** custom streamer ***]\n",fullname.c_str());
2853 const cling::Interpreter &interpreter,
2856 const clang::ASTContext& Ctx = interpreter.getCI()->getASTContext();
2858 clang::QualType originalType = instanceType;
2862 if (llvm::isa<clang::PointerType>(instanceType.getTypePtr())) {
2864 clang::Qualifiers quals = instanceType.getQualifiers();
2865 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
2866 if (newPointee != instanceType->getPointeeType()) {
2867 instanceType = Ctx.getPointerType(newPointee);
2869 instanceType = Ctx.getQualifiedType(instanceType, quals);
2871 return instanceType;
2876 if (llvm::isa<clang::ReferenceType>(instanceType.getTypePtr())) {
2878 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(instanceType.getTypePtr());
2879 clang::Qualifiers quals = instanceType.getQualifiers();
2880 clang::QualType newPointee =
AddDefaultParameters(instanceType->getPointeeType(), interpreter, normCtxt);
2882 if (newPointee != instanceType->getPointeeType()) {
2885 instanceType = Ctx.getLValueReferenceType(newPointee);
2887 instanceType = Ctx.getRValueReferenceType(newPointee);
2889 instanceType = Ctx.getQualifiedType(instanceType, quals);
2891 return instanceType;
2895 bool prefix_changed =
false;
2896 clang::NestedNameSpecifier *prefix =
nullptr;
2897 clang::Qualifiers prefix_qualifiers = instanceType.getLocalQualifiers();
2898 const clang::ElaboratedType* etype
2899 = llvm::dyn_cast<clang::ElaboratedType>(instanceType.getTypePtr());
2902 prefix = AddDefaultParametersNNS(Ctx, etype->getQualifier(), interpreter, normCtxt);
2903 prefix_changed = prefix != etype->getQualifier();
2904 instanceType = clang::QualType(etype->getNamedType().getTypePtr(),0);
2910 const clang::TemplateSpecializationType* TST
2911 = llvm::dyn_cast<const clang::TemplateSpecializationType>(instanceType.getTypePtr());
2913 const clang::ClassTemplateSpecializationDecl* TSTdecl
2914 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(instanceType.getTypePtr()->getAsCXXRecordDecl());
2926 bool mightHaveChanged =
false;
2927 if (TST && TSTdecl) {
2929 clang::Sema& S = interpreter.getCI()->getSema();
2930 clang::TemplateDecl *Template = TSTdecl->getSpecializedTemplate()->getMostRecentDecl();
2931 clang::TemplateParameterList *Params = Template->getTemplateParameters();
2932 clang::TemplateParameterList::iterator Param = Params->
begin();
2936 unsigned int dropDefault = normCtxt.
GetConfig().DropDefaultArg(*Template);
2938 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
2939 llvm::SmallVector<clang::TemplateArgument, 4> canonArgs;
2940 llvm::ArrayRef<clang::TemplateArgument> template_arguments = TST->template_arguments();
2941 unsigned int Idecl = 0, Edecl = TSTdecl->getTemplateArgs().size();
2942 unsigned int maxAddArg = TSTdecl->getTemplateArgs().size() - dropDefault;
2943 for (
const clang::TemplateArgument *
I = template_arguments.begin(), *E = template_arguments.end(); Idecl != Edecl;
2944 I != E ? ++
I :
nullptr, ++Idecl, ++Param) {
2948 if (
I->getKind() == clang::TemplateArgument::Template) {
2949 clang::TemplateName templateName =
I->getAsTemplate();
2950 clang::TemplateDecl* templateDecl = templateName.getAsTemplateDecl();
2952 clang::DeclContext* declCtxt = templateDecl->getDeclContext();
2954 if (declCtxt && !templateName.getAsQualifiedTemplateName()){
2955 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(declCtxt);
2956 clang::NestedNameSpecifier* nns;
2958 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx, ns);
2959 }
else if (clang::TagDecl* TD = llvm::dyn_cast<clang::TagDecl>(declCtxt)) {
2960 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx,TD,
false );
2963 desArgs.push_back(*
I);
2966 clang::TemplateName UnderlyingTN(templateDecl);
2967 if (clang::UsingShadowDecl *USD = templateName.getAsUsingShadowDecl())
2968 UnderlyingTN = clang::TemplateName(USD);
2969 clang::TemplateName templateNameWithNSS ( Ctx.getQualifiedTemplateName(nns,
false, UnderlyingTN) );
2970 desArgs.push_back(clang::TemplateArgument(templateNameWithNSS));
2971 mightHaveChanged =
true;
2977 if (
I->getKind() != clang::TemplateArgument::Type) {
2978 desArgs.push_back(*
I);
2982 clang::QualType SubTy =
I->getAsType();
2991 if (SubTy != newSubTy) {
2992 mightHaveChanged =
true;
2993 desArgs.push_back(clang::TemplateArgument(newSubTy));
2995 desArgs.push_back(*
I);
2998 }
else if (!isStdDropDefault && Idecl < maxAddArg) {
3000 mightHaveChanged =
true;
3002 const clang::TemplateArgument& templateArg
3003 = TSTdecl->getTemplateArgs().get(Idecl);
3004 if (templateArg.getKind() != clang::TemplateArgument::Type) {
3005 desArgs.push_back(templateArg);
3008 clang::QualType SubTy = templateArg.getAsType();
3010 clang::SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3011 clang::SourceLocation RAngleLoc = TSTdecl->getSourceRange().getBegin();
3013 clang::TemplateTypeParmDecl *TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*Param);
3016 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
3017 bool HasDefaultArgs;
3018 clang::TemplateArgumentLoc ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
3028 if (ArgType.getArgument().isNull()
3029 || ArgType.getArgument().getKind() != clang::TemplateArgument::Type) {
3031 "Template parameter substitution failed for %s around %s\n",
3032 instanceType.getAsString().c_str(), SubTy.getAsString().c_str());
3035 clang::QualType BetterSubTy = ArgType.getArgument().getAsType();
3036 SubTy = cling::utils::Transform::GetPartiallyDesugaredType(Ctx,BetterSubTy,normCtxt.
GetConfig(),
true);
3039 desArgs.push_back(clang::TemplateArgument(SubTy));
3048 if (mightHaveChanged) {
3049 instanceType = Ctx.getTemplateSpecializationType(TST->getTemplateName(),
3051 TST->getCanonicalTypeInternal());
3055 if (!prefix_changed && !mightHaveChanged)
return originalType;
3057 instanceType = Ctx.getElaboratedType(clang::ETK_None,prefix,instanceType);
3058 instanceType = Ctx.getQualifiedType(instanceType,prefix_qualifiers);
3060 return instanceType;
3080 llvm::StringRef title;
3083 if (clang::AnnotateAttr *A =
m.getAttr<clang::AnnotateAttr>())
3084 title = A->getAnnotation();
3096 if (errnum) *errnum =
VALID;
3098 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3099 size_t rightbracket = title.find(
']');
3100 if (rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3102 std::string working;
3103 llvm::StringRef indexvar(title.data()+1,rightbracket-1);
3110 size_t indexvarlen = indexvar.size();
3111 for ( i=0; i<indexvarlen; i++) {
3112 if (!isspace(indexvar[i])) {
3113 working += indexvar[i];
3118 const char *tokenlist =
"*+-";
3119 char *current =
const_cast<char*
>(working.c_str());
3120 current = strtok(current,tokenlist);
3124 if (isdigit(current[0])) {
3125 for(i=0;i<strlen(current);i++) {
3126 if (!isdigit(current[i])) {
3131 if (errstr) *errstr = current;
3132 if (errnum) *errnum =
NOT_INT;
3133 return llvm::StringRef();
3138 const clang::CXXRecordDecl *parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext());
3139 const clang::FieldDecl *index1 =
nullptr;
3141 index1 = GetDataMemberFromAll(*parent_clxx, current );
3143 if ( IsFieldDeclInt(index1) ) {
3148 for(clang::RecordDecl::field_iterator field_iter = parent_clxx->field_begin(), end = parent_clxx->field_end();
3152 if ( field_iter->getNameAsString() ==
m.getNameAsString() ) {
3158 if (errstr) *errstr = current;
3159 if (errnum) *errnum =
NOT_DEF;
3160 return llvm::StringRef();
3162 if ( field_iter->getNameAsString() == index1->getNameAsString() ) {
3170 if (errstr) *errstr = current;
3171 if (errnum) *errnum =
NOT_INT;
3172 return llvm::StringRef();
3179 clang::Sema& SemaR =
const_cast<cling::Interpreter&
>(interp).getSema();
3180 index1 = GetDataMemberFromAllParents(SemaR, *parent_clxx, current);
3183 if ( IsFieldDeclInt(index1) ) {
3190 if (errnum) *errnum =
NOT_INT;
3191 if (errstr) *errstr = current;
3195 if (errnum) *errnum =
NOT_INT;
3196 if (errstr) *errstr = current;
3197 return llvm::StringRef();
3199 if ( found && (index1->getAccess() == clang::AS_private) ) {
3202 if (errstr) *errstr = current;
3204 return llvm::StringRef();
3211 if (errstr) *errstr = indexvar;
3212 if (errnum) *errnum =
UNKNOWN;
3213 return llvm::StringRef();
3218 current = strtok(
nullptr, tokenlist);
3234 while((
c = in[i++])) {
3235 const char *repl =
nullptr;
3237 case '+': repl =
"pL";
break;
3238 case '-': repl =
"mI";
break;
3239 case '*': repl =
"mU";
break;
3240 case '/': repl =
"dI";
break;
3241 case '&': repl =
"aN";
break;
3242 case '%': repl =
"pE";
break;
3243 case '|': repl =
"oR";
break;
3244 case '^': repl =
"hA";
break;
3245 case '>': repl =
"gR";
break;
3246 case '<': repl =
"lE";
break;
3247 case '=': repl =
"eQ";
break;
3248 case '~': repl =
"wA";
break;
3249 case '.': repl =
"dO";
break;
3250 case '(': repl =
"oP";
break;
3251 case ')': repl =
"cP";
break;
3252 case '[': repl =
"oB";
break;
3253 case ']': repl =
"cB";
break;
3254 case '!': repl =
"nO";
break;
3255 case ',': repl =
"cO";
break;
3256 case '$': repl =
"dA";
break;
3257 case ' ': repl =
"sP";
break;
3258 case ':': repl =
"cL";
break;
3259 case '"': repl =
"dQ";
break;
3260 case '@': repl =
"aT";
break;
3261 case '\'': repl =
"sQ";
break;
3262 case '\\': repl =
"fI";
break;
3271 auto firstNonNumber = out.find_first_not_of(
"0123456789");
3272 if (firstNonNumber != std::string::npos)
3273 out.replace(0,firstNonNumber,
"");
3276static clang::SourceLocation
3278 clang::SourceLocation sourceLoc) {
3280 if (!sourceLoc.isFileID()) {
3281 return sourceManager.getExpansionRange(sourceLoc).getEnd();
3290 const cling::Interpreter& interp)
3320 using namespace clang;
3321 SourceLocation headerLoc = decl.getLocation();
3323 static const char invalidFilename[] =
"";
3324 if (!headerLoc.isValid())
return invalidFilename;
3326 HeaderSearch& HdrSearch = interp.getCI()->getPreprocessor().getHeaderSearchInfo();
3328 SourceManager& sourceManager = decl.getASTContext().getSourceManager();
3330 FileID headerFID = sourceManager.getFileID(headerLoc);
3331 SourceLocation includeLoc
3333 sourceManager.getIncludeLoc(headerFID));
3335 const FileEntry *headerFE = sourceManager.getFileEntryForID(headerFID);
3336 while (includeLoc.isValid() && sourceManager.isInSystemHeader(includeLoc)) {
3337 ConstSearchDirIterator *foundDir =
nullptr;
3340 assert(headerFE &&
"Couldn't find FileEntry from FID!");
3342 = HdrSearch.LookupFile(llvm::sys::path::filename(headerFE->getName()),
3344 true ,
nullptr, foundDir,
3345 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3353 headerFID = sourceManager.getFileID(includeLoc);
3354 headerFE = sourceManager.getFileEntryForID(headerFID);
3359 if (interp.getCI()->getLangOpts().Modules && !headerFE) {
3360 assert(decl.isFirstDecl() &&
"Couldn't trace back include from a decl"
3361 " that is not from an AST file");
3362 assert(StringRef(includeLoc.printToString(sourceManager)).startswith(
"<module-includes>"));
3366 sourceManager.getIncludeLoc(headerFID));
3369 if (!headerFE)
return invalidFilename;
3371 llvm::SmallString<256> headerFileName(headerFE->getName());
3374 llvm::sys::path::remove_dots(headerFileName,
true);
3385 bool isAbsolute = llvm::sys::path::is_absolute(headerFileName);
3386 clang::OptionalFileEntryRef FELong;
3388 for (llvm::sys::path::const_iterator
3389 IDir = llvm::sys::path::begin(headerFileName),
3390 EDir = llvm::sys::path::end(headerFileName);
3391 !FELong && IDir != EDir; ++IDir) {
3397 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3398 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3399 assert(trailingPart.data() + trailingPart.size()
3400 == headerFileName.data() + headerFileName.size()
3401 &&
"Mismatched partitioning of file name!");
3402 ConstSearchDirIterator* FoundDir =
nullptr;
3403 FELong = HdrSearch.LookupFile(trailingPart, SourceLocation(),
3404 true ,
nullptr, FoundDir,
3405 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3413 return invalidFilename;
3417 for (llvm::sys::path::reverse_iterator
3418 IDir = llvm::sys::path::rbegin(headerFileName),
3419 EDir = llvm::sys::path::rend(headerFileName);
3420 IDir != EDir; ++IDir) {
3421 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3422 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3423 assert(trailingPart.data() + trailingPart.size()
3424 == headerFileName.data() + headerFileName.size()
3425 &&
"Mismatched partitioning of file name!");
3426 ConstSearchDirIterator* FoundDir =
nullptr;
3429 if (HdrSearch.LookupFile(trailingPart, SourceLocation(),
3430 true ,
nullptr, FoundDir,
3431 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3434 nullptr,
nullptr ) == FELong) {
3435 return trailingPart.str();
3439 return invalidFilename;
3445 const clang::QualType &qtype,
3446 const clang::ASTContext &astContext)
3448 std::string fqname = cling::utils::TypeName::GetFullyQualifiedName(qtype, astContext);
3457 const clang::QualType &qtype,
3458 const cling::Interpreter &interpreter)
3463 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interpreter));
3467 interpreter.getCI()->getASTContext());
3475 clang::ClassTemplateDecl*& ctd,
3476 clang::ClassTemplateSpecializationDecl*& ctsd)
3478 using namespace clang;
3479 const Type* theType = qt.getTypePtr();
3486 if (theType->isPointerType()) {
3490 if (
const RecordType* rType = llvm::dyn_cast<RecordType>(theType)) {
3491 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(rType->getDecl());
3493 ctd = ctsd->getSpecializedTemplate();
3498 if (
const SubstTemplateTypeParmType* sttpType = llvm::dyn_cast<SubstTemplateTypeParmType>(theType)){
3503 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(qt->getAsCXXRecordDecl());
3505 ctd = ctsd->getSpecializedTemplate();
3520 using namespace clang;
3521 ClassTemplateSpecializationDecl* ctsd;
3522 ClassTemplateDecl* ctd;
3536 using namespace clang;
3537 TemplateName theTemplateName;
3539 const Type* theType = qt.getTypePtr();
3541 if (
const TemplateSpecializationType* tst = llvm::dyn_cast_or_null<const TemplateSpecializationType>(theType)) {
3542 theTemplateName = tst->getTemplateName();
3545 theTemplateName = TemplateName(ctd);
3548 return theTemplateName;
3554 llvm::SmallVectorImpl<clang::TemplateArgument>& preceedingTArgs,
3555 const clang::NamedDecl& tPar,
3556 const cling::Interpreter& interp,
3560 using namespace clang;
3563 TemplateTypeParmDecl* ttpdPtr =
const_cast<TemplateTypeParmDecl*
>(llvm::dyn_cast<TemplateTypeParmDecl>(&tPar));
3564 if (!ttpdPtr)
return false;
3565 if (!ttpdPtr->hasDefaultArgument())
return false;
3568 QualType tParQualType = ttpdPtr->getDefaultArgument();
3569 const QualType tArgQualType = tArg.getAsType();
3576 if (tParQualType.getTypePtr() == tArgQualType.getTypePtr())
return true;
3587 const clang::ElaboratedType* etype
3588 = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3590 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3591 etype = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3594 const TemplateSpecializationType* tst =
3595 llvm::dyn_cast<TemplateSpecializationType>(tParQualType.getTypePtr());
3600 ClassTemplateSpecializationDecl* TSTdecl
3601 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(tArgQualType->getAsCXXRecordDecl());
3606 TemplateDecl *Template = tst->getTemplateName().getAsTemplateDecl();
3609 SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3612 SourceLocation LAngleLoc = TSTdecl->getSourceRange().getBegin();
3617 TemplateArgument newArg = tArg;
3619 clang::Sema& S = interp.getCI()->getSema();
3620 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interp));
3621 llvm::SmallVector<clang::TemplateArgument, 4> canonArgs;
3622 bool HasDefaultArgs;
3623 TemplateArgumentLoc defTArgLoc = S.SubstDefaultTemplateArgumentIfAvailable(Template,
3632 newArg = defTArgLoc.getArgument();
3633 if (newArg.isNull() ||
3634 newArg.getKind() != clang::TemplateArgument::Type) {
3636 "Template parameter substitution failed!");
3639 ClassTemplateSpecializationDecl* nTSTdecl
3640 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(newArg.getAsType()->getAsCXXRecordDecl());
3643 isEqual = (nTSTdecl && nTSTdecl->getMostRecentDecl() == TSTdecl->getMostRecentDecl()) ||
3644 (tParQualType.getTypePtr() == newArg.getAsType().getTypePtr());
3656 const clang::NamedDecl& tPar)
3658 using namespace clang;
3659 const NonTypeTemplateParmDecl* nttpdPtr = llvm::dyn_cast<NonTypeTemplateParmDecl>(&tPar);
3660 if (!nttpdPtr)
return false;
3661 const NonTypeTemplateParmDecl& nttpd = *nttpdPtr;
3663 if (!nttpd.hasDefaultArgument())
3667 llvm::APSInt defaultValueAPSInt(64,
false);
3668 if (Expr* defArgExpr = nttpd.getDefaultArgument()) {
3669 const ASTContext& astCtxt = nttpdPtr->getASTContext();
3670 if (
auto Value = defArgExpr->getIntegerConstantExpr(astCtxt))
3671 defaultValueAPSInt = *
Value;
3674 const int value = tArg.getAsIntegral().getLimitedValue();
3677 return value == defaultValueAPSInt;
3687 using namespace clang;
3688 if (!nDecl)
return false;
3689 if (
const TemplateTypeParmDecl* ttpd = llvm::dyn_cast<TemplateTypeParmDecl>(nDecl))
3690 return ttpd->hasDefaultArgument();
3691 if (
const NonTypeTemplateParmDecl* nttpd = llvm::dyn_cast<NonTypeTemplateParmDecl>(nDecl))
3692 return nttpd->hasDefaultArgument();
3697static void KeepNParams(clang::QualType& normalizedType,
3698 const clang::QualType& vanillaType,
3699 const cling::Interpreter& interp,
3704 const clang::TemplateArgument &tArg,
3705 const cling::Interpreter& interp,
3707 const clang::ASTContext& astCtxt)
3710 using namespace clang;
3717 if (tArg.getKind() == clang::TemplateArgument::Type) {
3718 QualType thisNormQualType = normTArg.getAsType();
3719 QualType thisArgQualType = tArg.getAsType();
3724 normTArg = TemplateArgument(thisNormQualType);
3725 return (thisNormQualType != thisArgQualType);
3726 }
else if (normTArg.getKind() == clang::TemplateArgument::Pack) {
3727 assert( tArg.getKind() == clang::TemplateArgument::Pack );
3729 SmallVector<TemplateArgument, 2> desArgs;
3730 bool mightHaveChanged =
true;
3731 for (
auto I = normTArg.pack_begin(), E = normTArg.pack_end(),
3732 FI = tArg.pack_begin(), FE = tArg.pack_end();
3733 I != E && FI != FE; ++
I, ++FI)
3735 TemplateArgument pack_arg(*
I);
3737 desArgs.push_back(pack_arg);
3739 if (mightHaveChanged) {
3740 ASTContext &mutableCtx(
const_cast<ASTContext&
>(astCtxt) );
3741 normTArg = TemplateArgument::CreatePackCopy(mutableCtx, desArgs);
3743 return mightHaveChanged;
3754 const clang::QualType& vanillaType,
3755 const cling::Interpreter& interp,
3759 using namespace clang;
3763 ClassTemplateSpecializationDecl* ctsd;
3764 ClassTemplateDecl* ctd;
3765 if (! QualType2Template(vanillaType, ctd, ctsd)) return ;
3771 QualType originalNormalizedType = normalizedType;
3773 const ASTContext& astCtxt = ctsd->getASTContext();
3778 if (llvm::isa<clang::PointerType>(normalizedType.getTypePtr())) {
3780 clang::Qualifiers quals = normalizedType.getQualifiers();
3781 auto valNormalizedType = normalizedType->getPointeeType();
3782 KeepNParams(valNormalizedType,vanillaType, interp, normCtxt);
3783 normalizedType = astCtxt.getPointerType(valNormalizedType);
3785 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3791 if (llvm::isa<clang::ReferenceType>(normalizedType.getTypePtr())) {
3793 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(normalizedType.getTypePtr());
3794 clang::Qualifiers quals = normalizedType.getQualifiers();
3795 auto valNormType = normalizedType->getPointeeType();
3796 KeepNParams(valNormType, vanillaType, interp, normCtxt);
3800 normalizedType = astCtxt.getLValueReferenceType(valNormType);
3802 normalizedType = astCtxt.getRValueReferenceType(valNormType);
3804 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3809 bool prefix_changed =
false;
3810 clang::NestedNameSpecifier* prefix =
nullptr;
3811 clang::Qualifiers prefix_qualifiers = normalizedType.getLocalQualifiers();
3812 const clang::ElaboratedType* etype
3813 = llvm::dyn_cast<clang::ElaboratedType>(normalizedType.getTypePtr());
3817 prefix = AddDefaultParametersNNS(astCtxt, etype->getQualifier(), interp, normCtxt);
3818 prefix_changed = prefix != etype->getQualifier();
3819 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3825 const clang::ClassTemplateDecl* ctdWithDefaultArgs = ctd;
3826 for (
const RedeclarableTemplateDecl* rd: ctdWithDefaultArgs->redecls()) {
3827 clang::TemplateParameterList* tpl = rd->getTemplateParameters();
3828 if (tpl->getMinRequiredArguments () < tpl->size()) {
3829 ctdWithDefaultArgs = llvm::dyn_cast<clang::ClassTemplateDecl>(rd);
3834 if (!ctdWithDefaultArgs) {
3835 Error(
"KeepNParams",
"Not found template default arguments\n");
3836 normalizedType=originalNormalizedType;
3840 TemplateParameterList* tParsPtr = ctdWithDefaultArgs->getTemplateParameters();
3841 const TemplateParameterList& tPars = *tParsPtr;
3842 const TemplateArgumentList& tArgs = ctsd->getTemplateArgs();
3845 TemplateName theTemplateName = ExtractTemplateNameFromQualType(normalizedType);
3846 if (theTemplateName.isNull()) {
3847 normalizedType=originalNormalizedType;
3851 const TemplateSpecializationType* normalizedTst =
3852 llvm::dyn_cast<TemplateSpecializationType>(normalizedType.getTypePtr());
3853 if (!normalizedTst) {
3854 normalizedType=originalNormalizedType;
3858 const clang::ClassTemplateSpecializationDecl* TSTdecl
3859 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(normalizedType.getTypePtr()->getAsCXXRecordDecl());
3860 bool isStdDropDefault = TSTdecl && IsStdDropDefaultClass(*TSTdecl);
3867 llvm::SmallVector<TemplateArgument, 4> argsToKeep;
3869 const int nArgs = tArgs.size();
3870 const auto &normArgs = normalizedTst->template_arguments();
3871 const int nNormArgs = normArgs.size();
3873 bool mightHaveChanged =
false;
3876 for (
int formal = 0, inst = 0; formal != nArgs; ++formal, ++inst) {
3877 const NamedDecl* tParPtr = tPars.getParam(formal);
3879 Error(
"KeepNParams",
"The parameter number %s is null.\n", formal);
3886 if (formal == nNormArgs || inst == nNormArgs)
break;
3888 const TemplateArgument& tArg = tArgs.get(formal);
3889 TemplateArgument normTArg(normArgs[inst]);
3891 bool shouldKeepArg = nArgsToKeep < 0 || inst < nArgsToKeep;
3892 if (isStdDropDefault) shouldKeepArg =
false;
3901 if ( tParPtr->isTemplateParameterPack() ) {
3906 for( ; inst != nNormArgs; ++inst) {
3907 normTArg = normArgs[inst];
3909 argsToKeep.push_back(normTArg);
3915 argsToKeep.push_back(normTArg);
3918 if (!isStdDropDefault) {
3920 mightHaveChanged =
true;
3930 auto argKind = tArg.getKind();
3931 if (argKind == clang::TemplateArgument::Type){
3933 equal =
areEqualTypes(tArg, argsToKeep, *tParPtr, interp, normCtxt);
3934 }
else if (argKind == clang::TemplateArgument::Integral){
3939 argsToKeep.push_back(normTArg);
3941 mightHaveChanged =
true;
3947 if (!prefix_changed && !mightHaveChanged) {
3948 normalizedType = originalNormalizedType;
3953 if (mightHaveChanged) {
3954 Qualifiers qualifiers = normalizedType.getLocalQualifiers();
3955 normalizedType = astCtxt.getTemplateSpecializationType(theTemplateName,
3957 normalizedType.getTypePtr()->getCanonicalTypeInternal());
3958 normalizedType = astCtxt.getQualifiedType(normalizedType, qualifiers);
3964 normalizedType = astCtxt.getElaboratedType(clang::ETK_None,prefix,normalizedType);
3965 normalizedType = astCtxt.getQualifiedType(normalizedType,prefix_qualifiers);
3979 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
3982 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interpreter));
3983 clang::QualType normalizedType = cling::utils::Transform::GetPartiallyDesugaredType(ctxt,
type, normCtxt.
GetConfig(),
true );
3991 return normalizedType;
4005 if (
type.isNull()) {
4012 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
4013 clang::PrintingPolicy policy(ctxt.getPrintingPolicy());
4014 policy.SuppressTagKeyword =
true;
4015 policy.SuppressScope =
true;
4016 policy.AnonymousTagLocations =
false;
4021 std::string normalizedNameStep1;
4024 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
4025 normalizedType.getAsStringInternal(normalizedNameStep1,policy);
4035 if (norm_name.length()>2 && norm_name[0]==
':' && norm_name[1]==
':') {
4036 norm_name.erase(0,2);
4044 const clang::TypeDecl* typeDecl,
4045 const cling::Interpreter &interpreter)
4048 const clang::Sema &sema = interpreter.getSema();
4049 clang::ASTContext& astCtxt = sema.getASTContext();
4050 clang::QualType qualType = astCtxt.getTypeDeclType(typeDecl);
4059std::pair<std::string,clang::QualType>
4061 const cling::Interpreter &interpreter,
4065 std::string thisTypeName;
4066 GetNormalizedName(thisTypeName, thisType, interpreter, normCtxt );
4069 if (!hasChanged)
return std::make_pair(thisTypeName,thisType);
4073 "Name changed from %s to %s\n", thisTypeName.c_str(), thisTypeNameForIO.c_str());
4076 auto& lookupHelper = interpreter.getLookupHelper();
4078 const clang::Type* typePtrForIO;
4079 lookupHelper.findScope(thisTypeNameForIO,
4080 cling::LookupHelper::DiagSetting::NoDiagnostics,
4084 if (!typePtrForIO) {
4086 "Type not found: %s.",thisTypeNameForIO.c_str());
4089 clang::QualType typeForIO(typePtrForIO,0);
4092 if (!typeForIO->isRecordType()) {
4093 return std::make_pair(thisTypeNameForIO,typeForIO);
4096 auto thisDeclForIO = typeForIO->getAsCXXRecordDecl();
4097 if (!thisDeclForIO) {
4099 "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());
4100 return std::make_pair(thisTypeName,thisType);
4103 return std::make_pair(thisTypeNameForIO,typeForIO);
4109 const cling::Interpreter &interpreter,
4121 std::string dictFileName(moduleName);
4122 dictFileName +=
"_rdict.pcm";
4123 return dictFileName;
4127 llvm::errs() << llvm::StringRef(commentStart, 80) <<
'\n';
4153 clang::SourceManager& sourceManager = decl.getASTContext().getSourceManager();
4154 clang::SourceLocation sourceLocation = decl.getEndLoc();
4157 sourceLocation = sourceManager.getExpansionRange(sourceLocation).getEnd();
4165 if (!decl.hasOwningModule() && sourceManager.isLoadedSourceLocation(sourceLocation)) {
4171 const char *commentStart = sourceManager.getCharacterData(sourceLocation, &invalid);
4175 bool skipToSemi =
true;
4176 if (
const clang::FunctionDecl* FD = clang::dyn_cast<clang::FunctionDecl>(&decl)) {
4177 if (FD->isImplicit()) {
4181 if (FD->isExplicitlyDefaulted() || FD->isDeletedAsWritten()) {
4185 }
else if (FD->doesThisDeclarationHaveABody()) {
4188 assert((decl.getEndLoc() != sourceLocation || *commentStart ==
'}'
4190 &&
"Expected macro or end of body at '}'");
4191 if (*commentStart) ++commentStart;
4194 while (*commentStart && isspace(*commentStart)
4195 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4198 if (*commentStart ==
';') ++commentStart;
4202 }
else if (
const clang::EnumConstantDecl* ECD
4203 = clang::dyn_cast<clang::EnumConstantDecl>(&decl)) {
4205 if (ECD->getNextDeclInContext())
4206 while (*commentStart && *commentStart !=
',' && *commentStart !=
'\r' && *commentStart !=
'\n')
4214 while (*commentStart && *commentStart !=
';' && *commentStart !=
'\r' && *commentStart !=
'\n')
4216 if (*commentStart ==
';') ++commentStart;
4220 while ( *commentStart && isspace(*commentStart)
4221 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4225 if (commentStart[0] !=
'/' ||
4226 (commentStart[1] !=
'/' && commentStart[1] !=
'*')) {
4236 unsigned int skipChars = 2;
4237 if (commentStart[0] ==
'/' &&
4238 commentStart[1] ==
'/' &&
4239 (commentStart[2] ==
'/' || commentStart[2] ==
'!') &&
4240 commentStart[3] ==
'<') {
4242 }
else if (commentStart[0] ==
'/' &&
4243 commentStart[1] ==
'*' &&
4244 (commentStart[2] ==
'*' || commentStart[2] ==
'!') &&
4245 commentStart[3] ==
'<') {
4249 commentStart += skipChars;
4252 while ( *commentStart && isspace(*commentStart)
4253 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4256 const char* commentEnd = commentStart;
4258 while (*commentEnd && *commentEnd !=
'\n' && *commentEnd !=
'\r') {
4264 while (commentEnd > commentStart && isspace(commentEnd[-1])) {
4270 unsigned offset = commentStart - sourceManager.getCharacterData(sourceLocation);
4271 *loc = sourceLocation.getLocWithOffset(
offset - 1);
4274 return llvm::StringRef(commentStart, commentEnd - commentStart);
4282 if (!decl)
return false;
4284 auto& sema = interpreter.getCI()->getSema();
4285 auto maybeMacroLoc = decl->getLocation();
4287 if (!maybeMacroLoc.isMacroID())
return false;
4289 static const std::vector<std::string> signatures =
4290 {
"ClassDef",
"ClassDefOverride",
"ClassDefNV",
"ClassDefInline",
"ClassDefInlineOverride",
"ClassDefInlineNV" };
4292 for (
auto &
name : signatures)
4293 if (sema.findMacroSpelling(maybeMacroLoc,
name))
4307 clang::SourceLocation *loc,
4308 const cling::Interpreter &interpreter)
4310 using namespace clang;
4312 const Decl* DeclFileLineDecl
4313 = interpreter.getLookupHelper().findFunctionProto(&decl,
"DeclFileLine",
"",
4314 cling::LookupHelper::NoDiagnostics);
4318 SourceLocation commentSLoc;
4320 if (comment.size()) {
4327 return llvm::StringRef();
4336 const clang::Type *rawtype =
type.getTypePtr();
4339 if (rawtype->isElaboratedTypeSpecifier() ) {
4340 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4342 if (rawtype->isArrayType()) {
4343 rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
4345 if (rawtype->isPointerType() || rawtype->isReferenceType() ) {
4347 clang::QualType pointee;
4348 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
4350 rawtype = pointee.getTypePtr();
4352 if (rawtype->isElaboratedTypeSpecifier() ) {
4353 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4355 if (rawtype->isArrayType()) {
4356 rawtype = rawtype->getBaseElementTypeUnsafe ();
4360 if (rawtype->isArrayType()) {
4361 rawtype = rawtype->getBaseElementTypeUnsafe ();
4372 if (ctxt.isNamespace() || ctxt.isTranslationUnit())
4374 else if(
const auto parentdecl = llvm::dyn_cast<clang::CXXRecordDecl>(&ctxt))
4387 const clang::DeclContext *ctxt = decl.getDeclContext();
4388 switch (decl.getAccess()) {
4389 case clang::AS_public:
4391 case clang::AS_protected:
4393 case clang::AS_private:
4395 case clang::AS_none:
4399 assert(
false &&
"Unexpected value for the access property value in Clang");
4409 return cling::utils::Analyze::IsStdClass(cl);
4419 if (cling::utils::Analyze::IsStdClass(cl)) {
4420 static const char *names[] =
4421 {
"shared_ptr",
"__shared_ptr",
4422 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4423 llvm::StringRef clname(cl.getName());
4424 for(
auto &&
name : names) {
4425 if (clname ==
name)
return true;
4435 const clang::CXXRecordDecl ¤tCl)
4438 if (&cl == ¤tCl)
return true;
4440 const clang::CXXRecordDecl* previous = currentCl.getPreviousDecl();
4443 if (
nullptr == previous){
4462 const clang::CXXRecordDecl *thisDecl =
4463 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(lh.findScope(typ, cling::LookupHelper::WithDiagnostics));
4467 Error(
"IsOfType",
"Record decl of type %s not found in the AST.", typ.c_str());
4472 const clang::CXXRecordDecl *mostRecentDecl = thisDecl->getMostRecentDecl();
4497 if (!IsStdClass(cl)) {
4498 auto *nsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext());
4499 if (cl.getName() !=
"RVec" || nsDecl ==
nullptr || nsDecl->getName() !=
"VecOps")
4502 auto *parentNsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext()->getParent());
4503 if (parentNsDecl ==
nullptr || parentNsDecl->getName() !=
"ROOT")
4507 return STLKind(cl.getName());
4511 using namespace clang;
4512 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4513 bool VisitTypedefType(
const TypedefType* TD) {
4516 bool VisitArrayType(
const ArrayType* AT) {
4517 return Visit(AT->getElementType().getTypePtr());
4519 bool VisitDecltypeType(
const DecltypeType* DT) {
4520 return Visit(DT->getUnderlyingType().getTypePtr());
4522 bool VisitPointerType(
const PointerType* PT) {
4523 return Visit(PT->getPointeeType().getTypePtr());
4525 bool VisitReferenceType(
const ReferenceType* RT) {
4526 return Visit(RT->getPointeeType().getTypePtr());
4528 bool VisitSubstTemplateTypeParmType(
const SubstTemplateTypeParmType* STST) {
4529 return Visit(STST->getReplacementType().getTypePtr());
4531 bool VisitTemplateSpecializationType(
const TemplateSpecializationType* TST) {
4532 for (
const TemplateArgument &
TA : TST->template_arguments()) {
4533 if (
TA.getKind() == TemplateArgument::Type && Visit(
TA.getAsType().getTypePtr()))
4538 bool VisitTemplateTypeParmType(
const TemplateTypeParmType* TTPT) {
4541 bool VisitTypeOfType(
const TypeOfType* TOT) {
4542 return TOT->getUnmodifiedType().getTypePtr();
4544 bool VisitElaboratedType(
const ElaboratedType* ET) {
4545 NestedNameSpecifier* NNS = ET->getQualifier();
4547 if (NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4548 if (Visit(NNS->getAsType()))
4551 NNS = NNS->getPrefix();
4553 return Visit(ET->getNamedType().getTypePtr());
4574 using namespace llvm;
4575 using namespace clang;
4576 const clang::ASTContext &Ctxt =
instance->getAsCXXRecordDecl()->getASTContext();
4579 const clang::ElaboratedType* etype
4580 = llvm::dyn_cast<clang::ElaboratedType>(
input.getTypePtr());
4584 clang::Qualifiers scope_qualifiers =
input.getLocalQualifiers();
4585 assert(
instance->getAsCXXRecordDecl() !=
nullptr &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4587 clang::NestedNameSpecifier *scope = ReSubstTemplateArgNNS(Ctxt,etype->getQualifier(),
instance);
4590 if (scope) subTy = Ctxt.getElaboratedType(clang::ETK_None,scope,subTy);
4591 subTy = Ctxt.getQualifiedType(subTy,scope_qualifiers);
4595 QualType QT =
input;
4599 if (isa<clang::PointerType>(QT.getTypePtr())) {
4601 Qualifiers quals = QT.getQualifiers();
4604 if (nQT == QT->getPointeeType())
return QT;
4606 QT = Ctxt.getPointerType(nQT);
4608 QT = Ctxt.getQualifiedType(QT, quals);
4614 if (isa<ReferenceType>(QT.getTypePtr())) {
4616 bool isLValueRefTy = isa<LValueReferenceType>(QT.getTypePtr());
4617 Qualifiers quals = QT.getQualifiers();
4620 if (nQT == QT->getPointeeType())
return QT;
4624 QT = Ctxt.getLValueReferenceType(nQT);
4626 QT = Ctxt.getRValueReferenceType(nQT);
4628 QT = Ctxt.getQualifiedType(QT, quals);
4634 if (isa<clang::ArrayType>(QT.getTypePtr())) {
4636 Qualifiers quals = QT.getQualifiers();
4638 if (
const auto arr = dyn_cast<ConstantArrayType>(QT.getTypePtr())) {
4641 if (newQT == arr->getElementType())
return QT;
4642 QT = Ctxt.getConstantArrayType(newQT,
4645 arr->getSizeModifier(),
4646 arr->getIndexTypeCVRQualifiers());
4648 }
else if (
const auto arr = dyn_cast<DependentSizedArrayType>(QT.getTypePtr())) {
4651 if (newQT == QT)
return QT;
4652 QT = Ctxt.getDependentSizedArrayType (newQT,
4654 arr->getSizeModifier(),
4655 arr->getIndexTypeCVRQualifiers(),
4656 arr->getBracketsRange());
4658 }
else if (
const auto arr = dyn_cast<IncompleteArrayType>(QT.getTypePtr())) {
4661 if (newQT == arr->getElementType())
return QT;
4662 QT = Ctxt.getIncompleteArrayType (newQT,
4663 arr->getSizeModifier(),
4664 arr->getIndexTypeCVRQualifiers());
4666 }
else if (
const auto arr = dyn_cast<VariableArrayType>(QT.getTypePtr())) {
4669 if (newQT == arr->getElementType())
return QT;
4670 QT = Ctxt.getVariableArrayType (newQT,
4672 arr->getSizeModifier(),
4673 arr->getIndexTypeCVRQualifiers(),
4674 arr->getBracketsRange());
4678 QT = Ctxt.getQualifiedType(QT, quals);
4683 etype = llvm::dyn_cast<clang::ElaboratedType>(
instance);
4685 instance = etype->getNamedType().getTypePtr();
4689 const clang::TemplateSpecializationType* TST
4690 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instance);
4692 if (!TST)
return input;
4694 const clang::ClassTemplateSpecializationDecl* TSTdecl
4695 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instance->getAsCXXRecordDecl());
4697 if (!TSTdecl)
return input;
4699 const clang::SubstTemplateTypeParmType *substType
4700 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
input.getTypePtr());
4704 const clang::ClassTemplateDecl *replacedCtxt =
nullptr;
4706 const clang::DeclContext *replacedDeclCtxt = substType->getReplacedParameter()->getDeclContext();
4707 const clang::CXXRecordDecl *decl = llvm::dyn_cast<clang::CXXRecordDecl>(replacedDeclCtxt);
4708 unsigned int index = substType->getReplacedParameter()->getIndex();
4711 if (decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4712 const clang::ClassTemplatePartialSpecializationDecl *spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(decl);
4714 unsigned int depth = substType->getReplacedParameter()->getDepth();
4716 const TemplateArgument *instanceArgs = spec->getTemplateArgs().data();
4717 unsigned int instanceNArgs = spec->getTemplateArgs().size();
4721 for(
unsigned int A = 0; A < instanceNArgs; ++A) {
4722 if (instanceArgs[A].getKind() == clang::TemplateArgument::Type) {
4723 clang::QualType argQualType = instanceArgs[A].getAsType();
4725 const clang::TemplateTypeParmType *replacementType;
4727 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(argQualType);
4729 if (!replacementType) {
4730 const clang::SubstTemplateTypeParmType *argType
4731 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(argQualType);
4733 clang::QualType replacementQT = argType->getReplacementType();
4734 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(replacementQT);
4737 if (replacementType &&
4738 depth == replacementType->getDepth() &&
4739 index == replacementType->getIndex() )
4746 replacedCtxt = spec->getSpecializedTemplate();
4748 replacedCtxt = decl->getDescribedClassTemplate();
4750 }
else if (
auto const declguide = llvm::dyn_cast<clang::CXXDeductionGuideDecl>(replacedDeclCtxt)) {
4751 replacedCtxt = llvm::dyn_cast<clang::ClassTemplateDecl>(declguide->getDeducedTemplate());
4752 }
else if (
auto const ctdecl = llvm::dyn_cast<clang::ClassTemplateDecl>(replacedDeclCtxt)) {
4753 replacedCtxt = ctdecl;
4755 std::string astDump;
4756 llvm::raw_string_ostream ostream(astDump);
4759 ROOT::TMetaUtils::Warning(
"ReSubstTemplateArg",
"Unexpected type of declaration context for template parameter: %s.\n\tThe responsible class is:\n\t%s\n",
4760 replacedDeclCtxt->getDeclKindName(), astDump.c_str());
4761 replacedCtxt =
nullptr;
4764 if ((replacedCtxt && replacedCtxt->getCanonicalDecl() == TSTdecl->getSpecializedTemplate()->getCanonicalDecl())
4766 substType->getReplacedParameter()
4767 == TSTdecl->getSpecializedTemplate ()->getTemplateParameters()->getParam(
index))
4769 const auto &TAs = TST->template_arguments();
4770 if (
index >= TAs.size()) {
4776 }
else if (TAs[
index].getKind() == clang::TemplateArgument::Type) {
4777 return TAs[
index].getAsType();
4786 const clang::TemplateSpecializationType* inputTST
4787 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
input.getTypePtr());
4788 const clang::ASTContext& astCtxt = TSTdecl->getASTContext();
4791 bool mightHaveChanged =
false;
4792 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
4793 for (
const clang::TemplateArgument &
TA : inputTST->template_arguments()) {
4794 if (
TA.getKind() != clang::TemplateArgument::Type) {
4795 desArgs.push_back(
TA);
4799 clang::QualType SubTy =
TA.getAsType();
4801 if (llvm::isa<clang::ElaboratedType>(SubTy)
4802 || llvm::isa<clang::SubstTemplateTypeParmType>(SubTy)
4803 || llvm::isa<clang::TemplateSpecializationType>(SubTy)) {
4805 mightHaveChanged = SubTy != newSubTy;
4806 if (!newSubTy.isNull()) {
4807 desArgs.push_back(clang::TemplateArgument(newSubTy));
4810 desArgs.push_back(
TA);
4814 if (mightHaveChanged) {
4815 clang::Qualifiers qualifiers =
input.getLocalQualifiers();
4816 input = astCtxt.getTemplateSpecializationType(inputTST->getTemplateName(),
4818 inputTST->getCanonicalTypeInternal());
4819 input = astCtxt.getQualifiedType(
input, qualifiers);
4831 if ( nArgsToRemove == 0 ||
name ==
"")
4838 unsigned int nArgsRemoved=0;
4839 unsigned int nBraces=0;
4841 while (nArgsRemoved!=nArgsToRemove && cur<
length){
4843 if (
c ==
'<') nBraces++;
4844 if (
c ==
'>') nBraces--;
4845 if (
c ==
',' && nBraces==1 ) nArgsRemoved++;
4859 static const char *stls[] =
4860 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
4861 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",
"RVec",
nullptr};
4875 for(
int k=1;stls[k];k++) {
if (
type.equals(stls[k]))
return values[k];}
4886 TND = TND->getMostRecentDecl();
4887 while (TND && !(TND->hasAttrs()))
4888 TND = TND->getPreviousDecl();
4900 TD = TD->getMostRecentDecl();
4901 while (TD && !(TD->hasAttrs() && TD->isThisDeclarationADefinition()))
4902 TD = TD->getPreviousDecl();
4911 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4913 const clang::DeclContext* enclosingNamespaceDeclCtxt = decl.getDeclContext();
4914 if (!enclosingNamespaceDeclCtxt)
return;
4916 const clang::NamespaceDecl* enclosingNamespace =
4917 clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4918 if (!enclosingNamespace)
return;
4920 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4921 enclosingNamespace->isInline()));
4931 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4933 const clang::DeclContext* enclosingNamespaceDeclCtxt = ctxt.getParent ();
4936 if (!enclosingNamespaceDeclCtxt) {
4942 const clang::NamespaceDecl* enclosingNamespace = clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4943 if (!enclosingNamespace)
return;
4946 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4947 enclosingNamespace->isInline()));
4958 std::list<std::pair<std::string,unsigned int> >& enclosingSc)
4960 const clang::DeclContext* enclosingDeclCtxt = decl.getDeclContext();
4961 if (!enclosingDeclCtxt)
return nullptr;
4963 unsigned int scopeType;
4965 if (
auto enclosingNamespacePtr =
4966 clang::dyn_cast<clang::NamespaceDecl>(enclosingDeclCtxt)){
4967 scopeType= enclosingNamespacePtr->isInline() ? 1 : 0;
4968 enclosingSc.push_back(std::make_pair(enclosingNamespacePtr->getNameAsString(),scopeType));
4972 if (
auto enclosingClassPtr =
4973 clang::dyn_cast<clang::RecordDecl>(enclosingDeclCtxt)){
4974 return enclosingClassPtr;
4986 std::string::size_type beginVar = 0;
4987 std::string::size_type endVar = 0;
4988 while ((beginVar = txt.find(
'$', beginVar)) != std::string::npos
4989 && beginVar + 1 < txt.length()) {
4990 std::string::size_type beginVarName = beginVar + 1;
4991 std::string::size_type endVarName = std::string::npos;
4992 if (txt[beginVarName] ==
'(') {
4994 endVarName = txt.find(
')', beginVarName);
4996 if (endVarName == std::string::npos) {
4998 varname, txt.c_str() + beginVar);
5001 endVar = endVarName + 1;
5004 beginVarName = beginVar + 1;
5005 endVarName = beginVarName;
5006 while (isalnum(txt[endVarName]) || txt[endVarName] ==
'_')
5008 endVar = endVarName;
5011 const char* val = getenv(txt.substr(beginVarName,
5012 endVarName - beginVarName).c_str());
5015 txt.replace(beginVar, endVar - beginVar, val);
5016 int lenval = strlen(val);
5017 int delta = lenval - (endVar - beginVar);
5021 beginVar = endVar + 1;
5033 const char* envInclPath = getenv(
"ROOT_INCLUDE_PATH");
5037 std::istringstream envInclPathsStream(envInclPath);
5038 std::string inclPath;
5039 while (std::getline(envInclPathsStream, inclPath,
':')) {
5042 if (!inclPath.empty()) {
5043 clingArgs.push_back(
"-I");
5044 clingArgs.push_back(inclPath);
5055 size_t start_pos = 0;
5060 while((start_pos = str.find(from, start_pos)) != std::string::npos) {
5061 str.replace(start_pos, from.length(), to);
5062 start_pos += to.length();
5063 if (recurse) changed =
true;
5079 if (theString.size() < theSubstring.size())
return false;
5080 const unsigned int theSubstringSize = theSubstring.size();
5081 return 0 == theString.compare(theString.size() - theSubstringSize,
5090 if (theString.size() < theSubstring.size())
return false;
5091 const unsigned int theSubstringSize = theSubstring.size();
5092 return 0 == theString.compare(0,
5110 size_t linkdeflen = 9;
5112 if (0 == strncasecmp(
filename + (
len - linkdeflen),
"linkdef", linkdeflen - 2)
5128 return llvm::sys::path::extension(
filename) ==
".h" ||
5129 llvm::sys::path::extension(
filename) ==
".hh" ||
5130 llvm::sys::path::extension(
filename) ==
".hpp" ||
5131 llvm::sys::path::extension(
filename) ==
".H" ||
5132 llvm::sys::path::extension(
filename) ==
".h++" ||
5133 llvm::sys::path::extension(
filename) ==
"hxx" ||
5134 llvm::sys::path::extension(
filename) ==
"Hxx" ||
5135 llvm::sys::path::extension(
filename) ==
"HXX";
5141 cling::Interpreter::IgnoreFilesFunc_t ignoreFiles,
5142 const cling::Interpreter &interp,
5145 clang::Sema &sema = interp.getSema();
5146 cling::Transaction theTransaction(sema);
5147 std::set<clang::Decl *> addedDecls;
5148 for (
auto decl : decls) {
5150 clang::Decl *ncDecl =
const_cast<clang::Decl *
>(decl);
5151 theTransaction.append(ncDecl);
5153 std::string newFwdDecl;
5154 llvm::raw_string_ostream llvmOstr(newFwdDecl);
5156 std::string locallogs;
5157 llvm::raw_string_ostream llvmLogStr(locallogs);
5158 interp.forwardDeclare(theTransaction, sema.getPreprocessor(), sema.getASTContext(), llvmOstr,
true,
5159 logs ? &llvmLogStr : nullptr, ignoreFiles);
5163 logs->swap(locallogs);
5175 std::string& defString)
5187 std::string& defString)
5189 std::list<std::pair<std::string,unsigned int> > enclosingNamespaces;
5192 if (rcdPtr)
return rcdPtr;
5195 static const std::string scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5197 std::string scopeName;
5198 std::string scopeContent;
5199 unsigned int scopeIndex;
5200 for (
auto const & encScope : enclosingNamespaces){
5201 scopeIndex = encScope.second;
5202 scopeName = encScope.first;
5203 scopeContent =
" { " + defString +
" }";
5204 defString = scopeType[scopeIndex] +
5226 const clang::TemplateParameterList& tmplParamList,
5227 const cling::Interpreter& interpreter)
5230 for (
auto prmIt = tmplParamList.begin();
5231 prmIt != tmplParamList.end(); prmIt++){
5233 if (prmIt != tmplParamList.begin())
5234 templateArgs +=
", ";
5236 auto nDecl = *prmIt;
5237 std::string typeName;
5240 if (llvm::isa<clang::TemplateTypeParmDecl>(nDecl)){
5241 typeName =
"typename ";
5242 if (nDecl->isParameterPack())
5244 typeName += (*prmIt)->getNameAsString();
5247 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(nDecl)){
5248 auto theType = nttpd->getType();
5251 if (theType.getAsString().find(
"enum") != std::string::npos){
5252 std::string astDump;
5253 llvm::raw_string_ostream ostream(astDump);
5254 nttpd->dump(ostream);
5256 ROOT::TMetaUtils::Warning(
nullptr,
"Forward declarations of templates with enums as template parameters. The responsible class is: %s\n", astDump.c_str());
5265 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(nDecl)){
5268 std::string astDump;
5269 llvm::raw_string_ostream ostream(astDump);
5270 ttpd->dump(ostream);
5272 ROOT::TMetaUtils::Error(
nullptr,
"Cannot reconstruct template template parameter forward declaration for %s\n", astDump.c_str());
5277 templateArgs += typeName;
5288 const cling::Interpreter& interpreter,
5289 std::string& defString)
5291 std::string templatePrefixString;
5292 auto tmplParamList= templDecl.getTemplateParameters();
5293 if (!tmplParamList){
5295 "Cannot extract template parameter list for %s",
5296 templDecl.getNameAsString().c_str());
5303 "Problems with arguments for forward declaration of class %s\n",
5304 templDecl.getNameAsString().c_str());
5307 templatePrefixString =
"template " + templatePrefixString +
" ";
5309 defString = templatePrefixString +
"class ";
5310 if (templDecl.isParameterPack())
5311 defString +=
"... ";
5312 defString += templDecl.getNameAsString();
5313 if (llvm::isa<clang::TemplateTemplateParmDecl>(&templDecl)) {
5327 std::string& argFwdDecl,
5328 const cling::Interpreter& interpreter,
5329 bool acceptStl=
false)
5335 if (clang::TemplateArgument::Type != arg.getKind())
return 0;
5337 auto argQualType = arg.getAsType();
5340 while (llvm::isa<clang::PointerType>(argQualType.getTypePtr())) argQualType = argQualType->getPointeeType();
5342 auto argTypePtr = argQualType.getTypePtr();
5345 if (llvm::isa<clang::EnumType>(argTypePtr)){
5350 if (llvm::isa<clang::BuiltinType>(argTypePtr)){
5355 if (
auto tdTypePtr = llvm::dyn_cast<clang::TypedefType>(argTypePtr)) {
5356 FwdDeclFromTypeDefNameDecl(*tdTypePtr->getDecl(), interpreter, argFwdDecl);
5360 if (
auto argRecTypePtr = llvm::dyn_cast<clang::RecordType>(argTypePtr)){
5362 if (
auto argRecDeclPtr = argRecTypePtr->getDecl()){
5363 FwdDeclFromRcdDecl(*argRecDeclPtr,interpreter,argFwdDecl,acceptStl);
5375 const cling::Interpreter& interpreter,
5376 std::string& defString,
5377 const std::string &normalizedName)
5381 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)) {
5382 if (
const auto *specDef = tmplSpecDeclPtr->getDefinition()) {
5383 if (specDef->getTemplateSpecializationKind() != clang::TSK_ExplicitSpecialization)
5387 std::cout <<
" Forward declaring template spec " << normalizedName <<
":\n";
5388 for (
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()) {
5389 std::string argFwdDecl;
5392 std::cout <<
" o Template argument ";
5394 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5396 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5403 defString += argFwdDecl +
'\n';
5405 defString +=
"template <> class " + normalizedName +
';';
5419 const cling::Interpreter& interpreter,
5420 std::string& defString,
5428 if (!recordDecl.getIdentifier())
5432 std::string argsFwdDecl;
5434 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)){
5435 std::string argFwdDecl;
5437 std::cout <<
"Class " << recordDecl.getNameAsString()
5438 <<
" is a template specialisation. Treating its arguments.\n";
5439 for(
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()){
5442 std::cout <<
" o Template argument ";
5444 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5446 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5453 argsFwdDecl+=argFwdDecl;
5457 defString=argsFwdDecl;
5462 if (
auto tmplDeclPtr = tmplSpecDeclPtr->getSpecializedTemplate()){
5465 defString = argsFwdDecl +
"\n" + defString;
5470 defString =
"class " + recordDecl.getNameAsString() +
";";
5471 const clang::RecordDecl* rcd =
EncloseInScopes(recordDecl, defString);
5479 defString = argsFwdDecl +
"\n" + defString;
5490 const cling::Interpreter& interpreter,
5491 std::string& fwdDeclString,
5492 std::unordered_set<std::string>* fwdDeclSetPtr)
5494 std::string buffer = tdnDecl.getNameAsString();
5495 std::string underlyingName;
5496 auto underlyingType = tdnDecl.getUnderlyingType().getCanonicalType();
5497 if (
const clang::TagType* TT
5498 = llvm::dyn_cast<clang::TagType>(underlyingType.getTypePtr())) {
5499 if (clang::NamedDecl* ND = TT->getDecl()) {
5500 if (!ND->getIdentifier()) {
5514 if (underlyingName.find(
">::") != std::string::npos)
5517 buffer=
"typedef "+underlyingName+
" "+buffer+
";";
5529 auto& ctxt = tdnDecl.getASTContext();
5530 auto immediatelyUnderlyingType = underlyingType.getSingleStepDesugaredType(ctxt);
5532 if (
auto underlyingTdnTypePtr = llvm::dyn_cast<clang::TypedefType>(immediatelyUnderlyingType.getTypePtr())){
5533 std::string tdnFwdDecl;
5534 auto underlyingTdnDeclPtr = underlyingTdnTypePtr->getDecl();
5539 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(tdnFwdDecl).second)
5540 fwdDeclString+=tdnFwdDecl;
5541 }
else if (
auto CXXRcdDeclPtr = immediatelyUnderlyingType->getAsCXXRecordDecl()){
5542 std::string classFwdDecl;
5544 std::cout <<
"Typedef " << tdnDecl.getNameAsString() <<
" hides a class: "
5545 << CXXRcdDeclPtr->getNameAsString() << std::endl;
5554 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(classFwdDecl).second)
5555 fwdDeclString+=classFwdDecl;
5558 fwdDeclString+=buffer;
5570 std::string& valAsString,
5571 const clang::PrintingPolicy& ppolicy)
5573 auto defArgExprPtr = par.getDefaultArg();
5574 auto& ctxt = par.getASTContext();
5575 if(!defArgExprPtr->isEvaluatable(ctxt)){
5579 auto defArgType = par.getType();
5582 if (defArgType->isBooleanType()){
5584 defArgExprPtr->EvaluateAsBooleanCondition (
result,ctxt);
5585 valAsString=std::to_string(
result);
5590 if (defArgType->isIntegerType()){
5591 clang::Expr::EvalResult evalResult;
5592 defArgExprPtr->EvaluateAsInt(evalResult, ctxt);
5593 llvm::APSInt
result = evalResult.Val.getInt();
5594 auto uintVal = *
result.getRawData();
5595 if (
result.isNegative()){
5596 long long int intVal=uintVal*-1;
5597 valAsString=std::to_string(intVal);
5599 valAsString=std::to_string(uintVal);
5606 llvm::raw_string_ostream rso(valAsString);
5607 defArgExprPtr->printPretty(rso,
nullptr,ppolicy);
5608 valAsString = rso.str();
The file contains utilities which are foundational and could be used across the core component of ROO...
#define R(a, b, c, d, e, f, g, h, i)
static Roo_reg_AGKInteg1D instance
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
static void indent(ostringstream &buf, int indent_level)
static bool RecurseKeepNParams(clang::TemplateArgument &normTArg, const clang::TemplateArgument &tArg, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt, const clang::ASTContext &astCtxt)
static clang::SourceLocation getFinalSpellingLoc(clang::SourceManager &sourceManager, clang::SourceLocation sourceLoc)
const clang::DeclContext * GetEnclosingSpace(const clang::RecordDecl &cl)
bool IsTemplate(const clang::Decl &cl)
static void KeepNParams(clang::QualType &normalizedType, const clang::QualType &vanillaType, const cling::Interpreter &interp, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt)
This function allows to manipulate the number of arguments in the type of a template specialisation.
static void CreateNameTypeMap(const clang::CXXRecordDecl &cl, ROOT::MembersTypeMap_t &nameType)
Create the data member name-type map for given class.
const clang::CXXMethodDecl * GetMethodWithProto(const clang::Decl *cinfo, const char *method, const char *proto, const cling::Interpreter &interp, bool diagnose)
int dumpDeclForAssert(const clang::Decl &D, const char *commentStart)
static void replaceEnvVars(const char *varname, std::string &txt)
Reimplementation of TSystem::ExpandPathName() that cannot be used from TMetaUtils.
static bool areEqualValues(const clang::TemplateArgument &tArg, const clang::NamedDecl &tPar)
std::cout << "Are equal values?\n";
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.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
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>
constexpr Double_t C()
Velocity of light in .
void ShortType(std::string &answer, int mode)
Return the absolute type of typeDesc into the string answ.