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::ArrayRef<clang::TemplateArgument> template_arguments = TST->template_arguments();
2940 unsigned int Idecl = 0, Edecl = TSTdecl->getTemplateArgs().size();
2941 unsigned int maxAddArg = TSTdecl->getTemplateArgs().size() - dropDefault;
2942 for (
const clang::TemplateArgument *
I = template_arguments.begin(), *E = template_arguments.end(); Idecl != Edecl;
2943 I != E ? ++
I :
nullptr, ++Idecl, ++Param) {
2947 if (
I->getKind() == clang::TemplateArgument::Template) {
2948 clang::TemplateName templateName =
I->getAsTemplate();
2949 clang::TemplateDecl* templateDecl = templateName.getAsTemplateDecl();
2951 clang::DeclContext* declCtxt = templateDecl->getDeclContext();
2953 if (declCtxt && !templateName.getAsQualifiedTemplateName()){
2954 clang::NamespaceDecl* ns = clang::dyn_cast<clang::NamespaceDecl>(declCtxt);
2955 clang::NestedNameSpecifier* nns;
2957 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx, ns);
2958 }
else if (clang::TagDecl* TD = llvm::dyn_cast<clang::TagDecl>(declCtxt)) {
2959 nns = cling::utils::TypeName::CreateNestedNameSpecifier(Ctx,TD,
false );
2962 desArgs.push_back(*
I);
2965 clang::TemplateName templateNameWithNSS ( Ctx.getQualifiedTemplateName(nns,
false, templateDecl) );
2966 desArgs.push_back(clang::TemplateArgument(templateNameWithNSS));
2967 mightHaveChanged =
true;
2973 if (
I->getKind() != clang::TemplateArgument::Type) {
2974 desArgs.push_back(*
I);
2978 clang::QualType SubTy =
I->getAsType();
2987 if (SubTy != newSubTy) {
2988 mightHaveChanged =
true;
2989 desArgs.push_back(clang::TemplateArgument(newSubTy));
2991 desArgs.push_back(*
I);
2994 }
else if (!isStdDropDefault && Idecl < maxAddArg) {
2996 mightHaveChanged =
true;
2998 const clang::TemplateArgument& templateArg
2999 = TSTdecl->getTemplateArgs().get(Idecl);
3000 if (templateArg.getKind() != clang::TemplateArgument::Type) {
3001 desArgs.push_back(templateArg);
3004 clang::QualType SubTy = templateArg.getAsType();
3006 clang::SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3007 clang::SourceLocation RAngleLoc = TSTdecl->getSourceRange().getBegin();
3009 clang::TemplateTypeParmDecl *TTP = llvm::dyn_cast<clang::TemplateTypeParmDecl>(*Param);
3012 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
3013 bool HasDefaultArgs;
3014 clang::TemplateArgumentLoc ArgType = S.SubstDefaultTemplateArgumentIfAvailable(
3023 if (ArgType.getArgument().isNull()
3024 || ArgType.getArgument().getKind() != clang::TemplateArgument::Type) {
3026 "Template parameter substitution failed for %s around %s\n",
3027 instanceType.getAsString().c_str(), SubTy.getAsString().c_str());
3030 clang::QualType BetterSubTy = ArgType.getArgument().getAsType();
3031 SubTy = cling::utils::Transform::GetPartiallyDesugaredType(Ctx,BetterSubTy,normCtxt.
GetConfig(),
true);
3034 desArgs.push_back(clang::TemplateArgument(SubTy));
3043 if (mightHaveChanged) {
3044 instanceType = Ctx.getTemplateSpecializationType(TST->getTemplateName(),
3046 TST->getCanonicalTypeInternal());
3050 if (!prefix_changed && !mightHaveChanged)
return originalType;
3052 instanceType = Ctx.getElaboratedType(clang::ETK_None,prefix,instanceType);
3053 instanceType = Ctx.getQualifiedType(instanceType,prefix_qualifiers);
3055 return instanceType;
3075 llvm::StringRef title;
3078 if (clang::AnnotateAttr *A =
m.getAttr<clang::AnnotateAttr>())
3079 title = A->getAnnotation();
3091 if (errnum) *errnum =
VALID;
3093 if (title.size() == 0 || (title[0] !=
'['))
return llvm::StringRef();
3094 size_t rightbracket = title.find(
']');
3095 if (rightbracket == llvm::StringRef::npos)
return llvm::StringRef();
3097 std::string working;
3098 llvm::StringRef indexvar(title.data()+1,rightbracket-1);
3105 size_t indexvarlen = indexvar.size();
3106 for ( i=0; i<indexvarlen; i++) {
3107 if (!isspace(indexvar[i])) {
3108 working += indexvar[i];
3113 const char *tokenlist =
"*+-";
3114 char *current =
const_cast<char*
>(working.c_str());
3115 current = strtok(current,tokenlist);
3119 if (isdigit(current[0])) {
3120 for(i=0;i<strlen(current);i++) {
3121 if (!isdigit(current[i])) {
3126 if (errstr) *errstr = current;
3127 if (errnum) *errnum =
NOT_INT;
3128 return llvm::StringRef();
3133 const clang::CXXRecordDecl *parent_clxx = llvm::dyn_cast<clang::CXXRecordDecl>(
m.getDeclContext());
3134 const clang::FieldDecl *index1 =
nullptr;
3136 index1 = GetDataMemberFromAll(*parent_clxx, current );
3138 if ( IsFieldDeclInt(index1) ) {
3143 for(clang::RecordDecl::field_iterator field_iter = parent_clxx->field_begin(), end = parent_clxx->field_end();
3147 if ( field_iter->getNameAsString() ==
m.getNameAsString() ) {
3153 if (errstr) *errstr = current;
3154 if (errnum) *errnum =
NOT_DEF;
3155 return llvm::StringRef();
3157 if ( field_iter->getNameAsString() == index1->getNameAsString() ) {
3165 if (errstr) *errstr = current;
3166 if (errnum) *errnum =
NOT_INT;
3167 return llvm::StringRef();
3174 clang::Sema& SemaR =
const_cast<cling::Interpreter&
>(interp).getSema();
3175 index1 = GetDataMemberFromAllParents(SemaR, *parent_clxx, current);
3178 if ( IsFieldDeclInt(index1) ) {
3185 if (errnum) *errnum =
NOT_INT;
3186 if (errstr) *errstr = current;
3190 if (errnum) *errnum =
NOT_INT;
3191 if (errstr) *errstr = current;
3192 return llvm::StringRef();
3194 if ( found && (index1->getAccess() == clang::AS_private) ) {
3197 if (errstr) *errstr = current;
3199 return llvm::StringRef();
3206 if (errstr) *errstr = indexvar;
3207 if (errnum) *errnum =
UNKNOWN;
3208 return llvm::StringRef();
3213 current = strtok(
nullptr, tokenlist);
3229 while((
c = in[i++])) {
3230 const char *repl =
nullptr;
3232 case '+': repl =
"pL";
break;
3233 case '-': repl =
"mI";
break;
3234 case '*': repl =
"mU";
break;
3235 case '/': repl =
"dI";
break;
3236 case '&': repl =
"aN";
break;
3237 case '%': repl =
"pE";
break;
3238 case '|': repl =
"oR";
break;
3239 case '^': repl =
"hA";
break;
3240 case '>': repl =
"gR";
break;
3241 case '<': repl =
"lE";
break;
3242 case '=': repl =
"eQ";
break;
3243 case '~': repl =
"wA";
break;
3244 case '.': repl =
"dO";
break;
3245 case '(': repl =
"oP";
break;
3246 case ')': repl =
"cP";
break;
3247 case '[': repl =
"oB";
break;
3248 case ']': repl =
"cB";
break;
3249 case '!': repl =
"nO";
break;
3250 case ',': repl =
"cO";
break;
3251 case '$': repl =
"dA";
break;
3252 case ' ': repl =
"sP";
break;
3253 case ':': repl =
"cL";
break;
3254 case '"': repl =
"dQ";
break;
3255 case '@': repl =
"aT";
break;
3256 case '\'': repl =
"sQ";
break;
3257 case '\\': repl =
"fI";
break;
3266 auto firstNonNumber = out.find_first_not_of(
"0123456789");
3267 if (firstNonNumber != std::string::npos)
3268 out.replace(0,firstNonNumber,
"");
3271static clang::SourceLocation
3273 clang::SourceLocation sourceLoc) {
3275 if (!sourceLoc.isFileID()) {
3276 return sourceManager.getExpansionRange(sourceLoc).getEnd();
3285 const cling::Interpreter& interp)
3315 using namespace clang;
3316 SourceLocation headerLoc = decl.getLocation();
3318 static const char invalidFilename[] =
"";
3319 if (!headerLoc.isValid())
return invalidFilename;
3321 HeaderSearch& HdrSearch = interp.getCI()->getPreprocessor().getHeaderSearchInfo();
3323 SourceManager& sourceManager = decl.getASTContext().getSourceManager();
3325 FileID headerFID = sourceManager.getFileID(headerLoc);
3326 SourceLocation includeLoc
3328 sourceManager.getIncludeLoc(headerFID));
3330 const FileEntry *headerFE = sourceManager.getFileEntryForID(headerFID);
3331 while (includeLoc.isValid() && sourceManager.isInSystemHeader(includeLoc)) {
3332 const DirectoryLookup *foundDir =
nullptr;
3335 assert(headerFE &&
"Couldn't find FileEntry from FID!");
3337 = HdrSearch.LookupFile(llvm::sys::path::filename(headerFE->getName()),
3339 true ,
nullptr, foundDir,
3340 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3348 headerFID = sourceManager.getFileID(includeLoc);
3349 headerFE = sourceManager.getFileEntryForID(headerFID);
3354 if (interp.getCI()->getLangOpts().Modules && !headerFE) {
3355 assert(decl.isFirstDecl() &&
"Couldn't trace back include from a decl"
3356 " that is not from an AST file");
3357 assert(StringRef(includeLoc.printToString(sourceManager)).startswith(
"<module-includes>"));
3361 sourceManager.getIncludeLoc(headerFID));
3364 if (!headerFE)
return invalidFilename;
3366 llvm::SmallString<256> headerFileName(headerFE->getName());
3369 llvm::sys::path::remove_dots(headerFileName,
true);
3380 bool isAbsolute = llvm::sys::path::is_absolute(headerFileName);
3381 llvm::Optional<clang::FileEntryRef> FELong;
3383 for (llvm::sys::path::const_iterator
3384 IDir = llvm::sys::path::begin(headerFileName),
3385 EDir = llvm::sys::path::end(headerFileName);
3386 !FELong && IDir != EDir; ++IDir) {
3392 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3393 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3394 assert(trailingPart.data() + trailingPart.size()
3395 == headerFileName.data() + headerFileName.size()
3396 &&
"Mismatched partitioning of file name!");
3397 const DirectoryLookup* FoundDir =
nullptr;
3398 FELong = HdrSearch.LookupFile(trailingPart, SourceLocation(),
3399 true ,
nullptr, FoundDir,
3400 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3408 return invalidFilename;
3412 for (llvm::sys::path::reverse_iterator
3413 IDir = llvm::sys::path::rbegin(headerFileName),
3414 EDir = llvm::sys::path::rend(headerFileName);
3415 IDir != EDir; ++IDir) {
3416 size_t lenTrailing = headerFileName.size() - (IDir->data() - headerFileName.data());
3417 llvm::StringRef trailingPart(IDir->data(), lenTrailing);
3418 assert(trailingPart.data() + trailingPart.size()
3419 == headerFileName.data() + headerFileName.size()
3420 &&
"Mismatched partitioning of file name!");
3421 const DirectoryLookup* FoundDir =
nullptr;
3424 if (HdrSearch.LookupFile(trailingPart, SourceLocation(),
3425 true ,
nullptr, FoundDir,
3426 ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>>(),
3429 nullptr,
nullptr ) == FELong) {
3430 return trailingPart.str();
3434 return invalidFilename;
3440 const clang::QualType &qtype,
3441 const clang::ASTContext &astContext)
3443 std::string fqname = cling::utils::TypeName::GetFullyQualifiedName(qtype, astContext);
3452 const clang::QualType &qtype,
3453 const cling::Interpreter &interpreter)
3458 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interpreter));
3462 interpreter.getCI()->getASTContext());
3470 clang::ClassTemplateDecl*& ctd,
3471 clang::ClassTemplateSpecializationDecl*& ctsd)
3473 using namespace clang;
3474 const Type* theType = qt.getTypePtr();
3481 if (theType->isPointerType()) {
3485 if (
const RecordType* rType = llvm::dyn_cast<RecordType>(theType)) {
3486 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(rType->getDecl());
3488 ctd = ctsd->getSpecializedTemplate();
3493 if (
const SubstTemplateTypeParmType* sttpType = llvm::dyn_cast<SubstTemplateTypeParmType>(theType)){
3498 ctsd = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(qt->getAsCXXRecordDecl());
3500 ctd = ctsd->getSpecializedTemplate();
3515 using namespace clang;
3516 ClassTemplateSpecializationDecl* ctsd;
3517 ClassTemplateDecl* ctd;
3531 using namespace clang;
3532 TemplateName theTemplateName;
3534 const Type* theType = qt.getTypePtr();
3536 if (
const TemplateSpecializationType* tst = llvm::dyn_cast_or_null<const TemplateSpecializationType>(theType)) {
3537 theTemplateName = tst->getTemplateName();
3540 theTemplateName = TemplateName(ctd);
3543 return theTemplateName;
3549 llvm::SmallVectorImpl<clang::TemplateArgument>& preceedingTArgs,
3550 const clang::NamedDecl& tPar,
3551 const cling::Interpreter& interp,
3555 using namespace clang;
3558 TemplateTypeParmDecl* ttpdPtr =
const_cast<TemplateTypeParmDecl*
>(llvm::dyn_cast<TemplateTypeParmDecl>(&tPar));
3559 if (!ttpdPtr)
return false;
3560 if (!ttpdPtr->hasDefaultArgument())
return false;
3563 QualType tParQualType = ttpdPtr->getDefaultArgument();
3564 const QualType tArgQualType = tArg.getAsType();
3571 if (tParQualType.getTypePtr() == tArgQualType.getTypePtr())
return true;
3582 const clang::ElaboratedType* etype
3583 = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3585 tParQualType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3586 etype = llvm::dyn_cast<clang::ElaboratedType>(tParQualType.getTypePtr());
3589 const TemplateSpecializationType* tst =
3590 llvm::dyn_cast<TemplateSpecializationType>(tParQualType.getTypePtr());
3595 ClassTemplateSpecializationDecl* TSTdecl
3596 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(tArgQualType->getAsCXXRecordDecl());
3601 TemplateDecl *Template = tst->getTemplateName().getAsTemplateDecl();
3604 SourceLocation TemplateLoc = Template->getSourceRange ().getBegin();
3607 SourceLocation LAngleLoc = TSTdecl->getSourceRange().getBegin();
3612 TemplateArgument newArg = tArg;
3614 clang::Sema& S = interp.getCI()->getSema();
3615 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interp));
3616 bool HasDefaultArgs;
3617 TemplateArgumentLoc defTArgLoc = S.SubstDefaultTemplateArgumentIfAvailable(Template,
3625 newArg = defTArgLoc.getArgument();
3626 if (newArg.isNull() ||
3627 newArg.getKind() != clang::TemplateArgument::Type) {
3629 "Template parameter substitution failed!");
3632 ClassTemplateSpecializationDecl* nTSTdecl
3633 = llvm::dyn_cast_or_null<ClassTemplateSpecializationDecl>(newArg.getAsType()->getAsCXXRecordDecl());
3636 isEqual = (nTSTdecl && nTSTdecl->getMostRecentDecl() == TSTdecl->getMostRecentDecl()) ||
3637 (tParQualType.getTypePtr() == newArg.getAsType().getTypePtr());
3649 const clang::NamedDecl& tPar)
3651 using namespace clang;
3652 const NonTypeTemplateParmDecl* nttpdPtr = llvm::dyn_cast<NonTypeTemplateParmDecl>(&tPar);
3653 if (!nttpdPtr)
return false;
3654 const NonTypeTemplateParmDecl& nttpd = *nttpdPtr;
3656 if (!nttpd.hasDefaultArgument())
3660 llvm::APSInt defaultValueAPSInt(64,
false);
3661 if (Expr* defArgExpr = nttpd.getDefaultArgument()) {
3662 const ASTContext& astCtxt = nttpdPtr->getASTContext();
3663 if (
auto Value = defArgExpr->getIntegerConstantExpr(astCtxt))
3664 defaultValueAPSInt = *
Value;
3667 const int value = tArg.getAsIntegral().getLimitedValue();
3670 return value == defaultValueAPSInt;
3680 using namespace clang;
3681 if (!nDecl)
return false;
3682 if (
const TemplateTypeParmDecl* ttpd = llvm::dyn_cast<TemplateTypeParmDecl>(nDecl))
3683 return ttpd->hasDefaultArgument();
3684 if (
const NonTypeTemplateParmDecl* nttpd = llvm::dyn_cast<NonTypeTemplateParmDecl>(nDecl))
3685 return nttpd->hasDefaultArgument();
3690static void KeepNParams(clang::QualType& normalizedType,
3691 const clang::QualType& vanillaType,
3692 const cling::Interpreter& interp,
3697 const clang::TemplateArgument &tArg,
3698 const cling::Interpreter& interp,
3700 const clang::ASTContext& astCtxt)
3703 using namespace clang;
3710 if (tArg.getKind() == clang::TemplateArgument::Type) {
3711 QualType thisNormQualType = normTArg.getAsType();
3712 QualType thisArgQualType = tArg.getAsType();
3717 normTArg = TemplateArgument(thisNormQualType);
3718 return (thisNormQualType != thisArgQualType);
3719 }
else if (normTArg.getKind() == clang::TemplateArgument::Pack) {
3720 assert( tArg.getKind() == clang::TemplateArgument::Pack );
3722 SmallVector<TemplateArgument, 2> desArgs;
3723 bool mightHaveChanged =
true;
3724 for (
auto I = normTArg.pack_begin(), E = normTArg.pack_end(),
3725 FI = tArg.pack_begin(), FE = tArg.pack_end();
3726 I != E && FI != FE; ++
I, ++FI)
3728 TemplateArgument pack_arg(*
I);
3730 desArgs.push_back(pack_arg);
3732 if (mightHaveChanged) {
3733 ASTContext &mutableCtx(
const_cast<ASTContext&
>(astCtxt) );
3734 normTArg = TemplateArgument::CreatePackCopy(mutableCtx, desArgs);
3736 return mightHaveChanged;
3747 const clang::QualType& vanillaType,
3748 const cling::Interpreter& interp,
3752 using namespace clang;
3756 ClassTemplateSpecializationDecl* ctsd;
3757 ClassTemplateDecl* ctd;
3758 if (! QualType2Template(vanillaType, ctd, ctsd)) return ;
3764 QualType originalNormalizedType = normalizedType;
3766 const ASTContext& astCtxt = ctsd->getASTContext();
3771 if (llvm::isa<clang::PointerType>(normalizedType.getTypePtr())) {
3773 clang::Qualifiers quals = normalizedType.getQualifiers();
3774 auto valNormalizedType = normalizedType->getPointeeType();
3775 KeepNParams(valNormalizedType,vanillaType, interp, normCtxt);
3776 normalizedType = astCtxt.getPointerType(valNormalizedType);
3778 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3784 if (llvm::isa<clang::ReferenceType>(normalizedType.getTypePtr())) {
3786 bool isLValueRefTy = llvm::isa<clang::LValueReferenceType>(normalizedType.getTypePtr());
3787 clang::Qualifiers quals = normalizedType.getQualifiers();
3788 auto valNormType = normalizedType->getPointeeType();
3789 KeepNParams(valNormType, vanillaType, interp, normCtxt);
3793 normalizedType = astCtxt.getLValueReferenceType(valNormType);
3795 normalizedType = astCtxt.getRValueReferenceType(valNormType);
3797 normalizedType = astCtxt.getQualifiedType(normalizedType, quals);
3802 bool prefix_changed =
false;
3803 clang::NestedNameSpecifier* prefix =
nullptr;
3804 clang::Qualifiers prefix_qualifiers = normalizedType.getLocalQualifiers();
3805 const clang::ElaboratedType* etype
3806 = llvm::dyn_cast<clang::ElaboratedType>(normalizedType.getTypePtr());
3810 prefix = AddDefaultParametersNNS(astCtxt, etype->getQualifier(), interp, normCtxt);
3811 prefix_changed = prefix != etype->getQualifier();
3812 normalizedType = clang::QualType(etype->getNamedType().getTypePtr(),0);
3818 const clang::ClassTemplateDecl* ctdWithDefaultArgs = ctd;
3819 for (
const RedeclarableTemplateDecl* rd: ctdWithDefaultArgs->redecls()) {
3820 clang::TemplateParameterList* tpl = rd->getTemplateParameters();
3821 if (tpl->getMinRequiredArguments () < tpl->size()) {
3822 ctdWithDefaultArgs = llvm::dyn_cast<clang::ClassTemplateDecl>(rd);
3827 if (!ctdWithDefaultArgs) {
3828 Error(
"KeepNParams",
"Not found template default arguments\n");
3829 normalizedType=originalNormalizedType;
3833 TemplateParameterList* tParsPtr = ctdWithDefaultArgs->getTemplateParameters();
3834 const TemplateParameterList& tPars = *tParsPtr;
3835 const TemplateArgumentList& tArgs = ctsd->getTemplateArgs();
3838 TemplateName theTemplateName = ExtractTemplateNameFromQualType(normalizedType);
3839 if (theTemplateName.isNull()) {
3840 normalizedType=originalNormalizedType;
3844 const TemplateSpecializationType* normalizedTst =
3845 llvm::dyn_cast<TemplateSpecializationType>(normalizedType.getTypePtr());
3846 if (!normalizedTst) {
3847 normalizedType=originalNormalizedType;
3851 const clang::ClassTemplateSpecializationDecl* TSTdecl
3852 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(normalizedType.getTypePtr()->getAsCXXRecordDecl());
3853 bool isStdDropDefault = TSTdecl && IsStdDropDefaultClass(*TSTdecl);
3860 llvm::SmallVector<TemplateArgument, 4> argsToKeep;
3862 const int nArgs = tArgs.size();
3863 const auto &normArgs = normalizedTst->template_arguments();
3864 const int nNormArgs = normArgs.size();
3866 bool mightHaveChanged =
false;
3869 for (
int formal = 0, inst = 0; formal != nArgs; ++formal, ++inst) {
3870 const NamedDecl* tParPtr = tPars.getParam(formal);
3872 Error(
"KeepNParams",
"The parameter number %s is null.\n", formal);
3879 if (formal == nNormArgs || inst == nNormArgs)
break;
3881 const TemplateArgument& tArg = tArgs.get(formal);
3882 TemplateArgument normTArg(normArgs[inst]);
3884 bool shouldKeepArg = nArgsToKeep < 0 || inst < nArgsToKeep;
3885 if (isStdDropDefault) shouldKeepArg =
false;
3894 if ( tParPtr->isTemplateParameterPack() ) {
3899 for( ; inst != nNormArgs; ++inst) {
3900 normTArg = normArgs[inst];
3902 argsToKeep.push_back(normTArg);
3908 argsToKeep.push_back(normTArg);
3911 if (!isStdDropDefault) {
3913 mightHaveChanged =
true;
3923 auto argKind = tArg.getKind();
3924 if (argKind == clang::TemplateArgument::Type){
3926 equal =
areEqualTypes(tArg, argsToKeep, *tParPtr, interp, normCtxt);
3927 }
else if (argKind == clang::TemplateArgument::Integral){
3932 argsToKeep.push_back(normTArg);
3934 mightHaveChanged =
true;
3940 if (!prefix_changed && !mightHaveChanged) {
3941 normalizedType = originalNormalizedType;
3946 if (mightHaveChanged) {
3947 Qualifiers qualifiers = normalizedType.getLocalQualifiers();
3948 normalizedType = astCtxt.getTemplateSpecializationType(theTemplateName,
3950 normalizedType.getTypePtr()->getCanonicalTypeInternal());
3951 normalizedType = astCtxt.getQualifiedType(normalizedType, qualifiers);
3957 normalizedType = astCtxt.getElaboratedType(clang::ETK_None,prefix,normalizedType);
3958 normalizedType = astCtxt.getQualifiedType(normalizedType,prefix_qualifiers);
3972 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
3975 cling::Interpreter::PushTransactionRAII RAII(
const_cast<cling::Interpreter*
>(&interpreter));
3976 clang::QualType normalizedType = cling::utils::Transform::GetPartiallyDesugaredType(ctxt,
type, normCtxt.
GetConfig(),
true );
3984 return normalizedType;
3998 if (
type.isNull()) {
4005 clang::ASTContext &ctxt = interpreter.getCI()->getASTContext();
4006 clang::PrintingPolicy policy(ctxt.getPrintingPolicy());
4007 policy.SuppressTagKeyword =
true;
4008 policy.SuppressScope =
true;
4009 policy.AnonymousTagLocations =
false;
4014 std::string normalizedNameStep1;
4017 cling::Interpreter::PushTransactionRAII clingRAII(
const_cast<cling::Interpreter*
>(&interpreter));
4018 normalizedType.getAsStringInternal(normalizedNameStep1,policy);
4028 if (norm_name.length()>2 && norm_name[0]==
':' && norm_name[1]==
':') {
4029 norm_name.erase(0,2);
4037 const clang::TypeDecl* typeDecl,
4038 const cling::Interpreter &interpreter)
4041 const clang::Sema &sema = interpreter.getSema();
4042 clang::ASTContext& astCtxt = sema.getASTContext();
4043 clang::QualType qualType = astCtxt.getTypeDeclType(typeDecl);
4052std::pair<std::string,clang::QualType>
4054 const cling::Interpreter &interpreter,
4058 std::string thisTypeName;
4059 GetNormalizedName(thisTypeName, thisType, interpreter, normCtxt );
4062 if (!hasChanged)
return std::make_pair(thisTypeName,thisType);
4066 "Name changed from %s to %s\n", thisTypeName.c_str(), thisTypeNameForIO.c_str());
4069 auto& lookupHelper = interpreter.getLookupHelper();
4071 const clang::Type* typePtrForIO;
4072 lookupHelper.findScope(thisTypeNameForIO,
4073 cling::LookupHelper::DiagSetting::NoDiagnostics,
4077 if (!typePtrForIO) {
4079 "Type not found: %s.",thisTypeNameForIO.c_str());
4082 clang::QualType typeForIO(typePtrForIO,0);
4085 if (!typeForIO->isRecordType()) {
4086 return std::make_pair(thisTypeNameForIO,typeForIO);
4089 auto thisDeclForIO = typeForIO->getAsCXXRecordDecl();
4090 if (!thisDeclForIO) {
4092 "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());
4093 return std::make_pair(thisTypeName,thisType);
4096 return std::make_pair(thisTypeNameForIO,typeForIO);
4102 const cling::Interpreter &interpreter,
4114 std::string dictFileName(moduleName);
4115 dictFileName +=
"_rdict.pcm";
4116 return dictFileName;
4120 llvm::errs() << llvm::StringRef(commentStart, 80) <<
'\n';
4146 clang::SourceManager& sourceManager = decl.getASTContext().getSourceManager();
4147 clang::SourceLocation sourceLocation = decl.getEndLoc();
4150 sourceLocation = sourceManager.getExpansionRange(sourceLocation).getEnd();
4158 if (!decl.hasOwningModule() && sourceManager.isLoadedSourceLocation(sourceLocation)) {
4164 const char *commentStart = sourceManager.getCharacterData(sourceLocation, &invalid);
4168 bool skipToSemi =
true;
4169 if (
const clang::FunctionDecl* FD = clang::dyn_cast<clang::FunctionDecl>(&decl)) {
4170 if (FD->isImplicit()) {
4174 if (FD->isExplicitlyDefaulted() || FD->isDeletedAsWritten()) {
4178 }
else if (FD->doesThisDeclarationHaveABody()) {
4181 assert((decl.getEndLoc() != sourceLocation || *commentStart ==
'}'
4183 &&
"Expected macro or end of body at '}'");
4184 if (*commentStart) ++commentStart;
4187 while (*commentStart && isspace(*commentStart)
4188 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4191 if (*commentStart ==
';') ++commentStart;
4195 }
else if (
const clang::EnumConstantDecl* ECD
4196 = clang::dyn_cast<clang::EnumConstantDecl>(&decl)) {
4198 if (ECD->getNextDeclInContext())
4199 while (*commentStart && *commentStart !=
',' && *commentStart !=
'\r' && *commentStart !=
'\n')
4207 while (*commentStart && *commentStart !=
';' && *commentStart !=
'\r' && *commentStart !=
'\n')
4209 if (*commentStart ==
';') ++commentStart;
4213 while ( *commentStart && isspace(*commentStart)
4214 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4218 if (commentStart[0] !=
'/' ||
4219 (commentStart[1] !=
'/' && commentStart[1] !=
'*')) {
4229 unsigned int skipChars = 2;
4230 if (commentStart[0] ==
'/' &&
4231 commentStart[1] ==
'/' &&
4232 (commentStart[2] ==
'/' || commentStart[2] ==
'!') &&
4233 commentStart[3] ==
'<') {
4235 }
else if (commentStart[0] ==
'/' &&
4236 commentStart[1] ==
'*' &&
4237 (commentStart[2] ==
'*' || commentStart[2] ==
'!') &&
4238 commentStart[3] ==
'<') {
4242 commentStart += skipChars;
4245 while ( *commentStart && isspace(*commentStart)
4246 && *commentStart !=
'\n' && *commentStart !=
'\r') {
4249 const char* commentEnd = commentStart;
4251 while (*commentEnd && *commentEnd !=
'\n' && *commentEnd !=
'\r') {
4257 while (commentEnd > commentStart && isspace(commentEnd[-1])) {
4263 unsigned offset = commentStart - sourceManager.getCharacterData(sourceLocation);
4264 *loc = sourceLocation.getLocWithOffset(
offset - 1);
4267 return llvm::StringRef(commentStart, commentEnd - commentStart);
4275 if (!decl)
return false;
4277 auto& sema = interpreter.getCI()->getSema();
4278 auto maybeMacroLoc = decl->getLocation();
4280 if (!maybeMacroLoc.isMacroID())
return false;
4282 static const std::vector<std::string> signatures =
4283 {
"ClassDef",
"ClassDefOverride",
"ClassDefNV",
"ClassDefInline",
"ClassDefInlineOverride",
"ClassDefInlineNV" };
4285 for (
auto &
name : signatures)
4286 if (sema.findMacroSpelling(maybeMacroLoc,
name))
4300 clang::SourceLocation *loc,
4301 const cling::Interpreter &interpreter)
4303 using namespace clang;
4305 const Decl* DeclFileLineDecl
4306 = interpreter.getLookupHelper().findFunctionProto(&decl,
"DeclFileLine",
"",
4307 cling::LookupHelper::NoDiagnostics);
4311 SourceLocation commentSLoc;
4313 if (comment.size()) {
4320 return llvm::StringRef();
4329 const clang::Type *rawtype =
type.getTypePtr();
4332 if (rawtype->isElaboratedTypeSpecifier() ) {
4333 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4335 if (rawtype->isArrayType()) {
4336 rawtype =
type.getTypePtr()->getBaseElementTypeUnsafe ();
4338 if (rawtype->isPointerType() || rawtype->isReferenceType() ) {
4340 clang::QualType pointee;
4341 while ( (pointee = rawtype->getPointeeType()) , pointee.getTypePtrOrNull() && pointee.getTypePtr() != rawtype)
4343 rawtype = pointee.getTypePtr();
4345 if (rawtype->isElaboratedTypeSpecifier() ) {
4346 rawtype = rawtype->getCanonicalTypeInternal().getTypePtr();
4348 if (rawtype->isArrayType()) {
4349 rawtype = rawtype->getBaseElementTypeUnsafe ();
4353 if (rawtype->isArrayType()) {
4354 rawtype = rawtype->getBaseElementTypeUnsafe ();
4365 if (ctxt.isNamespace() || ctxt.isTranslationUnit())
4367 else if(
const auto parentdecl = llvm::dyn_cast<clang::CXXRecordDecl>(&ctxt))
4380 const clang::DeclContext *ctxt = decl.getDeclContext();
4381 switch (decl.getAccess()) {
4382 case clang::AS_public:
4384 case clang::AS_protected:
4386 case clang::AS_private:
4388 case clang::AS_none:
4392 assert(
false &&
"Unexpected value for the access property value in Clang");
4402 return cling::utils::Analyze::IsStdClass(cl);
4412 if (cling::utils::Analyze::IsStdClass(cl)) {
4413 static const char *names[] =
4414 {
"shared_ptr",
"__shared_ptr",
4415 "vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset"};
4416 llvm::StringRef clname(cl.getName());
4417 for(
auto &&
name : names) {
4418 if (clname ==
name)
return true;
4428 const clang::CXXRecordDecl ¤tCl)
4431 if (&cl == ¤tCl)
return true;
4433 const clang::CXXRecordDecl* previous = currentCl.getPreviousDecl();
4436 if (
nullptr == previous){
4455 const clang::CXXRecordDecl *thisDecl =
4456 llvm::dyn_cast_or_null<clang::CXXRecordDecl>(lh.findScope(typ, cling::LookupHelper::WithDiagnostics));
4460 Error(
"IsOfType",
"Record decl of type %s not found in the AST.", typ.c_str());
4465 const clang::CXXRecordDecl *mostRecentDecl = thisDecl->getMostRecentDecl();
4490 if (!IsStdClass(cl)) {
4491 auto *nsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext());
4492 if (cl.getName() !=
"RVec" || nsDecl ==
nullptr || nsDecl->getName() !=
"VecOps")
4495 auto *parentNsDecl = llvm::dyn_cast<clang::NamespaceDecl>(cl.getDeclContext()->getParent());
4496 if (parentNsDecl ==
nullptr || parentNsDecl->getName() !=
"ROOT")
4500 return STLKind(cl.getName());
4504 using namespace clang;
4505 struct SearchTypedef:
public TypeVisitor<SearchTypedef, bool> {
4506 bool VisitTypedefType(
const TypedefType* TD) {
4509 bool VisitArrayType(
const ArrayType* AT) {
4510 return Visit(AT->getElementType().getTypePtr());
4512 bool VisitDecltypeType(
const DecltypeType* DT) {
4513 return Visit(DT->getUnderlyingType().getTypePtr());
4515 bool VisitPointerType(
const PointerType* PT) {
4516 return Visit(PT->getPointeeType().getTypePtr());
4518 bool VisitReferenceType(
const ReferenceType* RT) {
4519 return Visit(RT->getPointeeType().getTypePtr());
4521 bool VisitSubstTemplateTypeParmType(
const SubstTemplateTypeParmType* STST) {
4522 return Visit(STST->getReplacementType().getTypePtr());
4524 bool VisitTemplateSpecializationType(
const TemplateSpecializationType* TST) {
4525 for (
const TemplateArgument &
TA : TST->template_arguments()) {
4526 if (
TA.getKind() == TemplateArgument::Type && Visit(
TA.getAsType().getTypePtr()))
4531 bool VisitTemplateTypeParmType(
const TemplateTypeParmType* TTPT) {
4534 bool VisitTypeOfType(
const TypeOfType* TOT) {
4535 return TOT->getUnderlyingType().getTypePtr();
4537 bool VisitElaboratedType(
const ElaboratedType* ET) {
4538 NestedNameSpecifier* NNS = ET->getQualifier();
4540 if (NNS->getKind() == NestedNameSpecifier::TypeSpec) {
4541 if (Visit(NNS->getAsType()))
4544 NNS = NNS->getPrefix();
4546 return Visit(ET->getNamedType().getTypePtr());
4567 using namespace llvm;
4568 using namespace clang;
4569 const clang::ASTContext &Ctxt =
instance->getAsCXXRecordDecl()->getASTContext();
4572 const clang::ElaboratedType* etype
4573 = llvm::dyn_cast<clang::ElaboratedType>(
input.getTypePtr());
4577 clang::Qualifiers scope_qualifiers =
input.getLocalQualifiers();
4578 assert(
instance->getAsCXXRecordDecl() !=
nullptr &&
"ReSubstTemplateArg only makes sense with a type representing a class.");
4580 clang::NestedNameSpecifier *scope = ReSubstTemplateArgNNS(Ctxt,etype->getQualifier(),
instance);
4583 if (scope) subTy = Ctxt.getElaboratedType(clang::ETK_None,scope,subTy);
4584 subTy = Ctxt.getQualifiedType(subTy,scope_qualifiers);
4588 QualType QT =
input;
4592 if (isa<clang::PointerType>(QT.getTypePtr())) {
4594 Qualifiers quals = QT.getQualifiers();
4597 if (nQT == QT->getPointeeType())
return QT;
4599 QT = Ctxt.getPointerType(nQT);
4601 QT = Ctxt.getQualifiedType(QT, quals);
4607 if (isa<ReferenceType>(QT.getTypePtr())) {
4609 bool isLValueRefTy = isa<LValueReferenceType>(QT.getTypePtr());
4610 Qualifiers quals = QT.getQualifiers();
4613 if (nQT == QT->getPointeeType())
return QT;
4617 QT = Ctxt.getLValueReferenceType(nQT);
4619 QT = Ctxt.getRValueReferenceType(nQT);
4621 QT = Ctxt.getQualifiedType(QT, quals);
4627 if (isa<clang::ArrayType>(QT.getTypePtr())) {
4629 Qualifiers quals = QT.getQualifiers();
4631 if (
const auto arr = dyn_cast<ConstantArrayType>(QT.getTypePtr())) {
4634 if (newQT == arr->getElementType())
return QT;
4635 QT = Ctxt.getConstantArrayType(newQT,
4638 arr->getSizeModifier(),
4639 arr->getIndexTypeCVRQualifiers());
4641 }
else if (
const auto arr = dyn_cast<DependentSizedArrayType>(QT.getTypePtr())) {
4644 if (newQT == QT)
return QT;
4645 QT = Ctxt.getDependentSizedArrayType (newQT,
4647 arr->getSizeModifier(),
4648 arr->getIndexTypeCVRQualifiers(),
4649 arr->getBracketsRange());
4651 }
else if (
const auto arr = dyn_cast<IncompleteArrayType>(QT.getTypePtr())) {
4654 if (newQT == arr->getElementType())
return QT;
4655 QT = Ctxt.getIncompleteArrayType (newQT,
4656 arr->getSizeModifier(),
4657 arr->getIndexTypeCVRQualifiers());
4659 }
else if (
const auto arr = dyn_cast<VariableArrayType>(QT.getTypePtr())) {
4662 if (newQT == arr->getElementType())
return QT;
4663 QT = Ctxt.getVariableArrayType (newQT,
4665 arr->getSizeModifier(),
4666 arr->getIndexTypeCVRQualifiers(),
4667 arr->getBracketsRange());
4671 QT = Ctxt.getQualifiedType(QT, quals);
4676 etype = llvm::dyn_cast<clang::ElaboratedType>(
instance);
4678 instance = etype->getNamedType().getTypePtr();
4682 const clang::TemplateSpecializationType* TST
4683 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
instance);
4685 if (!TST)
return input;
4687 const clang::ClassTemplateSpecializationDecl* TSTdecl
4688 = llvm::dyn_cast_or_null<const clang::ClassTemplateSpecializationDecl>(
instance->getAsCXXRecordDecl());
4690 if (!TSTdecl)
return input;
4692 const clang::SubstTemplateTypeParmType *substType
4693 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(
input.getTypePtr());
4697 const clang::ClassTemplateDecl *replacedCtxt =
nullptr;
4699 const clang::DeclContext *replacedDeclCtxt = substType->getReplacedParameter()->getDecl()->getDeclContext();
4700 const clang::CXXRecordDecl *decl = llvm::dyn_cast<clang::CXXRecordDecl>(replacedDeclCtxt);
4701 unsigned int index = substType->getReplacedParameter()->getIndex();
4704 if (decl->getKind() == clang::Decl::ClassTemplatePartialSpecialization) {
4705 const clang::ClassTemplatePartialSpecializationDecl *spec = llvm::dyn_cast<clang::ClassTemplatePartialSpecializationDecl>(decl);
4707 unsigned int depth = substType->getReplacedParameter()->getDepth();
4709 const TemplateArgument *instanceArgs = spec->getTemplateArgs().data();
4710 unsigned int instanceNArgs = spec->getTemplateArgs().size();
4714 for(
unsigned int A = 0; A < instanceNArgs; ++A) {
4715 if (instanceArgs[A].getKind() == clang::TemplateArgument::Type) {
4716 clang::QualType argQualType = instanceArgs[A].getAsType();
4718 const clang::TemplateTypeParmType *replacementType;
4720 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(argQualType);
4722 if (!replacementType) {
4723 const clang::SubstTemplateTypeParmType *argType
4724 = llvm::dyn_cast<clang::SubstTemplateTypeParmType>(argQualType);
4726 clang::QualType replacementQT = argType->getReplacementType();
4727 replacementType = llvm::dyn_cast<clang::TemplateTypeParmType>(replacementQT);
4730 if (replacementType &&
4731 depth == replacementType->getDepth() &&
4732 index == replacementType->getIndex() )
4739 replacedCtxt = spec->getSpecializedTemplate();
4741 replacedCtxt = decl->getDescribedClassTemplate();
4743 }
else if (
auto const declguide = llvm::dyn_cast<clang::CXXDeductionGuideDecl>(replacedDeclCtxt)) {
4744 replacedCtxt = llvm::dyn_cast<clang::ClassTemplateDecl>(declguide->getDeducedTemplate());
4745 }
else if (
auto const ctdecl = llvm::dyn_cast<clang::ClassTemplateDecl>(replacedDeclCtxt)) {
4746 replacedCtxt = ctdecl;
4748 std::string astDump;
4749 llvm::raw_string_ostream ostream(astDump);
4752 ROOT::TMetaUtils::Warning(
"ReSubstTemplateArg",
"Unexpected type of declaration context for template parameter: %s.\n\tThe responsible class is:\n\t%s\n",
4753 replacedDeclCtxt->getDeclKindName(), astDump.c_str());
4754 replacedCtxt =
nullptr;
4757 if ((replacedCtxt && replacedCtxt->getCanonicalDecl() == TSTdecl->getSpecializedTemplate()->getCanonicalDecl())
4759 substType->getReplacedParameter()->getDecl()
4760 == TSTdecl->getSpecializedTemplate ()->getTemplateParameters()->getParam(
index))
4762 const auto &TAs = TST->template_arguments();
4763 if (
index >= TAs.size()) {
4769 }
else if (TAs[
index].getKind() == clang::TemplateArgument::Type) {
4770 return TAs[
index].getAsType();
4779 const clang::TemplateSpecializationType* inputTST
4780 = llvm::dyn_cast<const clang::TemplateSpecializationType>(
input.getTypePtr());
4781 const clang::ASTContext& astCtxt = TSTdecl->getASTContext();
4784 bool mightHaveChanged =
false;
4785 llvm::SmallVector<clang::TemplateArgument, 4> desArgs;
4786 for (
const clang::TemplateArgument &
TA : inputTST->template_arguments()) {
4787 if (
TA.getKind() != clang::TemplateArgument::Type) {
4788 desArgs.push_back(
TA);
4792 clang::QualType SubTy =
TA.getAsType();
4794 if (llvm::isa<clang::SubstTemplateTypeParmType>(SubTy)
4795 || llvm::isa<clang::TemplateSpecializationType>(SubTy)) {
4797 mightHaveChanged = SubTy != newSubTy;
4798 if (!newSubTy.isNull()) {
4799 desArgs.push_back(clang::TemplateArgument(newSubTy));
4802 desArgs.push_back(
TA);
4806 if (mightHaveChanged) {
4807 clang::Qualifiers qualifiers =
input.getLocalQualifiers();
4808 input = astCtxt.getTemplateSpecializationType(inputTST->getTemplateName(),
4810 inputTST->getCanonicalTypeInternal());
4811 input = astCtxt.getQualifiedType(
input, qualifiers);
4823 if ( nArgsToRemove == 0 ||
name ==
"")
4830 unsigned int nArgsRemoved=0;
4831 unsigned int nBraces=0;
4833 while (nArgsRemoved!=nArgsToRemove && cur<
length){
4835 if (
c ==
'<') nBraces++;
4836 if (
c ==
'>') nBraces--;
4837 if (
c ==
',' && nBraces==1 ) nArgsRemoved++;
4851 static const char *stls[] =
4852 {
"any",
"vector",
"list",
"deque",
"map",
"multimap",
"set",
"multiset",
"bitset",
4853 "forward_list",
"unordered_set",
"unordered_multiset",
"unordered_map",
"unordered_multimap",
"RVec",
nullptr};
4867 for(
int k=1;stls[k];k++) {
if (
type.equals(stls[k]))
return values[k];}
4878 TND = TND->getMostRecentDecl();
4879 while (TND && !(TND->hasAttrs()))
4880 TND = TND->getPreviousDecl();
4892 TD = TD->getMostRecentDecl();
4893 while (TD && !(TD->hasAttrs() && TD->isThisDeclarationADefinition()))
4894 TD = TD->getPreviousDecl();
4903 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4905 const clang::DeclContext* enclosingNamespaceDeclCtxt = decl.getDeclContext();
4906 if (!enclosingNamespaceDeclCtxt)
return;
4908 const clang::NamespaceDecl* enclosingNamespace =
4909 clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4910 if (!enclosingNamespace)
return;
4912 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4913 enclosingNamespace->isInline()));
4923 std::list<std::pair<std::string,bool> >& enclosingNamespaces)
4925 const clang::DeclContext* enclosingNamespaceDeclCtxt = ctxt.getParent ();
4928 if (!enclosingNamespaceDeclCtxt) {
4934 const clang::NamespaceDecl* enclosingNamespace = clang::dyn_cast<clang::NamespaceDecl>(enclosingNamespaceDeclCtxt);
4935 if (!enclosingNamespace)
return;
4938 enclosingNamespaces.push_back(std::make_pair(enclosingNamespace->getNameAsString(),
4939 enclosingNamespace->isInline()));
4950 std::list<std::pair<std::string,unsigned int> >& enclosingSc)
4952 const clang::DeclContext* enclosingDeclCtxt = decl.getDeclContext();
4953 if (!enclosingDeclCtxt)
return nullptr;
4955 unsigned int scopeType;
4957 if (
auto enclosingNamespacePtr =
4958 clang::dyn_cast<clang::NamespaceDecl>(enclosingDeclCtxt)){
4959 scopeType= enclosingNamespacePtr->isInline() ? 1 : 0;
4960 enclosingSc.push_back(std::make_pair(enclosingNamespacePtr->getNameAsString(),scopeType));
4964 if (
auto enclosingClassPtr =
4965 clang::dyn_cast<clang::RecordDecl>(enclosingDeclCtxt)){
4966 return enclosingClassPtr;
4978 std::string::size_type beginVar = 0;
4979 std::string::size_type endVar = 0;
4980 while ((beginVar = txt.find(
'$', beginVar)) != std::string::npos
4981 && beginVar + 1 < txt.length()) {
4982 std::string::size_type beginVarName = beginVar + 1;
4983 std::string::size_type endVarName = std::string::npos;
4984 if (txt[beginVarName] ==
'(') {
4986 endVarName = txt.find(
')', beginVarName);
4988 if (endVarName == std::string::npos) {
4990 varname, txt.c_str() + beginVar);
4993 endVar = endVarName + 1;
4996 beginVarName = beginVar + 1;
4997 endVarName = beginVarName;
4998 while (isalnum(txt[endVarName]) || txt[endVarName] ==
'_')
5000 endVar = endVarName;
5003 const char* val = getenv(txt.substr(beginVarName,
5004 endVarName - beginVarName).c_str());
5007 txt.replace(beginVar, endVar - beginVar, val);
5008 int lenval = strlen(val);
5009 int delta = lenval - (endVar - beginVar);
5013 beginVar = endVar + 1;
5025 const char* envInclPath = getenv(
"ROOT_INCLUDE_PATH");
5029 std::istringstream envInclPathsStream(envInclPath);
5030 std::string inclPath;
5031 while (std::getline(envInclPathsStream, inclPath,
':')) {
5034 if (!inclPath.empty()) {
5035 clingArgs.push_back(
"-I");
5036 clingArgs.push_back(inclPath);
5047 size_t start_pos = 0;
5052 while((start_pos = str.find(from, start_pos)) != std::string::npos) {
5053 str.replace(start_pos, from.length(), to);
5054 start_pos += to.length();
5055 if (recurse) changed =
true;
5071 if (theString.size() < theSubstring.size())
return false;
5072 const unsigned int theSubstringSize = theSubstring.size();
5073 return 0 == theString.compare(theString.size() - theSubstringSize,
5082 if (theString.size() < theSubstring.size())
return false;
5083 const unsigned int theSubstringSize = theSubstring.size();
5084 return 0 == theString.compare(0,
5102 size_t linkdeflen = 9;
5104 if (0 == strncasecmp(
filename + (
len - linkdeflen),
"linkdef", linkdeflen - 2)
5120 return llvm::sys::path::extension(
filename) ==
".h" ||
5121 llvm::sys::path::extension(
filename) ==
".hh" ||
5122 llvm::sys::path::extension(
filename) ==
".hpp" ||
5123 llvm::sys::path::extension(
filename) ==
".H" ||
5124 llvm::sys::path::extension(
filename) ==
".h++" ||
5125 llvm::sys::path::extension(
filename) ==
"hxx" ||
5126 llvm::sys::path::extension(
filename) ==
"Hxx" ||
5127 llvm::sys::path::extension(
filename) ==
"HXX";
5133 cling::Interpreter::IgnoreFilesFunc_t ignoreFiles,
5134 const cling::Interpreter &interp,
5137 clang::Sema &sema = interp.getSema();
5138 cling::Transaction theTransaction(sema);
5139 std::set<clang::Decl *> addedDecls;
5140 for (
auto decl : decls) {
5142 clang::Decl *ncDecl =
const_cast<clang::Decl *
>(decl);
5143 theTransaction.append(ncDecl);
5145 std::string newFwdDecl;
5146 llvm::raw_string_ostream llvmOstr(newFwdDecl);
5148 std::string locallogs;
5149 llvm::raw_string_ostream llvmLogStr(locallogs);
5150 interp.forwardDeclare(theTransaction, sema.getPreprocessor(), sema.getASTContext(), llvmOstr,
true,
5151 logs ? &llvmLogStr : nullptr, ignoreFiles);
5155 logs->swap(locallogs);
5167 std::string& defString)
5179 std::string& defString)
5181 std::list<std::pair<std::string,unsigned int> > enclosingNamespaces;
5184 if (rcdPtr)
return rcdPtr;
5187 static const std::string scopeType [] = {
"namespace ",
"inline namespace ",
"class "};
5189 std::string scopeName;
5190 std::string scopeContent;
5191 unsigned int scopeIndex;
5192 for (
auto const & encScope : enclosingNamespaces){
5193 scopeIndex = encScope.second;
5194 scopeName = encScope.first;
5195 scopeContent =
" { " + defString +
" }";
5196 defString = scopeType[scopeIndex] +
5218 const clang::TemplateParameterList& tmplParamList,
5219 const cling::Interpreter& interpreter)
5222 for (
auto prmIt = tmplParamList.begin();
5223 prmIt != tmplParamList.end(); prmIt++){
5225 if (prmIt != tmplParamList.begin())
5226 templateArgs +=
", ";
5228 auto nDecl = *prmIt;
5229 std::string typeName;
5232 if (llvm::isa<clang::TemplateTypeParmDecl>(nDecl)){
5233 typeName =
"typename ";
5234 if (nDecl->isParameterPack())
5236 typeName += (*prmIt)->getNameAsString();
5239 else if (
auto nttpd = llvm::dyn_cast<clang::NonTypeTemplateParmDecl>(nDecl)){
5240 auto theType = nttpd->getType();
5243 if (theType.getAsString().find(
"enum") != std::string::npos){
5244 std::string astDump;
5245 llvm::raw_string_ostream ostream(astDump);
5246 nttpd->dump(ostream);
5248 ROOT::TMetaUtils::Warning(
nullptr,
"Forward declarations of templates with enums as template parameters. The responsible class is: %s\n", astDump.c_str());
5257 else if (
auto ttpd = llvm::dyn_cast<clang::TemplateTemplateParmDecl>(nDecl)){
5260 std::string astDump;
5261 llvm::raw_string_ostream ostream(astDump);
5262 ttpd->dump(ostream);
5264 ROOT::TMetaUtils::Error(
nullptr,
"Cannot reconstruct template template parameter forward declaration for %s\n", astDump.c_str());
5269 templateArgs += typeName;
5280 const cling::Interpreter& interpreter,
5281 std::string& defString)
5283 std::string templatePrefixString;
5284 auto tmplParamList= templDecl.getTemplateParameters();
5285 if (!tmplParamList){
5287 "Cannot extract template parameter list for %s",
5288 templDecl.getNameAsString().c_str());
5295 "Problems with arguments for forward declaration of class %s\n",
5296 templDecl.getNameAsString().c_str());
5299 templatePrefixString =
"template " + templatePrefixString +
" ";
5301 defString = templatePrefixString +
"class ";
5302 if (templDecl.isParameterPack())
5303 defString +=
"... ";
5304 defString += templDecl.getNameAsString();
5305 if (llvm::isa<clang::TemplateTemplateParmDecl>(&templDecl)) {
5319 std::string& argFwdDecl,
5320 const cling::Interpreter& interpreter,
5321 bool acceptStl=
false)
5327 if (clang::TemplateArgument::Type != arg.getKind())
return 0;
5329 auto argQualType = arg.getAsType();
5332 while (llvm::isa<clang::PointerType>(argQualType.getTypePtr())) argQualType = argQualType->getPointeeType();
5334 auto argTypePtr = argQualType.getTypePtr();
5337 if (llvm::isa<clang::EnumType>(argTypePtr)){
5342 if (llvm::isa<clang::BuiltinType>(argTypePtr)){
5347 if (
auto tdTypePtr = llvm::dyn_cast<clang::TypedefType>(argTypePtr)) {
5348 FwdDeclFromTypeDefNameDecl(*tdTypePtr->getDecl(), interpreter, argFwdDecl);
5352 if (
auto argRecTypePtr = llvm::dyn_cast<clang::RecordType>(argTypePtr)){
5354 if (
auto argRecDeclPtr = argRecTypePtr->getDecl()){
5355 FwdDeclFromRcdDecl(*argRecDeclPtr,interpreter,argFwdDecl,acceptStl);
5367 const cling::Interpreter& interpreter,
5368 std::string& defString,
5369 const std::string &normalizedName)
5373 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)) {
5374 if (
const auto *specDef = tmplSpecDeclPtr->getDefinition()) {
5375 if (specDef->getTemplateSpecializationKind() != clang::TSK_ExplicitSpecialization)
5379 std::cout <<
" Forward declaring template spec " << normalizedName <<
":\n";
5380 for (
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()) {
5381 std::string argFwdDecl;
5384 std::cout <<
" o Template argument ";
5386 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5388 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5395 defString += argFwdDecl +
'\n';
5397 defString +=
"template <> class " + normalizedName +
';';
5411 const cling::Interpreter& interpreter,
5412 std::string& defString,
5420 if (!recordDecl.getIdentifier())
5424 std::string argsFwdDecl;
5426 if (
auto tmplSpecDeclPtr = llvm::dyn_cast<clang::ClassTemplateSpecializationDecl>(&recordDecl)){
5427 std::string argFwdDecl;
5429 std::cout <<
"Class " << recordDecl.getNameAsString()
5430 <<
" is a template specialisation. Treating its arguments.\n";
5431 for(
auto arg : tmplSpecDeclPtr->getTemplateArgs().asArray()){
5434 std::cout <<
" o Template argument ";
5436 std::cout <<
"successfully treated. Arg fwd decl: " << argFwdDecl << std::endl;
5438 std::cout <<
"could not be treated. Abort fwd declaration generation.\n";
5445 argsFwdDecl+=argFwdDecl;
5449 defString=argsFwdDecl;
5454 if (
auto tmplDeclPtr = tmplSpecDeclPtr->getSpecializedTemplate()){
5457 defString = argsFwdDecl +
"\n" + defString;
5462 defString =
"class " + recordDecl.getNameAsString() +
";";
5463 const clang::RecordDecl* rcd =
EncloseInScopes(recordDecl, defString);
5471 defString = argsFwdDecl +
"\n" + defString;
5482 const cling::Interpreter& interpreter,
5483 std::string& fwdDeclString,
5484 std::unordered_set<std::string>* fwdDeclSetPtr)
5486 std::string buffer = tdnDecl.getNameAsString();
5487 std::string underlyingName;
5488 auto underlyingType = tdnDecl.getUnderlyingType().getCanonicalType();
5489 if (
const clang::TagType* TT
5490 = llvm::dyn_cast<clang::TagType>(underlyingType.getTypePtr())) {
5491 if (clang::NamedDecl* ND = TT->getDecl()) {
5492 if (!ND->getIdentifier()) {
5506 if (underlyingName.find(
">::") != std::string::npos)
5509 buffer=
"typedef "+underlyingName+
" "+buffer+
";";
5521 auto& ctxt = tdnDecl.getASTContext();
5522 auto immediatelyUnderlyingType = underlyingType.getSingleStepDesugaredType(ctxt);
5524 if (
auto underlyingTdnTypePtr = llvm::dyn_cast<clang::TypedefType>(immediatelyUnderlyingType.getTypePtr())){
5525 std::string tdnFwdDecl;
5526 auto underlyingTdnDeclPtr = underlyingTdnTypePtr->getDecl();
5531 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(tdnFwdDecl).second)
5532 fwdDeclString+=tdnFwdDecl;
5533 }
else if (
auto CXXRcdDeclPtr = immediatelyUnderlyingType->getAsCXXRecordDecl()){
5534 std::string classFwdDecl;
5536 std::cout <<
"Typedef " << tdnDecl.getNameAsString() <<
" hides a class: "
5537 << CXXRcdDeclPtr->getNameAsString() << std::endl;
5546 if (!fwdDeclSetPtr || fwdDeclSetPtr->insert(classFwdDecl).second)
5547 fwdDeclString+=classFwdDecl;
5550 fwdDeclString+=buffer;
5562 std::string& valAsString,
5563 const clang::PrintingPolicy& ppolicy)
5565 auto defArgExprPtr = par.getDefaultArg();
5566 auto& ctxt = par.getASTContext();
5567 if(!defArgExprPtr->isEvaluatable(ctxt)){
5571 auto defArgType = par.getType();
5574 if (defArgType->isBooleanType()){
5576 defArgExprPtr->EvaluateAsBooleanCondition (
result,ctxt);
5577 valAsString=std::to_string(
result);
5582 if (defArgType->isIntegerType()){
5583 clang::Expr::EvalResult evalResult;
5584 defArgExprPtr->EvaluateAsInt(evalResult, ctxt);
5585 llvm::APSInt
result = evalResult.Val.getInt();
5586 auto uintVal = *
result.getRawData();
5587 if (
result.isNegative()){
5588 long long int intVal=uintVal*-1;
5589 valAsString=std::to_string(intVal);
5591 valAsString=std::to_string(uintVal);
5598 llvm::raw_string_ostream rso(valAsString);
5599 defArgExprPtr->printPretty(rso,
nullptr,ppolicy);
5600 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 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_iterator begin() const
const std::string & GetPathSeparator()
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
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.
#define dest(otri, vertexptr)